Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Problems? Is your data what you think it is?
 
PerlMonks  

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.


Comment on Re: replace/substituion 4th field
Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019732]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2014-04-19 06:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (478 votes), past polls