Ekolet has asked for the wisdom of the Perl Monks concerning the following question:

Hi people, What i want to do is, create an empty array, scan a text with RegEx, and every time i get a match i want to insert it into my array. Any tips on this? Thanks in advance.

Replies are listed 'Best First'.
Re: Inserting elements into arrays
by roboticus (Chancellor) on Apr 18, 2012 at 16:01 UTC

    Ekolet:

    Yes, read perldocs perlintro, paying special attention to sections: "Files and I/O", "Regular Expressions", "Perl variable types" and "Conditional and looping constructs". There's enough there to get you on your way.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: Inserting elements into arrays
by choroba (Cardinal) on Apr 18, 2012 at 16:40 UTC
Re: Inserting elements into arrays
by JavaFan (Canon) on Apr 18, 2012 at 16:52 UTC
    It might be easier to just assign the result value to the array:
    my @array = $text =~ /pattern/g;
    This assumes the pattern doesn't contain parens though.
Re: Inserting elements into arrays
by aabi123 (Initiate) on Apr 19, 2012 at 09:18 UTC

    It may be use full for You...

    if ($text =~ /$pattern/) { push (@array , $text) ; }