user2654953
user2654953

Reputation: 221

How can I define and initialize several lexical variables at the same time?

I am learning how to use Perl and I am trying out different approaches. I know this is wrong, but I need to know why and how I can use a similar approach to assigning lexical variables. Your assistance would be greatly appreciated.

 #Set vars 
   my (
   $TIMESTAMP      = strftime("%Y%M%d%H%M%S", localtime),
   $SourceDir      = 'C:\Documents\Source_Dir',
   $destinationDir = 'C:\Documents\$website'
   );

Upvotes: 1

Views: 100

Answers (1)

brian d foy
brian d foy

Reputation: 132858

Use a list assignment with all the variables on the left on the assignment operator and all of the values on the right:

my( $TIMESTAMP, $SourceDir, $destinationDir ) = (
   strftime("%Y%M%d%H%M%S", localtime),
   'C:\Documents\Source_Dir',
   'C:\Documents\$website'
   );

Or, do them one by one.

Upvotes: 3

Related Questions