http://qs321.pair.com?node_id=317512

sunadmn has asked for the wisdom of the Perl Monks concerning the following question:

Good day fellow monks I have the below code and have a it working for the most part but one issue I have ran into is when I build $out if there is not seven dirs I get output that looks like so:

net.somedomain......

Now the issue I would like to resolve is how can I build my $out scalar so that it will grab anything from dir 4 on and build itself from that,so if I have a file living under /net it will build $out like somedomain.net and if I have something like /us/pa/k12 it will look like somadomain.k12.pa.us and with either I wont have the trailing "." after the name if it doesn't equal seven in length. Any help you may all point out to me would be great as I am pulling my hair out trying to figure this one out right now.

Sunadmn
USE PERL
#!/usr/bin/perl use strict; use File::Find; use FileHandle; my $base = "/chroot/named/master"; my $out = "/var/tmp/current_list"; find(\&wanted, $base); sub wanted { return unless ( -f "$File::Find::name" and $File::Find::name !~ m!/ +in-addr/! ); my $name = "$File::Find::name"; my $zone = new FileHandle "$name", "r"; my $out = join('.', ( split('/', $name) )[4..7]); print "$out\n"; }