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?

In reply to Re: quoting problems passing pattern to shell in backquotes by polettix
in thread quoting problems passing pattern to shell in backquotes by perl-diddler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.