develooper Front page | perl.perl5.porters | Postings from January 2012

[perl #108730] 5.12.3 breaks use of when outside a topicalizer(!!!)

Thread Next
Linda Walsh
January 21, 2012 21:21
[perl #108730] 5.12.3 breaks use of when outside a topicalizer(!!!)
Message ID:
# New Ticket Created by  Linda Walsh 
# Please include the string:  [perl #108730]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is a bug report for perl from,
generated with the help of perlbug 1.39 running under perl 5.12.3.

[Please describe your issue here]

It seems like perl is being a bit over zealous about it's policing
the use of "when".  Technically, a topicalizer is something that
defines the "topic" (or subject).. like given and when automatically
use '$_'.  But I can write my own 'topicalizer' that funnels data
into $_ -- trivially.  

A prime example would be 'when(<>){}', where you process lines like
/filt/ and do {xxyz; continue};
/filter/ and do {xxyz+1; next};

Sometimes an if/elsif/else/ construct is useful, but only if you
don't have exceptions.  

Another example I ran into today:

In a trivial prog, I had a foreach loop to parse args.  
Later had an arg that took a param -- how to skip a 'each', 
in foreach?    Well:

for ($_=$ARGV[$n = 0]; $n<@ARGV; $_=$ARGV[$n]) {
	when(arg (-rc) with param) {
		my $m=$n+1;
		$m>=$#ARGV or die "-rc needs param\n";
		$rc=$ARGV[$m]; ++$n 
	when (next case)...

Course now, this doesn't work  -- to make it work I'll
have to add an extra 2 lines inside the forloop, 
which I hope won't have any side effects...i.e. 

for ($_=each(@ARGV); $_<=lastmem(@ARGV); $_=next(@ARGV) ) {
	given ($_) {
		when ...

Can someone explain to me the rational for the interpreter
to 'restrict' the usage of 'when' to a smaller subset than
where 'last/next/continue' would work or why it not working
in the same places shouldn't be considered a bug?

(p.s. can you think of any side effects of tossing in the
extra given{} in the for loop to satisfy the interp's warnings?)

[Please do not change anything below this line]
This perlbug was built using Perl 5.12.3 - Fri May  6 13:31:41 UTC 2011
It is being executed now by  Perl 5.12.3 - Fri May  6 13:26:30 UTC 2011.

Site configuration information for perl 5.12.3:

Configured by abuild at Fri May  6 13:26:30 UTC 2011.

Summary of my perl5 (revision 5 version 12 subversion 3) configuration:
    osname=linux, osvers=2.6.36, archname=x86_64-linux-thread-multi
    uname='linux build33 2.6.36 #1 smp 2011-02-21 10:34:10 +0100 x86_64 x86_64 x86_64 gnulinux '
    config_args='-ds -e -Dprefix=/usr -Dvendorprefix=/usr -Dinstallusrbinperl -Dusethreads -Di_db -Di_dbm -Di_ndbm -Di_gdbm -Duseshrplib=true -Doptimize=-fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack- protector -funwind-tables -fasynchronous-unwind-tables -g -Wall -pipe -Accflags=-DPERL_USE_SAFE_PUTENV'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DPERL_USE_SAFE_PUTENV -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -Wall -pipe',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DPERL_USE_SAFE_PUTENV -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector'
    ccversion='', gccversion='4.5.1 20101208 [gcc-4_5-branch revision 167585]', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib64 -fstack-protector'
    libpth=/lib64 /usr/lib64 /usr/local/lib64
    libs=-lm -ldl -lcrypt -lpthread
    perllibs=-lm -ldl -lcrypt -lpthread
    libc=/lib64/, so=so, useshrplib=true,
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib/perl5/5.12.3/x86_64-linux-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib64 -fstack-protector'

Locally applied patches:

@INC for perl 5.12.3:

Environment for perl 5.12.3:
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About