> On Fri, 23 Jul 2004, Steve Bertrand wrote:
>
>> Perl hackers -- Figured someone would have a reasonably quick, easy
>> answer
>> for this:
>>
>> I am trying to read through a file, line-by-line, and I want to extract
>> the text in between the [ and ] characters.
>
> This is a job for......capturing parens!!!
>
> Try this:
>
> if ($_=~/\[(.+)\]/) {
>       $var=$1;
> }
>
> $1 would be the string matched by the regex between ( and )
>

Absolutely perfect!! This worked excellent:

while ($_ = <LOGFILE>) {
        if ($_ =~ /$struct/ && $_ =~ /$structStart/) {
                if ($_ =~ /\[(.+)\]/) {
                        $string = $1;
                        print "$string -- $struct$structStart\n";
                        # ... do other stuff, snipped
                }
        } else {

Thank-you so much!

Steve

>
>
>                       Fer
>


_______________________________________________
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to