How to make 2 dimensinal aray in Perl $mat(x,y)?

Discussion in 'Perl Misc' started by Joza, Oct 2, 2006.

  1. Joza

    Joza Guest

    How to make 2 dimensinal aray in Perl $mat(x,y)?

    Thanks
     
    Joza, Oct 2, 2006
    #1
    1. Advertising

  2. Gunnar Hjalmarsson, Oct 2, 2006
    #2
    1. Advertising

  3. Joza

    paul Guest

    Re: How to make 2 dimensinal aray in Perl $mat(x,y)?

    You can check in Perl doc along with the installation..


    Gunnar Hjalmarsson wrote:
    > Joza wrote:
    > > How to make 2 dimensinal aray in Perl $mat(x,y)?

    >
    > perldoc perlintro
    >
    > --
    > Gunnar Hjalmarsson
    > Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    paul, Oct 2, 2006
    #3
  4. Joza

    tim Guest

    Re: How to make 2 dimensinal aray in Perl $mat(x,y)?

    Hello

    The syntax is like so:

    $mat[x][y]

    where x and y are >= 0


    Joza wrote:
    > How to make 2 dimensinal aray in Perl $mat(x,y)?
    >
    > Thanks
     
    tim, Oct 2, 2006
    #4
  5. Joza

    -berlin.de Guest

    Re: How to make 2 dimensinal aray in Perl $mat(x,y)?

    tim <> wrote in comp.lang.perl.misc:
    > Joza wrote:


    [top posting corrected, please don't do that]

    > > How to make 2 dimensinal aray in Perl $mat(x,y)?
    > >
    > > Thanks


    > Hello
    >
    > The syntax is like so:
    >
    > $mat[x][y]


    That's not Perl, unless x and y are predefined functions, constants
    for example. Also, your syntax is already a simplification. The
    correct syntax is

    $mat[ $x]->[ $y]

    Strictly speaking, even that is a simplification. The basic syntax is

    ${ $mat[ $x] }[ $y]

    > where x and y are >= 0


    Wrong. Perl allows access through negative indices.

    Anno
     
    -berlin.de, Oct 2, 2006
    #5
  6. Joza

    tim Guest

    Re: How to make 2 dimensinal aray in Perl $mat(x,y)?

    sure, i realise that x and y aren't proper perl variables, i just used
    them because Joza did in his post!

    didn't know about the negative array indices though - thanks for that!


    -berlin.de wrote:
    > tim <> wrote in comp.lang.perl.misc:
    > > Joza wrote:

    >
    > [top posting corrected, please don't do that]
    >
    > > > How to make 2 dimensinal aray in Perl $mat(x,y)?
    > > >
    > > > Thanks

    >
    > > Hello
    > >
    > > The syntax is like so:
    > >
    > > $mat[x][y]

    >
    > That's not Perl, unless x and y are predefined functions, constants
    > for example. Also, your syntax is already a simplification. The
    > correct syntax is
    >
    > $mat[ $x]->[ $y]
    >
    > Strictly speaking, even that is a simplification. The basic syntax is
    >
    > ${ $mat[ $x] }[ $y]
    >
    > > where x and y are >= 0

    >
    > Wrong. Perl allows access through negative indices.
    >
    > Anno
     
    tim, Oct 2, 2006
    #6
  7. Joza

    tim Guest

    Re: How to make 2 dimensinal aray in Perl $mat(x,y)?

    yup! sorry about before....

    Michele Dondi wrote:
    > On 2 Oct 2006 04:20:47 -0700, "tim" <> wrote:
    >
    > >sure, i realise that x and y aren't proper perl variables, i just used
    > >them because Joza did in his post!
    > >
    > >didn't know about the negative array indices though - thanks for that!
    > >
    > >
    > >-berlin.de wrote:

    > [snip full quoted content]
    >
    > Thank you in advance for not top-posting next time! You won't, will
    > you?!?
    >
    >
    > Michele
    > --
    > {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    > (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    > .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    > 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
     
    tim, Oct 2, 2006
    #7
  8. Joza

    David Squire Guest

    Re: How to make 2 dimensinal aray in Perl $mat(x,y)?

    tim wrote:
    > yup! sorry about before....
    >
    > Michele Dondi wrote:
    >>
    >> Thank you in advance for not top-posting next time! You won't, will
    >> you?!?


    Tim, you did it again! If you don't know what top-posting is, please
    read the posting guidelines for this group that are posted here twice
    weekly (and are thus all over the archive at Google).

    Not many chances left...


    DS
     
    David Squire, Oct 2, 2006
    #8
  9. Re: How to make 2 dimensinal aray in Perl $mat(x,y)?

    tim <> wrote:

    > sorry about before....



    No you're not.

    So long!


    > Michele Dondi wrote:
    >> On 2 Oct 2006 04:20:47 -0700, "tim" <> wrote:
    >>
    >> >sure, i realise that x and y aren't proper perl variables, i just used
    >> >them because Joza did in his post!
    >> >
    >> >didn't know about the negative array indices though - thanks for that!
    >> >
    >> >
    >> >-berlin.de wrote:

    >> [snip full quoted content]
    >>
    >> Thank you in advance for not top-posting next time! You won't, will
    >> you?!?
    >>
    >>
    >> Michele
    >> --
    >> {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    >> (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    >> .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    >> 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,

    >



    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Oct 2, 2006
    #9
  10. Joza

    tim Guest

    Re: How to make 2 dimensinal aray in Perl $mat(x,y)?

    Tad McClellan wrote:
    > tim <> wrote:
    >
    > > sorry about before....

    >
    >
    > No you're not.


    Yes I am, I just didn't know what it was before!

    > So long!


    Bye
     
    tim, Oct 2, 2006
    #10
  11. Joza

    Ala Qumsieh Guest

    Re: How to make 2 dimensinal aray in Perl $mat(x,y)?

    -berlin.de wrote:

    > tim <> wrote in comp.lang.perl.misc:
    >> Joza wrote:

    >
    > [top posting corrected, please don't do that]
    >
    >> > How to make 2 dimensinal aray in Perl $mat(x,y)?
    >> >
    >> > Thanks

    >
    >> Hello
    >>
    >> The syntax is like so:
    >>
    >> $mat[x][y]

    >
    > That's not Perl, unless x and y are predefined functions, constants
    > for example. Also, your syntax is already a simplification.


    Yes, but besides the fact that x and y should have been $x and $y, his
    syntax was correct.

    > The correct syntax is
    >
    > $mat[ $x]->[ $y]


    Perl allows you to drop the arrow between indices, so this is not any more
    correct than the $mat[$x][$y] syntax.

    > Strictly speaking, even that is a simplification. The basic syntax is
    >
    > ${ $mat[ $x] }[ $y]


    Now, you are just showing off. I don't see what advantage pointing this out
    has, except intimidating the OP and confusing him/her even more with
    unnecessary information.

    --Ala
     
    Ala Qumsieh, Oct 2, 2006
    #11
  12. Joza

    -berlin.de Guest

    Re: How to make 2 dimensinal aray in Perl $mat(x,y)?

    Ala Qumsieh <> wrote in comp.lang.perl.misc:
    > -berlin.de wrote:
    >
    > > tim <> wrote in comp.lang.perl.misc:
    > >> Joza wrote:

    > >
    > > [top posting corrected, please don't do that]
    > >
    > >> > How to make 2 dimensinal aray in Perl $mat(x,y)?
    > >> >
    > >> > Thanks

    > >
    > >> Hello
    > >>
    > >> The syntax is like so:
    > >>
    > >> $mat[x][y]

    > >
    > > That's not Perl, unless x and y are predefined functions, constants
    > > for example. Also, your syntax is already a simplification.

    >
    > Yes, but besides the fact that x and y should have been $x and $y, his
    > syntax was correct.
    >
    > > The correct syntax is
    > >
    > > $mat[ $x]->[ $y]

    >
    > Perl allows you to drop the arrow between indices, so this is not any more
    > correct than the $mat[$x][$y] syntax.
    >
    > > Strictly speaking, even that is a simplification. The basic syntax is
    > >
    > > ${ $mat[ $x] }[ $y]

    >
    > Now, you are just showing off. I don't see what advantage pointing this out
    > has, except intimidating the OP and confusing him/her even more with
    > unnecessary information.


    Knowing how the arrow notation relates to the general de-referencing
    syntax isn't entirely useless.

    The answer I was replying to was way too pat. I gave an extra complete
    one in contrast. Neither did I intend to confuse anyone, nor to show off
    (what, really?).

    Anno
     
    -berlin.de, Oct 2, 2006
    #12
  13. Joza

    Ala Qumsieh Guest

    Re: How to make 2 dimensinal aray in Perl $mat(x,y)?

    -berlin.de wrote:

    > Knowing how the arrow notation relates to the general de-referencing
    > syntax isn't entirely useless.


    I never said it was useless. But you made it sound like it's more correct
    than dropping the arrow, which I disagree with. TMTOWTDI, and all of the
    ways are equally correct.

    People don't need to know the internals of Perl to use it, just like people
    don't need to know the internals of combustion engines to drive cars.

    > The answer I was replying to was way too pat. I gave an extra complete
    > one in contrast. Neither did I intend to confuse anyone, nor to show off
    > (what, really?).


    and I didn't intend to offend. But imagine what the OP, who's obviously a
    Perl newbie, would think after reading that $mat[$x][$y] is better written
    as $mat[$x]->[$y], which is better written as ${ $mat[ $x] }[ $y].

    My point is that an answer should be on the same level as the question
    itself. If you want to give more information, then you should at least
    point to docs that go into more depth about the subject.

    --Ala
     
    Ala Qumsieh, Oct 3, 2006
    #13
  14. Joza

    -berlin.de Guest

    Re: How to make 2 dimensinal aray in Perl $mat(x,y)?

    Ala Qumsieh <> wrote in comp.lang.perl.misc:
    > -berlin.de wrote:
    >
    > > Knowing how the arrow notation relates to the general de-referencing
    > > syntax isn't entirely useless.

    >
    > I never said it was useless.


    Superfluous, the same as "useless in this context".

    > But you made it sound like it's more correct
    > than dropping the arrow, which I disagree with. TMTOWTDI, and all of the
    > ways are equally correct.


    I'm not saying that one is more correct than the other, but depending
    on context one can be more appropriate than the other. In particular,
    I tend to relegate the "short" syntax without the arrow to cases where
    the structure is conceptually a multi-dimensional array. In general
    data structures I write the arrow. I see that the case in point was
    in fact a two-dimensional array. Still, showing only the short syntax
    is misleading.

    > People don't need to know the internals of Perl to use it, just like people
    > don't need to know the internals of combustion engines to drive cars.


    The difference between $x[ $i] and $x->[ $i] is hardly arcane. You
    *must* know it to deal with references successfully.

    > > The answer I was replying to was way too pat. I gave an extra complete
    > > one in contrast. Neither did I intend to confuse anyone, nor to show off
    > > (what, really?).

    >
    > and I didn't intend to offend. But imagine what the OP, who's obviously a
    > Perl newbie, would think after reading that $mat[$x][$y] is better written
    > as $mat[$x]->[$y], which is better written as ${ $mat[ $x] }[ $y].
    >
    > My point is that an answer should be on the same level as the question
    > itself. If you want to give more information, then you should at least
    > point to docs that go into more depth about the subject.


    I admit that I hardly thought of the OP of the thread when I wrote
    the posting. I responded to the reply which I found lacking. That's
    the well-known phenomenon of thread drift. Every Usenaut (where is
    Alan Flavell, BTW?) must cope with that.

    Anno
     
    -berlin.de, Oct 3, 2006
    #14
    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. ss
    Replies:
    1
    Views:
    1,386
    Gordon Beaton
    Jun 22, 2006
  2. Tom St Denis

    Sorting a string aray in order of string length

    Tom St Denis, Jul 9, 2003, in forum: C Programming
    Replies:
    9
    Views:
    480
    Kevin Easton
    Jul 10, 2003
  3. jose flanigan
    Replies:
    0
    Views:
    403
    jose flanigan
    Jul 3, 2003
  4. JoeC
    Replies:
    12
    Views:
    638
  5. max
    Replies:
    6
    Views:
    161
    RedGrittyBrick
    Jul 14, 2005
Loading...

Share This Page