Re: writing get_script as an external routine callable by C
- From: Jürgen Exner <jurgenex@xxxxxxxxxxx>
- Date: Thu, 14 May 2009 20:00:55 -0700
Franken Sense <frank@xxxxxxxxxxxxxxx> wrote:
Ok, here comes your last fish.
I _STRONGLY_ suggest to attend a Perl class or a self-study course where
you can learn the fundamentals of Perl in a structured and comprehensive
way instead of digging for random bits and pieces while trying to
implement some program.
In Dread Ink, the Grave Hand of Jürgen Exner Did Inscribe:[...]
Franken Sense <frank@xxxxxxxxxxxxxxx> wrote:
Where I'm hung up now is in creating a control that separates comments from
scriptures. Scriptures begin with numbers, comments don't. So I was
poking around for a function like isdigit and couldn't find anything.
perldoc -q number:
How do I determine whether a scalar is a number/whole/integer/float?
How do I determine whether a scalar is a number/whole/integer/float?
Assuming that you don't care about IEEE notations like "NaN" or
Yeah, I know the answer to that FAQ, there is no need to quote
paragraphs and paragraphs of it.
So, I want to test whether the first byte is a digit.
No, you probably don't. In all likelyhood you want to check if the first
character is a digit. Characters and bytes can be very different things.
I think this is
/\d/. The sad thing is that I can't even put it together at this point.
That's why I strongly recommend a more structured approach to your
learning endeavour.
I have @s populated in paragraph mode and then split. How does the test
condition look with these two: s[0] /\d/ ?
if (s[0] is a number)
If you mean "begins with a digit" as you said above
if ($s[0] =~ m/^\d/)
If you mean "is a number" as you are saying now
if ($s[0] =~ m/^\d+$/) #all characters are digits
or
if (! $s[0] =~ m/\D/) #does not contain any non-digits
Deciphering:
The m-operator is the match operator. It can be omitted if slashes are
used as delimiters, therefore it doesn't show up in the FAQ. I still
prefer to write it sometimes because it makes the program logic more
obvious.
Normally the m (and the s) operator will use $_. If you want them to
operate on a different variable instead, then you need to bind that
variable to the operation, which is achieved by the =~ operator.
And the argument of m is a regular expression, in this case delimited by
slashes:
Case 1 matches if the beginning of the string is followed by a digit
Case 2 matches if the beginning of the string is followed by 1 or more
digits followed by the end of the string.
Case 3 matches if the string contains (at least) one non-digit.
For further details see "perldoc perlretut" and "perldoc perlre".
jue
.
- Follow-Ups:
- Re: writing get_script as an external routine callable by C
- From: Franken Sense
- Re: writing get_script as an external routine callable by C
- References:
- writing get_script as an external routine callable by C
- From: Franken Sense
- Re: writing get_script as an external routine callable by C
- From: Ben Morrow
- Re: writing get_script as an external routine callable by C
- From: Franken Sense
- Re: writing get_script as an external routine callable by C
- From: Ben Morrow
- Re: writing get_script as an external routine callable by C
- From: Jürgen Exner
- Re: writing get_script as an external routine callable by C
- From: Franken Sense
- Re: writing get_script as an external routine callable by C
- From: Jürgen Exner
- Re: writing get_script as an external routine callable by C
- From: Franken Sense
- writing get_script as an external routine callable by C
- Prev by Date: Re: Launching 2 background processes with fork - how to make wait() work?
- Next by Date: Re: How to replace c:\Program Files with Program Files (x86) in all scripts?
- Previous by thread: Re: writing get_script as an external routine callable by C
- Next by thread: Re: writing get_script as an external routine callable by C
- Index(es):
Relevant Pages
|