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

Re: Pattern Matching - Remove Alpha

Thread Previous | Thread Next
From:
John W. Krahn
Date:
January 16, 2002 20:42
Subject:
Re: Pattern Matching - Remove Alpha
Message ID:
3C465615.8CC79CF4@acm.org
Hewlett Pickens wrote:
> 
> I am unable to use "split" with pattern matching to remove alpha characters
> from a string and will appreciate a pointer on what I'm doing wrong. (Have
> looked in "Learning Perl" and "Programming Perl" but can't spot my error.)
> 
> 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
> 
> From reading, my understanding of "split":  Discards all data that matches
> the pattern and returns a set of list values for the unmatched data. ("my
> understanding" may be the problem)
> 
> This pattern works - removes all blanks (white space) but leaves alpha and
> numbers which of course isn't what I want
> 
>    my @nums = split(/ +/,$stat);   # removes all blanks


my @nums = $stat =~ /\d+/g;


John
-- 
use Perl;
program
fulfillment

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