Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Variable numbers of folders...

by LazerRed (Pilgrim)
on Jul 25, 2003 at 18:39 UTC ( #277935=note: print w/replies, xml ) Need Help??

in reply to Variable numbers of folders...

Something like:

opendir(DIR, $directory) or die "Failed to open $directory: $!"; while (defined($filename = readdir(DIR))) { #Do stuff to each file $filename } closedir(DIR);
You could easily wrap in a foreach block if you have multiple directories specified.


Whip me, Beat me, Make me use Y-ModemG.

Update: Also, I might add, Learning Perl and Perl Cookbook are invaluable resources to have on hand.

Replies are listed 'Best First'.
Re: Re: Variable numbers of folders...
by bioinformatics (Friar) on Jul 28, 2003 at 17:39 UTC
    I have tried to implement your suggested code into the program, but have found it isn't workig very well. Apparently, it is unable to open the directory. This could be because I'm not entering the name in a readable form, but I'm not sure. Here's where I'm at:
    #! usr/local/bin/perl print STDOUT "Hello\!\n"; print STDOUT "This program will take a folder of Affymetrix text files + and put\n"; print STDOUT "their signal data in a format useful for Cyber-T\.\n"; print STDOUT "Please enter the name and location of the directory to p +arse\:\n"; $directory=<STDIN>; open (OUTPUTFILE,">data.csv"); opendir(DIR, "$directory") or die "Failed to open $directory: $!"; while (defined(@filename = readdir(DIR))) { @spliced_data=splice(@filename, 0, 15); foreach $_(@filename) { ($a, $b, $c, $d, $e, $f)=split(/\t/); push(@final_data, "$d\n");} print OUTPUTFILE "@final_data"; } closedir(DIR);
    Thanks for your help!!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://277935]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2018-01-19 02:17 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (215 votes). Check out past polls.