SPUG: Slice of an arrary within a hash?
ced at carios2.ca.boeing.com
ced at carios2.ca.boeing.com
Fri May 5 14:19:43 CDT 2000
> #!/usr/bin/perl -w
^^^^^^
^^^^^^
# enable warnings above. See -w
# in action below:
use strict; # this is important too.
> %DATA;
> $dsku = 'fred';
> @prices = ('11.11','22.22','33.33','44.44');
> $DATA{$dsku}[0] = '00.00';
> #$DATA{$dsku}[1 .. 4] = @prices[0 .. 3];
> #$DATA{$dsku}[1,2,3,4] = @prices[0,1,2,3];
> $DATA{$dsku}[1] = @prices[0];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If you'd used -w, you'd have been gently
tipped about the assignment above;
Scalar value @prices[0] better written as
$prices[0] at line...
Look at perldiag for that warning format and a
completer explanation:
perldoc perldiag
Or simply use the diagnostics module at the top
of your program to get the warning plus explanation
during program execution:
use diagnostics;
Otherwise, a possible bit of streamlining:
my %DATA;
my @prices = ('11.11','22.22','33.33','44.44');
my $dsku = 'fred';
$DATA{$dsku} = [ '00.00', @prices, '55.55' ];
The Perl data structures cookbook is a great
reference with plenty of examples of this
kind of thing:
perldoc perldsc
Rgds,
--
Charles DeRykus
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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