Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Regex Word Pairs

by Joost (Canon)
on Aug 15, 2007 at 23:20 UTC ( [id://632886]=note: print w/replies, xml ) Need Help??


in reply to Regex Word Pairs

Well that solution is pretty direct.

You could go (almost) without regexes and just get the pairs yourself - at the cost of some memory (since you need to store all the separate words):

#!/usr/local/bin/perl -w use strict; my $s = 'This is a test'; my @words = split / +/,$s; my @pairs = map [@words[$_,$_+1]],0 .. @words-2;
update: I'm sure there's a way to get rid of the intermediate @words array, I'm just not sure the code would get any clearer.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-25 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found