Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Instructions for Newbies:
Part A
What do you think the output of the code below is?

I figured that the result would be "In the beginning there
was nothing, in the end there will be nothing."

Part B
Give an accurate explanation for your answer.

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?


In reply to Re: NEWBIE Brain Teaser #2, by nysus by Ri-Del
in thread NEWBIE Brain Teaser #2, by nysus by nysus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-19 22:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found