Alternatives to eval
Ooops, I forgot to use plain text when I sent this the first time. Sorry
if this appears twice.
I want read some variable names and values out of a flat (xml) file and
assign them.
I suppose I could write
$s =3D "$x =3D 23";
eval $s;
Is this the best way? Is there a better way? In lisp, I would use the
set function instead of the setq function to assign a value to a
variable whose name is stored in a string. Is there a counterpart to the
lisp set function in Perl?
Siegfried
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Alternatives to eval
2011/4/26 <siegfried [at] heintze.com>:
>
>
> $s = "$x = 23";
> eval $s;
>
>
eval a string is considered a bad way.
You may store and read the variables to and from a pure Perl data
structure storage, like Tie::Hash.
Regards.
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: Alternatives to eval
On 11-04-25 09:20 PM, siegfried [at] heintze.com wrote:
> Is there a counterpart to the
> lisp set function in Perl?
Not really. Consider using a hash instead.
$hash{x} = 23;
To view your data structures, use Data::Dumper;
use Data::Dumper;
print Dumper( \%hash );
Data::Dumper is a standard module that comes with Perl. To see a list
of all the standard pragmatics and modules:
perldoc perlmodlib
--
Just my 0.00000002 million dollars worth,
Shawn
Confusion is the first step of understanding.
Programming is as much about organization and communication
as it is about coding.
The secret to great software: Fail early & often.
Eliminate software piracy: use only FLOSS.
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/