http://www.perlmonks.org?node_id=924971

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

SO i finally have the time to make a thread program that is so complicated it breaks perl. (documented perl thread bug they havent fixed yet)Then i get stuck on this stupidity.I feel like a moron. But ive tried 100 things. At this point im not going to stop until it gets done the way i want it no matter how long it takes.

All im trying to do is move the bloody file a new directory. Which works perfectly fine in the first half... Not in the second.

If anyone can help me figure out why i sure would appreciate it.

EVERYTHING BELOW WORKS perfectly fine. But is included for completeness. ########## PROBLEM IS HERE is where the problem is.

I have tried moving it up a DIR .. , tried renaming. tried deleteing... ad nasuem...

use Win32::Autoglob; use Cwd; my $keepgoing="keepgoing"; my @globline;my @argdata; my $mastercount =0; my $chunklock="orderlock.cfg"; my $successcheck = "successcheck.cfg"; my $chunksuccesscount="successlog1.cfg"; my $orderline="orderline.cfg"; my $trackingversion = 0; # 0 is ORDER 1 = Tracking # DoOrd.pl * #### SHIPPINGVERSION #system("pause"); if ($trackingversion == 0) { foreach my $thing (@ARGV) {if (($thing =~ /A-/) && ($thing =~ /.txt/)) + {push (@argdata, $thing)} } # REPLACE FILENAME (ADD A UNIQUE NUMBER) + MOVE TO LIMBO foreach (@argdata) { @datain=();$oldfilename = $_;open(DGRAB, $oldfile +name ) || die ("Could not open $oldfilename (DATA TO GRAB) \n"); whil +e (<DGRAB>) {push(@datain, $_)};close DGRAB; my $movefilename = @datain[2];$movefilename =~ s/ /-/g;$movefilename = +~ s/[^\w\d()-]+//g;my $range = 8999;my $minimum = 1000;my $random_num +ber = int(rand($range)) + $minimum; $movefilename = "A-" . $movefilename . "--" . $random_number . ".txt"; push (@newargdata, $movefilename);system("move $oldfilename limbo/$mov +efilename"); } # FOREACH # ASSIGN NEW FILENAME FROM ORDERNAME @argdata = @newargdata; # DUPLICATE FOR MULTIPLE QUANTITIES foreach (@argdata) {@datain=();my $originalfilenamequantity= "";$filen +amequantity = "limbo/" . $_;open(DGRAB, $filenamequantity ) || die (" +Could not open $filenamequantity (DATA TO GRAB) \n"); while (<DGRAB>) + {push(@datain, $_)};close DGRAB;print "$filenamequantity LOADED \n"; foreach (@datain) { if ($_ =~ /QUANTITY:::/) {print "Q \n";@quantitysp +lit1 = split(/QUANTITY:::/, $_);@quantitysplit2 = split(/:::/, @quant +itysplit1[1]);$quantityvalue=@quantitysplit2[0];print "@quantitysplit +1[1] Quantityvalue: $quantityvalue \n\n";}} # DUPLICATE ORDER BASED ON QUANTITY AMOUNTS if ($quantityvalue > 1) {my $originalfilenamequantity=$filenamequantit +y; # CREATE DUPLICATES BASED ON QUANTITY for ( my $count = 1; $count <= $quantityvalue; $count++) {@copydatain= +();open(DGRAB, $filenamequantity ) || die ("Could not open $filenameq +uantity (DATA TO GRAB) \n"); while (<DGRAB>) {push(@copydatain, $_)}; +close DGRAB; my $copydatainstring = join('',@copydatain);my $quantitytoreplacestrin +g = "QUANTITY:::" . $quantityvalue . ":::";$copydatainstring =~ s/$qu +antitytoreplacestring/QUANTITY:::1:::/; my $duplicatefilenamequantity = $filenamequantity . $count;open (DGRAB +, ">$duplicatefilenamequantity");print DGRAB "$copydatainstring";clos +e(DGRAB); } # IF $quantityvalue > 1 ########## PROBLEM IS HERE ########## PROBLEM IS HERE ########## PROBLEM IS HERE # MOVE ORIGINAL TO ../Done/M-archiv # $originalfilenamequantity =~ s/limbo\///; # tried short fuilenames l +ong filenames... yada yada $currentdir = getcwd;$originalfilenamequantity = $currentdir . "/" . +$originalfilenamequantity;print "Currentdir : $currentdir \n FILE: :$ +originalfilenamequantity: \n"; print "move $originalfilenamequantity 1.txt \n"; system("move $originalfilenamequantity .."); } # FOREACH (@datain) } # foreach die; ########## PROBLEM IS HERE ########## PROBLEM IS HERE ########## PROBLEM IS HERE
################################################ ################################################ ################################################ ################################################ ################################################
Z:\SALESD~1\LOGS\ORDERS\0-ORDER>DoOrd.pl * limbo/A-Chad-Black(GI)--2429.txt LOADED Q 1::: Quantityvalue: 1 limbo/A-Mickey-Carpenter(JJ)--4891.txt LOADED Q 2::: Quantityvalue: 2 Currentdir : Z:/SALESD~1/LOGS/ORDERS/0-ORDER FILE: :Z:/SALESD~1/LOGS/ORDERS/0-ORDER/limbo/A-Mickey-Carpenter(JJ)-- +4891.txt: move Z:/SALESD~1/LOGS/ORDERS/0-ORDER/limbo/A-Mickey-Carpenter(JJ)--489 +1.txt 1.tx t The system cannot find the path specified. limbo/A-Bob-Denk(HC)--3621.txt LOADED Q 3::: Quantityvalue: 3 Currentdir : Z:/SALESD~1/LOGS/ORDERS/0-ORDER FILE: :Z:/SALESD~1/LOGS/ORDERS/0-ORDER/limbo/A-Bob-Denk(HC)--3621.txt +: move Z:/SALESD~1/LOGS/ORDERS/0-ORDER/limbo/A-Bob-Denk(HC)--3621.txt 1. +txt The system cannot find the path specified. Press any key to continue . . . Died at Z:\SALESD~1\LOGS\ORDERS\0-ORDER\DoOrd.pl line 48. Z:\SALESD~1\LOGS\ORDERS\0-ORDER>

Replies are listed 'Best First'.
Re: FIle Directory Problem Driving me crazy.
by luis.roca (Deacon) on Sep 09, 2011 at 01:10 UTC

    Hi Monkomatic,

    I took a shot at fixing your code. A lot of errors were returned (75 exactly) nearly all having to do with undeclared variables. Here's the list if you want to add it to the top of your script:

    my @datain; my $oldfilename; my @newargdata; my $filenamequantity; my @quantitysplit1; my @quantitysplit2; my $quantityvalue; my @copydatain; my $currentdir;

    There is also a missing curly brace or bracket somewhere in your script but I figured I'd let you have fun with that one :-)) Hope this helps.


    "...the adversities born of well-placed thoughts should be considered mercies rather than misfortunes." — Don Quixote
Re: FIle Directory Problem (w/Perl::Tidy)
by luis.roca (Deacon) on Sep 09, 2011 at 00:32 UTC

    I quickly reformatted this with Perl::Tidy straight out of the box (no options). Check it out. It was fun to use. ;-)

    #!/usr/bin/perl use strict; use warnings; use diagnostics; use Data::Dumper; use Win32::Autoglob; use Cwd; my $keepgoing = "keepgoing"; my @globline; my @argdata; my $mastercount = 0; my $chunklock = "orderlock.cfg"; my $successcheck = "successcheck.cfg"; my $chunksuccesscount = "successlog1.cfg"; my $orderline = "orderline.cfg"; my $trackingversion = 0; # 0 is ORDER 1 = Trackin +g # DoOrd.pl * #### SHIPPINGVERSION #system("pause"); if ( $trackingversion == 0 ) { foreach my $thing (@ARGV) { if ( ( $thing =~ /A-/ ) && ( $thing =~ /.txt/ ) ) { push( @argdata, $thing ); } } # REPLACE FILENAME (ADD A UNIQUE NUMBER) + MOVE TO LIMBO foreach (@argdata) { @datain = (); $oldfilename = $_; open( DGRAB, $oldfilename ) || die("Could not open $oldfilename (DATA TO GRAB) \n"); while (<DGRAB>) { push( @datain, $_ ) } close DGRAB; my $movefilename = @datain[2]; $movefilename =~ s/ /-/g; $movefilename =~ s/[^\w\d()-]+//g; my $range = 8999; my $minimum = 1000; my $random_number = int( rand($range) ) + $minimum; $movefilename = "A-" . $movefilename . "--" . $random_number . + ".txt"; push( @newargdata, $movefilename ); system("move $oldfilename limbo/$movefilename"); } # FOREACH # ASSIGN NEW FILENAME FROM ORDERNAME @argdata = @newargdata; # DUPLICATE FOR MULTIPLE QUANTITIES foreach (@argdata) { @datain = (); my $originalfilenamequantity = ""; $filenamequantity = "limbo/" . $_; open( DGRAB, $filenamequantity ) || die("Could not open $filenamequantity (DATA TO GRAB) \n") +; while (<DGRAB>) { push( @datain, $_ ) } close DGRAB; print "$filenamequantity LOADED \n"; foreach (@datain) { if ( $_ =~ /QUANTITY:::/ ) { print "Q \n"; @quantitysplit1 = split( /QUANTITY:::/, $_ ); @quantitysplit2 = split( /:::/, @quantitysplit +1[1] ); $quantityvalue = @quantitysplit2[0]; print "@quantitysplit1[1] Quantityvalue: $quantityvalu +e \n\n"; } } # DUPLICATE ORDER BASED ON QUANTITY AMOUNTS if ( $quantityvalue > 1 ) { my $originalfilenamequantity = $filenamequantity; # CREATE DUPLICATES BASED ON QUANT +ITY for ( my $count = 1 ; $count <= $quantityvalue ; $count++ +) { @copydatain = (); open( DGRAB, $filenamequantity ) || die("Could not open $filenamequantity (DATA TO GR +AB) \n"); while (<DGRAB>) { push( @copydatain, $_ ) } close DGRAB; my $copydatainstring = join( '', @copydatain ); my $quantitytoreplacestring = "QUANTITY:::" . $quantityvalue . ":::"; $copydatainstring =~ s/$quantitytoreplacestring/QUANTITY:::1:::/; my $duplicatefilenamequantity = $filenamequantity . $c +ount; open( DGRAB, ">$duplicatefilenamequantity" ); print DGRAB "$copydatainstring"; close(DGRAB); } # IF $quantityvalue > 1 ########## PROBLEM IS HERE ########## PROBLEM IS HERE ########## PROBLEM IS HERE # MOVE ORIGINAL TO ../Done/M-archiv # $originalfilenamequantity =~ s/limbo\///; # tried short fuilenames l +ong filenames... yada yada $currentdir = getcwd; $originalfilenamequantity = $currentdir . "/" . $originalfilenamequantity; print "Currentdir : $currentdir \n FILE: :$originalfilenamequantity: \n"; print "move $originalfilenamequantity 1.txt \n"; system("move $originalfilenamequantity .."); } # FOREACH (@datain) } # foreach die; ########## PROBLEM IS HERE ########## PROBLEM IS HERE ########## PROBLEM IS HERE


    "...the adversities born of well-placed thoughts should be considered mercies rather than misfortunes." — Don Quixote
