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

Hi Monks, I am bit stuck with a process, actually I have a tab separated file wi +th 3 columns(shown below), what I am trying to do is read this file a +nd the sending column 3 values to a database on the internet and when + the files are recieved it should write in a file in the directory wi +th the name of the directory as column1_column2(Ex: reme_9625) and th +is process should be done for whole file.
open(FH,"upload") or die "Check The File"; while(<FH>) { chomp $_; my @temp = split(/\t/,$_); my $gene=$temp[0]; my $geneid=$temp[1]; my $string=$temp[2]; mkdir "$gene-$geneid" or die "Could not make the directory"; print "$gene-$geneid\n"; }
File looks like<br> REME 9625 17[CHR] AND 76705160:76721740[CHRPOS] ABNM 369 X[CHR] AND 47305522:47316264[CHRPOS] BCKD 1029 16[CHR] AND 31027249:31031422[CHRPOS]
Actually I am a new to perl and past 3 days I am trying to work it out +. Any help will greatly be appreciated...

Replies are listed 'Best First'.
Re: automatic web query and writing files in a directory
by moritz (Cardinal) on Jun 07, 2007 at 17:29 UTC
    First of all, please put only code in <code>-Tags, you can seperate paragraphs with the <p>-Tag.

    You should have a look at perlopentut and split, they should do much of your work.

    How are you planning to connect the database "on the internet"?

    Maybe you'll need DBI as well

      Hi , There is a program available form that website only which fetches the results, well its working fine,.... When I submit the file contatining the columns it fetches the results. No problem till here.....but I want that for each query returned it should make a folder on the local machine with name as column1_column2...............here i am stuck.... once again thanks for replying.......
Re: automatic web query and writing files in a directory
by Grundle (Scribe) on Jun 07, 2007 at 20:57 UTC
    my $basepath = "c:\\foo\\bar"; my $dir = $basepath."\\".$gene."_".$geneid; mkdir($dir, 0755) or die "Failed creating $dir\n"; chdir($dir); #what file are you writing? That is so ambiguous. Let us pretend $st +ring is your file contents and I will make up a filename becuase you +weren't specific about that either. my $file = "baz.txt"; open(OUT, ">>$file") or die "Cannot open $file for writing\n"; print OUT $string; close(OUT);
      Thanks Grundle, Actually i want it to make automatic, the code should fetch the data from the website and write the file, check wheather the file is written in the specied folder then pause for a moment and then start to fetch another file and repeat the process.... If its possible then I will send u the whole code and file for which I want to automate the process....

        There's always the drastic step of reading the docs for something like WWW::Mechanize, HTML::TableContentParser, sleep or somesuch yourself, rather than relying on Grundle to do your coding for you... Plus you'll be in a much better position to help yourself later on if something ever happens to Grundle (heaven forbid)...

        HTH,

        planetscape