Front page | perl.beginners |
Postings from January 2002
Re: Pattern Matching - Remove Alpha
Thread Previous
|
Thread Next
From:
Tanton Gibbs
Date:
January 16, 2002 19:01
Subject:
Re: Pattern Matching - Remove Alpha
Message ID:
002901c19f01$e7a94b60$54486e0a@brooklyn
Michael brings up a good point...for this problem, you would probably be
better served by tr
$stat =~ tr/a-zA-Z//d;
will delete any alpha character.
Although split will do the job, I think tr would be a more "idiomatic"
choice, probably more efficient too.
----- Original Message -----
From: "Michael Fowler" <michael@shoebox.net>
To: "Hewlett Pickens" <HPickens@bimoyle.com>
Cc: <beginners@perl.org>
Sent: Wednesday, January 16, 2002 7:47 PM
Subject: Re: Pattern Matching - Remove Alpha
> 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
> --
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
>
Thread Previous
|
Thread Next