|
|
sybperl-l Archive
Up Prev Next
From: "Klein, Shoshana R" <Shoshana dot Klein at gs dot com>
Subject: RE: splitting a field by an unrecognizable null field
Date: Sep 25 2000 1:03PM
Thanks alot
Your detailed explanation fills in alot gaps that I didn't pick up from
reading the Perl books
Thank You
Shoshana Klein
-----Original Message-----
From: btk4 [mailto:btk4@msn.com]
Sent: Monday, September 25, 2000 4:29 AM
To: SybPerl Discussion List
Subject: Re: splitting a field by an unrecognizable null field
Without parenthesis enclosing the return variables, you are implying to the
split function that you want back, not the values that were split, but the
'count' of variables.
By the counts of splits that were returned in your examples, it seems that
the proper 'count' of splits were when you used
the 'space' or \s expression.
When using the split function, to return to an array.
Add parenthesis as follows:
($first, $last) = split(/\s/, $name);
print "s first=$first last= $last name= $name \n";
You can still do without parenthesis, however the matches will be found in
the @_ array.
Brian
----- Original Message -----
From: Klein, Shoshana R
To: SybPerl Discussion List
Sent: Sunday, September 24, 2000 9:55 PM
Subject: splitting a field by an unrecognizable null field
> Hi,
> I'm trying to split a name field into first and last name, the input data
> has the name as one field that appears to have a space in between the
first
> and last name.
>
> I tried splitting on \t \s \b \w / / and it doesn't work.
> any ideas how I can separate this field without knowing what kind of
> character actually is there.
> I'm not quite sure where the data came from, it could have been from a
> massaged excel,word,
> notepad etc file.
>
> $first, $last = split(/\b/, $name);
> print "b first=$first last= $last name= $name \n";
> $first, $last = split(/\w/, $name);
> print "w first=$first last= $last name= $name \n";
> $first, $last = split(/\t/, $name);
> print "tab first=$first last= $last name= $name \n";
> $first, $last = split(/ /, $name);
> print "blank first=$first last= $last name= $name \n";
> $first, $last = split(/\s/, $name);
> print "s first=$first last= $last name= $name \n";
>
> ($first, $last) = split(/![a-z,A-Z]/, $name);
> print "nots first=$first last= $last name= $name \n";
>
>
> tHE OUTPUT LOOKS LIKE THIS
> b first= Karen Livings last= 3 name= Rachel Tippetts
> w first= Karen Livings last= 7 name= Rachel Tippetts
> tab first= Karen Livings last= 1 name= Rachel Tippetts
> blank first= Karen Livings last= 2 name= Rachel Tippetts
> s first= Karen Livings last= 2 name= Rachel Tippetts
> nots first=Rachel Tippetts last= name= Rachel Tippetts
>
>
|