Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: searching problem

by Khen1950fx (Canon)
on Jan 18, 2013 at 17:24 UTC ( #1014093=note: print w/replies, xml ) Need Help??

in reply to searching problem

I was thinking of something along these lines:
#!/usr/bin/perl -l BEGIN { $| = 1; $^W = 1; } use strict; use warnings; use List::MoreUtils 'any'; my($string) = q(mamy dady bal foo bar); my(@allwords) = split(" ", $string, 0); my($revwords) = join(" ", reverse(@allwords)); my(@strings_list) = scalar reverse $revwords; my $match = any( sub { /^ymam*/}, @strings_list, ); print "match" if $match; print "no match" unless $match;

Replies are listed 'Best First'.
Re^2: searching problem
by Lotus1 (Curate) on Jan 18, 2013 at 22:27 UTC
    my($string) = q(mamy dady bal foo bar);

    Your wordlist doesn't contain anything that will match what the OP requested.

    my(@strings_list) = scalar reverse $revwords;

    This will put all the words into the first element of @strings_list so there is no need to use any(). Would have been much simpler to just reverse the original string and then split it into an array.

    my $rev = reverse $string; my @strings = split ' ', $rev; print join ',',@strings;
    sub { /^ymam*/}, @strings_list,

    ^ymam* will match 0 or more 'm's after yma which is not going to work. The * is not needed here.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1014093]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2018-06-20 02:37 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (116 votes). Check out past polls.