ActiveState!

ActivePerl Documentation
Table of Contents

(Usage Statistics)
(about this ver)


* Getting Started
    * Welcome To ActivePerl
    * Release Notes
    * Readme
    * ActivePerl Change Log
* Install Notes
    * Linux
    * Solaris
    * Windows
* ActivePerl Components
    * Overview
    * PPM
    * Windows Specifics
       * OLE Browser
       * PerlScript
       * Perl for ISAPI
       * PerlEZ
* ActivePerl FAQ
    * Introduction
    * Availability & Install
    * Using PPM
    * Docs & Support
    * Windows Specifics
       * Perl for ISAPI
       * Windows 9X/NT/2000
       * Quirks
       * Web Server Config
       * Web programming
       * Programming
       * Modules & Samples
       * Embedding & Extending
       * Using OLE with Perl
* Windows Scripting
    * Active Server Pages
    * Windows Script Host
    * Windows Script Components

Core Perl Documentation


* perl
* perlfaq
* perltoc
* perlbook

* perlsyn
* perldata
* perlop
* perlreftut
* perldsc
* perllol

* perllexwarn
* perldebug

* perlrun
* perlfunc
* perlopentut
* perlvar
* perlsub
* perlmod
* perlpod

* perlstyle
* perlmodlib
* perlmodinstall
* perltrap
* perlport
* perlsec

* perlref
* perlre
* perlform
* perllocale
* perlunicode

* perlboot
* perltoot
* perltootc
* perlobj
* perlbot
* perltie

* perlipc
* perlnumber
* perlfork
* perlthrtut

* perldiag
* perlfaq1
* perlfaq2
* perlfaq3
* perlfaq4
* perlfaq5
* perlfaq6
* perlfaq7
* perlfaq8
* perlfaq9

* perlcompile

* perlembed
* perlxstut
* perlxs
* perlguts
* perlcall
* perlfilter
* perldbmfilter
* perlapi
* perlintern
* perlapio
* perltodo
* perlhack

* perlhist
* perldelta
* perl5005delta
* perl5004delta

* perlamiga
* perlcygwin
* perldos
* perlhpux
* perlmachten
* perlos2
* perlos390
* perlvms
* perlwin32

Pragmas


* attributes
* attrs
* autouse
* base
* blib
* bytes
* charnames
* constant
* diagnostics
* fields
* filetest
* integer
* less
* lib
* locale
* lwpcook
* open
* ops
* overload
* perllocal
* re
* sigtrap
* strict
* subs
* utf8
* vars
* warnings

Libraries


* ActivePerl
    * DocTools
        * TOC
            * RDF
* AnyDBM_File
* Archive
    * Tar
* AutoLoader
* AutoSplit
* B
    * Asmdata
    * Assembler
    * Bblock
    * Bytecode
    * C
    * CC
    * Debug
    * Deparse
    * Disassembler
    * Lint
    * Showlex
    * Stackobj
    * Terse
    * Xref
* Benchmark
* Bundle
    * LWP
* ByteLoader
* Carp
    * Heavy
* CGI
    * Apache
    * Carp
    * Cookie
    * Fast
    * Pretty
    * Push
    * Switch
* Class
    * Struct
* Compress
    * Zlib
* Config
* CPAN
    * FirstTime
    * Nox
* Cwd
* Data
    * Dumper
* DB
* Devel
    * DProf
    * Peek
    * SelfStubber
* Digest
    * HMAC
    * HMAC_MD5
    * HMAC_SHA1
    * MD2
    * MD5
    * SHA1
* DirHandle
* Dumpvalue
* DynaLoader
* English
* Env
* Errno
* Exporter
    * Heavy
* ExtUtils
    * Command
    * Embed
    * Install
    * Installed
    * Liblist
    * MakeMaker
    * Manifest
    * Miniperl
    * Mkbootstrap
    * Mksymlists
    * MM_Cygwin
    * MM_OS2
    * MM_Unix
    * MM_VMS
    * MM_Win32
    * Packlist
    * testlib
