in reply to Re: System and a question of style
in thread System and a question of style

Good idea steves++ , I suppose it depends on one's perl version and personal preference, but being able to call system with list syntax (bypassing the shell hence no jiggery-pokery with escaping things) is IMHO so groovy it hurts doing it the old way!. I'd make a small modification to your subroutine.

sub run_command { # invoke system(@list) if more than one arg passed. ($#_) ? system(@_) : system($_[0]); if ($?) { my $rc = $? >> 8; die "Failed to run '$command': exit code $rc\n"; } } # Easy arg passing with a list; run_command('blah' , '-v' , '-q'); # Pass as scalar for shell interpretation of metachars run_command('tar cvf /dev/null /tmp/*.sock');

warning - the args to run_command are untested but no harmful

I can't believe it's not psellchecked

Replies are listed 'Best First'.
Re: Re: Re: System and a question of style
by bsb (Priest) on Feb 07, 2003 at 06:42 UTC
    Perhaps you should put $! in the die string too.
Re: Re: Re: System and a question of style
by bronto (Priest) on Feb 07, 2003 at 11:24 UTC

    Why don't force the list syntax? For example, doing a system(@_,"")?

    --bronto


    The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
    --John M. Dlugosz