Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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"; }

In reply to Building scalar from File::Find by sunadmn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-19 05:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found