RE: Padding a length of string
"Impson, Jeremy" <[email protected]>
| Newsgroups | gmane.comp.lang.perl.fun |
|---|---|
| Message-ID | <[email protected]> |
This may not be fun for most FWP regulars, but we should keep in mind that "fun" is subjective, and I expect that for many of us it was doing stuff like this that made us realize that Perl can be fun way back when. $max = $ARGV[0]; $key = $ARGV[1]; $pad_string = $ARGV[2]; $key .= $pad_string while (length $key < $max); Or just $ARGV[1] .= $ARGV[2] while (length $ARGV[1] < $ARGV[0]); Now I'll sit back and watch the golf pros have a go. -- Jeremy Impson Senior Network Security Engineer Lockheed Martin Systems Integration-Owego email: [email protected] phone: 607 751 5618 cell: 607 765 7630 fax: 607 751 6025 -----Original Message----- From: Brian Morgan [mailto:[email protected]] Sent: Monday, April 19, 2004 3:05 PM To: [email protected] Subject: Padding a length of string 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: #BEGIN EXAMPLE $max = $ARGV[0]; $key = $ARGV[1]; $pad_string = $ARGV[2]; @key_chars = split(//, $key); $count = $#key_chars + 1; while ($count <= $max){ $key .= $pad_string; $count++; } print $key; #END EXAMPLE So can anyone out there compress this down? I can't wait to see the results. Thanks, Brian