Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: vec overflow?

by LanX (Canon)
on Jun 25, 2013 at 09:46 UTC ( #1040572=note: print w/ replies, xml ) Need Help??


in reply to Re^2: vec overflow?
in thread vec overflow?

Ok, I had errors testing it out in the debugger, but turned out that just the automatic Data::Dump couldn't handle lvalues.

Asa suggestion:

I think using a foreach alias like shown in the docs for substr is a clearer alternative to lvalue-refs.

Cheers Rolf

( addicted to the Perl Programming Language)


Comment on Re^3: vec overflow?
Re^4: vec overflow?
by BrowserUk (Pope) on Jun 25, 2013 at 13:47 UTC
    I think using a foreach alias like shown in the docs for substr is a clearer alternative to lvalue-refs.

    Maybe, though I've been aware of LVALUE refs, and using them regularly, for a long time, but I've never seen a use of a for alias used that way until I followed your link to a newer set of docs than I have locally.

    Comparing:

    my $ref = \ substr( $astring, $start, $len ); vec( $$ref, $offset, $size ) = 1;

    To:

    vec( $_, $offset, $size ) = 1 for substr( $astring, $start, $len );

    The first one is very familiar (to me), whereas the latter just looks weird.

    The presence of \ and $$ref seem stronger clues than the $_ and for.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      A matter of taste ...

      for me

      vec( $_, $offset, $size ) = 1 for substr( $astring, $start, $len );

      has no big advantage over

      vec( substr( $astring, $start, $len ), $offset, $size ) = 1;

      but

      for my $chunk ( substr( $astring, $start, $len ) ) { ... vec( $chunk, $offset, $size ) = 1; ... }

      looks better for me than de/referencing and has the advantage to be documented in the docs.

      And your use of \ substr( $astring, $start, $len ); is less frequent and makes me wondering about precedences.

      (The practice to reference lvalues is still somehow new for me...)

      OTOH your approach has the (dis?)advantage that the ref can be passed around w/o being restricted to the body of a for loop...

      Well ... I'll better continue meditating about it after seeing more use cases! :)

      Cheers Rolf

      ( addicted to the Perl Programming Language)

        vec( $_, $offset, $size ) = 1 for substr( $astring, $start, $len ); has no big advantage over vec( substr( $astring, $start, $len ), $offset, $size ) = 1;

        I agree. But I've only very recently 'discovered' nested lvalue subs -- this thread is the first time I've ever used the construct publicly -- and I've never seen it used anywhere else.

        I can well imagine that there are lot of silent readers looking at

        • vec( vec( ... ), ... ) = 1;
        • vec( substr(... ), ... ) = 1;
        • substr( vec( ... ), ... ) = $stuff;
        • substr( substr( ...), ... ) = $stuff;
        • substr( vec( substr( vec( substr( ...), ... ), ... ), ... ), ... ) = $something;

        and thinking:

        "I'd never use such an unholy constructs even if it meant my code running a 1000 times more slowly."

        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1040572]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (12)
As of 2014-07-11 17:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (232 votes), past polls