Solved

Convert Perl to Visual Basic

Posted on 2000-04-26
10
275 Views
Last Modified: 2012-05-04
I have a Perl Script and I don't write Perl.  I know the script is moving files to folders based on the names of the files.  Rather than learn Perl and convert it, I'll post it.  Please help me decipher it and give the appropriate VB Commands for the various sections.  I'm not asking for a total conversion (but it would be nice!):

#File_Move.pl Moves or copies a file from one folder to another.
#
$currtime = time();
$timelist = localtime ($currtime);
$execute_time = $timelist;
$execute_time =~ s/^.{11}//g;
$execute_time =~ s/.{5}$//g;
$timelist =~ s/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]//;
$Log_out_file = $timelist;
$Log_out_file =~ s/ /_/g;
$Log_out_file =~ s/__2000/_2000/;
$Destination = "";

#Execute Command input queue sends filename with the path.
$In_File = $ARGV[0];
$Out_File = $In_File;

#Strip the path off of the filename
$Out_File =~ s/[a-z,A-Z]:\\//g;
$Out_File =~ s/\w+\\//g;

#Figure out which folder the file came in.
if ($In_File =~ /^d:\\icl_pages\\/i) {
      goto ICL;
} elsif ($In_File =~ /^d:\\ClassPS\\/i) {
      goto ICL;
} elsif ($In_File =~ /^e:\\Send_to_OMan\\/i) {
      goto STO;
} elsif ($In_File =~ /^e:\\OPI_Incoming_Art\\/i) {
      goto OPI;
} elsif ($In_File =~ /^d:\\DTI_Pages\\/i) {
      goto DTI;
} elsif ($In_File =~ /^d:\\DTI_11\\/i) {
      $Destination = "d:\\Drop\\DTI_11-5\\$Out_File";
      goto Move_File;
} elsif ($In_File =~ /^d:\\DTI_12\\/i) {
      $Destination = "d:\\Drop\\DTI_12-5\\$Out_File";
      goto Move_File;
}


DTI:
if ($Out_File =~ /^cp/i) {
      $Destination = "d:\\Drop\\DTIClassPrf\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^cx/i) {
      $Destination = "d:\\Drop\\Dti_12-5\\$Out_File";
      goto Move_File;
} goto BADFILENAME;


ICL:
if ($Out_File =~ /^ap/i) {
      goto NewsProof;
} elsif ($Out_File =~ /^ax/i) {
      $Destination = "d:\\Drop\\AdvNeg\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^cc/i) {
      $Destination = "d:\\Drop\\ClsTest\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^cp/i) {
      $Destination = "d:\\Drop\\ClsPrf\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^cx/i) {
      $Destination = "d:\\Drop\\ClsNeg\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^dc/i) {
      $Destination = "d:\\Drop\\DailyColorNeg\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^dx/i) {
      $Destination = "d:\\Drop\\DailyNeg\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx/i) {
      goto OPI;
} elsif ($Out_File =~ /^vp/i) {
      $Destination = "d:\\Drop\\ClsDsPrf\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^xp/i) {
      goto AdProof;
} goto BADFILENAME;


NewsProof:
if ($Out_File =~ /^ap\w\w[0-9]/i) {
      $Destination = "D:\\Drop\\EdTabPrf\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^ap\w\w[a,b,c,d,m,y]/i) {
      $Destination = "D:\\Drop\\EdPrf\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^ap\w\w[e,f,g,h,j,k,s,u,v,w,x,z]/i) {
      $Destination = "D:\\Drop\\EdAdvPrf\\$Out_File";
      goto Move_File;
} goto BADFILENAME;


AdProof:
if ($Out_File =~ /^xp\w\w[0-9]/i) {
      $Destination = "D:\\Drop\\AdTabPrf\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^xp\w\w[a,b,c,d,y]/i) {
      $Destination = "D:\\Drop\\AdPrf\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^xp\w\w[e,f,g,h,j,k,s,u,v,w,x,z]/i) {
      $Destination = "D:\\Drop\\AdAdvPrf\\$Out_File";
      goto Move_File;
} goto BADFILENAME;


