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

I get the following error when trying to print the below statement,even though $profile_name is declared,if I remove the underscore after profile_name the error is gone.What am I doing wrong?

Global symbol "$profile_name_" requires explicit package name at c:\perl_scripts\profile.pl line 32

print "\n$profile_name_$opt_$date\n";

Replies are listed 'Best First'.
Re: Error while printing a variable
by GrandFather (Saint) on Mar 24, 2011 at 01:03 UTC

    _ is a valid character in an identifier so Perl sees $profile_name_ as a variable name. To avoid the problem you can:

    print "\n${profile_name}_$opt_$date\n";

    Note the {} to delimit the variable name.

    True laziness is hard work