プログラミングは嫌い!でも興味はあるw

特に言語とかジャンルを指定しないで書いてみたいと思います。プログラミングが苦手でも知っておいて損はないと思うので、勉強した結果を共有していきたいと思います。

perlでHello world

前準備:perl実行できるかな?

Mac端末の場合、perlの実行環境がすでにある。はず。

ここではMacの場合のみ説明しますmm

ターミナルから以下のコマンドを入力して、バージョン情報を確認する。

$ perl -v

This is perl 5, version 18, subversion 2 (v5.18.2) built for darwin-thread-multi-2level (with 2 registered patches, see perl -V for more detail) Copyright 1987-2013, 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 http://www.perl.org/, the Perl Home Page.

※コマンドの表示結果は私のPCの例なので、参考までに。。

プログラム書こう

1.ファイルの作成

ターミナルから以下のコマンド入力

$ vi hello_world.pl

これでhello_world.plという名前のファイルが作成され、、という感じです。

ファイルの作成は最後の反映までいかないとされませんが、とりあえず作り始めみたいなイメージです。なのでこの時点で作成はされていません。

2.新規のファイルに以下をコピペ

# 文法のチェック
use strict;
use warnings;
# 画面出力
print "Hello World¥n"

3.ファイルのセーブ

ターミナルから以下のコマンド入力

escキー、:wqの順番に入力。これで先ほどコピーした内容が反映され、ファイルが作成されます。

いざ、実行!

ターミナルから以下のコマンドを入力

$ perl hello_world.pl
Hello world