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

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

1. ### JozaGuest

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

Thanks

Joza, Oct 2, 2006

3. ### paulGuest

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

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

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

>
> perldoc perlintro
>
> --
> Email: http://www.gunnar.cc/cgi-bin/contact.pl

paul, Oct 2, 2006
4. ### timGuest

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
5. ### -berlin.deGuest

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
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
6. ### timGuest

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
> 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
7. ### timGuest

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

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
8. ### David SquireGuest

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

tim wrote:
>
> 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

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

tim <> wrote:

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,

>

--
Perl programming
Fort Worth, Texas

10. ### timGuest

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

> tim <> wrote:
>

>
>
> No you're not.

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

> So long!

Bye

tim, Oct 2, 2006
11. ### Ala QumsiehGuest

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

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
12. ### -berlin.deGuest

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

>
> 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
13. ### Ala QumsiehGuest

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
14. ### -berlin.deGuest

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

> 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