SPUG: flip-flops

Matt Tucker tuck at whistlingfish.net
Mon Feb 11 15:04:18 CST 2002


-- "Michael R. Wolf" <MichaelRunningWolf at att.net> spake thusly:

> David Dyck <dcd at tc.fluke.com> writes:
> 
>> On 10 Feb 2002 at 14:47 -0500, Michael R. Wolf
>> <MichaelRunningWolf at att.net>...:
>> 
>> > Note that dollar ($) means ...
>> >  ... "last line" in the flip-flop.
>> > 
>> >     $body   .= $_ if /^$/ .. $;
> 
>> I don't think this does what you want
> 
> But I think this does:
<snip>
>
>     perl -n -e '$body   .= $_ if (/^$/ .. $);' \
>             -e '$head   .= $_ if (1 .. /^$/);' \
>             -e 'END{print $head, "\n", "="x40, "\n", $body;}'

This gives:

    syntax error at -e line 1, near "$);"
    Execution of -e aborted due to compilation errors.

This code:

    perl -n -e '$body   .= $_ if /^$/ .. $ ;' \
            -e '$head   .= $_ if (1 .. /^$/);' \
            -e 'END{print $head, "\n", "="x40, "\n", $body;}'

gives:

    Scalar found where operator expected at -e line 2, near "$ ;
    $head"
            (Missing semicolon on previous line?)
    syntax error at -e line 2, near "$ ;
    $head   "
    Execution of -e aborted due to compilation errors.

I've never seen just a bare '$' in Perl to indicate "last line". Do you
have any documentation to support the existence of it? Regardless,
doing the following gives the correct behavior:

    perl -n -e '$body   .= $_ if /^$/ .. 0;' \
            -e '$head   .= $_ if (1 .. /^$/);' \
            -e 'END{print $head, "\n", "="x40, "\n", $body;}'
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
Url : http://mail.pm.org/archives/spug-list/attachments/20020211/d42a0d21/attachment.bin


More information about the spug-list mailing list