Re: avoiding the hash
by smitz (Chaplain) on May 09, 2003 at 10:09 UTC
|
for (0 .. scalar(@array1)) {
$temparray[$_] = $array[$_] . '|' . $array2[$_];
}
then you can split @temparray on the bar (|)
Smitz
this reply makes me feel dirty | [reply] [Watch: Dir/Any] [d/l] [select] |
|
| [reply] [Watch: Dir/Any] |
|
will fail as soon as you have '|' in any of array's elements.
| [reply] [Watch: Dir/Any] |
|
He says numbers. The first time I too thought he needs an escape function.
| [reply] [Watch: Dir/Any] |
|
I wondered if there was a way of pairing up the numbers from two arrays
I assumed numbers in this case matched \d
Smitz
Update Messed up my Regex, thanks nkuvu
| [reply] [Watch: Dir/Any] |
Re: avoiding the hash
by zby (Vicar) on May 09, 2003 at 10:03 UTC
|
You can put them into a string:
$array[0] . "|" . $array2[0]
Or you can put them into an array:
my $newarray[0] = [$array[0], $array2[0]];
Update: Got rid of the escape function: they are just numbers. Got rid of the temporary variable. | [reply] [Watch: Dir/Any] [d/l] [select] |
Re: avoiding the hash
by Skeeve (Parson) on May 09, 2003 at 10:24 UTC
|
You simply want to avoid it because of the order? So why not not-avoid and do it this way:
@hash{@array}=@array2;
foreach $v (@array) {
print $hash{$v};
}
You have paired them in %hash and keep the sequence in @array.
| [reply] [Watch: Dir/Any] [d/l] |
|
| [reply] [Watch: Dir/Any] [d/l] |
|
*sigh* There is always a downside :-/
| [reply] [Watch: Dir/Any] |
Re: avoiding the hash
by bart (Canon) on May 09, 2003 at 12:08 UTC
|
You want a hash, but one that maintains the order? Just like in PHP? Then perhaps look into one of those many hash modules on CPAN. The FAQ only mentions Tie::IxHash, and seen its age, I gather it must be one of the more robust modules for this purpose. | [reply] [Watch: Dir/Any] |
Re: avoiding the hash
by Anonymous Monk on May 09, 2003 at 12:26 UTC
|
Your playing with fire, this an intrinsicly dangerous thing, mainly because no concrete coupling will exist between the two separate arrays and so your data could easily get out of sequence. I think what you are looking for is :
1) An Array of Arrays (perls way of doing higher dimentional data structures)
2) A routine to take your pair of arrays and combine them (re-index) into the array of arrays. | [reply] [Watch: Dir/Any] |