From: "Dan Muey" <[EMAIL PROTECTED]>
> > Not sure this is what you are after but ...
> >
> > *x = \15;
> > print "\$x=$x\n";
> > $x = 16; # => Modification of a read-only value attempted at ...
> > print "\$x=$x\n";
> >
> > Jenda
>
> You're a genius!
No I'm not. I saw this somewhere in the docs.
> I'd love to understand further:
> - why using a glob like that makes it readonly
> - why you have to \15 instead 15 to assign it a value(is it to show
> it's a scalar?) - does this work with arrays/hashes/etc of *x? - how
> do assign something besides a nuber to $x? ( *x = \grabdata(); or *x
> = \"hi there";) - how do I assign somthign to @x or %x etc...
1)
*y = \$x;
changes $y into an alias to $x. From now it doesn't matter whether
you assign or read $y or $x, they'll both contain the same value.
2)
\15
creates a scalar reference to a constant. See:
print '\15 = ', \15, "\n";
3)
This means that
*x = \15;
changes $x into an alias of 15.
And just like you can't write
15 = 16;
you can't from now on write
$x = 16;
Now this only works for constants. The only way to set a readonly
variable based on the return of some function would be using eval"":
{ my $value = grabdata(parameters);
$value =~ s/([\\'])/\\$1/g;
eval "\*const = '$value'";
}
And it's not possible to make a constant array or hash this way.
AFAIK.
Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]