"Purcell, Scott" wrote:
>
> Hello,
> >From the perlreftut, I have some in which I am creating a hash of arrays
> where each array only has 2 values.
>
> # creation of hash of arrays
> $sth = &DoSQL($sql);
> while (($item, $cost, $charge) = $sth->fetchrow_array()) {
> push @{$costtable{$item}}, ($cost, $charge);
> }
>
> # spitting out the whole lot
> foreach my $key(sort keys %costtable) {
> print "$key:\n";
> my @tmp = @{$costtable{$key}};
> print "@tmp<br>\n";
> }
>
> But I only want to get the second element in the array, So I tried the
> following but it doesn't work.
> print "<br>$costtable{shipping}->[1] here it is";
Works for me (assuming shipping is defined in your hash). The -> isn't needed.
> I have tried other tactics, but cannot access it. Does anyone know how to
> grab the second array element in a hash of arrays?
Check your hash structure to make sure you have what you think you have:
use Data::Dumper; $Data::Dumper::Indent=1;
print Data::Dumper->Dump([%costtable], [qw(Costtable)]);
--
,-/- __ _ _ $Bill Luebkert ICQ=14439852
(_/ / ) // // DBE Collectibles http://www.todbe.com/
/ ) /--< o // // Mailto:[EMAIL PROTECTED] http://dbecoll.webjump.com/
-/-' /___/_<_</_</_ http://www.freeyellow.com/members/dbecoll/
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users