in reply to Substitution of text within a file
As you have noted, this does not change the file in place. You have two possible approaches here :
#!/usr/bin/perl -w use strict; use Tie::File; my $newdigit="+615"; my $search_id="0001"; my $personel_filename; my @personel; tie @personel, 'Tie::File', File::Spec->catfile($FindBin::Bin,$persone +l_filename) or die "Couldn't read '$personel_filename'\n"; for my $line (@personel) { my ($id, $name, $family, $oldphone)=split(/\|/, $line); # Look if we want to replace the phone if ($id eq $search_id) { $newphone = $newdigit .$oldphone; # And overwrite the line in the array $line = join ("|",$id, $name, $family, $newphone); }; };
|
|---|