Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Generating a List of numbers

by choroba (Canon)
on Feb 02, 2012 at 09:22 UTC ( #951391=note: print w/ replies, xml ) Need Help??


in reply to Re: Generating a List of numbers
in thread Generating a List of numbers

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:

#!/usr/bin/perl use warnings; use strict; my $tmpipaccountingfile = "tmpipaccountingfile"; my $DestDevice = "Box"; my %data; open my $TMPIPACCOUNTINGFILE, "<", "$tmpipaccountingfile" or die "$!"; while (<$TMPIPACCOUNTINGFILE>) { next if (/^(?:$|sh|\s*Source|^$DestDevice|Accounting)/); my @fields = split; push @{ $data{$fields[1]} }, [ @fields[0,2,3] ]; } close $TMPIPACCOUNTINGFILE; while (<DATA>) { print; chomp; for my $match (@{ $data{$_} }) { print join "\t", $match->[0], $_, @{$match}[1,2]; print "\n"; } } __DATA__ 10.2.9.2 10.2.9.3 10.2.9.6


Comment on Re^2: Generating a List of numbers
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2015-07-04 16:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls