For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > May 2004 > Re: String problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: String problem
John W. Krahn

2004-05-20, 6:30 pm

Werner Otto wrote:
>
> Hi there,


Hello,

> I am trying to do the following:
>
> $string = system ("ping -a $hostname | cut -c20-30");


Use the Net::Ping module instead.

http://search.cpan.org/~bbb/Net-Ping-2.31/


> This result returns 0 which is suppose to indicate success. But it never
> proves me wrong it always stays un-changed at 0.
>
> More to the point. I am trying to store the value returned, which would be
> "is alive" in a string variable. How would I go about it.
>
> I've tried $string = " ";
> and then
> $string .= $string + system ("ping -a $hostname | cut -c20-30");


If you want to get the standard output of the command as well as the return
value then this should work:

my $string = join '', map substr( $_, 19, 11 ), qx/ping -a $hostname/;
my $result = $? >> 8;



John
--
use Perl;
program
fulfillment
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com