Google Groups Home
Help | Sign in
Message from discussion I need to extract an array from a scalar regex-wise ?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
advice please wireless 802.11 on RH8  
View profile
 More options May 9, 2:22 pm
Newsgroups: comp.lang.perl.misc
From: "advice please wireless 802.11 on RH8" <buell...@gmail.com>
Date: Fri, 9 May 2008 11:22:57 -0700 (PDT)
Local: Fri, May 9 2008 2:22 pm
Subject: I need to extract an array from a scalar regex-wise ?
This is not a homework assignment. I'd be interested in more elegante'
solutions than mine is all..

Let's say I want to extract all of the days of the week out of a
scalar such as :

$_ =
'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.'

I want a regex/map/grep/etc (no iterative clauses PLEASE!) that
yields:

@days = qw( Monday Sunday Saturday Thursday Tuesday Wednesday )

My best shot is:
 my @days = keys %{  /((mon|tues|wednes|thurs|fri|satur|sun)day)/gi };

Which, oddly, doesn't seem to work. I say "oddly", because

   /((mon|tues|wednes|thurs|fri|satur|sun)day)/gi

=

  0  'Saturday'
  1  'Satur'
  2  'Thursday'
  3  'Thurs'
  4  'Tuesday'
  5  'Tues'
  6  'Wednesday'
  7  'Wednes'

yet %{  /((mon|tues|wednes|thurs|fri|satur|sun)day)/gi }

is an empty array!? *TILT*

I'm also not crazy about the hash solution because order may be
significant.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google