Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: divide one file into multiple arrays

by LanX (Chancellor)
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" =)

Replies are listed 'Best First'.
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/ /; 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 dealio3 FX-yes d +53 Y-03 X123 TV-yes DB-yes dealio1 FX-no d01 +Y-03 X412 TV-no DB-no 192.365.25.23 rayovac2 FX-yes d1 +3 Y-07

      Cheers Rolf

      ( addicted to the Perl Programming Language)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1040635]
[ambrus]: Sometimes it's easier to just match elements in ways other than xpath, like directly with perl code.
[marto]: this is a cheap hack, a script that doesn't need to run for long, using WWW::Mechanize:: Firefox to drive some awful interface.
[marto]: if it were anything more serious I'd spend more time looking into it properly :P

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2016-12-08 10:58 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (140 votes). Check out past polls.