in reply to Re^3: reading data ...
in thread reading data ...

Sure, no prob.

First, this:
my @data = map { chomp; [ split ',' ] } <DATA>; Can reformatted as my @data = map { chomp; [ split ',' ] } <DATA>;
Which means, "read each line of input from <DATA>, and for each line, pass it through the map block, and what comes out the other end, assign that to @data." The map block defines what happens to each line of input. The final value evaluated in the block -- its result -- is what "comes out the other end". So here, we chomp the line, split it on commas, and stuff that resulting list into a new, anonymous array. The result of the block (for each iteration, mind you) is the reference to that array. In short: for each line in, get an array-ref out.

The enhancement is almost identical; we're just doing a bit more inside the map block:
my @data = map { chomp; [ map { /"(.*)"/ ? $1 : $_ } split ',' ] } <DATA>;
Instead of just schlurping the result of the split directly into the new anonymous array, we're passing those list items through a map. The point of this map is to strip off leading/trailing quote pair, if it exists. That's what the regex is for. If the match succeeds, "keep" the part inside the quotes; if it fails, keep the original string. (By "keep", I mean "Let the map block result in". Hope that's not too confusing.)

It seems like obfuscation, but it's really just plain, albeit dense, idiomatic perl.

jdporter
...porque es dificil estar guapo y blanco.

Replies are listed 'Best First'.
Re^5: reading data ...
by Ionizor (Pilgrim) on Dec 18, 2002 at 08:03 UTC
    Ah! Thank you. I always wondered about map. Now that I know what map does, what the rest of the code does is straightforward. Now I can probably decode half those sigs I wondered about too. :)