Other than its memory space and the time taken to create it, what concerns you about the lvalue? Unless there is more I wouldn't call this a side-effect, as many things are implemented with intermediate lvalues. Am I missing something?
Having not talked much about 'lvalues' it is possible that my usage is baroque. I'd say altering a named value inadvertently is a side-effect. Your usage just seems extremely strict: like saying creating $main::val has the side-effect of creating a whole typeglob. Is this type of usage common? I see its correctness and how compiler writers would use it as I understand your usage here.
I agree with your preference, but I have never used or seen the do2dollar_ for ($var); constructions you have been talking about. I dislike assigning $stuff as the last operation. It just doesn't read well, the invisible $_ seems much better used in the second version. So again I ask, what are the reasons for your preference?
I am going to read this thread to find out more about this usage of for. My first reaction is suspection but I also like a less indented style of coding.
#!/usr/bin/perl -w use strict; sub return_value { return "" unless wantarray; return ("this is a value", "xxx", "yyy", "zzz") ; }; my $stuff; for ( return_value() ) { chomp; s/foo//g; tr/x/y/; $stuff = $_; } print "\$stuff >$stuff<\n"; $stuff = return_value(); for ($stuff) { chomp; s/foo//g; tr/x/y/; } print "\$stuff >$stuff<\n"; # the output __DATA__ $stuff >zzz< $stuff ><
In reply to (Re:)+ Using $_ as a temp var, especially in functions
by rir
in thread Using $_ as a temp var, especially in functions
by BUU
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |