in reply to A first attempt at obfuscation.

It's actually pretty readable once it's properly formatted (and once you've run it to see what it does). It runs fine with strict and warnings, too. I wasn't familiar with the use of "%*d" in sprintf.
#! /usr/bin/perl use strict; use warnings; $/ = length( $" = int <STDIN> ) + 1; for $! ( 1 .. $" ) { print $_< $" + 1 - $! ? " " x $/ : $_ <= $" ? sprintf "%*d", $/, $" + 1 - $_ : $_ <= $" + $! - 1 ? sprintf "%*d", $/, abs $" - 1 - $_ : $_ == 2 * $" ? "\n" : "" foreach ( 1 .. ( 2 * $" ) ); }
We can interpret the ternary operators as being the equivalent of a C switch() statement. The first case of the switch() prints out the leading spaces needed to maintain the pyramid shape. The second case prints out the numbers from $! down to 1. The third case prints out the numbers from 2 up to $!. The fourth case prints the final newline. The default case prints nothing.

Replies are listed 'Best First'.
Re^2: A first attempt at obfuscation.
by Pic (Scribe) on Feb 22, 2005 at 00:24 UTC
    Quite correct. And as I said, it's a first attempt. As for the sprintf format declarations, man 3 printf (I'd be very surprised if the internal implement ation of the perl printf functions aren't just wrappers to the original libc ones) is your friend. It's a bit on the terse side (or at least the GNU manpage was that to me) but quite useful once you get used used to the style.