Skip Menu | You are currently an anonymous guest. | Login | Return to Main | Preferences
Id: 23614
Status: resolved
Left: 0 min
Priority: 0/0
Queue: perl5

Owner: Nobody
Requestors: mjd [at] plover.com
Cc:
AdminCc:

Operating System: Linux
PatchStatus: (no value)
Severity: low
Type: wontfix
Perl Version: 5.8.0
Fixed In: (no value)



X History Display mode: Brief headersFull headers
#   Wed Aug 27 11:15:48 2003 mjd@plover.com - Ticket created  
Date: 27 Aug 2003 18:08:06 -0000
From: mjd@plover.com
To: perlbug@perl.org
Subject: 'next' doesn't support dynamic label
Download (untitled) [text/plain 3.7k]

This is a bug report for perl from mjd@plover.com,
generated with the help of perlbug 1.34 running under perl v5.8.0.


-----------------------------------------------------------------
[Please enter your report here]

This doesn't work:


$label = 'A';
A: for my $a (1..3) {
print $a;
next $label;
print "x";
}

I want 'next $label' to be equivalent to 'next A' when $label contains 'A'.

If nexts were defined at compile time as jumps, this would be
impossible. But they're not; they're defined at run time. So this
should be possible, perhaps even easy.

The late-binding behavior of the existing implementation leads to
weird behaviors, so we ought to get some use out of it. The usual
benefit of late binding is flexibility. In this case, the flexibility
is lost.

I have applications of this in mind, but I don't want to explain them
because I am afraid of confusing people.

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
category=core
severity=low
---
Site configuration information for perl v5.8.0:

Configured by mjd at Thu Apr 17 11:57:37 EDT 2003.

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
Platform:
osname=linux, osvers=2.4.2-2, archname=i586-linux
uname='linux plover.com 2.4.2-2 #1 sun apr 8 19:37:14 edt 2001 i586 unknown '
config_args='-des'
hint=previous, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef 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 -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
optimize='-O2',
cppflags='-fno-strict-aliasing -I/usr/local/include -I/usr/include/gdbm -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm'
ccversion='', gccversion='2.96 20000731 (Red Hat Linux 7.1 2.96-81)', 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 =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -lndbm -lgdbm -ldl -lm -lc -lcrypt -lutil
perllibs=-lnsl -ldl -lm -lc -lcrypt -lutil
libc=/lib/libc-2.2.2.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.2.4'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:


---
@INC for perl v5.8.0:
/usr/local/lib/perl5/5.8.0/i586-linux
/usr/local/lib/perl5/5.8.0
/usr/local/lib/perl5/site_perl/5.8.0/i586-linux
/usr/local/lib/perl5/site_perl/5.8.0
/usr/local/lib/perl5/site_perl/5.7.3
/usr/local/lib/perl5/site_perl/5.7.2
/usr/local/lib/perl5/site_perl/5.6.1
/usr/local/lib/perl5/site_perl/5.6.0
/usr/local/lib/perl5/site_perl
.

---
Environment for perl v5.8.0:
HOME=/home/mjd
LANG=C
LANGUAGE (unset)
LD_LIBRARY_PATH=/lib:/usr/lib:/usr/X11R6/lib
LOGDIR (unset)
PATH=/home/mjd/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/games:/sbin:/usr/sbin:/usr/local/bin/X11R6:/usr/local/bin/mh:/data/mysql/bin:/usr/local/bin/pbm:/usr/local/bin/ezmlm:/home/mjd/TPI/bin:/usr/local/teTeX/bin:/usr/local/mysql/bin
PERL_BADLANG (unset)
SHELL=/bin/bash
#   Wed Aug 27 11:15:49 2003 RT_System - Default: Keyword/9 changed from (no value) to 'Linux'  
#   Wed Aug 27 11:15:50 2003 RT_System - Default: Keyword/11 changed from (no value) to 'low'  
#   Wed Aug 27 11:15:50 2003 RT_System - Default: Keyword/12 changed from (no value) to 'core'  
#   Wed Aug 27 11:15:50 2003 RT_System - Default: Keyword/13 changed from (no value) to '5.8.0'  
#   Wed Aug 27 13:34:50 2003 enache - Correspondence added  
Date: Wed, 27 Aug 2003 23:35:25 +0300
From: Enache Adrian <enache@rdslink.ro>
To: perl5-porters@perl.org
Subject: Re: [perl #23614] 'next' doesn't support dynamic label
Download (untitled) [text/plain 801b]
On Wed, Aug 27, 2003 a.d., Mark-Jason Dominus wrote:
> $label = 'A';
> A: for my $a (1..3) {
> print $a;
> next $label;
> print "x";
> }
>
> I want 'next $label' to be equivalent to 'next A' when $label contains 'A'.
>
> If nexts were defined at compile time as jumps, this would be
> impossible. But they're not; they're defined at run time. So this
> should be possible, perhaps even easy.

Basically, let pp_next be a SVOP instead of a PVOP in that case.
(just like y/// is a SVOP when translating to/from utf8).

But is it worth the overhead of yet another special case (and another
test in pp_next) ? (just asking).

I'm currently using the ugly:

#! perl
$a = "LOOP";
LOOP: for (1, 2, 3) {
eval "next $a";
}
__END__

Regards,
Adi
#   Wed Aug 27 13:45:18 2003 mjd@plover.com - Correspondence added  
To: perlbug-followup@perl.org
Subject: Re: [perl #23614] 'next' doesn't support dynamic label
Date: Wed, 27 Aug 2003 16:45:18 -0400
From: Mark Jason Dominus <mjd@plover.com>
Download (untitled) [text/plain 237b]

> Basically, let pp_next be a SVOP instead of a PVOP in that case.

Yes, I was looking into this this morning.

> But is it worth the overhead of yet another special case (and another
> test in pp_next) ? (just asking).

Probably not.
#   Thu Aug 28 03:17:42 2003 yves.orton@de.mci.com - Correspondence added  
From: "Orton, Yves" <yves.orton@de.mci.com>
To: "'perl5-porters@perl.org'" <perl5-porters@perl.org>
CC: 'Mark Jason Dominus' <mjd@plover.com>
Subject: RE: [perl #23614] 'next' doesn't support dynamic label
Date: Thu, 28 Aug 2003 11:08:30 +0100
Download (untitled) [text/plain 355b]
> This doesn't work:
>
>
> $label = 'A';
> A: for my $a (1..3) {
> print $a;
> next $label;
> print "x";
> }
>

Odd that it doesnt work for next as it does work for goto.

$label = time % 2 ? 'A' : 'B';
goto $label;
print "This shouldn't happen BTW\n";
A:{
die "In A";
}
B:{
die "in B";
}

Yves
#   Thu Aug 28 03:38:23 2003 schwern - Correspondence added  
Date: Thu, 28 Aug 2003 03:33:54 -0700
From: Michael G Schwern <schwern@pobox.com>
To: "Orton, Yves" <yves.orton@de.mci.com>
CC: "'perl5-porters@perl.org'" <perl5-porters@perl.org>, 'Mark Jason Dominus' <mjd@plover.com>
Subject: Re: [perl #23614] 'next' doesn't support dynamic label
Download (untitled) [text/plain 727b]
On Thu, Aug 28, 2003 at 11:08:30AM +0100, Orton, Yves wrote:
> > This doesn't work:
> >
> >
> > $label = 'A';
> > A: for my $a (1..3) {
> > print $a;
> > next $label;
> > print "x";
> > }
> >
>
> Odd that it doesnt work for next as it does work for goto.

If I allowed "next $label" then I'd also have to allow "goto $label",
and I don't think you really want that... :-)
--Larry Wall in <1991Mar11.230002.27271@jpl-devvax.jpl.nasa.gov>

Is ironic, no?


--
Michael G Schwern schwern@pobox.com http://www.pobox.com/~schwern/
Do not try comedy at home! Milk & Cheese are advanced experts! Attempts at
comedy can be dangerously unfunny!
#   Thu Aug 28 03:47:48 2003 yves.orton@de.mci.com - Correspondence added  
From: "Orton, Yves" <yves.orton@de.mci.com>
To: 'Michael G Schwern' <schwern@pobox.com>
CC: "'perl5-porters@perl.org'" <perl5-porters@perl.org>, 'Mark Jason Dominus' <mjd@plover.com>
Subject: RE: [perl #23614] 'next' doesn't support dynamic label
Date: Thu, 28 Aug 2003 11:45:41 +0100
Download (untitled) [text/plain 601b]
On 28 August 2003 at 12:34 Michael G Schwern wrote
> On Thu, Aug 28, 2003 at 11:08:30AM +0100, Orton, Yves wrote:
> > Odd that it doesnt work for next as it does work for goto.
>
> If I allowed "next $label" then I'd also have to allow
> "goto $label",
> and I don't think you really want that... :-)
> --Larry Wall in
> <1991Mar11.230002.27271@jpl-devvax.jpl.nasa.gov>
>
> Is ironic, no?

Indeed.

:-)

I cant say ive used this often though. But it did come in quite handy once.

So if it does work for goto but not next, whats the cause of the difference
I wonder?

Yves
#   Thu Aug 28 09:51:50 2003 mjtg@cam.ac.uk - Correspondence added  
From: Mike Guy <mjtg@cam.ac.uk>
Subject: RE: [perl #23614] 'next' doesn't support dynamic label
To: perl5-porters@perl.org
Date: Thu, 28 Aug 2003 17:49:59 +0100
Download (untitled) [text/plain 354b]
"Orton, Yves" <yves.orton@de.mci.com> wrote
> So if it does work for goto but not next, whats the cause of the difference
> I wonder?

goto has to allow an arbitrary SV as argument, in order to support

my $sub = sub { ... };
...
goto &$sub;

I guess that cases like

my $label = 'LABEL';
...
goto $label;

just came out in the wash.


Mike Guy
#   Thu Aug 28 13:43:25 2003 schwern - Correspondence added  
Date: Thu, 28 Aug 2003 13:36:43 -0700
From: Michael G Schwern <schwern@pobox.com>
To: Mike Guy <mjtg@cam.ac.uk>
CC: perl5-porters@perl.org
Subject: Re: [perl #23614] 'next' doesn't support dynamic label
Download (untitled) [text/plain 971b]
On Thu, Aug 28, 2003 at 05:49:59PM +0100, Mike Guy wrote:
> "Orton, Yves" <yves.orton@de.mci.com> wrote
> > So if it does work for goto but not next, whats the cause of the difference
> > I wonder?
>
> goto has to allow an arbitrary SV as argument, in order to support
>
> my $sub = sub { ... };
> ...
> goto &$sub;
>
> I guess that cases like
>
> my $label = 'LABEL';
> ...
> goto $label;
>
> just came out in the wash.

No, they do totally different things and internally they're totally
different sets of code.

If you look at pp_goto inside pp_ctl.c you'll see

/* This egregious kludge implements goto &subroutine */

followed by a 200 line if statement.


--
Michael G Schwern schwern@pobox.com http://www.pobox.com/~schwern/
It should indeed be said that notwithstanding the fact that I make
ambulatory progress through the umbragious inter-hill mortality slot,
terror sensations will no be initiated in me, due to para-etical phenomena.
#   Sun Aug 31 13:25:35 2003 rafael - Comments added  
Download (untitled) [text/plain 80b]
I'm resolving this as a "wontfix" bug, based on the performance penalty
remarks.
#   Sun Aug 31 13:25:36 2003 rafael - Status changed from 'new' to 'resolved'  
#   Sun Aug 31 13:25:52 2003 rafael - Default: Keyword/12 changed from (no value) to 'wontfix'  
#   Sun Aug 31 13:25:52 2003 rafael - Default: Keyword/ changed from 'core' to ''  


For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org