Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Jul 2004 12:42:27 -0400 (EDT)
From:      "Steve Bertrand" <iaccounts@ibctech.ca>
To:        "Fernando Gleiser" <fgleiser@cactus.fi.uba.ar>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Perl split() question (OT)...
Message-ID:  <1870.209.167.16.15.1090600947.squirrel@209.167.16.15>
In-Reply-To: <20040723130007.V6864@cactus.fi.uba.ar>
References:  <1718.209.167.16.15.1090596743.squirrel@209.167.16.15> <20040723130007.V6864@cactus.fi.uba.ar>

next in thread | previous in thread | raw e-mail | index | archive | help
> 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
>




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1870.209.167.16.15.1090600947.squirrel>