SPUG: Slice of an arrary within a hash?
Rob Garrett
robg at techie.com
Fri May 5 14:54:18 CDT 2000
Thanks Joel and Ned -
That's it!
I wasn't seeing the forest for the trees (the array reference behind the
subscripts).
I was using the slice to "cast/transform/..." the @prices array into a list
of exactly 4 elements regardless of the size of the array (and this seems to
work). I could accomplish the same result by setting the array size prior
to assigning its contents to %DATA?
Thanks!
Rob
------Original Message------
From: Joel <largest at largest.org>
To: spug-list at pm.org
Sent: May 5, 2000 6:46:25 PM GMT
Subject: Re: SPUG: Slice of an arrary within a hash?
Replying to myself here...
I now see you were talking about slices. If this is what you want, you
could do one of the following 2 ways:
#!/usr/bin/perl
# You should always use strict
use strict;
my %DATA;
my $dsku = 'fred';
my @prices = ('11.11','22.22','33.33','44.44');
# EITHER THIS
$DATA{$dsku}[0] = '00.00';
@{ $DATA{$dsku} }[1..4] = @prices;
$DATA{$dsku}[5] = '55.55';
# OR THIS
@{ $DATA{$dsku} }[0..5] = ('00.00', @prices, '55.55');
#I also moved my $count++ so that it reflects 0-5, not 1-6
my $count = 0;
for my $element ( @{ $DATA{$dsku} } ) {
print "\$DATA{\$sku}[$count] = '$element'\n";
$count++;
}
__END__
HTH
Joel
______________________________________________
FREE Personalized Email at Mail.com
Sign up at http://www.mail.com/?sr=signup
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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