in reply to Large File Parsing

my @items; foreach my $key (keys %hash){ push(@items,$key); }

Or simply:

my @items = keys %hash;


my $rxMatchItems; { local $" = q{|}; $rxMatchItems = qr{(?:@items)}; }

Or simply:

my $rxMatchItems = do { local $" = q{|}; qr{(?:@items)} };


Because your %hash is empty your pattern match becomes:

$ perl -le'my @items; my $rxMatchItems = do { local $" = q{|}; qr{(?:@ +items)} }; print $rxMatchItems' (?-xism:(?:))

And the pattern (?-xism:(?:)) will match everything.

Replies are listed 'Best First'.
Re^2: Large File Parsing
by Anonymous Monk on Jan 03, 2010 at 05:36 UTC
    my $rxMatchItems = do { local $" = q{|}; qr{(?:@items)} };

    Oh noes :)

    my $rxMatchItems = join '|', map quotemeta, @items; $rxMatchItems = qr/$rxMatchItems/;

      I'm guessing from the variable name and the use of quoting constructs that the OP grabbed that bit of code from one of my solutions, probably one where @items contained values known not to need quotemeta'ing. Invariable application of quotemeta without any consideration of whether it is necessary is just another form of cargo cult programming. I don't think we can tell from the OP's code whether it is required or not. Even if it is required, the do block construct is as valid as using join.

      my $rxMatchItems = do { local $" = q{|}; qr{(?:@{ [ map quotemeta, @items ] })}; };

      Cheers,

      JohnGG