in reply to Difference Of Two Strings
I wanted to remove the split() entirely, but my knowledge of Perl isn't strong enought yet to come up with that solution. Here's a slight improvement that I came up with.
#!/usr/bin/perl use strict; my ($full, $part) = @ARGV; my ($left) = leftover($full, $part); if (defined($left)) { print "$full - $part = $left\n"; } else { print "$full - $part = undef\n"; } #----------------------------------------------------------- sub leftover { my ($full, $part) = @_; my ($ch); my (@parts) = split('', $part); my ($regx) = join('+.*', @parts); if ($full =~ m{$regx}) { foreach $ch (@parts) { $full =~ s/[$ch]{1}//; } } else { $full = undef; }; return $full; }
Here's pseudo code for what my original idea was (maybe someone else can make it work):
sub leftover{ my ($full, $part) = @_; while ($full && $part) { #RexExp to substitute nothing for the first match #then remove the matched character from $part } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Difference Of Two Strings
by YuckFoo (Abbot) on Nov 03, 2001 at 05:22 UTC |