in reply to Re^4: getting ancestors of element
in thread getting ancestors of element

I think it should be unless($e), not unless(/$e/). When this change is made the code runs well. Please consider using the here file syntax for test scripts as it makes it easier to test them:

my @l = << 'END'; aaaa bbbb END

Thanks!

Replies are listed 'Best First'.
Re^6: getting ancestors of element
by jccunning (Acolyte) on Sep 08, 2012 at 21:05 UTC
    I discovered that $1 is sometimes undefined on lines 381 and 394 when calling ret_ancestors and caused the error. Need to rethink my logic in the For loop on line 349.
Re^6: getting ancestors of element
by jccunning (Acolyte) on Sep 08, 2012 at 22:18 UTC
    I discovered my problem is in regex
    $tname =~ m/[declaration_]?name="(\w+[:]?.\w+[:]?.\w+);
    where I am trying to extract the value of the name attribute which could be single word all lowercase or all uppercase, could also be Panoply::Blah or Panoply::Blah::Blah2 or have special character in name such as ~BAR In script $tname would contain something like
    all_members name="~BAR" protection="public" scope="Panoply::BAR"
    Also noticed from test that passing ~BAR in the argument $1 in
    ret_ancestors sub {@list = join(" => ", @_)}, $nitemstr, $1;
    Does not return a list because of ~ character. Any help with regex appreciated.
      Fixed it everything appears to work now with this regex
      $tname =~ m/[declaration_]?name="(.*?)"/;
        I don't think so
        use YAPE::Regex::Explain; print YAPE::Regex::Explain->new( qr/[declaration_]?name="(.*?)"/ )->explain; __END__ The regular expression: (?-imsx:[declaration_]?name="(.*?)") matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- [declaration_]? any character of: 'd', 'e', 'c', 'l', 'a', 'r', 'a', 't', 'i', 'o', 'n', '_' (optional (matching the most amount possible)) ---------------------------------------------------------------------- name=" 'name="' ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- .*? any character except \n (0 or more times (matching the least amount possible)) ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- " '"' ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------

        http://perldoc.perl.org/perlintro.html#Regular-expressions/perlrequick