Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Short (and clever?) CSV-to-AoA

by merlyn (Sage)
on Apr 23, 2001 at 20:35 UTC ( [id://74758]=note: print w/replies, xml ) Need Help??


in reply to Short (and clever?) CSV-to-AoA

Is this really any better than:
my @AoA = map [split], <DATA>;

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re: Re: Short (and clever?) CSV-to-AoA
by scott (Chaplain) on Apr 23, 2001 at 23:59 UTC

    Yes, it is much better ... Because my code does something different than yours does. :)

    My code turns each *column* of DATA into a single anonymous array, stored in @AoA so the print statement gives

    1, 4, 7, A, D, G, J, M, P, S, V, Y

    Your

    my @AoA = map [split], <DATA>; print join( ', ' , @{ $AoA[ 0 ] } ) , "\n";
    gives 1, 2, 3.

      Ahh, then it's just a matter of asking for the right print! The idiom for "extract a column while printing" is known, and reusable:
      my @AoA = map [split], <DATA>; print join(", ", map $AoA[0][$_], 0..$#{$AoA[0]}), "\n";

      -- Randal L. Schwartz, Perl hacker

        Cool. But I don't want to extract a column while printing, the print was just a way of showing the results if someone wanted to run the code.

        I want to have an AoA with each element being a column of data ...not that I ever said as much, which, in retrospect, would have avoided lots of time spent by other people trying to figure out what my real goal was.

        Sorry.

        And thanks for the 'idiom', I added it to my personal archive of neat little bits O'Perl.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2025-01-24 17:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (68 votes). Check out past polls.