3 dimension array

Discussion in 'Perl Misc' started by Tanja, Jan 2, 2005.

  1. Tanja

    Tanja Guest

    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
    Tanja, Jan 2, 2005
    #1
    1. Advertising

  2. Tanja

    Peter Wyzl Guest

    "Julius Plenz" <> wrote in message
    news:...
    :* Tanja <> [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...

    --
    Wyzelli
    Peter Wyzl, Jan 2, 2005
    #2
    1. Advertising

  3. Tanja

    Matt Garrish Guest

    "Tanja" <> wrote in message
    news:41d7bec2$5.net...
    > 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
    Matt Garrish, Jan 2, 2005
    #3
  4. Tanja

    Matt Garrish Guest

    "Matt Garrish" <> wrote in message
    news:6UYBd.2769$P%...
    >
    > "Tanja" <> wrote in message
    > news:41d7bec2$5.net...
    >> 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
    Matt Garrish, Jan 2, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shapper

    Array Dimension

    Shapper, Jun 7, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    459
    =?Utf-8?B?RGF2aWQgQW50b24=?=
    Jun 8, 2005
  2. Larry Lindsey
    Replies:
    5
    Views:
    526
    Mike Wahler
    Sep 27, 2003
  3. James
    Replies:
    11
    Views:
    93,846
    yousafzai
    Jun 4, 2011
  4. Adam Hartshorne

    Multi-Dimension Array Question

    Adam Hartshorne, Jun 8, 2005, in forum: C++
    Replies:
    6
    Views:
    2,135
  5. Luuk
    Replies:
    15
    Views:
    808
    Nobody
    Feb 11, 2010
Loading...

Share This Page