Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Question on DeFoy's range operator example

by nysus (Parson)
on Jan 27, 2019 at 22:27 UTC ( [id://1229038]=perlquestion: print w/replies, xml ) Need Help??

nysus has asked for the wisdom of the Perl Monks concerning the following question:

I'm looking at Brian DeFoy's recent article. He's got:

$ perl -le "\$, = q( ); print q(a)..q(z)" a b c d e f g h i j k l m n o p q r s t u v w x y z

I get an error, though:

Experimental aliasing via reference not enabled at -e line 1.

And this simpler line works for me, without error with version 5.24.1 and 5.28.1:

perl -le '$, = q( ); print a..z'

So I'm curious to know what he's doing with his referencing of the output field separator, $,. Thanks.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re: Question on DeFoy's range operator example
by choroba (Cardinal) on Jan 27, 2019 at 22:47 UTC
    Maybe you are on MSWin where quotes behave differently to *nix? The \$, is there to prevent the shell from expanding the $, (which wouldn't happen anyway), on MSWin, you are safe to remove the backslash (as we're on *nix).

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      Windows requires double quotes and does not allow the backslash.

      >perl -le "\$, = q( ); print q(a)..q(z)" Experimental aliasing via reference not enabled at -e line 1. >perl -le "$, = q( ); print q(a)..q(z)" a b c d e f g h i j k l m n o p q r s t u v w x y z >perl -le '$, = q( ); print q(a)..q(z)' Can't find string terminator "'" anywhere before EOF at -e line 1. >perl -le '\$, = q( ); print q(a)..q(z)' Can't find string terminator "'" anywhere before EOF at -e line 1.
      Bill

      I'm on a Mac, bash 4.4.23.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

Re: Question on DeFoy's range operator example
by 1nickt (Canon) on Jan 28, 2019 at 12:32 UTC

    Presumably you mean brian d foy? Where did you come up with that spelling?

    I have thought for 15 years or more that it's a silly affectation, but it's his name and his choice, and every book, every article on the blog you quoted, every conference announcement and, yes, post in this monastery, has carried that rendition for that long or more. It seems a bit disrespectful, or, at least, inattentive, to come up with your own version of it.

    (FWIW the blog post you asked about shows commands with single and double quotes and with and without the backslash...)

    Hope this helps!


    The way forward always starts with a minimal test.

      My bad. Had a few beers that afternoon, as I recall. :)

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

        My bad

        I wouldn't be too worried about it.
        Just because Brian can't spell his own name correctly is no reason that everyone else should perpetuate the error ;-)

        Cheers,
        Rob
Re: Question on DeFoy's range operator example
by bliako (Monsignor) on Jan 28, 2019 at 10:55 UTC

    Apropos:

    perl -le "$(cat <<'EOF' $, = q( ); print q(a)..q(z); print "I am a JAPH-BASH in-line-multi-line.\n"; EOF )"

    Heredoc, only in bash

    bw, bliako

Re: Question on DeFoy's range operator example
by Theodore (Friar) on Jan 28, 2019 at 09:17 UTC
    Using a csh instead of bash maybe? With bash, the original works fine. With tcsh, i'm getting the same error about aliasing, which goes away when i remove the backslash:
    $ perl -le '$, = q( ); print q(a)..q(z)' a b c d e f g h i j k l m n o p q r s t u v w x y z
      which goes away when i remove the backslash:

      ... and, at the same time, replacing the double quotes with single. They go hand-in-hand 🙌

      No, bash 4.4.23 on a mac.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

Re: Question on DeFoy's range operator example
by nysus (Parson) on Jan 28, 2019 at 11:44 UTC

    Ah, dammit. I was using single quotes and he has double quotes. My bad.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

      but I'm still not sure why he is backslashing $,

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

        It's not needed, but doesn't hurt. `$,` is not a valid variable name in bash, but if you don't remember the bash rules, you can safely quote every $.

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1229038]
Approved by davies
Front-paged by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-25 05:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found