Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^4: Perl's feature to determine, in current point of loop, that this is the last one?

by ikegami (Patriarch)
on Jan 24, 2022 at 04:01 UTC ( #11140774=note: print w/replies, xml ) Need Help??


in reply to Re^3: Perl's feature to determine, in current point of loop, that this is the last one?
in thread Perl's feature to determine, in current point of loop, that this is the last one?

It's so easy to avoid the limitation. Replace $v eq $values[-1] with \$v == \$values[-1]

  • Comment on Re^4: Perl's feature to determine, in current point of loop, that this is the last one?
  • Select or Download Code

Replies are listed 'Best First'.
Re^5: Perl's feature to determine, in current point of loop, that this is the last one?
by LanX (Sage) on Jan 24, 2022 at 08:44 UTC
    > It's so easy to avoid the limitation.

    unfortunately no, but good idea nonetheless ... :)

    DB<39> x @input 0 2 1 7 2 11 3 15 DB<40> use experimental 'refaliasing'; \$input[1] = \$input[-1] DB<41> x @input 0 2 1 15 2 11 3 15 DB<42> for my $v (@input) { say $v if \$v==\$input[-1] } 15 15 DB<43>

    I'm not even sure that experimental feature is even needed...

    IIRC one could somehow use typeglob aliasing on array elements.

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

      unfortunately no, but good idea nonetheless ... :)

      Good catch. I'll add a warning to my answer that first suggested the idea.

      I'm not even sure that experimental feature is even needed...

      Correct.

      my $inputs = sub { \@_ }->( 0, $x, $x ); for my $v (@$inputs) { say \$v; }
      SCALAR(0x559bb5b21960) SCALAR(0x559bb5b33228) SCALAR(0x559bb5b33228)

      I imagine that would Data::Alias can also achieve this.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2022-05-25 16:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (90 votes). Check out past polls.

    Notices?