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