Try this:
$word = <DATA>; #Assign the next line to the $word variable chomp $word; print "$word\n"; $word =~ /^\s*(\S+)\s+(\S+)\s+(\S+)\s*$/; #assign the matches in parenthesis to $# vars my $target = $1; my $count = $2; my $num = $3; print "Target = $target \n"; print "Count = $count \n"; -----Original Message----- From: Michael Stearman [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 02, 2002 9:28 AM To: [EMAIL PROTECTED] Subject: Re: Creating variables of a string 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" <[EMAIL PROTECTED]> >To: "Tanton Gibbs" <[EMAIL PROTECTED]>, "Michael Stearman" ><[EMAIL PROTECTED]>, <[EMAIL PROTECTED]> >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" <[EMAIL PROTECTED]> >To: "Michael Stearman" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> >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" <[EMAIL PROTECTED]> > > To: <[EMAIL PROTECTED]> > > 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: [EMAIL PROTECTED] > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > -- > > 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] > _________________________________________________________________ Send and receive Hotmail on your mobile device: http://mobile.msn.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -------------------------------------------------------------------------------- This email may contain confidential and privileged material for the sole use of the intended recipient. If you are not the intended recipient, please contact the sender and delete all copies. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]