Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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."

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://282885]
help
Chatterbox?
[choroba]: command line FTW!
[marto]: good morning all, sane dots all round
[Corion]: Hi marto! I hope all is well!

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2016-12-07 09:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (125 votes). Check out past polls.