Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Array size issue

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

in reply to Array size issue

if($line =~ m/ on $ipaddress/) { if (scalar(@matches) <= 2){ push(@matches, $line); } else { exit(0); } foreach $line (@matches){ print "$line\n"; } }
This is where your trouble is. You probably meant to write it thusly:
if($line =~ m/ on $ipaddress/) { if (scalar(@matches) <= 2){ push(@matches, $line); } else { foreach $line (@matches){ print "$line\n"; } exit(0); } }

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

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

    That is not what I want. I want to save the line to the array if it matches the expression. I don't want to print anything this is just for debugging to make sure my array is containing the proper lines.

          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

        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;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://999145]
[Corion]: stonecolddevin: I think Jack White is highly regarded, but ...
[Corion]: ... I'm not really knowledgeable about good guitar players
[stonecolddevin]: I've been on a Stevie Ray Vaughan kick lately: https://www. v=wVjdMLAMbM0
[stonecolddevin]: Corion I haven't heard much of his work to be honest.
[erix]: here is a nice cover, stevieb
[planetscape]: hello, Corion
[Corion]: Hi planetscape!
[stevieb]: Corion I like the groundbreaking ones (guitar players). I have the ability to pick up on sounds that are groundbreaking or specific to a person, thanks to my years of doing recording/mixing/ sampling (hip-hop mind you, but years of it...
[stevieb]: ...has honed in my skills of recognizing sound
[stevieb]: All of the early members are coming out of the woodwork today :) Hey, planetscape

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2017-06-22 21:26 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (531 votes). Check out past polls.