Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.92k stars 549 forks source link

Targeting printf %n format at any lvalue, not just scalar variable #2175

Closed p5pRT closed 12 years ago

p5pRT commented 24 years ago

Migrated from rt.perl.org#3471 (status was 'resolved')

Searchable as RT3471$

p5pRT commented 24 years ago

From domo@computer.org

Created by domo@free-internet.lu

A little more fall-out from the new\, improved sprintf.t​:

This works (under 5.6.0 and perl-current)​:

$ perl -we 'printf("%%n%n %d\n"\, $n\, $n)' %n 2

So does this​:

$ perl -wle '$x=0; sub l​:lvalue{$x}; l=5; print $x' 5

But this doesn't​:

$ ./perl -wle '$x=-1; sub l​:lvalue{$x}; printf "%%n%n %d\n"\, l\, $x' %n -1

I think that it should be possible to target %n at any scalar lvalue\, not just a named scalar variable. (My angle is that I want to have the target for %n generated by an eval\, and I have not been able to find anything that works.)

Perl Info ``` Flags: category=core severity=low This perlbug was built using Perl v5.6.0 - Mon Jun 26 19:35:23 WET DST 2000 It is being executed now by Perl v5.6.0 - Tue Jun 27 09:36:29 WET DST 2000. Site configuration information for perl v5.6.0: Configured by domo at Tue Jun 27 09:36:29 WET DST 2000. Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration: Platform: osname=machten, osvers=4.1.4, archname=powerpc-machten uname='machten ppp100 5 0.5 powerpc ' config_args='-de' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=undef d_sfio=undef uselargefiles=define use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef Compiler: cc='cc', optimize='-O2 -fomit-frame-pointer', gccversion=2.8.1 cppflags='-DNOTDEF_MACHTEN -DREG_INFTY=2047 -I/usr/local/include' ccflags ='-DNOTDEF_MACHTEN -DREG_INFTY=2047 -I/usr/local/include' stdchar='char', d_stdstdio=undef, usevfork=true intsize=4, longsize=4, ptrsize=4, doublesize=8 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=4 alignbytes=8, usemymalloc=y, prototype=define Linker and Libraries: ld='ld', ldflags =' -Xlstack=1048576 -L/usr/local/lib' libpth=/usr/local/lib /usr/lib libs=-lndbm -lgdbm -ldb -lm -lc libc=/usr/lib/libc.a, so=so, useshrplib=false, libperl=libperl.a Dynamic Linking: dlsrc=dl_none.xs, dlext=none, d_dlsymun=undef, ccdlflags='' cccdlflags='', lddlflags='' Locally applied patches: @INC for perl v5.6.0: lib /usr/local/lib/perl5/5.6.0/powerpc-machten /usr/local/lib/perl5/5.6.0 /usr/local/lib/perl5/site_perl/5.6.0/powerpc-machten /usr/local/lib/perl5/site_perl/5.6.0 /usr/local/lib/perl5/site_perl . Environment for perl v5.6.0: HOME=/home/domo LANG (unset) LANGUAGE (unset) LD_LIBRARY_PATH=/usr/lib LOGDIR (unset) PATH=/sbin:/usr/sbin:/home/domo/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11/bin:/usr/libexec PERL_BADLANG (unset) SHELL=/bin/bash ```
p5pRT commented 24 years ago

From [Unknown Contact. See original ticket]

On Jul 6\, Dominic Dunlop said​:

This is a bug report for perl from domo@​free-internet.lu\, generated with the help of perlbug 1.29 running under perl v5.6.0.

$ ./perl -wle '$x=-1; sub l​:lvalue{$x}; printf "%%n%n %d\n"\, l\, $x' %n -1

I think that it should be possible to target %n at any scalar lvalue\, not just a named scalar variable. (My angle is that I want to have the target for %n generated by an eval\, and I have not been able to find anything that works.)

Part of the problem\, methinks\, is due to the argument list to printf() being evaluated before %n has a chance to say "I will modify this value". You seem to be looking for the EXPR-type argument style that map and grep can handle​:

  @​list = map $_ > 5\, @​numbers;

where '$_ > 5' is stored as an expression to be evaluated later.

Personally\, I don't know how to get around this.

p5pRT commented 24 years ago

From @ysth

In article \p04320410b58a34bf2f90@​\[192\.168\.1\.4\]\, Dominic Dunlop \domo@​computer\.org wrote​:

$ ./perl -wle '$x=-1; sub l​:lvalue{$x}; printf "%%n%n %d\n"\, l\, $x' %n -1

I think that it should be possible to target %n at any scalar lvalue\, not just a named scalar variable.

