Hi Satya,
On Fri, 13 Jul 2012 15:38:20 +0000
"Nemana, Satya" <[email protected]> wrote:
> Hi
>
> I have written a small program like this to just print file2 from the second
> element of the array by removing the .template from the entry (the name file2
> can change and can be longer or shorter)
>
> use strict;
> use Data::Dumper;
> use warnings;
>
> my @templates = (
> "/a/b/c/d/e/f/file1.template",
> "/a/b/c/d/e/f/file2.template"
> );
>
> my @tokens=split( /\//, $templates[1]);
> print("\n".substr($tokens[$#tokens],0,-9));
>
> However I want this to be more efficient and want to do this in a single line
> as I have to do this several times.
> How can I do that?
>
See File::Basename - http://perldoc.perl.org/File/Basename.html . In the
future, you may wish to use regular expressions for similar tasks:
http://perl-begin.org/topics/regular-expressions/
Regarding achieving stuff in one line, see:
http://www.shlomifish.org/humour/fortunes/show.cgi?id=newline-prices
and if you're so concerned about that, you can always write subroutines to
encapsulate commonly done tasks.
Regards,
Shlomi Fish
> TIA,
>
> Regards,
> Satya
>
>
>
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
Escape from GNU Autohell - http://www.shlomifish.org/open-source/anti/autohell/
Beliefs are what divide people. Doubt unites them.
— http://en.wikiquote.org/wiki/Peter_Ustinov
Please reply to list if it's a mailing list post - http://shlom.in/reply .
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/