Loading ...
Sorry, an error occurred while loading the content.

RE: [PBML] Printf formatting

Expand Messages
  • Bobby Jafari
    Thanks, I apologize for not looking in perldoc sprintf. (I only looked in perldoc printf) Its very clear and I now have : printf( FILEHANDLE Test Case : %-51s
    Message 1 of 3 , Oct 24, 2005
    • 0 Attachment
      Thanks, I apologize for not looking in perldoc sprintf. (I only looked
      in perldoc printf)

      Its very clear and I now have :

      printf( FILEHANDLE "Test Case : %-51s PASSED\n", $FileName);

      Regards,
      Bobby
      -----Original Message-----
      From: Randal L. Schwartz [mailto:merlyn@...]
      Sent: Tuesday, 25 October 2005 9:37
      To: Bobby Jafari
      Cc: perl-beginner@yahoogroups.com
      Subject: Re: [PBML] Printf formatting

      >>>>> "Bobby" == Bobby Jafari <bobby.jafari@...> writes:

      Bobby> Hi all,
      Bobby> printf ( FILEHANDLE "Test Case : %s PASSED\n" $FileName );

      Bobby> I need the printed line to always be 70 characters long. I need
      Bobby> PASSED to be right justified (i.e PASSED needs to be printed as
      Bobby> characters 65 to 70.) I looked up the printf manpage but I didn't

      Bobby> help much. Any idea's how this is done?

      $ perldoc -tf printf
      printf FILEHANDLE FORMAT, LIST
      printf FORMAT, LIST
      Equivalent to "print FILEHANDLE sprintf(FORMAT, LIST)",
      except
      that $\ (the output record separator) is not appended. The
      first
      argument of the list will be interpreted as the "printf"
      format.
      See "sprintf" for an explanation of the format argument.
      [...]
      $ perldoc -tf sprintf
      sprintf FORMAT, LIST
      [...]
      flags
      one or more of: space prefix positive number with a
      space +
      prefix positive number with a plus sign - left-justify
      within the field 0 use zeros, not spaces, to
      right-justify #
      prefix non-zero octal with "0", non-zero hex with "0x",
      non-zero binary with "0b"

      For example:

      printf '<% d>', 12; # prints "< 12>"
      printf '<%+d>', 12; # prints "<+12>"
      printf '<%6s>', 12; # prints "< 12>"
      printf '<%-6s>', 12; # prints "<12 >"
      printf '<%06s>', 12; # prints "<000012>"
      printf '<%#x>', 12; # prints "<0xc>"
      [...]

      What part of that 3rd example is not clear?

      --
      Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
      0095 <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
      Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
      See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
      training!
    Your message has been successfully submitted and would be delivered to recipients shortly.