tart has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; my $val1 = '5234'; $val1 = append($val1,'_'); unless($val1) { print "return undef\n"; } print "$val1\n"; sub append { my $val2 = shift; my $character = shift; if($val2 =~ /\d\d\d\d/) { $val2 =~ s/(\d)(\d)(\d\d)/$1$character$2$character$3$4/g; } elsif($val2 =~ /\d\d\d/) { $val2 =~ s/(\d)(\d)(\d)/$1$character$2$character$3/g; } elsif($val2 =~ /\d\d/) { $val2 =~ s/(\d)(\d)/$1$character$2/g; } else { return; } return $val2; } Cheers! <br> Marshall, <br> First of all thank for reply But if there is 4 digit(5234) I want it t +o be(5_2_34)!<br> where as for 3(523) I want it (5_2_3)<br> and for 2(52) is want it to be (5_2)<br><br> Thanks any way!!!<br>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Check substitute digit
by jwkrahn (Abbot) on Jul 26, 2010 at 01:23 UTC | |
|
Re: Check substitute digit
by AnomalousMonk (Archbishop) on Jul 26, 2010 at 00:46 UTC | |
|
Re: Check substitute digit
by Marshall (Canon) on Jul 26, 2010 at 00:07 UTC | |
|
Re: Check substitute digit
by toolic (Bishop) on Jul 26, 2010 at 00:44 UTC | |
|
Re: Check substitute digit
by suhailck (Friar) on Jul 26, 2010 at 03:16 UTC |