Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Firstly, it's broken. The # marks a comment, so the closing } will be ignored and break the code. Looking at:
1 sub firstline { 2 open( my $in, shift ) 3 && return 4 scalar <$in>; 5 # no close() required 6 }
line 1: starting a new sub called 'firstline'
Line 2: (from right to left)
    shift: gets the first parameter passed to the sub
    $in: is just a variable
    my $in: says $in only exists in this sub
    open: open a file. In this case the file name is the first parameter to the sub, and $in becomes the handle
line 3: &&: A logical-and ensure that if the file open fails, the next command will be skipped.
    return: return the following data
line 4: scalar: tells perl to think of the next 'thing' as a single line of text.
    <$in>: read from the file handle. Combined with the 'scalar' instruction will get just one line.
line 5: a comment noting that the file is automatically closed when the $in filehandle 'dissapears' at the end of the sub.
line 6: ending the sub.

So.. Line 2 opens a file. Line 4 gets a single line of text and Line 3 returns that single line.

Try reading http://perldoc.perl.org/perlopentut.html and other tutorials.

In reply to Re: what is the return value by The_Dj
in thread what is the return value by arasumg

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 chilling in the Monastery: (5)
As of 2024-03-28 08:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found