LoginSignup
1
1

More than 5 years have passed since last update.

Perl6 の File Test operators

Posted at

こんばんは :whale2:
Perl 6 Advent Calendar 2015の13日目です。

今日はFile Test operatorsについて

File Test operators

operator description
:e Exists
:d Directory
:f File
:l Symbolic link
:r Readable
:w Writable
:x Executable
:s Size
:z Zero size

使い方

ファイルが存在するか

  • Perl5 では -e 検査対象 と書いていました。
use v5.18;

my $exists = '.bash_profile';

if( -e $exists ){
  say 'Exists'; #=> Exists
}
  • Perl6 ではこんな感じに書きます。
use v6;

my $exists = '.bash_profile';

if $exists.IO.e {
  say 'Exists'; #=> Exists
}
  • [参考] testコマンド
$ test -e .bash_profile && echo $?
0

読み取り可能か

  • Perl5
use v5.18;

my $readable = '.atom/packages/japanese-menu/package.json';

if( -r $readable ) {
  say 'Readable'; #=> Readable
}

# ファイルサイズ
say -s $readable; #=> 7956
  • Perl6
use v6;

my $readable = '.atom/packages/japanese-menu/package.json';

# こんな風にも書けます
if $readable.IO ~~ :r  {
  put 'Readable'; #=> Readable
}

# ファイルサイズ
put $readable.IO.s; #=> 7956

おわりです。

参考と注釈

class IO::Path - Perl 6 Documentation

1
1
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
1
1