use constant XX => ( ...

Discussion in 'Perl Misc' started by Julian Lafontaine, Nov 19, 2008.

  1. 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.
    Julian Lafontaine, Nov 19, 2008
    #1
    1. Advertising

  2. 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
    Josef Moellers, Nov 19, 2008
    #2
    1. Advertising

  3. Julian Lafontaine <> 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
    killfiled due to its use by several trolls.
    ]

    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
    Tad J McClellan, Nov 19, 2008
    #3
  4. Julian Lafontaine <> wrote in
    news:4923e512$0$2853$:

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

    comp.lang.perl.misc guidelines on the WWW:
    http://www.rehabitation.com/clpmisc/
    A. Sinan Unur, Nov 19, 2008
    #4
  5. Thank you Josef, Sinan,...

    Tad J McClellan a écrit :
    > Julian Lafontaine <> 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
    > killfiled due to its use by several trolls.
    > ]
    >
    Julian Lafontaine, Nov 19, 2008
    #5
  6. On 2008-11-19 10:06, Julian Lafontaine <> 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?
    Peter J. Holzer, Nov 23, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christopher M. Lusardi
    Replies:
    1
    Views:
    4,086
  2. Martin Magnusson
    Replies:
    2
    Views:
    503
    John Harrison
    Oct 8, 2004
  3. Tor Erik Soenvisen
    Replies:
    14
    Views:
    558
    Tim Roberts
    Nov 23, 2006
  4. Replies:
    4
    Views:
    338
    Keith Thompson
    Dec 14, 2006
  5. Victor Porton
    Replies:
    7
    Views:
    111
    TonyV
    Dec 11, 2007
Loading...

Share This Page