Ok. So again, thanks for getting me on the right track. I am now at my compare 
routine. This is where I cannot figure out how to compare within 100. My first 
instinct is to write something like the following:

#!/usr/bin/perl -w
for (1 .. 5){

        my $hping = `sudo hping3 www.microsoft.com -S -p 80 -c 1`;
        push @hping_array,(split'\ ',$hping)[15];
}
$hping_compare = "$hping_array[0]";

foreach (@hping_array){
if ($_ le $hping_compare){

        print "Appears to be load balancing\n";

}
elsif ($_ ge $hping_compare){

        print "Does not appear to be load balancing\n";
}
else{
        print "Something Else\n";
}
}

I cannot find any reference in any documentation or Google that says I can say 
ge or le 100 or more. 

What I am trying to do is say if the 2, 3,4 and 5 values are less than or equal 
to, then print "We are probably load balancing". Elsif we are greater than by 
more than 100 print "We are probably load balancing". Else if we are greater 
than but less than 100 greater than print "we are probably not load balancing. 

It seems like smart search might be along the right lines, but I can't find any 
similar examples.

On Feb 8, 2010, at 7:19 PM, Uri Guttman wrote:

>>>>>> "CS" == Curt Shaffer <cshaf...@gmail.com> writes:
> 
>  CS> OK. So I have tried some things. I guess the largest issue that I
>  CS> can't find an answer for elsewhere is how to evaluate variables to
>  CS> be >, = or <100 in one evaluation.  Before I get there, obviously
>  CS> I need to get the variables.
> 
>  CS> @hping_array = ();
> 
> you are not using strict and warnings. always ask perl for all the help
> it can give you.
> 
>  CS> $hcount = 1;
>  CS> for (; $hcount < 5;){
> 
> that is not perlish.
> 
>       for ( 1 .. 5 ) {
> 
> no need for a counter since you don't even use it.
> 
>  CS>         system ("sudo hping3 $domain -S -p 80 -c 1|awk '{print $5}'");
> 
> system doesn't return any output to the program, just to stdout. you
> need qx or backticks to do this. and why shell out to awk when perl can
> do that for you?
> 
>       my $hping = `sudo hping3 $domain -S -p 80 -c 1` ;
> 
> then parse out the field value you want. i don't know hping3's format
> but you seem to want the 5th white space separated field. this could be
> off by one as iirc awk is 1 based on fields but perl is 0 based.
> 
>       push( @hpings, (split ' ', $hping)[5] ;
> 
> 
>  CS>         chomp;
> 
> that is chomping $_ is not even set. enabling warnings would have told
> you this.
> 
>  CS>         push hping_array, $_;
> 
> where is the @ in that array name? that won't even compile. please make
> sure your code at least compiles before posting it.
> 
> you seem to think system puts its output into $_. where did you get that
> idea? 
> 
>  CS>         $hcount++;
> 
> not needed as i said above
> 
>  CS> }
>  CS> print "@hping_array\n";
> 
>  CS> So the code is trying to run the hping3 command against $domain. I
>  CS> am awking for $5 which is the IPID value in the response. I am
>  CS> trying to push it into the array @hping_array. This should happen
>  CS> 5 times.
> 
> well, it doesn't. 
> 
> 
>  CS> Then I'm printing @hping_array. I'm only getting one value and it
>  CS> is actually the whole response from hping. It seems to not respect
>  CS> the awk.
> 
> no, that isn't true. the system call is sending hping's output to stdout
> (via awk but maybe that code is broken too. my awk is massively
> rusty). your print is printing nothing (which warnings would also have
> told you).
> 
>  CS> I have done this partially with just doing my $hping_result =
>  CS> `sudo hping3 $domain -S -p 80 -c 1|awk '{print $5}'; So I know the
>  CS> system command by itself is working.
> 
> if you know about backticks, why did you switch to system? please read
> the docs and learn the difference between the two.
> 
> uri
> 
> -- 
> Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
> -----  Perl Code Review , Architecture, Development, Training, Support ------
> ---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to