perlmonkee has asked for the wisdom of the Perl Monks concerning the following question:

I asked a question earlier about forking an exe from perl.   I couldn't make it work with all the suggestions, but I found a nice perl module to do what I need called
Net::Syslog; it writes to a remote syslog daemon.

use Net:Syslog; my $s=new Net::Syslog(SyslogHost=>'1.2.3.4'); $s->send('see this is in the 1.2.3.4 syslog file');
works well, but I need to do this $s->send('$somevar'); and that yields "$somevar" in the remote syslog

I have tried ('"$somevar"') (`print "$somevar"`) and lots of others in the remote syslog in get literally $somevar, `print $somevar`, Can't find file somevar....

The closer I think I am the farther away I get.
Thanks

janitored by ybiC: Balanced <code> tags around code examples, minor format tweaks for legibility

Replies are listed 'Best First'.
Re: escaping output
by davorg (Chancellor) on Aug 12, 2004 at 15:06 UTC

    Variables aren't expanded in single quoted strings.

    $s->send($somevar);
    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      thanks. simplest form of things often overlooked.
Re: escaping output
by etcshadow (Priest) on Aug 12, 2004 at 16:24 UTC
    You should look in perldoc perlop in the "quotes and quote-like operators" section... but the short explanation is:
    • double quotes "..." will expand variables.
    • single quotes '...' will not expand variables.
    • backticks `...` will expand variables AND execute the string as though it were a command typed at the shell, AND THEN take the output of that command as the value of `...`.
    For example: $x = "oo"; "f$x" (or just "foo") would yield the same result as 'foo', which would also yield the same result as `echo foo` (well... except that echo would probably put a newline on the end, so it would be like "foo\n"... but whatever).
    ------------ :Wq Not an editor command: Wq