in reply to Re^4: Space between digits
in thread Space between digits
my $string = "(\d+)\:(\d+) (\d+)\/(\d+)\/(\d+)";
What is the purpose of this line? Does it really help you to do what you want to? What happens if you leave it out entirely?
s/// works in place (that is, on the variable it is bound to). What happens if you rewrite it as this:
if ($_ =~ m/(\d+)\:(\d+) (\d+)\/(\d+)\/(\d+)/ ){ $_ =~ s/ / /; }
And of course, m// and s/// works on $_ in lieu of any other variable, so you could even just go:
if (m/(\d+)\:(\d+) (\d+)\/(\d+)\/(\d+)/ ){ s/ / /; }
Which could be shortend to:
s/ / / if m/(\d+)\:(\d+) (\d+)\/(\d+)\/(\d+)/;
Those parens serve no purpose, as you're seemingly not capturing anything, so we can be even more briefer without harming readability:
s/ / / if m/\d+\:\d+ \d+\/\d+\/\d+/;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: Space between digits
by AnomalousMonk (Archbishop) on Nov 23, 2012 at 04:56 UTC |
In Section
Seekers of Perl Wisdom