String::Numeric::Whatever - It's a test implement to ignore the difference between <=> and cmp
<=>
cmp
use String::Numeric::Whatever; my $str = String::Numeric::Whatever->new('strings'); say q|Succeeded in comparing with strings by 'eq'| if $str eq 'strings'; say q|Succeeded in comparing with Int by 'ne'| if $str ne 100; say q|Succeeded in comparing with Int by '!='| if $str != 100; say q|Succeeded in comparing with strings by '=='| if $str == 'strings';
If you have knowledge of other language, You may think like that.
Why strings can't be compared with using ==?
==
I can't answer the reason why, but can give you this module.
It provides us comparable object with using ==, eq or whatever!
eq
I'm sorry that you have to call constructors before getting the benefits of this module.
There is no validation. accepts all types of SCALAR
my $str = String::Numeric::Whatever->new('strings'); my $num = String::Numeric::Whatever->new(1234);
or you can set like this:
tie my $str => 'String::Numeric::Whatever', 'strings'; tie my $num => 'String::Numeric::Whatever', 1234;
Now you can compare the values with using any operators in below:
< <= > >= == != <=> lt le gt ge eq ne cmp
After you assigned the constructors, you don't have to care about whatever this is a string or number.
So you can write like below without warnings:
say $str if $str == 'string'; # strings say $num if $num ne 0; # 1234
Copyright (C) worthmine.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Yuki Yoshida(worthmine)
To install String::Numeric::Whatever, copy and paste the appropriate command in to your terminal.
cpanm
cpanm String::Numeric::Whatever
CPAN shell
perl -MCPAN -e shell install String::Numeric::Whatever
For more information on module installation, please visit the detailed CPAN module installation guide.