[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: backslash-newline change: my world has become black

From: Steve James
Subject: Re: backslash-newline change: my world has become black
Date: Wed, 21 Dec 2005 12:17:13 +0000
User-agent: KMail/1.7.2

On Tuesday 20 December 2005 22:39, Paul D. Smith wrote:
> %% Dan Jacobson <address@hidden> writes:
>   dj> You guys have a new backslash-newline deal that is breaking 1000
>   dj> of my scripts.
>   dj>   make
>   dj>   perl -pwle '\
>   dj>           BEGIN{print "#jidanni ~root/config auto changed"}\
>   dj>           s/^server pool.ntp.org/#jidanni off $&/;\
>   dj>           END{print "#more jidanni ~root/config auto changes";\
>   dj>           print "server $_.stdtime.gov.tw offline maxdelay 1" for
> qw/tick \ dj>           time tock/; print "mailonchange address@hidden
> 12";\ dj>           print "#jidanni: restarting in /etc/ppp/ip-up.d/chrony
> so \ dj>           can use
> hostnames\n#http://www.stdtime.gov.tw/ntp/CONF.HTM"}' \... dj>   Useless
> use of single ref constructor in void context at -e line 6. dj>   Useless
> use of reference constructor in void context at -e line 2. dj>   Useless
> use of reference constructor in void context at -e line 4. dj>   Can't call
> method "BEGIN" without a package or object reference at -e line 2, <> line
> 1.
>   dj> There is no documentation on how I am supposed to fix my 1000
> scripts.
> The behavior of backslash/newline in a makefile command script follows
> exactly the behavior you would get if you typed the same command
> directly to shell prompt.  That's the POSIX-required behavior.  And, it
> enables all sorts of other capabilities for multi-line scripting that
> were not possible before.
> There are two ways to do what you want to do:
> First, you can use double quotes instead of single quotes.  Just as with
> the shell prompt, inside double quotes the backslash-newline will be
> processed and removed by the shell before your command is invoked.
> Consider the difference between running:
>     perl -e '\
>             exit(0);'
> and:
>     perl -e "\
>             exit(0);"
> Of course, changing to double quotes has a lot of ramifications on your
> script for that very reason (the shell parses the content of the quoted
> string) and so this can be painful.
> Another option is to store the script in a make variable:
> backslash-newline management in make variables uses make rules, not
> shell rules.  You didn't provide an actual example of a make target that
> I can use for an example, but this will work the same way the old code
> used to work:
>     PERLFUNC = '\
>            BEGIN{print "#jidanni ~root/config auto changed"}\
>            s/^server pool.ntp.org/#jidanni off $&/;\
>            END{print "#more jidanni ~root/config auto changes";\
>            print "server $_.stdtime.gov.tw offline maxdelay 1" for qw/tick
> \ time tock/; print "mailonchange address@hidden 12";\
>            print "#jidanni: restarting in /etc/ppp/ip-up.d/chrony so \
>            can use hostnames\n#http://www.stdtime.gov.tw/ntp/CONF.HTM"}'
>     all:
>             perl -e $(PERLFUNC)

Good: this is the sort of advice that I was suggesting is included in the 
manual; the current text alludes to the change but offers no advice on how to 
accommodate it.

I've had the same grief with broken make scripts because of this change, 
though fortunately I don't have nearly as many as 1000 instances to address! 
I've taken to using defines like this:

define makevars.pl
  $$_=<>; $$_=<>; $$_=<>; $$_=~ s/\s//; \
  if (($$instance, $$type, $$name, $$version)=split q[/]) { \
    print qq[ccm_name     := $$name\n], \
          qq[ccm_instance := $$instance\n], \
          qq[ccm_type     := $$type\n], \
          qq[ccm_version  := $$version\n], \
          qq[ccm_project  := $$name-$$version:$$type:$$instance\n], \

%.makevars : .ccmwaid.inf
        @ echo GENERATING $@
        @ perl -e '$(makevars.pl)' < $< > $@

In the long run, I think this makes for a more readable script than it would 
have been had I inlined the perl into the recipe, so this makes this enforced 
change more palateable for me.

Death wish, n.:
        The only wish that always comes true, whether or not one wishes it to.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]