6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Perlでの単独shiftとは

Posted at

perl初心者の自分ようメモです。。。。

perlでのshift関数の一般的な使い方の例

my @city = ("東京", "大阪");
my $val = shift(@city);
print "$val¥n";

→東京 と表示される

では配列変数の引数がない単独shiftはどのようになるのか。

mainモジュールでは「@ARGV」がデフォルトの引数で、sub内では、「@_」がデフォルトの引数になる。
@ARGV」は、コマンドラインの引数の配列で、「@_」は、サブルーチンの引数の配列。

◆サンプル
subx(4000);

sub subx {
my $para = shift || 3000;
print $para, "\n";
}

◆サンプル実行結果
C:\perltest>perl shift.pl
4000

6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?