You must make sure that your do blocks always evaluate to an intended result. In this case, you have to add an else { undef } clause.
Indeed.
In your case, the value of $foo is assigned to $bar if $foo is false.
Perl is a bit wierd about the return value of a loop of which the body never runs. This code:
prints:#!/usr/bin/perl -w my $true = "foo"; my $false = "0"; my $dc = "bar"; warn do { $dc if $false }; warn do { $dc unless $true }; warn do { $dc while $false }; warn do { $dc until $true }; warn do { if ($false) { $dc } }; warn do { unless ($true) { $dc } }; warn do { while ($false) { $dc } }; warn do { until ($true) { $dc } }; warn do { $dc if "0" }; warn do { $dc unless "foo" }; warn do { $dc while "0" }; warn do { $dc until "foo" }; warn do { if ("0") { $dc } }; warn do { unless ("foo") { $dc } }; warn do { while ("0") { $dc } }; warn do { until ("foo") { $dc } }; __END__
Useless use of private variable in void context at a line 9. Useless use of private variable in void context at a line 10. Useless use of private variable in void context at a line 13. Useless use of private variable in void context at a line 14. Useless use of private variable in void context at a line 21. Useless use of private variable in void context at a line 22. 0 at a line 7. foo at a line 8. 0 at a line 9. foo at a line 10. 0 at a line 11. foo at a line 12. 0 at a line 13. foo at a line 14. 0 at a line 15. foo at a line 16. 0 at a line 17. Warning: something's wrong at a line 18. 0 at a line 19. Warning: something's wrong at a line 20. Warning: something's wrong at a line 21. Warning: something's wrong at a line 22.
In reply to Re^3: A cleaner way of scoping variables
by ambrus
in thread A cleaner way of scoping variables
by bradcathey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |