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.
In reply to Re: usage of awk and grep together
by juster
in thread usage of awk and grep together
by raghu_shekar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |