#!/usr/local/bin/perl use strict; use warnings; #variavle my $msg = "hello darkness\n"; #prints print $msg; print "hwdy?\n"; print "hello" . "kt"; print "hello\n" x 5; #Array&Hush my %sales = ('kate'=>150, 'yuma'=>200, 'kyoco'=>300); my @colors = ('red', 'green', 'yellow'); my @colors = qw(red green yellow); my @mixed = (150, 'green', 1.5); my @inc = (1..20); print "$sales{'yuma'}\n"; print "@colors[0..$#colors]\n"; print "$mixed[0]\n"; #Conditional branch my $score = 85; if($score >= 80){ print("good job!\n"); }elsif($score >= 40){ print("soso...\n"); }else{ print("you baaad...\n"); } print("OK!\n") if ($score >= 80); #The ternary operator my $a = 100; my $b = 20; my $max = ($a > $b) ? $a : $b; print("$max\n"); #Loop(while) my $iw = 0; while($iw < 10){ print("iw = $iw\n"); $iw++; } #Loop(for) for(my $if = 0; $if < 10; $if++){ print("if = $if\n"); } #Loop(foreach) my @colors = qw(red blue green yellow); foreach my $color(@colors){ print("color = $color\n"); } #foreach(abridgement) for(@colors){ print("color = $_\n"); } #foreach(hush) my %sales = ("kate"=>300, "yuma"=>500,"kyoco"=>700 ); foreach my $key (keys(%sales)){ print("sales for $key is $sales{$key}\n"); } for (keys %sales){ print("sales for $_ is $sales{$_}\n"); } #File In/Out #RegExp #Subroutine #print max(12, 80); sub max { my $max = shift; # @_ for (@_) { $max = $_ if $_ > $max; } $max; } print max(120, 80, 100, 200, 300, 23, 38);