Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing With Perl

Status
Not open for further replies.

jonnymp316

IS-IT--Management
Jun 6, 2003
6
US
Hello,
I am a beginner with Perl and I was wondering how I could script with perl to read the output of file. In other words how can I parse the output from a dos application?

For instance I run...

C:\>status.exe
name=Jonny
value=10
status=10x2
C:\>

all I want to do it to pick out the number of 10x2 out of that line from status. Can anyone help. Like I said I am a newbie so don't go to hard on me.

Thanks,
-Jonny
 
Untested, but looks good in theory:
Code:
#these first two help keep a person honest
use strict;
use warnings;

#catch the output of a command
#backticks ` not apos '
my @lines = `status.exe`

my $stored; #place to put value you're looking for

#loop over each line
foreach(@lines)
{
  chomp; #remove trailing newline

  #split each line on =, saving each part
  my ($name, $value) = split /=/;

  #set stored if $name is status
  $stored = $value if($name eq 'status');
}

print $stored;

----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top