leocharre has asked for the wisdom of the Perl Monks concerning the following question:
Some functions set the $! error code, like
open(FILE,"</this/file") or die($!);
How would I get my own sub to populate '$!'? Is it any printing to STDERR that ends up in '$!'- no.. right? (I searched the docs but this is throwing me off) Is the special variable '$!' only set by C libraries or something spooky like that?
How would I get the following to work? (uncommenting the line doesn't do what I would like).
for(qw(1 4 haha)){ usenumbers($_) or die($!); } sub usenumbers { my $var = shift; $var=~/^\d+$/ or # ( $! = 'these were not digits' ) and return; print "Yes, [$var] has numbers."; return 1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I return false and set an error in special variable $!
by RMGir (Prior) on May 17, 2007 at 17:48 UTC | |
|
Re: How do I return false and set an error in special variable $!
by ikegami (Patriarch) on May 17, 2007 at 17:54 UTC | |
|
Re: How do I return false and set an error in special variable $!
by eric256 (Parson) on May 17, 2007 at 18:10 UTC | |
|
Re: How do I return false and set an error in special variable $!
by kyle (Abbot) on May 17, 2007 at 17:55 UTC | |
|
Re: How do I return false and set an error in special variable $!
by naikonta (Curate) on May 18, 2007 at 02:14 UTC |