Anonymous user
Extract file extension: Difference between revisions
→{{header|Perl 6}}: use the new test-cases, and compare output to the built-in .extension method
m (→{{header|REXX}}: changed comments and whitespace.) |
(→{{header|Perl 6}}: use the new test-cases, and compare output to the built-in .extension method) |
||
Line 10:
If your programming language (or standard library) has built-in functionality for extracting a filename extension, show how it would be used
{{task heading|Specification}}
Line 31:
|
|-
| <code>
| <code>.
|
|-
Line 801:
=={{header|Perl 6}}==
The built-in <code>
<lang perl6>say $path.IO.extension;</lang>
Contrary to this task's specification, it
* doesn't include the dot in the output
* doesn't restrict
Here's a custom implementation which does satisfy those requirements:▼
<lang perl6>sub extension (Str $filename --> Str) {▼
$filename.match(/:i ['.' <+alpha-[_]>+]? $ /).Str▼
}</lang>
Testing:
<lang perl6>
for <
CharacterModel.3DS
.desktop
document
/etc/pam.d/login
>;</lang>
{{out}}
<pre>
http://example.com/download.tar.gz ".gz" "gz"
CharacterModel.3DS ".3DS" "3DS"
.desktop ".desktop" "desktop"
document "" ""
document.txt_backup "" "txt_backup"
/etc/pam.d/login "" ""
</pre>
|