johnarky has asked for the wisdom of the Perl Monks concerning the following question:

My work site has a Perl script that Recognizes File Name Patterns in an Angle Operator in a While Loop Condition. Here's the code:

while (<$$Config{ldir}/$$Config{lfile}>)

This means that if a $$Config{lfile} is *.gpg and there's a star.gpg in $$Config{ldir}, then $_ will iterate as star.gpg. But I can't replicate this in a new script, for example:

while (<"/export/home/usps_edi/*pl">) { -f $_ && print "ok\n";}'

And I've run the new script with all the modules use'd by the old script:

use EDI::Config; use POSIX qw(uname); use File::Copy; use File::Basename;

(EDI::Config is a local module.) What do I need to do to get the magic of the old script to work with the new script?

Replies are listed 'Best First'.
Re: Recognizing File Name Patterns in an Angle Operator in a While Loop Condition
by Perlbotics (Archbishop) on May 21, 2012 at 18:14 UTC

    Use an explicit glob:

    while ( glob "/export/home/usps_edi/*pl" ) { -f $_ && print "ok\n";}'

      Works like a charm! Thanks very much!