composer@chem.bu.edu (Jeff Kellem) (01/30/91)
In article <090557.28625@timbuk.cray.com> eric@redwood06.cray.com (Eric Markwardt) writes: > Date: 29 Jan 91 15:29:20 GMT > > I'm trying to get the current time displayed as part of part of > my page header -- something like: > > format pageheader = > The time is @>:@> > $hour, $min > . > > I can't seem to get the leading zeros to print if needed (i.e. I get > 'The time is 4: 5', rather than 04:05). > > Is it possible to do this in a format, or do I need to mess around with > using printf to create a correctly formatted string, which I then can > use in the format? Off hand, I don't believe it's possible with just the format. My mind could be missing something. ;-) You can kludge it a tiny bit, using sprintf with something like.. format pageheader = The time is @<<< $time . $time = sprintf("%02d:%02d", $hour, $min); then, do whatever else you want .. along with your `write'. Cheers... -jeff Jeff Kellem Internet: composer@chem.bu.edu
roger@gtisqr.uucp (Roger Droz) (02/06/91)
In article <COMPOSER.91Jan29110249@chem.bu.edu> composer@chem.bu.edu writes: >In article <090557.28625@timbuk.cray.com> eric@redwood06.cray.com (Eric Markwardt) writes: > > Date: 29 Jan 91 15:29:20 GMT > > > > I'm trying to get the current time displayed as part of part of > > my page header -- something like: > > > > format pageheader = > > The time is @>:@> > > $hour, $min > > . > > > > Is it possible to do this in a format, or do I need to mess around with > > using printf to create a correctly formatted string, which I then can > > use in the format? > >You can kludge it a tiny bit, using sprintf with something like.. > > format pageheader = > The time is @<<< > $time > . > > $time = sprintf("%02d:%02d", $hour, $min); > I'm not sure this trick is even between the lines in the man page, but I have had success using expressions (including subroutine calls) in formats: format pageheader = This time is @<<<< sprintf("%-2.2d:%-2.2d", $hour, $min) . I'm not a fan of using undocumented features, so I'd like the official blessing of the Gurus before continuing to use expressions in formats. ____________ Roger Droz () () Maverick International / Global Technology International (_______) Mukilteo, WA ( ) | | Disclaimer: "We're all mavericks here: | | Each of us has our own opinions, (___) and the company has yet different ones!" Internet: roger@mav.COM UUCP: uw-beaver!gtisqr!roger
lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (02/06/91)
In article <1991Feb05.223438.15456@gtisqr.uucp> roger@gtisqr.uucp (Roger Droz) writes:
: I'm not sure this trick is even between the lines in the man page, but I
: have had success using expressions (including subroutine calls) in
: formats:
:
: format pageheader =
: This time is @<<<<
: sprintf("%-2.2d:%-2.2d", $hour, $min)
: .
:
: I'm not a fan of using undocumented features, so I'd like the official
: blessing of the Gurus before continuing to use expressions in formats.
It's documented as legal in the book.
Larry