dbae has asked for the wisdom of the Perl Monks concerning the following question:

What are the conventional suffixes of Perl or Perl-related files? Using Google, I found some lists from particular Linux sources, but couldn't find any list that claimed to be comprehensive as far as Perl is concerned. If there is such a list, I would like to see it.

Long ago, I think Perl source files were often indicated by something.p, but maybe my memory is playing tricks on me. The .p suffix doesn't seem to be used any more.

Does it make any difference on any platform? My own opinion is that a convention can be pretty helpful: for example when I've mislaid one of my programs and forgotten its name, I can use a find command, provided the suffix is appropriate.

Can suffixes be associated with particular programs in modern \w*n[ui]x operating systems, as in Windows or MacOsX?

Thanks

Replies are listed 'Best First'.
Re: Conventional filename suffixes
by AReed (Pilgrim) on Aug 07, 2005 at 16:21 UTC
    merlyn recommends reserving the .pl extension for "perl libraries", meaning files that contain code to be "included" in other programs. He goes on to say that "experts recommend" using .plx to indicate that the file is a "perl executable" if you either choose to or are required to use an extension.

    Any errors in the paraphrasing are my own. Refer to to the footnote at the bottom of page 7 in Learning Perl Objects, References & Modules.

Re: Conventional filename suffixes
by davido (Cardinal) on Aug 07, 2005 at 16:31 UTC

    Historically .pl stood for Perl Library. This was "back in the day" before modules were introduced. Nowadays you see fewer and fewer Perl Libraries in use as people migrate to proper modules. But libraries still are put to good practical use, so the .pl standard continues to exist.

    .pm stands for Perl Module. This is an etched in stone convention that exists cross platform. The use statement expects that if you (for example) use Data::Dumper Perl should look for Dumper.pm in the Data directory in one of several possible places where modules typically reside.

    Because some operating systems don't have an 'executable' file attribute, and don't look for shebang lines (the #!/path/to/perl line; these are always examine d for switches regardless of OS, but not necessarily for path to Perl and association) it has become somewhat of a convention to use .pl as an extension on Perl scripts that can be associated with the Perl interpreter (perl.exe, on these operating systems). For example, in the Windows registry, if one associates .pl files with perl.exe it will be possible to double-click on a .pl file and have it invoke perl.exe, much like you could click on a .doc file and have it invoke MSWord. It is an unfortunate requirement and convention, as it makes it difficult to differentiate between a Perl script and an old Perl Library.

    The .cgi convention is not set in stone. It is dependant on your webserver configuration, and could be something different entirely or not even required. It's not strictly a Perl convention, as scripts written in other scripting languages could also use the .cgi extension to alert the webserver that it's a CGI script. And like I said, there are some webserver configurations where .cgi isn't even needed.

    This is discussed in greater detail in the platform specific POD area of Perl's documentation and to some degree in perlrun.


    Dave

Re: Conventional filename suffixes
by sk (Curate) on Aug 07, 2005 at 15:23 UTC
    I have seen .pl, .pm (perl module), .cgi. Others with more experience than me would have seen more.

    You don't need to associate them as in UNIX/Linux the shebangs line takes care of it.

    If you put #!/usr/bin/perl -w or whatever is approripate for your system based on where Perl is installed as the first line in your script, the shell will automatically execute the file for you when invoked from the command line.

    Agreed, extensions are useful for searching and it is totally a personal preference and so nothing is enforced when it comes to Perl.

    If you are looking for perl files and you did not have an extension, you can look for things "inside" the code while searching for all files. In UNIX you do it with the find | xargs grep commands. In Window$ you can bring the find utility and use the containing text box to search.

    If you have been use my in your code then searching for my $ might help. Watch out when you do that in unix as $ should be escaped in std grep.

    NOTE: Searching all the files for text will take too long! (depends on where and how many files you search)

    -SK

Re: Conventional filename suffixes
by davidrw (Prior) on Aug 07, 2005 at 15:25 UTC
    Source programs are typically .pl or w/no extension (update: or .cgi), and modules will have the .pm extension. For modules, it matters and they schould always be .pm .. for scripts, it really doesn't matter. Personally, i usually name scripts foo.pl so i can at a ls glance see it's perl, but when i "install" it somewhere for real use, i will rename it and drop the extension and make sure it's executable. Depends if i want to run it like perl foo.pl or ./foo

    as far as finding scripts, i would do a combination of searching for '.pl' and using the file command.. e.g. file /usr/bin | grep -i perl

    as for associating files un linux/unix, if a text file is executable, it's not the extension that matters but what's one the first line of the file in the she-bang line (e.g. #!/usr/bin/perl).
Re: Conventional filename suffixes
by holli (Abbot) on Aug 07, 2005 at 15:26 UTC
    Well, for modules the standard extension is ".pm".
    For scripts your free to chose. Under windows ".pl" ist the quasi standard, under *x people seem to prefer to have no extension.


    holli, /regexed monk/
Re: Conventional filename suffixes
by spiritway (Vicar) on Aug 07, 2005 at 22:12 UTC

    I've also seen the extension '*.perl'. This appears to be used by some to indicate a text file somehow related to a script or module.