Try:
[~]$ perl -MFile::Basename -le '@file_list = qw(aaa ddd bbb/aaa ccc
ddd kkk/ddd hhh); $,="," ; print grep { $h{$_} == 1 } grep { ++$h{$_}
} map { basename($_) } @file_list;'
ccc,hhh
[~]$ perl -le '@file_list = qw(aaa ddd bbb/aaa ccc ddd kkk/ddd hhh);
$,="," ; print grep { $h{$_} == 1 } grep { ++$h{$_} } map { (split
/\//)[-1] } @file_list;'
ccc,hhh
On Sat, Dec 18, 2010 at 7:30 PM, Sooraj S <[email protected]> wrote:
> On Dec 18, 9:07 am, [email protected] (David Christensen)
> wrote:
>> Sooraj S wrote:
>>
>> > I have an array file_list which contains absolute/relative paths of
>> > files. I want to remove duplicate elements and elements whose
>> > filenames(not the path) are same. How can i do this using grep and
>> > hash?
>>
>> You should buy the Perl Cookbook:
>>
>> http://oreilly.com/catalog/9781565922433
>>
>> This recipe should solve the first part of your problem:
>>
>> http://docstore.mik.ua/orelly/perl/cookbook/ch04_07.htm
>>
>> Add in File::Basename and you should be able to do the rest.
>>
>> HTH,
>>
>> David
>
> Hi thanks for your reply..
>
> Probably you might not have noticed my code. The first part i've
> already solved. The second part is the only one that i have asked how
> to do using grep. I have other logics also to do it.. But still i
> wanted to know if there is any better way of doing this together ie
> with a single grep command and hash.
>
>
> --
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> http://learn.perl.org/
>
>
>
--
::: Keep Smiling :::
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/