···1# Perl {#sec-language-perl}
23-## Running perl programs on the shell {#ssec-perl-running}
45When 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:
6···3536```nix
37ClassC3 = buildPerlPackage rec {
38- name = "Class-C3-0.21";
039 src = fetchurl {
40- url = "mirror://cpan/authors/id/F/FL/FLORA/${name}.tar.gz";
41 sha256 = "1bl8z095y4js66pwxnm7s853pi9czala4sqc743fdlnk27kq94gz";
42 };
43};
44```
4546-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
4748```nix
49foo = import ../path/to/foo.nix {
···72{ buildPerlPackage, fetchurl, db }:
7374buildPerlPackage rec {
75- name = "BerkeleyDB-0.36";
07677 src = fetchurl {
78- url = "mirror://cpan/authors/id/P/PM/PMQS/${name}.tar.gz";
79 sha256 = "07xf50riarb60l1h6m2dqmql8q5dij619712fsgw7ach04d8g3z1";
80 };
81···9091```nix
92ClassC3Componentised = buildPerlPackage rec {
93- name = "Class-C3-Componentised-1.0004";
094 src = fetchurl {
95- url = "mirror://cpan/authors/id/A/AS/ASH/${name}.tar.gz";
96 sha256 = "0xql73jkcdbq4q9m0b0rnca6nrlvf5hyzy8is0crdk65bynvs8q1";
97 };
98 propagatedBuildInputs = [
···111 version = "11.50";
112113 src = fetchurl {
114- url = "https://www.sno.phy.queensu.ca/~phil/exiftool/Image-ExifTool-11.50.tar.gz";
115 sha256 = "0d8v48y94z8maxkmw1rv7v9m0jg2dc8xbp581njb6yhr7abwqdv3";
116 };
117···139```ShellSession
140$ nix-generate-from-cpan XML::Simple
141 XMLSimple = buildPerlPackage rec {
142- name = "XML-Simple-2.22";
0143 src = fetchurl {
144- url = "mirror://cpan/authors/id/G/GR/GRANTM/${name}.tar.gz";
145 sha256 = "b9450ef22ea9644ae5d6ada086dc4300fa105be050a2030ebd4efd28c198eb49";
146 };
147 propagatedBuildInputs = [ XMLNamespaceSupport XMLSAX XMLSAXExpat ];
···1# Perl {#sec-language-perl}
23+## Running Perl programs on the shell {#ssec-perl-running}
45When 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:
6···3536```nix
37ClassC3 = buildPerlPackage rec {
38+ pname = "Class-C3";
39+ version = "0.21";
40 src = fetchurl {
41+ url = "mirror://cpan/authors/id/F/FL/FLORA/${pname}-${version}.tar.gz";
42 sha256 = "1bl8z095y4js66pwxnm7s853pi9czala4sqc743fdlnk27kq94gz";
43 };
44};
45```
4647+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
4849```nix
50foo = import ../path/to/foo.nix {
···73{ buildPerlPackage, fetchurl, db }:
7475buildPerlPackage rec {
76+ pname = "BerkeleyDB";
77+ version = "0.36";
7879 src = fetchurl {
80+ url = "mirror://cpan/authors/id/P/PM/PMQS/${pname}-${version}.tar.gz";
81 sha256 = "07xf50riarb60l1h6m2dqmql8q5dij619712fsgw7ach04d8g3z1";
82 };
83···9293```nix
94ClassC3Componentised = buildPerlPackage rec {
95+ pname = "Class-C3-Componentised";
96+ version = "1.0004";
97 src = fetchurl {
98+ url = "mirror://cpan/authors/id/A/AS/ASH/${pname}-${version}.tar.gz";
99 sha256 = "0xql73jkcdbq4q9m0b0rnca6nrlvf5hyzy8is0crdk65bynvs8q1";
100 };
101 propagatedBuildInputs = [
···114 version = "11.50";
115116 src = fetchurl {
117+ url = "https://www.sno.phy.queensu.ca/~phil/exiftool/${pname}-${version}.tar.gz";
118 sha256 = "0d8v48y94z8maxkmw1rv7v9m0jg2dc8xbp581njb6yhr7abwqdv3";
119 };
120···142```ShellSession
143$ nix-generate-from-cpan XML::Simple
144 XMLSimple = buildPerlPackage rec {
145+ pname = "XML-Simple";
146+ version = "2.22";
147 src = fetchurl {
148+ url = "mirror://cpan/authors/id/G/GR/GRANTM/XML-Simple-2.22.tar.gz";
149 sha256 = "b9450ef22ea9644ae5d6ada086dc4300fa105be050a2030ebd4efd28c198eb49";
150 };
151 propagatedBuildInputs = [ XMLNamespaceSupport XMLSAX XMLSAXExpat ];