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

Re: (Expert) Splicing a slice

by calin (Deacon)
on Sep 28, 2005 at 15:58 UTC ( [id://495811]=note: print w/replies, xml ) Need Help??


in reply to (Expert) Splicing a slice

Here's a failed attempt. It does NOT work correctly (inserting or deleting does not "shift" elements in the original array), also suffers from all the joys of local esp. you can not use the original foo while in the local scope. Just for your amusement.

$ perl @foo = 1..5; $" = ':'; { # setup *bar = \@foo; # or other aliasing method, or localise from foo itsel +f local @bar[3..$#bar]; splice @bar, 3; # "test" code print "[1] =@bar=\n"; splice @bar, 1, 0, 'new'; print "[2] =@bar=\n"; } # examine @foo after print "[3] =@foo=\n"; ^D [1] =1:2:3= [2] =1:new:2:3= [3] =1:new:2:4:5=

Update: minor wording update

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-04-23 20:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found