Perl: repeated text
Tutoring Perl programming, you are aware of so many little tricks Perl contains for doing specific tasks. The tutor shares a fun one.
I recall, when I was a kid, a common trick to show off was to fill up the computer screen with your name. A kid with a little programming instruction could easily do it; a kid with no knowledge of programming, had no hope of pulling it off.
At the time, I had no knowledge of programming. However, I saw a kid do the trick on a Commodore Vic-20 (I’m really showing my age here). For years I wondered how he did it.
The kid likely did it in BASIC; Perl wasn’t even invented then. However, I’ll show how it’s done in Perl:
#!/usr/bin/perl
$name=”Johnny Smith! ” x100;
# the x100 means repeat the name 100 times
print “$name”;
Of course, you could replace x100 with x500 or whatever. Don’t overdo it; you just want to fill the screen, right?:)
I might start coverage of BASIC; it’s a fun language. If I recall correctly, I think it uses dollar signs in front of variables the way Perl does. It’s been awhile.
Source: McGrath, Mike. Perl in easy steps. Warwickshire, UK: Computer Step, 2004.
Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.