New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFE: "qqw( $var/x $var/y word3 $var4=word4 )" #15209
Comments
From perl-diddler@tlinx.orgCreated by perl-diddler@tlinx.orgEvery once in a while, I start filling an array using my short_paths=[ qw( sysfs sys_classes netclass sysmods) ]; : ${prefix:=/} In the 1st example one would want to loop through short_paths, then I wondered whether it was worth it keeping the "qqw" terms "simple", or my ($sysfs, $sys_classes, $netclass, $sys_modules); Anyway, am I just missing this feature, or is it something Is there any reason wny it would be a good idea? Perl Info
|
From @maukeAm 02.03.2016 um 05:32 schrieb Linda Walsh (via RT):
It's not core perl, but Quote::Code (available for perl 5.14+) lets you use Quote::Code; -- |
The RT System itself - Status changed from 'new' to 'open' |
From @cpansproutOn Wed Mar 02 00:03:42 2016, plokinom@gmail.com wrote:
Also, if you *know* that your strings contain no wildcards, you can do <foo bar $baz> (or </sys $sysfs/class $sys_classes/net $sysfs/module>), and it won’t even go out to the filesystem, though it is marginally slower than qw and Quote::Code (at least in theory; I have not measured it). -- Father Chrysostomos |
From perl-diddler@tlinx.orgOn Wed Mar 02 00:03:42 2016, plokinom@gmail.com wrote:
Yeah, I could think of a few ways to do it "manually", but none with the reliability or orthogonal grace of "q"/"qq" => "qw"/"??". It seemed like one of those things that looked like it was missing rather than needing an extension or clever work-workaround. |
From @rjbs* Linda Walsh <perlbug-followup@perl.org> [2016-03-01T23:32:14]
$x = "good job"; Is @y now ('good', 'job', 'hunter') or ('good job', 'hunter')? I would think I think that many Perl programmers have wished for qqw at one time or another, -- |
From @cpansproutOn Sat Mar 05 10:14:48 2016, perl.p5p@rjbs.manxome.org wrote:
I would have assumed the former. So I suppose it’s not obvious. BTW, this does the former: $x = "good job"; -- Father Chrysostomos |
From Eirik-Berg.Hanssen@allverden.noOn Sat, Mar 5, 2016 at 8:06 PM, Father Chrysostomos via RT <
In Perl6, this does the former, too: eirik@purplehat[22:25:34] … which surprised me, until I found that this does the latter: eirik@purplehat[22:27:52] :) Eirik |
From @ap* Father Chrysostomos via RT <perlbug-followup@perl.org> [2016-03-05 20:10]:
I prefer the former. So much so, in fact, that I don’t see any point in @y = split ' ', "$x hunter"; But a list in which variable values are interpolated yet atomic requires @subdir = ( "$prefix/foo", "$prefix/bar", "$prefix/baz" ); Consider how much nicer that would be if you got to leave out all those @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 Regards, |
From @ap* Aristotle Pagaltzis <pagaltzis@gmx.de> [2016-03-05 23:00]:
(I meant that I prefer the *latter* – as the rest of the message should |
From @kentfredricOn 6 March 2016 at 10:59, Aristotle Pagaltzis <pagaltzis@gmx.de> wrote:
What would this do?: $prefix = "/some/path/with a space/"; 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 expanding-qqw: variables with spaces in them are interpolated into being lists -- KENTNL - https://metacpan.org/author/KENTNL |
From @ap* Kent Fredric <kentfredric@gmail.com> [2016-03-06 06:20]:
Sorry for the confusion. If you ignore the opening prose and concentrate This line: qqw( $prefix/foo $prefix/bar $prefix/baz ); … ought to yield the same result as this line: ( "$prefix/foo", "$prefix/bar", "$prefix/baz" ); … and *not* as this line: split ' ', "$prefix/foo $prefix/bar $prefix/baz"; … because that last line is already real easy to write in various ways split ' ', qq( There’s little point in adding yet another way of writing that, when the ( (And that’s the least noisy way of formatting it.) So that is the case that ought to gain some syntactic relief, if any. Hope I did a better job this time. Regards, |
From @kentfredricOn 6 March 2016 at 22:18, Aristotle Pagaltzis <pagaltzis@gmx.de> wrote:
Agreed, so we are both proponents of "preserving"-qqw.
The only residual question I have is, what does this do: @x = ('word','word with space'); I assume that the "most obvious" thing would be this to compile the same as: @z = ( -- KENTNL - https://metacpan.org/author/KENTNL |
From @b2gillsI'm going to point out that Perl 6 has a vastly different way of parsing strings On Sat Mar 05 13:29:44 2016, Eirik-Berg.Hanssen@allverden.no wrote:
First off `< ... >` is the same as `qw/ ... /`, and `« ... »` is the same as `qqww/ ... /` Perl 6 starts off with a zero feature quoting mechanism `Q/ ... /` `「 ... 」` then adds features to it Then there is `'...'` `q/.../` `Q:q/.../` `Q:single/.../` which enables backslashing backslashes and the quoting character `:qq` / `:double` enables `:c` / `:closure`, `:s` / `:scalar`, `:a` / `:array`, `:h` / `:hash`, `:f` / `:function` Some combinations can be combined without the colons like `qqww/.../` `qx/.../` `qqx/.../` There are several other features that can also be enabled like `:to` for heredocs Basically `<< ... >>` / `« ... »` is short for The spaces between adverbs (feature flags) are optional. The relevant bit for this discussion: use v6.c; # :words not :quotewords # ignores quotes inside of the embedded string ( Again you could use `<< ... >>` or `« ... »` instead of `qqww/.../` ) Perhaps there should be qw// qqw// qww// qqww// |
From @rjbs* Aristotle Pagaltzis <pagaltzis@gmx.de> [2016-03-05T16:59:38]
Me, too. Other cases to consider: @x = qqw( abc @def ghi ); ...which would need to have three elements, to match this: @x = qqw( x:abc x:@def x:ghi ); It would be bizarre for the second example to only have x: on the first element Someone will probably have to stop and think about: @x = qqw( ...because of the spaces in the expr in the second element. I think this is
Agreed.
I have no feelings on this. -- |
From @cpansproutOn Thu Mar 10 16:01:19 2016, perl.p5p@rjbs.manxome.org wrote:
Would you please clarify with examples? Does x:@def above become one element of @x, or does it fill @x with as many elements as are in @def?
You just switch to a different parsing style when you encounter the $. Standard double-quote parsing solves it that way. <wishful thinking> That said, I wish we could solve this kind of nonsense: qq<$x{">"}>; # syntax error If strings were parsed just like blocks of code, there would be no reason for that not to work. After all, { "}" } and ["]"] work. As it is, the final delimiter of the string is searched for before the body is parsed. It has to be that way for quote-like operators with flags at the end. It would have been saner if the parsing had been done the other way round from day 1 (with the flags in some other spot). Would it be possible to make qqw work the ‘new’ way? Or would it be to confusing if it does not conform to the way qw works? </wishful>
That is one of the most annoying warnings. If it warned *only* when all the elements are comma-separated, it would be helpful for new bees without annoying people trying to do this: qw( . , ; : ) etc. Currently, just *one* comma anywhere in the qw will raise the warning. If we could restrict the warning that way, I would not mind it on qqw. It might be good to apply the restriction to qw as well. -- Father Chrysostomos |
From @rjbs* Father Chrysostomos via RT <perlbug-followup@perl.org> [2016-03-11T00:52:04]
I mean that, given @def=(1,2,3), @x would be: ("x:abc", "x:1 2 3", "x:ghi")
I think it would be too confusing. :( -- |
From @AbigailOn Thu, Mar 10, 2016 at 07:00:53PM -0500, Ricardo Signes wrote:
Do we have to make a choice? If someone is going through the Abigail |
From @ap* Abigail <abigail@abigail.be> [2016-03-23 18:50]:
IMO the other option already has an existing construct: split ' ', qq( ... ) Do you consider that not good enough for some reason? Regards, |
From @AbigailOn Wed, Mar 23, 2016 at 09:22:08PM +0100, Aristotle Pagaltzis wrote:
First of all, I don't have a strong need for qqw, regardless of what As for the "but here's a way to do it" argument, I don't find that a qw can be expressed as split ' ', q (...) but does that mean qw() is a waste? Also, the variant you favour can also be easily expressed otherwise: @y = ($x, "hunter"); so that would argue to not implement qqw at all. Nor 99% of the other features which are being proposed. Abigail |
From zefram@fysh.orgThe proposed qqw() should be implemented on CPAN first. If experience -zefram |
From @xsawyerxOn Thu, 14 Dec 2017 23:13:43 -0800, zefram@fysh.org wrote:
Agreed. Examples of other examples: https://metacpan.org/pod/Quote::Code |
@xsawyerx - Status changed from 'open' to 'rejected' |
Migrated from rt.perl.org#127640 (status was 'rejected')
Searchable as RT127640$
The text was updated successfully, but these errors were encountered: