FAQ

On Wed Oct 17 17:13:08 2012, jgibson@perforce.com wrote:

This is a bug report for perl from jgibson@perforce.com,
generated with the help of perlbug 1.39 running under perl 5.16.1.


-----------------------------------------------------------------
[Please describe your issue here]

When overloading readpipe, the arguments it is passed are the literal
variable names in the source instead of the values of the variables.
I'd have expected string interpolation to applied before the
overloaded
function was called.
I have never had occasion to use the readpipe function, so I don't claim
to be able to provide an expert response. However, ....
Note that one semi-workaround is to use package variables ('our' vs
lexical 'my') and the String::Interpolate package. This mostly works.

#! /usr/bin/env perl

use feature ':5.16';
use strict;
use warnings FATAL => 'all';

sub _readpipe { say "overload argument: '@_'" }

BEGIN { *CORE::GLOBAL::readpipe = \&_readpipe }

my $cmd = 'uname';

# Prints : overload argument: '$cmd'
# Expected: overload argument: 'uname'

`$cmd`;
My hunch is that your problem has nothing to do with readpipe or with
overloading. Call: "perldoc -q backtick". The first response (from
perlfaq8) says [edited]:

#####
What's wrong with using backticks in a void context?

Strictly speaking, nothing. Stylistically speaking, it's not a good way
to write maintainable code. Perl has several operators for running
external commands. Backticks are one; they collect the output from the
command for use in your program. ...

Writing backticks in your program sends a clear message to the readers
of your code that you wanted to collect the output of the command. Why
send a clear message that isn't true?
#####

In the example provided, you are using backticks in a void context.
Hence, you are not *collecting* the output of the command inside the
backticks for re-use.

#####
$ perl -E '$cmd = q{uname};`$cmd`;$output = `$cmd`;say $output;'
Darwin
#####

I don't know whether the first `$cmd` *runs* uname or not. But it's
clear that the void context frustrates the point of backticks in Perl.

In contrast, collecting the output of `$cmd` in a variable makes that
output available for re-use.

The following collects and uses the output of the backticked command
even without explicit assignment to a variable.

#####
perl -E '$cmd = q{uname};`$cmd`;say `$cmd`;'
#####

So, unless others have different views, I don't think we have a bug here.

Thank you very much.
Jim Keenan

---
via perlbug: queue: perl5 status: new
https://rt.perl.org:443/rt3/Ticket/Display.html?id=115330

Search Discussions

  • Father Chrysostomos via RT at Oct 18, 2012 at 3:08 am

    On Wed Oct 17 18:53:34 2012, jkeenan wrote:
    My hunch is that your problem has nothing to do with readpipe or with
    overloading. Call: "perldoc -q backtick". The first response (from
    perlfaq8) says [edited]:

    #####
    What's wrong with using backticks in a void context?

    Strictly speaking, nothing. Stylistically speaking, it's not a good way
    to write maintainable code. Perl has several operators for running
    external commands. Backticks are one; they collect the output from the
    command for use in your program. ...

    Writing backticks in your program sends a clear message to the readers
    of your code that you wanted to collect the output of the command. Why
    send a clear message that isn't true?
    I couldn’t disagree more with that paragraph, but that is not relevant
    here. The `` operator is certainly being executed in the example given.
    Otherwise $cmd would never have been printed.
    #####

    In the example provided, you are using backticks in a void context.
    Hence, you are not *collecting* the output of the command inside the
    backticks for re-use.

    #####
    $ perl -E '$cmd = q{uname};`$cmd`;$output = `$cmd`;say $output;'
    Darwin
    #####

    I don't know whether the first `$cmd` *runs* uname or not.
    But if you override readpipe, which makes `` call your readpipe
    function, you *can* tell, except it calls '$cmd' instead.

    So, unless others have different views, I don't think we have a bug here.
    This interpolates:

    $ perl -MO=Deparse -e '$_ = `$cmd`'
    $_ = `$cmd`;
    -e syntax OK

    This does not:

    $ perl -MO=Deparse -e 'use subs "readpipe"; $_ = `$cmd`'
    use subs ('readpipe');
    $_ = readpipe('$cmd');
    -e syntax OK

    --

    Father Chrysostomos


    ---
    via perlbug: queue: perl5 status: open
    https://rt.perl.org:443/rt3/Ticket/Display.html?id=115330

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupperl5-porters @
categoriesperl
postedOct 18, '12 at 1:53a
activeOct 18, '12 at 3:08a
posts2
users1
websiteperl.org

1 user in discussion

Father Chrysostomos via RT: 2 posts

People

Translate

site design / logo © 2021 Grokbase