Re: Quoting non-numbers

From: Ben Morrow (usenet_at_morrow.me.uk)
Date: 03/11/04


Date: Thu, 11 Mar 2004 01:07:03 +0000 (UTC)


Quoth anno4000@lublin.zrz.tu-berlin.de (Anno Siegel):
> Ben Morrow <usenet@morrow.me.uk> wrote in comp.lang.perl.misc:
> >
> > Quoth "John W. Krahn" <krahnj@acm.org>:
> > >
> >
> > {
> > no warnings 'numeric';
> >
> > > s/(\S+)/ $1 eq $1 + 0 ? $1 : "'$1'" /eg;
> >
> > }
>
> That quotes 1.0. Not to mention leading zeros.
>
> I have been using the "+ 0" test in this form:
>
> sub is_num {
> use warnings FATAL => 'numeric';
> no warnings 'void';
> eval { shift + 0 };
> not $@;
> }
>
> That reflects Perl's opinion about a string being a number, but it doesn't
> inline easily.

If you're going to do that, you might as well use
Scalar::Util::looks_like_number, which I'd imagine would be somewhat
faster.

Ben

-- 
It will be seen that the Erwhonians are a meek and long-suffering people,
easily led by the nose, and quick to offer up common sense at the shrine of
logic, when a philosopher convinces them that their institutions are not based 
on the strictest morality.  [Samuel Butler, paraphrased]       ben@morrow.me.uk


Relevant Pages

  • Re: FieldInfo Class - SetValue Member Method
    ... > End Sub ... > ByVal fldname As String, ... > Public Class testing ... > opinion to use endless late binding, what can in my opinion only lead to the ...
    (microsoft.public.dotnet.languages.vb)
  • Re: How to Force Field Size
    ... will not *store* leading zeros, ... Public Function LeftPadToLength(strVal As String, intLength As Integer, ... I have decided to change my numbers into the 10 digits ... >>End Sub ...
    (microsoft.public.access.modulesdaovba)
  • Re: Formula to consolidate numbers?
    ... everytime the problem happens, are leading zeros involved, right? ... Function returnConnection(strValue As String, Plus As Boolean) As ... Dim a As Double ... at the beginning and end of sub main, ...
    (microsoft.public.excel.misc)
  • Re: FieldInfo Class - SetValue Member Method
    ... Public Sub starttest() ... ByVal fldname As String, ByVal value As Object) ... Public Class testing ... opinion to use endless late binding, what can in my opinion only lead to the ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Quoting non-numbers
    ... That quotes 1.0. ... Not to mention leading zeros. ... That reflects Perl's opinion about a string being a number, ...
    (comp.lang.perl.misc)