SPUG: Slice of an arrary within a hash?
Lou Hevly
lou at visca.com
Fri May 5 14:55:06 CDT 2000
At 14:04 05/05/00 -0400, Rob Garrett wrote:
>Good morning -
>
>I'd appreciate a little help understanding the
>behavior of the following script.
>
>I've included 3 versions of the same script
>which are identical except for the subset of
>lines which have been commented out.
<snip>
How 'bout a *hash* slice? Also, using Data::Dumper will help us visualize what's actually going on.
----
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
my %data;
my $dsku = 'fred';
my @prices = ('00.00', '11.11','22.22','33.33','44.44');
@{$data{$dsku}} = @prices;
for my $i (0.. $#{$data{$dsku}} )
{
print "\$data{\$dsku}[$i] = '$data{$dsku}[$i]'\n";
}
# or
print Dumper %data;
----
RESULT:
$data{$dsku}[0] = '00.00'
$data{$dsku}[1] = '11.11'
$data{$dsku}[2] = '22.22'
$data{$dsku}[3] = '33.33'
$data{$dsku}[4] = '44.44'
$VAR1 = 'fred';
$VAR2 = [
'00.00',
'11.11',
'22.22',
'33.33',
'44.44'
];
----
HTH.
--
All the best (Adéu-siau),
Lou Hevly
lou at visca.com
http://www.visca.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
SUBSCRIBE/UNSUBSCRIBE: Replace "action" below by subscribe or unsubscribe
Email to majordomo at pm.org: "action" spug-list your_address
More information about the spug-list
mailing list