Hi There,

In asking my question for clarification I belive I have answered myself but anyway:

Can I have some clarification on the wonderful line:

my %prices = $str =~ m/((?:$animal)s?)\s(?:is|are)\s(\$\d+)/g;
As I understand it the brackets are use to return the values as $1, $2 .. $9

It looks like (?: .. ) is something special and is not returning a numbered variable so all we get out are two variables $1 and $2 used respectively in the hash as the key and value?

I have often wanted to check to see if a string contains one of multiple sub-strings.. I assume I could do it like this:

use strict; my $something = 'This is a bang of a bing thing'; if($something =~ m/((?:bing|bong|bang))/i) { print "Found '$1' in '$something'\n"; }
Woo Hoo!
Found 'bang' in 'This is a bang of a bing thing'
It returned the first one found.. which is fair.. I wonder if this could return all matches found, in this case 'band' and 'bing'?

And could I check for a string contain anything from a list?

... my @list = qw / bing bong bang /; if($something =~ m/(?:@list)/i) ...
naturally does not work :-(

thanks

___ /\__\ "What is the world coming to?" \/__/ www.wolispace.com

In reply to Re: Re: Another regexp question by wolis
in thread Another regexp question by carric

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.