* Fatal
* Fcntl
* File
    * Basename
    * CheckTree
    * Compare
    * Copy
    * CounterFile
    * DosGlob
    * Find
    * Glob
    * Listing
    * Path
    * Spec
        * Functions
        * Mac
        * OS2
        * Unix
        * VMS
        * Win32
    * stat
* FileCache
* FileHandle
* FindBin
* Font
    * AFM
* Getopt
    * Long
    * Std
* HTML
    * AsSubs
    * Element
    * Entities
    * Filter
    * Form
    * FormatPS
    * Formatter
    * FormatText
    * HeadParser
    * LinkExtor
    * Parse
    * Parser
    * TokeParser
    * TreeBuilder
* HTTP
    * Cookies
    * Daemon
    * Date
    * Headers
        * Util
    * Message
    * Negotiate
    * Request
        * Common
    * Response
    * Status
* I18N
    * Collate
* IO
    * Dir
    * File
    * Handle
    * Pipe
    * Poll
    * Seekable
    * Select
    * Socket
        * INET
        * UNIX
* IPC
    * Msg
    * Open2
    * Open3
    * Semaphore
    * SysV
* LWP
    * Debug
    * MediaTypes
    * MemberMixin
    * Protocol
    * RobotUA
    * Simple
    * UserAgent
* Math
    * BigFloat
    * BigInt
    * Complex
    * Trig
* MD5
* MIME
    * Base64
    * QuotedPrint
* NDBM_File
* Net
    * Cmd
    * Config
    * Domain
    * DummyInetd
    * FTP
    * hostent
    * libnetFAQ
    * netent
    * Netrc
    * NNTP
    * PH
    * Ping
    * POP3
    * protoent
    * servent
    * SMTP
    * SNPP
    * Time
* O
* ODBM_File
* Opcode
* Pod
    * Checker
    * Find
    * Html
    * InputObjects
    * Man
    * Parser
    * ParseUtils
    * Plainer
    * Select
    * Text
        * Color
        * Termcap
    * Usage
* POSIX
* PPM
    * SOAPClient
    * SOAPServer
* Safe
* SDBM_File
* Search
    * Dict
* SelectSaver
* SelfLoader
* SHA
* Shell
* SOAP
    * Defs
    * Envelope
    * EnvelopeMaker
    * GenericHashSerializer
    * GenericInputStream
    * GenericScalarSerializer
    * Lite
    * OutputStream
    * Packager
    * Parser
    * Transport
        * HTTP
            * Apache
            * CGI
            * Client
            * Server
        * LOCAL
        * MAILTO
        * POP3
        * TCP
    * TypeMapper
* Socket
* Symbol
* Sys
    * Hostname
    * Syslog
* Term
    * ANSIColor
    * Cap
    * Complete
    * ReadLine
* Test
    * Harness
* Text
    * Abbrev
    * ParseWords
    * Soundex
    * Tabs
    * Wrap
* Thread
    * Queue
    * Semaphore
    * Signal
    * Specific
* Tie
    * Array
    * Handle
    * Hash
    * RefHash
    * Scalar
    * SubstrHash
* Time
    * gmtime
    * Local
    * localtime
    * tm
* UDDI
    * Lite
* UNIVERSAL
* URI
    * data
    * Escape
    * file
    * Heuristic
    * ldap
    * URL
    * WithBase
* User
    * grent
    * pwent
* Win32
    * AuthenticateUser
    * ChangeNotify
    * Clipboard
    * Console
    * Event
    * EventLog
    * File
    * FileSecurity
    * Internet
    * IPC
    * Mutex
    * NetAdmin
    * NetResource
    * ODBC
    * OLE
        * Const
        * Enum
        * NEWS
        * NLS
        * TPJ
        * Variant
    * PerfLib
    * Pipe
    * Process
    * Registry
    * Semaphore
    * Service
    * Sound
    * TieRegistry
* Win32API
    * File
    * Net
    * Registry
* WWW
    * RobotRules
        * AnyDBM_File
* XML
    * Element
    * Parser
        * Expat
    * PPD
    * PPMConfig
    * ValidatingElement
* XSLoader

 sscanf - emulate the sscanf of the C stdio library


NAME

sscanf - emulate the sscanf() of the C stdio library


