RExp matchs many times,how can i get the matched content?

Discussion in 'Perl Misc' started by firenet, Jul 25, 2006.

  1. firenet

    firenet Guest

    #!/usr/bin/perl -w
    undef $/;
    $buf=<>;
    print foreach($buf =~/<img>(.*?)<\/img>/sg);

    By the program above , i can print the content i wanted;but i want to
    get it directly.
    What should i do? Thanks.
    firenet, Jul 25, 2006
    #1
    1. Advertising

  2. firenet

    firenet Guest

    thanks a lot. i'm newbie for perl , so i didn't recognize that is a
    array.
    Aukjan van Belkum wrote:
    > firenet wrote:
    >
    > > print foreach($buf =~/<img>(.*?)<\/img>/sg);

    >
    > my @array = ($buf =~/<img>(.*?)<\/img>/sg);
    >
    > > By the program above , i can print the content i wanted;but i want to
    > > get it directly.

    >
    > You are traversing an array with 'foreach', you should have then noticed
    > that you could also just assing this array to another array...
    >
    > Aukjan
    firenet, Jul 25, 2006
    #2
    1. Advertising

  3. firenet

    Ben Morrow Guest

    Quoth Aukjan van Belkum <>:
    > firenet wrote:
    >
    > > print foreach($buf =~/<img>(.*?)<\/img>/sg);

    >
    > my @array = ($buf =~/<img>(.*?)<\/img>/sg);
    >
    > > By the program above , i can print the content i wanted;but i want to
    > > get it directly.

    >
    > You are traversing an array with 'foreach', you should have then noticed
    > that you could also just assing this array to another array...


    It's not an array, it's a list.

    Ben

    --
    The cosmos, at best, is like a rubbish heap scattered at random.
    Heraclitus
    Ben Morrow, Jul 25, 2006
    #3
  4. firenet

    -berlin.de Guest

    Aukjan van Belkum <> wrote in comp.lang.perl.misc:
    > Ben Morrow wrote:
    >
    > >
    > > It's not an array, it's a list.
    > >

    > ok: s/array/list/gs


    The /s modifier has no effect, it shouldn't be there.

    Anno
    -berlin.de, Jul 26, 2006
    #4
  5. Aukjan van Belkum <> wrote:
    > Ben Morrow wrote:
    >
    >>
    >> It's not an array, it's a list.
    >>

    > ok: s/array/list/gs

    ^
    ^

    A useless use of a regex modifier.

    s/array/list/g


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Jul 26, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?bWF2cmlja18xMDE=?=

    SetAuthCookie works some times and fails some times?

    =?Utf-8?B?bWF2cmlja18xMDE=?=, Mar 23, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    498
    =?Utf-8?B?bWF2cmlja18xMDE=?=
    Mar 23, 2006
  2. =?Utf-8?B?bWF2cmlja18xMDE=?=

    Forms Authentication Fails some times and not some times???

    =?Utf-8?B?bWF2cmlja18xMDE=?=, Mar 28, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    483
    =?Utf-8?B?bWF2cmlja18xMDE=?=
    Mar 28, 2006
  3. djskrill
    Replies:
    9
    Views:
    687
    djskrill
    Oct 1, 2003
  4. Peng Yu
    Replies:
    17
    Views:
    672
    Peng Yu
    Sep 14, 2008
  5. Jack Steven
    Replies:
    2
    Views:
    416
    Chris Rebert
    Mar 9, 2009
Loading...

Share This Page