Re: Array, foreach problem

2010-05-05 Thread Akhthar Parvez K
On Thursday 06 May 2010, Rob Coops wrote: > Of course and a system like nagios does exactly that, it reports errors and > positives, mail is of course not the way right to deal with monitoring > certainly in large environments it is simply not done via mail. Currently > looking at the monitoring sy

Re: Array, foreach problem

2010-05-05 Thread Uri Guttman
> "APK" == Akhthar Parvez K writes: APK> Thanks for the explanation John. Could you give one or two real APK> time examples where you used a list (instead of an array) except APK> in loops such as: for ('a', 'b', 'c', 'd')? I wonder if I'm APK> underusing lists in my Perl programs. i

Re: Array, foreach problem

2010-05-05 Thread Akhthar Parvez K
On Wednesday 05 May 2010, John W. Krahn wrote: > > If I could explain this further for Perl beginners: > > With that foreach statement, it reads the file first and creates an > > array with each line as elements and that array is being looped so the > > overhead is higher, whereas with that while s

Re: Array, foreach problem

2010-05-05 Thread Rob Coops
On Wed, May 5, 2010 at 8:50 PM, Akhthar Parvez K wrote: > On Wednesday 05 May 2010, Rob Coops wrote: > > > > A file never starts life being huge but certainly logs tend to grow, and > > they are not always kept in check properly so assume they will be massive > > (I've seen flat text logs that gre

Re: Array, foreach problem

2010-05-05 Thread Akhthar Parvez K
On Wednesday 05 May 2010, Rob Coops wrote: > > A file never starts life being huge but certainly logs tend to grow, and > they are not always kept in check properly so assume they will be massive > (I've seen flat text logs that grew by as much as +1GB per day) assuming > that the file will always

Re: Array, foreach problem

2010-05-05 Thread Rob Coops
On Wed, May 5, 2010 at 7:21 PM, Akhthar Parvez K wrote: > On Wednesday 05 May 2010, Rob Coops wrote: > > Would it not be more efficient to reset the file handle to the star of > the > > file? > > > > use strict; > > use warnings; > > use Fcntl qw(:seek); > > ... > > foreach my $condition (@conditi

Re: Array, foreach problem

2010-05-05 Thread Akhthar Parvez K
On Wednesday 05 May 2010, Rob Coops wrote: > Would it not be more efficient to reset the file handle to the star of the > file? > > use strict; > use warnings; > use Fcntl qw(:seek); > ... > foreach my $condition (@conditions) { >  seek ( $fh, 0, 0 ) or die "ERROR: Could not reset file handle\n";

Re: Array, foreach problem

2010-05-05 Thread John W. Krahn
Akhthar Parvez K wrote: On Wednesday 05 May 2010, Shawn H Corey wrote: Brian wrote: foreach $line () { while (my $line = <$logfile>) would be a better idea than foreach $line. Just curious for an explanation to this. I tend to use foreach too. Don't they both accomplish the same thin

Re: Array, foreach problem

2010-05-05 Thread Rob Coops
On Wed, May 5, 2010 at 10:18 AM, Shlomi Fish wrote: > Hi Paul, > > a few comments on your code - so you'll know how to write Perl better. > > On Wednesday 05 May 2010 02:52:03 Paul Fontenot wrote: > > Hi, > > > > I'm stuck on using an array to determine the out come of a foreach loop. > > The scr

Re: Array, foreach problem

2010-05-05 Thread Akhthar Parvez K
On Wednesday 05 May 2010, Shawn H Corey wrote: > Brian wrote: > >> > >>> foreach $line () { > >> while (my $line = <$logfile>) would be a better idea than foreach $line. > >> > > > > Just curious for an explanation to this. I tend to use foreach too. Don't > > they both accomplish the sam

Re: Array, foreach problem

2010-05-05 Thread Akhthar Parvez K
On Wednesday 05 May 2010, Shlomi Fish wrote: > > Wouldn't there be any issues if we use same name for lexical filehandle and > > the scalar variable. Is Perl too intelligent to recognize both of them? > > There certainly would be, and I don't think Perl is that intelligent to > multiplex between

Re: Array, foreach problem

2010-05-05 Thread Shlomi Fish
On Wednesday 05 May 2010 17:20:25 Akhthar Parvez K wrote: > On Wednesday 05 May 2010, Shlomi Fish wrote: > > 2. Don't use bareword filehandles - use lexical ones: > > > > open(my $output, ">>", $output) or die "Could not append to output - $!"; > > Wouldn't there be any issues if we use same name

Re: Array, foreach problem

2010-05-05 Thread Akhthar Parvez K
On Wednesday 05 May 2010, Shlomi Fish wrote: > 2. Don't use bareword filehandles - use lexical ones: > > open(my $output, ">>", $output) or die "Could not append to output - $!"; Wouldn't there be any issues if we use same name for lexical filehandle and the scalar variable. Is Perl too intellig

Re: AW: Array, foreach problem

2010-05-05 Thread Shawn H Corey
Thomas Bätzler wrote: Brian asked: foreach $line () { while (my $line = <$logfile>) would be a better idea than foreach $line. Just curious for an explanation to this. I tend to use foreach too. Don't they both accomplish the same thing? :) "foreach ()" means that the whole file w

Re: Array, foreach problem

2010-05-05 Thread Shawn H Corey
Brian wrote: foreach $line () { while (my $line = <$logfile>) would be a better idea than foreach $line. Just curious for an explanation to this. I tend to use foreach too. Don't they both accomplish the same thing? :) Yes, but they go about it in different ways. The foreach lo

AW: Array, foreach problem

2010-05-05 Thread Thomas Bätzler
Brian asked: > >> foreach $line () { > > > > while (my $line = <$logfile>) would be a better idea than > > foreach $line. > > Just curious for an explanation to this. I tend to use foreach too. > Don't they both accomplish the same thing? :) "foreach ()" means that the whole file will

Re: Array, foreach problem

2010-05-05 Thread Brian
> > >> >> foreach $line () { > > while (my $line = <$logfile>) would be a better idea than foreach $line. > Just curious for an explanation to this. I tend to use foreach too. Don't they both accomplish the same thing? :) -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org Fo

Re: Array, foreach problem

2010-05-05 Thread Shlomi Fish
Hi Paul, a few comments on your code - so you'll know how to write Perl better. On Wednesday 05 May 2010 02:52:03 Paul Fontenot wrote: > Hi, > > I'm stuck on using an array to determine the out come of a foreach loop. > The script is below. > -

Re: Array, foreach problem

2010-05-04 Thread Uri Guttman
> "JG" == Jim Gibson writes: JG> On 5/4/10 Tue May 4, 2010 4:52 PM, "Paul Fontenot" JG> scribbled: JG> You need to reset LOGFILE to the beginning for subsequent JG> iterations over the @conditions array. As written, the nested JG> foreach will never be executed except for the fi

Re: Array, foreach problem

2010-05-04 Thread Paul Fontenot
Thank you very much On 5/4/2010 6:12 PM, Shawn H Corey wrote: Jim Gibson wrote: You need to reset LOGFILE to the beginning for subsequent iterations over the @conditions array. As written, the nested foreach will never be executed except for the first condition. Add the indicated seek call.

Re: Array, foreach problem

2010-05-04 Thread Shawn H Corey
Jim Gibson wrote: You need to reset LOGFILE to the beginning for subsequent iterations over the @conditions array. As written, the nested foreach will never be executed except for the first condition. Add the indicated seek call. The actual command is seek. See `perldoc -f seek` or http://per

Re: Array, foreach problem

2010-05-04 Thread Jim Gibson
On 5/4/10 Tue May 4, 2010 4:52 PM, "Paul Fontenot" scribbled: > Hi, > > I'm stuck on using an array to determine the out come of a foreach loop. > The script is below. > -- > -- > #!/usr/bin

Array, foreach problem

2010-05-04 Thread Paul Fontenot
Hi, I'm stuck on using an array to determine the out come of a foreach loop. The script is below. #!/usr/bin/perl # @conditions = ("NET", "eth"); $hostname = (`/bin/hostname`); $logfil