develooper Front page | perl.perl5.porters | Postings from July 2019

POC: perl -ə

Thread Next
From:
H.Merijn Brand
Date:
July 18, 2019 10:03
Subject:
POC: perl -ə
Message ID:
20190718120251.750c15eb@pc09.procura.nl
Don't we all want perl one-liners to be strict with warnings? :}

I quite often want an option that is the equivalent of

 $ perl -Mstrict -Mwarnings -E'...'

-Mwarnings is available as -w, so

 $ perl -Mstrict -wE'...'

I have one of those virtues: I am lazy and I quite often (to be honest,
most of the time) leave -Mstrict out, which (sometimes) causes hurt

That I pondered on other options, like -Ǝ -é -è -ë -ē -ę -ė -ê -ě -ę
or -ə to include all three

Call me sick, but this was easy :)
Thoughts? Feedback?

POC:

We already have

$ perl -e'$x += "abc"'
$ perl -we'$x += "abc"'
Name "main::x" used only once: possible typo at -e line 1.
Argument "abc" isn't numeric in addition (+) at -e line 1.
$ perl -Mstrict -e'$x += "abc"'
Global symbol "$x" requires explicit package name (did you forget to declare "my $x"?) at -e line 1.
Execution of -e aborted due to compilation errors.
Exit 255
$ perl -Mstrict -we'$x += "abc"'
Global symbol "$x" requires explicit package name (did you forget to declare "my $x"?) at -e line 1.
Execution of -e aborted due to compilation errors.
Exit 255
$ perl -Mstrict -E'$x += "abc"'
Global symbol "$x" requires explicit package name (did you forget to declare "my $x"?) at -e line 1.
Execution of -e aborted due to compilation errors.
Exit 255
$ perl -Mstrict -wE'$x += "abc"'
Global symbol "$x" requires explicit package name (did you forget to declare "my $x"?) at -e line 1.
Execution of -e aborted due to compilation errors.
Exit 255

now I can do

$ perl -ə'$a += "abc"'
Argument "abc" isn't numeric in addition (+) at -e line 1.
$ perl -ə'$x += "abc"'
Global symbol "$x" requires explicit package name (did you forget to declare "my $x"?) at -e line 1.
Execution of -e aborted due to compilation errors.
Exit 255
$ perl -é'$x += "abc"'
Global symbol "$x" requires explicit package name (did you forget to declare "my $x"?) at -e line 1.
Execution of -e aborted due to compilation errors.
Exit 255
$ perl -ë'$x += "abc"'
Unrecognized switch: -ë$x += "abc"  (-h will show valid options).
Exit 29

--8<---
$ diff -purd ../perl-git/perl.c perl.c
--- a/perl.c  2019-07-18 11:57:28.958145441 +0200
+++ b/perl.c  2019-07-18 11:48:32.700594365 +0200
@@ -2066,16 +2066,16 @@ S_parse_body(pTHX_ char **env, XSINIT_t
 #endif
        case ' ':
        case '0':
-       case 'F':
        case 'a':
        case 'c':
        case 'd':
        case 'D':
+       case 'F':
        case 'h':
        case 'i':
        case 'l':
-       case 'M':
        case 'm':
+       case 'M':
        case 'n':
        case 'p':
        case 's':
@@ -2118,6 +2118,29 @@ S_parse_body(pTHX_ char **env, XSINIT_t
            s++;
            goto reswitch;

+       case '\303': /* c3 first bye of UTF-8 ? */
+           if (s[1] == '\251') { /* c3 a9 U+00e9 e acute */
+               s++;
+               goto opt_e_acute;
+           }
+           /* more "special" options */
+           goto invalid_option;
+
+       case '\311': /* c9 first bye of UTF-8 ? */
+           if (s[1] == '\231') { /* c9 99 U+0259 schwa */
+               s++;
+               goto opt_e_acute;
+           }
+           /* more "special" options */
+           goto invalid_option;
+
+       case '\233': /* e9 e-acute */
+         opt_e_acute:
+           if (! (PL_dowarn & G_WARN_ALL_MASK)) {
+               PL_dowarn |= G_WARN_ON;
+           }
+           Perl_av_create_and_push(aTHX_ &PL_preambleav, newSVpvs("use strict"));
+           /* FALLTHROUGH */
        case 'E':
            PL_minus_E = TRUE;
            /* FALLTHROUGH */
@@ -2203,6 +2226,7 @@ S_parse_body(pTHX_ char **env, XSINIT_t
            s--;
            /* FALLTHROUGH */
        default:
+         invalid_option:
            Perl_croak(aTHX_ "Unrecognized switch: -%s  (-h will show valid options)",s);
        }
     }
-->8---
-- 
H.Merijn Brand  http://tux.nl   Perl Monger  http://amsterdam.pm.org/
using perl5.00307 .. 5.29   porting perl5 on HP-UX, AIX, and openSUSE
http://mirrors.develooper.com/hpux/        http://www.test-smoke.org/
http://qa.perl.org   http://www.goldmark.org/jeff/stupid-disclaimers/

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About