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

[FWP] Sideways Perl



Perl is great.  However, I'm sure that all of you have been annoyed at the
fact that it forces you to write from left to right instead of top to
bottom.

To remedy this situation, here's a perl program that lets you write your
programs
lt
ih
ki
es
 .

Call it like
  perl -w updown myscript

=cut=
#!/usr/local/bin/perl5 -w
use strict;
my(@file, $maxlen, @lines);

$maxlen = 0;
while (<>) { # note: considers all input to be one big file
	chomp;
	push @file, $_;
	length > $maxlen and $maxlen = length;
}

for (my $i = 0; $i < $maxlen; $i++) {
	my $cur = '';
	for (@file) {
		if (length $_ < $i + 1) {
			$cur .= ' ';
		} else {
			$cur .= substr($_, $i, 1);
		}
	}
	$cur .= "\n";
	push @lines, $cur;
}

for (@lines) { s/ *$// }
eval join '', @lines;
=cut=

To get you started, here's a sideways perl script to print random city names:
=cut=
ummmm f						}
syyyy om$m$mp
e     rysysyr
 $@@@   1 2 i
saCVE m$ $ $n
tm    ys.s.st
ro===  1=2=3
iu    $     u
cnqqq c=$ $ c
ttwww o V=V=f
; /// u$[ [ i
 =bat nCi$i$r
    o t[nCnEs
 3cen  it[t[t
 0    (n(i(i
 ;gyb 1trnrn$
    u .(atats
  cor .rn(n(1
  h g $adrdr,
   i  an(a(a
  g/l md$n$n$
  r;e o(#d#ds
    t u$V(V(2
  d   n# $ $,
    f tC+#+#
  g o )  C E$
  l r  +1 1 s
    d { )+)+3
  f    1) ) ,
  / v  )]1]1
  ; i  ););)"
    l  ] ) )\
    l  ; ] ]n
    e    ; ;"
            ;
    d
    a
    l
    e
    /
    ;
=cut=

BUGS:
among other things, it's a little hard to get command line args to the
updownperl program.

I hope you all find this useful in your sideways Perl endeavours!

--David Glasser

glasser@iname.com



==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe