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

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

Thread Previous
From:
Father Chrysostomos via RT
Date:
March 2, 2016 16:33
Subject:
[perl #127640] RFE: "qqw( $var/x $var/y word3 $var4=word4 )"
Message ID:
rt-4.0.18-26760-1456936407-414.127640-15-0@perl.org
On Wed Mar 02 00:03:42 2016, plokinom@gmail.com wrote:
> Am 02.03.2016 um 05:32 schrieb Linda Walsh (via RT):
> >
> > Every once in a while, I start filling an array using
> > "qw()", when I run into, not too infrequently, a desire
> > to have a var or expression as a "word".  Paths can be
> > a good example:
> >
> > my short_paths=[ qw( sysfs    sys_classes             netclass
> > sysmods) ];
> > my spth_vals  =[qqw( /sys             $sysfs/class
> > $sys_classes/net        $sysfs/module ) ];
> 
> It's not core perl, but Quote::Code (available for perl 5.14+) lets
> you
> write this:
> 
> use Quote::Code;
> my $pth_vals = [qcw(
>    /sys {$sysfs}/class {$sys_classes}/net {$sysfs}/module
> )];

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


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

Thread Previous


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