jls13 has asked for the wisdom of the Perl Monks concerning the following question:

insead of trying to exlain my problem ill just cp the code here (if that doesnt work, ill try again):
foreach $table(keys %tableNum){ my $sth = $dbh->prepare($sqlbyTabs{"$table"}) || die("Unable +to perpare statement"); $sth->execute() || die("Database execute Error: $DBI::errstr") +; @results = @{ $sth->fetchall_arrayref }; for ($row = 0; $row <= $#results; $row++) { $h = @{$results[$row]}[0]; map{$Data{$h}{$tableFts{$table}[$_]} = @{$results[$row]}[$_ +]}1..$#results->[$row]; <br> } }
my problem arises in that map statement. i want $_ to get from 1 to the count of the anonomys array (so basically $results[$row][1..the count here])...will this work, or can you give me something that will . thanks

Replies are listed 'Best First'.
Re: mapping 2nd array
by Zaxo (Archbishop) on Feb 13, 2005 at 20:42 UTC

    It would have been well to explain what you want, instead. I'm not sure what you're trying to accomplish. It looks like you want to assign a slice to a slice inside a map in void context. But, you are assigning the value of a hash of hashes to the number of elements in an array reference, instead.

    Your hash slices ought to look like @foo{LIST}. Map returns the list it produces, so you may clarify things for yourself by rewriting the map in the form,     @{slice_or_whatever} = map {whatever} @results;

    Your C-style for loop is confusing things, too.

    for (@{$sth->fetchall_arrayref}) { # . . . }
    will suffice.

    As always, use strict; and use warnings; will keep you out of trouble.

    After Compline,
    Zaxo

      yea some c habits die hard. let me simplify in hopes of better explaining what i want.
      @ superArray = ('1' =>[], ...etc); map{$some_hash{$_} = $some_other_hash{$_}}1..$#superArray[][i want the + count/total of this one]
Re: mapping 2nd array
by Errto (Vicar) on Feb 13, 2005 at 21:55 UTC
    for my $row (@{$sth->fetchall_arrayref}) { # note $row is an actual ro +w, not a number my $h = $row->[0]; $Data{$h}{$tableFts{$table}[$_]} = $row->[$_] for 1 .. $#{$row}; }
    This illustrates two points: a) that it's much cleaner to use a Perl-style foreach loop if you're going to be capturing the whole array anyway, and b) that the way to get the maximum subscript of an array reference is to put braces after the $#.