in reply to NEWBIE Brain Teaser #2, by nysus
The reason I assumed this, was because I thought that @_ = qw(alpha, omega); assigned the values "alpha" and "omega" to an array called "_". While, $_ = qw(nothing, nothing); ends up assigning the value "nothing" to a scalar variable called "_". Which I think is related somehow to the manner in which we call the array "_". Hmm, perhaps we are actually altering something with the array by assigning a value to the $_ variable? I've just started learning perl and I seem to remember reading something about that.
Part C What happens when you replace "subroutine ();" in line 7 with "&subroutine;"? Why?
Well, I had to go look it up, because quite frankly I had no clue whatsoever. However, it appears that by placing an '&' in front of the "subroutine ();" call is really no different than not putting it in front because of the fact that the '&' prefix is considered to be optional. According to the second edition of the camel book, on page 114, it seems that when one names a subroutine, or if one is attempting to get a reference to a subroutine, or if one wishes to "do an indirect subroutine call with a subroutine name or reference using the &$subref() or &{$subref}() constructs..." then the '&' is not optional.
Another Question: When I attempted to add "-w" and then correct the "Use of uninitialized value in concatenation (.) at brain2.pl line 10." I think I realized that in fact we are using something that really isn't a variable or an array. So um.. I thought maybe @_ and $_ are actualling something else, so that is when I decided to go to the index of my trusty Camel II book. I think I realize where I went wrong and it is related to the error I recieved when I added "-w". Apparently $_ and @_ are actually global variables. But my question is, what exactly are they? Are they the arguments that are passed in when I run the script?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: NEWBIE Brain Teaser #2, by nysus
by nysus (Parson) on Apr 16, 2001 at 01:28 UTC | |
by Ri-Del (Friar) on Apr 16, 2001 at 01:59 UTC | |
by nysus (Parson) on Apr 16, 2001 at 02:24 UTC | |
by yakko (Friar) on Apr 16, 2001 at 06:33 UTC | |
by nysus (Parson) on Apr 16, 2001 at 06:47 UTC | |
Re: Re: NEWBIE Brain Teaser #2, by nysus
by nysus (Parson) on Apr 16, 2001 at 01:38 UTC | |
Re: Re: NEWBIE Brain Teaser #2, by nysus
by nysus (Parson) on Apr 16, 2001 at 01:55 UTC |