Here's an interesting variation that I am at a loss to explain​:

[D​:\home\sthoenna]perl -wle "@​x=0..9; printf '%%n%n %d '\, $#x\, $#x; print $#x" %n 2 9

p5pRT commented 24 years ago

From [Unknown Contact. See original ticket]

sthoenna@​efn.org (Yitzchak Scott-Thoennes) wrote

Here's an interesting variation that I am at a loss to explain​:

[D​:\home\sthoenna]perl -wle "@​x=0..9; printf '%%n%n %d '\, $#x\, $#x; print $#x" %n 2 9

And as I different variation\, I can't get lvalue subs to work at all​:

  DB\<1> sub lv​:lvalue { $x }

  DB\<2> $x = 3

  DB\<3> x lv() 0 3   DB\<4> x lv = 4 0 4   DB\<5> x $x 0 3   DB\<6>

That's using perl-current.

Have lvalue subs ever worked?

Mike Guy

p5pRT commented 24 years ago

From [Unknown Contact. See original ticket]

And as I different variation\, I can't get lvalue subs to work at all​:

DB\<1> sub lv​:lvalue { $x }

DB\<2> $x = 3

DB\<3> x lv() 0 3 DB\<4> x lv = 4 0 4 DB\<5> x $x 0 3 DB\<6>

That's using perl-current.

It's a debugger issue. Your code\, run stand-alone​:

  #!/usr/bin/perl -l   sub lv​:lvalue { $x }   $x = 3;   print lv;   lv = 4;   print $x;

Does produce the expected result​:

  3   4

Have lvalue subs ever worked?

Yes.

--tom

p5pRT commented 24 years ago

From [Unknown Contact. See original ticket]

At 16​:36 -0700 2000-07-07\, Yitzchak Scott-Thoennes wrote​:

[D​:\home\sthoenna]perl -wle "@​x=0..9; printf '%%n%n %d '\, $#x\, $#x; print $#x" %n 2 9

Cool! Not enlightening\, but cool.

p5pRT commented 14 years ago

From @xdg

Confirmed still exists on 5.11.1 on Linux.

p5pRT commented 12 years ago

From @cpansprout

On Fri Jul 07 23​:34​:16 2000\, RT_System wrote​:

And as I different variation\, I can't get lvalue subs to work at all​:

DB\<1> sub lv​:lvalue { $x }

DB\<2> $x = 3

DB\<3> x lv() 0 3 DB\<4> x lv = 4 0 4 DB\<5> x $x 0 3 DB\<6>

That's using perl-current.

It's a debugger issue. Your code\, run stand-alone​:

\#\!/usr/bin/perl \-l
sub lv&#8203;:lvalue \{ $x \}
$x = 3;
print lv;
lv = 4;
print $x;

Does produce the expected result​:

3
4

Have lvalue subs ever worked?

Yes.

And it works in the debugger in 5.10.1\, but not 5.10.0.

--

Father Chrysostomos

p5pRT commented 12 years ago

From @cpansprout

On Thu Jul 06 00​:54​:57 2000\, domo@​computer.org wrote​:

This is a bug report for perl from domo@​free-internet.lu\, generated with the help of perlbug 1.29 running under perl v5.6.0.

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

A little more fall-out from the new\, improved sprintf.t​:

This works (under 5.6.0 and perl-current)​:

$ perl -we 'printf("%%n%n %d\n"\, $n\, $n)' %n 2

So does this​:

$ perl -wle '$x=0; sub l​:lvalue{$x}; l=5; print $x' 5

But this doesn't​:

$ ./perl -wle '$x=-1; sub l​:lvalue{$x}; printf "%%n%n %d\n"\, l\, $x' %n -1

I think that it should be possible to target %n at any scalar lvalue\, not just a named scalar variable. (My angle is that I want to have the target for %n generated by an eval\, and I have not been able to find anything that works.)

Twelve years later\, you get your wish\, with commit 69974ce61.

I doubt you are still tackling this problem (who knows? :-)\, but in older perls (than 5.16) you can use ${eval "....."} and have the eval return a reference to a scalar.

--

Father Chrysostomos

p5pRT commented 12 years ago

@cpansprout - Status changed from 'open' to 'resolved'

p5pRT commented 12 years ago

From shouldbedomo@me.com

No questions or concerns. Just thanks!

On 20 Jan 2012\, at 08​:06\, Father Chrysostomos via RT wrote​:

According to our records\, your request regarding "Targeting printf %n format at any lvalue\, not just scalar variable" has been resolved.

If you have any further questions or concerns\, please respond to this message.

For other topics\, please create a new ticket.

\<URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=3471 >

-- Dominic Dunlop