On Apr 1, 2009, at 2:04 PM, Chas. Owens wrote:


If I understand you correctly, you want a map[1] that feeds a join[2]:

#!/usr/bin/perl

use strict;
use warnings;

my @aref = (
        [qw/a1 b1 c1/],
        [qw/a2 b2 c2/],
        [qw/a3 b3 c3/],
);

print join(", ", map { "($_->[0]=$_->[2])" } @aref), "\n";


Well, that certainly did what I needed.  Thanks.

I was getting tangled up with the complexities of addressing the various things inside the "table". Here, for no particular purpose, are a few experiments I did:

#!/usr/bin/perl

use strict;
use warnings;

my @ary = ( # non-square so I fail if I switch row & column accidentally
    [qw/a1 b1 c1 d1/],
    [qw/a2 b2 c2 d2/],
    [qw/a3 b3 c3 d3/],
    );


my $a_ref = \...@ary;        # Simulate a ref to a row set returned by DBI

# Demonstrate that one deref. takes us to array of three refs

print q/Printing @$a_ref to show it's an array of three refs:/, "\n@ $a_ref\n\n";

print "Show slices of each row:\n";

for my $j (@$a_ref) { # Iterates thrice; each time, $j is ref to horiz. array print "($j->[0], $j->[3])\n"; # use '->[]' to get to the contents: scalar, so use '$'
}

print "\nPractice navigating to places in the table with one expression:\n"; print q/$a_ref =/, "$a_ref\n"; # Ref to the "vertical" array print q/@$a_ref =/, "@$a_ref\n"; # The vertical array itself? print q/$$a_ref[2] =/, "$$a_ref[2]\n"; # Element 2 of the vertical array print q/@{$$a_ref[2]} =/, "@{$$a_ref[2]}\n"; # Horizontal array 2 (all three elements)
print q/${$$a_ref[2]}[3]  =/, "${$$a_ref[2]}[3]\n"; # Cell [2][3]
print "Can the last one be simplified any?\n"; #





--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to