darren at u.washington.edu
Thu Apr 13 17:07:57 CDT 2000
Dan Ebert, in an immanent manifestation of deity, wrote:
>I though that it would give the number of elements in an array, but ...
>I have some code that creates a nested array:
>$record = $var1a;
>$record = $var1b
>$record = $var322a;
>$record = $var322b;
>When I do a "scalar(@record)" it gives me 323 ... when I expected to get 221
>(322 minus 101). It is OK, because my goal was to arrive at the value that
>'scalar(@record)' returned anyway, but it wasn't what I expected.
It does give you the number of elements in the array. You have 101
elements from $record to $record that are set to undef.
Note that it gives you the number of elements once removed. It forces
the array into a scalar context. Any array in scalar context will yield
the number of elements in the array.
This means that the following give identical answers:
$num_recs = @record;
<torin at daft.com> <http://www.daft.com/~torin> <torin at debian.org> <torin at io.com>
Darren Stalder/2608 Second Ave, @282/Seattle, WA 98121-1212/USA/+1-800-921-4996
@ Sysadmin, webweaver, postmaster for hire. C/Perl/CGI/Pilot programmer/tutor @
@ Make a little hot-tub in your soul. @
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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