Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Array: inserting what isn't there

by arthas (Hermit)
on May 30, 2003 at 14:11 UTC ( [id://261852]=note: print w/replies, xml ) Need Help??


in reply to Array: inserting what isn't there

Hi!

The following code creates a second array which is the original one completed with the missing elements. You can then copy it back over the old one. Otherwise, you can try to work something out with splice() to work directly on the original array.
use strict; my @array = ("1.found","2.found", "4.found", "5.found"); my @array2; my $i = 1; foreach my $a(@array) { my ($n) = split /\./, $a; while ($n > $i) { push @array2, "$i.lost"; $i++; } push @array2, $a; $i++; }
Michele.

Replies are listed 'Best First'.
Re: Re: Array: inserting what isn't there
by aquarium (Curate) on May 31, 2003 at 12:40 UTC
    do you realy need the final array with the negatives filled in?...when they can be inferred in any further access to the array, ie the negative element won't be there. also, since this looks like a binary problem (the result is either 1 or 0) you should realy think about expressing it as such, and save LOTS of space and time walking through it.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-04-19 20:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found