Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
"be consistent"
 
PerlMonks  

Re: Use of Constants

by 2teez (Chaplain)
on Jul 24, 2012 at 20:48 UTC ( #983518=note: print w/ replies, xml ) Need Help??


in reply to Use of Constants

Hi,

Instead of use constant, why don't you try use Readonly like so:

#! /usr/bin/perl use Readonly; Readonly my $vars => { X => 20, Y => 20 }; Readonly my $eq => [ 2 * Y, -2 * X * Y ]; $x = $vars->{X}; $y = $vars->{Y}; print "Val of \$x is $x \n"; # print 20 print "Val of \$y is $y \n"; # print 20 $temp = $eq->[0]; print "$temp \n"; # print 0 print $eq->[1] . "\n"; print 0
However, to get desired print out for both
print "$temp \n"; # and print $eq->[1] . "\n";
You could could have:
Readonly my $eq => [ 2 * $vars->{Y}, -2 * $vars->{X} * $vars->{Y} ]; ### instead of Readonly my $eq => [ 2 * Y, -2 * X * Y ];
Then you have:
print "$temp \n"; ## prints 40 # and print $eq->[1] . "\n"; ## prints -800


Comment on Re: Use of Constants
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2013-05-18 20:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (395 votes), past polls