Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Print text on the same line after match

by periodicalcoder (Novice)
on Dec 14, 2018 at 22:48 UTC ( [id://1227280]=note: print w/replies, xml ) Need Help??


in reply to Re: Print text on the same line after match
in thread Print text on the same line after match

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?

Replies are listed 'Best First'.
Re^3: Print text on the same line after match
by haukex (Archbishop) on Dec 14, 2018 at 23:08 UTC
    Is there a better way to store the result into the variable?

    Yes - I showed how to do this without calling an extra perl process, it'll give you much more power and control.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1227280]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-19 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found