Re: sprintf format question
[email protected] (April)
| Newsgroups | perl.beginners |
|---|---|
| Organization | http://groups.google.com |
| Message-ID | <48055032-4e26-45e1-a9af-ec274bf673a9@t54g2000hsg.googlegroups.com> |
On Jun 4, 8:00 am, [email protected] (Rob Dixon) wrote: > April wrote: > > sprintf( "%s%$Fmt%s", ("%$Fmt=|", $TestStr, "|")) > > > This is in Perl for Dummies, 4th ed, p160. > > > I'm trying to understand this ... > > > the first part, "%s%$Fmt%s", my understanding is the format part, > > which specifies the formats for the second part, thelist part, ("% > > $Fmt=|", $TestStr, "|"): %s for "%$Fmt=|", %$Fmt for $TestStr, and %s > > for "|", respectively. Is this correct? > > > Then what is %$Fmt, it seems a % for format and then a variable $Fmt, > > the book did not mention any format string like this ... > > > Anyone can shed some light? Thanks! > > Hi April > > The value of $Fmt will be interpolated into the double-quoted sting before it is > used as a format. It needs to be one of the single-character format conversion. > If you're not clear what I mean then try running this piece of code. > > for my $Fmt ('s', 'd') { > print "%s%$Fmt%s", "\n"; > > } > > HTH, > > Rob- Hide quoted text - > > - Show quoted text - I understand now Rob, thanks!