【perl】数と文字列について復習〜vol.1

今まで、とにかくサンプルを集めてそのサンプルから分からないことを逆引きしてプログラミングしてきたが、集めた知識がなかなかつながっていく感覚がないので、当たり前ですがやっぱり基礎をしっかりとするべきかなっと。ということで、今日のブログは、数と文字列について改めて勉強をしました。

#! usr/bin/perl

use strict;
use warnings;

my $price = 2000;
print "$price\n";

print $price*0.5;
print "\n";

my $discount_price = $price*0.9;
print "$discount_price\n";

print "値段は$price円です。\n";

#ダブルクォーテーション内は、変数展開される。但し、\を前につけると変数展開されない。
print "\$price is $price\n";

$price = 3000;
print "$price is $price \n";


#シングルクォーテーション内は、変数展開されない。\を前につけるのと同義。
print '$price is a variable.';
print "\n";
print '$price is a variable.\n';
print "\n";

print '$price is a variable.', "\n";