[prog] Perl code

Jacinta Richardson jarich at perltraining.com.au
Tue Feb 8 10:33:55 EST 2005


Noir wrote:
> Thanks for the help. I didn't know that Perl is so
> fussy about spacing.

Typically Perl isn't fussy about spacing.

    $names [ $_ - 1 ]

is usually the same as:

    $names[$_-1]

etc.

However when printing, Perl cannot tell the difference between:

    print "$names [normal text in literal square brackets]";

and

    print "$names [some index]";

so it assumes you mean the former.

Had you been using strict you would have got an error telling you that 
$names (the scalar) had not been predefined and thus you would have 
realised your error faster.

I find the inconvenience of having to write "my" before my variables is 
well worth the convenience of having strict point out this kind of silly 
typo.

all the best,

     Jacinta

-- 
    ("`-''-/").___..--''"`-._          |  Jacinta Richardson         |
     `6_ 6  )   `-.  (     ).`-.__.`)  |  Perl Training Australia    |
     (_Y_.)'  ._   )  `._ `. ``-..-'   |      +61 3 9354 6001        |
   _..`--'_..-_/  /--'_.' ,'           | contact at perltraining.com.au |
  (il),-''  (li),'  ((!.-'             |   www.perltraining.com.au   |




More information about the Programming mailing list