Re: FIle Directory Problem Driving me crazy.
by repellent (Priest) on Sep 09, 2011 at 06:45 UTC
      I have tried moving it up a DIR ..
      # MOVE ORIGINAL TO ../Done/M-archiv print "move $originalfilenamequantity 1.txt \n"; system("move $originalfilenamequantity ..");

    All 4 of the above I gathered from the OP. I can't tell your intentions from your code comment and print statement.

    Some advice: it's best to use absolute paths when performing system. If you use relative paths like "..", then that is relative to the current working directory of the spawned system process (most likely the dir where you launched your program, which may change). Maybe something like this:
    my $dest = "$currentdir/.."; # means Z:/SALESD~1/LOGS/ORDERS my $cmd = "move $originalfilenamequantity $dest"; system($cmd) == 0 or warn("Failed: $cmd");

    Update: Correction by anonymonk.

      system($cmd) or warn("Failed: $cmd");

      See system and  0 == system... or warn "Failed...";

Re: FIle Directory Problem Driving me crazy.
by AnomalousMonk (Archbishop) on Sep 08, 2011 at 23:35 UTC

    I look at the three wadges of code in this post and I think "The problem ain't just there!". Beyond that, I don't know what to say.

      I know that why its driving me NUTS....

      gonna keep at it till its done though.... :) And it says its the path not the file not found...

        Gentle Monkomatic, please do yourself a huge favor and re-format the code of the OP (if that is, indeed, what you are dealing with) into human-readable form before you go any further. I haven't used it myself, but I hear nice things said about Perl::Tidy.

Re: FIle Directory Problem Driving me crazy.
by Voronich (Hermit) on Sep 09, 2011 at 13:12 UTC

    What happens when you add

    use strict; use warnings;

    Then fix all that?
    Me
Re: FIle Directory Problem Driving me crazy.
by Anonymous Monk on Sep 09, 2011 at 00:01 UTC
Re: FIle Directory Problem Driving me crazy.
by Mr. Muskrat (Canon) on Sep 12, 2011 at 20:55 UTC
    move Z:/SALESD~1/LOGS/ORDERS/0-ORDER/limbo/A-Bob-Denk(HC)--3621.txt 1. +txt The system cannot find the path specified.

    This tells me that the move to limbo did not work.