[Perl] Que faire contre ce « warning » ?
Philippe Bruhat (BooK)
philippe.bruhat at free.fr
Lun 16 Jan 02:54:11 CET 2017
On Sat, Jan 14, 2017 at 10:44:05AM +0000, Yon wrote:
> Si tu rajoutes:
>
> use diagnostics;
>
> au début du fichier, tu obtiens plus de détails :
>
> (W misc) In a conditional expression, you used <HANDLE>, <*> (glob),
> each(), or readdir() as a boolean value. Each of these constructs
> can return a value of "0"; that would make the conditional expression
> false, which is probably not what you intended. When using these
> constructs in conditional expressions, test their values with the
> defined operator.
>
Sans modifier son programme, on peut aussi juste copier le message
(simulé ici avec `echo`) dans `splain`
$ echo 'Value of <HANDLE> construct can be "0"; test with defined() at ./truc.pl line 11.' | splain
Value of <HANDLE> construct can be "0"; test with defined() at ./truc.pl line
11 (#1)
(W misc) In a conditional expression, you used <HANDLE>, <*> (glob),
each(), or readdir() as a boolean value. Each of these constructs
can return a value of "0"; that would make the conditional expression
false, which is probably not what you intended. When using these
constructs in conditional expressions, test their values with the
defined operator.
Maintenant que j'ai lu la doc de splain/diagnostics.pm, je peux aussi vous
livrer cette petite perle qui s'y trouve:
If you don't want to modify your source code, but still have on-the-fly
warnings, do this:
exec 3>&1; perl -w test.pl 2>&1 1>&3 3>&- | splain 1>&2 3>&-
Nifty, eh?
--
Philippe Bruhat (BooK)
Eliminate a problem before it eliminates you!
(Moral from Groo The Wanderer #65 (Epic))
Plus d'informations sur la liste de diffusion Perl