Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

G'day starface245,

That's not really enough information to provide a definitive answer.

Do you get that error once or multiple times? Is script.pl in the same directory as the *.msg files or accessible via $PATH? Have you tried anything to track down why the file(s) can't be found? Is the error being emitted by the code you posted or script.pl? Can you show us the code in script.pl?

You could try something like the following (redirecting the output to a temporary file and searching for No such file or directory).

$ perl -e ' use strict; use warnings; my @files = glob("*.msg"); for my $file (@files) { my $cmd = "ls -l $file"; system($cmd); } ' -rw-r--r-- 1 ken staff 10 26 Oct 03:01 a.msg -rw-r--r-- 1 ken staff 10 26 Oct 03:01 b.msg -rw-r--r-- 1 ken staff 10 26 Oct 03:02 c.msg

With a script.pl like this:

$ cat script.pl while (<>) { print "$_\n"; }

This code works fine for me:

$ perl -e ' use strict; use warnings; my @files = glob("*.msg"); for my $file (@files) { my $cmd = "perl script.pl < $file"; system($cmd); } ' Message A Message B Message C

But I also get the same output with a single line:

$ perl script.pl *.msg Message A Message B Message C

Consider whether you really need thousands of shell and Perl processes if a single Perl process would do the same job.

-- Ken


In reply to Re: Using wildcards to open files. by kcott
in thread Using wildcards to open files. by starface245

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



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2024-03-29 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found