Uri Guttman wrote:
only for ++/-- and +=/-= will that work with no warnings. if he uses an
undef value in another arithmetic expression it will warn.

Also, undef values work in if/unless and while/until conditions.

Usually when you see indexes used with arrays, it is because the programmer does know of all the tools available for manipulating lists. 99.97% of the time, indexes are not needed. But if you must insist on initializing the array, it's better to use the ||= assignment to indicated that zero is the default value, even if the array hasn't been used before.

$a[$_] ||= 0 for 0 .. 125;

One of the common patterns in Perl is using || for defaults.

$var ||= $default;

or

$var = expr || $default;

You should use common patterns where possible so that your code will be easier to understand.


--
Just my 0.00000002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to