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 (Abbot) 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.