Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: how do i put an equasion in a variable

by cwest (Friar)
on Jun 29, 2000 at 23:06 UTC ( #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? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2023-02-07 08:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (38 votes). Check out past polls.

    Notices?