3 dimension array

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
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

Re: 3 dimension array

> 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?]/

Julius

Re: 3 dimension array

: > 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]x/i

would be better..

dunno really...

--
Wyzelli

Re: 3 dimension array

>  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

Re: 3 dimension array

>
>>  a.. How to make 3 dimensional array

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