develooper Front page | perl.perl5.porters | Postings from March 2016

Re: [perl #127640] RFE: "qqw( $var/x $var/y word3 $var4=word4 )"

Thread Previous | Thread Next
From:
Kent Fredric
Date:
March 6, 2016 05:19
Subject:
Re: [perl #127640] RFE: "qqw( $var/x $var/y word3 $var4=word4 )"
Message ID:
CAATnKFCi9N7rVnjqAk69-MosDGA7yu2jVTWSz6jn-UwAgVsNOQ@mail.gmail.com
On 6 March 2016 at 10:59, Aristotle Pagaltzis <pagaltzis@gmx.de> wrote:
> * Father Chrysostomos via RT <perlbug-followup@perl.org> [2016-03-05 20:10]:
>> On Sat Mar 05 10:14:48 2016, perl.p5p@rjbs.manxome.org wrote:
>> > $x = "good job";
>> > @y = qqw( $x hunter );
>> >
>> > Is @y now ('good', 'job', 'hunter') or ('good job', 'hunter')?
>> > I would think the latter.
>>
>> I would have assumed the former. So I suppose it’s not obvious. BTW,
>> this does the former:
>>
>>   $x = "good job";
>>   @y = < $x hunter >;
>
> I prefer the former. So much so, in fact, that I don’t see any point in
> the feature if it does the latter. Because that result is already easy
> to achieve in several ways – starting with this very conventional, very
> boring, nobody-will-ever-scratch-their-head-about-it approach:
>
>     @y = split ' ', "$x hunter";
>
> But a list in which variable values are interpolated yet atomic requires
> lots of syntactic ceremony using currently available means:
>
>     @subdir = ( "$prefix/foo", "$prefix/bar", "$prefix/baz" );
>
> Consider how much nicer that would be if you got to leave out all those
> quotes and separators:
>
>     @subdir = qqw( $prefix/foo $prefix/bar $prefix/baz );
>
> A qqw() that splits after interpolating would deprive us of that.
>
> So I think it must work that way or else there’s no point in bothering.
>
> While we’re at it – I would also prefer qqw() to allow comments, and/but
> allow backslashing whitespace and octothorpes to demote them from syntax
> to string content. Oh, and please – no qw()-style warnings about commas.
>
> Regards,


What would this do?:

$prefix = "/some/path/with a space/";
@y = qqw{   $prefix/hunter  $prefix/bar  };


Your description so far indicates that the output would be

( '/some/path/with' , 'a' , 'space/hunter'  )

etc.

For clarity, we need a description of the 2 behaviours other than
"former" or "Latter" because backtracking to
work out which one we're talking about is kinda confusing.

expanding-qqw:  variables with spaces in them are interpolated into being lists
preserving-qqw:  variables with spaces in them are treated as
syntactically atomic and indivisible, and any spaces in them are
treated as non-spaces for the purpose of the qqw construct, and only
literal spaces in qqw itself is a separator


-- 
Kent

KENTNL - https://metacpan.org/author/KENTNL

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About