Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: One line assigment statement with regex match

by broquaint (Abbot)
on Jun 23, 2005 at 09:27 UTC ( #469331=note: print w/replies, xml ) Need Help??

in reply to One line assigment statement with regex match

This looks like a good case for Regex::Presuf i.e
use Regex::PreSuf; my $lineFromSomeTextFile = "your line right here\n"; my @terms = qw/ something matching a line /; my($word) = $lineFromSomeTextFile =~ /(${\presuf(@terms)})/; # or without PreSuf my($word) = $lineFromSomeTextFile =~ do {local $" = '|'; "(@terms)"}; print "found '$word' in: $lineFromSomeTextFile"; __output__ found 'line' in: your line right here


Replies are listed 'Best First'.
Re^2: One line assigment statement with regex match
by planetscape (Chancellor) on Jun 23, 2005 at 18:05 UTC

    Just because I really like grinder's Regexp::Assemble, and think such a cool module needs more exposure:

    #!/usr/bin/perl -w use Regexp::Assemble; my $lineFromSomeTextFile = "your line right here\n"; my $ra = Regexp::Assemble->new->add( "something", "matching", "a", "line" ); print $ra->re . "\n"; # because the output is cool # and sometimes educational my($word) = $lineFromSomeTextFile =~ /($ra)/; print "found '$word' in: $lineFromSomeTextFile";

    (For more on Regexp::Assemble see: Why machine-generated solutions will never cease to amaze me.)



Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://469331]
[perldigious]: If you want a linguistic adventure...
[perldigious]: No offense to any Scotsman, I love Scots. Well actually, I love Scotch, but I'm sure the people are great too. :-P
[Discipulus]: perldigious i understand i word on ten, to be optimistic..
LanX will try to give his next LPW talk with a Cogney intonation
[Discipulus]: if you love Scotch in scotland your safety will be.. glengranted
[LanX]: *Cockney

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2017-06-23 16:53 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (552 votes). Check out past polls.