[BNE-PM] you lot have all gone quiet again? (Fwd)
Derek Thomson
derek at wedgetail.com
Tue Sep 17 05:27:57 CDT 2002
Anthony Thyssen wrote:
> ------- Forwarded Message
>
> From: Anthony Thyssen <anthony at wumpus.cit.gu.edu.au>
> To: "David Bussenschutt" <d.bussenschutt at mailbox.gu.edu.au>
> Subject: Re: [BNE-PM] you lot have all gone quiet again?
> Date: Tue, 17 Sep 2002 18:00:19 +1000
> Reply-to: Anthony Thyssen <anthony at cit.gu.edu.au>
>
> "David Bussenschutt" on wrote...
> | Is it just me... or have you lot out there on this list all gone quiet
> | again. We'll be having none of that!.
> |
> | Ok, here's my challenge to you all: I want one-liners. useful,
> | useless, fun,necessary,unique,quirky, whatever I don't care. Let's
> | see
> | what interesting one-liner perl programs you lot have come up with.
> | Send-em to the list, and we'll all become a little wiser as a
> | result.
I didn't know about the "-l" option. Handy, that!
>
> As the co-worker... How about this perl chalange...
>
> Write a print one-linter that can take the place of either
> the "column" or "pr" command above :-)
Horizontal columns is easy:
perl -le 'print for 1..100' | perl -ne 'chomp; print "$_\t"; print "\n"
unless $. % 10'
(it's less than 80 columns if you disregard the separate program that
generates the numbers, so it's a valid one-liner)
Vertical columns are much harder. Here's a start:
perl -le 'print for 1..104' | perl -e '@a=<>; chomp @a;
$c=int(@a/10)+(@a%10>0); for $i (0..$c-1) { for ($j=0; $j<@a; $j+=$c) {
printf "%6d", $a[$i+$j] } print "\n"; }'
This is too long by far, and has a bug - "filler" values in the final
column are printed as "0". I could fix that, but it's too long already
:( Suggestions?
Possibly the best solution for vertical columns is to get the
Array::PrintCols module from CPAN, and use that:
perl -le 'print for 1..104' | perl -MArray::PrintCols -e '@a=<>; chomp
@a; print_cols \@a'
Yes, that's breaking the rules for one-liners - no modules (*everything*
can be done in one line if you've got CPAN!)
--
D.
More information about the Brisbane-pm
mailing list