2013-07-21T05:16:56 flixxflaxxinsbesondere wenn ich sie zwischen funktionen hin und herreiche und dann immer aus den pointern die normalen arrays basteln muss...
1 2 3 4 5 6 7 8 9 10 11 12 13
sub foo { my ($tuples) = @_; # über alle tupel iterieren for my $tuple (@$tuples) { my $first = $tuple->[0]; my ($first, $second) = @$tuple; } say $tuples->[23]->[0]; # wert eins aus tupel nummer 24 } my $all_tuples = [ [2,3], [7,8], [101,102], ... ]; foo($all_tuples);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$t1 : A, B, C
$t2 : G, H, I
$t3 : A, B, C, D, E, F, G, H, I
--------------
$t1->[1], $t3->[4], $t2->[1] : B, E, H
$t3->[1], $t3->[4], $t3->[7] : B, E, H
@$t3[1,4,7]) : B, E, H
$t3->get(1,4,7) : B, E, H
$t3->(1,4,7) : B, E, H
--------------
$t6 : A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P
$t6->(0,3,6,9,12) : A, D, G, J, M
--------------
A,B | C,D | E,F | G,H | I,J | K,L | M,N | O,P |
--------------
$t6 : A, B-1, C, D, E-3, F, G, H-2, I, J, K-4, L, M, N-5, O, P, Q, R, S, T, U
1 2 3 4 5 6 7 8 9 10
my $step=2; my $pos=0; while( $pos <= 10) { my @list=@t[$pos..$pos+$step-1]; # ... $pos+=$step; }
2013-07-21T21:33:57 topegWas du beschreibst wäre in Python t[0:10:2] was Perl so nicht kann.
2013-07-21T21:41:21 betterworld2013-07-21T21:33:57 topegWas du beschreibst wäre in Python t[0:10:2] was Perl so nicht kann.
Habe ich das beschrieben? Ich habe nur gesagt, was das Modul von hlubenow macht.
my $self = {scalarvariable => 1};
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#!/usr/bin/env python # coding: iso-8859-1 # Statt: a = (((1, 2), (3, 4)), ((5, 6), (7, 8)), ((9, 10), (11, 12))) print a[2][1][1] # So: class Container: def __init__(self): self.e_00_00 = (1, 2) self.e_00_01 = (3, 4) self.e_01_00 = (5, 6) self.e_01_01 = (7, 8) self.e_02_00 = (9, 10) self.e_02_01 = (11, 12) c = Container() print c.e_02_01[1]
1 2 3 4 5 6 7 8 9 10 11 12 13
{ package Container; use Moose; has e_00_00 => ( is => 'ro', isa => 'ArrayRef[Int]', default => sub { [1,2] }, auto_deref => 1 ); has e_00_01 => ( is => 'ro', isa => 'ArrayRef[Int]', default => sub { [3,4] }, auto_deref => 1 ); has e_01_00 => ( is => 'ro', isa => 'ArrayRef[Int]', default => sub { [5,6] }, auto_deref => 1 ); has e_01_01 => ( is => 'ro', isa => 'ArrayRef[Int]', default => sub { [7,8] }, auto_deref => 1 ); has e_02_00 => ( is => 'ro', isa => 'ArrayRef[Int]', default => sub { [9,10] }, auto_deref => 1 ); has e_02_01 => ( is => 'ro', isa => 'ArrayRef[Int]', default => sub { [11,12] }, auto_deref => 1 ); } my $c = Container->new; print +($c->e_02_00)[0];
1 2 3 4 5
my @x = ([[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]); print $x[2][1][1];
1 2 3 4 5 6 7 8 9
my %c = ( e_00_01 => [3, 4], e_01_00 => [5, 6], e_01_01 => [7, 8], e_02_00 => [9, 10], e_02_01 => [11, 12] ); say $c{e_00_01}[1];
2013-07-25T12:49:52 MuffiWas ist nicht so ganz verstanden hab ist, was jetzt z.B. an meiner Perllösung so kompliziert sein soll.
1 2 3 4 5
my @a = (1..4); my @b = (5..7); my @c = (@a, @b); # das selbe wie (1..7); my @d = (\@a, \@b); # wie ([1..4],[5..7]); my @e = ((1..4), (5..7)); # wie @c