in reply to Questions about split

First off, that [2] is creating an anonymous array. Get rid of the brackets.

As to throwing away values, if you want to ignore the first one, just do this: If you're going to ignore the first value, do this:

(undef, $match_I_want) = split /:/, $_, 2;
As to your next part:
I did get it to work by doing this:
($user) = split /:/, $_, [1]; ($temp, $foo{$user}) = split /:/, $_, [2];
Sounds like what you really want is this:
($user,$name) = split /:/, $_, 2; $name_lookup{$user} = $name;
Finally, what you're doing may be unnecessary. I'm assuming that you're doing a build of /etc/passwd, right? You may also want to look into the getpwnam, getpwuid and related functions and let them take care of the work for you. If you want to read everything from the password file, take a look at getpwent.

xoxo,
Andy
--
<megaphone> Throw down the gun and tiara and come out of the float! </megaphone>

Replies are listed 'Best First'.
Re: Re: Questions about split (indexing /etc/passwd)
by blax (Sexton) on Jul 01, 2001 at 12:18 UTC
    Thank you both for your replies... they where both very helpfull to me.

    The getpwent function does exactly what I was trying to do. I was wondering if the perl functions are built into the parser or are they installed as scripts? I found a few scripts such as bigint.pl, but they all say "This librarisy is no longer being maintained...".

    Thanks,
    blax