in reply to Use of grep and foreach
Give this a try:
#!/usr/bin/perl use strict; use warnings; use Tie::File; my @file; tie @file, 'Tie::File', '/tmp/filename' or die "Failed to tie file: $!"; foreach my $matching_line ( grep { m/^myLine/ } @file ){ $matching_line =~ s/^myLine/this_was_a_match/; }
cp
----
"Never be afraid to try something new. Remember, amateurs built the ark. Professionals built the Titanic."
In Section
Seekers of Perl Wisdom