Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: perl typecasting

by jrtayloriv (Pilgrim)
on Feb 05, 2008 at 07:08 UTC ( #666231=note: print w/replies, xml ) Need Help??

in reply to perl typecasting

Regexp::Common does this nicely:

use Regexp::Common; # get your $data ... if ($data ~= /$RE{num}{int}/){ print "It's an integer\n"; }

Replies are listed 'Best First'.
Re^2: perl typecasting
by perl_junkie (Acolyte) on Feb 05, 2008 at 18:28 UTC
    TGI, I really appreciate you taking time off to review my code. Thanks..!!!

    I am working on my regex skills now. I should get better at it in the coming weeks.

    The variables I have not defined are globals.. sorry I should have mentioned that... Your code looks much cleaner and easier to debug than mine...!!!! Thanks a lot...!!!!!

    I have got a lot of people telling me about using the modules. Can anyone give me info on how I can check this. Everytime I use this, I get this error message.

    "Can't locate Regexp/ in @INC (@INC contains: /et/pkgs/perl/5.8.0_crm/lib/perl5 /et/pkgs/perl/5.8.0_crm/lib/perl5/site_perl /et/pkgs/perl/5.8.0_crm/lib/site_perl /usr/perl5/5.00503/sun4-solaris /usr/perl5/5.00503 /usr/perl5/site_perl/5.005/sun4-solaris /usr/perl5/site_perl/5.005 .) at line 3."


      Regular expressions may seem awkward at first, but keep at it! Your efforts will pay off in the long run. Perl is a far more powerful language for having them, and you'll be able to do many more things, easier, for being able to use them.

      The Camel (Programming Perl, Wall/Christiansen/Orwant) has a good chapter on Pattern Matching; you can also use 'perldoc perlre' to get an overview. Neither one is probably ideal for a total regexp newbie, however. I learned RE syntax from years of using sed, awk, and vi, so I can't recommend any specific introductory books (although many exist).


      Did your use line look like this?

      use Regexp::Common

      Note the double colon -- not the slash you used in your note.

      ...and did your error end with a line like this?

      BEGIN failed--compilation aborted at line 3.

      I mention the first because the first thing that occurs to me is that you tried to

      use Regexp/Common;

      If you used the correct form (as in the first sample above), then IMO, the problem is likely that Regexp::Common is not installed.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2020-12-01 06:34 GMT
Find Nodes?
    Voting Booth?

    No recent polls found