in reply to Problem with GetOptions

Put in a print join ":", @ARGV before the GetOptions, and test for yourself what it is getting. You probably want to say slimserver "$SLIMSERVER_ARGS", not slimserver $SLIMSERVER_ARGS. Trying in bash:
$ THEORB2="|fgrep -e THE -e B2" $ perl -we'print join ":", @ARGV' $THEORB2 |fgrep:-e:THE:-e:B2 $ perl -we'print join ":", @ARGV' "$THEORB2" |fgrep -e THE -e B2

Replies are listed 'Best First'.
Re^2: Problem with GetOptions
by robinbowes (Beadle) on Dec 22, 2004 at 20:50 UTC
    Thanks for both suggestions.

    I used the "print join" suggestion to see what was going on and used single quotes in the string to prevent GetOptions splitting the log command.

    I then saw that the script was tring to open the log file with ">>$log", which of course failed with a pipe for a log file. I removed the ">>" and it now works as desired.

    Is there a foolproof way to only add the ">>" if the log file is a file rather than a pipe?

    Is it as simple as checking for the pipe character at the start of the string? Something like:

    $logfilename = $log; if (substr($log, 0, 1) ne "|") { $logfilename = ">>" . $log; } if (!open STDOUT, $logfilename) { die "Can't write to $logfilename: $! +";}
    Thanks,

    R.

    --

    Robin Bowes | http://robinbowes.com

      Whitespace before the | is allowed (even tabs and newlines!), so you may want to check for that also. If $log has a trailing | or leading <, removing your >> may also be not what you want, but those cases you probably ought to treat as input errors, along with |- (which also can have whitespace between the two chars).
        ysth,

        Thanks for the suggestions.

        For the my purposes, I'm happy to keep it simple and to fail on anything other than a leading "|".

        Thanks again,

        R.

        --

        Robin Bowes | http://robinbowes.com