Re: writing get_script as an external routine callable by C



In Dread Ink, the Grave Hand of Jürgen Exner Did Inscribe:

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

if ($s[0] =~ m/\d/) seems to work.


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

Thx. I'll take a look later.
--
Frank

If you put the two Bushs together in their over seven years of their two
presidencies, not one new job has been created. Numbers do not lie. If you
extrapolated from that, if the Bushs had run this country from its very
beginning to the current time, not one American would have ever worked.
We'd be hunter-gatherers.
~~ Al Franken, in response to the 2004 SOTU address
.



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 ... used as delimiters, therefore it doesn't show up in the FAQ. ... Case 2 matches if the beginning of the string is followed by 1 or more ...
    (comp.lang.perl.misc)
  • 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)
  • Problem with Function to Convert Number To Words
    ... It has following problem displaying for Unit and Tens Only for eg. ... Dim Rupees, Paisa As String ... Dim Hundred, Words As String ... ' Do we have a Hundred place digit to convert? ...
    (microsoft.public.excel)
  • Re: a challenge
    ... // if the remainder isn't zero. ... // recursively to convert it to a string ... // of the hundred's digit (there can be only ...
    (alt.lang.asm)