Using split to return a @ without splitting on spaces 
Author Message
 Using split to return a @ without splitting on spaces

I have a user's password (/etc/passwd) entry in an array.  I want the
full user name from the GECOS field.


not what I expect.  For example, the full user name from the GECOS field
should be contained in $gecos[0], but is instead contained over multiple

is to split both on the pattern ',' AS WELL as on whitespace.


print "Content-type: text/html\n\n";
if( defined $pwent[6] ) {
        ($full_name, $blah) = split /,/, $pwent[6];

Quote:
}

else {
        print "GECOS Field not found for $http_data{ 'loginID' }<BR>\n";
        exit 1;
Quote:
}

----------- snip, snip --------------------

If you print $full_name and $gecos[0], the result is NOT THE SAME!
$full_name will be the COMPLETE name, while $gecos[0] will be the FIRST
NAME ONLY!.

What can I do to prevent splitting on whitespace????

TIA

Matt Murdock



Tue, 24 Oct 2000 03:00:00 GMT  
 Using split to return a @ without splitting on spaces

Quote:

>         ($full_name, $blah) = split /,/, $pwent[6];

> If you print $full_name and $gecos[0], the result is NOT THE SAME!
> $full_name will be the COMPLETE name, while $gecos[0] will be the FIRST
> NAME ONLY!.

You don't need to SHOUT! :-)


run your code above, and get this to happen? I can't...

    $pwent[6] = 'my full name, some other data, some more';
    ($full_name, $blah) = split /,/, $pwent[6];

    print "\$full_name is '$full_name'.\n";
    print "\$gecos[0] is '$gecos[0]'.\n";

Of course, split is documented to work differently when splitting into a
literal list, but I don't think that's what you're seeing. Are you certain
that you are running the code you've given us? Hope this helps!

--
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



Tue, 24 Oct 2000 03:00:00 GMT  
 Using split to return a @ without splitting on spaces

Quote:


> >         ($full_name, $blah) = split /,/, $pwent[6];

> > If you print $full_name and $gecos[0], the result is NOT THE SAME!
> > $full_name will be the COMPLETE name, while $gecos[0] will be the FIRST
> > NAME ONLY!.

> You don't need to SHOUT! :-)


> run your code above, and get this to happen? I can't...

    You are right.  The problem I was having is *not* what I described.  I
was trying to print the array, such as:


    The above code acts as I described, where each array element seems to be
broken up by the spaces in the data, not by true list elements.  However,
what I described was not accurate, as you kindly pointed out!  At any rate, I
now know how to access the data I want, but am left with another question:
Why does the above code not print each list element individually?

Quote:
> Of course, split is documented to work differently when splitting into a
> literal list, but I don't think that's what you're seeing. Are you certain
> that you are running the code you've given us? Hope this helps!

    It did help.  Thanks!

Matt Murdock



Wed, 25 Oct 2000 03:00:00 GMT  
 Using split to return a @ without splitting on spaces

[snip]

: > run your code above, and get this to happen? I can't...
:
:     You are right.  The problem I was having is *not* what I described.  I
: was trying to print the array, such as:
:

What's that globbing operator <> doing in that while condition??  Also,
while over a list doesn't magically iterate like it does over a
<FILEHANDLE>.  What you probably mean is




on each loop iteration.  {*filter*}...

---------------------------------------------------------------------

 --*--    Home Page: http://www.*-*-*.com/
   |      Member of The HTML Writers Guild: http://www.*-*-*.com/ ;
       "Every man and every woman is a star."



Wed, 25 Oct 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. splitting, without losing the thing you split with

2. howto split without regard to white spaces?

3. PERLFUNC: split - split up a string using a regexp delimiter

4. PERLFUNC: split - split up a string using a regexp delimiter

5. split using varible length white spaces as field separators

6. Split on single space AND double space

7. Strange warning about split, without a split being used.

8. How to use split function to split on a backslash

9. split inside split - can it be done ?

10. Help with split please - or maybe split isn't correct

11. Splitting But NOT Splitting

12. Complicated pattern splitting in split

 

 
Powered by phpBB® Forum Software