SUPPORTED PLATFORMS

  • Linux
  • Solaris
  • Windows
This module is not included with the standard ActivePerl distribution. It is available as a separate download using PPM.

SYNOPSIS

        use String::Scanf;      # this will import sscanf() into the
                                # current namespace
        @values = sscanf($scanf_format_string, $scalar_to_scan);
        # the default scan target is the $_
        @values = sscanf($scanf_format_string);
        # converting scanf formats to regexps (::format_to_re
        # is never exported to the current namespace)
        $regexp_string = String::Scanf::format_to_re($scanf_format_string);


DESCRIPTION

Perl sscanf() can be used very much like the C stdio sscanf(), for detailed sscanf() documentation please refer to your usual documentation resources. The supported formats are: [diuoxefgsc] and the character class [].

All of the format must match. If not, an empty list is returned and all the values end up empty.

The c format returns an anonymous list (see perlref) containing the numeric values of the characters it matched.

The ::format_to_re() function may be helpful if one wants to develop her own parsing routines.


FEATURES

Embedded underscores are accepted in numbers just like in Perl, even in octal/hexadecimal numbers (Perl does not currently support this). Please note the word embedded, not leading or trailing.

If the oh formats are used, the octal/hexadecimal interpretation is forced even without the leading 0 or 0x.


LIMITATIONS

Certain features of the C sscanf() are unsupported:

        * the formats C<[npSC]>
        * in the C<[efg]> formats the C<INF> and various C<NaN>s

The numeric formats are scanned in as strings, this meaning that numeric overflows may occur. For example: 1.2345e67890 will match the %g format but in most machines Perl cannot handle that large floating point numbers and bizarre values may end up in the Perl variable. Similar caveats apply for integer-type numbers. Results of such huge numbers (or very tiny numbers, say, 1.24345e-67890) are implementation-defined, which translates quite often as garbage. NOTE: if you really want Big numbers please consider using the Math::BigInt and Math::BigFloat, these packages come standard with Perl 5, or the Math::Pari package, available from CPAN.

For Perl <integers> and floating point numbers are the same thing. Also, the possible hl modifiers for the integers mean nothing: they are accepted but still they do nothing because Perl does not care about short/long integer differences.

The character class format is not so rigorously checked for correctness that an illegal character class definition could not be sneaked in. For example [z-a,X] is a bad example: perfectly illegal as a character class but String::Scanf will happily accept it. Beware.

The ::format_to_re() only does the scanf format -> regular expression conversion. It ignores tricky things like the c format (see above) and the %n$ argument reordering. If you want these, you may as well use the full ::sscanf().


EXAMPLES

        # business as usual
        ($i, $s, $x) = sscanf('%d %3s %g', ' -5_678     abc 3.14e-99 9');
        # 'skip leading whitespace': $x becomes 42 despite the leading space
        # 'the illegal character': $y becomes 'ab' despite the '3'
        # 'c' format: $z becomes [120 100], the numeric values of 'x'
        # and 'd' (assuming ASCII or ISO Latin 1)
        ($x, $y, $z) = sscanf('%i%3[a-e]%2c', ' 42acxde');
        # reordering the arguments: $a becomes 34, $b becomes 12
        ($a, $b) = sscanf('%2$d %1$d', '12 34');
        # converting scanf formats to regexps
        $re = String::Scanf::format_to_re('%x');

More examples in the test set t/scanf.t.


INTERNALS

The Perl sscanf() turns the C-stdio style sscanf() format string into a Perl regexp (see perlre) which captures the wanted values into submatches and returns the submatches as a list.

Originally written for purposes of debugging but also useful for educational purposes:

        String::Scanf::debug(1);        # turn on debugging: shows the regexps
                                # used and the possible reordering list
                                # and the character (%c) conversion targets
        String::Scanf::debug(0);                # turn off debugging
        print String::Scanf::debug(), "\n";     # the current debug status


VERSION

v1.1, $Id: Scanf.pm,v 1.8 1995/12/27 08:32:28 jhi Exp $


AUTHOR

Jarkko Hietaniemi, Jarkko.Hietaniemi@iki.fi

 sscanf - emulate the sscanf of the C stdio library