Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Pearls

Name: Anonymous 2011-05-17 17:10

I was told Perl was some complicated masterful thing that was hard to learn and puts python to shame

easier then basic to learn and exact same functionality... am i missing something

Name: Anonymous 2011-05-18 20:30

>>15
To do this right we should have written

@b=([(0.8,0.9,1)],2,3,4);

when we created the list. The []s enter a reference to the inner list as the first element of the outer list instead of flattening the inner list into the outer one.

OK. So we try again:

$b[0]

gives us

ARRAY(0xb75eb0)

So obviously we manage to find the array, but something still goes wrong along the way. The problem is that we use $b, which makes Perl think that we want a scalar and so it gives us a reference to the array instead of the array itself (which is not a scalar).

Aha! Of course! We must use

@b[0]

because @ tells Perl we want an array value. Not so. We get

ARRAY(0xb75eb0)

once again. I've never managed to understand why this is so and at this point I gave up on the entire thing.

Some weeks later I saw a helpful posting on no.perl: one should request a reference to the array, like this

@{$b[0]}

which actually gives us

(0.8 0.9 1)

So now I can write code with arrays inside arrays and hashes inside hashes.

Now, ask yourself: do you really think you should have to go through all this in order to put one list inside another?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List