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

Re: Creating variables of a string

Thread Previous | Thread Next
From:
Michael Stearman
Date:
April 2, 2002 09:28
Subject:
Re: Creating variables of a string
Message ID:
F185iPm8MdpfKz1YuDG00004a85@hotmail.com
Right now it is not working and I was wondering if I sent the code maybe 
someone with more experience with this will see the problem.  I am very new 
to this.  The line I am trying to create the variables from is

C6xxxSimulator(TI)  	61	1

and the code is

$word = <DATA>; #Assign the next line to the $word variable
chomp $word;
print "$word\n";
my ($target, $count, $num) = $word = ~ /^\s*(\S+)\s+(\S+)\s+(\S+)\s*$/;
print "Target = $target \n";
print "Count = $count \n";

and the output is

C6xxxSimulator(TI)  	61	1
Target = 4294967295
Count =

Does anyone have any ideas?  I'm lost.


>From: "Tanton Gibbs" <thgibbs@deltafarms.com>
>To: "Tanton Gibbs" <thgibbs@deltafarms.com>,   "Michael Stearman" 
><qazwsxe7@hotmail.com>, <beginners@perl.org>
>Subject: Re: Creating variables of a string
>Date: Tue, 2 Apr 2002 12:12:11 -0500
>
>Actually, since the others are numbers you could replace the last two \S+
>with \d+
>----- Original Message -----
>From: "Tanton Gibbs" <thgibbs@deltafarms.com>
>To: "Michael Stearman" <qazwsxe7@hotmail.com>; <beginners@perl.org>
>Sent: Tuesday, April 02, 2002 12:06 PM
>Subject: Re: Creating variables of a string
>
>
> > 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
> > >
> >
> >
> > --
> > To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> > For additional commands, e-mail: beginners-help@perl.org
> >
>
>
>--
>To unsubscribe, e-mail: beginners-unsubscribe@perl.org
>For additional commands, e-mail: beginners-help@perl.org
>




_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com


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