perl : regular expression to replace the strings

There are 2 strings as below.

$str1 = "41148,,,,,,,,,,,,,,,,,,,,,,,,";
$date = "TUE 08-28-2012";

The output should be as below

 
$str1 = "TUE 08-28-2012,,,,,,,,,,,,,,,,,,,,,,,,";

Could anyone please help with the perl regular expression or any other alternative?

One way:

#!/usr/bin/perl
use warnings;
use strict;

my $str1 = "41148,,,,,,,,,,,,,,,,,,,,,,,,";
my $date = "TUE 08-28-2012";

print "Before : $str1\n";
my @temp = split /,/, $str1, -1;
shift @temp;
$str1 = join ",", $date, @temp;
print "After  : $str1\n";

producing

Before : 41148,,,,,,,,,,,,,,,,,,,,,,,,
After  : TUE 08-28-2012,,,,,,,,,,,,,,,,,,,,,,,,

--------

And with a regexp:

#!/usr/bin/perl
use warnings;
use strict;

my $str1 = "41148,,,,,,,,,,,,,,,,,,,,,,,,";
my $date = "TUE 08-28-2012";

print "Before : $str1\n";
$str1 =~ s/\A.*?,/$date,/;
print "After  : $str1\n";
1 Like

Many thanks... It helped me a lot... Thanks once again...

Also one more doubt..
I had a text file which contains the data as below.
Now I need to check only the lines that start with a digit.

xyz.net-Multilink1,BW: 1.07 M,,,,,,,,,,,,,,,,,,,,,,,
Hrly Avg (IN / OUT),0:00,1:00,2:00,3:0041148,,,,,,,,,,,,,,,,,,,,,,,,
41149,,,,,,,,,,,,,,,,,,,,,,,,
41150,,,,,,,,,,,,,,,,,,,,,,,,
41151,,,,,,,,,,,,,,,,,,,,,,,,
41152,,,,,,,,,,,,,,,,,,,,,,,,

In the above, line 1 and 2 can be ignored as it starts with characters and
line 3,4 and line 5 has to be processed.

Could you please help me in this regard?

Thanks in advance..

Regards,
GS

$ cat testfile
xyz.net-Multilink1,BW: 1.07 M,,,,,,,,,,,,,,,,,,,,,,,
Hrly Avg (IN / OUT),0:00,1:00,2:00,3:0041148,,,,,,,,,,,,,,,,,,,,,,,,
41149,,,,,,,,,,,,,,,,,,,,,,,,
41150,,,,,,,,,,,,,,,,,,,,,,,,
41151,,,,,,,,,,,,,,,,,,,,,,,,
41152,,,,,,,,,,,,,,,,,,,,,,,,

$ perl -wne 'print if /\A[0-9]+/' testfile
41149,,,,,,,,,,,,,,,,,,,,,,,,
41150,,,,,,,,,,,,,,,,,,,,,,,,
41151,,,,,,,,,,,,,,,,,,,,,,,,
41152,,,,,,,,,,,,,,,,,,,,,,,,