Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Parsing a generic file

by hdb (Prior)
on Jul 25, 2013 at 13:47 UTC ( #1046344=note: print w/replies, xml ) Need Help??

in reply to Parsing a generic file

Nice exercise for Text::CSV fans:

use strict; use warnings; use Text::CSV; my( $infile, $outfile, @cols ) = @ARGV; print "Reading from $infile.\n"; print "Writing to $outfile.\n"; print "Target columns are @cols.\n"; open my $in, "<", $infile or die "Cannot open $infile: $!\n"; open my $out, ">", $outfile or die "Cannot open $outfile: $!\n"; $_-- for @cols; # correct column numbering my $csv = Text::CSV->new( ); my $pipe = Text::CSV->new( { sep_char => '|' } ); my $tilde = Text::CSV->new( { sep_char => '~', eol => "\n" } ); while( my $line = $csv->getline( $in ) ) { $pipe ->combine( @$line ); $tilde->combine( @$line[@cols], $pipe->string ); print $out $tilde->string; } close $out; close $in;

Replies are listed 'Best First'.
Re^2: Parsing a generic file
by IyengarRaj (Initiate) on Jul 26, 2013 at 16:41 UTC
    Thanks you very much guys. Really appreciate it very much. Clue about Text::CSV was the key element and how easily this can be done using that. I love this group. Thanks again.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1046344]
[erix]: how does one find out how to install a program like cvsgrep
[erix]: I mean, I suppose it's just the one file so I can download that
[erix]: Makefile.PL should tell me, probably

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2017-06-22 16:44 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (524 votes). Check out past polls.