in reply to Syntax error when trying to use a hash value as a file stream specifier
Did you consider redirecting your default output with select rather than passing it as an argument?
UPDATE: I believe that the OP is passing a file-handle to a subroutine using the method that his reference (Cookbook recipe 10.7) calls 'Named Parameters'. Using this method, the file-handle is stored as a value in a hash. He as asking for the syntax to use that value in a print statement. AnomalousMonk has provided the answer. My suggestion to use select to pass the file-handle to the subroutine would work, but I no longer recommend it.
use strict; use warnings; myfunction1( handle => \*STDERR); sub myfunction1{ my %hash = ( handle => \*STDOUT, @_ ); print "something will happen\n"; print {$hash{handle}} "anything from myfunction1\n"; # ^ ^ # braces added here }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Syntax error when trying to use a hash value as a file stream specifier
by afoken (Chancellor) on Sep 03, 2022 at 10:47 UTC | |
by BillKSmith (Monsignor) on Sep 03, 2022 at 18:41 UTC | |
by choroba (Cardinal) on Sep 04, 2022 at 18:06 UTC |