Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^3: Array size issue

by blue_cowdawg (Monsignor)
on Oct 15, 2012 at 18:45 UTC ( #999150=note: print w/replies, xml ) Need Help??

in reply to Re^2: Array size issue
in thread Array size issue

      That is not what I want.

Sorry.... could have fooled me considering the logic in your original post.

If I break your code down into pseudo-code it reads like this:

    open a pipe to the tail -f command for a logfile (unnamed)
    iterate over the pipe
      if less than 3 files are in array
        if the line matches a (undetermined) IP address
          push the line into an array
          exit the program
      Iterate over the contents of the array
        print line

Part of the art of getting good answers on Perl Monks is being concise about your questions and not leaving what you are after up to the interpretation of the reader.

Once again I will attempt to extrapolate what you are after. You code will work better if you don't put the print lines in and change the exit for last.

Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Replies are listed 'Best First'.
Re^4: Array size issue
by hmb104 (Sexton) on Oct 15, 2012 at 19:03 UTC

    I apologize for not being clear and I do appreciate all the valuable input I get from this community.

    Without the print statement I will not be able to debug my code. I want to make sure my array is carrying the proper line/data before attempting to process it. This is what I got after reading all the comments. I think I'm missing a small piece and I can't figure it out.

    open my $tailf, "tail -f $logFile |" or die; while (<$tailf>) { chomp; my $line = $_; if($line =~ m/ on $ipaddress/) { if (scalar(@matches) <= 2){ push(@matches, $line); } else { last; } } } foreach $line (@matches){ print "$line\n"; } close $tailf;

      myself I'd rewrite two of your "ifs."

      next unless ($line =~ m@on $ipaddress@); last if scalar(@matches) >= 2;
      At least to my eye that's more readable.

      Peter L. Berghold -- Unix Professional
      Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://999150]
[perldigious]: Also coincidentally, I'm currently in the middle of a winter storm that has dropped 1 foot of snow and is expected to drop another. I might have to adapt this for customers/vendors who come visit and put it at the beggining of every presentation I give.
[Discipulus]: the photo was removed... Cyrano de Berjerac was not of the same idea..
[stevieb]: perldigious: video near our hq in Montreal. Here in Calgary, it's -28c... we've only got 3" of snow so far, but there are several feet in the mountains already
[perldigious]: Snowshoeing time stevieb? I need to buy a pair so I can walk my German Shepherd properly through the country.

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2016-12-06 16:28 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (112 votes). Check out past polls.