#!/usr/bin/perl -w # Strict use strict; use warnings; use Data::Dumper; # User defined my $text = " It's been said ever so often by many an expert that in ol' plain text one neer can get a round tuit, but just look here "; # Main program $text =~ s/(? text = [$text]\n"; # Show text $text =~ s/\s+//; # Strip all other spaces $text =~ s/\n/@/gs; # Convert newlines to '@' my @text = grep { /\S/ms } split //, $text; # Split text into characters # Find the mass of the diamond my $mass = (my $temp = $text) =~ s/\S/./g; print "Debug2> mass = [$mass]\n"; # Circle mass 'm' = pi * r^2, so the radius 'r' = sqrt(m / pi) my $radius = sqrt($mass / 3.14159265358); print "Debug3> radius = $radius\n"; # Format the text into a circle, my $circle = ""; my $aspect = 1.0; for (my $row = -($radius + 10); $row <= ($radius + 10); $row++) { for (my $col = -($radius + 10); $col <= ($radius + 10); $col++) { my $char = " "; if (($aspect * $row) ** 2 + $col ** 2 <= $aspect * ($radius ** 2)) { $char = shift @text || '*'; } $circle .= ($char eq '@'? ' ': $char); } $circle .= "\n"; } # Show the resulting circle print "$circle\n"; __END__ Output: Debug1> text = [ It's been@said ever@so@often by@many@an@expert that@in@ol'@plain@text one@neer@can@get@a round@tuit,@but just@look here ] Debug2> mass = [120] Debug3> radius = 6.18038723238067 It's be en said e ver so ofte n by many a n expert tha t in ol' pla in text one neer can get a round tu it, but ju st look here #### my $text = " This document is intended to give you a quick overview of the Perl programming language, along with pointers to further documentation. It is intended as a \"bootstrap\" guide for those who are new to the language, and provides just enough information for you to be able to read other peoples' Perl and understand roughly what it's doing, or write your own simple scripts. This introductory document does not aim to be complete. It does not even aim to be entirely accurate. In some cases perfection has been sacrificed in the goal of getting the general idea across. You are *strongly* advised to follow this introduction with more information from the full Perl manual, the table of contents to which can be found in perltoc. "; #### This docume nt is intended to give you a quic k overview of the Per l programming language, along with pointers to further documentation. It is intended as a "bootstrap " guide for those who are ne w to the language, and provid es just enough information fo r you to be able to read other peoples' Perl and understand roughly what it's doing, or wr ite your own simple scripts. This introductory document doe s not aim to be complete. It d oes not even aim to be entirel y accurate. In some cases per fection has been sacrificed i n the goal of getting the ge neral idea across. You are *strongly* advised to foll ow this introduction with more information from the full Perl manual, the table of conte nts to which can be found in p erltoc. #### This docume nt is intended to g ive you a quick overview of the Perl programming lan guage, along with pointers to f urther documentation. It is intend ed as a "bootstrap" guide for those who are new to the language, and pro vides just enough information for you to be able to read other peoples' Perl and understand roughly what it's doing, or write your own simple scripts. This introductory document does not aim to b e complete. It does not even aim to be entirely accurate. In some cases perfec tion has been sacrificed in the goal of getting the general idea across. You are *strongly* advised to follo w this introduction with more in formation from the full Perl manual, the table of conte nts to which can be fo und in perltoc.