Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: RFC - Regular Expressions Tutorial, the Basics (for BEGINNERS)

by ww (Archbishop)
on Jan 22, 2007 at 19:11 UTC ( #595968=note: print w/replies, xml ) Need Help??

in reply to Regular Expressions Tutorial, the Basics (for BEGINNERS)

brusimm, this seems a good start; even meritorious!

      ...sufficiently so that I hope I will not offend with observations on a few things that seem to me to be shortcomings. So, if you care,

You seem to be a bit categorical when, even in the context framed by your RFC, you might do better to qualify remarks. For example,

"Patterns are used to locate text strings within text lines."
... to which I say, 'yep, but also across line-endings and not necessarily only for what the target audience might consider a "text string"

I would urge great care in language in comments, as well. For example, in "example 1"

004:   print "There, brus showed up.\n" ; # if the pattern is found, print it!
You mileage may vary, but I read the comment as at least mildly MISleading because of what I see as potential confusion on the reader's part between the hardcoded output "brus showed up" and the captured "brus"

BTW, here or, at latest, the next section might be the time, despite the added complexity entailed, to introduce the wisdom of testing whether a match actually DID succeed.

# Possible revision, example 1 $_ = "I logged in as brusimm and found that I had email."; # Test s +tring if (/brus/) { # Patter +n: brus print "There, our pattern showed up in our string.\n" ; # Tell u +ser } else { print "No match in our string for our pattern.\n"; # As you +'ll see... }
where the truncated comment might be used to foreshadow a later segment of your tut that demonstrates the dangers of using a presumed but untested match.

I hold (again, YMMV) that economy of language helps the reader to understand.

Hence, IMO,

Lets say we knew whoever wrote the line, had issues with typing, for example, I had too much coffee and wrote the following:
might better be phrased (trying not to impose too much of a nitpicker's editor's judgement on your bid to be "user friendly):"
Let's say I'd had too much coffee, and might have mis-typed the test string.

I'd also urge greater care (or, perhaps, selectivity) in language such as:

Notice the control character of s before the forward slash. Check it out with this script:

001: # example 3
002: #
003: $_ = "I logged into bruuuusimm and saw I had email.\n"; # original error
004: print $_ ; # printing proof of error
005: if (s/bru*s/brus/) { # fixing it
006: ....

While your reference to the "s" before the slash as a "control character" is arguably CORRECT, as a tutor you may want to consider your audience's preconceptions/prior knowledge/frame of reference. Many who are new to regexen may have sufficient computer experience to simply slide over a semi-familiar phrase, confident in a preconception that a "control character" is a byte in the range 0-0x20; something quite different than what you intend.

I could go on a bit more, but perhaps this is a better time to simply offer the thoughts that:
1. Very few are their own best editors.
2. Work with someone whose language skills rival your coding skills.

  • Comment on Re: RFC - Regular Expressions Tutorial, the Basics (for BEGINNERS)
  • Download Code

Replies are listed 'Best First'.
Re^2: RFC - Regular Expressions Tutorial, the Basics (for BEGINNERS)
by MidLifeXis (Monsignor) on Jan 24, 2007 at 19:20 UTC

    Additionally, within your statement of Notice the control character of s before the forward slash, you are using multiple slashes in the statement, and each of them is preceeded by an 's'. This could be misleading.

    Great start, however.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2017-10-23 09:06 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (277 votes). Check out past polls.