Hi everyone,

I'm trying to update the phone numbers in a ASCII file but for some reason it's not working.

Here is a portion of the file(personel.txt):

#id|Name|family|phone
0001|Tony|Hintz|0407561232
0002|James|Green|0403652154
0003|Isaac|Thomas|0403655871

I'm greping a line basing on the id and then changing the phone number and then trying to replace it back into the file, but for some reason it is not working. Have a look on my code:

#!/usr/bin/perl -w $newdigit="+615"; $id="0001"; $line = `grep $id personel.txt`; ($id, $name, $family, $oldphone)=split(/\|/, $line); $newphone = $newdigit .$oldphone; $NewLine= join ("|",$id, $name, $family, $newphone); open(PERS,">>personel.txt"); while (<PERS>) { s/$line/$NewLine/; }


can anyone tell me what's going wrong? and if there any better way to do it?

TANX,
a very newbie

Ps: $NewLine reflects the changes but i'm not able to write it back to the file.

20030606 Edit by Corion: Changed title from "Substitue!"


In reply to Substitution of text within a file by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.