in reply to Clever Padding
What kind of fixed field application do you have that would require padding with other than zero or space? Maybe you are asking how do deal with 12345 above? And the print should be '123' or '345'?#!/usr/bin/perl -w use strict; printf("%03d\n", 5); printf("%03d\n", 12345); __END__ Prints: 005 12345
I looked at your site reference http://www.comp.leeds.ac.uk/Perl/control.html#exercise and there is some really bogus advice there! Use chomp() to get rid of trailing LF or CR,LF, not chop()! chop() deletes the last char in the string no matter what it is! chomp() is conditional and only gets rid of trailing "new line" characters. In the case of Windows, chomp() will get rid of 2 characters (the CR and LF), on Unix only one (the LF) - in case of a simple string without any "new line" characters, nothing happens.
Anyway, please explain your application with something other than zero or space leading pad characters. That would be unusual and I'd like to understand it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Clever Padding (chomp, Win32)
by tye (Sage) on Jan 27, 2010 at 22:05 UTC | |
by ikegami (Patriarch) on Jan 27, 2010 at 23:07 UTC | |
by tye (Sage) on Jan 27, 2010 at 23:32 UTC | |
by ikegami (Patriarch) on Jan 27, 2010 at 23:49 UTC |