Nikhil Hegde Nikhil Hegde - 22 days ago 6
Perl Question

Not sure of the reason for output value

I have these two statements in a perl code that I'm trying to understand.

our $CSITOOLS=`/x/eng/csitools/netapp_menu/common/csitools.sh`;
print "${CSITOOLS}\n";


Output:

/x/eng/csitools


How does
${VARIABLE_NAME}
work? (In this case
{CSITOOLS}
)

Thanks!

Answer

From perldata:

As in some shells, you can enclose the variable name in braces to disambiguate it from following alphanumerics (and underscores).

That is:

If you have a variable like $foo and you want to interpolate that whithin a string:

my $string = "This is $foobar";

then Perl would look for the variable $foobar. To make clear your variable's name is just $foo you need to write

my $string = "This is ${foo}bar";

This is the way to delimit the variable's name. In your particular case the curlies {} aren't needed because "$CSITOOLS\n" already is unambiguous. However, it does no harm.