u can look at the below code.

use File::Basename;

while(<DATA>){
        my $line=$_;
        chomp;
        my $dir = dirname($line);
        print "$dir\n";
}


-----Original Message-----
From: Owen Cook [mailto:[EMAIL PROTECTED]
Sent: Thursday, December 02, 2004 2:44 PM
To: perl beginners
Subject: Re: Getting the dir structure




On Thu, 2 Dec 2004, Nilay   Puri, Noida wrote:

> 
> I have a file with thousands of line  like :
> 
> /abc/def/ijk/test.txt
> 
> /pqr/lmn/test1.t
> 
>  
> 
> I want to get the directory where the files test.txt and test1.txt are
> lying.


Try something like this

-----------------------------------------

#!/usr/bin/perl -w

use strict;

while(<DATA>){
my $line=$_;
chomp;
if(($line=~/test\.txt/) or ($line=~/test1\.txt/)){print "$`\n"}
        }

__DATA__
/abc/def/ijk/test.txt
/pqr/lmn/test1.txt


----------------------------------------

and see if it helps



Owen

ps you could probably get rid of the chomp.


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



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


Reply via email to