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

Re^2: Why split function treats single quotes literals as regex, instead of a special case?

by likbez (Sexton)
on Aug 14, 2020 at 19:29 UTC ( [id://11120739]=note: print w/replies, xml ) Need Help??


in reply to Re: Why split function treats single quotes literals as regex, instead of a special case?
in thread Why split function treats single quotes literals as regex, instead of a special case?

The balkanization of built-in functions that are truly special cases of a general case is against any philosophical underpinnings that Perl follows. I am not saying it's perfect, but it is highly resistant to becoming a tower of babble. If that's your interest (not accusing you of being malicious), there are more fruitful avenues to attack Perl

I respectfully disagree. Perl philosophy states that there should be shortcuts for special cases if they are used often. That's the idea behind suffix conditionals (  return if (index($line,'EOL')>-1) ) and bash-style if statement (($debug) && say line; )

You also are missing the idea. My suggestion is that we can enhance the power of Perl by treating single quoted string differently from regex in split. And do this without adding to balkanization.

Balkanization of built-ins is generally what Python got having two different functions. Perl can avoid this providing the same functionality with a single function. That's the idea.

And my point is that this particular change requires minimal work in interpreter as it already treats ' ' in a special way (AWK way).

So this is a suggestion for improving the language, not for balkanization, IMHO. And intuitively it is logical as people understand (and expect) the difference in behavior between single quoted literals and regex in split. So, in a way, the current situation can be viewed as a bug, which became a feature.

  • Comment on Re^2: Why split function treats single quotes literals as regex, instead of a special case?
  • Select or Download Code

Replies are listed 'Best First'.
Re^3: Why split function treats single quotes literals as regex, instead of a special case?
by perlfan (Vicar) on Aug 15, 2020 at 08:04 UTC
    >So, in a way, the current situation can be viewed as a bug, which became a feature.

    To be fair, this is a lot of perl. But I can't rightfully assert that this behavior was unintentional, in fact it appears to be very intentional (e.g., awk emulation).

    >You also are missing the idea.

    My understanding is that you wish for "strings" (versus "regexes") to invoke the awk behavior of trimming leading white space. Is that right? I'm not here to judge your suggestion, but I can easily think of several reasons why adding another special case to split is not a great idea.

    All I can say is you're the same guy who was looking for the trim method in Perl. If that's not a red flag for being okay with balkanization, I don't know what is.

    Finally, I must reiterate. A "string" is a regular expression. The single quoted whitespace is most definitely a special exception since it is also a regular expression. You're recommending not only removing one regex from the pool of potential regexes, but an entire class of them available via quoting - i.e., fixed length strings of a fixed ordering. I am not sure how this is really a suggestion of making all quoted things not be regexes, because then how do you decide if it is "regex" or not? (maybe use a regex? xD)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11120739]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-19 13:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found