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

Re: Creating variables of a string

Thread Previous | Thread Next
From:
Tanton Gibbs
Date:
April 2, 2002 09:07
Subject:
Re: Creating variables of a string
Message ID:
00e601c1da68$aa145e00$23d9550a@brooklyn
my ($word, $num1, $num2) = $string =~ /^\s*(\S+)\s+(\S+)\s+(\S+)\s*$/;

This matches
^ - the start of the string
\s* - any number (including 0) of spaces
(\S+) - any number (not including 0) of NON spaces.  It also saves the value
\s+ - any number (not including 0) of spaces
(\S+) - see above
\s+ - see above
(\S+) - see above
\s* - see above
$ - the end of the string (including a possible newline)

The saved values will then be set back to the three variables $word, $num1,
and $num2
----- Original Message -----
From: "Michael Stearman" <qazwsxe7@hotmail.com>
To: <beginners@perl.org>
Sent: Tuesday, April 02, 2002 12:02 PM
Subject: Creating variables of a string


>
> Hi,
>
> I have a string that contains a word and 2 numbers.  For example,
>
> Michael     57   3
>
> I want to assign each of these three to different variables.  My only
> problem is that the word and the numbers are always different and the
space
> between the words and numbers is always different as well.  Does anyone
know
> how I would assign the word and numbers to three different variables?
> Thanks in advance.
>
> Mike.
>
>
> _________________________________________________________________
> Send and receive Hotmail on your mobile device: http://mobile.msn.com
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
>


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