Re: Padding a length of string

Arjen Laarhoven <[email protected]>
Newsgroups gmane.comp.lang.perl.fun
Message-ID <[email protected]>
Heya,

On Monday, 19 April 2004 at 15:05, Brian Morgan wrote:
> Hello all,
> Here is something that I have been playing with, and I am wondering if 
> it can be shortened at all.
> 
> The script is given a string that is shorter then a MAX length as well 
> as a special character. It
> then adds onto the end of the string the special character until the 
> length of the string is equal
> to MAX.
> 
> Here is my solution as an example of what I am talking about:
[snip]

6-fold compression of the main logic:

---
$max = $ARGV[0];
$key = $ARGV[1];
$pad_string = $ARGV[2];

$key .= $pad_string x ($max - length($key));

print $key;
---

Arjen

-- 
Arjen Laarhoven                         |
Email: [email protected]             |        
Web: http://www.laarhoven.info          | All that is gold does not glitter...
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.