http://www.perlmonks.org?node_id=201436

i wrote a usefull (at least for me) perl script that executes aterm with flags where the -tint $color flag everytime you execute the script changes ... so everytime you open a new aterm window ... it has a random tint color...

any suggestions on making the script better are wellcome.

#!/usr/bin/perl my @colors = ( 'red', 'green', 'blue', 'cyan' ); $howmany=@colors; $color = @colors[abs(rand($howmany))]; $line = 'aterm -fg green -tr -trsb -tint '."$color".' -cr green -pr gr +een -bd green +sb'; `$line`;

Replies are listed 'Best First'.
Re: aterm script
by Aristotle (Chancellor) on Sep 28, 2002 at 22:21 UTC
    #!/usr/bin/perl -w use strict; my @color = qw(red green blue cyan); exec 'aterm', qw(-fg green -tr -trsb), -tint => $color[rand @color], qw(-cr green -pr green -bd green);

    You don't need all those temporary variables; strive to minimize their amounts. strict and warnings should be a habit you don't even need to think about.

    That's just style though, the actual improvement would be dropping the backticks which spawn a new process, start a shell in it and have it run your program, capturing its output and returning it. All that for naught, since you're not using the output. Save two processes, a bunch of memory and a shell call (which should always be avoided when possible) by exec()ing instead. You don't need to have control returned from the external program anyway.

    For some general hints on good programming habits, see Mark-Jason Dominus' excellent Program Repair Shop and Red Flags article series on Perl.com.

    Makeshifts last the longest.

(jeffa) Re: aterm script
by jeffa (Bishop) on Sep 28, 2002 at 21:16 UTC
    use strict; my @color = qw(red green blue cyan); my $color = $color[rand @color]; ...

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: aterm script
by Anonymous Monk on Nov 01, 2002 at 17:07 UTC
    More choice. And is this ugly :)
    #!/usr/bin/perl my @colors = (split (/\n/,`cat /usr/lib/X11/rgb.txt |awk '{print \$4}' +`) ); $howmany=@colors; $color = @colors[abs(rand($howmany))]; $line = 'aterm -fg green -tr -trsb -tint '."$color".' -cr green -pr gr +een -bd green +sb'; `$line`;
    nfytn@rasmus.uib.no