in reply to using a regex to determine if a string is the start of the FILE

Something like:

my $re = qr/(?<=\S)\s*\n"99","END"/sm;

Perl reduces RSI - it saves typing
  • Comment on Re: using a regex to determine if a string is the start of the FILE
  • Download Code

Replies are listed 'Best First'.
Re^2: using a regex to determine if a string is the start of the FILE
by ftumsh (Scribe) on Sep 18, 2008 at 12:27 UTC
    Will this still work bearing in mind that the file isn't slurped or binmoded so the line with the "99"..... will always be at the start of the line ie no preceding chars to look back at?

      Ah, that makes it a little more interesting and experimental. Try:

      /(??{ $. == 1 ? '"99","END"' : '(?=x)(?=X)' })/

      Perl reduces RSI - it saves typing

        Thanks for that. I used:

        /(??{ $. == 1 ? '"99","END"' : 'FOOBAR' })/

        Which also didn't work due to tainting. However, I managed to get the code to be changed, but not in the regex area which might have broken something (it's very old and no test packs), to have

        <code>use re 'eval';<code>

        Which works well, so, thank you all for your time

        John
Re^2: using a regex to determine if a string is the start of the FILE
by ftumsh (Scribe) on Sep 18, 2008 at 12:18 UTC
    My apologies. In another part of the code, which I didn't post the compile statement looks like:
    my $rx = qr/$_/;

    and I can't change that either. I do believe there is a way to put modifiers into a regex tho, I'll have a poke around in perlretut

      Yes you can, (?ms:$regex).

      Note that the scoping of /m inside the regex changed between perl 5.8.8 and perl 5.10.0.