Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: quoting problems passing pattern to shell in backquotes

by polettix (Vicar)
on Dec 28, 2007 at 10:00 UTC ( [id://659318]=note: print w/replies, xml ) Need Help??

in reply to quoting problems passing pattern to shell in backquotes

While I understand playing on one's strenghts, I think you're using the wrong tool for the job. Perl is quite good at playing with text, so I don't fully understand your insistence upon using shell expansions. Apart from lack of knowledge of better tools, maybe :)

I'd suggest you to take a look to File::Find::Rule. Your problem can be solved quite easily:

#!/usr/bin/env perl use strict; use warnings; use File::Find::Rule; my $pattern = qr/ \A gcc # start with "gcc" - # first separating hyphen [^-]+ # first sequence of non-hyphen - # second - also last - separating hyphen [^-]+ # second sequence of non-hypen \.rpm \z # end with ".rpm" /mxs; my @files = File::Find::Rule->file()->name($pattern)->maxdepth(1)->in( +'.'); print "files: [@files]\n";
No shell expansion quoting headaches, no process spawning, comments in your pattern... and it even works!
poletti@PolettiX:~/sviluppo/perl/testdir$ ls gcc-32bit-4.2-24.x86_64.rpm gcc41-32bit-4.1.3_20070724-15.x86_64.rpm gcc41-4.1.3_20070724-15.x86_64.rpm gcc41-ada-4.1.3_20070724-15.x86_64.rpm gcc41-c++-4.1.3_20070724-15.x86_64.rpm gcc41-fortran-32bit-4.1.3_20070724-15.x86_64.rpm gcc41-fortran-4.1.3_20070724-15.x86_64.rpm gcc41-gij-32bit-4.1.3_20070724-25.x86_64.rpm gcc41-gij-4.1.3_20070724-25.x86_64.rpm gcc41-java-4.1.3_20070724-15.x86_64.rpm gcc41-locale-4.1.3_20070724-15.x86_64.rpm gcc41-objc-32bit-4.1.3_20070724-15.x86_64.rpm gcc41-obj-c++-4.1.3_20070724-15.x86_64.rpm gcc41-objc-4.1.3_20070724-15.x86_64.rpm gcc41-testresults-4.1.3_20070724-25.x86_64.rpm gcc-4.2-24.x86_64.rpm gcc42-32bit-4.2.1_20070724-17.x86_64.rpm gcc42-4.2.1_20070724-17.x86_64.rpm gcc42-ada-4.2.1_20070724-17.x86_64.rpm gcc42-c++-4.2.1_20070724-17.x86_64.rpm gcc42-fortran-32bit-4.2.1_20070724-17.x86_64.rpm gcc42-fortran-4.2.1_20070724-17.x86_64.rpm gcc42-gij-32bit-4.2.1_20070724-26.x86_64.rpm gcc42-gij-4.2.1_20070724-26.x86_64.rpm gcc42-info-4.2.1_20070724-17.x86_64.rpm gcc42-java-4.2.1_20070724-17.x86_64.rpm gcc42-locale-4.2.1_20070724-17.x86_64.rpm gcc42-objc-32bit-4.2.1_20070724-17.x86_64.rpm gcc42-obj-c++-4.2.1_20070724-17.x86_64.rpm gcc42-objc-4.2.1_20070724-17.x86_64.rpm gcc42-testresults-4.2.1_20070724-26.x86_64.rpm gcc-ada-4.2-24.x86_64.rpm gcc-c++-4.2-24.x86_64.rpm gcc-fortran-32bit-4.2-24.x86_64.rpm gcc-fortran-4.2-24.x86_64.rpm gcc-gij-32bit-4.2-24.x86_64.rpm gcc-gij-4.2-24.x86_64.rpm gcc-info-4.2-24.x86_64.rpm gcc-java-4.2-24.x86_64.rpm gcc-locale-4.2-24.x86_64.rpm gcc-objc-32bit-4.2-24.x86_64.rpm gcc-obj-c++-4.2-24.x86_64.rpm gcc-objc-4.2-24.x86_64.rpm poletti@PolettiX:~/sviluppo/perl/testdir$ perl files: [gcc-4.2-24.x86_64.rpm]

Hey! Up to Dec 16, 2007 I was named frodo72, take note of the change! Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf

Io ho capito... ma tu che hai detto?

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://659318]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-06-15 20:03 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.