in reply to Re: What's so wrong with this (dereferencing)code? (Symbolic Refs)
in thread What's so wrong with this (dereferencing)code?

I'm not 100% sure what you mean by DRY here, but I'll concede my code is only elegant from the perspective of the programmer not wanting to rewrite already written code rather than future readers. Now $_ = zeropad($_) for $sec, $min, $hour, $day, $month; OTOH? That's what I'm talking about! One added line, understandable at first glance and I've learnt a new construct. I'm also pleased to have learnt about hash slices of course but kind of overkill for solving this specific problem.
  • Comment on Re^2: What's so wrong with this (dereferencing)code? (Symbolic Refs)
  • Download Code

Replies are listed 'Best First'.
Re^3: What's so wrong with this (dereferencing)code? (Aliasing / UPDATED)
by LanX (Saint) on Jun 26, 2024 at 13:44 UTC
    DRY = Don't repeat yourself

    Symbolic references are just implicit hash lookups, doing them explicitly is better in the vast majority of cases.

    The for-solution you showed is aliasing which has similarities to referencing, but should not be confused.

    Update

    > Now $_ = zeropad($_) for $sec, $min, $hour, $day, $month;

    > OTOH? That's what I'm talking about!

    No you weren't.

    But FWIW, aliasing it's also feasible with hash values.

    Consider

    $_ = zeropad($_) for values %time

    and revaluate the clarity of concise code.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

      > Now $_ = zeropad($_) for $sec, $min, $hour, $day, $month;
      > OTOH? That's what I'm talking about!

      No you weren't.

      "That's what I'm talking about!" is an American idiom that expresses delight or approval. He wasn't saying it was the topic of previous remarks.