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

RE: Creating variables of a string

Thread Previous | Thread Next
From:
David Gray
Date:
April 2, 2002 11:42
Subject:
RE: Creating variables of a string
Message ID:
000101c1da7e$7e5aaa10$7800a8c0@3b2.com
> Michael Stearman wrote:
> > 
> > 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*$/;
> 
> my ($target, $count, $num) = split ' ', $word;

I think that needs to be:

my ($target,$count,$num) = split /\s+/, $word;

to handle multiple spaces between the values.

Cheers,

 -dave



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