Philip, 

I think, the way you went about solving the problem {might be very trivial for 
you}, but laying bare your entire thought process, just taught something to me. 

Thanks and I am sure, many other beginners have picked it up from here. 

Yes,indeed after you pointed out to me, I (figuratively) kicked myself.

Thanks 

Soham




________________________________
From: Philip Potter <philip.g.pot...@gmail.com>
To: Soham Das <soham...@yahoo.co.in>
Cc: beginners@perl.org
Sent: Fri, 9 October, 2009 2:22:49 PM
Subject: Re: Building a record on the fly via hash of hashes

2009/10/9 Soham Das <soham...@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

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


      From cricket scores to your friends. Try the Yahoo! India Homepage! 
http://in.yahoo.com/trynew

Reply via email to