lundi 24 février 2014

Re: use strict; use warnings; topic




Marek Novotny <(E-Mail Removed)> writes:

>
> When I started to try to use the use strict and warnings, I got warnings
> such as: Scalar value @diamonds[$i] better written as $diamonds[$i] at ./
> obj10.pl line 55.
>
> But the whole point of what I am doing is loading elements into an
> array... So I wanted it as @diamonds, not $diamonds, and so on.
>

Yeah, this is a common mistake.

Single elements of an @array are scalars themselves, so they are
addressed as $elem[$index]. The @array[$number] syntax is used to take a
*slice* of an array. This might work (it usually does), but can cause
hard to find bugs.

Mart





Aucun commentaire:

Enregistrer un commentaire