Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Perl has a lot of features that are not immediately obvious to the casual observer. By "casual observer," I mean someone who sees the language "in the wild" but hasn't formally learned it. Think of the programmer who learns it by opening up some working Perl and modifying it.

Consider, as an example, split. Here's a typical invocation:

my @fields = split /:/, $record;

To the casual observer, there are three things that go with split: a record, a field separator, and someplace to put the separated fields. One could see a lot of Perl without ever seeing any variation on this usage.

Nevertheless, there are a lot of possible variations.

  • The $record is optional and defaults to $_.
  • The field separator is also optional and defaults to a special form of splitting on white space (leading white space is ignored).
  • The field destination is optional too. If split is used in a scalar (or void) context, fields go into @_ (clobbering your sub arguments, if you have any). If you have warnings on, you may also learn that, "Use of implicit split to @_ is deprecated."
  • There's an optional third argument (a number) that limits how many fields split is allowed to return.
  • If the field separator contains capturing parentheses, whatever is captured in them will be returned as a field.
  • If the field separator is a single space (' '), it invokes the special white space splitting feature that you get with no arguments.

Those are just the ones I know off the top of my head. A look at the split documentation shows other interesting special cases that I'm pretty sure I've never run into. I know at least some of the features I've listed above were present in Perl 4, and yet they still feel to me like afterthoughts.

(A better example of an "afterthought feature" might be the (?xxx) style features in modern regular expressions. Why do they always start with an open parenthesis and a question mark? I've always assumed it's because that would have been a syntax error in earlier versions of Perl. No earlier code could have been relying on (?xxx) to do anything meaningful, so it's safe to have later code use it for features the earlier Perl didn't have. Now we have lots of different things introduced by an open parenthesis and a question mark.)

I like these extra features. It's fun, like discovering a pocket you didn't know you had in a garment you've worn for years. Still, I wonder sometimes if Perl's casual observers are put off by these things. My guess is that it depends on one's attitude. Some are (as I am) delighted by discovering something new in something old. Others may be dismayed that they did not know the language as well as they thought and may even despair that they'll never master it as they'd like.

I think this is why the Perl community is so important. The monks welcome newcomers and guide them through the language. Experts can show the inexperienced what's in the dark corners and tell them when and why to go there. There are pitfalls, but at the Monastery, there's usually someone hanging around to direct the unwary away from them. In these and other efforts, the monks demonstrate an attitude that delights in discovery so that those without that attitude may witness it, learn of it, and perhaps take it as their own.

In reply to Special cases make special community by kyle

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2023-03-22 03:35 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (60 votes). Check out past polls.