In order to run Perl Scripts that use Perl libraries installed with Fink (like the PDL) within BBEdit, the environment variable PERL5LIB needs to be set at the user level.
When I used the 'Run terminal' command in BBEdit, everything was fine, because the environment variable for the tcsh had been properly set. The list of paths in @INC does include /sw/lib/perl5/ and /sw/lib/perl5/darwin, so the PDL library was loaded.
However, when using the 'Run' command within BBEdit, the compilation would abort, saying that the PDL.pm library was not found in @INC. The list of paths did not include /sw/lib/perl5/ or /sw/lib/perl5/darwin.
This hint from David Wheeler and Rick Frankel, found on a newsgroup, gave me the solution. I also found some information on Apple's web site. The idea is to set the environment variable for each user at login by creating a ~/.MacOSX/environment.plist file in XML format as explained by Apple. This is how the file should look like in this particular case (the DOCTYPE entry should be one row with a space instead of a line break):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PERL5LIB</key>
<string>/sw/lib/perl5/darwin:/sw/lib/perl5</string>
</dict>
</plist>
For some reason, the /sw/lib/perl5/darwin is then included twice, which is OK, I guess. One way of not getting it twice is by using the following environment.plist file (the DOCTYPE entry should be one row with a space instead of a line break):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PERL5LIB</key>
<string>/sw/lib/perl5/darwin</string>
<key>PERL5LIB</key>
<string>/sw/lib/perl5</string>
</dict>
</plist>
I should add that it is impossible to create such a file using PropertyListEditor application, because you can't have two keys with the same name. You have to make it in a text editor. It seems to work well, though, and I don't know if this is better or not.
Mac OS X Hints
http://hints.macworld.com/article.php?story=20030508202847727