.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "String::Scanf 3pm" .TH String::Scanf 3pm "2022-10-22" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" String::Scanf \- emulate sscanf() of the C library .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use String::Scanf; # imports sscanf() \& \& ($a, $b, $c, $d) = sscanf("%d+%d %f\-%s", $input); \& ($e, $f, $g, $h) = sscanf("%x %o %s:%3c"); # input defaults to $_ \& \& $r = String::Scanf::format_to_re($f); .Ve .PP or .PP .Vb 2 \& # works only for Perl 5.005 or later \& use String::Scanf qw(); # import nothing \& \& my $s1 = String::Scanf\->new("%d+%d %f\-%s"); \& my $s2 = String::Scanf\->new("%x %o %s:%3c"); \& \& ($a, $b, $c, $d) = $s1\->sscanf($input); \& ($e, $f, $g, $h) = $s2\->sscanf(); # input defaults to $_ .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" String::Scanf supports scanning strings for data using formats similar to the libc/stdio \fBsscanf()\fR. .PP The supported \fBsscanf()\fR formats are as follows: .ie n .IP "%d" 4 .el .IP "\f(CW%d\fR" 4 .IX Item "%d" Decimal integer, with optional plus or minus sign. .ie n .IP "%u" 4 .el .IP "\f(CW%u\fR" 4 .IX Item "%u" Decimal unsigned integer, with optional plus sign. .ie n .IP "%x" 4 .el .IP "\f(CW%x\fR" 4 .IX Item "%x" Hexadecimal unsigned integer, with optional \*(L"0x\*(R" or \*(L"0x\*(R" in front. .ie n .IP "%o" 4 .el .IP "\f(CW%o\fR" 4 .IX Item "%o" Octal unsigned integer. .ie n .IP "%e %f %g" 4 .el .IP "\f(CW%e\fR \f(CW%f\fR \f(CW%g\fR" 4 .IX Item "%e %f %g" (The [efg] work identically.) .Sp Decimal floating point number, with optional plus or minus sign, in any of these formats: .Sp .Vb 8 \& 1 \& 1. \& 1.23 \& .23 \& 1e45 \& 1.e45 \& 1.23e45 \& .23e45 .Ve .Sp The exponent has an optional plus or minus sign, and the \f(CW\*(C`e\*(C'\fR may also be \f(CW\*(C`E\*(C'\fR. .Sp The various borderline cases like \f(CW\*(C`Inf\*(C'\fR and \f(CW\*(C`Nan\*(C'\fR are not recognized. .ie n .IP "%s" 4 .el .IP "\f(CW%s\fR" 4 .IX Item "%s" A non-whitespace string. .ie n .IP "%c" 4 .el .IP "\f(CW%c\fR" 4 .IX Item "%c" A string of characters. An array reference is returned containing the numerical values of the characters. .IP "%%" 4 A literal \f(CW\*(C`%\*(C'\fR. .PP The \fBsscanf()\fR formats [pnSC] are not supported. .PP The \f(CW%s\fR and \f(CW%c\fR have an optional maximum width, e.g. \f(CW%4s\fR, in which case at most so many characters are consumed (but fewer characters are also accecpted). .PP The numeric formats may also have such a width but it is ignored. .PP The numeric formats may have \f(CW\*(C`[hl]\*(C'\fR before the main option, e.g. \f(CW%hd\fR, but since such widths have no meaning in Perl, they are ignored. .PP Non-format parts of the parameter string are matched literally (e.g. \f(CW\*(C`:\*(C'\fR matches as \f(CW\*(C`:\*(C'\fR), expect that any whitespace is matched as any whitespace (e.g. \f(CW\*(C` \*(C'\fR matches as \f(CW\*(C`\es+\*(C'\fR). .SH "WARNING" .IX Header "WARNING" The numeric formats match only something that looks like a number, they do not care whether it fits into the numbers of Perl. In other words, \f(CW123e456789\fR is valid for \f(CW\*(C`sscanf()\*(C'\fR, but quite probably it won't fit into your Perl's numbers. Consider using the various Math::* modules instead. .SH "AUTHOR, COPYRIGHT AND LICENSE" .IX Header "AUTHOR, COPYRIGHT AND LICENSE" Jarkko Hietaniemi .PP Copyright (c) 2002,2004 Jarkko Hietaniemi. All rights reserved. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.