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

why doesnt this work?
$xtemplate = "stuff i want to be in the first element of @template *** +*filename.ext****"; my @template = $xtemplate =~ /(.*?)\*{4}filename.ext\*{4}/s; why wont @template =("stuff i want to be in the first element of @temp +late ")

Replies are listed 'Best First'.
putting regex results into an array. (boo)
by boo_radley (Parson) on Aug 23, 2001 at 23:13 UTC
    your regex works (you can verify this by looking at the contents of $1), but you're not putting it into @template correctly.

    try this syntax, which forces the results of the regex into the proper context through the use of the outermost set of parens : @template = ($xtemplate =~ /(.*?)filename.ext\*{4}/s);

      1 - Yes, the regex works fine, but so does all of the code. I.e., I see nothing wrong with the context, but maybe I'm not grokking something. I threw parentheses around the *{4}filename.ext*{4} portion of the regex and it was stored in the array properly, too.

      2 - Perhaps maddfisherman was looking in $template1 instead of $template[0] ?

      apprentice
        One thing I missed the first look, you need to escape the "@template" in the string like this "\@template" else your string, and hence the first element of @template will not have "@template".

        apprentice