Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Use of grep and foreach

by crouchingpenguin (Priest)
on Aug 11, 2003 at 14:22 UTC ( #282885=note: print w/ replies, xml ) Need Help??


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."


Comment on Re: Use of grep and foreach
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://282885]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2015-07-04 09:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (59 votes), past polls