Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: tripping over filehandle / subroutine usage

by roboticus (Chancellor)
on Dec 21, 2012 at 21:04 UTC ( #1009960=note: print w/replies, xml ) Need Help??

in reply to tripping over filehandle / subroutine usage


What you want to do should work. But you don't show the code that's failing, so I can't tell you why it fails. But I do it often enough.

$ perl $ cat out.txt bob $ cat #!/usr/bin/perl use strict; use warnings; foo("bob"); sub foo { my $txt = shift; open my $FH, '>', 'out.txt' or die $!; bar($FH, $txt); } sub bar { my ($FH, $msg) = @_; baz($FH, $msg); } sub baz { my ($FH, $message) = @_; print $FH $message; }


When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^2: tripping over filehandle / subroutine usage
by LanX (Chancellor) on Dec 21, 2012 at 21:09 UTC
    normally I avoid typing lexicals $filehandles in uppercase.

    To much risk to confuse them with bareword FILEHANDLES...

    Cheers Rolf

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (14)
As of 2016-10-28 13:29 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (383 votes). Check out past polls.