in reply to Re: What's the idiom for finding and removing the found @ARRAY element?
in thread What's the idiom for finding and removing the found @ARRAY element?

Good point about the reverse, if I was removing more than one. That's what I'm doing, but returning out of the loop as soon as I found it.

Now, can you apply the $# syntax to a reference? My brain gagged at that, even if Perl wouldn't (I went with scalar -1).

  • Comment on Re: Re: What's the idiom for finding and removing the found @ARRAY element?

Replies are listed 'Best First'.
Re^3: What's the idiom for finding and removing the found @ARRAY element?
by Aristotle (Chancellor) on Nov 06, 2002 at 12:25 UTC
    my $arr = [(1) x 5]; print $#$arr;

    Makeshifts last the longest.

Re: Re: Re: What's the idiom for finding and removing the found @ARRAY element?
by jdporter (Paladin) on Nov 06, 2002 at 14:11 UTC
    Sure, that's what curly braces are for. (Well, one of the many things.)
    for my $i ( reverse 0 .. $#{ $ar } ) { splice @{ $ar }, 0, $i; }