У меня есть каталог с файлами изображений foo_0.jpg
до foo_99.jpg
. Я хочу скопировать файлы с foo_0.jpg
по foo_54.jpg
.
Возможно ли это, просто используя подстановочные знаки bash?
Я думаю что-то вроде cp foo_ [0-54] .jpg
, но я знаю, что это выбирает 0-5
и 4
(верно?)
Кроме того, если это невозможно (или эффективно) с использованием только подстановочных знаков, что было бы лучше сделать это?
Спасибо.
-121--718400-
Что мне не хватает в следующей цепочке подтипов и принуждения? Я хотел бы иметь возможность принудительно вызвать ссылку на массив проверенных типов или умереть из следующих входных данных:
Предположим, что все типы полностью namespaced и что необъявленные функции validate
и coerce_str
validate (возвращающие bool) и принуждение и возвращают допустимую строку из ввода соответственно.
subtype 'CustomType'
=> as 'Str'
=> where { validate($_) }
;
coerce 'CustomType'
=> from 'Str'
=> via { if (my $coerced = coerce_str($_)) {
return $coerced;
}
return $_;
}
;
subtype 'ArrayRefofCustomTypes'
=> as 'ArrayRef[CustomType]'
;
coerce 'ArrayRefofCustomTypes'
=> from 'CustomType'
=> via { [ $_ ] }
;
has 'values' => ( is => 'ro', required => 1,
isa => 'ArrayRefofCustomTypes',
coerce => 1,
);
Я знаю, что CustomType работает; поскольку я могу определить атрибут как он и инициализировать объект, используя либо приводимую строку, либо уже действительную строку. Я не совсем уверен, как это сделать, так это явно обрабатывать вхождение в переданную ссылку на массив из конструктора и индивидуальную проверку всех содержащихся строк. Я прочитал документацию по глубокому принуждению ( http://search.cpan.org/dist/Moose/lib/Moose/Manual/Types.pod#Deep_coercion ) пару раз, и я просто не совсем понимаю и надеюсь, что кто-то может указать мне правильное направление. Спасибо!
Здесь я сократил его, чтобы обрисовать более лаконично, но:
{
package My::Class;
use strict;
use warnings;
use Moose;
use Moose::Util::TypeConstraints;
subtype 'CustomType'
=> as 'Str'
=> where { validate($_) }
;
coerce 'CustomType'
=> from 'Str'
=> via { if (my $coerced = coerce_str($_)) {
return $coerced;
}
return $_;
}
;
subtype 'ArrayRefofCustomTypes'
=> as 'ArrayRef[CustomType]'
;
coerce 'ArrayRefofCustomTypes'
=> from 'CustomType'
=> via { [ $_ ] }
;
has 'values' => ( is => 'ro', required => 1,
isa => 'ArrayRefofCustomTypes',
coerce => 1,
);
sub validate {
my $val = shift;
if ($val =~ /^\w+$/) {
return 1;
}
return ();
}
sub coerce_str {
my $val = shift;
$val =~ s/\W/_/g;
return $val;
}
}
{
package main;
use strict;
use warnings;
use Test::More qw/no_plan/;
new_ok( 'My::Class' => [ values => [ 'valid' ] ]); #ok
new_ok( 'My::Class' => [ values => [ qw/valid valid still_valid/ ] ]); #ok
new_ok( 'My::Class' => [ values => 'valid' ]); # ok
new_ok( 'My::Class' => [ values => [ 'invalid; needs some coercion - ^&%&^' ] ]); #not ok
new_ok( 'My::Class' => [ values => 'invalid; needs some coercion - ^&%&^' ]); # not ok
cmp_ok( My::Class::coerce_str('invalid; needs some coercion - ^&%&^'), 'eq', 'invalid__needs_some_coercion________', 'properly coerces strings'); #ok
}
Выполнение этого как есть дает мне следующее. Проблема не в проверке, а в том, что я явно не определяю свои приведения, и я не уверен, что мне не хватает:
ok 1 - The object isa My::Class
ok 2 - The object isa My::Class
ok 3 - The object isa My::Class
not ok 4 - new() died
# Failed test 'new() died'
# at testcoercion.pl line 63.
# Error was: Attribute (values) does not pass the type constraint because: Validation failed for 'ArrayRefofCustomTypes' with value [ "invalid; needs some coercion - ^&%&^" ] at C:/strawberry/perl/site/lib/Moose/Meta/Attribute.pm line 1131
<< cut >>
not ok 5 - new() died
# Failed test 'new() died'
# at testcoercion.pl line 64.
# Error was: Attribute (values) does not pass the type constraint because: Validation failed for 'ArrayRefofCustomTypes' with value "invalid; needs some coercion - ^&%&^" at C:/strawberry/perl/site/lib/Moose/Meta/Attribute.pm line 1131
<< cut >>
ok 6 - properly coerces strings
1..6
# Looks like you failed 2 tests of 6.