Re: Something screwy with split

2003-06-20 Thread R. Joseph Newton
[EMAIL PROTECTED] wrote:

 This works but does anyone have any ideas on the previous question?
  while(passwd_file )
{
$line=$_;
chomp($line);
@list=split(/:/,$line);
$account_key=$list[0];
$account=join :,@list;
$record{$account_key}=$account;
}

 I am trying to split off the user name and the password record in one pass
 through however what I am getting is only the first record is being
 populated into my user array.

 Can someone tell me am I going about this the right way?

 Thanks,
 Royce

 my @user=(split(/:/,(@passwd=(split(/\n/,`cat /etc/passwd`)))[0]));
 for($i=0;$i = $#passwd ; $i++)
 {
 print $user[$i]\n;
 print $passwd[$i]\n;
 }

In brief, the one that works is ismple and direct, and therefore likely to
work, if only because it is simpler to understand.  The earlier version twists
in upon itself in unnecessary complication, and such complication in itself is
likely to induce errors/.  Specifically here, the inner split probably
generates onelist, and calling split on that list will operate only on the
first item, since split is used to split scalars into lists, and does not
operate on lists.

The principle of KISS operates in the programming field more than in any other
science IMHO.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Something screwy with split

2003-06-14 Thread Rob Dixon
Royce Wells wrote:
 I am trying to split off the user name and the password record in one pass
 through however what I am getting is only the first record is being
 populated into my user array.

 Can someone tell me am I going about this the right way?

 Thanks,
 Royce



 my @user=(split(/:/,(@passwd=(split(/\n/,`cat /etc/passwd`)))[0]));
 for($i=0;$i = $#passwd ; $i++)
 {
 print $user[$i]\n;
 print $passwd[$i]\n;
 }

Come on guys.

The answers a resounding 'no'. But why on earth try to write fancy code
which is neither comprehensible nor functional. Let's start from here:

  open PWD, '/etc/passwd' or die $!;

next line, anybody?

Rob






-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Something screwy with split

2003-06-14 Thread Harry Putnam
Rob Dixon [EMAIL PROTECTED] writes:

   open PWD, '/etc/passwd' or die $!;

 next line, anybody?

while (PWD){
 hehe


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Something screwy with split

2003-06-13 Thread royce . wells
I am trying to split off the user name and the password record in one pass
through however what I am getting is only the first record is being
populated into my user array.

Can someone tell me am I going about this the right way?

Thanks,
Royce



my @user=(split(/:/,(@passwd=(split(/\n/,`cat /etc/passwd`)))[0]));
for($i=0;$i = $#passwd ; $i++)
{
print $user[$i]\n;
print $passwd[$i]\n;
}




The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential and/or privileged
material. Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by persons or
entities other than the intended recipient is prohibited. If you received
this in error, please contact the sender and delete the material from any
computer.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Something screwy with split

2003-06-13 Thread royce . wells
This works but does anyone have any ideas on the previous question?
 while(passwd_file )
   {
   $line=$_;
   chomp($line);
   @list=split(/:/,$line);
   $account_key=$list[0];
   $account=join :,@list;
   $record{$account_key}=$account;
   }








I am trying to split off the user name and the password record in one pass
through however what I am getting is only the first record is being
populated into my user array.

Can someone tell me am I going about this the right way?

Thanks,
Royce



my @user=(split(/:/,(@passwd=(split(/\n/,`cat /etc/passwd`)))[0]));
for($i=0;$i = $#passwd ; $i++)
{
print $user[$i]\n;
print $passwd[$i]\n;
}




The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential and/or privileged
material. Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by persons or
entities other than the intended recipient is prohibited. If you received
this in error, please contact the sender and delete the material from any
computer.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential and/or privileged
material. Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by persons or
entities other than the intended recipient is prohibited. If you received
this in error, please contact the sender and delete the material from any
computer.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Something screwy with split

2003-06-13 Thread James Edward Gray II
On Friday, June 13, 2003, at 12:01  PM, [EMAIL PROTECTED] wrote:

I am trying to split off the user name and the password record in one 
pass
through however what I am getting is only the first record is being
populated into my user array.

Can someone tell me am I going about this the right way?
Hmm, I don't think so.

my @user=(split(/:/,(@passwd=(split(/\n/,`cat /etc/passwd`)))[0]));
Okay, let's see what this is doing in English:

1.  Run `cat /etc/passwd`
2. Split the results of that on newlines
3. Store that in @passwd
# problems begin on the next step, I believe
4. Take the first entry of that array and split it on :
5. Store those results in @user
I'm not 100% sure how your /etc/passwd is formatted, but if the name is 
before the first colon and the password is after, we could populate a 
hash with something like:

my %users = map { (split /:/, $_)[0, 1] } grep !/^#/, split /\n/, `cat 
/etc/passwd`;

And print it with:

print $_ $users{$_}\n foreach keys %users;

for($i=0;$i = $#passwd ; $i++)
{
print $user[$i]\n;
print $passwd[$i]\n;
}
Hope that helps.

James

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Something screwy with split

2003-06-13 Thread Casey West
It was Friday, June 13, 2003 when [EMAIL PROTECTED] took the soap box, saying:
: Can someone tell me am I going about this the right way?
: 
: my @user=(split(/:/,(@passwd=(split(/\n/,`cat /etc/passwd`)))[0]));
: for($i=0;$i = $#passwd ; $i++)
: {
: print $user[$i]\n;
: print $passwd[$i]\n;
: }

Whoa.  That looks like complicated code.  I think we can clean it up.
Your first attempt with a while loop was much closer.  And you
probably shouldn't be trying to juggle data between two arrays like
that.  Why don't we go back to your original attept.

I'm going to assume that order isn't important to you.

  open( PASSWD, /etc/passwd ) || die $!;
  my %records;
  while (PASSWD) {
my($user, $pass) = split( /:/, $_ );
$records{$user} = $pass;
  }
  close( PASSWD );

That was easy, and I know from your first exapmle that you understand
it pretty well too.  If order is important to you, you want the list
to stay in the same order as the passwd file, you can change this
arround a bit and use a list of hashes.

  my @records;
  while (PASSWD) {
my($user, $pass) = split( /:/, $_ );
push @records, {
  user = $user,
  pass = $pass,
};
  }

Enjoy!

  Casey West

-- 
Louis Pasteur's theory of germs is ridiculous fiction.
 -- Pierre Pachet, Professor of Physiology at Toulouse, 1872


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Something screwy with split

2003-06-13 Thread John W. Krahn
Royce Wells wrote:
 
 I am trying to split off the user name and the password record in one pass
 through however what I am getting is only the first record is being
 populated into my user array.
 
 Can someone tell me am I going about this the right way?

You should probably use perl's builtin functions to access password
information.

perldoc -f getpwnam
perldoc -f getpwuid
perldoc -f getpwent
perldoc -f setpwent
perldoc -f endpwent
perldoc User::pwent


 my @user=(split(/:/,(@passwd=(split(/\n/,`cat /etc/passwd`)))[0]));
 for($i=0;$i = $#passwd ; $i++)
 {
 print $user[$i]\n;
 print $passwd[$i]\n;
 }

while ( my ( $user, $passwd ) = getpwent ) {
print $user\n$passwd\n;
}



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Something screwy with split

2003-06-13 Thread James Edward Gray II
On Friday, June 13, 2003, at 12:54  PM, [EMAIL PROTECTED] wrote:

password file format

user:passwd:uid:gid:gecos:homedir:shell

I need to be able to change any of the fields within each user record.
While having the hash key remain the same user across many files.
I'm not sure I understand the question here, but the following should 
load a hash for you:

# Format:  user = [ passwd, uid, gid, gecos, homedir, shell ]
my %users;
foreach (grep !/^#/, split /\n/, `cat /etc/passwd`) {
my($name, @details) = split /:/, $_;
$users{$name} = [ @details ];
}
# sample printout
print User:  $_, Passwd:  $users{$_}[0], ..., Shell:  $users($_}[5]\n 
foreach keys %users;

Hope that helps.

James

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Something screwy with split

2003-06-13 Thread Steve Grazzini
On Fri, Jun 13, 2003 at 12:28:47PM -0500, James Edward Gray II wrote:
 On Friday, June 13, 2003, at 12:01  PM, [EMAIL PROTECTED] wrote:
 
 my @user=(split(/:/,(@passwd=(split(/\n/,`cat /etc/passwd`)))[0]));
 
 I'm not 100% sure how your /etc/passwd is formatted, but if the name is 
 before the first colon and the password is after, we could populate a 
 hash with something like:
 
 my %users = map { (split /:/, $_)[0, 1] } grep !/^#/, split /\n/, `cat 
 /etc/passwd`;

That could be a little bit more compact:

  my %users = map +(split /:/)[0,1], grep !/^#/, `cat /etc/passwd`;

Or even:

  my %users;
  $users{$a} = $b while ($a,$b) = getpwent;

-- 
Steve

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]