Fwd: a question regarding the use of Split operator in Perl
Jerry
greenmt at gmail.com
Tue Sep 11 14:31:50 EDT 2007
Hi,
I sorta found a workaround: adding a line before using Split operator
s /^\s\*\s/^ /g;
I'm sure there's a better way than this.
Zhao
---------- Forwarded message ----------
From: Jerry <greenmt at gmail.com>
Date: Sep 11, 2007 1:32 PM
Subject: a question regarding the use of Split operator in Perl
To: gnhlug-discuss at mail.gnhlug.org
Hi,
First I want to apologize for that lately I've been blasting this great list
with my "almost stupid" questions. I simply couldn't find any better place
to ask than here. :-)
Say I have 2 lines of phrases shown below, with the patten described in the
bracket
[
patten:
1, there is only one whitespace within the phrase
2, there are 2+ whitespace in between the phrases)
3, each line start with 3 whitespace
]
good morning good evening good night
go south go north go east go west
I want to separate the phrases by 2+ whitespace to separate these phrases,
so I think the perl code should look like this
@list = split ( /\s{2,}/, $_);
The desired output should look like this:
"good morning", "good evening", "good night"
"go south", "go north", "go east", "go west"
However, if some lines do not start with 3 whitespace, instead start with "
* " (one whitespace, then a star, then a whitespace again)
For example:
good morning good evening good night
* go south go north go east go west
How to use Split operator to separate out these phrases to achieve the same
result as from the 1st example, regardless the presence of "*" in this
example?
Thank you!
Zhao
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.gnhlug.org/mailman/private/gnhlug-discuss/attachments/20070911/d44ab58c/attachment.html
More information about the gnhlug-discuss
mailing list