in reply to combining elements of arrays
I think the issue is probably this: the line you quoted is substituting a pair of spaces for a single space in the variable $_, not the variable $line, because you forgot to specify which variable the substitution applies to. More likely you meant this:
although you could write that much more easily as$line =~ s/$1/ /g if ($line =~ m/^\w.*(\s\s).*/);
or even$line =~ s/\s\s/ /g;
if your intent is actually to reduce all sequences of spaces to a single space.$line =~ s/\s{2,}/ /g;
Update: For those who notice, yes, it's true my first suggested alternative does not exactly match the semantics of the OP. Specifically, if $line contains one sequence of a tab followed by a space, and a later sequence of two spaces, my substitution will touch that second sequence and the OP's won't, but I'll venture to guess that mine is closer to the intent.
|
|---|