in reply to Re: Specifying how many times a regex should work
in thread Specifying how many times a regex should work

Thanks for your help. I finally was able to get it to work with yoru first example but ran into *another* problem. I spent a few hours trying different methods to do this but nothing seems to work. The original script only saved the regex information to the variable but I need the entire contents of each separated data to be stored so I can use it again.

I'm only using regexes so I can resort the data. I'm trying to get the phone1, phone2, price, everything else in that order so I really need to store ALL of that paragraph stored so I can apply my s///s and other regexes to it.

Does this make any sense or am I in too deep and this won't ever work?

  • Comment on Re^2: Specifying how many times a regex should work

Replies are listed 'Best First'.
Re^3: Specifying how many times a regex should work
by BrowserUk (Patriarch) on Jun 05, 2004 at 21:20 UTC

    I'd tackle your original problem this way. I've used simplified regexes to demonstrate the technique. They seem to work pretty well on your original sample data, but you can adapt them to your needs.

    #! perl -slw use strict; local $/= "\n====\n"; while( <DATA> ) { ## Clear out residual values from global vars our( $no1, $no2, $price ) = ( undef ) x 3; tr[\n][ ]; ## Strip newlines ## Extract the cash value into $price s[ ( \$[\d,]+ (?:\.\d+)? ) (?{ $price = $^N }) ] +[ ]x; ## Grab the first 1 or 2 telephone numbers s[ ( [\d-]{12} ) (?{ $no1 ? $no2 = $^N : $no1 = $^N }) ] +[ ]xg; ## join them together in the requisite order and output print join ', ', $no1||'n/a', $no2||'n/a', $price||'n/a', $_; }

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail