The context around &return_value differs.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.