You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#!/usr/bin/perluse DDP;
foreach (1..2) {
p;
p $_;
}
It outputs:
undef
1
undef
2
but I'm expected it to output:
1
1
2
2
What you do think? Is this behaviour good and should it be implemented? Or this is the expected behaviour that should be left as it is? Or this is a bug?
By the way, If I run this scrip without custom .dataprinter I'll get error:
Not enough arguments for Data::Printer::p at a.pl line 6, near "p;"
Execution of a.pl aborted due to compilation errors.
The text was updated successfully, but these errors were encountered:
I don't think p() should be called without arguments (which is why it complains about it without the 'use_prototypes => 0' in your .dataprinter), so I'd say it's a bug that it lets you do it!
That said, I looks very reasonable to me that if you say p() without arguments you are interested in $_, feels perlish. I'm gonna think about it for a bit and see if I can come up with a decent solution that works with and without function prototypes. Tomorrow. It's almost 4am here now :D
Alright, prototypes are hitting me hard here. According to perlsub, adding a "_" to the prototype list before the ; should do the trick, but right now I'm only able to get the non-prototyped version to see the caller's $_ variable, and even thought it's a cool feature to have, I don't think it's sane to have a feature like that only working if the user has a specific setup, and I can't get rid of the prototypes altogether without losing lots of syntax sugar too, like non-backslashed variables and inline options without braces.
What do you think? Can you make the (\[@$%&];%) prototype saner and considering $_? Patches are welcome!
Otherwise, the best I can do is turn it into a feature you get only without prototypes, but that would really hurt consistency, so I'm not very confident about it.
garu
changed the title
Using default variable when calling p() without parameters.
[wishlist] Using default variable when calling p() without parameters.
Mar 4, 2021
Here is my .dataprinter:
And here is the test script:
It outputs:
but I'm expected it to output:
What you do think? Is this behaviour good and should it be implemented? Or this is the expected behaviour that should be left as it is? Or this is a bug?
By the way, If I run this scrip without custom .dataprinter I'll get error:
The text was updated successfully, but these errors were encountered: