Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Can't clone STD handle with :via layer

by frozenwithjoy (Priest)
on Apr 08, 2014 at 13:53 UTC ( [id://1081509]=note: print w/replies, xml ) Need Help??


in reply to Can't clone STD handle with :via layer

Hi there. I have two suggestions:

(1) Why are you trying to open a filehandle to STDOUT? Why not just print?

For example, this:

#!/usr/bin/env perl use strict; use warnings; use PerlIO::via::QuotedPrint; binmode STDOUT, ':via(QuotedPrint)'; print " ";

Prints this:

=20=

(2) If you actually need to use STDOUT as a filehandle, an alternative that gives the same output as above is this:

binmode STDOUT, ':via(QuotedPrint)'; my $fh = \*STDOUT; print $fh " ";

Replies are listed 'Best First'.
Re^2: Can't clone STD handle with :via layer
by zdm (Beadle) on Apr 08, 2014 at 14:56 UTC

    As i correctly understand '>&' - is standard technique to clone handle.

    I use Capture::Tiny, which clone all STD handles on each call. Probably other CPAN code may use handle cloning too. So i wish to understand, why cloning with :via layer not working.

    Maybe something missing in PerlIO::via::QuotedPrint - which prevents cloning normally?

      It's nothing specific to PerlIO::via::QuotedPrint; it seems to happen with all PerlIO::via::* modules, but not with built-in layers like :unix, :utf8, or :encoding(iso-8859-1).

      Update: indeed, the error message is generated within PerlIO::via. Here's the relevant code.

      use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
        Maybe it makes a sense to create issue in perl rt?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 21:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found