in reply to Re^2: Random Desktop Background for IceWM
in thread Random Desktop Background for IceWM

What I meant was to use lexical filehandles:
{ open my $PREF, '<', $pref; open my $NEW_PREF, '>>', $new_pref; while (<$PREF>) { s#$image_directory/.*#$wallpaper"#; print $NEW_PREF $_; }
Once you leave this block, the filehandles go away and the connections to your files are closed.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Replies are listed 'Best First'.
Re^4: Random Desktop Background for IceWM
by Texadan (Monk) on Apr 07, 2009 at 19:00 UTC
    Gotcha. Thank you.
      While you're at it, another "Best Practice" is to check "open" returns for failure, to avoid mysterious bugs :
      open my $PREF, '<', $pref or die "Awwww, can't open $pref: $?";
        Thank you.