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
Feature: get "name" of lvalue expression #16328
Comments
From @epaCreated by @epaOften an error message ends up repeating the name of the variable it's dealing with. die "bad height $height" unless (50 <= $height && $height <= 150); One would want to refactor the above code into something like my @checks = ([ $height, 50, 150 ], [ $width, 20, 70 ], [ $length, 50, 200 ]); But then you lose the useful text in the error message. Of course you If you forgo lexically scoped variables then you can do this. You Clearly, this could not be expected to work in all circumstances. die "bad value $v from variable " . nameof($v); If the scalar passed to nameof() can be found in the current scope Since the normal use would be only for debugging messages and error (An alternative way to cut down on typing would be some kind of compile my ($height, $width, $length); but I think that is going too far for a dynamic language like Perl. Perl Info
|
From @epaAn obvious flaw in my proposal is that nameof($v) returns '$v'. sub check { At this point you no longer have a 'ponies' solution which just prints out whatever the name is of the variable you were dealing with. So the bug might be best closed; as nice as it would be, the magic probably doesn't exist. |
The RT System itself - Status changed from 'new' to 'open' |
@iabyn - Status changed from 'open' to 'rejected' |
Migrated from rt.perl.org#132628 (status was 'rejected')
Searchable as RT132628$
The text was updated successfully, but these errors were encountered: