Since you get the output you desire when printing to STDOUT, you have a problem with shell redirection, hence yours is not a Perl {question,problem} but a {shell,OS} one.
Or else you may simply have a problem with buffering. Are you trying to read from the file before the writing has terminated? Try adding e.g. $|++ at the top of your script.
Update: OTOH, it doesn't have anything to do with your problem, but generally Perl-style for loops are preferrable over C-style ones. Your script may be rewritten as (untested):
#!/usr/bin/perl -l
use strict;
use warnings;
use Net::Ping;
my @net=map "192.168.$_",
qw/97 100 102 104 105 32 33 34/;
my $p=Net::Ping->new or
die "Can't create ping object: $!\n";
for my $net (@net) {
for (16..250) {
my $host="$net.$_";
warn "$host not responding!\n" and next
if !$p->ping($host);
print $host;
}
}
__END__
Please note that I also made a few minor, "cosmetic", changes. E.g. I turned a
print into a
warn. This may not be what you want, but is often appropriate in similar situations.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.