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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.