···11# Perl {#sec-language-perl}
2233-## Running perl programs on the shell {#ssec-perl-running}
33+## Running Perl programs on the shell {#ssec-perl-running}
4455When executing a Perl script, it is possible you get an error such as `./myscript.pl: bad interpreter: /usr/bin/perl: no such file or directory`. This happens when the script expects Perl to be installed at `/usr/bin/perl`, which is not the case when using Perl from nixpkgs. You can fix the script by changing the first line to:
66···35353636```nix
3737ClassC3 = buildPerlPackage rec {
3838- name = "Class-C3-0.21";
3838+ pname = "Class-C3";
3939+ version = "0.21";
3940 src = fetchurl {
4040- url = "mirror://cpan/authors/id/F/FL/FLORA/${name}.tar.gz";
4141+ url = "mirror://cpan/authors/id/F/FL/FLORA/${pname}-${version}.tar.gz";
4142 sha256 = "1bl8z095y4js66pwxnm7s853pi9czala4sqc743fdlnk27kq94gz";
4243 };
4344};
4445```
45464646-Note the use of `mirror://cpan/`, and the `${name}` in the URL definition to ensure that the name attribute is consistent with the source that we’re actually downloading. Perl packages are made available in `all-packages.nix` through the variable `perlPackages`. For instance, if you have a package that needs `ClassC3`, you would typically write
4747+Note the use of `mirror://cpan/`, and the `pname` and `version` in the URL definition to ensure that the `pname` attribute is consistent with the source that we’re actually downloading. Perl packages are made available in `all-packages.nix` through the variable `perlPackages`. For instance, if you have a package that needs `ClassC3`, you would typically write
47484849```nix
4950foo = import ../path/to/foo.nix {
···7273{ buildPerlPackage, fetchurl, db }:
73747475buildPerlPackage rec {
7575- name = "BerkeleyDB-0.36";
7676+ pname = "BerkeleyDB";
7777+ version = "0.36";
76787779 src = fetchurl {
7878- url = "mirror://cpan/authors/id/P/PM/PMQS/${name}.tar.gz";
8080+ url = "mirror://cpan/authors/id/P/PM/PMQS/${pname}-${version}.tar.gz";
7981 sha256 = "07xf50riarb60l1h6m2dqmql8q5dij619712fsgw7ach04d8g3z1";
8082 };
8183···90929193```nix
9294ClassC3Componentised = buildPerlPackage rec {
9393- name = "Class-C3-Componentised-1.0004";
9595+ pname = "Class-C3-Componentised";
9696+ version = "1.0004";
9497 src = fetchurl {
9595- url = "mirror://cpan/authors/id/A/AS/ASH/${name}.tar.gz";
9898+ url = "mirror://cpan/authors/id/A/AS/ASH/${pname}-${version}.tar.gz";
9699 sha256 = "0xql73jkcdbq4q9m0b0rnca6nrlvf5hyzy8is0crdk65bynvs8q1";
97100 };
98101 propagatedBuildInputs = [
···111114 version = "11.50";
112115113116 src = fetchurl {
114114- url = "https://www.sno.phy.queensu.ca/~phil/exiftool/Image-ExifTool-11.50.tar.gz";
117117+ url = "https://www.sno.phy.queensu.ca/~phil/exiftool/${pname}-${version}.tar.gz";
115118 sha256 = "0d8v48y94z8maxkmw1rv7v9m0jg2dc8xbp581njb6yhr7abwqdv3";
116119 };
117120···139142```ShellSession
140143$ nix-generate-from-cpan XML::Simple
141144 XMLSimple = buildPerlPackage rec {
142142- name = "XML-Simple-2.22";
145145+ pname = "XML-Simple";
146146+ version = "2.22";
143147 src = fetchurl {
144144- url = "mirror://cpan/authors/id/G/GR/GRANTM/${name}.tar.gz";
148148+ url = "mirror://cpan/authors/id/G/GR/GRANTM/XML-Simple-2.22.tar.gz";
145149 sha256 = "b9450ef22ea9644ae5d6ada086dc4300fa105be050a2030ebd4efd28c198eb49";
146150 };
147151 propagatedBuildInputs = [ XMLNamespaceSupport XMLSAX XMLSAXExpat ];