3 dimension array

T

Tanja

a.. How to make 3 dimensional array
b.. How to check pattern with asterix (wild) character?
e.g.: word linux
and I have word li??x, or ?inux to check

linux
li??x is OK
?inux is OK
 
P

Peter Wyzl

:* Tanja <[email protected]> [2005-01-02]:
: > a.. How to make 3 dimensional array
:
: my @array = [ # first dimension
: [[1,2,3], [1,2,3]],
: [[1,2,3], [1,2,3], [1,2,3]].
: ];
:
: Access: $a[0][1][2] => 3
:
: > b.. How to check pattern with asterix (wild) character? e.g.: word
: > linux and I have word li??x, or ?inux to check
: >
: > linux
: > li??x is OK
: > ?inux is OK
:
: Hm, I don't have a nice solution, but try this:
:
: /[l?][i?][n?][u?][x?]/

more like

/.i..x/

But I read the OP as wanting either /li..x/ or /.inux/ but am not really
certain.

Maybe \w would be better than . for the wildcards, but that still allows
[0-9] so maybe

/[a-z]i[a-z]{2}x/i

would be better..

dunno really...
 
M

Matt Garrish

Tanja said:
a.. How to make 3 dimensional array
b.. How to check pattern with asterix (wild) character?
e.g.: word linux
and I have word li??x, or ?inux to check

linux
li??x is OK
?inux is OK

One possibility would be to convert the string to a valid perl regex first
(assuming only * and ?):

my $word = 'linux';
my $pattern = 'l?n*';

$pattern =~ s/\?/[a-z]?/g;
$pattern =~ s/\*/[a-z]*/g;

print 'Regex will match linux' if $word =~ /^$pattern$/i;

Of course, the regex will match many other things, too, but it's not clear
whether that is important or not to you.

Matt
 
M

Matt Garrish

Sorry with respect to this question, just make one:

my @AoAoA = ( [[1,2,3], [4,5,6]], [[7,8,9], [0,1,2]] );

print $AoAoA[0][0][1]; # prints 2
print $AoAoA[1][0][2]; # prints 9

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top