http://www.perlmonks.org?node_id=181638


in reply to Re: Re: Storing Substitution Output String
in thread Storing Substitution Output String

Printing the scalars (and adding the add'l text and tags at that point) allows me to print only the first instance of each match, Little. How would you suggest printing all of the matches made?
  • Comment on Re: Re: Re: Storing Substitution Output String

Replies are listed 'Best First'.
Re: Re: Re: Re: Storing Substitution Output String
by little (Curate) on Jul 14, 2002 at 20:08 UTC

    say your text is in a string (or an array of strings) then I would use grep and map :-) to get a list of all matches nicely formatted as list items, but for sure there is an easier way which refuses to come to my mind now :-)

    perhaps this might do :-)

    # the substitution is none in effect, it just digs around $page2 =~ s|<title>(.*)</title>|${my_count(\$1)}|gi; my matches = (); sub my_count { my $occurance = shift; push @matches, ${$occurance} ; return $occurance; } # see what we've got foreach (@matches) { print '<li>'.$_.'</li>'."\n"; # just to format the output :-) }

    Have a nice day
    All decision is left to your taste

    Update

    fixed stupid error in the substitutional part where I inserted the '<title>' again.

Re: Re: Re: Re: Storing Substitution Output String
by bob (Novice) on Jul 15, 2002 at 21:55 UTC
    You see there might be a dozen matching patterns in each document, Little. And I want to print all of the matches with the additional text added.
Re: Re: Re: Re: Storing Substitution Output String
by bob (Novice) on Jul 15, 2002 at 22:02 UTC
    I may be missing replies..... Never used this board before, and now I see replies that aren't showing up in the thread.... Ok, fixed my thread depth.... I'm taking a look at your latest suggestion now, Little.