in reply to Help with regex

Adding some test data:
use List::Util 'shuffle'; my @fileData = shuffle map { "$_\n" } 1 .. 20, (1) x 5; my $linenumber=1; foreach my $line(@fileData) { $linenumber=$linenumber+1; if ($line =~ m/^1$/) { print "$linenumber\n"; } }

Output:

6 7 8 16 17 25

Are you sure you're reading your data correctly?

Replies are listed 'Best First'.
Re^2: Help with regex
by ChuckularOne (Prior) on Sep 28, 2007 at 16:40 UTC
    My data must be something other than what I think it is. I'll revisit it. Thanks.
      You might try m/^1\s*$/ for your regular expression.
      -- gam3
      A picture is worth a thousand words, but takes 200K.

      How are you populating your @fileData array? Is there any reason not to iterate over the filehandle directly?

      use strict; use warnings; my $infile = 'whatever'; open my $fh, '<', $infile or die "Couldn't open '$infile' for read: $! +\n"; while ( my $line = <$fh> ) { print "$.\n" if $line =~ m/^1$/; }