FAQ

2009/10/9 Soham Das <sohamdas@yahoo.co.in>:
When I compile this, it gives me an error like this:

Can't modify constant item in scalar assignment at Test.pl line 18, near "}";

So for the sake of clarity I highlited the Line 18.

'Action'=$trades->{'Action'},

A bit of help in this, will be great!
When perl gives you a line number, it's usually best to check the
whole statement for errors, not just the line that it gives you; in
this case the statement (from $dailytrade to the next semicolon ; ) is
six lines long.

The error message tells you that you can't modify a constant. It also
mentions an assignment. Here's the full statement:
$dailytrade->{$trades->{'Scrip'}}={
'Action'=$trades->{'Action'},
'Scrip'= $trades->{'Scrip'},
'Shares'= $trades->{'Shares'},
'Price'=($trades->{'Price'})*1.00845,
};
Looking at line 18 again:
'Action'=$trades->{'Action'},
Aha! You have an assignment (an = sign) which is trying to assign to
'Action', a string constant. The error message was right! The solution
is that you should have used a fat comma (a => sign) instead:
'Action'=>$trades->{'Action'},
This is the syntax used to create hash initialisers. If this confuses
you, I suggest you read perldoc perldata, section "List value
constructors". (If this confuses you too, then we need to have a chat
about perldoc :) )

Going back to the original statement:
$dailytrade->{$trades->{'Scrip'}}={
'Action'=$trades->{'Action'},
'Scrip'= $trades->{'Scrip'},
'Shares'= $trades->{'Shares'},
'Price'=($trades->{'Price'})*1.00845,
};
You've made the same mistake in lines 19, 20 and 21. You should now be
able to fix your code.

Philip

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 8 of 10 | next ›
Discussion Overview
groupbeginners @
categoriesperl
postedOct 9, '09 at 5:14a
activeOct 9, '09 at 12:09p
posts10
users5
websiteperl.org

People

Translate

site design / logo © 2021 Grokbase