Beefy Boxes and Bandwidth Generously Provided by pair Networks
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
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?
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 rifling through the Monastery: (6)
As of 2015-07-08 00:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls