[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
【文字列の変数への代入】
文字列は「'」または「"」で囲んで代入する
- $a = 'test';
- $a = "test";
【文字列の連結】
文字列を「.」で連結する
- $a = 'test'.'study';
【文字列の繰り返し】
- $a = 'test';
- $b = $a x 5;
数値データのsort(昇順) | @nums = sort {$a <=> $b} @nums; |
foreach (sort {$a <=> $b} keys(%data)) { } |
|
数値データのsort(降順) | @nums = sort {$b <=> $a} @nums; |
文字列データのsort(昇順) | @strs = sort {$a cmp $b} @strs; |
foreach (sort {$a cmp $b} keys(%data)) { } |
|
文字列データのsort(降順) | @strs = sort {$b cmp $a} @strs; |
[Perl目次]へ戻る
【if elsif else】
if ( ) {
} elsif { ←注)elseif ではない
} else {
}
【switch case】
use Switch;
switch ($flg) {
case 1 {
}
case "a" {
}
else {
}
}
[Perl目次]へ戻る
【半角カタカナに変換(Perl5.8以降)】
use Encode;
use Encode::JP::H2Z;
Encode::from_to($str, "sjis", "euc-jp");
Encode::JP::H2Z::z2h(\$str);
Encode::from_to($str, "euc-jp", "sjis");
### 全角へはEncode::JP::H2Z::h2z(\$str); ###
【半角カタカナに変換(旧Perl)】
require "jcode.pl";
jcode::convert(\$str, "sjis", "", "h");
### jcode.pl → 漢字等の処理を行う ###
### 全角へは jcode::convert(\$str, "sjis", "", "z"); で、できるはずだけど、使えなかった ###
【全角カタカナに変換(旧Perl)】
require "jcode.pl";
&jcode::h2z_sjis(\$str);
[Perl目次]へ戻る