Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternate regexp delimiters trigger a warning #89

Closed
scottchiefbaker opened this issue Jun 29, 2020 · 12 comments · Fixed by #95
Closed

Alternate regexp delimiters trigger a warning #89

scottchiefbaker opened this issue Jun 29, 2020 · 12 comments · Fixed by #95
Milestone

Comments

@scottchiefbaker
Copy link

Consider the following code to remove https:// from a string

my $str = "https://google.com";

# Triggers a warning (but is must more readable)
$str =~ s|https://||;

# No warning, but a lot harder to read
$str =~ s/https:\/\///;

I think alternate regexp delimiters should be considered standard. At least some primary chars like: |, /, !', and maybe @` should be OK.

@rabbiveesh
Copy link

rabbiveesh commented Jun 29, 2020 via email

@xsawyerx
Copy link
Owner

xsawyerx commented Jun 29, 2020

s can use the following additional delimiters:

  • s{}{}
  • s[][]
  • s()()
  • s!!!

Pipe is possible but I'm not a fan because it's a fairly distance character for non-Perl devs who aren't used to other Perl devs using it. (I never used it personally.) Will s!!! not work?

@scottchiefbaker
Copy link
Author

I dunno why but I've always used | as an alternate delimiter. it's not a huge deal breaker though. I can switch to !.

Not really clear what this means:

I'm not a fan because it's a fairly distance character for non-Perl devs who aren't used to other Perl devs using it

@jeffreykegler
Copy link

FWIW I favor being extremely liberal in delimiters. |, for example, is visually quite distinct, and can have the right 'look' in some cases. Of course, if the strings to be delimited contain ! but not | , then | is a superior choice. And I can imagine some application which has painted itself into a corner where the only character that is not in a delimited string is '3' is, in which case the digit 3 is the ideal delimiter. I personally like to have any printable character available as a delimiter, just in case.

@scottchiefbaker
Copy link
Author

I took an informal poll on #perl and | was a popular delimiter. I'm fine if we want to exclude it, but bear in mind it's used in a lot of "real" code.

@gonzus
Copy link
Collaborator

gonzus commented Jul 1, 2020

I think the point here is to restrict this and get back some sanity. I remember seeing code that used \0 as delimiters... which is great for war stories, but is totally bonkers. I am personally also against # because I want my brain to think "comment" when I see a #.

FWIW, I personally like using | as a delimiter. But I will go along with any restricted list that excludes crazy shit.

@xsawyerx
Copy link
Owner

xsawyerx commented Jul 2, 2020

I dunno why but I've always used | as an alternate delimiter. it's not a huge deal breaker though. I can switch to !.

Not really clear what this means:

I'm not a fan because it's a fairly distance character for non-Perl devs who aren't used to other Perl devs using it

Sorry, this is my poor phrasing.

I meant that, if you're not a Perl developer who saw a different Perl developer use the pipe operator as a delimiter, you wouldn't even think about using it. Of course, this is a presumption on my part.

I'm okay adding the pipe symbol as a delimiter. I'll try to add it this week. (I want to add a bunch of docs and merge other stuff too for a release this weekend.)

@scottchiefbaker
Copy link
Author

Sounds good. Thank you for being flexible on this issue.

@xsawyerx
Copy link
Owner

xsawyerx commented Jul 3, 2020

Honestly, no reason here for me to be stubborn. The pipe symbol still gives us all we want. Also, I'm not likely to argue a point that is in opposition to both @gonzus and @jeffreykegler. :)

@xsawyerx xsawyerx modified the milestones: V0, 0.005 Jul 3, 2020
xsawyerx added a commit that referenced this issue Jul 4, 2020
This allows:

    q|...|
    s|foo|bar|

etc.
@xsawyerx xsawyerx linked a pull request Jul 4, 2020 that will close this issue
@xsawyerx
Copy link
Owner

xsawyerx commented Jul 4, 2020

PR now available.

xsawyerx added a commit that referenced this issue Jul 4, 2020
This allows:

    q|...|
    s|foo|bar|

etc.
xsawyerx added a commit that referenced this issue Jul 4, 2020
    * Add proper documentation to Guacamole.pm.
    * GH #88: Fix bareword STDIN with -t and file op precedence.
    * GH #87: Document Standard Perl in standard.pm.
    * GH #89: Added '|' as a delimiter for QLike values.
    * GH #90: Support methods without arglists (Thanks, chromatic!)
    * GH #93: Explain Standard Perl better. (Thanks, brian d foy)
    * GH #97: Fix test dependency. (Thanks, Graham @plicease Ollis)
@xsawyerx
Copy link
Owner

xsawyerx commented Jul 5, 2020

This is now available in 0.005, on CPAN: https://metacpan.org/pod/standard.

@scottchiefbaker
Copy link
Author

This is issue is resolved after testing with 0.005.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants