Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re^6: Regex help/ Lua parse

by marquezc329 (Scribe)
on Oct 27, 2012 at 18:52 UTC ( #1001222=note: print w/replies, xml ) Need Help??

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

Aaah. I see. It seems much more obvious to me with the reduced regexes. I've never used such extensive regexes and I think I may have been letting myself get overwhelmed and distracted by the length and complexity of these statements in comparison to the shorter more basic code I've been learning with. So in essence,
if (x = y) { print x; }
and, in simple situations
if (x = y) { print x; }
are ok, but
if (x = y) { print x; }
is not. In this stripped down form I can see how the last example, although interpreted properly by Perl, can look like a random  if (x = y) and an unrelated block of { print x; }. I'm not entirely sure of what kind of examples you are asking for, but from this node:
if ($Age < 13) && ($Age > 0)) { print "What are you doing here, $firstName? This Web site is strictly PG-13. Shame on you for being so naughty as to come here!"; } elsif ($Age < 18) && ($Age > 12)) { print "Not to long ago, we’d have have chased you away from our Web site. But now that you’re a teenager and mature enough for PG-13 materials, we’re glad to see you $firstName."; }
has the same qualities as my code and could be cleaned up (focusing on the indentation and curly braces) by saying:
if (($Age < 13) && ($Age > 0)) { print "content"; } elsif (($Age < 18) && ($Age > 12)) { print "content"; }
or even:
if (($Age < 13) && ($Age > 0)) { print "content"; } elsif (($Age < 18) && ($Age > 12)) { print "content"; }
Thank you again for taking time out to help me grasp the fundamentals. Please let me know if I am missing your point. I enjoy Perl (and learning programming in general) and feel I have been progressing rather quickly, but I want to squash bad habits and form a good foundation in style and understanding before moving to some of the more complex concepts and modules in Perl.

Replies are listed 'Best First'.
Re^7: Regex help/ Lua parse
by kcott (Chancellor) on Oct 28, 2012 at 07:42 UTC

    Another book you may be interested is Perl Best Practices Standards and Styles for Developing Maintainable Code. Amongst all its other good advice, this has an entire chapter devoted to guidelines for code layout.

    Be aware that this book provides guidelines; not rules. Also, as it was released in 2005, it won't make references to features added in more recent versions of Perl (perlhist provides a history of Perl releases, if you're interested).

    -- Ken

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1001222]
[choroba]: I fear there's no other way than patch

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2018-01-24 10:52 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (257 votes). Check out past polls.