Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: quoting problems passing pattern to shell in backquotes

by polettix (Vicar)
on Dec 28, 2007 at 10:00 UTC ( #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 findit.pl 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 findit.pl 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?


Comment on Re: quoting problems passing pattern to shell in backquotes
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2015-07-04 22:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls