File extension is in extensions list: Difference between revisions

→‎{{header|Perl 6}}: handle extensions the Unix Way, agnostically
(→‎{{header|Perl 6}}: handle extensions the Unix Way, agnostically)
Line 83:
a/b/c\d/foo: true</pre>
=={{header|Perl 6}}==
<lang perl6>mysub ext-in-list(@ext,@files) = < .c .o >;{
for @files {
when / :i @ext $ / { say "$_True\t$/ is in the list_" }
when / '.' <-[/.]>*+ $ / { say "$_False\t$/ is not in the list_" }
default { say "$_----\t (has no extension)$_" }
}
}
 
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}}
<pre>True foo.C .C is in the listc
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}}==
Anonymous user