Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re^2: Getting columns from csv file in perl

by pnsreee (Initiate)
on Apr 24, 2007 at 13:57 UTC ( #611739=note: print w/replies, xml ) Need Help??

in reply to Re: Getting columns from cvs file in perl
in thread Getting columns from csv file in perl

Hi Joost, It is csv file. I want expresion with out using Text::xSV or Text::CSV_XS.
  • Comment on Re^2: Getting columns from csv file in perl

Replies are listed 'Best First'.
Re^3: Getting columns from csv file in perl
by Fletch (Chancellor) on Apr 24, 2007 at 14:47 UTC

    Just don't come back whinging when you have data with embedded commas or newlines and the quick hack no longer works. You may get away with it this time, but n months down the road someone (possibly even yourself) will be swearing under their breath at you as they clean up the mess.

Re^3: Getting columns from csv file in perl
by Joost (Canon) on Apr 24, 2007 at 14:17 UTC
      my @data = map { [split /,/] } <>;

      You might want a chomp in there to avoid leaving the line terminator in the last field.

      my @data = map { chomp; [split /,/] } <>;

      I second your *sigh* by the way.



Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://611739]
[Lady_Aleena]: The whole line is push @line, ref($list_addition ) ? @$list_addition : $list_addition if $list_addition;
[Lady_Aleena]: And I forgot to do the array check, I'm such a doofus today.
[Lady_Aleena]: push @line, ref($list_addition ) eq 'ARRAY' ? @$list_addition : $list_addition if $list_addition; #trying again
[shmem]: Discipulus: yummy. I like those. Didn't have them for some time now, forgot the name. Should go get some...
[shmem]: Lasy_Aleena: correct, although for clarity I'd use an if() block, not a statement modifier
[shmem]: this allows you to add an else if maintainance makes it neccesary
[Lady_Aleena]: shmem, okeydokey.
[shmem]: ...or logging or debugging or such

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2017-04-27 11:51 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (504 votes). Check out past polls.