Skip to content

Instantly share code, notes, and snippets.

@maeharin
Created May 12, 2012 08:10
Show Gist options
  • Save maeharin/2665160 to your computer and use it in GitHub Desktop.
Save maeharin/2665160 to your computer and use it in GitHub Desktop.
perl基礎文法練習(途中)
#perl基礎文法練習(途中)
use strict;
use warnings;
#スカラー
my $number1 = 3;
my $number2 = 4;
my $result = $number1 + $number2;
print $result . "\n";
print "---\n";
#配列
my @foods = ('ラーメン', '寿司', 'カレー');
print $foods[0];
for my $food(@foods) {
print $food . "\n";
}
print "---\n";
#配列(無名リファレンス)
my $foods_ref = ['ラーメン', '寿司', 'カレー'];
print $foods_ref->[0];
for my $food_ref(@$foods_ref) { #配列のリファレンスは@でデリファレンス
print $food_ref . "\n";
}
print "---\n";
#ハッシュ
my %ore = (
name => 'maeharin',
tall => 169
);
print $ore{name} . "\n";
print $ore{tall} . "\n";
foreach my $k (keys(%ore)) {
print $k . "::" . $ore{$k} . "\n";
}
print "---\n";
#ハッシュ(無名リファレンス)
my $ore_ref = {
neme => 'maeharin',
tall => 169
};
print $ore_ref->{name}; #なんか違うっぽい
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment