Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^2: Regex help/ Lua parse

by marquezc329 (Scribe)
on Oct 26, 2012 at 21:24 UTC ( #1001138=note: print w/replies, xml ) Need Help??

in reply to Re: Regex help/ Lua parse
in thread Regex help/ Lua parse

Thank you for your detailed response.

Read and bookmarked perlstyle.

$line =~ /^\s*names\s*=\s*{\s*([^}]+)/; (my $names = $1) =~ y/" //d; my @tags = split /,/ => $names;

^ I figured that my original method could be reduced, but I couldn't seem to figure out how to go about it. This is definitely a much more elegant solution. Thank you for your reference to Quote-Like-Operators. I do have a question though about:

(my $names = $1) =~ y/" //d;
I have seen this construct before on PerlMonks. I did a search and found Use of parentheses around a variable, but wasn't sure how it applied to regexps. Is there a specific name for this method of assignment that I can use to better my search results?

Concepts are easily read, but I feel like I learn most by having my code reviewed by the talented and experienced monks. Thank you again for taking the time out to provide guidance in my learning.

Replies are listed 'Best First'.
Re^3: Regex help/ Lua parse
by kcott (Chancellor) on Oct 27, 2012 at 04:55 UTC

    I don't think that construct has a specific name - it's just using parentheses to change precedence. Usage examples for s/// can be found in Regexp Quote-Like Operators; examples for y/// (although its synonym tr/// is used in these examples) can be found in Quote-Like Operators.

    In Perl 5.14.0, an r option was introduced (see perl5140delta under Core Enhancements - Regular Expressions - Non-destructive substitution). This makes the following equivalences:

    # For y/// (my $x = $y) =~ y///; my $x = $y =~ y///r; # Ditto for its synonym tr/// (although not mentioned in perl5140delta +) (my $x = $y) =~ tr///; my $x = $y =~ tr///r; # And for s/// (my $x = $y) =~ s///; my $x = $y =~ s///r;

    The first two links above are for the current Perl version (5.16.0 at the time of writing) so they have examples of this also.

    -- Ken

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1001138]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2018-03-19 01:57 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (231 votes). Check out past polls.