How to trim URL to root domain?

How do we get/install this module?
I read the cpan.org article, but it says:

This module will attempt to search etc directories in /usr/share/publicsuffix, /usr, /usr/local, and /opt/local for the effective_tld_names.dat file. If a file is not found, a default file is loaded from Domain::PublicSuffix::Default, which is current at the time of the module's release. You can override the data file path by giving the new() method a 'data_file' argument.

does your script do that?

Seems so, yes. I haven't done big testing, but it works fine with the examples I've put in the script above.

To install a perl module use cpan, or more comfortable, cpanminus. You can install cpanminus with Homebrew:

brew install cpanm

Before – if not already done – install perl with brew install perl (Instead of using the system perl)

OK, I installed both in the order you said:
brew install perl
brew install cpanm

but when I run from a KM Execute Shell Script, I get this:

Can't locate Domain/PublicSuffix.pm in @INC (you may need to install the Domain::PublicSuffix module) (@INC contains: /Library/Perl/5.18/darwin-thread-multi-2level /Library/Perl/5.18 /Network/Library/Perl/5.18/darwin-thread-multi-2level /Network/Library/Perl/5.18 /Library/Perl/Updates/5.18.2 /System/Library/Perl/5.18/darwin-thread-multi-2level /System/Library/Perl/5.18 /System/Library/Perl/Extras/5.18/darwin-thread-multi-2level /System/Library/Perl/Extras/5.18 .) at /var/folders/hb/6xgg0y8j4g530m81rd1f9mpc0000gn/T/Keyboard-Maestro-Script-51EF52D5-FB9D-48E7-B9B0-BF516C979CFF line 7.
BEGIN failed--compilation aborted at /var/folders/hb/6xgg0y8j4g530m81rd1f9mpc0000gn/T/Keyboard-Maestro-Script-51EF52D5-FB9D-48E7-B9B0-BF516C979CFF line 7.

I'm a total shell script dummy, so I don't have idea what this means, except that it could not find the Domain/PublicSuffix.pm

Any ideas on how to fix?

Does the script run outside KM?

(Copy it to a BBEdit document, save it as foo.pl, then hit ⌥⌘R)

Nope. Same basic error:

/Users/Shared/Dropbox/SW/DEV/Projects/[KM] Extract Domain Name/Get-Domain.pl:7: Can't locate Domain/PublicSuffix.pm in @INC (you may need to install the Domain::PublicSuffix module) (@INC contains: /usr/local/Cellar/perl/5.26.0/lib/perl5/site_perl/5.26.0/darwin-thread-multi-2level /usr/local/Cellar/perl/5.26.0/lib/perl5/site_perl/5.26.0 /usr/local/Cellar/perl/5.26.0/lib/perl5/5.26.0/darwin-thread-multi-2level /usr/local/Cellar/perl/5.26.0/lib/perl5/5.26.0 /usr/local/lib/perl5/site_perl/5.26.0)

To install "Domain::PublicSuffix module", do I need to do it from any particular dir?
Last time I did it from my home dir.

I just tried installing it again, and got this:

iMac-27-JMU:~ jimunderwood$ brew install cpanm
Warning: cpanminus 1.7043 is already installed
iMac-27-JMU:~ jimunderwood$ 

Any ideas?

When installing perl via Homebrew, have you seen and followed the instruction that have said something like this?:

PERL_MM_OPT="INSTALL_BASE=$HOME/perl5" cpan local::lib
echo 'eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)"' >> ~/.bash_profile

Or: do you have the line

eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)"

in your .bash_profile ?

Don't remember that.
I don't seem to have a bash profile:

iMac-27-JMU:~ jimunderwood$ open -a BBEdit.app .bash_profile
The file /Users/jimunderwood/.bash_profile does not exist.

How do I create it, and what should be in it?

Then in the ~./bashrc ?

I found this helpful article. Should I follow it to create bash profile?
MY MAC OSX BASH PROFILE

iMac-27-JMU:~ jimunderwood$ open -a BBEdit.app ~./bashrc
The file /Users/jimunderwood/~./bashrc does not exist.

The Domain::PublicSuffix module you have installed before, is it located here? That is, do you have this folder?

~/perl5/lib/perl5/Domain/PublicSuffix

!? If you don't have a .bash_profile and don't have a .bashrc, where is your bash config stored? I mean your bash aliases and all that stuff?

I'm just seeing you have searched at the wrong path. It is ~/.bashrc, not /Users/jimunderwood/~./bashrc

How would I search differently from this:

iMac-27-JMU:~ jimunderwood$ open -a BBEdit.app .bash_profile
The file /Users/jimunderwood/.bash_profile does not exist.
iMac-27-JMU:~ jimunderwood$ open -a BBEdit.app ~./bashrc
The file /Users/jimunderwood/~./bashrc does not exist.
iMac-27-JMU:~ jimunderwood$ open -a BBEdit.app ~/.bashrc
The file /Users/jimunderwood/.bashrc does not exist.
iMac-27-JMU:~ jimunderwood$ cd ~/
iMac-27-JMU:~ jimunderwood$ open -a BBEdit.app .bashrc
The file /Users/jimunderwood/.bashrc does not exist.
iMac-27-JMU:~ jimunderwood$ 

Isn't ~/ the same as my home dir, which is jimunderwood$ ?

Yes. But above you have written The file /Users/jimunderwood/~./bashrc does not exist. I was referring to that.

Have you found the module in this location?

Well, if the modules aren’t there, they should be in /usr/local/Cellar/perl/5.26.0/lib/perl5/site_perl/5.26.0.

So I propose:

In KM make a variable named ENV_PERL5LIB and paste this into it:

/Users/jimunderwood/perl5/lib/perl5:/usr/local/Cellar/perl/5.26.0/lib/perl5/site_perl/5.26.0

Check if you have the same perl version as in the path (5.26.0).

If perl (run from within KM) finds its modules now, but you get a weird dyld: error, then in the script replace the

#!/usr/bin/env perl

with

#!/usr/local/bin/perl

OK, I DO have that folder, but I can't find "PublicSuffix" folder anywhere on my mac.

But you did install the Domain::PublicSuffix module? (cpanm Domain::PublicSuffix)

If not then type

cpanm Domain::PublicSuffix

in the Terminal. (Assuming you have installed cpanm.)

If the module is already installed you’ll get a message saying that is up to date.