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?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|