Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: what is the return value

by Skeeve (Vicar)
on Jul 09, 2013 at 13:49 UTC ( #1043318=note: print w/ replies, xml ) Need Help??

in reply to what is the return value

That code won't work.

Put "use strict; use warnings;" in

use strict; use warnings; sub firstline { open (my $in, shift) && return scalar <$in>; # no close() required } print firstline("/etc/hosts");
and you'll get:
Global symbol "$in" requires explicit package name at lin +e 4. Execution of aborted due to compilation errors.
If you don't use strict/warnings, you'll simply get an empty line.

Update: Removed the "; 1 " which I putted in to make the code at least print out something.


Comment on Re: what is the return value
Select or Download Code
Replies are listed 'Best First'.
Re^2: what is the return value
by choroba (Canon) on Jul 09, 2013 at 13:52 UTC
    Works for me.
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Maybe different perl version?
      $ perl -v This is perl 5, version 14, subversion 2 (v5.14.2) built for cygwin-th +read-multi-64int (with 7 registered patches, see perl -V for more detail) Copyright 1987-2011, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at, the Perl Home Pa +ge.

        No, the update was the reason.
        لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2015-11-28 13:29 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (742 votes), past polls