home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!sgigate!sgi!wdl1!wdl39!mab
- From: mab@wdl39.wdl.loral.com (Mark A Biggar)
- Newsgroups: comp.lang.perl
- Subject: Re: How to output % symbol in perl
- Message-ID: <1992Nov19.195334.3693@wdl.loral.com>
- Date: 19 Nov 92 19:53:34 GMT
- References: <1992Nov19.004813.16052@leland.Stanford.EDU>
- Sender: news@wdl.loral.com
- Distribution: usa
- Organization: Loral Western Development Labs
- Lines: 27
-
- In article <1992Nov19.004813.16052@leland.Stanford.EDU> donghao@leland.Stanford.EDU (dong hao zhang) writes:
- >Suppose we run a file like the following:
- >#! /usr/pubsw/bin/perl
- >printf STDOUT "\% A Latex Picture. \n";
- >The output of the above file is:
- >A Latex Picture.
- >instead of the desired: % A Latex Picture.
- >Any idea why the backslash does not protect the % symbol from
- >being interpreted ? And how may I output the % symbol with a perl script?
-
- Because, just like in C's printf() you should used %% to get a % on output.
- Besides \ interpretation happens before printf see the string so by that time
- the \ is already gone, just like the \n is already been turned into a real
- newline char. So either use:
-
- printf STDOUT "%% A Latex Picture. \n";
-
- or
-
- print STDOUT "% A Latex Picture. \n";
-
- The latter is more effecient anyway.
-
- --
- Perl's Maternal Uncle
- Mark Biggar
- mab@wdl1.wdl.loral.com
-