Hi Eyal,

I should note that your plain text message is mal-formatted. It's not clear 
which parts were said by me, and which parts were said by you. Next time, 
please configure your mailer (GMail.com?) to format the message as plaintext 
and to use proper "> " quoting as needed by netiquette rules.

On Friday 21 Jan 2011 10:00:06 אייל ב. wrote:
> Hi Shlomi
> I tried to put this answer on the Google group, but didn't succeed. (Sent
> it but it didn't published)

It's not a Google group - it's a @perl.org-hosted mailing list. I don't know 
why it wasn't published, but you can try E-mail postmas...@perl.org about it. 
I'm CCing the list in any case.

> I hope this is OK I'm sending it right here.

I guess. I'm CCing the list.

> BTW, I read your story and very likes that. It's good and very brave to
> share your self with others.

Which story?

> Looks like you are really dealing with your life.
> 
> Back to Perl :
> Tried to implement your recommendations .... step by step .....
> 
> #! C:\Perl\bin\perl
> use strict;
> use warnings;
> 
> my %list =
> (60=>"linux",61=>"linux",62=>"linux",63=>"linux",64=>"linux",65=>"linux",12
> 5=>"Windows",126=>"Windows",127=>"Windows",128=>"Windows",250=>"Unix",251=>
> "Unix",252=>"Unix",253=>"Unix",254=>"Unix",255=>"Unix",
> 256=>"Unix",257=>"Unix",258=>"Unix",259=>"Unix",260=>"Unix");

Like I said you should reformat that. And since you have a lot of duplicacy 
you can use something like:

my %ttls_to_os =
(
        Linux => [60..65],
        Windows => [125 .. 128],
        Unix => [250 .. 260],
);

And then construct a TTL->OS mapping using 
http://perldoc.perl.org/functions/map.html .

> 
>     my $path = "hosts.txt" ;
>     # open (MACHINES,$path) or die "Couldn't open file for writing";
>         open my $input_fh, "<", $path
>             or die "Could not open '$path' - $!";
> 
> # Shlomi, you wrote : "Use three args open and don't use bareword file
> handles..."
> 
> # I'm asking : Trying to implement that (Though, didn't understand what is
> "bareword")....where do I indicate the MACHINES handle ?

A bareword is something like «MACHINES», i.e: starting with an uppercase 
letter and without a "$" sigil in front. And you can do:

[code]
open my $machines_fh, '<', $path
        or die "Could not open '$path' - $!";
[/code]

And then use the «$machines_fh» file handle instead of «MACHINES».

> 
>     my $machine_IP ;
>                 while ($machine_IP = <MACHINES>)
>                 {

This should be written as:

[code]
while (my $machine_ip = <$machines_fh>)
[/code]

>                 chomp($machine_IP) ;
>                 my $line ;
>                 my $cmd ;
>                 $cmd = "ping $machine_IP";
>                   open(HANDLE,"$cmd|");
> 
> # Shlomi, you wrote : You should use three-args open, lexical filehandles
> and "or die".
> # I'm  asking : Can you pls show me how should I write that ?

You can do:

[code]
open my $handle, "ping $machine_IP|"
        or die "Could not open the ping process - $!";
[/code]

In this case, a three args open using '-|' won't work because it's not 
implemented in Windows yet.

> # Furthermore, use $cmd is not needed here as you can interpolate directly
> from $cmd.
> # I didn't understand what that means.

See above.

> 
>                     while ($line = <HANDLE>)
>                         {
>                         if("$line" =~ "TTL=")
> 
> # No need for wrapping $line in double quotes here as $line is a string.
> # as mentioned above




> 
> 
>                              {
>                                 $line =~ s/.*TTL=//;
>                                 print "TTL = $line\n";
>                                 print $list{$line} ;
>                                 last;                                   }
> # You can do all that in one regex match.
> # I didn't reach so far ... Is that
> 
> # if (my ($ttl) = $line =~ m{TTL=(\d+)})
> 

Yes, it's that.

>                            # print "Machine $machine_IP is $list{$line}" ;
> 
> 
>                         }
>    }
> close HANDLE;
> close MACHINES;
> 
> # Without make the changes about the File Handle -
> I still got the error : Use of uninitialized value within %list in print at
> C:\system\Perl\OS-recognize\os-rec5.1_.pl line 35, <HANDLE> line 4.
> 

Maybe you have a missing TTL from your hash. Try using a debugger:

http://perl-begin.org/topics/debugging/

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Apple Inc. is Evil - http://www.shlomifish.org/open-source/anti/apple/

Chuck Norris can make the statement "This statement is false" a true one.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
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