File extension is in extensions list: Difference between revisions

Content added Content deleted
(→‎{{header|Perl 6}}: handle extensions the Unix Way, agnostically)
Line 83: Line 83:
a/b/c\d/foo: true</pre>
a/b/c\d/foo: true</pre>
=={{header|Perl 6}}==
=={{header|Perl 6}}==
<lang perl6>my @ext = < .c .o >;
<lang perl6>sub ext-in-list(@ext,@files) {
for @files {
when / :i @ext $ / { say "True\t$_" }
when / '.' <-[/.]>+ $ / { say "False\t$_" }
default { say "----\t$_" }
}
}


ext-in-list
for < foo.C foo.zkl foo foo. > {
«
when / :i @ext $ / { say "$_\t$/ is in the list" }
.c
when / '.' <-[/.]>* $ / { say "$_\t$/ is not in the list" }
.C#
default { say "$_\t (has no extension)" }
.o
}</lang>
.yup
.½xy
'. embedded blanks '
»,
«
foo.c
foo.C
foo.C++
foo.c#
foo.zkl
somefile
'holy smoke'
afile.
/a/path/to/glory.yup/or_not
funny...
unusual.½xy
'fly_in_the_ointment. embedded blanks '
»;</lang>
{{out}}
{{out}}
<pre>foo.C .C is in the list
<pre>True foo.c
True foo.C
foo.zkl .zkl is not in the list
False foo.C++
foo (has no extension)
True foo.c#
foo. . is not in the list</pre>
False foo.zkl
---- somefile
---- holy smoke
---- afile.
---- /a/path/to/glory.yup/or_not
---- funny...
True unusual.½xy
True fly_in_the_ointment. embedded blanks
</pre>


=={{header|Python}}==
=={{header|Python}}==