--- Brian <[EMAIL PROTECTED]> wrote:
> #1 How can I tell the upper boundary limit of the array (IE, Max Entries)
If I understand your question correctly, in Perl, there really aren't "upper
boundaries" to
arrays. Those are more dependant on how much memory your system has :) If you're
using 20
elements in an array and then suddenly use element 30, the intervening elements are
automatically
created for you (and the intervening elements will have 'undef' values).
> #2 if I have an array: @item ... how can I see just the 5th element?
> something like: print @item[5]; ?? Would that work?
Perl arrays typically start with 0 as the first element. You can change this by
setting the $[
variable, but this is deprecated: don't do it!
To access the 5th element of an array, you would do something like
print $item[4];
Do not use the @ symbol when printing out a single array element as the @ symbol will
suggest that
you are trying to use an array slice and a one-element slice is almost never what you
want (a
slice is merely a selection of any number of elements from a list, array, or hash --
usually more
than one element):
print $item[4]; # good
print @item[4]; # bad
If you have warnings enabled, Perl will complain about the second statement, but it
will *usually*
do the right thing. However, since Perl views @item[4] as a one-element slice, it's
important to
remember that this can affect the outcome of your program. Here's a little snippet
that will show
you how a 'wantarry' in a sub can return bad input:
use strict;
use warnings;
use Data::Dumper;
my @item = qw/ one two /;
$item[0] = getstuff();
@item[1] = getstuff();
print Dumper \@item;
sub getstuff {
my @newarray = qw/ 1 2 3 4 5 /;
return wantarray ? 'bad' : 'good';
}
Run that snippet and study the output.
Cheers,
Curtis "Ovid" Poe
=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/
__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]