develooper Front page | perl.beginners | Postings from January 2002

Re: Pattern Matching - Remove Alpha

Thread Previous | Thread Next
From:
Michael Fowler
Date:
January 16, 2002 18:42
Subject:
Re: Pattern Matching - Remove Alpha
Message ID:
20020117004757.GA2363@shoebox.net
On Wed, Jan 16, 2002 at 05:38:56PM -0600, Hewlett Pickens wrote:
> The detail:
> 
>  "$stat" is a string that has alpha and numeric data in it.
>  I want to remove all of the alpha and put the numeric data into an array.
> 
>  The first attempt:
> 
>    my @nums = split(/a-zA-Z/,$stat); # removes all data from the string
> 
>  The second attempt:
> 
>    my @nums = split(/a-z/,$stat); # removes all data from the string

You've somehow got tr/// and regexes confused, or perhaps tr/// and split,
or perhaps you're just making stuff up.  ;)

Regardless, split(/a-zA-Z/, $stat) splits the string $stat on the string
"a-zA-Z".  Say, for example, $stat = "foo bar a-zA-Z baz qux".  Your split
would result in the list ("foo bar ", " baz qux").  You were probably aiming
for the regex /[a-zA-Z]/, or better yet, \w, as in, split(/\w/, $stat), or
perhaps split(/\w+/, $stat).

Please read perldoc perlre and the regex sections of your books.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About