http://www.perlmonks.org?node_id=1009960


in reply to tripping over filehandle / subroutine usage

chexmix:

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 t.pl $ cat out.txt bob $ cat t.pl #!/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; }

...roboticus

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 (Saint) 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