Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wishlist] Using default variable when calling p() without parameters. #44

Open
bessarabov opened this issue Feb 27, 2013 · 2 comments
Open
Labels

Comments

@bessarabov
Copy link
Contributor

Here is my .dataprinter:

{
    use_prototypes => 0,
}

And here is the test script:

#!/usr/bin/perl

use 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.
@garu
Copy link
Owner

garu commented Mar 2, 2013

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

@garu
Copy link
Owner

garu commented Mar 3, 2013

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 garu added the wishlist label May 30, 2015
@garu garu changed the title Using default variable when calling p() without parameters. [wishlist] Using default variable when calling p() without parameters. Mar 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants