Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Print the Global special constant Variable

by aantonyselvam (Beadle)
on Feb 09, 2011 at 12:25 UTC ( [id://887180]=perlquestion: print w/replies, xml ) Need Help??

aantonyselvam has asked for the wisdom of the Perl Monks concerning the following question:

How should I print the Global special constant Variable in the double quote. I should not use the temporary variable also to store

print "This is the package =>" . __PACKAGE__ . "<="; (or) $pack = __PACKAGE__; print "This is the package => $pack <=";

instead of the above statement I need to use the variable in print statement as follows.

print "This is the package => __PACKAGE__ <=";

Replies are listed 'Best First'.
Re: Print the Global special constant Variable
by Anonyrnous Monk (Hermit) on Feb 09, 2011 at 12:56 UTC

    If you absolutely must interpolate the constant (I'm not sure why, and what's wrong with your first solution using concatenation...), you can say:

    print "This is the package => ${\__PACKAGE__} <="; # or print "This is the package => @{[__PACKAGE__]} <=";

    The idea is just to create a reference to whatever you want to interpolate, and then dereference it using the double-quote-interpolated sigils ${...} or @{...}.

Re: Print the Global special constant Variable
by AnomalousMonk (Archbishop) on Feb 09, 2011 at 19:29 UTC

    printf is a print statement. Why not just use that?

    >perl -wMstrict -le "printf 'This is the package => %s <=', __PACKAGE__; " This is the package => main <=
Re: Print the Global special constant Variable
by vetrivel (Sexton) on Feb 09, 2011 at 15:46 UTC
    The below code is used to print the Global special constant value
    print "Program Name is ${\__FILE__} " ;

Log In?
Username:
Password:

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

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

    No recent polls found