Closed p5pRT closed 12 years ago
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.)
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.
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
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
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
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.
Confirmed still exists on 5.11.1 on Linux.
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​: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
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
@cpansprout - Status changed from 'open' to 'resolved'
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
Migrated from rt.perl.org#3471 (status was 'resolved')
Searchable as RT3471$