in reply to Re: splitting a word
in thread splitting a word
I think the syntax ($match) = $var =~ /regex/;
is a concise and flexible way to extract parts of a string. The following code should illustrate this nicely - note especially the usage with the /g modifier.
#!/usr/bin/perl -w use strict; $_ = q/one two three four five/; my ($match, @matches); ($match) = /\w+\W+(\w+)/; print $match, "\n"; # prints two @matches = /(\w+)\W+(\w+)/; print join('|', @matches), "\n"; # prints one|two @matches = /(\w+)\W+(\w+)/g; print join('|', @matches), "\n"; # prints one|two|three|four @matches = /(\w+)/g; print join('|', @matches), "\n"; # prints one|two|three|four|five
-- Hofmator
|
|---|