Question from the perlmod man pages.

Discussion in 'Perl Misc' started by grocery_stocker, Oct 28, 2006.

  1. I'm sort of drawing a stump on the following:

    "Perl packages may be nested inside other package names, so we can have
    package names containing ::. But if we used that package name directly
    as a filename it would make for unwieldy or impossible filenames on
    some systems. Therefore, if a module's name is, say, Text::Soundex,
    then its definition is actually found in the library file
    Text/Soundex.pm."

    Say I have a module name Text::Soundex. I use this in my Perl script
    as:

    use Text::Soundex;

    I know there is a module called Soundex.pm. I also know there is a
    directory
    name with the name Text. However, would there also be a module named
    Text.pm?

    Chad
    grocery_stocker, Oct 28, 2006
    #1
    1. Advertising

  2. grocery_stocker

    Jim Gibson Guest

    In article <>,
    grocery_stocker <> wrote:

    > I'm sort of drawing a stump on the following:
    >
    > "Perl packages may be nested inside other package names, so we can have
    > package names containing ::. But if we used that package name directly
    > as a filename it would make for unwieldy or impossible filenames on
    > some systems. Therefore, if a module's name is, say, Text::Soundex,
    > then its definition is actually found in the library file
    > Text/Soundex.pm."
    >
    > Say I have a module name Text::Soundex. I use this in my Perl script
    > as:
    >
    > use Text::Soundex;
    >
    > I know there is a module called Soundex.pm. I also know there is a
    > directory
    > name with the name Text. However, would there also be a module named
    > Text.pm?


    No, there need not be a module named Text.pm. The pattern A::B is a
    naming convention, and does not establish a hierarchical relationship
    between modules A and B or their symbol tables. See 'perldoc perlmod'
    for details.
    Jim Gibson, Oct 28, 2006
    #2
    1. Advertising

  3. Jim Gibson wrote:
    > In article <>,
    > grocery_stocker <> wrote:
    >
    > > I'm sort of drawing a stump on the following:
    > >
    > > "Perl packages may be nested inside other package names, so we can have
    > > package names containing ::. But if we used that package name directly
    > > as a filename it would make for unwieldy or impossible filenames on
    > > some systems. Therefore, if a module's name is, say, Text::Soundex,
    > > then its definition is actually found in the library file
    > > Text/Soundex.pm."
    > >
    > > Say I have a module name Text::Soundex. I use this in my Perl script
    > > as:
    > >
    > > use Text::Soundex;
    > >
    > > I know there is a module called Soundex.pm. I also know there is a
    > > directory
    > > name with the name Text. However, would there also be a module named
    > > Text.pm?

    >
    > No, there need not be a module named Text.pm. The pattern A::B is a
    > naming convention, and does not establish a hierarchical relationship
    > between modules A and B or their symbol tables. See 'perldoc perlmod'
    > for details.


    The source of this confusion stems from the following lines of code:

    #!/usr/bin/perl

    # change these two lines
    $server_port = 1234;
    $identification_phrase = 'insert phrase here';

    # redirect error messages to a logfile
    open(STDERR, ">>/tmp/logserver.log");

    # code stolen liberally from Perl Cookbook

    use IO::Socket;

    $logfile = $ARGV[0];
    open(LOG, "<$logfile");
    # read to the current end of the log
    while(<LOG>) {
    }

    $server = IO::Socket::INET->new(LocalPort => $server_port,
    Type => SOCK_STREAM,
    Reuse => 1,
    Listen => 10 ) # or SOMAXCONN
    or exit; # "Couldn't be a tcp server on port $server_port : $@\n";

    while (($client,$client_address) = $server->accept()) {
    ($client_port, $client_ip) = unpack_sockaddr_in($client_address);
    @decimal_address = unpack("C4", $client_ip);
    $ip_number = join(".", @decimal_address);
    warn "connection from $ip_number";
    while(<$client>) {
    last if /$identification_phrase/;
    }
    warn "connection from $ip_number gave pass phrase";
    $lines = 0;
    while(<LOG>) {
    $lines++;
    print $client $_;
    }
    warn "returned $lines lines to $ip_number";
    close($client);
    }

    close($server);

    Why go

    use IO::Socket;

    Why just not

    use IO::Socket::INET;

    in this case
    grocery_stocker, Oct 28, 2006
    #3
  4. grocery_stocker

    Guest

    "grocery_stocker" <> wrote:
    > Jim Gibson wrote:
    > > No, there need not be a module named Text.pm. The pattern A::B is a
    > > naming convention, and does not establish a hierarchical relationship
    > > between modules A and B or their symbol tables. See 'perldoc perlmod'
    > > for details.

    >
    > The source of this confusion stems from the following lines of code:
    >
    > #!/usr/bin/perl
    >
    > # change these two lines
    > $server_port = 1234;
    > $identification_phrase = 'insert phrase here';
    >
    > # redirect error messages to a logfile
    > open(STDERR, ">>/tmp/logserver.log");
    >
    > # code stolen liberally from Perl Cookbook
    >
    > use IO::Socket;
    >

    ....
    >
    > $server = IO::Socket::INET->new(LocalPort => $server_port,

    ....

    >
    > Why go
    >
    > use IO::Socket;
    >
    > Why just not
    >
    > use IO::Socket::INET;
    >
    > in this case


    No particular reason that I can think of. When you use IO::Socket, it
    automatically uses IO::Socket::INET for you. That is just the kind of
    relationship that IO::Socket and IO::Socket::INET have with each other.
    Other modules have a more stand-offish relationship.


    OK, maybe one reason to use IO::Socket rather than IO::Socket::INET is
    that, if you decide to switch to the different kind of socket, (say, UNIX)
    then you would only need to change the "new" line rather than changing both
    the "new" and the "use".

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , Oct 28, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Pfaff

    Re: man pages for C commands (GCC commands)

    Ben Pfaff, Jun 24, 2003, in forum: C Programming
    Replies:
    4
    Views:
    3,952
    Thomas Stegen
    Jun 28, 2003
  2. JS

    "man" pages for setjmp.h

    JS, Mar 28, 2005, in forum: C Programming
    Replies:
    2
    Views:
    329
  3. Hartmut Goebel

    Install man-pages with distutils/setuptools

    Hartmut Goebel, May 17, 2008, in forum: Python
    Replies:
    1
    Views:
    677
    Sebastian 'lunar' Wiesner
    May 17, 2008
  4. Yehuda Berlinger

    Is there an index to the perl man pages?

    Yehuda Berlinger, Aug 21, 2003, in forum: Perl Misc
    Replies:
    1
    Views:
    70
    Bob Walton
    Aug 25, 2003
  5. Jaap Karssenberg

    conflict between man perlipc and man perlfunc !?

    Jaap Karssenberg, Jan 9, 2004, in forum: Perl Misc
    Replies:
    0
    Views:
    144
    Jaap Karssenberg
    Jan 9, 2004
Loading...

Share This Page