Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > use constant XX => ( ...

Reply
Thread Tools

use constant XX => ( ...

 
 
Julian Lafontaine
Guest
Posts: n/a
 
      11-19-2008
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.
 
Reply With Quote
 
 
 
 
Josef Moellers
Guest
Posts: n/a
 
      11-19-2008
Julian Lafontaine wrote:
> 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".

--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
 
Reply With Quote
 
 
 
 
Tad J McClellan
Guest
Posts: n/a
 
      11-19-2008
Julian Lafontaine <(E-Mail Removed)> wrote:


> 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
http://www.velocityreviews.com/forums/(E-Mail Removed) killfiled due to its use by several trolls.
]

--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      11-19-2008
Julian Lafontaine <(E-Mail Removed)> wrote in
news:4923e512$0$2853$(E-Mail Removed):

> 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 <(E-Mail Removed)>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
Reply With Quote
 
Julian Lafontaine
Guest
Posts: n/a
 
      11-19-2008
Thank you Josef, Sinan,...

Tad J McClellan a écrit :
> Julian Lafontaine <(E-Mail Removed)> wrote:
>
>
>> use constant LIST => qw( listitem1, listitem2, listitem3);

>
>
> 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 Removed) killfiled due to its use by several trolls.
> ]
>

 
Reply With Quote
 
Peter J. Holzer
Guest
Posts: n/a
 
      11-23-2008
On 2008-11-19 10:06, Julian Lafontaine <(E-Mail Removed)> wrote:
> 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?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"use constant X=>(1,2);" or "use constant X=>[1,2];"? Victor Porton Perl Misc 7 12-11-2007 09:10 PM
pointers to constant characters and constant pointers to characters sam_cit@yahoo.co.in C Programming 4 12-14-2006 11:10 PM
len(var) is [CONSTANT] equal to len(var) == [CONSTANT]? Tor Erik Soenvisen Python 14 11-23-2006 09:57 PM
"Non-constant" constant can't be used as template argument Martin Magnusson C++ 2 10-08-2004 08:41 AM
Understanding How To Use #ifdef Constant #define Constant Sequence In Multible Files Christopher M. Lusardi C++ 1 09-02-2004 07:43 AM



Advertisments