#Send_to_OMan ,a,b,c
STO:
if ($Out_File =~ /^[0-9,A,B,C,D]/i) {
      goto AdDir;
} elsif ($Out_File =~ /^g/i) {
      $Destination = "e:\\hires\\dk1\\tmp\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^k/i) {
      $Destination = "e:\\hires\\dk1\\cls\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^n/i) {
      $Destination = "e:\\hires\\dk1\\prm\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^p/i) {
      $Destination = "e:\\hires\\dk1\\ctm\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^s/i) {
      $Destination = "e:\\hires\\dk1\\cls\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tf/i) {
      $Destination = "e:\\hires\\dk1\\cls\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^x/i) {
      $Destination = "e:\\hires\\dk1\\tmp\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx/i) {
      goto OPI;
} goto BADFILENAME;
$Destination = "e:\\Bad_Filename\\$Out_File";
goto Move_File;

#Parse on the 4th character and move the file to final directory.
AdDir:
if ($Out_File =~ /^\w\w\w0/) {
      $Destination = "e:\\hires\\dk1\\ad0\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^\w\w\w1/) {
      $Destination = "e:\\hires\\dk1\\ad1\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^\w\w\w2/) {
      $Destination = "e:\\hires\\dk1\\ad2\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^\w\w\w3/) {
      $Destination = "e:\\hires\\dk1\\ad3\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^\w\w\w4/) {
      $Destination = "e:\\hires\\dk1\\ad4\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^\w\w\w5/) {
      $Destination = "e:\\hires\\dk1\\ad5\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^\w\w\w6/) {
      $Destination = "e:\\hires\\dk1\\ad6\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^\w\w\w7/) {
      $Destination = "e:\\hires\\dk1\\ad7\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^\w\w\w8/) {
      $Destination = "e:\\hires\\dk1\\ad8\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^\w\w\w9/) {
      $Destination = "e:\\hires\\dk1\\ad9\\$Out_File";
      goto Move_File;
} goto BADFILENAME;


OPI:
if ($Out_File =~ /^0,1\w\w\wab/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\Incoming\\Apt_Book\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^0,1\w\w\wff/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\Incoming\\FarmFresh\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^0,1\w\w\who/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\Incoming\\Home_Search\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^t/i) {
      goto Tab;
} goto BADFILENAME;


Tab:
if ($Out_File =~ /^tx\w\w\wab/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\Incoming\\Apt_Book\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wal/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\style\\Special_Style\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wba/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\beacon\\Bayside\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\w(be|cn)/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\beacon\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wbx/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\beacon\\Bayside\\xtra_bayside\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wcc/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\coast\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wce/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\clipper\\east\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\w(cl|pe)/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\clipper\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wco/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\compass\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\w(cu|en)/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\currents\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wcw/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\clipper\\west\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wdc/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\port_folio\\Downtown_Connection\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wfs/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\style\\Family_Style\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wga/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\Gator\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\who/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\Incoming\\Home_Search\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\whr/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\style\\Inside_Business\\Inside_Hampton\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\whs/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\style\\Home_Style\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wib/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\style\\Inside_Business\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wis/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\style\\Inside_Special\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wke/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\beacon\\Kempsville\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wkx/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\beacon\\Kempsville\\xtra_kempsville\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wlx/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\beacon\\Lynnhaven\\xtra_lynnhaven\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wly/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\beacon\\Lynnhaven\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wnc/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\tvweek\\north_carolina\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wof/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\beacon\\oceanfront\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wox/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\beacon\\oceanfront\\xtra_oceanfront\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wpa/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\beacon\\Princess_Anne\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wpb/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\Port_folio\\Portfolio_Bride\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wpf/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\Port_folio\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wph/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\Port_folio\\Portfolio_Home\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wpp/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\Port_folio\\Peninsula_Parent\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wps/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\Port_folio\\Portfolio_Special\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wpx/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\beacon\\Princess_Anne\\xtra_princess_anne\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\w(re|rw|tr)/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\realestate\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wri/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\style\\Inside_Business\\Inside_Richmond\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wsg/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\Port_folio\\Stockley_Gardens\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wsh/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\style\\Inside_Business\\Inside_Hampton\\Hampton_Special\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wsp/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\special\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wsr/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\style\\Inside_Business\\Inside_Richmond\\Richmond_Special\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wss/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\jobs_today\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wst/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\style\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\w(su|ta)/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\sun\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wtp/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\port_folio\\Tidewater_Parent\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wtv/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\tvweek\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wty/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\Circuit_City\\$Out_File";
      goto Move_File;
} elsif ($Out_File =~ /^tx\w\w\wwa/i) {
      $Destination = "e:\\hires\\dk1\\OPI\\welcome_aboard\\$Out_File";
      goto Move_File;
}

