in reply to Portable way of checking if a scalar is a number / integer / float

G'day bishop729,

Welcome to the Monastery.

If a module is installed, you can simply put

use Some::Module;

in your code (see use for some variations on that syntax).

If you don't want your users to have to install anything, you can put the module source in your repo. Something like this:

bin/ script.pl lib/ Some/ Module.pm

You can use FindBin so your code can find the module.

Be aware that you'll need to keep copies of Some::Module in all repos; all fixes, enhancements, extensions, etc. will need to be kept in sync across all repos. This tends towards a maintenance nightmare and I certainly don't recommend it; however, if it's a requirement that users don't install modules, this is probably what you'll need to do.

I don't know how familiar you are with writing modules. I'd recommend using Exporter to avoid namespace pollution. Your code might look something like this:

package Some::Module; use strict; use warnings; our $VERSION = '0.001'; use Exporter 'import'; our @EXPORT_OK = qw{isnum isint isfloat}; our %EXPORT_TAGS = (all => [@EXPORT_OK]); sub isnum { ... } sub isint { ... } sub isfloat { ... } 1;

And don't forget to add your POD after that.

See also:

— Ken

Replies are listed 'Best First'.
Re^2: Portable way of checking if a scalar is a number / integer / float
by bishop729 (Initiate) on May 13, 2023 at 23:02 UTC
    Thanks for the welcome. I'm pleased at how quickly I got a solution to my problem. For now I am copying the source Scalar::Util::Numeric:PP into my repo. I realize it's not sustainable as my dependencies increase in number and complexity, and I will revisit your suggestions when the time comes.