Hi,

I need to search 3 different servers and list the output of the directories to a specific file for each server. I understand how declare the constant(s) but unsure of how to iterate through all of the constants and list the file output. Any ideas would be helpful.

Perlnewbe

#!/usr/local/bin/perl

use strict;
use warnings;

use IO::File;
use File::Find;

use constant Dir1 => "//servvername/dir/";
use constant Dir2 => "//servername/dir/";
use constant Dir3 => "//servername/dir/";

open (DEST, '>c:/servername.txt') or die "Unable to open the destination file";

find (\&process_file, $constant;

sub process_file {

      print $File::Find::name, -d && "/", "\n";
      print DEST $File::Find::name, -d && "/", "\n",;
}

close (DEST)

Instead of using separate scalar constants you could use an array of constants that you can iterate through.

#!/usr/bin/perl
use strict;
use warnings;

# Use a constant array instead of separate constants
use constant SERVERNAMES => qw(//firstserver/somedir/
                            //secondserver/somedir/
                            //thirdserver/somedir/);
                            
foreach my $srvr (SERVERNAMES) {
    print "$srvr \n";
}

What he said! The thing is perlnewb... look at learning more about arrays and hashes. These are the tools that can improve your perl greatly. THEN, look at more complex data structures (arrays of hashes, hashes of arrays and real perl objects).

Good Luck!

One question (if you don't mind) what language have you started with? What language are you familiar with? It would be interesting for me to know.

What he said! The thing is perlnewb... look at learning more about arrays and hashes. These are the tools that can improve your perl greatly. THEN, look at more complex data structures (arrays of hashes, hashes of arrays and real perl objects).

Good Luck!

One question (if you don't mind) what language have you started with? What language are you familiar with? It would be interesting for me to know.

I have done programming at different times during my test engineering career using silktest, qtp, ruby and others but have never done any perl scripting. Thanks you for your help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.