erik
erik

Reputation: 3880

Retrieving value from single-line Perl script

I am attempting to parse an output file for some data, and am having problems returning the value to my Windows shell.

What I am trying to do is simply return a value using a simple regular expression, and store that into my shell variable.

I currently have something like this:

%VAL% = %PERL% -e '$tmp="Value: 1000"; if ($tmp =~ /Value:\s(\d+)/) { print $1; }'

where %VAL% is where I'd like to return what was found in $1, and %PERL% points to a local copy of perl.exe.

Can somebody please point out the proper way of doing this?

Upvotes: 1

Views: 125

Answers (2)

cristis
cristis

Reputation: 1995

EDIT: It's a bit uglier than Unix:

for /f "tokens=*" %i in ('perl -e "$tmp=\"Value: 1000\"; if ($tmp =~ /Value:\s(\d+)/) { print $1; }"') do set VAL = %i

Or use set /p with an intermediary file:

%PERL% -e '$tmp="Value: 1000"; if ($tmp =~ /Value:\s(\d+)/) { print $1; }' > file.txt
set /p VAL = < file.txt
del file.txt

From Silly Batch File Tricks

Upvotes: 2

Aif
Aif

Reputation: 11220

Why don't you create the variable inside the script? see env_var on win32 perl wiki.

Upvotes: 0

Related Questions