------------------------------------------------
On Tue, 11 Feb 2003 21:37:30 -0600, Mark VanMiddlesworth <[EMAIL PROTECTED]> wrote:
> OK, I cleaned up the script a bit. Here it is now, but I can't get it
> to accept two variables in a row:
>
> $b = 0;
> print "insert first three digits of ip (xxx.xxx.xxx.): ";
> $address = <STDIN>;
> open (LOG, ">>/perl/pinglog.txt") || die "can't open";
> foreach my $x (1 .. 255) {
> $b ++;
> $a = `ping -q -c 1 -l 1 $address$b`;
> print $a;
> print LOG `date`;
> print LOG "\n\n";
> print LOG $a;
> }
> close LOG;
>
> When I run it, I get the errors:
> ping: unknown host 192.168.1.
> and
> sh: 1: command not found
>
> It seems like it is treating the two variables as separate commands.
It is :-). Because you are taking the input from standard in there is a new line
character on the end of the sting, and I believe this is causing the problem. You
should 'chomp' each line of the standard input to remove this new line character:
perldoc -f chomp
You need a line like:
chomp $address;
After reading from STDIN.
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]