Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: changing the position of an element in an array

by blazar (Canon)
on Nov 17, 2005 at 13:29 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://509399]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-25 14:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found