Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^2: How to find out if an argument is an LVALUE ?

by harangzsolt33 (Chaplain)
on Nov 09, 2023 at 13:28 UTC ( [id://11155500]=note: print w/replies, xml ) Need Help??

in reply to Re: How to find out if an argument is an LVALUE ?
in thread How to find out if an argument is an LVALUE ? (TinyPerl)

Well, first of all, I think, I had the definition of an lvalue all mixed up. Now, it's getting clearer.

Secondly, I am unsure how you call a literal in a function call. When we pass a literal number, for example MODIFY(4), what do you call that?

Thirdly, I am using Windows XP again with TinyPerl 5.8 now. So, do you think, there was a significant change in how Perl creates these references between versions 5.8 and 5.38? Because it seems to me that we're getting different error messages. I only get the "modification of read-only value attempt" error when I uncomment the line MODIFY($_); in my code. In other words, directly trying to modify the literal is not working, but when I try to do it through a reference, TinyPerl 5.8 gets away with it without an error message. Lol

  • Comment on Re^2: How to find out if an argument is an LVALUE ?

Replies are listed 'Best First'.
Re^3: How to find out if an argument is an LVALUE ?
by soonix (Canon) on Nov 09, 2023 at 15:11 UTC
    When we pass a literal number, for example MODIFY(4), what do you call that?
    I call it "argument", just as any non-literal argument. The difference is subtly hinted at in perlsub:
    In a subroutine that does not use signatures, any arguments passed in show up in the array @_. Therefore, if you called a function with two arguments, those would be stored in $_[0] and $_[1]. The array @_ is a local array, but its elements are aliases for the actual scalar parameters. In particular, if an element $_[0] is updated, the corresponding argument is updated (or an error occurs if it is not updatable).
    Maybe your original question stems from this, as "updatable" is more or less the same as "lvalue"?
Re^3: How to find out if an argument is an LVALUE ?
by jo37 (Deacon) on Nov 09, 2023 at 14:16 UTC

    Maybe you found a bug in (Tiny)Perl 5.8.0. It's a bit too late for a bugreport, I'm afraid.


Re^3: How to find out if an argument is an LVALUE ?
by NERDVANA (Deacon) on Nov 10, 2023 at 03:03 UTC
    Do you mean this?
    $ perl -E 'sub foo { $_[0]= 5 } foo(4)' Modification of a read-only value attempted at -e line 1.

    I would call '4' a "constant", though it appears perl calls it a "read-only value". You can find out whether one of your parameters is readonly like this:

    use Scalar::Util "readonly"; sub foo { printf "%s\n", readonly($_[0])? "readonly" : "writable"; $_[0]= 5 if !readonly($_[0]) } foo(4); foo(my $x= 4); print "$x\n";

    Maybe tinyperl's errors are different. If you had an error somewhere like "Can't use a constant as an LVALUE" I can see where that might have been confusing, but LVALUE is referring to "a thing which can be assigned-to", and that error would be saying basically that you can't use a read-only or constant on the left side of an equal sign.

Re^3: How to find out if an argument is an LVALUE ?
by Bod (Parson) on Nov 09, 2023 at 14:00 UTC
    Thirdly, I am using Windows XP again with TinyPerl 5.8 now

    I have a feeling that I am going to regret asking...but I am rather intrigued...

    Why are you using an OS that was retired over a decade ago and what are you using a Perl version from two decades ago?

    Do you drive an Austin Allegro by any chance???

      No, I don't drive an Austin Allegro. Haha I drive a minivan. I use Windows XP, because it's small and fast and gets the job done. And it's just perfect for my needs. When I was about 12 years old, my parents bought me my first computer. It was a 386DX 40MHz with 128MB HDD and 4MB RAM. It had MS-DOS 5.00 on it. I had a friend named Simon Istvan who is a computer programmer who gave me lessons every week. And he taught me C/C++, assembly, HTML, and he also tried to introduce me to Linux and Perl, but at that time I did not have any interest in Perl. Linux is something I found very interesting, and I loved it. But it never really stuck with me. I was always a DOS/Windows primary user. Linux is something I used just for fun or in case of emergencies.

      (Unlike most people, I think playing computer games is a total waste of time. There were only three games I liked -- chess, SimCity, and Sokoban. But I found none of them addictive. Like I could start and stop an hour later and never play again. In fact, I haven't played computer games in I don't know how many years. I just don't find it fulfilling or fun. I think, computer programming is a lot more fun, because you CREATE something real, something useful, something that makes the world a better place. So, I see computer programming as a way to improve the world. Games are just a waste of life.)

      So, I have always been very interested in computer programming. When I was 17 years old, I began building computers and troubleshooting Windows problems, and people would call me almost every week to look at their computer. And I became known as a guru of some sort. And this went on for about a decade. In 2010, I created a computer business. Now I do data recovery, virus removal, Windows/Linux installation, website maintenance, and I refurbish old computers. But the amount of money that comes in through this business is so little that it's barely enough to buy chicken feed for my chickens! I have 24 chickens. LOL So, I do other things like construction... In 2000, I learned JavaScript by myself at home. Over the years, I came to love JavaScript. And in 2016, I began to learn Perl, and I realized how similar the two languages are. They are like brothers!

      So, anyway, Windows XP stuck with me, because I have used it for so many years. I like the way it looks. I know how it works. There are certain things that it can do that I don't know how to do with other operating systems. I also know XP's limitations, so if I know it can't do a certain thing that I need, then I switch over to Linux or I have Windows 10 on another computer here, and I'll use that. So, I'm okay. But for most things, I use XP. Yesterday I opened a text file on my computer which I created over a decade ago. It's a file where I wrote down all the things I love to do and what makes me happy. One of the items on the list said, "I love using Windows XP." Interestingly, all the things listed in there are still true today! I still love to raise chickens. And I love to write programs. etc... I didn't change much at all. :)

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-19 18:44 GMT
Find Nodes?
    Voting Booth?

    No recent polls found