man Video::DVDRip::CPAN::Scanf () - emulate sscanf() of the C library


String::Scanf - emulate sscanf() of the C library


    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);


    # works only for Perl 5.005
    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 $_


String::Scanf supports scanning strings for data using formats similar to the libc/stdio sscanf().

The supported sscanf() formats are as follows:

Decimal integer, with optional plus or minus sign.
Decimal unsigned integer, with optional plus sign.
Hexadecimal unsigned integer, with optional 0x or 0x in front.
Octal unsigned integer. (The [efg] work identically.) Decimal floating point number, with optional plus or minus sign, in any of these formats:
The exponent has an optional plus or minus sign, and the CWe may also be CWE. The various borderline cases like CWInf and CWNan are not recognized.
A non-whitespace string.
A string of characters. An array reference is returned containing the numerical values of the characters.
A literal CW%.

The sscanf() formats [pnSC] are not supported.

The CW%s and CW%c have an optional maximum width, e.g. CW%4s, in which case at most so many characters are consumed (but fewer characters are also accecpted).

The numeric formats may also have such a width but it is ignored.

The numeric formats may have CW[hl before the main option, e.g. CW%hd, but since such widths have no meaning in Perl, they are ignored.

Non-format parts of the parameter string are matched literally (e.g. CW: matches as CW:), expect that any whitespace is matched as any whitespace (e.g. CW matches as CW\s+).


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, CW123e456789 is valid for CWsscanf(), but quite probably it won't fit into your Perl's numbers. Consider using the various Math::* modules instead.


Jarkko Hietaniemi <>

Copyright (c) 2002 Jarkko Hietaniemi. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.