Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Dereference a reference to a file handle created with IO::File

by Fletch (Bishop)
on Oct 28, 2020 at 02:08 UTC ( [id://11123244]=note: print w/replies, xml ) Need Help??


in reply to Dereference a reference to a file handle created with IO::File

Not 100% sure this is your issue but if you use anything in the indirect object / filehandle argument "slot" to print other than a simple scalar variable (edit: or a plain bareword, of course) you're going to need to wrap it in a block like print { $ads{ $this_ad} } "blah blah";. I'm surprised that it's even parsing and not throwing a syntax error the way you've got it now (samples w/5.32.0 on OS X).

$ perl -MO=Deparse,-p,-q -E 'print $ads{$this_ad} "$line\n";' String found where operator expected at -e line 1, near "} "$line\n"" (Missing operator before "$line\n"?) syntax error at -e line 1, near "} "$line\n"" -e had compilation errors. $ perl -MO=Deparse,-p,-q -E 'print { $ads{$this_ad} } "$line\n";' use feature 'current_sub', 'bitwise', 'evalbytes', 'fc', 'postderef_qq +', 'say', 'state', 'switch', 'unicode_strings', 'unicode_eval'; print({$ads{$this_ad};} ($line . "\n")); -e syntax OK

Afterthought: you also could call the print method on your handle as an alternative: $ads{$this_ad}->print( "blah" )

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^2: Dereference a reference to a file handle created with IO::File
by dgdriscoll (Initiate) on Oct 28, 2020 at 18:43 UTC

    Thank you very much. I chose your second suggestion, calling a method on the handle as being both shorter and, to me at least, clearer. There is something about nested {}'s when the inner and outer set do different things that is challenging for someone who gets into Perl once every couple of years or so. If there is any performance differential, it won't matter in my case. Thanks again, Dave Driscoll

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-04-25 03:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found