Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Dependant Arrays intersection

by Mr. Muskrat (Canon)
on Feb 04, 2016 at 21:46 UTC ( [id://1154432]=note: print w/replies, xml ) Need Help??


in reply to Dependant Arrays intersection

Here is one way to do that. I chose to use List::Util's any subroutine in conjunction with a for loop.

#!/bin/env perl use strict; use warnings; use List::Util qw(any); my @small = ('var/qWDszw1dQd', 'aHO0rvbglz/pg_extra_dump', 'OtherSchem +a'); my @big = load_paths(); my @selected; for my $item (@big) { push @selected, $item if any { $item =~ /\Q$_\E/ } @small; } print "selected:\n", join "\n", @selected, "\n"; sub load_paths { return qw( ./gh/dbix-class-schema-loader/t/var/QN40VTMAuz ./gh/dbix-class-schema-loader/t/var/QN40VTMAuz/common_dump ./gh/dbix-class-schema-loader/t/var/QN40VTMAuz/common_dump/DBIXCSL +_Test ./gh/dbix-class-schema-loader/t/var/QN40VTMAuz/common_dump/DBIXCSL +_Test/Schema ./gh/dbix-class-schema-loader/t/var/QN40VTMAuz/common_dump/DBIXCSL +_Test/Schema/MyResult ./gh/dbix-class-schema-loader/t/var/BIdR9nVlmM ./gh/dbix-class-schema-loader/t/var/Qt5_emwFhF ./gh/dbix-class-schema-loader/t/var/Qt5_emwFhF/common_dump ./gh/dbix-class-schema-loader/t/var/Qt5_emwFhF/common_dump/DBIXCSL +_Test ./gh/dbix-class-schema-loader/t/var/Qt5_emwFhF/common_dump/DBIXCSL +_Test/Schema ./gh/dbix-class-schema-loader/t/var/Qt5_emwFhF/common_dump/DBIXCSL +_Test/Schema/MyResult ./gh/dbix-class-schema-loader/t/var/oc8ziKYqZb ./gh/dbix-class-schema-loader/t/var/VZa7q4FOlm ./gh/dbix-class-schema-loader/t/var/wxbUMQkA3e ./gh/dbix-class-schema-loader/t/var/wxbUMQkA3e/common_dump ./gh/dbix-class-schema-loader/t/var/wxbUMQkA3e/common_dump/DBIXCSL +_Test ./gh/dbix-class-schema-loader/t/var/wxbUMQkA3e/common_dump/DBIXCSL +_Test/Schema ./gh/dbix-class-schema-loader/t/var/wxbUMQkA3e/common_dump/DBIXCSL +_Test/Schema/MyResult ./gh/dbix-class-schema-loader/t/var/9Br774226y ./gh/dbix-class-schema-loader/t/var/9Br774226y/common_dump ./gh/dbix-class-schema-loader/t/var/9Br774226y/common_dump/DBIXCSL +_Test ./gh/dbix-class-schema-loader/t/var/9Br774226y/common_dump/DBIXCSL +_Test/Schema ./gh/dbix-class-schema-loader/t/var/9Br774226y/common_dump/DBIXCSL +_Test/Schema/MyResult ./gh/dbix-class-schema-loader/t/var/9Br774226y/common_dump/TestSch +emaFromAnother ./gh/dbix-class-schema-loader/t/var/9Br774226y/common_dump/TestSch +emaFromAnother/Result ./gh/dbix-class-schema-loader/t/var/AZzU5Mp5c8 ./gh/dbix-class-schema-loader/t/var/BrS2LkS6Wh ./gh/dbix-class-schema-loader/t/var/SN_06brsqD ./gh/dbix-class-schema-loader/t/var/sso1WR7JVK ./gh/dbix-class-schema-loader/t/var/sso1WR7JVK/common_dump ./gh/dbix-class-schema-loader/t/var/aHO0rvbglz ./gh/dbix-class-schema-loader/t/var/aHO0rvbglz/pg_extra_dump ./gh/dbix-class-schema-loader/t/var/aHO0rvbglz/pg_extra_dump/PGMul +tiSchema ./gh/dbix-class-schema-loader/t/var/aHO0rvbglz/pg_extra_dump/PGMul +tiSchema/Result ./gh/dbix-class-schema-loader/t/var/aHO0rvbglz/common_dump ./gh/dbix-class-schema-loader/t/var/aHO0rvbglz/common_dump/DBIXCSL +_Test ./gh/dbix-class-schema-loader/t/var/aHO0rvbglz/common_dump/DBIXCSL +_Test/Schema ./gh/dbix-class-schema-loader/t/var/aHO0rvbglz/common_dump/DBIXCSL +_Test/Schema/MyResult ./gh/dbix-class-schema-loader/t/var/aHO0rvbglz/common_dump/TestSch +emaFromAnother ./gh/dbix-class-schema-loader/t/var/aHO0rvbglz/common_dump/TestSch +emaFromAnother/Result ./gh/dbix-class-schema-loader/t/var/SMPvZQWwxI ./gh/dbix-class-schema-loader/t/var/ZQHeJ7xJLS ./gh/dbix-class-schema-loader/t/var/ZQHeJ7xJLS/common_dump ./gh/dbix-class-schema-loader/t/var/ZQHeJ7xJLS/common_dump/DBIXCSL +_Test ./gh/dbix-class-schema-loader/t/var/ZQHeJ7xJLS/common_dump/DBIXCSL +_Test/Schema ./gh/dbix-class-schema-loader/t/var/ZQHeJ7xJLS/common_dump/DBIXCSL +_Test/Schema/MyResult ./gh/dbix-class-schema-loader/t/var/qWDszw1dQd ./gh/dbix-class-schema-loader/t/var/A_asDKxIPg ./gh/dbix-class-schema-loader/t/var/MbRwgdPYzG ./gh/dbix-class-schema-loader/t/var/OKOTLfXlcS ./gh/dbix-class-schema-loader/t/var/OKOTLfXlcS/common_dump ./gh/dbix-class-schema-loader/t/var/OKOTLfXlcS/common_dump/DBIXCSL +_Test ./gh/dbix-class-schema-loader/t/var/OKOTLfXlcS/common_dump/DBIXCSL +_Test/Schema ./gh/dbix-class-schema-loader/t/var/OKOTLfXlcS/common_dump/DBIXCSL +_Test/Schema/MyResult ./gh/dbix-class-schema-loader/t/var/LDoLlFrpEm ./gh/dbix-class-schema-loader/t/var/xf484Q14Tm ./gh/dbix-class-schema-loader/t/var/xf484Q14Tm/common_dump ./gh/dbix-class-schema-loader/t/var/xf484Q14Tm/common_dump/DBIXCSL +_Test ./gh/dbix-class-schema-loader/t/var/xf484Q14Tm/common_dump/DBIXCSL +_Test/Schema ./gh/dbix-class-schema-loader/t/var/xf484Q14Tm/common_dump/DBIXCSL +_Test/Schema/MyResult ./gh/dbix-class-schema-loader/t/var/4HJSJyMOLQ ./gh/dbix-class-schema-loader/t/var/4HJSJyMOLQ/common_dump ./gh/dbix-class-schema-loader/t/var/4HJSJyMOLQ/common_dump/DBIXCSL +_Test ./gh/dbix-class-schema-loader/t/var/4HJSJyMOLQ/common_dump/DBIXCSL +_Test/Schema ./gh/dbix-class-schema-loader/t/var/4HJSJyMOLQ/common_dump/DBIXCSL +_Test/Schema/MyResult ./gh/dbix-class-schema-loader/t/var/Ta_ZGMdtD3 ./gh/dbix-class-schema-loader/t/var/PvDTGVICln ./gh/dbix-class-schema-loader/t/var/VSshFiOQrb ./gh/dbix-class-schema-loader/t/var/VSshFiOQrb/dump ./gh/dbix-class-schema-loader/t/var/VSshFiOQrb/dump/DBICTest ./gh/dbix-class-schema-loader/t/var/VSshFiOQrb/dump/DBICTest/DumpM +ore ./gh/dbix-class-schema-loader/t/var/VSshFiOQrb/dump/DBICTest/DumpM +ore/1 ./gh/dbix-class-schema-loader/t/var/VSshFiOQrb/dump/DBICTest/DumpM +ore/1/Result ./gh/dbix-class-schema-loader/t/var/VSshFiOQrb/dump/DBICTest/DumpM +ore/1/Result/MySchema ./gh/dbix-class-schema-loader/t/var/VSshFiOQrb/dump/DBICTest/DumpM +ore/1/Result/OtherSchema ./gh/dbix-class-schema-loader/t/var/VSshFiOQrb/dump/DBICTest/DumpM +ore/omit_timestamp ./gh/dbix-class-schema-loader/t/var/VSshFiOQrb/dump/DBICTest/DumpM +ore/Upgrade ./gh/dbix-class-schema-loader/t/var/VSshFiOQrb/dump/DBICTest/DumpM +ore/Upgrade/Result ./gh/dbix-class-schema-loader/t/var/VSshFiOQrb/dump/DBICTest/DumpM +ore/omit_both ./gh/dbix-class-schema-loader/t/var/VSshFiOQrb/dump/DBICTest/DumpM +ore/omit_version ); } __DATA__ selected: ./gh/dbix-class-schema-loader/t/var/aHO0rvbglz/pg_extra_dump ./gh/dbix-class-schema-loader/t/var/aHO0rvbglz/pg_extra_dump/PGMultiSc +hema ./gh/dbix-class-schema-loader/t/var/aHO0rvbglz/pg_extra_dump/PGMultiSc +hema/Result ./gh/dbix-class-schema-loader/t/var/qWDszw1dQd ./gh/dbix-class-schema-loader/t/var/VSshFiOQrb/dump/DBICTest/DumpMore/ +1/Result/OtherSchema

Replies are listed 'Best First'.
Re^2: Dependant Arrays intersection
by simong (Initiate) on Feb 04, 2016 at 21:57 UTC
    thanks Muskrat, already implemented your code, but since @big const 400k elements, 1 or worster 2 nested cycles , take very much time

      Did I miss your examples or did you add them later? If all of the fragments in your small array will match the end of an item in the large array then you should anchor the search at the end with a $ like you had in your grep.

      push @selected, $item if any { $item =~ /\Q$_\E$/ } @small;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1154432]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-23 18:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found