use constant XX => ( ...

J

Julian Lafontaine

Hi Group,

There are two syntax for the "use constant" pragma: to declare a scalar
or to declare a list.

use constant CONST => scalarvalue;

use constant LIST => qw( listitem1, listitem2, listitem3);



I've found this in a perl module :Win32::Exe.
Could someone explain the syntax?


use constant DISPATCH_TABLE => (
"PE\0\0" => "PE",
'*' => sub { die "Incorrect PE header -- not a valid .exe file" },
);

What is DISPATCH_TABLE: a scalar or a list?

Thanks in advance.
 
J

Josef Moellers

Julian said:
Hi Group,

There are two syntax for the "use constant" pragma: to declare a scalar
or to declare a list.

use constant CONST => scalarvalue;

use constant LIST => qw( listitem1, listitem2, listitem3);



I've found this in a perl module :Win32::Exe.
Could someone explain the syntax?


use constant DISPATCH_TABLE => (
"PE\0\0" => "PE",
'*' => sub { die "Incorrect PE header -- not a valid .exe
file" },
);

What is DISPATCH_TABLE: a scalar or a list?

It is a list. The "=>" are "fat commas".
 
T

Tad J McClellan

use constant LIST => qw( listitem1, listitem2, listitem3);


You should always enable warnings when developing Perl code.



[ I also suggest choosing a less common munged address. I have
(e-mail address removed) killfiled due to its use by several trolls.
]
 
A

A. Sinan Unur

use constant DISPATCH_TABLE => (
"PE\0\0" => "PE",
'*' => sub { die "Incorrect PE header -- not a valid
.exe file" },
);

What is DISPATCH_TABLE: a scalar or a list?

It is a list which is most likely used to construct a hash someplace.

Sinan

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
J

Julian Lafontaine

Thank you Josef, Sinan,...

Tad J McClellan a écrit :
You should always enable warnings when developing Perl code.

You, are, definitely, right!,
[ I also suggest choosing a less common munged address. I have
(e-mail address removed) killfiled due to its use by several trolls.
]
 
P

Peter J. Holzer

There are two syntax for the "use constant" pragma: to declare a scalar
or to declare a list.

use constant CONST => scalarvalue;

"scalarvalue" is a scalar.
use constant LIST => qw( listitem1, listitem2, listitem3);

"qw( listitem1, listitem2, listitem3)" is a list (although it probably
doesn't contain the values you would expect).
I've found this in a perl module :Win32::Exe.
Could someone explain the syntax?


use constant DISPATCH_TABLE => (
"PE\0\0" => "PE",
'*' => sub { die "Incorrect PE header -- not a valid .exe file" },
);

What is DISPATCH_TABLE: a scalar or a list?

What is

(
"PE\0\0" => "PE",
'*' => sub { die "Incorrect PE header -- not a valid .exe file" },
)
?

A scalar or a list?
 

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,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top