in reply to Re: Re: Regular Expressions to ignore lines starting with #
in thread Regular Expressions to ignore lines starting with #

and i would do it like this:

s/#.*$//; next if /^$/;

to remove any comment (up to end of line) and skip if there's nothing left. but this might be stretching the requirement a bit.

Replies are listed 'Best First'.
Re: Re: Re: Re: Regular Expressions to ignore lines starting with #
by sauoq (Abbot) on May 19, 2003 at 20:22 UTC
    s/#.*$//; next if /^$/;

    That'll probably bite you eventually. Consider these lines from an imaginary configuration file:

    # Set the format for currency: currency_format = '$###.##';

    Skipping comment-only lines right off the bat is an optimization. Other lines will probably require smarter parsing.

    Even if the file format guaranteed that your method could be used safely, I wouldn't use it. Why do an expensive substitution on lines you are going to throw out? I'd do it like this:

    next if /^\s*#/; s/#.*$//;

    We've probably strayed quite a bit from the OP's needs though.

    -sauoq
    "My two cents aren't worth a dime.";