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

While it is simple to include an svn keyword (E.g. "$Ig: $") in a perl comment, I want to assign it to a string variable so I can print it out or include it in a log file etc.

Various warnings etc. from the compiler suggested I declare and assign a value to it first, otherwise perl complained I was using it before it was assigned.

That was relatively trivial to fix (albeit perhaps not "properly" - see below), the remaining problem is the trailing (dangling) '$' in the string. I can't escape it using a backslash as svn doesn't find it. Ending the string with $\\" also produces a warning (uninitialized value). If I use something like the following:

our $Id = ""; our $IdEnd = ""; $script_version = "$Id: Myob2010_mpbudget.pl 32 2010-05-28 03:57:52Z a +ndrew $IdEnd";

The ending $IdEnd is not interpreted as an empty string and appears literally, which of course I could just strip off for output, but I am hoping there is a more elegant solution.

I have ended up using a "double dollar", so the svn keyword before expansion is "$Id: $$"

Can this be improved on ?

Replies are listed 'Best First'.
Re: Subversion Keyword in string
by ikegami (Patriarch) on May 28, 2010 at 04:37 UTC
    Use non-interpolating quotes.
    '$Id: Myob2010_mpbudget.pl 32 2010-05-28 03:57:52Z andrew $'
Re: Subversion Keyword in string
by tinita (Parson) on May 28, 2010 at 08:07 UTC
    i also like the following:
    my $script_version = q$Id: Myob2010_mpbudget.pl 32 2010-05-28 03:57:52Z andrew$;
Re: Subversion Keyword in string
by BrowserUk (Patriarch) on May 28, 2010 at 04:28 UTC

    Would $id=''; $version = "$id: Myob2010_mpbudget.pl 32 2010-05-28 03:57:52Z andrew $,"; work?

Re: Subversion Keyword in string
by nullandvoid (Initiate) on May 28, 2010 at 05:53 UTC

    Thanks to both BrowserUk and ikegami for their responses.

    I didn't try both suggestions, as the non-interpolating quotes triggered a dim and dusty light bulb somewhere and I can confirm that it does the trick.

    I very much appreciate both your quick answers.