in reply to usage of awk and grep together
Anything awk/grep can do perl can do better! You don't need to inefficiently call them externally, perl already has adopted their strengths.
sub get_log_data { open my $logfile, '<', 'logfile' or die "open on logfile: $!"; my @data_lines; while (<$logfile>) { next unless ( /fileid/ .. /^-{5}/ ); # range operator! if (/specificdata/) { push @data_lines, $_; } } close $logfile; die 'could not find specificdata in logfile' unless (@data_lines); return join q{}, @data_lines; }
Please try to enclose your code and error message in <c> and </c> tags in the future. Your error did not display right and the code is easier to read with these tags.
Update: fixed bug where only one line of specificdata matching would be returned, not multiple lines.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: usage of awk and grep together
by JavaFan (Canon) on May 20, 2009 at 08:19 UTC | |
|
Re^2: usage of awk and grep together
by raghu_shekar (Novice) on May 20, 2009 at 06:33 UTC | |
by juster (Friar) on May 20, 2009 at 18:18 UTC |