--- Daniel Falkenberg <[EMAIL PROTECTED]> wrote:
> Curtis,
> 
> Cheers for that that makes alot more sense now :).  Yes your are correct
> about the /etc/passwd file.  It's all well and good to be able to issue
> that command from a command line, but what if I wanted to issue the
> exact same code but from a script?
> 
> Regards,
> 
> Dan

Dan,

You can use -i on the shebang line.  Passing /etc/passwd as an argument gives you this 
(untested):

    #!/usr/bin/perl -wi
    use strict;

    while(<>) {
        my @F = split /:/;
        s/^/*/ if $F[3] == 45;
    }

Otherwise, you could try this (*very* untested):

    #!/usr/bin/perl -w
    use strict;

    my $file = '/etc/passwd';
    open FILE, "+< $file" or die "Cannot open $file in update mode:$!";
    my @lines = <FILE>;
    @lines = map { add_star( $_ ) }
             map { [split /:/] } @lines;

    seek FILE, 0, 0;
    print FILE @lines;
    truncate( FILE, tell(FILE) );
    close FILE;

    sub add_star {
        my $array_ref = shift;
        if ( $array_ref->[3] == 45 ) {
            $array_ref->[0] =~ s/^/*/;
        }
        return join ':', @$array_ref;
    }

The above code should give you an idea of how to proceed.  I just typed it in, though. 
 It's
untested. (and add_star is a stupid sub name, but I really don't know what this is 
for, so it's
all I could come up with :)

Cheers,
Curtis "Ovid" Poe

=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/

__________________________________________________
Do You Yahoo!?
Find a job, post your resume.
http://careers.yahoo.com

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

Reply via email to