Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: replace/substituion 4th field

by tmharish (Friar)
on Feb 20, 2013 at 08:15 UTC ( #1019732=note: print w/replies, xml ) Need Help??

in reply to replace/substituion 4th field

Considering you have already split up $line, why replace in the original? I would simply join @fields like so:

while (my $line = <$data>) { chomp $line; my @fields = split ",", $line, -1; my $sum = $fields[3]; $fields[3] = 'volemd' if ($fields[3] > 310 ) ; $fields[3] = 'volemd1' if ($fields[3] == 70 ) ; print join( ',', @fields ) . "\n" ; }

Update: Modified as per correction by jwkrahn below.

Replies are listed 'Best First'.
Re^2: replace/substituion 4th field
by jwkrahn (Monsignor) on Feb 20, 2013 at 17:04 UTC
    chomp $line; my @fields = split "," , $line; ... print join( ',', @fields ) . "\n" ;

    That won't work correctly on the data provided.    You need to change split "," , $line to split "," , $line, -1.

      Absolutely - Updated above.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019732]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2018-03-23 04:08 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (287 votes). Check out past polls.