[thelist] Perl references
shawn allen
shawn at alterior.net
Wed Feb 19 13:13:01 CST 2003
quoth Beam:
> > I suspect that it's my failure to grasp referencing implementation
> > in Perl, but I would appreciate *any* help here...
>
> rule #1: put the "-w" flag at the end of the #! line on every perl
> script you write.
> rule #2: put 'use strict' at the top of every perl script
Great advice.
> for ($i = 0; $i < $#week; $i++) { # $#arrname gives the index value
`$#week' will actually give you the value of the list's last index,
which is *one less than* the total number of elements in a 0-based list.
Example:
#!/usr/bin/perl
@week = qw(foo bar baz);
printf("\%d\n", $#week);
This prints 2. Either use the <= operator in your for loop, or use
`scalar @week' instead. :)
--
shawn allen
mailto://shawn@alterior.net
phone://415.577.3961
http://alterior.net
aim://shawnpallen
More information about the thelist
mailing list