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__} " ;