dimanche 23 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.


In Perl, the tenth element of array @something is $something[10]. So the
warnings are correct — you should write $diamonds[$i] instead of
@diamonds[$i].

Another problem is that you declare the $i variable multiple times. You
should only declare it once, the first time you use it. You can also
refactor

my $i = 0;
while ($i < 13){
$spades[$i] = shift(@startingdeck);
$i++;
}

to

for (my $i = 0 ; $i < 13 ; $i++) {
$spades[$i] = shift(@startingdeck);
}

Finally, there are several undeclared variables (@hearts, @diamonds,
@spades, @clubs, @sorted, $ace).

After fixing these three problems the code should run without warnings
under use strict; use warnings;
--
Marius Gavrilescu

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBCgAGBQJTCuiSAAoJEMoENb5ewbNiiHEP/jwwTB6zhIUmT28HW1uzsIWF
iwdYvfStkWhMnGuT5O2ZEkEMFIiepFy1PW9/eFzvT0fC6b3fVIAr4AruBQf67Zh/
k5Spkn+Sd+OweUbGJ3lRRaEow4iwPHXTVAfy0O+3qdZaRhXyJn x/dtx363fqjUPo
VyxUHkT6iK/HBD0fqz+GNxT/2c0S1Pi7YED1xr7FbhJ9iO63lDFXlkOw+Woacyv4
gZsw8LEekOZu08AD5ggeMhFNr8SrWsvY59ux5QdU/319/3UoAXiK+VVK6mXy9rvO
2n5GBuPBqAvrgkWmI9cZb9VWuqANSpjz65+z29i9gdRvFa2IJb le4scpmtdDSlpw
/w3VobCmuzVBSerSpiXQVQZBavuJ87DIYamDrzdGgThqgSzg9Md GhCbo6EIb7gOm
i5Ph19hdlB7p2RuNITr3X/noYJzEzhOTKYURuuEF92ehMhEVxdh76+YbeDn9jZDO
+ltZ2l1eBRYT4IzIo9KMAq2jyH6ZM+Ah0e2CVPHL3GObiCrGdI iiBYFS2sPBxF85
qpMl3NjI7Ia7J/dIJKpazylV+PtWhxjAM5MA1I9bSpEO3srdQ9sUPXfGwXYRjRUY
uIO+IPOVF0s4bhtwxISY1E1ED2LlhSt+eoh+zQwe7RPRY2r8zx GkLQZO00TPNji2
BQuT1PBMa9MMhChfxSVN
=coba
-----END PGP SIGNATURE-----





Aucun commentaire:

Enregistrer un commentaire