関数順 インデックス
目的別 インデックス

構文
 
 qw/文字列/

返り値
 
 文字列を空白文字で分割したリスト

説明

  • 指定した文字列を空白文字(スペース,タブ,改行など)で分割したリストを返します。
  • 配列に文字列をいくつも代入する場合に使用すると,すっきり書くことができて便利です。

使用例

配列@num1と@nums2のそれぞれに値を代入する
#!/usr/bin/perl
use strict;
use warnings;

my @nums1 = ('one', 'two', 'three');
my @nums2 = qw/one two three/;

print "@nums1\n";
print "@nums2\n";
配列@dirsに値を代入する(qwでスラッシュ以外の記号を使う)
#!/usr/bin/perl
use strict;
use warnings;

my @dirs = qw(
  /usr/bin/perl
  /home/user1/.bashrc
  /etc/passwd
);

foreach my $dir (@dirs) {
  print $dir, "\n";
}

※スラッシュ以外の記号を使うこともできます。