Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: changing the position of an element in an array

by blazar (Canon)
on Nov 17, 2005 at 13:29 UTC ( #509399=note: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my $pos;
    for (0..$#array) {
    ...
          if $array[$_] eq $wanted;
    }
    @array[$pos,-1]=@array[-1,$pos];
    
  2. or download this
    my $pos;
    for (0..$#array) {
    ...
          if $array[$_] eq $wanted;
    }
    @array=@array[0..$pos-1, $pos+1..$#array, $pos];
    
  3. or download this
    @array=((grep $_ ne $wanted, @array), $wanted);
    
  4. or download this
    @array = do {
        my $i;
    ...
        (grep $i || $_ ne $wanted || $i++, @_),
          $i ? $wanted : ();
    }
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (11)
As of 2014-09-16 21:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (49 votes), past polls