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

Hey Everyone,

I just started learning pearl last week and my first 10hrs with perl has been full with excitements. I am currently developing a search enigine with perl. However, I have reached to a point I thought with help from you all I will accomplish my task.

Firstly, Is there a way in perl that I can write two seperate scripts and call one in the other? if so, could someone kindly show me how to do that?.

Secondly, I am triying to crawl through directories to be able to open subfolders and files. however, using the "readir" and "opendir" command, I am only able to see the availble subdirectories but I cannot open them. Thus could someone kindly help me with that.

EAXMPLE. I have a folder called EDMAN located at C:\views\EDMAN. within EDMAN, there are subfolders call TEDDY, SAM, JOHN. all of which has multiple xml files with them. I can only see the folders TEDDY, SAM, JOHN using the readir and opendir command but I actually want to go into each of these folders and read the content of the xml file. I am still working on it but the below code is where I have gotten so far, thus can anyone kindly help me this ?

if (opendir(SEARCH, $path) && open(DATA,">$database")) { while (defined ($search = readdir(SEARCH))) { next if $search =~ /^\.\.?$/; if (!($search =~ /.xml|.txt|.zip|include/)) { print (DATA "$search\n"); } } closedir SEARCH ; }

Edit: g0n - code tags

Replies are listed 'Best First'.
Re: Help with opening subdirectories
by Praveen (Friar) on Feb 27, 2006 at 16:02 UTC
    Try This
    use File::Find; sub process_file { if(-f $File::Find::name) { open(FILE1, $File::Find::name) || die "Cannot open file : $!"; $line1 = <FILE1>; print "$File::Find::name\n"; print $line1; } } find(\&process_file, "C:\/views\/EDMAN");
      Thanks a lot, I will try this. You and Phil are my hero
Re: Help with opening subdirectories
by philcrow (Priest) on Feb 27, 2006 at 16:00 UTC
    When you use readdir, it only gives you the file name. To open it, you must prepend the directory:
    my $full_name = "$path\$search";
    Using File::Spec makes this portable across operating systems.

    To call one script from another use either backquotes `` or system. Most people prefer system. See perldoc -f system perlfunc.

    Phil

    Edit: g0n - reparented from reaped duplicate of OP

Re: Help with opening subdirectories
by zer (Deacon) on Feb 28, 2006 at 05:40 UTC
    you are not very clear about the first question.

    "Firstly, Is there a way in perl that I can write two seperate scripts and call one in the other? if so, could someone kindly show me how to do that?."

    what are you trying to do?

    and are you using *nux or something else?