Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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

by jeroenes (Priest)
on Apr 23, 2001 at 20:40 UTC ( [id://74761]=note: print w/replies, xml ) Need Help??


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

Well, there are some things that might be useful:
1. You assign to an array in a for loop. That usually is a sign for something inefficient.
2. Your use of $#i will put all data in one array, so you technically don't have an AoA, but just an array.
3. You can loose the push/pop mechanism, replace that with a map.

This is how I would write that:

my @AoA = map{ [split] } <DATA>; print join "\n", map{ join ',' @$_ } @AoA;
You could also turn to Supersplit code.

Have fun,

Jeroen
"We are not alone"(FZ)

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

    1. You assign to an array in a for loop. That usually is a sign for something inefficient.

    It seemed more 'cool' to me than inefficient. I particularly liked the fact that I could get away with only one synthetic variable and that a loop counter (of sorts). Why is it inefficient?

    2. Your use of $#i will put all data in one array, so you technically don't have an AoA, but just an array.

    Errr ... but it *does* produce an AoA.

    print join( ', ' , @AoA ) , "\n";
    Gives
    ARRAY(0x1b9528c), ARRAY(0x1b952a4), ARRAY(0x1b952d4)

    3. You can loose the push/pop mechanism ...

    See my comment to merlyn.

      Mea culpa, I clearly missed the fact that you were transposing the table. But the other things stay.


      1. Assigning in a for loop is something that goes automagically. If there is the need to assign to an array in something that already works on an array, that should ring a bell that something is inefficient there. Your for loop actually is an assignment and a conditional statement.That maybe nice for obfuscation (well, not really, but a bit maybe), but not cool IMHO.


      3. As merlyn responded, you can rewrite that to a map, too.

      Jeroen
      "We are not alone"(FZ)

Log In?
Username:
Password:

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

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












    Results (63 votes). Check out past polls.