BADFILENAME:
`net send nt_omclient_1 "$Out_File is not a legitimate filename or was sent wrong."`;
`net send nt_omclient_2 "$Out_File is not a legitimate filename or was sent wrong."`;
$Destination = "e:\\Bad_Filename\\$Out_File";
goto Move_File;

Move_File:
rename ($In_File, $Destination);

Log:
open (log_file, ">> g:\\tech_logs\\Move_File_Logs\\File_Move_$Log_out_file.txt");
            print log_file ("$In_File M--> $Destination at $execute_time\n");
close (log_file);

End:

0
Comment
Question by:dakarr
  • 5
  • 5
10 Comments
 
LVL 4

Expert Comment

by:adam923
ID: 2764945
just about every other line of that program has pattern matching statements ( /blah/ is a pattern ) and those would be quite hard to translate to vb, it's not built in to that language... any way you could just install perl and use the script as is? perl is available for free on windows or unix
0
 

Author Comment

by:dakarr
ID: 2766270
Adjusted points from 400 to 500
0
 

Author Comment

by:dakarr
ID: 2766271
Are you saying that it is difficult for VB to look at a file name, break it down into sections, and move it to another folder?  I know very little about Perl and know a small amount of VB but I have a hard time believing that it's that difficult to do.  The structure seems like it would be very similar to Perl.

It seems as though the $ at the top of the script are much like Dim statements, the next section calls a function for each type of file based on the characters in the name, the functions follow, and the end is for error handling.

My objective here is to convert the script to VB so that I can build a form and build a graphical interface so operators can watch what is occurring.  The script is presently running and working - however - I want to convert it to VB, that's why I posted the question.
0
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 
LVL 4

Expert Comment

by:adam923
ID: 2766553
ok, thanks for the clarification... the $ is just a symbol that precedes any scalar variable name, there are no declarations in perl, varaibles are just used on the fly
since the perl script seems to require no user interaction why don't you just create a vb front end that runs the perl script with a system call?
0
 

Author Comment

by:dakarr
ID: 2766573
The company I work for is moving away from Perl, Java, CGI, etc. and trying to put everything in C, VB, VBA.  Not my choice, theirs.
0
 
LVL 4

Expert Comment

by:adam923
ID: 2766657
ok, i'll give it a shot after i get back from work tonight...
0
 

Author Comment

by:dakarr
ID: 2766669
Thanks - sorry for all the miscommunication.
0
 
LVL 4

Expert Comment

by:adam923
ID: 2768151
ok, i have it ready but rather than post 400 lines of code it would be nice to email you the vb project.  i have visual basic version 5 but if yours is newer i'm sure it will convert the project for you
please post your email address or send it to adammitz@hotmail.com if you don't feel comfortable posting it.
0
 
LVL 4

Accepted Solution

by:
adam923 earned 500 total points
ID: 2771685
i'm going to post an answer since i've already mailed you the code
0
 

Author Comment

by:dakarr
ID: 2774448
Great - thank-you
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an explanation of a simple data model to help parse a JSON feed
This is about my first experience with programming Arduino.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question