Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Anyone want to compress this a little more?

by naveed010 (Acolyte)
on Jan 11, 2008 at 14:58 UTC ( [id://661889]=perlquestion: print w/replies, xml ) Need Help??

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

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Anyone want to compress this a little more?

Replies are listed 'Best First'.
Re: Anyone want to compress this a little more?
by olus (Curate) on Jan 11, 2008 at 15:45 UTC
    I'd suggest that instead of worrying about compressing the code, you focused on making it readable.
    Good software is one that, besides running properly, is easily understandable.

    update
    This is not a challenge to compress the code.
    The title should be 'Debug this for me'!
    I rearranged the code and, instead of making it shorter, I made it longer. But still, I think it shows better what (I think) you are trying to do.
    my $workDir = "/workdir"; my $oraLogin = "user/password@database"; my @filesToLoad = ( { "FileName" => 'file1.dat', "FileLoc" => 'dir1'}) +; foreach my $fileToLoad (@filesToLoad) { my $fileToLoadPath = "$workDir/$fileToLoad{'FileLoc'}"; opendir CTLDIR, $dileToLoadPath; my @allFiles = readdir(CTLDIR); closedir CTLDIR; #my @ctlFiles = grep { /\.run_ctl/i && -f $workingDir/$_} readdir( +CTLDIR); #what is workingDir? aren't all .run_ctl files? my @ctlFiles = grep { /\.run_ctl/i} @allFiles; + my @sqlFiles = grep { /\.run_sql/i} @allFiles; loader($fileToLoadPath, \@ctlFiles); loader($fileToLoadPath, \@sqlFiles); } sub loader { my $path = shift; my $fileList = shift; foreach my $file (@{ $fileList }) { system("sqlldr $oraLogin $path/$file rows=10000 errors=99999 $ +path/sqlldr.log"); } }
Re: Anyone want to compress this a little more?
by Anonymous Monk on Jan 11, 2008 at 19:48 UTC

    OK, I've cleaned it up, compiled it, using olu's help.

    olus, your help was great, but I need to call SQLplus on the sql files and SQL*Loader with the ctl files, but it was the guidance I needed (as well as the kick in the rear ;)

    Thanks again for the help folks.

    my $workDir = './whatever'; my $oraLogin = 'user/password\@database'; my @filesToLoad = ( { "FileName" => 'datfile.dat',"FileLoc" => 'filedir',"OKFile" => "O +K.htm"}); chdir($workDir); foreach my $fileToLoad (@filesToLoad) { my $fileToLoadPath = "$workDir/$fileToLoad{'FileLoc'}"; my $dataFile = "$fileToLoadPath/$fileToLoa{'FileName'}"; my $okFile = "$fileToLoadPath/$fileToLoad{'OKFile'}"; if ($fileToLoad{'OKFile'}!="NO" && -e $dataFile ) { #remove OK file if (-e $okFile) {rm("$okFile");} #load available files opendir CTLDIR, $fileToLoadPath; my @allFiles = readdir(CTLDIR); closedir CTLDIR; # build array of files my @ctlFiles = grep {/\.run_ctl/i} @allFiles; my @sqlFiles = grep {/\.run_sql/i} @allFiles; #execute the files SQLloader($fileToLoadPath, \@ctlFiles); SQLplus ($fileToLoadPath, \@sqlFiles); } } sub SQLloader { my $path = shift; my $fileList = shift; foreach my $file (@{ $fileList }) { system("sqlldr $oraLogin control=$path/$file rows=10000 error +s=99999 $path/sqlldr.log"); } } sub SQLplus { my $path = shift; my $fileList = shift; foreach my $file (@{ $fileList }) { system("sqlplus $oraLogin \@$path/$file"); } }
Re: Anyone want to compress this a little more?
by olus (Curate) on Jan 11, 2008 at 17:03 UTC
    Now for a really compressed version
    #!/usr/bin/perl opendir D %{$fileToLoad$i}; opendir D %{$fileToLoad$i};
    Both scripts, your code and the above, produce the same output:
    Scalar found where operator expected at err.pl line 6, near "$fileToLo +ad$i" (Missing operator before $i?) Scalar found where operator expected at err.pl line 14, near "$fileToL +oad$i" (Missing operator before $i?) syntax error at err.pl line 6, near "$fileToLoad$i" Missing comma after first argument to opendir function at err.pl line +6, near "};" syntax error at err.pl line 14, near "$fileToLoad$i" Missing comma after first argument to opendir function at err.pl line +14, near "};" Execution of err.pl aborted due to compilation errors.
      While I thought the original question was lacking something, I also think your response is not particularly useful either.

      The original poster should use the <code> tags to show the program in the correctly formatted way. If they had done that, the two lines which you chose to discuss would have kept their square-brackets, and thus worked much better than you indicate. If you look closely, the $i is underlined, as $i, because perlmonks writeup ate the brackets, not because the poster's program itself was broken (in that way).

      To the original poster: an impersonal general request like "here's some code to improve if you like" won't gather as much useful response as a direct or specific question. Even "I'm not happy with the way this code looks, how would you make it better?" would probably be enough to get more folks interested in collaborating. In brief, if it doesn't sound like you care about it yourself, why should we?

      --
      [ e d @ h a l l e y . c c ]

        I think the original post lacks a lot of things, and <code> is the least of them.
        Had he used the <code> tags, compile errors would still appear.

        The <code> tag would not make the comma show up on opendir lines neither help in resolving $workingDir to be $workDir or even $fileToLoad[$i] as an item of @filesToLoad

        Since the question is not asking what on earth is the code doing or why it was not working, he challenged everyone tho write something that does the same, but smaller.

        Add the square brackets to both scripts and the output will still be the same for both.
        Sincerest apologies to all, and thank you ed for the constructive response. I'm new to the monks site. I do care about it. I'm in the process of writing it, haven't compiled it yet and the thought came to me, there must be a way to compress this down such that I don't need to cut/paste/tweak the same 6 lines. I just tossed it out there as an afterthought as I continute to grind this out. I had hoped my breif explanation at the top of the message was sufficient to explain what I was trying to do. Again, sorry.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://661889]
Approved by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-20 04:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found