Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: non numeric data

by derby (Abbot)
on Jun 24, 2013 at 12:53 UTC ( [id://1040427]=note: print w/replies, xml ) Need Help??


in reply to non numeric data

I would assume your data is not what you think it is:

#!/usr/bin/env perl use strict; use warnings; my @array_H = ( 'ABCD', 1234, '1234', ' 1234' ); foreach my $ele ( @array_H ) { if( $ele !~ /^[0-9]+$/ ) { block( $ele ); } } sub block { my $ele = shift; print "Woot -- $ele --\n"; }
--
Woot -- ABCD -- Woot -- 1234 --

-derby

Replies are listed 'Best First'.
Re^2: non numeric data
by torres09 (Acolyte) on Jun 24, 2013 at 13:00 UTC

    ya i figured that out , there is a possibility that numbers having - sign are not being blocked so I modified by code . please tell if it is fine or not

    if (($array_H[$i] !~ /^[0-9]+$/) &&($array_H[$i] !~ /^-+$/))

    I am new to perl so please pardon me for obvious mistakes

      Depending on the source of your data, it may have whitespace (especially a newline) at the end.
      Bill

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1040427]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-25 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found