1#!/usr/local/bin/perl 2# colwide 0.01 3# Copyright (c) 2014 Neel Chauhan <neel@neelc.org> 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGE (INCLUDING, BUT NOT LIMITED TO, 20# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 26use strict; 27my $char = "#"; 28my $defwidth = 80; 29 30sub wholenumerr { 31 print "\"@ARGV[0]\" is not a whole number\n"; 32 print "For colwide to work, you need to either:\n"; 33 print " * Specify a whole number in the arguments and print out the "; 34 print "specified amount \n"; 35 print " of characters based on the number defined\n"; 36 print " * Don't specify anything and default to 80 characters\n"; 37 exit(); 38} 39 40sub usage { 41 print "Usage: colwide [nochar]\n"; 42 print "[nochar] is optional. If specified, has to be a whole number\n"; 43 print "If [nochar] isn't specified, it will default to 80\n"; 44 exit(); 45} 46 47my $nochar; 48 49if (defined(@ARGV[0])) { 50 if (@ARGV[0] =~ m/^\d+\z/) { 51 $nochar = @ARGV[0]; 52 } 53 elsif (lc(@ARGV[0]) eq "help") { 54 usage(); 55 } 56 else { 57 wholenumerr(); 58 } 59} 60else { 61 $nochar = $defwidth; 62} 63 64for (my $oncol = 0; $oncol < $nochar; $oncol++) { 65 print $char; 66} 67 68print "\n"; 69