Talk:Source:SwRaid

From FAIWiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Perl style

I was very delighted to find this hook, because it was exactly what I needed. However I'd like to note that the Perl code ([1]) is not very clean. I'm going to fix some things:

  • open FILE, ">$filename" || die "blah"
The "||" here has more precedence than ",", i. e. "die" is never executed (because ">$filename" is always a true value). Use "or" rather than "||" because it has lower precedence (or use parentheses).
  • $result = `sh -c '$command'`;
Backticks invoke a shell anyway, so using "sh -c" here is redundant and only makes the quoting mess worse. In some particular case, $command is something like "echo 'y' | mdadm --create $config{$md}{options} --verbose /dev/$md --level=$config{$md}{level} --raid-devices=$config{$md}{num_devices} $config{$md}{devices}" which has the effect that the green single quote terminates the red one, which is certainly not what the author intended. I've changed the backticks to a system call because the result is only used for printing anyway.
  • When writing to a file, one should check errors for the print and close calls, otherwise the script will not notice when the disk is full.

--Betterworld 16:31, 7 September 2007 (CEST)