For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > September 2006 > reg perl parsing a file









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author reg perl parsing a file
sivga

2006-09-06, 7:57 am

hello all ,

Iam new to perl .this is wat iam trying to do i have a text file with
following lines

exact 5
sea 3
switch text 1.2
new data 20
cd data 10
phase 30
extra 40
same 200
different 500

wat i need do is i neeed to read the file and if the file has (matches)
switch text i need to write switch text to a new file say k2 and the
next four lines new data ,cd data,extra and phase to k2 .other wise no
need to write to the file k2. ,I cannot form the string say new data cd
data and write to a file coz the numbers at the end will differ .How do
i do it ?

while (<AG> ) {

if ($_ =~ /exact +([0-9]+)/ ) {
print k1 " $_";

} elsif ( $_ =~ /switch text /) {
print k2 "$_";

} elsif ($_ =~ /same/) {
print k1 "$_";
}

Thanks for the help

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com