Your skill will accomplishwhat the force of many cannot PerlMonks

### Re: List Compare

by dragonchild (Archbishop)
 on Oct 21, 2005 at 14:26 UTC ( #502008=note: print w/replies, xml ) Need Help??

Assuming you're working with just strings, something like the following would work:
```my @a = 'a' .. 'c';
my @b = 'a' .. 'f';

my \$compare = do {
my \$temp = join '.*?', @a;
qr/\$temp/;
};

sub compare {
my @b = @_;

my \$temp = join '', @b;
return \$temp =~ \$compare;
}

My criteria for good software:
1. Does it work?
2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re^2: List Compare
by inman (Curate) on Oct 21, 2005 at 14:32 UTC
You beat me to it!! I had it the other way round though as per the OPs example. The joined @a is only calculated once and then matched against the regex made from joining @b with .*?
```my @a= qw (a b c d e f);
my @b= qw (a b c);

my \$joined_a = join '', @a;
my \$joined_b = join '.*?', @b;

print "yes!\n" if \$joined_a =~ /\$joined_b/;

But I guess there are no prizes for coming second...

Re^2: List Compare
by sauoq (Abbot) on Oct 21, 2005 at 20:11 UTC

This... uh... doesn't meet your first criteria for good software. (And it didn't even before he updated his spec.)

Set @b = qw( a foobar c ) to see it fail.

You might get away with something like that by including some "\0"s in your join but I certainly would not recommend it. Even before he added the additional constraint that there could be no missing elements, this would be easily solved with a single loop.

```-sauoq
"My two cents aren't worth a dime.";
```

Create A New User
Node Status?
node history
Node Type: note [id://502008]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2018-10-18 03:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When I need money for a bigger acquisition, I usually ...

Results (99 votes). Check out past polls.

Notices?