develooper Front page | perl.perl5.porters | Postings from May 2013

[perl #117903] assignment to hash in subroutine return corrupts result

Thread Next
From:
ran @ sapior . com
Date:
May 7, 2013 16:21
Subject:
[perl #117903] assignment to hash in subroutine return corrupts result
Message ID:
rt-3.6.HEAD-6955-1367910128-994.117903-75-0@perl.org
# New Ticket Created by  ran@sapior.com 
# Please include the string:  [perl #117903]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=117903 >



This is a bug report for perl from ran@sapior.com,
generated with the help of perlbug 1.39 running under perl 5.12.4.


-----------------------------------------------------------------
[Please describe your issue here]

Am getting disparity between result of a function when a hash is assigned within the return statement or beforehand. Easiest example is:

perl -e 'sub s1 {
  my @a=qw/b 1 c 2 a 3 a 4/;
  my %h=@a;
  return %h
  }
  print "@{[ s1()]}\n"'
c 2 a 4 b 1


perl -e 'sub s1 {
  my @a=qw/b 1 c 2 a 3 a 4/;
  my %h=@a;
  return %h=@a
  }
  print "@{[ s1()]}\n"'
c 2 c 2 a c

Why does (re)assigning to hash in return statement (2nd example) corrupt the returned hash?

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

Configured by ran at Tue Mar 19 11:14:21 PDT 2013.

Summary of my perl5 (revision 5 version 12 subversion 4) configuration:
   
  Platform:
    osname=freebsd, osvers=9.0-release, archname=amd64-freebsd
    uname='freebsd 64-142-100-122.colo.sonic.net 9.0-release freebsd 9.0-release #0: tue jan 3 07:46:30 utc 2012 root@farrell.cse.buffalo.edu:usrobjusrsrcsysgeneric amd64 '
    config_args='-sde -Dprefix=/usr/local -Darchlib=/usr/local/lib/perl5/5.12.4/mach -Dprivlib=/usr/local/lib/perl5/5.12.4 -Dman3dir=/usr/local/lib/perl5/5.12.4/perl/man/man3 -Dman1dir=/usr/local/man/man1 -Dsitearch=/usr/local/lib/perl5/site_perl/5.12.4/mach -Dsitelib=/usr/local/lib/perl5/site_perl/5.12.4 -Dscriptdir=/usr/local/bin -Dsiteman3dir=/usr/local/lib/perl5/5.12.4/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Ui_malloc -Ui_iconv -Uinstallusrbinperl -Dcc=cc -Duseshrplib -Dinc_version_list=none -Dccflags=-DAPPLLIB_EXP="/usr/local/lib/perl5/5.12.4/BSDPAN" -Doptimize=-O2 -pipe -fno-strict-aliasing -Ui_gdbm -Dusethreads=n -Dusemymalloc=n -Duse64bitint'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-DAPPLLIB_EXP="/usr/local/lib/perl5/5.12.4/BSDPAN" -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include',
    optimize='-O2 -pipe -fno-strict-aliasing',
    cppflags='-DAPPLLIB_EXP="/usr/local/lib/perl5/5.12.4/BSDPAN" -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.2.1 20070831 patched [FreeBSD]', 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 ='-pthread -Wl,-E  -fstack-protector -L/usr/local/lib'
    libpth=/usr/lib /usr/local/lib
    libs=-lgdbm -lm -lcrypt -lutil
    perllibs=-lm -lcrypt -lutil
    libc=, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='  -Wl,-R/usr/local/lib/perl5/5.12.4/mach/CORE'
    cccdlflags='-DPIC -fPIC', lddlflags='-shared  -L/usr/local/lib -fstack-protector'

Locally applied patches:
    

---
@INC for perl 5.12.4:
    /usr/local/lib/perl5/5.12.4/BSDPAN
    /usr/local/lib/perl5/site_perl/5.12.4/mach
    /usr/local/lib/perl5/site_perl/5.12.4
    /usr/local/lib/perl5/5.12.4/mach
    /usr/local/lib/perl5/5.12.4
    .

---
Environment for perl 5.12.4:
    HOME=/home/ran
    LANG=en_US.C
    LANGUAGE (unset)
    LC_ALL=C
    LD_LIBRARY_PATH=:/lib:/usr/local/lib
    LOGDIR (unset)
    PATH=/sbin:/bin:/usr/sbin:/usr/bin:/rampool/pg/bin:/usr/local/sbin:/usr/local/bin:/home/ran/bin
    PERL_BADLANG (unset)
    SHELL=/usr/local/bin/ksh93


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