By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,178 Members | 987 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,178 IT Pros & Developers. It's quick & easy.

script

P: 12
i am trying to get these 3 scripts to work together and having problems can some one point out where the hang up is

Expand|Select|Wrap|Line Numbers
  1. open (IN, 'ALL_UIC.doc'); 
  2. open (OUT,'>>UIC_1');
  3. $outcount = 1;
  4.  
  5. while (<IN>) { 
  6.  
  7.     print OUT;
  8.  
  9.        if ( $_=~/Performance of Duty for/ )
  10.         {
  11.  
  12.  
  13.             $UIC = substr $_, 42, 5;     # extract the UIC for file name
  14.  
  15.         }
  16.  
  17.         if ( $_=~/Dollar value of unliquidated funds/ )
  18.         {
  19.  
  20.             close (OUT,'>>UIC_$outcount');
  21.  
  22.  
  23.             rename ("UIC_$outcount","POD$UIC.doc");
  24.  
  25.             $outcount++;
  26.  
  27.             open (OUT,">>UIC_$outcount");
  28.  
  29.         }
  30.  
  31.  
  32. $dir="/home/grimp/test/"
  33. opendir DIR $dir;
  34. @files=readdir DIR;
  35. closedir DIR;
  36.  
  37. foreach $file (@files) {
  38.   if (-f "$dir$file") {  # true if $dir$file is a regular file
  39.     #move $file, mv POD*.doc /home/grimp/lougp
  40.   }
  41. }
  42.  
  43.  
  44.  
  45. # Create a Zip file
  46.   use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
  47.   my $zip = Archive::Zip->new();
  48.  
  49. # Add a directory
  50.   #$dir_member = $zip->addDirectory( 'dirname/' );
  51.  
  52.  
  53. # Add a file from disk
  54.   $file_member = $zip->addFile( 'POD*.doc' );
  55.  
  56.  
  57. # Save the Zip file
  58.    unless ( $zip->writeToFileNamed('POD.zip') == AZ_OK ) {
  59.        die 'write error';
  60.    }
  61.  
Oct 13 '08 #1
Share this Question
Share on Google+
21 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
Can you please provide a better explanation of exactly what the scripts are supposed to do and what you are seeing that isn't right or is erroring out?

Also, please use code tags around code you submit to the forums.

Regards,

Jeff
Oct 13 '08 #2

P: 12
Can you please provide a better explanation of exactly what the scripts are supposed to do and what you are seeing that isn't right or is erroring out?

Also, please use code tags around code you submit to the forums.

Regards,

Jeff

ok i am new to programming and i am wanting to use the first script which works to break apart a large doc int smaller ones then i need to move the smaller docs to another dir and then zip the smaller docs into one zip file and is a code tag and html tag the same thing
Oct 13 '08 #3

numberwhun
Expert Mod 2.5K+
P: 3,503
ok i am new to programming and i am wanting to use the first script which works to break apart a large doc int smaller ones then i need to move the smaller docs to another dir and then zip the smaller docs into one zip file and is a code tag and html tag the same thing
First, thank you for your explanation, but it leaves a lot to wonder. Why don't you do all of your tasks in one script? Why break it up? Also, you have not mentioned what problems you are having with the script(s).

Regards,

Jeff
Oct 13 '08 #4

P: 12
First, thank you for your explanation, but it leaves a lot to wonder. Why don't you do all of your tasks in one script? Why break it up? Also, you have not mentioned what problems you are having with the script(s).

Regards,

Jeff

oh sorry i can not get the files to move to a different directory have been able to get one to move but not all of them would not mind doing it all in one that is the big plan first i was trying to get the syntax right unix is different than dos not that i have a lot of edperiance there either
Oct 13 '08 #5

numberwhun
Expert Mod 2.5K+
P: 3,503
oh sorry i can not get the files to move to a different directory have been able to get one to move but not all of them would not mind doing it all in one that is the big plan first i was trying to get the syntax right unix is different than dos not that i have a lot of edperiance there either
To move files, you might want to read up on the File::Copy module. Also, you might want to read up on the perlfaq's over at perldoc.perl.org as they provide a wealth of information on how to do some normal everyday things and would be really beneficial to you.

Regards,

Jeff
Oct 13 '08 #6

KevinADC
Expert 2.5K+
P: 4,059
Your code is pretty confusing to me so I am unable to suggest changes or improvements. At a minimum this line looks wrong:

Expand|Select|Wrap|Line Numbers
  1.             close (OUT,'>>UIC_$outcount');
should be:

Expand|Select|Wrap|Line Numbers
  1.             close (OUT);
Oct 13 '08 #7

Icecrack
Expert 100+
P: 174
for the actual move try this


Expand|Select|Wrap|Line Numbers
  1. $old = "$dir$file";
  2. $new = "/home/grimp/lougp";
  3. move($old, $new);
Oct 13 '08 #8

KevinADC
Expert 2.5K+
P: 4,059
there is no move() function in perl. rename() actually moves a file, or there is the File::Copy module that has a move function. Its a standard perl module so should be installed.
Oct 14 '08 #9

numberwhun
Expert Mod 2.5K+
P: 3,503
there is no move() function in perl. rename() actually moves a file, or there is the File::Copy module that has a move function. Its a standard perl module so should be installed.
The move() function is a part of the File::Copy module that I pointed him to, but you are right, its not a built-in function.
Oct 14 '08 #10

Icecrack
Expert 100+
P: 174
thank you Kevin,numberwhun, Forgot to add the use :P


Expand|Select|Wrap|Line Numbers
  1. use File::Copy;
  2.  

i looked at a script that i made to move files in a folder once a month,
i forgot to copy the use File::Copy;


thanks once again :P
Oct 14 '08 #11

KevinADC
Expert 2.5K+
P: 4,059
The move() function is a part of the File::Copy module that I pointed him to, but you are right, its not a built-in function.
My bad.... I missed that.

Perdona me. Gracias.
Oct 14 '08 #12

P: 12
My bad.... I missed that.

Perdona me. Gracias.

ok i think that makes sence but what if i want to move multiple files and keep the same names ( like PODUA87G.doc, POD87745.doc, PODQWUYT.doc) about 20 in all
Oct 14 '08 #13

numberwhun
Expert Mod 2.5K+
P: 3,503
ok i think that makes sence but what if i want to move multiple files and keep the same names ( like PODUA87G.doc, POD87745.doc, PODQWUYT.doc) about 20 in all
I would say that you could take a listing of what is in the directory, put it into an array, then cycle through the array performing the move() command on each.

Regards,

Jeff
Oct 14 '08 #14

P: 12
I would say that you could take a listing of what is in the directory, put it into an array, then cycle through the array performing the move() command on each.

Regards,

Jeff
ok how hard is an array to make the move function is causing me to loose hair already
Oct 14 '08 #15

numberwhun
Expert Mod 2.5K+
P: 3,503
ok how hard is an array to make the move function is causing me to loose hair already
Arrays are quite easy to work with. Since you are dealing with basic arrays and not arrays of arrays of hashes of arrays, you shouldn't really be pulling your hair out. Its not that bad to work with.

Here is a quick bit of code I just threw together. It is COMPLETELY UNTESTED. I have not verified it will work, but feel free to let me know if it does what you expect. You can incorporate the code you need into your script, being mindful that there are two modules being used in here:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use File::Util;
  6. use File::Copy;
  7.  
  8. ### Variables ###
  9. my $newpath = "/new/file/path/";  # where to put new files
  10. my $oldpath = "/old/file/path/";  # where files were
  11. my $newfilepath;
  12. my $oldfilepath;
  13.  
  14. # Put list of files into array
  15. my @filelist = File::Util::list_dir(/your/directory , --files-only);
  16.  
  17. # Cycle through files array and move each one to destination
  18. foreach my $file (@filelist){
  19.     $oldfilepath = $oldpath . $file;
  20.     $newfilepath = $newpath . $file;
  21.     move($oldfilepath, $newfilepath);
  22. }
Regards,

Jeff
Oct 14 '08 #16

P: 12
Arrays are quite easy to work with. Since you are dealing with basic arrays and not arrays of arrays of hashes of arrays, you shouldn't really be pulling your hair out. Its not that bad to work with.

Here is a quick bit of code I just threw together. It is COMPLETELY UNTESTED. I have not verified it will work, but feel free to let me know if it does what you expect. You can incorporate the code you need into your script, being mindful that there are two modules being used in here:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use File::Util;
  6. use File::Copy;
  7.  
  8. ### Variables ###
  9. my $newpath = "/new/file/path/";  # where to put new files
  10. my $oldpath = "/old/file/path/";  # where files were
  11. my $newfilepath;
  12. my $oldfilepath;
  13.  
  14. # Put list of files into array
  15. my @filelist = File::Util::list_dir(/your/directory , --files-only);
  16.  
  17. # Cycle through files array and move each one to destination
  18. foreach my $file (@filelist){
  19.     $oldfilepath = $oldpath . $file;
  20.     $newfilepath = $newpath . $file;
  21.     move($oldfilepath, $newfilepath);
  22. }
Regards,

Jeff
will i be able to keep the same file names
Oct 14 '08 #17

P: 12
ok ran the script
Expand|Select|Wrap|Line Numbers
  1. 1. #!/usr/bin/perl 
  2.  2.  
  3.  3. use strict; 
  4.  4. use warnings; 
  5.  5. use File::Util; 
  6.  6. use File::Copy; 
  7.  7.  
  8.  8. ### Variables ### 
  9.  9. my $newpath = "/home/grimp/lougp/";  # where to put new files 
  10. 10. my $oldpath = "/home/grimp/test/";  # where files were 
  11. 11. my $newfilepath; 
  12. 12. my $oldfilepath; 
  13. 13.  
  14. 14. # Put list of files into array 
  15. 15. my @filelist = File::Util::list_dir("/home/grimp/test" , 'POD77702.doc','POD8AUAA.doc','POD8AURB.doc'); 
  16. 16.  
  17. 17. # Cycle through files array and move each one to destination 
  18. 18. foreach my $file (@filelist){ 
  19. 19.     $oldfilepath = $oldpath . $file; 
  20. 20.     $newfilepath = $newpath . $file; 
  21. 21.     move($oldfilepath, $newfilepath); 
  22. 22. } 
  23.  
first error
(Can't locate File/Util.pm in @INC (@INC contains: /opt/perl_32/lib/5.8.3/IA64.A.
BEGIN failed--compilation aborted at array.pl line 5.)

then commented out line 5

Second error

(Bareword found where operator expected at array.pl line 15, near "/home/grimp"
(Missing operator before rimp?)
syntax error at array.pl line 15, near "/home/grimp"
Execution of array.pl aborted due to compilation errors.)

the directories exist and the files exist i am reading up on what i have about arrays but making no progress yet as i have not found is the array list a seperate scipt or is it built into the script you made

lhis is all done on an HPUX system if it matters

ok added quotes arround the dir path at line 15 now i have

this error
(Undefined subroutine &File::Util::list_dir called at array.pl line 15.)
Oct 14 '08 #18

numberwhun
Expert Mod 2.5K+
P: 3,503
will i be able to keep the same file names
I don't see why the move would change them unless you implicitly told it to.
Oct 14 '08 #19

numberwhun
Expert Mod 2.5K+
P: 3,503
ok ran the script
Expand|Select|Wrap|Line Numbers
  1. 1. #!/usr/bin/perl 
  2.  2.  
  3.  3. use strict; 
  4.  4. use warnings; 
  5.  5. use File::Util; 
  6.  6. use File::Copy; 
  7.  7.  
  8.  8. ### Variables ### 
  9.  9. my $newpath = "/home/grimp/lougp/";  # where to put new files 
  10. 10. my $oldpath = "/home/grimp/test/";  # where files were 
  11. 11. my $newfilepath; 
  12. 12. my $oldfilepath; 
  13. 13.  
  14. 14. # Put list of files into array 
  15. 15. my @filelist = File::Util::list_dir("/home/grimp/test" , 'POD77702.doc','POD8AUAA.doc','POD8AURB.doc'); 
  16. 16.  
  17. 17. # Cycle through files array and move each one to destination 
  18. 18. foreach my $file (@filelist){ 
  19. 19.     $oldfilepath = $oldpath . $file; 
  20. 20.     $newfilepath = $newpath . $file; 
  21. 21.     move($oldfilepath, $newfilepath); 
  22. 22. } 
  23.  
first error
(Can't locate File/Util.pm in @INC (@INC contains: /opt/perl_32/lib/5.8.3/IA64.A.
BEGIN failed--compilation aborted at array.pl line 5.)

then commented out line 5

Second error

(Bareword found where operator expected at array.pl line 15, near "/home/grimp"
(Missing operator before rimp?)
syntax error at array.pl line 15, near "/home/grimp"
Execution of array.pl aborted due to compilation errors.)

the directories exist and the files exist i am reading up on what i have about arrays but making no progress yet as i have not found is the array list a seperate scipt or is it built into the script you made

lhis is all done on an HPUX system if it matters

ok added quotes arround the dir path at line 15 now i have

this error
(Undefined subroutine &File::Util::list_dir called at array.pl line 15.)
First, CODE TAGS.....CODE TAGS.....CODE TAGS!!! We have all been using them in this post and they are required. Please remember to use them.

Can't locate File/Util.pm in @INC (@INC contains: /opt/perl_32/lib/5.8.3/IA64.A.
BEGIN failed--compilation aborted at array.pl line 5
I had mentioned that you need to watch the Perl modules that were used. This one doesn't seem to be installed on your system and you will need to install it.

my @filelist = File::Util::list_dir("/home/grimp/test" , 'POD77702.doc','POD8AUAA.doc','POD8AURB.doc');
This is not even what I had the line looking like. Here is what I had:
Expand|Select|Wrap|Line Numbers
  1. my @filelist = File::Util::list_dir(/your/directory , --files-only);
All you should have needed to do here was replace /your/directory with the directory you want to get a listing of. the --files-only NEEDS to be there. You don't put your file names as that line will obtain a list of ALL files in the $oldpath directory you specified and put them into the @filelist array.

If you are not sure what this does, then please reference the module page on CPAN so that you know what is going on.

Fix those issues, re-run and troubleshoot from there.
Oct 14 '08 #20

P: 12
ok i want to make shure i do things the right way sorry about the code tags

when i post the error

Expand|Select|Wrap|Line Numbers
  1. this is the error
this is what i should do?

and second if i do not have a module installed where do i find it to install
Oct 14 '08 #21

Icecrack
Expert 100+
P: 174
ok i want to make shure i do things the right way sorry about the code tags

when i post the error

Expand|Select|Wrap|Line Numbers
  1. this is the error
this is what i should do?

and second if i do not have a module installed where do i find it to install

He has given you the link to the module you need in the post above read it.
Oct 20 '08 #22

Post your reply

Sign in to post your reply or Sign up for a free account.