Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Generating a List of numbers

by mlebel (Hermit)
on Feb 02, 2012 at 02:59 UTC ( #951330=note: print w/ replies, xml ) Need Help??

in reply to Generating a List of numbers

I read the post "I know what I mean. Why don't you?" so based on that I will re-write this again.(i'm really not sure how short i can keep it but i will try).

I fixed a part of my problem. I needed to open the "tmpipaccountingfile" during the outer loop and close it right after the end of the second loop.

I shrunk the "tmpipaccountingfile" to this:

Source Destination Packets Bytes 5 504 33 15941 14 3416 14 3404 57 39207 84 8006 Accounting data age is 0w1d Box#

And i put the rest of the data within the script which looks like this:

#!/usr/bin/perl use warnings; use strict; my $tmpipaccountingfile = "tmpipaccountingfile"; my $DestDevice = "Box"; foreach my $OuterData (<DATA>) { print "OuterData = $OuterData"; open TMPIPACCOUNTINGFILE, "<", "$tmpipaccountingfile"; foreach my $Line (<TMPIPACCOUNTINGFILE>) { chomp $Line; next if ($Line =~ m/^sh/); next if ($Line =~ m/^\s*Source/); next if ($Line =~ m/^$DestDevice/); next if ($Line =~ m/^Accounting/); next if ($Line =~ m/^$/); next unless ($Line =~ m/^\s*\d*.\d*.\d*.\d*\s*$OuterData/); print "Line = $Line\n\n"; } close TMPIPACCOUNTINGFILE; } exit; __DATA__

Now this mostly works. The new problem that I am running into now, is that I don't get any output with the script like this. But if i replace the line "next unless ($Line =~ m/^\s*\d*.\d*.\d*.\d*\s*"$OuterData"/);" with "next unless ($Line =~ m/^\s*\d*.\d*.\d*.\d*\s*""/);" for example, I will get the following output:

OuterData = Line = 84 8006 OuterData = Line = 84 8006 OuterData = Line = 84 8006

I beleive that this proves that it works but it's not what I am looking for. The output that I am expecting to see with the code that I provided is this:

OuterData = Line = 5 504 Line = 33 15941 OuterData = Line = 14 3416 Line = 14 3404 Line = 14 3404 Line = 57 39207 OuterData = Line = 84 8006

I hope that this is clear because I have no clue how to simplify it any further.

Aaron, I will be going to read up on hash array's since it seems that it's probably the way to achieve this from what I gather from all the posts. From what you said, it sounds like what I am looking for and if I need a hash to acheive this, how would that be written?

The results of each ip groups found would ultimately be pushed to an array for some calculations to be done for each ip's individually. I say this incase it influences any code that you might provide

Now, I must say that you guy's are pretty tough, but it's ok, I have thick skin and I am learning in the process to become a better programmer. so thank you.

So, lastly, how do i fix this?

Comment on Re: Generating a List of numbers
Select or Download Code
Replies are listed 'Best First'.
Re^2: Generating a List of numbers
by choroba (Canon) on Feb 02, 2012 at 09:22 UTC
    You are not chomping $OuterData. Therefore, it contains a newline at the end which prevents it from matching in the regular expression.
    Update: Looping over the file several times makes your algorithm very slow if the file is big. Using a hash, you can avoid this problem:

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://951330]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2015-12-02 00:42 GMT
Find Nodes?
    Voting Booth?

    My keyboard shows this many letters:

    Results (31 votes), past polls