Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have to read lines from a log file which begins with // with some white spaces before and put them in a array so below is the code what i could write and this works. But i want to know if i can remove the spaces before pushing into array instead of using s/^\s+//g; in foreach loop while printing and also i want to ignore the lines with -// which is getting included.
open (FH,"$file") || die ("could not openfile"); my @arr; while (<FH>) { chomp; push @arr , $_ unless $_ !~ /\s+\/\// ; } foreach (@arr){ s/^\s+//g; s/^-\/\/.+//g; print $_."\n"; } Thanks in advance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help in reading log file
by hipowls (Curate) on Mar 14, 2008 at 08:51 UTC | |
|
Re: Help in reading log file
by Punitha (Priest) on Mar 14, 2008 at 07:05 UTC | |
|
Re: Help in reading log file
by jwkrahn (Abbot) on Mar 14, 2008 at 07:08 UTC | |
|
Re: Help in reading log file
by poolpi (Hermit) on Mar 14, 2008 at 07:11 UTC |