Memo

メモ > 技術 > プログラミング言語: Perl > ローカル環境構築(StrawberryPerl)

■ローカル環境構築(StrawberryPerl)
■StrawberryPerlインストール かつてはActivePerlが定番だったが、今は色々と問題があるらしい 代わりに、StrawberryPerlがよく紹介されている 今更だけど、ActivePerlからStrawberryPerlに乗り換えた話: 書きたい事や思いついた事を記録する備忘ブログ http://blog.makewls.com/article/188720799.html さよならActivePerl、こんにちはStrawberry Perl - mballackの日記 https://mballack.hatenadiary.org/entry/2020/09/29/160427 以下を参考に、XAMPPからStrawberryPerlを使ってみる Perl | Strawberry Perlのダウンロード及びインストール https://www.javadrive.jp/perl/activeperl/index4.html 以下でPerlのバージョンを確認すると、「5.10.1 以上(5.32 を推奨 / 5.36 まで検証済み)」と書かれている 動作に必要な環境とブラウザの対応 | CMSプラットフォーム Movable Type ドキュメントサイト https://www.movabletype.jp/documentation/system_requirements.html 以下にアクセスして「More downloads (all releases)」から「5.36.1.1 / 64bit」をダウンロードする Strawberry Perl for Windows https://strawberryperl.com/ ダウンロードした「strawberry-perl-5.36.1.1-64bit.msi」をダブルクリックでインストール デフォルト設定のまま進めて「C:\Strawberry\」にインストール 完了すると、以下の環境変数が自動で追加される C:\Strawberry\ C:\Strawberry\perl\site\bin C:\Strawberry\perl\bin コマンドラインから、Perlを参照できていることを確認する
>perl -v This is perl 5, version 36, subversion 1 (v5.36.1) built for MSWin32-x64-multi-thread Copyright 1987-2023, Larry Wall Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using "man perl" or "perldoc perl". If you have access to the Internet, point your browser at https://www.perl.org/, the Perl Home Page.
CGIプログラムから参照してみる 「Perl = 5.036001」のように表示されれば成功(Perl5.6.0以降、バージョンの値は「5.6.0」ではなく「5.006」のように表示されるので注意)
#!/Strawberry/perl/bin/perl print "Content-Type: text/html; charset=Shift_JIS\n\n"; print "<html>\n"; print "<head><title>Perl</title></head>\n"; print "<body>\n"; print "<p>Perl = " . $] . "</p>\n"; print "</body>\n"; print "</html>\n"; exit;
Perl/CGIプログラムからPerlパッケージのバージョンを取得する - 木村秀一のホームページ https://kimurashuuichi.com/programming/perl/memo/system_perl_version.html ■既存モジュールの利用を確認
#!/Strawberry/perl/bin/perl use strict; use warnings; use Math::BigInt; my $big_int = Math::BigInt->new('11111111111111111111111111111111111111111111'); $big_int = $big_int * 2; print "Content-Type: text/html; charset=Shift_JIS\n\n"; print "<html>\n"; print "<head><title>Perl</title></head>\n"; print "<body>\n"; print "<p>BigInt = " . $big_int . "</p>\n"; print "</body>\n"; print "</html>\n"; exit;
Math::BigInt、Math::BigFloat - 大きな桁数を持つ数の計算 - Perlゼミ|Perlの基礎をインストールからサンプルで丁寧に解説 https://perlzemi.com/blog/20080925122245.html ■CPANからモジュールを追加
>cpan Loading internal logger. Log::Log4perl recommended for better logging Starting with version 2.29 of the cpan shell, a new download mechanism is the default which exclusively uses cpan.org as the host to download from. The configuration variable pushy_https can be used to (de)select the new mechanism. Please read more about it and make your choice between the old and the new mechanism by running o conf init pushy_https Once you have done that and stored the config variable this dialog will disappear. Unable to get Terminal Size. The Win32 GetConsoleScreenBufferInfo call didn't work. The COLUMNS and LINES environment variables didn't work. at C:\Strawberry\perl\vendor\lib/Term/ReadLine/readline.pm line 410. cpan shell -- CPAN exploration and modules installation (v2.36) Enter 'h' for help. cpan> install Image::EXIF Starting with version 2.29 of the cpan shell, a new download mechanism is the default which exclusively uses cpan.org as the host to download from. The configuration variable pushy_https can be used to (de)select the new mechanism. Please read more about it and make your choice between the old and the new mechanism by running 〜中略〜 Files found in blib\arch: installing files in blib\lib into architecture dependent library tree Installing C:\STRAWB~1\perl\site\lib\auto\Image\EXIF\EXIF.xs.dll Installing C:\STRAWB~1\perl\site\lib\Image\EXIF.pm Appending installation info to C:\STRAWB~1\perl\lib/perllocal.pod ARC/Image-EXIF-2.01.tar.gz C:\STRAWB~1\c\bin\gmake.exe install UNINST=1 -- OK
コマンドライン経由だとモジュールを参照できるが、Apache経由だと参照できず …だったが、Windowsを再起動すると解消した
#!/Strawberry/perl/bin/perl use strict; use warnings; use Image::Exif; print "Content-Type: text/html; charset=Shift_JIS\n\n"; print "<html>\n"; print "<head><title>Perl</title></head>\n"; print "<body>\n"; print "<p>Perl = " . $] . "</p>\n"; print "</body>\n"; print "</html>\n"; exit;
■データベース接続 DBIのインストールコマンドを実行しなくても接続できているような CPANの設定をしたことで、使えるようになったのか Perlのパス以外は、「ローカル環境構築(XAMPP)」と同じで接続できる

Advertisement