Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

What does this statement do?

by Fian7 (Initiate)
on Jun 10, 2010 at 22:23 UTC ( #844137=perlquestion: print w/ replies, xml ) Need Help??
Fian7 has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I am trying to read a PERL program, and the following line has me confused - what is it trying to do? unless ($nth =~ /^+-?\d+$/ ) { ##Removed this code to make things simpler## }

Comment on What does this statement do?
Re: What does this statement do?
by choroba (Abbot) on Jun 10, 2010 at 22:52 UTC
    Welcome to the Monastery, Fian7. Please, read and try to follow the basic rules: Markup in the Monastery. Also note there is nothing called PERL here, the language is "Perl" and the interpreter is "perl".
    Concerning the code, it should have probably been:
    unless ($nth =~ /^[+-]?\d+$/ ) { ##Removed this code to make things si +mpler## }
    unless means if not (see perlsyn).
    The =~ operator matches (see perlop) the variable $nth against a regular expression, enclosed in slashes.
    To match, a string can (hence ?) start with a plus or minus sign, then it should have one or more (hence +) digits (\d) and nothing more ($).
Re: What does this statement do?
by linuxer (Deacon) on Jun 10, 2010 at 22:56 UTC
    The regular expression can be explained, e.g.:

    Documentation: perlretut perlre


Re: What does this statement do?
by aquarium (Curate) on Jun 10, 2010 at 23:45 UTC
    I'd (wildly) guess that this is part of a routine that handles numbers with the code provided executing the block of code only when there is not a valid exponent. An exponent is (typically) such a simple number as that being matched, a signed or unsigned (+/-) integer.
    the hardest line to type correctly is: stty erase ^H

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://844137]
Approved by toolic
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
As of 2014-07-14 09:00 GMT
Find Nodes?
    Voting Booth?

    When choosing user names for websites, I prefer to use:

    Results (257 votes), past polls