tobold.org

correct • elegant • free

△ comp.lang.perl △

◅ Need help on Perl and fork()

Nee file lock example using fcntl ▻

A little split problem

In article <5bigdc$ecl@star.cs.vu.nl>, Buis RWL <rwlbuis@cs.vu.nl> wrote:
>I want to translate this string:
>procedure    writec(c : character);
>into this array:
>('procedure', 'writec', '(', 'c', ':', 'character', ')', ';').

The easiest way is to use the match operator with the global modifier,
`m//g'.  Then you just need to write a regexp that selects all the parts
of the string you are interested in.

    @words = ($line =~ m/(\w+|[:;()])/g);

Tim.
--
Tim Goodwin   | "A language needs both intestines and guts." -- Larry Wall

Original headers:

From: tim@pipex.net (Tim Goodwin)
Newsgroups: comp.lang.perl.misc
Subject: Re: A little split problem
Date: 15 Jan 1997 15:21:41 GMT
Organization: UUNET PIPEX
Message-ID: <5bism5$b87@join.news.pipex.net>
References: <5bigdc$ecl@star.cs.vu.nl>

△ comp.lang.perl △

◅ Need help on Perl and fork()

Nee file lock example using fcntl ▻