in reply to Re: Substitue!
in thread Substitution of text within a file

Indeed. All you need is the -i option, and possibly the -p option (see perlrun) to do the loop and the printing. You can even use them in regular scripts. Note that with the -p option, anything you want to do before the loop needs to be in a BEGIN block.

In the next code, the -l option takes care of the newlines.

#!/usr/bin/perl -p -i.bak -l BEGIN { @ARGV = 'personel.txt'; $newdigit="+615"; $id="0001"; } if(/^$id\|/o) { my($id, $name, $family, $oldphone) = split /\|/; $newphone = $newdigit .$oldphone; $_ = join ("|", $id, $name, $family, $newphone); }

p.s. You're trying to read from a file opened for append. Jeez.

Replies are listed 'Best First'.
Re: Re: Re: Substitue!
by Anonymous Monk on Jun 07, 2003 at 07:47 UTC
    Bart, tanx for ur reply. Your code is working perfectly, however if i try to call it from a web browser through a get method (passing the id) it won't work!.. any clue why this is happening..