Thanks for the comments Smoot.
I thought "while (<>) {...}" was the same as "foreach (<>) {...}". Is this
because foreach provides a list context to the file being read and while
provides scalar context? I read this in the camel book but didn't understand
the significance. It makes a difference when the list is large?
Without the if statement in the code, if the last line is blank then I get
something like this as a return...
vaugw001 is reachable.
vadgw001 is reachable.
oh3gw001 is reachable.
tx88gw001 is NOT reachable. #done on purpose
is NOT reachable.
The input file for above is:
---cut here---
vaugw001
vadgw001
oh3gw001
tx88gw001
---cut here---
Could I be looking at the blank line differently or be more careful with the
input file format?
Finally, is this the only way to run this script for a single host?
echo vaugw001 | live
Thanks again,
K
[EMAIL PROTECTED] wrote:
> > Kevin der Kinderen <[EMAIL PROTECTED]> said:
>
> >
> > Question: What is the proper way to include a version number in the
> > code? When I do a "perl -MCPAN -eshell" and type "r" for the reinstall
> > recommendations - many modules show the version. Looking at the code to
> > some of these modules it seems it uses the "vars" pragma. According to
> > perldoc - it's obsolete. What is the correct way to do this - or does it
> > even make a difference.
>
> I usually add a "-V" or --version option to the code which displays the
> current version number. Take a look at Getopt::Std or Getopt ::Long
> for option processing.
>
> > For those who might want to comment - here's the code... (be kind - I'm
> > new at this).
> >
> > ./live <seed.dat
> >
> > #!/usr/bin/perl -w
> >
> > use strict;
> > use warnings;
> > use Net::Ping;
> >
> > my $p;
> > my $host;
> >
> > our $VERSION = "0.01";
> >
> > $p = Net::Ping->new("icmp");
> > foreach (<>)
> > {
> > chomp;
> > if ($_ eq "") {
> > print STDERR "\nDone\n";
> > exit(0);
> > }
> > print "$_ is ";
> > print "NOT " unless $p->ping($_, 2);
> > print "reachable.\n";
> > }
> > $p->close();
>
> Not a bad first start. I an curious about the "if". Are you tagging
> the end of the device list with an empty line? The foreach loop you
> have will read in the entire file and then each line in processed from
> the resulting list. I usually do I/O with a while loop e.g.
>
> while (<>) {
>
> }
>
> This reads the input a line at a time.
>
> With the magic <> you can also call your script like this:
>
> ./live seed.dat
>
> or even
>
> ./live seed1.dat seed2.dat
>
> The <> will take each argument and treat it as a filename, opening each in
> turn.
>
> --
> Smoot Carl-Mitchell
> Consultant
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]