The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
! operator in variable mmunir Shell Programming and Scripting 1 05-30-2008 12:29 AM
perl scalar variable in backquoted string mehdi9 Shell Programming and Scripting 6 10-09-2007 11:33 AM
what is diff b/w copy constructor and overloaded assignment operator amitpansuria High Level Programming 3 08-06-2007 12:45 PM
Can't modify not in scalar assignment compilation error new2ss Shell Programming and Scripting 2 05-18-2006 02:03 AM
@ in a variable assignment rkap UNIX for Dummies Questions & Answers 1 05-23-2005 07:53 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-17-2008
Registered User
 

Join Date: Nov 2007
Posts: 73
scalar variable assignment in perl + { operator

When reading over some perl code in a software document, I came across an assignment statement like this

$PATH = ${PROJECT}/......./....

In this particular form of scalar variable assignment, what does the curly braces operators do ? Also, what is the benefit in doing scalar assignment this way ?

many thanks
Reply With Quote
Forum Sponsor
  #2  
Old 01-17-2008
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,477
Surrounding the identifier with curly braces is more frequently seen in double-quoted strings to separate it from neighbouring text. For example,

"The time now is ${time}A.M."

This syntax also works outside strings, as you cited, but that is rarely needed and being most of the time redundant. It is there to support identifiers that start with a ^ sign, which is normally not allowed. However, I cannot think of any case that really needs to refer this kind of variables.

For more information, refer to

perlvar - perldoc.perl.org
Reply With Quote
  #3  
Old 01-17-2008
Yogesh Sawant's Avatar
Part Time Moderator and Full Time Dad
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 798
Code:
#!/usr/bin/perl
my $cap = 53;
print "${cap}rd cap! \n";
output:
Code:
53rd cap!
Reply With Quote
  #4  
Old 01-20-2008
Registered User
 

Join Date: Nov 2007
Posts: 73
thanks guys.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
perlvar

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:13 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0