Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Use of grep and foreach

by crouchingpenguin (Priest)
on Aug 11, 2003 at 14:22 UTC ( [id://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."

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-19 18:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found