ChOas has asked for the wisdom of the Perl Monks concerning the following question:
This results from a discussion in the chatterbox
Please help me on this one, can someone explain to
me the result of the following code:
Result:
martijn@xxxx$ ./test
one two three
nope
one two three four
yep
four one two three
nope
Strange innit ?
Please help me on this one, can someone explain to
me the result of the following code:
#!/usr/bin/perl -w use strict; my @keys = qw(one two three); my %hash = ( four => 4, five => 5, six => 6); print "@keys\n"; if (@hash{@keys}) { print "yep\n"; } else { print "nope\n"; } push @keys, 'four'; print "@keys\n"; if (@hash{@keys}) { print "yep\n"; } else { print "nope\n"; } @keys = qw(one two three); unshift @keys,'four'; print "@keys\n"; if (@hash{@keys}) { print "yep\n"; } else { print "nope\n"; }
Result:
martijn@xxxx$ ./test
one two three
nope
one two three four
yep
four one two three
nope
Strange innit ?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Hash slices ?
by kilinrax (Deacon) on Dec 01, 2000 at 17:30 UTC | |
by snax (Hermit) on Dec 01, 2000 at 17:45 UTC | |
by davorg (Chancellor) on Dec 01, 2000 at 17:53 UTC | |
by snax (Hermit) on Dec 01, 2000 at 18:03 UTC | |
by ChOas (Curate) on Dec 01, 2000 at 18:09 UTC | |
by merlyn (Sage) on Dec 01, 2000 at 20:14 UTC | |
by tye (Sage) on Dec 02, 2000 at 06:48 UTC | |
by tilly (Archbishop) on Apr 13, 2001 at 18:43 UTC | |
| |
by snax (Hermit) on Dec 01, 2000 at 21:24 UTC | |
by Russ (Deacon) on Dec 01, 2000 at 21:41 UTC | |
Re: Hash slices ?
by ChOas (Curate) on Dec 01, 2000 at 15:38 UTC | |
by arturo (Vicar) on Dec 01, 2000 at 18:58 UTC | |
by davorg (Chancellor) on Dec 01, 2000 at 19:06 UTC |
Back to
Seekers of Perl Wisdom