Toolic, that did work, and thank you!
One detail that I forgot to mention, and I edited the original post, is that I am working on Windows with Strawberry Perl. I had some trouble integrating the command into my script and could not store the output into a variable as it just went to stdout due to the "print $1 if" portion. I tried to redirect stdout, and not using "print" at all, but I ended up creating a temp file using this code to store the resulting number in a variable:
use IO::Handle;
# Extract the Payee ID from the file and store it into a temporary fil
+e
my $payeeid;
system( q(perl -ne "print $1 if /INC\*XX\*(\d+)/" cr835.txt > payee.tx
+t) );
# Define a file variable and read the contents to a variable
my $file;
$file = path("./payee.txt");
my $payeeid = $file->slurp;
# Define the date and time for use in the new file name
use constant DATETIME => strftime("%Y-%m-%d_%H-%M", localtime);
# Define the new file name
my $file = "CR835.txt";
my $newfilename = "CR835-" . $payeeid . "-processed_" . DATETIME . ".t
+xt";
# Rename the file
move $file, $newfilename;
Is there a better way to store the result into the variable?
-
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.
|