in reply to Use of Constants
Instead of use constant, why don't you try use Readonly like so:
However, to get desired print out for both#! /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
You could could have:print "$temp \n"; # and print $eq->[1] . "\n";
Then you have:Readonly my $eq => [ 2 * $vars->{Y}, -2 * $vars->{X} * $vars->{Y} ]; ### instead of Readonly my $eq => [ 2 * Y, -2 * X * Y ];
print "$temp \n"; ## prints 40 # and print $eq->[1] . "\n"; ## prints -800
|
|---|