Thread mehrere Referenzen von arrays zurückgeben (26 answers)
Opened by Gustl at 2013-06-25 17:29

Gast wer
 2013-06-25 17:44
#168574 #168574
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/perl -w
use strict;
use warnings;
 
my @array1 = (1,2,3,4,5,6,7,8,9,10);
my @array2 = (10,20,30,40,50,60,70,80,90,100);
my @array3 = (100,200,300,400,500,600,700,800,900,1000);
my @array4 = (1000,2000,3000,4000,5000,6000,7000,8000,9000,10000);

reverse_all_arrays(\@array1, \@array2, \@array3, \@array4);

sub reverse_all_arrays{
  @$_ = reverse(@$_) for(@_);
}


oder:

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/perl -w
use strict;
use warnings;
 
my @array1 = (1,2,3,4,5,6,7,8,9,10);
my @array2 = (10,20,30,40,50,60,70,80,90,100);
my @array3 = (100,200,300,400,500,600,700,800,900,1000);
my @array4 = (1000,2000,3000,4000,5000,6000,7000,8000,9000,10000);

my ($array1_ref, $array2_ref, $array3_ref, $array4_ref) = reverse_all_arrays(\@array1, \@array2, \@array3, \@array4);
@array1 = @$array1_ref;
@array2 = @$array2_ref;
@array3 = @$array3_ref;
@array4 = @$array4_ref;


sub reverse_all_arrays{
  my @ret;
  push( @ret, [reverse(@$_)] ) for(@_);
  return @ret;
}

Last edited: 2013-06-25 17:53:48 +0200 (CEST)

View full thread mehrere Referenzen von arrays zurückgeben