J
Jerry C.
Hi, I have the following code which finds and prints the first 2 digits
in a string. I'm trying to make it more efficient. Here's the code:
$sentence = "January 23, 1992";
if ($sentence =~ /\d\d/) { $sentence = "$&"; }
print $sentence;
If I know that "$sentence" will ALWAYS have a two digit date, is there a
way I can get rid of the "if - then" statement and just have it print
$sentence??? I tried this, and it doesn't work:
$sentence = "January 23, 1992";
$sentence = /\d\d/;
print $sentence;
I'm just trying to make my script slightly more efficient by getting rid
of that "if - then" statement.
Thanks,
-Jerry
p.s. I really appreciate your help! If you could answer this question,
too, it would be greatly appreciated: In Perl Version 5.6.1, this code
worked, but in version 5.8.0, it no longer works. Any idea why?
$sentence = "January 23, 1992";
$sentence =~ s/[^\d]+//g;
$sentence = substr($sentence,0,2);
$sentence =~ s/\b0//;
print $sentence;
in a string. I'm trying to make it more efficient. Here's the code:
$sentence = "January 23, 1992";
if ($sentence =~ /\d\d/) { $sentence = "$&"; }
print $sentence;
If I know that "$sentence" will ALWAYS have a two digit date, is there a
way I can get rid of the "if - then" statement and just have it print
$sentence??? I tried this, and it doesn't work:
$sentence = "January 23, 1992";
$sentence = /\d\d/;
print $sentence;
I'm just trying to make my script slightly more efficient by getting rid
of that "if - then" statement.
Thanks,
-Jerry
p.s. I really appreciate your help! If you could answer this question,
too, it would be greatly appreciated: In Perl Version 5.6.1, this code
worked, but in version 5.8.0, it no longer works. Any idea why?
$sentence = "January 23, 1992";
$sentence =~ s/[^\d]+//g;
$sentence = substr($sentence,0,2);
$sentence =~ s/\b0//;
print $sentence;