Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: question about using constants

by emilford (Friar)
on Feb 02, 2005 at 20:23 UTC ( [id://427420]=note: print w/replies, xml ) Need Help??


in reply to Re: question about using constants
in thread question about using constants

So then is that all the @{[]} is doing? Beyond finding a cleaner way, I want to also understand the workings of this.

Replies are listed 'Best First'.
Re^3: question about using constants
by dragonchild (Archbishop) on Feb 02, 2005 at 20:24 UTC
    You're creating an array reference, then dereferencing it. In the process, you're allowed to make any sort of Perl executing code, not just variable interpolation.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Re^3: question about using constants
by davido (Cardinal) on Feb 03, 2005 at 00:45 UTC

    It really falls under the category of one of those things that is possible but not all that advisable.

    Just because it's possible to say, "Let's interpolate a function: @{[PI]}\n";, I'm not convinced that it's in any way clearer than: "Lets not interpolate: " . PI . "\n";

    In the first example the double-quoted string is parsed for interpolation components. The @{...} is found, and that tells Perl you want to interpolate a reference to an array. And the [....] creates that reference, based on the "...." expression.

    In the second example, you start with a string, concatenate the evaluated expression, and concatenate a newline character. Much simpler, and less work.


    Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://427420]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found