Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
jwkrahn has the right idea. Instead of using Perl to call an O/S specific function, write Perl code that runs on multiple platforms: Windows, Cygwin or Unix.

Perhaps some code like this code for your first system call with grep?
I did not create the test files necessary to actually prove that this works on my Windows system, but this is plausible.

#!/usr/bin/perl use strict; use warnings; use autodie; #system ('grep -l "DATAmessage.*3\.0" *.xml > 3.0_files_arraydata.txt' +); open my $OUT, '>', '3.0_files_arraydata.txt'; foreach my $filename (<*.xml>) { open my $in, '<', $filename; print $OUT "$filename\n" if grep{/DATAmessage.*3\.0/}<$in>; }
The above code will be slower than Unix grep -l because this code looks at every line of the input file and reports the number of lines that matched, and if >0, that fact causes the filename to be printed. grep -l stops at the first matching line and reports the file name. Speed depends upon how big your files are. A couple more lines of Perl code can emulate the exact grep -l functionality (stop reading the file when the first match is found). I have no idea what File::Grep is and why you would need it. Perl regex is very fast. Literally decades of tweaking have gone into the regex engine.

Anyway, try the above out and see how it goes.


In reply to Re: Using system (); with Strawberry Perl by Marshall
in thread Using system (); with Strawberry Perl by hadrons

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 about the Monastery: (5)
As of 2024-04-18 07:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found