Thelma Lubkin <> wrote:
> I am trying to compare two strings that must match except for their
> spacing.
>
> If I write:
>
> $h1 = 'here i am';
> $h2 = 'herei am';
>
> can I do a less clumsy comparison than
>
> ($hh2 = $h2) =~ s/\s//x;
( the s///x option is a no-op there, you must have meant s///g instead?)
( that ignores characters other than the space character. Is that
what you intended? if not then: s/ //g, or better: tr/ //d.
)
I don't think so, normalizing the data before the comparison seems
the best approach to me. You would of course need a similarly
de-spaced copy of $h1 too though.
> if($hh2 =~ /^$h1$/x) ...
Do you intend for $h1 to contain regex metacharacters that *are* meta?
If not, then what you have there is an equality test disguised as a
pattern match and implemented in an "expensive" way.
if ( $hh2 eq $hh1 ) # more clear AND faster!
--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas