Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hello karlgoethebier,

I’ve been a fan of Const::Fast since I discovered it recently in the Perl Advent Calendar 2017. But constant does have one important advantage over Const::Fast: it is applied at compile time, whereas Const::Fast takes effect only at run time. So, in this respect, Const::Fast suffers from the same limitation, identified by choroba, as the &CONSTANT syntax for the constant pragma — the constant isn’t inlined:

0:59 >perl -Mstrict -MData::Dump -MConst::Fast -we "use constant A => + 12; const our $B => 13; my %h = ( (A) => 'twelve', $B => 'thirteen') +; dd \%h;" { 12 => "twelve", 13 => "thirteen" } 0:59 >perl -Mstrict -MO=Deparse -MData::Dump -MConst::Fast -we "use c +onstant A => 12; const our $B => 13; my %h = ( (A) => 'twelve', $B => + 'thirteen'); dd \%h;" BEGIN { $^W = 1; } use strict; use Data::Dump; use Const::Fast; use constant ('A', 12); &const(\our $B, 13); my(%h) = (12, 'twelve', $B, 'thirteen'); dd(\%h); -e syntax OK 0:59 >

(AFAICT, this also makes Const::Fast unsuitable in situations where one wants to write code like this:

use constant DEBUG => 0; ... perform_some_debugging_operation() if DEBUG; ...

and have the compiler remove the expensive operation when it sees that DEBUG is false.)

Update: Changed perform_expensive_debugging_operation() to perform_some_debugging_operation(), because, as Eily pointed out in a private message, the cost of the operation is irrelevant if DEBUG (or $DEBUG) is false.

Cheers,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re^2: Using constants as hash keys by Athanasius
in thread Using constants as hash keys by choroba

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-25 22:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found