473,748 Members | 2,523 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

script

12 New Member
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
21 2264
Icecrack
174 Recognized Expert New Member
thank you Kevin,numberwhu n, 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
4,059 Recognized Expert Specialist
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
pgrimsley
12 New Member
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
3,509 Recognized Expert Moderator Specialist
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
pgrimsley
12 New Member
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
3,509 Recognized Expert Moderator Specialist
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
pgrimsley
12 New Member
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
pgrimsley
12 New Member
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::li st_dir called at array.pl line 15.)
Oct 14 '08 #18
numberwhun
3,509 Recognized Expert Moderator Specialist
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
3,509 Recognized Expert Moderator Specialist
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::li st_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::lis t_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

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

Similar topics

6
12984
by: Mike Daniel | last post by:
I am attempting to use document.write(pageVar) that displays a new html page within a pop-up window and the popup is failing. Also note that pageVar is a complete HTML page containing other java scripts. Being a javascript newbie and after significant testing, I suspect that the document.write fails after finding a </script> within pageVar. Does a trick exist that enables one to slightly alter pageVar whereby enabling...
1
3255
by: bayouprophet | last post by:
Cant get menu script to to put linked page in the same frame. I am new to Java and I am wondering what am I doing wrong? below are my java applet file, frame.html file, and my text file and one of my link file that should load next to the menu on the same page. And Thank You in advance. Here is my menu applet: <html>
1
4818
by: Allen | last post by:
I am trying to add an additional photo/hyperlink to the company web site (I didn't create it) without any luck. The mouseover feature 'highlights' pics by swapping them with another pic using this command in some type of array. I added the mailbox in the lower left corner (see link below)http://www.aamechanical.com/indextemp.htm but I cannot get it to swap. Here is the code for the page: Thanks for your help in advance
3
2959
by: Water Cooler v2 | last post by:
Questions: 1. Can there be more than a single script block in a given HEAD tag? 2. Can there be more than a single script block in a given BODY tag? To test, I tried the following code. None of the script gets executed. Can someone please give me a direction as to what I may be missing? Thanks.
2
2970
by: bilaribilari | last post by:
Hi all, I am using Tidy (C) for parsing html pages. I encountered a page that has some script as follows: <script> .... var abc = "<script>some stuff here</" + "script>"; .... </script>
19
3827
by: thisis | last post by:
Hi All, i have this.asp page: <script type="text/vbscript"> Function myFunc(val1ok, val2ok) ' do something ok myFunc = " return something ok" End Function </script>
3
2488
by: rsteph | last post by:
I have a script that shows the time and date. It's been working on my site for quite a while now. Suddenly it stops showing up, after getting my drop down menu to work. If I put text between the <div id="datetime"></div> tags, the text shows up, but the javascript output being sent to those some divs doesn't seem to want to work. It should be showing up in the middle of the content pane, just below the first table box. (set by .css) Here's...
3
3680
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of html is: <a class="searchsavechanges btn btn3d tbbtn" href="javascript:" style="position:static"> <div id="TBsearchsavechanges">Search</div> </a>
7
3614
by: imtmub | last post by:
I have a page, Head tag Contains many Scripts and style sheet for Menu and Page. This code working fine and displaying menus and page as i wanted. Check this page for reference. http://www.marco.com.cn/web-content/marco_re10.html -------------------------------------------------------------- <head> <!-- InstanceBeginEditable name="doctitle" --> <title>Marco</title> <!-- InstanceEndEditable -->
1
47476
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
8994
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9555
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9329
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9250
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8247
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4878
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.