Re: I need to extract an array from a scalar regex-wise ?
- From: "Gordon Etly" <get@xxxxxxxxxxx>
- Date: Sat, 10 May 2008 23:46:48 -0700
Uri Guttman wrote:
[please stop leading quoted text with spaces]
ordon Etly <get@xxxxxxxxxxx> writes:
Uri Guttman wrote:
Gordon Etly <get@xxxxxxxxxxx> writes:
Ok, so I mis-read. After re-reading it seems he just wants to
capture
the days of the week from the string, so the answer is simple:
you misread AGAIN.
No I didn't:
advice please wireless 802.11 on RH8 wrote:
> Let's say I want to extract all of the days of the week out
> of a scalar
...
> I want a regex/map/grep/etc (no iterative clauses PLEASE!)
> that yields:
>
> @days = qw( Monday Sunday Saturday Thursday Tuesday Wednesday )
He wanted the days in the string (presuming in the order they appear)
and ultimately stored into an array. My example fulfills this.
Code:
$_ =
'We went to the beach on Monday but it turned out that Sunday would
have been better. The weather report Saturday said no rain until
Thursday but I asked Tuesday (a trick!) and she said it rained
Wednesday.';
my @days = m#((?:mon|tues|wednes|thurs|fri|satur|sun)day)#gi;
print join(", ", @days);
the OP wanted the unique set of days which is why his post had a keys
on a dereferenced but incorrect hash ref. and he wanted it in one
expressions without external loops.
advice please wireless 802.11 on RH8 wrote:
> I'm also not crazy about the hash solution because order may
> be significant.
He never said "unique", all he said was he wanted to capture the
occurrences of days of the week in the string into an array. He never
said their couldn't be duplicates. He _did_ say that "order may be
significant", which to me is in line with capturing each occurrence of a
day of the week in the string (as they appear.)
also he got correct answers from other people (including myself) a
Actually your answer was based on the occurrences' being unique, a
requirement the OP never gave, so your answer imposes a limit the OP
most likely doesn't want, where as mine solution merely gets each
occurrence, in the _order_ they appear.
while back. try reading followups before posting another answer
This answer I gave in my last post was correct. It was also simple and
to the point. Maybe _you_ should read the original post more carefully.
--
G.Etly
.
- Follow-Ups:
- Re: I need to extract an array from a scalar regex-wise ?
- From: advice please wireless 802.11 on RH8
- Re: I need to extract an array from a scalar regex-wise ?
- From: advice please wireless 802.11 on RH8
- Re: I need to extract an array from a scalar regex-wise ?
- References:
- I need to extract an array from a scalar regex-wise ?
- From: advice please wireless 802.11 on RH8
- Re: I need to extract an array from a scalar regex-wise ?
- From: Gordon Etly
- Re: I need to extract an array from a scalar regex-wise ?
- From: Uri Guttman
- Re: I need to extract an array from a scalar regex-wise ?
- From: Gordon Etly
- Re: I need to extract an array from a scalar regex-wise ?
- From: Uri Guttman
- I need to extract an array from a scalar regex-wise ?
- Prev by Date: Re: I need to extract an array from a scalar regex-wise ?
- Next by Date: FAQ 3.28 I've read perlembed, perlguts, etc., but I can't embed perl in my C program; what am I doing wrong?
- Previous by thread: Re: I need to extract an array from a scalar regex-wise ?
- Next by thread: Re: I need to extract an array from a scalar regex-wise ?
- Index(es):
Relevant Pages
|