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

given (@a) when (/REGEX/) #10505

Open
p5pRT opened this issue Jul 22, 2010 · 6 comments
Open

given (@a) when (/REGEX/) #10505

p5pRT opened this issue Jul 22, 2010 · 6 comments

Comments

@p5pRT
Copy link

p5pRT commented Jul 22, 2010

Migrated from rt.perl.org#76660 (status was 'open')

Searchable as RT76660$

@p5pRT
Copy link
Author

p5pRT commented Jul 22, 2010

From @ikegami

Created by @ikegami

perlsyn indicates that "when (/REGEX/)" is treated as "when ($_ =~ /REGEX/)"
instead of "when ($_ ~~ /REGEX/)". Why? It seems to me the latter would be
more useful.

------ BEGIN EXAMPLE -----
use 5.010; # say, switch
use strict;
use warnings;

my @​a = qw(abc def);

if (@​a ~~ /abc/ ) { say '/abc/'; } # Matches
if (@​a ~~ qr/abc/) { say 'qr/abc/'; } # Matches
if (@​a ~~ /ARRAY/) { say '/ARRAY/'; } # Doesn't match

say '--';

given (@​a) {
  when (/abc/ ) { say '/abc/'; continue; } # Doesn't match!!!
  when (qr/abc/) { say 'qr/abc/'; continue; } # Matches
  when (/ARRAY/) { say '/ARRAY/'; continue; } # Matches!!!
}

say '--';

given ($a[0]) {
  when (/abc/ ) { say '/abc/'; continue; } # Matches
  when (qr/abc/) { say 'qr/abc/'; continue; } # Matches
}
------ END EXAMPLE -----

------ BEGIN OUTPUT -----
/abc/
qr/abc/
--
qr/abc/
/ARRAY/
--
/abc/
qr/abc/
------ END OUTPUT -----

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl 5.12.0:

Configured by eric at Tue May  4 17:51:08 EDT 2010.

Summary of my perl5 (revision 5 version 12 subversion 0) configuration:

  Platform:
    osname=linux, osvers=2.6.26-2-686, archname=i686-linux
    uname='linux fmdev10 2.6.26-2-686 #1 smp tue mar 9 17:35:51 utc 2010
i686 gnulinux '
    config_args='-de -Dprefix=/home/eric/usr/perlbrew/perls/perl-5.12.0'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-fno-strict-aliasing -pipe -fstack-protector
-I/usr/local/include'
    ccversion='', gccversion='4.3.2', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.7.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.7'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib
-fstack-protector'

Locally applied patches:



@INC for perl 5.12.0:

/home/eric/usr/perlbrew/perls/perl-5.12.0/lib/site_perl/5.12.0/i686-linux
    /home/eric/usr/perlbrew/perls/perl-5.12.0/lib/site_perl/5.12.0
    /home/eric/usr/perlbrew/perls/perl-5.12.0/lib/5.12.0/i686-linux
    /home/eric/usr/perlbrew/perls/perl-5.12.0/lib/5.12.0
    .


Environment for perl 5.12.0:
    HOME=/home/eric
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)

PATH=/home/eric/usr/perlbrew/bin:/home/eric/usr/perlbrew/perls/current/bin:.:/home/eric/bin:/usr/local/bin:/usr/bin:/bin:/usr/games
    PERLBREW_ROOT=/home/eric/usr/perlbrew
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Jul 24, 2010

From @obra

Confirmed as giving the same output on 5.12.1

@p5pRT
Copy link
Author

p5pRT commented Jul 24, 2010

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Sep 12, 2012

From @cpansprout

On Thu Jul 22 09​:14​:47 2010, ikegami@​adaelis.com wrote​:

given (@​a) {
when (/abc/ ) { say '/abc/'; continue; } # Doesn't match!!!
when (qr/abc/) { say 'qr/abc/'; continue; } # Matches
when (/ARRAY/) { say '/ARRAY/'; continue; } # Matches!!!
}

Under the new scheme, given($array_ref) won’t be particularly
meaningful, will it?

So should given(@​a) continue to turn automagically into given(\@​a)?

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Sep 12, 2012

From @doy

On Tue, Sep 11, 2012 at 10​:34​:14PM -0700, Father Chrysostomos via RT wrote​:

On Thu Jul 22 09​:14​:47 2010, ikegami@​adaelis.com wrote​:

given (@​a) {
when (/abc/ ) { say '/abc/'; continue; } # Doesn't match!!!
when (qr/abc/) { say 'qr/abc/'; continue; } # Matches
when (/ARRAY/) { say '/ARRAY/'; continue; } # Matches!!!
}

Under the new scheme, given($array_ref) won’t be particularly
meaningful, will it?

So should given(@​a) continue to turn automagically into given(\@​a)?

Oh, so it's not just when(), but given also has weird syntax special
cases? )​:

In my opinion, as long as we're fixing everything else, given(@​a) should
just be interpreted as given(scalar(@​a)).

-doy

@p5pRT
Copy link
Author

p5pRT commented Sep 12, 2012

From @cpansprout

On Tue Sep 11 22​:37​:30 2012, doy@​tozt.net wrote​:

On Tue, Sep 11, 2012 at 10​:34​:14PM -0700, Father Chrysostomos via RT
wrote​:

On Thu Jul 22 09​:14​:47 2010, ikegami@​adaelis.com wrote​:

given (@​a) {
when (/abc/ ) { say '/abc/'; continue; } # Doesn't match!!!
when (qr/abc/) { say 'qr/abc/'; continue; } # Matches
when (/ARRAY/) { say '/ARRAY/'; continue; } # Matches!!!
}

Under the new scheme, given($array_ref) won’t be particularly
meaningful, will it?

So should given(@​a) continue to turn automagically into given(\@​a)?

Oh, so it's not just when(), but given also has weird syntax special
cases? )​:

In my opinion, as long as we're fixing everything else, given(@​a) should
just be interpreted as given(scalar(@​a)).

This is probably getting off-topic for this ticket, but newWHENOP is
part of the API, yet its parameter list is not sufficient to distinguish
when() from when{}, and its unused on CPAN.

Is this something that can change? (I.e., if we are going to break Perl
code [probably just one module], is it OK to break XS at the same time
[probably none].)

--

Father Chrysostomos

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

No branches or pull requests

2 participants