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 põhjapõder (Novice)
on Feb 20, 2013 at 08:21 UTC ( #1019734=note: print w/ replies, xml ) Need Help??

in reply to replace/substituion 4th field

Hello hyans.milis,

You should consider using Text::CSV for this task:

#!/usr/bin/perl use strict; use warnings; use Text::CSV; die "Usage: $0 <filename>\n" unless @ARGV > 0; open (my $fh, '<', $ARGV[0]) || die "$ARGV[0]: $!\n"; my $csv = Text::CSV->new(); $csv->eol("\n"); my $sum = 0; while (my $row = $csv->getline( $fh )) { $sum = $row->[3]; if ($sum > 310) { $row->[3] = 'volemd'; } elsif ($sum == 70) { $row->[3] = 'volemd1'; } $csv->print(\*STDOUT, $row); } $csv->eof or $csv->error_diag(); close ($fh);

This should also work with large files, since it processes one line at a time only.

Comment on Re: replace/substituion 4th field
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (10)
As of 2015-11-25 07:53 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (672 votes), past polls