Printing in format statments using e/g format 
Author Message
 Printing in format statments using e/g format

How do I use the write/format stemnet to print out a real number using
either g or e format?  The following example prints the wrong thing.

#!/usr/local/bin/perl

$# = "%.7e";

$r = 1.234e-12;

$~ = fmt;

write;


$r
 .

--

Thermal Control & Life Support Division (YC)
European Space Research and Technology Centre (ESTEC),
Noordwijk, The Netherlands.



Mon, 21 Oct 1996 21:16:08 GMT  
 Printing in format statments using e/g format
:
: How do I use the write/format stemnet to print out a real number using
: either g or e format?  The following example prints the wrong thing.
:
: #!/usr/local/bin/perl
:
: $# = "%.7e";
:
: $r = 1.234e-12;
:
: $~ = fmt;
:
: write;
:
: format fmt =

: $r
:  .

Either use printf directly, or if you really want to use a format, say

    format STDOUT =

    sprintf("%.e", $r)
    .

$# comes highly UNrecommended.  It's just there to help the awk-to-perl
translator.

Larry



Wed, 23 Oct 1996 23:48:58 GMT  
 Printing in format statments using e/g format

Quote:

>$# comes highly UNrecommended.  It's just there to help the awk-to-perl
>translator.

It's very useful, though. Is there any chance of a replacement?
Something hooked in wherever floats are converted to strings would
be more complete than $#. Why is the latter deprecated, anyhow?

Anthony

--
AJR Heading, Defence Research Agency, St. Andrews Road, Great Malvern, UK



Thu, 24 Oct 1996 00:22:13 GMT  
 Printing in format statments using e/g format


: >$# comes highly UNrecommended.  It's just there to help the awk-to-perl
: >translator.
:
: It's very useful, though. Is there any chance of a replacement?
: Something hooked in wherever floats are converted to strings would
: be more complete than $#. Why is the latter deprecated, anyhow?

The main problem is that it can change the semantics of unsuspecting
library routines, up to and including blowing them out of the water.
Hooking this into where floats are converted to strings would only
make this worse.

$[ is deprecated for similarly insidious reasons.

Larry



Sat, 26 Oct 1996 03:03:43 GMT  
 Printing in format statments using e/g format

Quote:

>The main problem is that it can change the semantics of unsuspecting
>library routines, up to and including blowing them out of the water.
>Hooking this into where floats are converted to strings would only
>make this worse.

>$[ is deprecated for similarly insidious reasons.

Ah. Yes, I suppose it might. What if a new version were given lexical
scope? I assume separate files are different lexical scopes a la C
statics, so most library routines could be protected.

I remember now the proposal that $[ could become a compiler
directive. The same sort of arguments hold, I imagine. Did that
get blown out the water because of backward compatibility problems?
And if so, would a spangly new pragma help?

Anthony
--
AJR Heading, Defence Research Agency, St. Andrews Road, Great Malvern, UK



Sun, 27 Oct 1996 09:08:56 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Massively confused about format statments!!!!!!

2. Using formats, way to avoid exact formatting???

3. using a format to print out a #comment

4. printing using the Format function

5. printing report using format

6. Printing table cells using "format"

7. FORMAT: printing non-printing characters

8. ANNOUNCE: IO::Format 0.02 (perl formats, object oriented, footers)

9. Converting from ctime format to time_t format

10. Perl manual (Emacs info-mode format?, NG format)

11. PERLFUNC: format - declare a picture format with use by the write() function

12. PERLFUNC: format - declare a picture format with use by the write() function

 

 
Powered by phpBB® Forum Software