SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    modules and a mysterious 1

    Hello,

    I am trying to get to grips with modules. Here is my module code, saved in the lib folder as motor.pm.

    Code:
    #!c:\perl\bin\perl.exe
    
    package Motor;
    1;
    
    require Exporter;
    @ISA = ("Exporter");
    @EXPORT = ();
    @EXPORT_OK = ("motorStatements");
    
    sub motorStatements
    {
    	$statements = print("\"I have an engine\"\n\"I have wheels\"\n\"I have doors\"");
    	return $statements;
    }
    And here is the .pl file, saved in perl\programs as motorVehicle.pl.

    Code:
    #!c:\perl\bin\perl.exe
    
    use Motor("motorStatements");
    
    print motorStatements();
    When I type perl motorVehicle.pl, it prints the three lines as expected, but immediately after the last one there is a mysterious 1.


    I don't know where it came from and can't get rid of it. What is happening?

  2. #2
    SitePoint Wizard bronze trophy KevinR's Avatar
    Join Date
    Nov 2004
    Location
    Moon Base Alpha
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    #!c:\perl\bin\perl.exe
    
    package Motor;
    
    require Exporter;
    @ISA = ("Exporter");
    @EXPORT = ();
    @EXPORT_OK = ("motorStatements");
    
    sub motorStatements
    {
    	$statements = print("\"I have an engine\"\n\"I have wheels\"\n\"I have doors\"");
    	return $statements;
    }
    
    1;#<-- should be down here

  3. #3
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    KevinR rides to the rescue once again


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •