Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: how do i put an equasion in a variable

by cwest (Friar)
on Jun 29, 2000 at 23:06 UTC ( [id://20469]=note: print w/replies, xml ) Need Help??


in reply to how do i put an equasion in a variable, one which is evaluated at the time of use?

my $array = [ 5, 5 ]; $array->[2] = sub { $array->[0] * $array->[1] }; print &{$array->[2]}; # 25 $array->[1] = 10; print &{$array->[2]}; # 50
Is this good enough?

Update: You could also use eval:

$array->[2] = '$array->[0] * $array->[1]'; print eval $array->[2];
--
Casey

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://20469]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-03-28 23:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found