Building off mrbbking, why don't we try and get rid of \n. After thinking and messing around bit, I ended up using $*: The multiline matching variable. I'd love to know *why* this works, and if it's compatible with *nix, as I used activestate.

Update: Tested on a FreeBSD shell, and it *does* work, as long as we run it with perl -l...

Please don't run this with warnings, as it won't work because $* is a deprecated special variable.

Here Goes: Still 59 Letters
#! perl -l %couples = ( Fred=>"Wilma", Barney=>"Betty", George=>"Jane", Homer=>"Marge", Peter=>"Lois" ); print"$_ is married to $couples{$_}$*"for sort keys%couples
Another idea that may or may not have merit is to set %couples to a shorter word, and call that in the print. Something that would (logically) be *like*
print"$_ is married to $c{$_}$*"for sort keys(%c=%couples)
That code doesn't work, though, and would save you just one character.

Update 2: I found it strange that I was getting newlines, instead of 0 or 1 from $*, so I investigated. From perldoc perlrun: -l enables automatic line-ending processing. If octnum is omitted, sets $\ to the current value of $/. That means that there's no reason to use $*, as -l will give us $/, anyways.

You will then realize that the previous answers would be correct, if we got rid of \n, or in my case $* (-l chops the last letter off in addition, which meant that my $* which should have been evaluated as 0 or 1, was being chopped off and replaced by a newline ($/). Strage, but we don't even need to print newlines, with perl -l :)

That means: print"$_ is married to $couples{$_}"for sort keys%couples can replace the respective line in the previous solution(s)

Gyan Kapur
gyan.kapur@rhhllp.com

In reply to Re: (Revelation) Re: A Bit Of Help by Revelation
in thread perl puzzle - cartoon couple registry (beginner, semi-golf) by boo_radley

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.