On Thu, Aug 09, 2001 at 11:15:01AM -0700, Sofia wrote:
> %compilers = (
>    system1 => "compiler_a",
>    system2 => ["compiler_b", "compiler_c"],
>    system3 => "compiler_d",
> );
> 
> foreach $compiler (@{$compilers{$system}}) (

This code shouldn't work.  Have you made this modification recently, without
testing it?  The problem is that you're dereferencing each value of
%compilers as an array, but not all of the values are arrays; when it hits
one that isn't, it'll die a horrible, screaming death.


>         $compiler_passwd = $compilers{$system} .
> "_passwd";

You already have $compilers{$system}, it's $compiler.


>         open ($compiler, "< $compiler_passwd") or die
> "Can't open file $compiler_passwd: $!\n";

You just opened a handle on top of $compiler, obliterating that value. 
That's almost certainly not what you wanted.


>         while (<$compiler>) {
>            chomp;
>            @cmplr_data = (split(/:/))[0,1,2,4,5,6];
>            ($cusername, $cpswd, $cuid, $cgecos,
> $chome, $cshell) = @cmplr_data;

You're doing too much work here.


>            push(@{$compiler_data{$cuid}}, $cusername,
> $cpswd, $cgecos, $chome, $cshell);
>         }
>         close ($compiler) or die "Can't close file
> $compiler_passwd: $!\n";

>         open($compiler, "> $compiler_passwd") or die
> "Can't open file $compiler_passwd: $!\n";
> }

You open the file again for reading, but don't do anything with it.  If you
do plan on doing something with it, open the filehandle for reading and
writing to begin with.


Below is how your data and code should look.  It hasn't been tested, I'm
being lazy today.

    #!/usr/bin/perl -w

    use Fcntl qw(SEEK_SET);
    use strict;


    %compilers = (
        system1 =>  ['compiler_a'],
        system2 =>  ['compiler_b', 'compiler_c'],
        system3 =>  ['compiler_d'],
    );

    foreach my $compiler (@{ $compilers{$system} }) {
        my $compiler_passwd = $compiler . '_passwd';

        open(COMPILER, "+<$compiler_passwd")
            || die("Unable to open \"$compiler_passwd\": \l$!.\n");

        while (<COMPILER>) {
            chomp;
            my($username, $password, $uid, $gecos, $home, $shell) = split(/:/);

            push(
                @{ $compiler_data{$uid} },
                $username, $password, $gecos, $home, $shell
            );
        }


        seek(COMPILER, 0, SEEK_SET)
            || die("Seek on COMPILER filehandle failed: \l$!.\n");

        ...
    }


You never actually make use of %compiler_data, so I don't know what kind of
scope it should have, or if it's going to hold data for multiple compilers. 
These things would affect how you set it.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

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

Reply via email to