RE: Skip then print

2005-12-05 Thread David Sudjiman
On Mon, 5 Dec 2005, Moon, John wrote:
> while ($line = <>) {
>   next if $. <= 10;
> ...
>   }

CMIIW, this one will check (if $.) for each of the line.

thx
.dave

http://www.davidsudjiman.info

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Skip then print

2005-12-05 Thread David Sudjiman
On Mon, 5 Dec 2005, Ron McKeever wrote:

> Hello,
> 
> I would like to skip the first ten lines of output from tail, then print any 
> new records matching my array, but I seem to be stuck, below will run but 
> nothing prints:
> tail /var/log/messages is piped to it...
> 
> #!/usr/bin/perl
> 
> my @names = ("nb","tp","ape","berry","jab");
> my $log = "/local/tp/tp";
> 
> #skip first ten
> @array = ( 1 .. 10 );
> 
> while ($line = <>) {
> foreach $number ( @array ) {
> ($mo, $day, $tm, $host, $proc, @data) = split(" ", $line);
>  foreach my $i (@names){
> print "Seen on ". localtime() .": $line"  if $host =~ /$i/;
>   }
>  }
>}

@file = <>;
foreach (11..$#file) {
   chomp;
   print $_ . "\n" ;
}

thx
.dave

http://www.davidsudjiman.info

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Skip then print

2005-12-05 Thread Moon, John
From: Ron McKeever [mailto:[EMAIL PROTECTED] 
Sent: Monday, December 05, 2005 11:50 AM
To: beginners@perl.org
Subject: Skip then print

Hello,

I would like to skip the first ten lines of output from tail, then print
any new records matching my array, but I seem to be stuck, below will
run but nothing prints:
tail /var/log/messages is piped to it...

#!/usr/bin/perl

my @names = ("nb","tp","ape","berry","jab");
my $log = "/local/tp/tp";

#skip first ten
@array = ( 1 .. 10 );

while ($line = <>) {
foreach $number ( @array ) {
($mo, $day, $tm, $host, $proc, @data) = split(" ", $line);
 foreach my $i (@names){
print "Seen on ". localtime() .": $line"  if $host =~ /$i/;
  }
 }
   }

Thanks,
Rob

This may help 

while ($line = <>) {
next if $. <= 10;
...
}

Don't know about the split... I "assume" the data fields are separated
by a single space(?). Plus I only see the last 10 records with your
construct and I split the 10 records 10 times each 



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Skip then print

2005-12-05 Thread Shawn Corey

Ron McKeever wrote:

I would like to skip the first ten lines of output from tail


If you want the last line of a file, you can get tail to print only 
that. See `man tail`.


$ tail -n 1 

--

Just my 0.0002 million dollars worth,
   --- Shawn

"Probability is now one. Any problems that are left are your own."
   SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Skip then print

2005-12-05 Thread Ron McKeever
Hello,

I would like to skip the first ten lines of output from tail, then print any 
new records matching my array, but I seem to be stuck, below will run but 
nothing prints:
tail /var/log/messages is piped to it...

#!/usr/bin/perl

my @names = ("nb","tp","ape","berry","jab");
my $log = "/local/tp/tp";

#skip first ten
@array = ( 1 .. 10 );

while ($line = <>) {
foreach $number ( @array ) {
($mo, $day, $tm, $host, $proc, @data) = split(" ", $line);
 foreach my $i (@names){
print "Seen on ". localtime() .": $line"  if $host =~ /$i/;
  }
 }
   }

Thanks,
Rob


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]