[clug-talk] Perl regular expressions ?
dave.lee.wilson at gmail.com
Mon Mar 21 20:08:17 PST 2005
Michael Gale <michael.gale at bluesuperman.com> wrote:
> print $input it will equal "Memory Usage: 1234;678;000;4567"
> print $input =~ /(\d+);(\d+);(\d+);(\d+)/; it will produce "12346780004567"
> which may be confusing ... because what happens to $1 ? Remember because
> "/(pattern)/" is supposed to assign the match to a $1 and $2 and so on.
> It actually does ... it just gets printed with out any spaces.
use the field seperator variable, $, if you assign a string to this
variable the output of the print function will more clearly show the
individual values $1,$2,$3,etc. for example:
$, = "\n";
print $input =~ /(\d+);(\d+);(\d+);(\d+)/;
will print each of the values on their own line.
More information about the clug-talk