Re: Pattern Matching - Remove Alpha

2002-01-18 Thread Michael Fowler

On Wed, Jan 16, 2002 at 09:51:45PM -0500, Tanton Gibbs wrote:
 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.

That might work, except one of his requirements is that the numeric data be
placed into an array.

tr/// is more efficient; I can't really guage its level of idiomicity
compared to split.


  On Wed, Jan 16, 2002 at 05:38:56PM -0600, Hewlett Pickens wrote:
[snip]
$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.
[snip]


Michael Fun with Language Fowler
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Pattern Matching - Remove Alpha

2002-01-16 Thread Hewlett Pickens

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 

Hewlett


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Pattern Matching - Remove Alpha

2002-01-16 Thread Wagner-David

Could do something like:

   @MyNbrs = map{ /(\d+)/g } $MyInp;

Small script:

my @MyNbrs = ();

while ( 1 ) {
   printf Please enter string of data:\n;
   chomp(my $MyInp = STDIN);
   last if ( $MyInp =~ /^ex$/i );
   @MyNbrs = map{ /(\d+)/g } $MyInp;
   my $MyCnt = 1;
   foreach ( @MyNbrs ) {
  printf %3d: %6d\n, $MyCnt++, $_;
}
 }

Input:
adfafdafd1234erer12dasd34qweqeqweqw4567

Output:

  1:   1234
  2: 12
  3: 34
  4:   4567

Wags ;)
-Original Message-
From: Hewlett Pickens [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 16, 2002 15:39
To: [EMAIL PROTECTED]
Subject: Pattern Matching - Remove Alpha


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 

Hewlett


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Pattern Matching - Remove Alpha

2002-01-16 Thread Michael Fowler

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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Pattern Matching - Remove Alpha

2002-01-16 Thread John W. Krahn

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

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]