構文 |
|
qw/文字列/ |
返り値 |
|
文字列を空白文字で分割したリスト |
説明
- 指定した文字列を空白文字(スペース,タブ,改行など)で分割したリストを返します。
- 配列に文字列をいくつも代入する場合に使用すると,すっきり書くことができて便利です。
使用例
#!/usr/bin/perl
use strict;
use warnings;
my @nums1 = ('one', 'two', 'three');
my @nums2 = qw/one two three/;
print "@nums1\n";
print "@nums2\n";
#!/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";
}