На самом деле Windows-> Предпочтения-> Java-> установленный не показывает Вам то выполнения Eclipse под, но только JRE по умолчанию, что выполняет вещи под.
Для наблюдения того Eclipse работает под, перейдите к Справке-> О Eclipse Platform-> Детали Конфигурации и ищите свойство eclipse.vm.
, Например:
eclipse.vm=C:\Program Files\Java\jre6\bin\client\jvm.dll
my @files = glob "$dir/*.txt";
for (0..$#files){
$files[$_] =~ s/\.txt$//;
}
достаточно изменить одну строку:
my @files= map{s/\.[^.]+$//;$_}grep {/\.txt$/} readdir DIR;
If you can use the new features of Perl 5.10, this is how I would write it.
use strict;
use warnings;
use 5.10.1;
use autodie; # don't need to check the output of opendir now
my $dir = ".";
{
opendir my($dirhandle), $dir;
for( readdir $dirhandle ){ # sets $_
when(-d $_ ){ next } # skip directories
when(/^[.]/){ next } # skip dot-files
when(/(.+)[.]txt$/){ say "text file: ", $1 }
default{
say "other file: ", $_;
}
}
# $dirhandle is automatically closed here
}
Or if you have very large directories, you could use a while
loop.
{
opendir my($dirhandle), $dir;
while( my $elem = readdir $dirhandle ){
given( $elem ){ # sets $_
when(-d $_ ){ next } # skip directories
when(/^[.]/){ next } # skip dot-files
when(/(.+)[.]txt$/){ say "text file: ", $1 }
default{
say "other file: ", $_;
}
}
}
}
To get just the ".txt" files, you can use a file test operator (-f : regular file) and a regex.
my @files = grep { -f && /\.txt$/ } readdir $dir;
Otherwise, you can look for just text files, using perl's -T (ascii-text file test operator)
my @files = grep { -T } readdir $dir;
Просто используйте это:
my @files = map {-f && s{\.txt\z}{} ? $_ : ()} readdir DIR;