in reply to Re: Custom Module question
in thread Custom Module question

Thanks for the comments, this is great here is my updated code
module package Printname; use strict; use warnings; use parent qw/ Exporter /; our @EXPORT_OK = qw/ print_name /; sub print_name { my($name) = @_; print "\nHello, $name\n"; } 1;
script
#!/usr/bin/perl package main; use strict; use warnings; use lib "C:/Perl64/lib/printname"; use lib "C:/Perl64/site/lib/printname"; use PrintName qw/ print_name /; print_name("John");
error C:\Scripts>perl testmodule.pl Undefined subroutine &main::print_name called at testmodule.pl line 11. line 11 is print_name("John"); I tried calling the subroutine from within the module itself but it didn't make a difference. Thanks

Replies are listed 'Best First'.
Re^3: Custom Module question
by davido (Cardinal) on Dec 04, 2014 at 19:20 UTC

    Thanks for fixing your formatting.

    The other response is correct: "use PrintName", vs package Printname... these things are case sensitive.

    Also, if I recall, Windows filenames are not case-sensitive, but many other operating systems are. For all those OS's that are case-sensitive, when your module starts out with package PrintName;, the file it lives in should usually be named PrintName.pm, not printname.pm. In your environment case sensitivity of filenames is probably not an issue, but someday you'll discover the rest of the world and realize what you've been missing. ;)


    Dave

      Ok I made your changes when I run the script I receive the following error. BTW thanks again I have used perl for a while but I am learning a good deal from your help. New to modules. Thanks Again C:\Scripts>perl testmodule.pl Subroutine print_name redefined at C:/Perl64/site/lib/printname/PrintName.pm line 10. Hello, John Module
      use Printname; use strict; use warnings; use parent qw/ Exporter /; our @EXPORT_OK = qw/ print_name /; sub print_name { my($name) = @_; print "\nHello, $name\n"; } 1;
      script
      #!/usr/bin/perl package main; use strict; use warnings; use lib "C:/Perl64/lib/printname"; use lib "C:/Perl64/site/lib/printname"; # use PrintName qw/ print_name /; use PrintName; print_name("John");

        The first line of your module should be
        package PrintName;
        not use Printname;

        poj
Re^3: Custom Module question
by davido (Cardinal) on Dec 04, 2014 at 17:34 UTC

    Why didn't you format it using <code>...</code> tags? I can't read it the way it is.

    Please see Writeup Formatting Tips for details. Once you've updated your post with code tags I'll look it over if I can still get to it.


    Dave

Re^3: Custom Module question
by poj (Abbot) on Dec 04, 2014 at 17:38 UTC
    # package Printname; package PrintName;
    poj