Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: reg perl substitution

by mwah (Hermit)
on Nov 09, 2007 at 19:45 UTC ( [id://649983]=note: print w/replies, xml ) Need Help??


in reply to Re: reg perl substitution
in thread reg perl substitution

think i have to use tie::file.I went thru the perl doc ..but its not clear how to use it .could you give me a simple eg how to use it

for Tie::File, you have look at the file's lines as if they would be like "array elements", - by changing them you'd change the file. What did you try so far - what didn't work?

BTW, this problem looks rather simple, so you could employ your own file handling - sth. like this:

... my ($fnNew, $fnOld) = ('test.cfg', 'test.cfg.bak'); rename $fnNew, $fnOld or die "can't rename $fnNew, $!"; open my $fin, '<', $fnOld || die "$fnOld - $!"; open my $fout, '>', $fnNew || die "$fnNew - $!"; while( my $line = <$fin> ) { $line =~ s/(newyork\s+)1536000/${1}7878787878/; print $fout $line } close $fin; close $fout; ...

This would do basically the same as the 'one-liner' in another example already given.

Regards

mwa

Log In?
Username:
Password:

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

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

    No recent polls found