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

A

anno4000

tim said:
Joza wrote:

[top posting corrected, please don't do that]
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
 
T

tim

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!


tim said:
Joza wrote:

[top posting corrected, please don't do that]
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
 
T

tim

yup! sorry about before....

Michele said:
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!


(e-mail address removed)-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,
 
D

David Squire

tim said:
yup! sorry about before....

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
 
T

Tad McClellan

tim said:
sorry about before....


No you're not.

So long!

Michele said:
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!


(e-mail address removed)-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,
 
A

Ala Qumsieh

tim said:
Joza wrote:

[top posting corrected, please don't do that]
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
 
A

anno4000

Ala Qumsieh said:
tim said:
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
 
A

Ala Qumsieh

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
 
A

anno4000

Ala Qumsieh said:
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
 

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,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top