Re: Padding a length of string

John Douglas Porter <[email protected]>
Newsgroups gmane.comp.lang.perl.fun
Message-ID <[email protected]>
Arjen Laarhoven <[email protected]> wrote:
> $max = $ARGV[0];
> $key = $ARGV[1];
> $pad_string = $ARGV[2];
> 
> $key .= $pad_string x ($max - length($key));
> print $key;

That's pretty much the canonical example. Only thing I'd do
is twink around with the rigging, e.g.

  my( $max, $key, $pad ) = @ARGV;
  print $key, $pad x ($max - length($key));

My own thoughts tend toward the following:

  $_ = $pad x $max;
  substr( $_, 0, length($key) ) = $key;
  print;

But I can't shake the feeling that that second line
could be shortened, perhaps by using s/// cleverly...

-- 
John Douglas Porter



	
		
__________________________________
Do you Yahoo!?
Yahoo! Photos: High-quality 4x6 digital prints for 25¢
http://photos.yahoo.com/ph/print_splash
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.