Re: writing get_script as an external routine callable by C



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
.



Relevant Pages

  • Re: writing get_script as an external routine callable by C
    ... I _STRONGLY_ suggest to attend a Perl class or a self-study course where ... If you mean "begins with a digit" as you said above ... Case 2 matches if the beginning of the string is followed by 1 or more ... If you put the two Bushs together in their over seven years of their two ...
    (comp.lang.perl.misc)
  • Re: VBA Code for converting Type-E UPC to Type-A (barcodes)
    ... Function IsNumber(ByVal Value As String) As Boolean ... ' Get local setting for decimal point ... following code input the result of a Type-A UPC into B5 & the skip digit into ... UPCEString$ = UPCE ...
    (microsoft.public.excel.programming)
  • Re: Sorted Fixed Length String
    ... >I have a String of Numerical Digits Created Using Concatenate. ... >The Strings could be from 6 Characters in Length to 11 Characters in ... >The Least Characters in a String with a Digit GREATER than 1 can ONLY be ... Dim str As String ...
    (microsoft.public.excel.programming)
  • Re: Pi as the Mother Number
    ... For example if we find our 100-digit string starting at the ... 37th digit of pi, we can just say, go to the 37th digit of pi and print the ... problem with using this principle to compress numbers is the problem of the ... Foundation of Mathematics, first to understand the difference between ...
    (sci.math)