maddfisherman has asked for the wisdom of the Perl Monks concerning the following question:

how do you gather all the characters starting with the fist char in a file untill say 4 * in a row, this is what i came up with, i want to make sure it keeps the very first char.
$data = $fileinfo =~ /^(.*?)\*{4}/sg;

Replies are listed 'Best First'.
Re: regex ???
by dragonchild (Archbishop) on Aug 23, 2001 at 17:20 UTC
    Ok. First off, a general suggestion - don't use something unless you need to. Why is this important? Cause you're using the /g modifier. You don't need it.

    The second thing is that your expression needs to be

    my ($data) = $fileinfo =~ /^(.*?)\*{4}/s;
    You need to localize $data (if you want to be strict-compliant, which is a "Good Thing"(tm) ...). You also need to put $data in array context, because the match-regex returns a list, not a scalar.

    ------
    /me wants to be the brightest bulb in the chandelier!

    Vote paco for President!

Re: regex ???
by Monky Python (Scribe) on Aug 23, 2001 at 10:48 UTC
    please, could you give us an small example (data and result)

    MP