#!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd /; Main( @ARGV ); exit( 0 ); sub Main { MainOne(); MainToo(); } sub MainOne { my @fields = ( 'I foo', 'foo who?', 'the foo and the moo' ); my @querys = qw/ foo% %foo% %f%o% /; for my $field ( @fields ) { for my $search ( @querys ) { my $re = WildcardRe( $search ); if( $field =~ m{$re}i ) { dd( { andthe => $field, has => $search, says => $re } +); } } } } ## end sub Main sub WildcardRe { ## todo update with Regexp::Wildcards my( $search ) = @_; my @parts = split /%/, $search; $_ = quotemeta( $_ ) for @parts; my $re = join '.+', @parts; $re = '^' . $re . '$'; return $re; } ## end sub WildcardRe sub MainToo { my @fields = ( 'I foo', 'foo who?', 'the foo and the moo' ); my @querys = qw/ foo% %foo% %f%o% /; @querys = map { [ $_, WildcardRe( $_ ) ]; } @querys; for my $field ( @fields ) { for my $query ( @querys ) { my( $search, $re ) = @$query; if( $field =~ m{$re}i ) { dd( { andthe => $field, has => $search, says => $re } +); } } } } ## end sub MainToo
ppi_dumper can tell you what manual to look up the basic perl syntax in ... like perlsyn ... example of this Re: use constant usage clarification (Deparse)
In reply to Re: Need to append and replace for % sign in a variable string ( Regexp::Wildcards->new( type => 'sql')
by Anonymous Monk
in thread Need to append and replace for % sign in a variable string
by jayd11
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |