Nishi Bhonsle wrote:
> 
> On 2/16/07, John W. Krahn <[EMAIL PROTECTED]> wrote:
>> Nishi Bhonsle wrote:
>>
>> > I have a string such as
>> > instance/bit/bitGroup/default/tz/l_cs
>> > where the last directory stands for os languages.
>> >
>> > I have to get the last directory and assign it to a var such as
>> > $mylang = l_cs, in the above example.
>> > How can i achieve that?
>>
>> $ perl -le'
>> use File::Basename;
>>
>> my $string = "instance/bit/bitGroup/default/tz/l_cs";
>> my $mylang = basename $string;
>> print $mylang;
>> '
>> l_cs
>
> In case the string i am looking for is secondlast position as in
>
> instance/bit/bitGroup/default/tz/l_cs/messages
>
> How can i change the manip code to get l_cs in this case?


$ perl -le'
use File::Spec;

my $string = "instance/bit/bitGroup/default/tz/l_cs/messages";
my $mylang = ( File::Spec->splitdir( $string ) )[ -2 ];
print $mylang;
'
l_cs



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to