array question

A

a

Hi,
To declare an array, do I need to declare the size as well? If yes, how to
do it properly?
Can I do the following?
my @ary;
$ary[0]="a";
$ary[1]="b";
....
Thanks
 
J

Jürgen Exner

a said:
Hi,
To declare an array, do I need to declare the size as well?

No, normally you don't.
If yes, how to do it properly?
Can I do the following?
my @ary;
$ary[0]="a";
$ary[1]="b";

Have you tried it? What happened?

jue
 
J

Jürgen Exner

[Top posting corrected, please don't do that]
a said:
Jürgen Exner said:
Can I do the following?
my @ary;
$ary[0]="a";
$ary[1]="b";

Have you tried it? What happened?

Syntax error complains but not specific

Can't repro:

C:\tmp>type t.pl
use strict; use warnings;
my @ary;
$ary[0]="a";
$ary[1]="b";

C:\tmp>perl -c t.pl
t.pl syntax OK

jue
 
A

a

Hi
By the way, how to comment the whole block of code?
Thanks

Bernard El-Hagin said:
a said:
Hi,
To declare an array, do I need to declare the size as well?

No.


Can I do the following?
my @ary;
$ary[0]="a";
$ary[1]="b";


Yes.


See perldoc perldata for more details.
 
A

a

syntax error at filename line 20, near "]~"
Thanks

Bernard El-Hagin said:
[don't top-post]


a said:
Jürgen Exner said:
a wrote:
Hi,
To declare an array, do I need to declare the size as well?

No, normally you don't.

If yes, how to do it properly?
Can I do the following?
my @ary;
$ary[0]="a";
$ary[1]="b";

Have you tried it? What happened?


Hi,
Syntax error complains but not specific


They are always specific. What was the error message you got?
 
A

A. Sinan Unur

[ Please don't top-post ]
By the way, how to comment the whole block of code?

You are expected to read the FAQ before you post here:

perldoc -q "How can I comment out a large block of perl code?"
 
X

Xicheng

a said:
Hi,
To declare an array, do I need to declare the size as well? If yes, how to
do it properly?
no, check any Perl book containing "autovivification", or check
http://www.answers.com for "autovivification"..
Can I do the following?
my @ary;
$ary[0]="a";
$ary[1]="b";
Generally you do it the following way:
my @arr = qw(a b);
or
my @arr = ('a','b');

Xicheng
 
P

Paul Lalli

Please fix your quoting. Post your reply *below* the material you are
replying to, and trim the quotes appropriately. This is not the first
time you have been asked. If you continue to be rude by ignoring these
requests, people will not be likely to continue to help you.
"Bernard El-Hagin"
[don't top-post]
a said:
"Jürgen Exner"
a wrote:
Can I do the following?
my @ary;
$ary[0]="a";
$ary[1]="b";

Have you tried it? What happened?
Syntax error complains but not specific

They are always specific. What was the error message you got?
syntax error at filename line 20, near "]~"

You do not have any ]~ sequence in the code you showed. Therefore, the
code you showed us has nothing to do with your error.

Please read the posting guidelines for this group. Then post a SHORT
but COMPLETE script that demonstrates the error you are having.

Paul Lalli
 
T

Tad McClellan

a said:
syntax error at filename line 20, near "]~"


line _20_ huh?

Bernard El-Hagin said:
[don't top-post]
^^^^^^^^^^^^^^
^^^^^^^^^^^^^^
^^^^^^^^^^^^^^

Did you see that?

If you don't understand what it means, then ask what it means.

If you do understand what it means, then stop doing it!

a said:
"Jürgen Exner" <[email protected]> ¼¶¼g©ó¶l¥ó·s»D
:K%HBf.1621$iD.886@trnddc08...
a wrote:
Can I do the following?
my @ary;
$ary[0]="a";
$ary[1]="b";

Have you tried it? What happened?


Hi,
Syntax error complains but not specific


They are always specific. What was the error message you got?


We have seen only a 3-line program.

There *is no* line 20, so you are on your own...


Have you seen the Posting Guidelines that are posted here frequently?
 

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

Forum statistics

Threads
474,183
Messages
2,570,965
Members
47,511
Latest member
svareza

Latest Threads

Top