in reply to Grep a word and print the filename
Hello alokranjan,
my $cname = "$File::Find::name"; #prints location of file my @chunks = split '/', $cname; $country = $chunks[4];
Update 1: Added the code snippet quotation.
If the full path+filename is /home/alok/countries/London, then the call to split produce a 4-member list. But the fourth element (London) of the array @chunks is $chunks[3], because array indices start at zero.
Update 2: alokranjan is correct, of course: the first element is the empty string. Note to self: always test before posting! Sorry for the noise. :-(
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Grep a word and print the filename
by alokranjan (Acolyte) on Aug 15, 2015 at 10:37 UTC | |
|
Re^2: Grep a word and print the filename
by alokranjan (Acolyte) on Aug 15, 2015 at 21:57 UTC |