CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [hwnd] constant in perl (use constant)?: Edit Log



2teez
Novice

Jun 2, 2013, 10:44 PM


Views: 482
Re: [hwnd] constant in perl (use constant)?

If I may add a 2 'kobo' note on what [ hwnd ] posted.

Code
use constant BAR, "foo";     # This won't work if you 'use strict'


As well as this:

Code
 my %h = ( president , 'obama');

WHY? Because the words in hash before the comma is a BAREWORD, which is not allowed while "strict subs" in use. So also is the 'BAR' as shown above.
Using the 'FAT COMMA' resolves this for the reason previously given.
However, this would work:

Code
use constant BAR(), "foo";     # This works

The writer of Perl Best Practice would argue in favour of [Readonly], others [Const::Fast] as a better alternative for using constant 'like' other programming language.


(This post was edited by 2teez on Jun 2, 2013, 10:57 PM)


Edit Log:
Post edited by 2teez (Novice) on Jun 2, 2013, 10:54 PM
Post edited by 2teez (Novice) on Jun 2, 2013, 10:56 PM
Post edited by 2teez (Novice) on Jun 2, 2013, 10:57 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives