in reply to Mini-Tutorial: Scalar vs List Assignment Operator
So, ok, maybe the code shouldn't die when called in a list context :-/ But it demonstrates how you might use it.sub pedantic_syswrite { my $context=wantarray; if (defined ($context)) { if ($context) { # caller wants an array, which is (mostly) silly f +or write die "write doesn't return an array, silly!\n"; } else { # scalar context # no warning, because user should always check return value syswrite @_; } } else { # void context die "I'm not going to write if you don't check my return value\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Mini-Tutorial: Scalar vs List Assignment Operator
by ikegami (Patriarch) on Aug 21, 2009 at 03:15 UTC | |
by dec (Beadle) on Aug 21, 2009 at 12:35 UTC | |
by ikegami (Patriarch) on Aug 21, 2009 at 13:29 UTC | |
by dec (Beadle) on Aug 22, 2009 at 01:35 UTC | |
by dec (Beadle) on Aug 22, 2009 at 01:23 UTC | |
by ikegami (Patriarch) on Aug 22, 2009 at 03:46 UTC |