in reply to Re^3: Printing a hollow square of Asterisks
in thread Printing a hollow square of Asterisks

hey thanks for this.. but i cant seem to run this code..
  • Comment on Re^4: Printing a hollow square of Asterisks

Replies are listed 'Best First'.
Re^5: Printing a hollow square of Asterisks
by Anonymous Monk on Mar 04, 2009 at 15:45 UTC
Re^5: Printing a hollow square of Asterisks
by ww (Archbishop) on Mar 04, 2009 at 18:58 UTC

    possible mis-use of single-quoting if you are on W32? Or, try:

    #!/usr/bin/perl -l use strict; use warnings; my $n = shift; # assign the number provided as an argue +ment to $n die q{Please provide a positive number.} if ($n < 0); # not negative print q{*} x $n; # print "*" $n times followed by newline +(the shebang's -l switch if ($n >1) { foreach (2 .. $n - 1) { # print second line .. next +to last line print q{*}, q{ } x ($n - 2), q{*}; # with $n-2 spaces (first & +last postions are * } print "*" x $n ; }

    Tested on *nix and W2k