Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: what is the return value

by The_Dj (Sexton)
on Jul 09, 2013 at 04:45 UTC ( #1043235=note: print w/replies, xml ) Need Help??


in reply to what is the return value

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1043235]
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: (1)
As of 2023-06-03 20:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (17 votes). Check out past polls.

    Notices?