Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: outputting fun

by Corion (Patriarch)
on Aug 29, 2000 at 19:47 UTC ( [id://30154]=note: print w/replies, xml ) Need Help??


in reply to outputting fun

Here's my try at it. It uses two forms of string replacement - one transliteration, replacing every G with a space, and one regular expression, replacing a single character, followed by one or more spaces and then that character again, with two more spaces.

#!/usr/bin/perl -w use strict; my $line; print( $line = join( "", ('A' .. 'G'), reverse ( 'A'..'F' )), "\n" ); $line =~ tr/G/ /; print( $line, "\n" ); while ($line !~ /^\s+$/) { $line =~ s/(\S)(\s+)\1/ $2 /; print( $line, "\n"); };
This is obviously not the smallest possible code, but a bit more Perlish and elegant (IMholyO) :-)

Replies are listed 'Best First'.
RE: Re: outputting fun
by lindex (Friar) on Aug 30, 2000 at 11:55 UTC
    Just would like to say that Iam a wingnut :)
    for(my($c)=71,my($i)=0; $c >= 65; $c--,$i++) { print ( (chr(65)..chr($c)), (' 'x($i+($i-1))), reverse(chr(65)..chr(($c==71)? $c-1 : $c)), "\n" ); }
    p.s. I broke it into multi-line so that it was readable :)



    lindex
    /****************************/ jason@gost.net, wh@ckz.org http://jason.gost.net /*****************************/
Re: Re: outputting fun
by stefp (Vicar) on Mar 28, 2001 at 00:10 UTC
    There is the obvious
    print <<EOF; ABCDEFGFEDCBA ABCDEF FEDCBA ABCDE EDCBA ABCD DCBA ABC CBA AB BA A A EOF
    How about?
    $a = "ABCDEFGFEDCBA\n"; print($a), substr($a, 7-$_, 2*$_-1) = " " ." " x ($_-1) for 1..7
    -- stef

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://30154]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-03-19 03:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found