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

Re: divide one file into multiple arrays

by LanX (Canon)
on Jun 25, 2013 at 17:33 UTC ( #1040635=note: print w/ replies, xml ) Need Help??


in reply to divide one file into multiple arrays

> print "@bad_log\n"; #currently returns entire $log

The code is fine╣, I suppose your @sites have an empty string or so, which always matches!

try pushing the regex too, to see what matches in the dump of @bad_log.

push @bad_log, [$_,$site] if ($_ =~ /$site/);

By the way you'll get multiple entries per line if different sites match!

Cheers Rolf

( addicted to the Perl Programming Language)

╣) in the sense of "it works", not in the sense of "well coded" =)


Comment on Re: divide one file into multiple arrays
Select or Download Code
Re^2: divide one file into multiple arrays
by tevus_oriley (Novice) on Jun 25, 2013 at 17:51 UTC
    That was it! the last line in the list of sites was a blank line. Its always something silly, Thanks Rolph
      here some suggestions to improve your code

      use strict; use warnings; use Data::Dumper qw(Dumper); my @sites=qw/ www.yahoo.com www.google.com www.comcast.com /; my @bad_log; LINE: while (my $line = <DATA>) { my $www = (split / /,$line)[5]; foreach my $site (@sites) { next if $site eq ""; if ( $www =~ /\Q$site/ ) { push @bad_log, $line; next LINE; } } } print Dumper \@bad_log; __DATA__ X456 TV-yes DB-no 123.12.23.45 dealio3 www.google.com-------- FX-yes d +53 Y-03 X123 TV-yes DB-yes 34.154.43.21 dealio1 www.ask.com-------- FX-no d01 +Y-03 X412 TV-no DB-no 192.365.25.23 rayovac2 www.microsoft.com--- FX-yes d1 +3 Y-07

      Cheers Rolf

      ( addicted to the Perl Programming Language)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2015-07-01 22:06 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 (24 votes), past polls