While this is completely accurate for the sample data you provided it will
substitute all 1's with 0's.  Is there any chance of 1's in earlier fields,
or an 11, 12, 21, 151, etc in the last field.

The second solution offered is more precise...
$oldline =~ /^(.+\, )(.)$/;
if ($2 == 1) {
    $2 = 0;
}
$newline = $1.$2;

But again may fail with any significant variation in your data (e.g.
multiple digit number in 3rd field would just be erased since it would not
match the regular expression (.) and $2 would be undefined (or null, not
sure).  I'd suggest a slightly modified...

$oldline =~ /^(.+\, )(.*)$/;

which would load everything after the last comma into $2.  One last note:
is your data comma delimited or comma-space delimited per your example.  If
it's really comma only remove the space in the regular expression.

paul.



                                                                                       
      
                    "Gary Tam"                                                         
      
                    <[EMAIL PROTECTED]        To:     "'Daniel Falkenberg'"                 
      
                    .au>                 <[EMAIL PROTECTED]>,               
      
                                         <[EMAIL PROTECTED]>                          
      
                    10/01/2001           cc:                                           
      
                    09:31 PM             Subject:     RE: Modifying a text file with 
perl.   
                    Please                                                             
      
                    respond to                                                         
      
                    gtam                                                               
      
                                                                                       
      
                                                                                       
      



Daniel,

The following code will do.

undef $/;

open (INPUT, "test") || die "Can't open the input file";

$data=<INPUT>;
close INPUT;

open (OUTPUT, ">test") || die "Can't open the output file";
$data =~ s/1/0/g;
print OUTPUT $data;
close OUTPUT;

Cheers,
Gary

-----Original Message-----
From: Daniel Falkenberg [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, 2 October 2001 12:54
To: [EMAIL PROTECTED]
Subject: Modifying a text file with perl.


List,

I have comma seperated text file here with 3 entries per line...

hello, world, 1

Is it possible with perl to change that value of 1 to 0?

Regards,

Daniel Falkenberg

==============================
VINTEK CONSULTING PTY LTD
(ACN 088 825 209)
Email:  [EMAIL PROTECTED]
WWW:    http://www.vintek.net
Tel:    (08) 8523 5035
Fax:    (08) 8523 2104
Snail:  P.O. Box 312
        Gawler   SA   5118
==============================


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to