@kyanny's blog

My thoughts, my life. Views/opinions are my own.

今日のPerlMonks そしてこちらは「Perlを本格的に使いはじめたい」という人へ贈る力強いメッセージ。


I've been using Perl for some UNIX administration tasks, but only the very basics.

I want to learn more, and I have a web project coming up, so want to use Perl. I usually use PHP for web stuff, but I want to use Perl since I find it great for admin scripting tasks, so want to get better at it.

I've been recommended a template system like TT or Mason, but I really want to get my hands dirty with Perl without getting confused. Do people recommend I go this route? The first site coming up is only small and besides including files, I think I could do most of it with just Perl by itself.

While I'm posting, I have a technical question: I've searched the net and haven't found an equivalent function to PHP's include() - basically I need to embed a file that needs to be parsed by the Perl compiler - any ideas?

Unixを使った業務をこなすうちに簡単なスクリプトとしてではなくもっと本格的にPerlを使っていきたい、Web系の開発はPHPでやっていたがPerlでやりたいのでよさげなテンプレートを教えて、PHPのincludeに相当する命令はないの?というあたり。

で、これの回答コメントの最初三つくらいが素晴らしすぎる。完璧に模範的すぎて素晴らしいと思った。

Well for learning Perl, there is a book which's name surprisingly is Learning Perl ;-) I'd start with that, followed by the camel.

I would always use a Templating System, even for smaller projects. It saves you much debugging time. And you can learn them, especially TT, rather quickly.

As you have some PHP experience, Embedding Perl in HTML with Mason could be interesting for you. I personally prefer TT, for which I have some printable docu in PDF format on my homepage.

The answer to your last question:

perldoc -f require

Happy coding.

You might find this node useful

The best way to start learning Perl?.

Happy Perling!

Look in our Tutorials section.

Among many wonderful pearls of wisdom, there is Where and how to start learning Perl.

But since you are at it, bookmark that page and read all of them!

それぞれちゃんと重複しない、かつとても有益な情報を提示している。特に最初にポストした人がすげえ。必要最小限の言葉の中に情報を詰め込んでいて、さりげなく「僕はTTが好き」なんてのもほのめかしている。

下のほうにいくにしたがってTTよりHTML::Templateのほうがいいとか好みの問題にシフトしていって質問者置き去りの感もあるが、この人の指摘は(英文全部わかってないけどニュアンス的に)なるほどと思った。

I don't think may people here will agree, but i recommend for your first web-app you don't use a templating system and just print HTML statements wherever you need them. This has 2 advantages:

* You really see what happens right in the code
* It gets so dirty so quickly that next time you'll want to use a templating system

As for the inclusion of another perl file:
You can use eval but the better way would be to create a perl module (.pm file) that you can then use.

以下の二つの理由により、最初からテンプレートを使わずにあえてHTMLをコードに埋め込むやり方を経験しておくべきだ、というもの。

  • (自分の書いた)コードを見るだけで何が起こっているかを一望できること
  • 汚いやり方を経験したほうが、のちのちテンプレートを学ぶときに早く習得できる

うーん下の理由のほうはほとほと自信がない。so - soがわかってないんだ・・・。それはともかく、こういうまっとうな理由があるうえでの反論意見は有意義だと思う。この理由ならば、いわゆる「わかってるひとたち」だけが納得したり反論したりするだけのもので終わらないだろうし。