przemo has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
One way of making scalar read-only is to assign to glob the reference to constant scalar, e.g.
*PI = \3.14;
However, I have a problem with constructing read-only strings. If
*NAME = \"My name";
is marked read-only,
*NAME2 = \"My $name";
isn't.
Bigger snippet:
$bar = 'bar'; # This prints 'bar' *foo = \"The $bar is here"; $foo = "bar"; print "$foo\n"; # This dies *foo = \"The bar is here"; $foo = "bar2"; # error here print "$foo\n";
My question is: how to make "non-constant" strings (e.g. variables) become constant ones? Neither concatenation with '.', nor variable embedding in string works for me.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Constant string reference
by diotalevi (Canon) on Dec 09, 2004 at 12:58 UTC | |
by dave_the_m (Monsignor) on Dec 09, 2004 at 14:03 UTC | |
by diotalevi (Canon) on Dec 09, 2004 at 14:50 UTC | |
by dave_the_m (Monsignor) on Dec 09, 2004 at 15:15 UTC | |
by diotalevi (Canon) on Dec 09, 2004 at 15:17 UTC | |
| |
|
Re: Constant string reference
by reneeb (Chaplain) on Dec 09, 2004 at 12:48 UTC | |
by przemo (Scribe) on Dec 09, 2004 at 13:00 UTC | |
|
Re: Constant string reference
by gellyfish (Monsignor) on Dec 09, 2004 at 12:56 UTC | |
by Fletch (Bishop) on Dec 09, 2004 at 13:03 UTC | |
|
Re: Constant string reference
by przemo (Scribe) on Sep 18, 2009 at 10:07 UTC |