Ron, Shlomi, 

I realized I haven’t thanked you.

Thanks,

Regards,
Satya
P.S : I am not a fan of one liners but as a beginner of perl there are many 
others out there who want to see the power of perl to do that in one line, it 
is just a way to be a fan of the language and then things get improved 
automatically since  you love it.

-----Original Message-----
From: Shlomi Fish [mailto:shlo...@shlomifish.org] 
Sent: 13 July 2012 17:00
To: Nemana, Satya
Cc: beginners@perl.org
Subject: Re: one liner for removing string from an element of string array

Hi Satya,

On Fri, 13 Jul 2012 15:38:20 +0000
"Nemana, Satya" <snem...@sonusnet.com> 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 .

Reply via email to