in reply to So what is an array slice anyway?
Next, understand that an array (or hash) slice is simply a list (see here for one discussion). In other words, writing @foo[1,2] is like writing ($foo[1], $foo[2]) explicitly. Yes, it's a bit confusing because the @ sigil is reminiscent of an array...#!/usr/bin/perl -l ## list: print scalar (4,5,6,7); ## 7 ## array: my @foo = (4,5,6,7); print scalar @foo; ## 4
Now you can see why the array slices didn't compare with == like you thought. The == operator imposes scalar context, which causes the slices to return their last element and the arrays to return their size. If it helps, scatter some print scalar @foo[0,1] statements around to see what numbers really are being compared with == in those conditionals.
blokhead
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: So what is an array slice anyway?
by revdiablo (Prior) on Aug 26, 2004 at 05:37 UTC | |
|
Re^2: So what is an array slice anyway?
by beable (Friar) on Aug 26, 2004 at 04:42 UTC | |
by revdiablo (Prior) on Aug 26, 2004 at 05:49 UTC |