in reply to Re: Trouble usig a subroutine from a custom module
in thread Trouble usig a subroutine from a custom module

Choroba, thanks for your reply. I implemented your suggestions and will add the code here for trouble shooting purposes, but I am still getting this error:
Undefined subroutine &VSCOperl::trim called at ./dupCheck.pl line 19, <DATA> line 960.

Here is the new code to my program:

#!/home/myhomedrive/opt/perl/bin/perl use strict; use warnings; use Data::Dumper; use Net::LDAP; use lib '/home/myhomedrive/scripts/lib'; use customPerlMod qw{ trim ltrim rtrim }; my $string = " ll "; $string = customPerlMod::trim ( $string );

and here is the Module:

#!/home/myhomedrive/opt/perl/bin/perl package customPerlMod; use strict; use warnings; use Exporter 'import'; our @EXPORT_OK = qw(return_month return_day trim ltrim rtrim ); # Perl trim function to remove whitespace from the start and end of th +e string sub trim($) { my $string = shift; $string =~ s/^\s+//; $string =~ s/\s+$//; return $string; } # Left trim function to remove leading whitespace sub ltrim($) { my $string = shift; $string =~ s/^\s+//; return $string; } # Right trim function to remove trailing whitespace sub rtrim($) { my $string = shift; $string =~ s/\s+$//; return $string; } 1;

what do you mean by prototypes?

Thanks in advance for your help! Frank

Replies are listed 'Best First'.
Re^3: Trouble usig a subroutine from a custom module
by choroba (Cardinal) on Nov 11, 2024 at 16:23 UTC
    Something is off here.

    I copied the program to a file ~/_/0/1.pl and the module to ~/_/0/customPerlMod.pm. I changed the path to lib to actually point to the directory:

    use lib $ENV{HOME} . '/_/0';
    and added the following line:
    print "<$string>\n";
    When I run the script, I get back the following line:
    <ll>

    I get the same output when I drop the fully qualified name, as it's not needed with imported subroutines:

    $string = trim ($string);

    Prototypes are the ($) after subroutine names in their declarations. They tell Perl parser how to parse the arguments, they are not argument lists. If you don't know what they are and what they do, you should drop them.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      To all. Thanks for your help, but I was able to figure what I was doing wrong.

      It was an ID10t error.

      In addition to the changes that choroba suggested, I realized that I had a typo in my Package.pm file. In the code that I submitted to this question, I changed around some names to mask my company and some directories for the company. In the process, I did not realize that the Package name in the .PL file was named something along the lines of :

      use customPerlMod;

      and although my file name as customPerlMod.pm, in the file itself, it was named:

      package customPerlmod;

      Note that the "m" in the package is lower case while the call to the package in the code has an upper case "M".

      Thanks for all of your help. Apologizes for my error