Concatenation

How can I do this:

date = 4 -----------> 04
Month= 3-----------> 03

I wish to make a varibale named Var1 which will hold the value of current date and month value as:

2 digits for date.
2 digits for month.

So finally var1 should hold value as 0403 --- MMDD

var1=$( printf "%02d%02d" $date $Month )

But it is prompting syntax error...

$DB_Date=$(printf "%02d%02d", $date, $Month );

That is the syntax used in shell script.
Try this

$DB_Date=sprintf("%02d%02d", $date, $Month);
$DB_Date=sprintf("%02d%02d", $date, $Month);
$DB_Date=printf("%02d%02d", $date, $Month);

I have previously tried the above....

But It gives out 0000 ...

Really I am lost how it could be possible in PERL.

Can you show your full code?

#!/bin/perl -w
use IO::Handle;

($day, $month, $year) = (localtime)[3,4,5];


$month=$month+1;
$year=$year+1700;
$DB_Date=printf("%02d%02d", $date, $Month);

open (dbfile, "/data1/scp/store/DB/0403/SCP_PP_SUBS.dat") or die "Couldn't get at THE FILE";

@data;
$credit;
$count =0;



          print "DB_Date:: $DB_Date \n\n";                       
          print "LESS then the 100 Credit $day/$month/$year\n\n";  
           print "-------------------------------------------\n";

 while (<dbfile>) 
 {
         ........................
         ..........................
         ............................
         ...........................

 Do some file parsing operation

}

print "Total Count: $count \n";
close dbfile;

$year=$year+1900;
$DB_Date=sprintf("%02d%02d", $date, $Month);

But the output is same...

print $DB_Date ---> 0000

I see the following warning ..

Use of uninitialized value in sprintf at /dev/fd/4 line 9
#!/bin/perl -w
use IO::Handle;

($day, $month, $year) = (localtime)[3,4,5];


$month=$month+1;
$year=$year+1700;
$DB_Date=printf("%02d%02d", $date, $Month);

Use day instead of date.Variables are case sensitive.Change the case of month

THx man ,, It worked ,, ...... :slight_smile:

Your help was really appriciating..

Asteroid, as a side note, get familiar with the use strict; pragma to avoid that $month $Month situation.

From the Perl traps for the unwary page at Perl Documentation - Perldoc Browser