For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > March 2005 > help in parsing the text file in a directory









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 help in parsing the text file in a directory
user1

2005-03-31, 8:04 pm

I am not able to get the name of the text file by parsing the filename

Here is the code

Files are in the following format

FilekeyID=L19147&report=annualgeoseg.txt

opendir(DIR, "c:\\ApplinkClassic\\Results\\Server") or die "Can'topen c:\\Results\\Server: $!";

my @files = grep (/^File[\w&=]+\.txt$/, readdir DIR);

close (DIR);

#print "@files\n"; #Works fine

foreach (@files) { /^(File[\w&=]+)\.txt$/;

my $file2 = $1;

print "$_\n"; # doesn't work

print "$file2\n"; #doesn't work


}

I am not able to get the $file2 which should contain 'FilekeyID=L19147&report=annualgeoseg'

Thanks for the help
Sponsored Links







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

Copyright 2009 codecomments.com