in reply to Prototype for constant items???
I can't see what's confusing you about \"1" resulting in a SCALAR - I remember reading somewhere, I think it's in one of the O'Reillys, but senility and alcohol together combine to prevent me from remembering exactly where, that a primitive means of constructing a constant relies on this - using idioms of the form:
Soooo, AFAICT, pre-declaring the literal as a constant solves your problem...*PI = \3.14159; *STR = \'Some string'; # etc.
Givinguse warnings; use strict; no strict qw/vars/; *STR = \'Some string'; my ($str1, $str2) = (\'Some string', $STR); sub foo(\$) { return } eval { foo($STR) }; warn "$@"; eval { foo($str1) }; warn "$@"; eval { foo($str2) }; warn "$@";
Doesn't it ?$ perl tst.pl Warning: something's wrong at tst.pl line 10. Warning: something's wrong at tst.pl line 12. Warning: something's wrong at tst.pl line 14.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Prototype for constant items???
by LanX (Saint) on Sep 25, 2009 at 13:39 UTC | |
by SuicideJunkie (Vicar) on Sep 25, 2009 at 14:40 UTC | |
by LanX (Saint) on Sep 25, 2009 at 14:55 UTC | |
by SuicideJunkie (Vicar) on Sep 25, 2009 at 16:34 UTC | |
by LanX (Saint) on Sep 26, 2009 at 00:48 UTC | |
| |
by Porculus (Hermit) on Sep 26, 2009 at 17:37 UTC | |
by LanX (Saint) on Sep 26, 2009 at 20:17 UTC |