|
|
sybperl-l Archive
Up Prev Next
From: Andrew Armstrong <andrew at qdebit dot com>
Subject: RE: splitting a field by an unrecognizable null field
Date: Sep 26 2000 12:42PM
I would also recomend changing it to this.
($first, $last) = split(/\s+/, $name , 2 );
or
($first, $last , $other) = split(/\s+/, $name , 3 );
because if you split a name that looks like this
"John Edward Johnson"
with
($first, $last) = split(/\s+/, $name);
print "s+ first='$first' last='$last' \n" ;
will print
s+ first='Edward' last='Johnson'
Quoting "McNay, Gavin" :
> i think you should change the code from
>
> $first, $last = split(/\b/, $name);
>
> to
> ($first, $last) = split(/\s+/, $name);
>
> what you were seeing was a precedence problem, but \s+ is probably what
> u
> want anyway
>
> Gavin
> -----Original Message-----
> From: Monty Scroggins [mailto:Monty.Scroggins@wcom.com]
> Sent: 25 September 2000 06:11
> To: SybPerl Discussion List
> Subject: Re: splitting a field by an unrecognizable null field
>
>
> Maybe you can split on \W (anything but a word character)..
>
> Just a thought
>
> Monty
>
> ----- Original Message -----
> From: "Klein, Shoshana R"
> To: "SybPerl Discussion List"
> Sent: Sunday, September 24, 2000 8: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
> >
>
-------------------------------------------------------------------------------
Andrew Armstrong andrew@qdebit.com
Chief E-Commerce Engineer http://www.qdebit.com
AMIS , LLC.
|