At 12:23 PM 10/2/2001 +0930, Daniel Falkenberg wrote:
>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?


OK - I'm new at this too, but I am going to attempt to learn
something better by answering the question... =)

presuming:
$oldline = "hello, world, 1"

------

Doesn't matter that it's comma-separated.  The comma is
just another character as far as Perl is concerned.

Here's how you'd do a pattern search across the string to
keep each datapiece separate:

$oldline =~ /^(.+\, )(.)$/;
if ($2 == 1) {
    $2 = 0;
}
$newline = $1.$2;

($1 would be "Hello, World, "; and $2 would be "1")

------

Alternatively (and I think there's less overhead with
this method):

$holder = chop ($oldline);
if ($_ == 1) {
    $_ = 0;
}
$newline = $holder.$_;

------

Presuming the 1 is always present at the end of every
line:

$holder = chop($oldline);
$newline = $holder."0";


Cheers,
-Zander


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

Reply via email to