in reply to Re: What is a "slice" ?
in thread What is a "slice" ?
Say you had a hash set up as:
And since a hash doesn't come out in any meaningful predictable order - you created an array to get the order you wanted:my %month_hash = ( '1' => 'January', '2' => 'February', '3' => 'March', '4' => 'April' );
Finally, for some reason you wanted to create a new array with the month names in it - you might try:my @order = (1 .. 4);
This would work unless one of your keys was deleted as such:my @months = @month_hash{@order}; print $_,$/ for @months;
You would then get an error about an uninitialized value. This happens because the hash slice creates a new key for '3' and sets its value to undef.delete $month_hash{3}; my @months = @month_hash{@order}; print $_,$/ for @months;
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: What is a "slice" ?
by edan (Curate) on Aug 24, 2003 at 05:08 UTC |