How can I call the Perl function from a shell script?

I wrote a library in Perl that contains a specific function that returns server information as a character string. Is it possible to call this function from the shell directly?

My boss asks, "Can you call it from the shell right now?" Because he said it, I think I can do it, but how can I do it?

+3
source share
2 answers
perl -MServerlib=server_information -e 'print server_information()'

This is another way to do this, but only if Serverlib exports the server_informationsub. If this is not the case, you will need to do the following:

perl -MServerlib -e 'print MServerlib::server_information()'
+10
source

perl , perl script, . , script serverinfo, :

#!/usr/bin/perl

require 'library.pl';
say library::getServerInformation();

:

chmod u+x serverinfo

, script , . script, , API, .

+7

Source: https://habr.com/ru/post/1709046/


All Articles