Group,

        I think I figured it out I can strip $foo by doing the following:

$foo = "3212";
@FOO_NEW;
($FOO_NEW[0],$FOO_NEW[1]) = split (//, $foo);
#should return a value of "32"

Anyone see a problem with this? Or, perhaps, and easier way? Thanks much.

-Wes


Original Message ->


Thanks for the info I do have about 5 or 6 Perl books. And will look into
them.

Here's the problem, I made a mistake in my previous e-mail, I know how to
split an array by a certian character...for example

$foo = "3.2.1";
@FOO_NEW;
($FOO_NEW[0],$FOO_NEW[1]) = split (/\./, $foo); #Voila I have my first and
second position

The mistake I made is $foo doesn't contain "." separated values it's more
like this:

$foo = "321";
or it could be
$foo = "3214";

So I want the first 2 values which will change depending on what $foo is set
as. I wondered if I could split in between characters? Suggestions?

-Wes

-----Original Message-----
From: Mike [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, May 08, 2001 7:33 PM
To: North, Wesley J; '[EMAIL PROTECTED]'
Subject: Re: Another stripping question


Hi Wesley, first I would suggest acquiring O'Reilly's books on Regular
Expressions, Programming Perl, and Perl CookBook.  Regular expressions are
a very powerful tool in Perl.

To answer your question, there are many ways to do what you want but the
first thing that come to my mind is this:
$val =~ /(\d+\.\d+)/;
print "$1\n";

What this does is Perl creates a "backreference" and remembers what you
matched inside the () and places that value in a special variable $1.

Now if you want to take this a step further you can pluck-out your integers
by using the $1 and $2 special variables.
$val =~ /(\d+)\.(\d+)/;
print "$1--$2\n";

Mike...


*********** REPLY SEPARATOR  ***********

On 5/8/01 at 10:04 AM North, Wesley J wrote:

>Hello all,
>
>       Quick question. I have the following variables:
>
>$ver_num1 = "3.2.1";
>$ver_num2 = "4.4";
>$ver_num3 = "4.0.1";
>
>I need to keep the first 2 numbers and discard the rest so that each
>variable will look like:
>
>$ver_num1 = 3.2
>$ver_num2 = 4.4
>$ver_num3 = 4.0
>
>>From there I will strip out the ".", which is really easy. My question
is,
>how do I strip everything except the first 2 numbers? Any/all suggestions
>will be greatly appreciated. Thanks much.
>
>
>-Wes
>_______________________________________________
>ActivePerl mailing list
>[EMAIL PROTECTED]
>http://listserv.ActiveState.com/mailman/listinfo/activeperl


_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl

Reply via email to