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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regex result shell -> perl script

Status
Not open for further replies.

ilicosys

Programmer
Joined
Feb 27, 2007
Messages
2
Location
BR
hello perl friends,

a regex result of a bash command ([command][file] | grep [pattern]) should be passed in to a perl script to be available for further processing by the script.

the script line:

open ( INFO,"< [command] ARGV[0] | grep [pattern]" )
|| die "can't fork: $!";

leads to the 'die' part of the script line.
what would be the correct procedure to accomplish the task?

thank you.
best regards.

pj
 
Hi pj,

I can see what you're trying to do and why you wrote it like that but you missed a $ in front of ARGV[0], and the way you're reading the output of a command isn't quite right; try:
Code:
open ( INFO,"[COLOR=red]|[/color] [command] [COLOR=red]$[/color]ARGV[0] | grep [pattern]" )
|| die "can't [COLOR=red]read from pipe[/color]: $!";


Mike

Hardware is that part of a computer which, when you remove electrical power, doesn't go away.

Want great answers to your Tek-Tips questions? Have a look at faq219-2884
 
hello perl friends,

thank you mike.

how is the output of the pipe associated to a local variable in the perl script?

is

@info=<INFO>;

correct, so that the output string from the pipe could be processed with:

if ($info =~ /pattern/) {
[do something] ;
}

thank you.
best regards.

pj
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top