in reply to Re: Path to enlightment
in thread Path to enlightment

OK, I ++'d KM for his answer, since it gives what was asked for -- a hint. Slightly more than a hint:

# FILE is open for read, OUTPUT is open for writing while (<FILE>) { s/^(\d+:)//; # take $_, replace one or more # digits at the beginning of the line #followed by a : with #nothing print OUTPUT; }

Note: that may not be exactly what you want; for how to change it, see KM's first reference. 'Course, there's some one-liner goodness to be had here too (you can do this on the command line with one -- albeit complex -- command. For that, see:

perldoc perlrun

Specifically, the -p switch).

Good luck!

Philosophy can be made out of anything. Or less -- Jerry A. Fodor

Replies are listed 'Best First'.
Re: Re: Re: Path to enlightment
by KM (Priest) on Jan 23, 2001 at 23:48 UTC
    s/^(\d+:)//;

    Minor nit.. you don't need to do the grouping. And, although he didn't say it he may also want the whitespace removed after the colon.

    s!^\d+:\s+!!;

    Cheers,
    KM

      s!^\d+:\s+!!o;
      I added the o modifier, since the pattern doesn't change, may as well compile it once for the loop.

      The o modifier is a no-op on a regex that doesn't contain any interpolated variables, BTW.

              - tye (but my friends call me "Tye")
        Whoops, you are correct. The /o would be a no-op. This is what happens when you are doing ten things at once :)

        Cheers,
        KM

      The 'o' modifier on your regexp is useless as it applies to regexp's that contain variables in them. From the Camel

      PATTERN may contain variables, which will be interpolated (and the pattern recompiled) every time the pattern search is evaluated....mentioning /o constitutes a promise that you won't change the variables in the pattern. If you do change them, Perl won't even notice.