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

is this an unnecessary warning from Perl's undef #580

Open
richardalg opened this issue Aug 15, 2023 · 1 comment
Open

is this an unnecessary warning from Perl's undef #580

richardalg opened this issue Aug 15, 2023 · 1 comment

Comments

@richardalg
Copy link

https://perlmaven.com/use-of-uninitialized-value

In this use case, $x becomes undef. I doubt it matters why, but as an example, reading an expected numerical value from an external database can cause it if the code return is empty.
Then a choice has to be made : create another database with not-null values, or assign a value of '0' (zero) in Perl, thus :
< if ($x[$k] eq '') {$x[$k] = 0}>
where $k is a variable that sets an index to the array @x.

When the code is run, a warning is returned for each undefined value.
This isn't necessarily a problem, as the warnings can be ignored, but I would prefer to be able to set a flag to temporarily prevent the warning message being thrown.

@szabgab
Copy link
Owner

szabgab commented Aug 16, 2023

either check if defined $x[$k] and handle that case or you can turn off warnings that will impact till the end of the lexical scope.

See this new article: https://perlmaven.com/selectively-ignore-warnings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants