Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

anniyan's scratchpad

by anniyan (Monk)
on Dec 14, 2005 at 15:42 UTC ( [id://516674]=scratchpad: print w/replies, xml ) Need Help??

The code below is written by me in 10 mins. The work is, A data file data.txt will be having n number of sheets in in it. Sheets is nothing but heading sheet1,2....etc. ALong with that a key file will be given which i put it in the __DATA__ Each section will be having all the keys in the same order but with some lines in between. SO what i need to do is i have to get the value from key1 to key2 from each sheet and append it to a file named key1.txt. Similarly for all the 10 keys. The code below will do that. use strict; my @data; { local $/="ReportType=Sheet"; open (FILE , "data.txt") or die ("data.txt not opened\n"); @data=<FILE>; chomp @data; @data=grep {!/^\s*$/} @data; } my %file; my @key = <DATA>; @key = map {(split/;/)[0]}@key; foreach my $d (@data) { foreach my $k (@key) { my $limit = join '|', grep {$_!=$k}(@key,'$'); my ($head)=$d=~/^(.*PageName=Sheet(\d)+)/si; if ($d=~m/$k(.*?)($limit)/si) { push @{$file{$k}},"ReportType=Sheet".$head.$/.$1; } } } foreach my $k (keys %file) { open KEY, '>'.$k.'.txt' or die ("$k.txt not opened"); print KEY join $/,@{$file{$k}}; close KEY; } __DATA__ 1000300490000;FOOD - LOUISVILLE - DMA 1000300330000;FOOD - MILWAUKEE - DMA 1000300340000;Kmart - Milwaukee - DMA 1000300350000;Target - Milwaukee - DMA 1002300490000;DRUG - LOUISVILLE - DMA 1002300330000;DRUG - MILWAUKEE - DMA 1004300310000;Kmart - Louisville - DMA 1004300320000;Target - Louisville - DMA 1000800070009;FDM Louisville DMA 1000800070010;FDM MILWAUKEE DMA Regards, Murugesan Kandasamy.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-20 04:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found