On May 18, Dale said:
Hi John W. Krahn, you wrote:
If I understand you correctly then this will do what you want:
$str =~ tr/ //s;
Or if you want a slower method:
$str =~ s/ +/ /g;
This might sound a strange question, but why is the first one faster?
The first one is not a regex, it's merely a character transliteration.
$str = join ' ', split ' ', $str;
This just confuses me!
split(' ', $str) returns a list of chunks of non-whitespace, and join(' ') joins those chunks together with one space.
I thought that I could remove lines from the data by matching whether the first character was a letter by using the 'if' statement as :
if(substr($line,0,1) eq [a-zA-Z])
...but this doesn't work. Neither does :
if($line eq [\s\d])
...to try and find if it's just contain numbers and spaces.
They don't work because eq is for strings, and you're trying to use character classes (or more generally, regexes).
if (substr($line, 0, 1) =~ /[a-zA-Z]/) { ... }
and
if ($line =~ /^[\s\d]+$/) { ... }
probably do what you want.
-- Jeff "japhy" Pinyan % How can we ever be the sold short or RPI Acacia Brother #734 % the cheated, we who for every service http://japhy.perlmonk.org/ % have long ago been overpaid? http://www.perlmonks.org/ % -- Meister Eckhart
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>