home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / perl / 7062 < prev    next >
Encoding:
Internet Message Format  |  1992-11-19  |  1.3 KB

  1. Path: sparky!uunet!olivea!sgigate!sgi!wdl1!wdl39!mab
  2. From: mab@wdl39.wdl.loral.com (Mark A Biggar)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: How to output % symbol in perl
  5. Message-ID: <1992Nov19.195334.3693@wdl.loral.com>
  6. Date: 19 Nov 92 19:53:34 GMT
  7. References: <1992Nov19.004813.16052@leland.Stanford.EDU>
  8. Sender: news@wdl.loral.com
  9. Distribution: usa
  10. Organization: Loral Western Development Labs
  11. Lines: 27
  12.  
  13. In article <1992Nov19.004813.16052@leland.Stanford.EDU> donghao@leland.Stanford.EDU (dong hao zhang) writes:
  14. >Suppose we run a file like the following:
  15. >#! /usr/pubsw/bin/perl
  16. >printf STDOUT "\% A Latex Picture. \n";
  17. >The output of the above file is:
  18. >A Latex Picture. 
  19. >instead of the desired: % A Latex Picture.
  20. >Any idea why the backslash does not protect the % symbol from 
  21. >being interpreted ? And how may I output the % symbol with a perl script?
  22.  
  23. Because, just like in C's printf() you should used %% to get a % on output.
  24. Besides \ interpretation happens before printf see the string so by that time
  25. the \ is already gone, just like the \n is already been turned into a real
  26. newline char. So either use:
  27.  
  28. printf STDOUT "%% A Latex Picture. \n";
  29.  
  30. or
  31.  
  32. print STDOUT "% A Latex Picture. \n";
  33.  
  34. The latter is more effecient anyway.
  35.  
  36. --
  37. Perl's Maternal Uncle
  38. Mark Biggar
  39. mab@wdl1.wdl.loral.com
  40.