Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Modification of a read-only value attempted

by panku (Initiate)
on Nov 27, 2012 at 13:34 UTC ( #1005857=note: print w/ replies, xml ) Need Help??


in reply to Re: Modification of a read-only value attempted
in thread Modification of a read-only value attempted

Thanks for the Reply. Please clarify one more doubt. 1.) $c=99; Here $c is var which is holding 99 as value. We can change $c here ? 2.) $c=\99; Here also $c is reference which is pointing to 99. So why we can't change $c=1000? Thanks in advance


Comment on Re^2: Modification of a read-only value attempted
Re^3: Modification of a read-only value attempted
by roboticus (Canon) on Nov 27, 2012 at 13:48 UTC

    panku:

    You can change $c=1000. What you can't do is change 99 to 1000. When you use $c=1000, it tells perl that $c is no longer pointing to a reference to the constant 99, but is now containing the value 1000. When you use $$c=1000, you're telling perl to change the thing $c points to to 1000. But $c points to the constant value 99. Perl is telling you that it refuses to break the time-space continuum by making 99 be 1000.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re^3: Modification of a read-only value attempted
by BrowserUk (Pope) on Nov 27, 2012 at 13:57 UTC
    So why we can't change $c=1000?

    As roboticus points out, you can make that change. That is, you can overwrite the value in $c -- currently the address of the constant 99 -- with any other value.

    What you cannot do is overwrite the value held at the address held in $c, because it is a constant.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    RIP Neil Armstrong

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2014-09-24 03:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (245 votes), past polls