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

Can i use 'sysem' command with @array

Status
Not open for further replies.

JaybOt

Programmer
Apr 18, 2001
101
GB
Hi all,

Can anyone help with this one. i'm trying to use the 'system' command in a foreach loop with a perl array but can't get it to work. Heres what i'm doing ...

foreach (@ARRAY)
{
system('dig -x [@ARRAY] hinfo');
next
}

the DNS lookup is being done on "@ARRAY". The array contains a list of ip addersses, 1 per line.

any help welcome.

Jaybot. "Always know what you say, but don't always say what you know!"
 
when you say

foreach (@ARRAY)
{
.
.
.
}

you're really saying

foreach $_ (@ARRAY){

because foreach sets $_ unless you tell it otherwise

you could re-write your loop like this

foreach $addr (@ARRAY)
{
system("dig -x $addr hinfo");
}

(you don't need the "next" by the way) Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Thanks again mike!

Didn't work at first, but i changed the ' ' to " " and hey presto!

Cheers!:) "Always know what you say, but don't always say what you know!"
 
that's what I said... <grin> Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top