473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

subroutine

Can any one please help me. Everything here works perfect except the other subroutine “&sftp()” , it works fine too when used before “&excel()” subroutine. But I want to transfer the file after it is created. There is something still open in the first subroutine which is not allowing the other subroutine to transfer the file. Can anyone please tell me what i am missing. The table(excel spreadsheet) is input from which I am extracting only the selected fields as indicated by field1 ,2 and 3.


Type Country1 Order Country2 Product Cu 1995_Jan Cu 1995_Feb Cu 1995_Mar Cu 1995_Apr Cu 1995_May
Production World Total 132 World Total Blister 4633463 34634636 3463463 567567 4574757
Production World Total 132 World Total Ores CNT 6546456 3463463 3463447 56745346 5676575
Production World Total 132 World Total Ref Cu 453453 3463463 567564 658567567 5675675
Stocks Democratic Republic Congo 5 Democratic Republic Congo Ref Cu 34634 34634 4567457 657547 67856

Expand|Select|Wrap|Line Numbers
  1. #  Variable initialization.
  2.  
  3. my $data_dir = $DATA . '/in/';
  4. my $file = 'prod1.xls';
  5. my $dat = 'datfile.dat';
  6. my $data = '/ABCD/';
  7. my $gaa_daily = $data . 'daily/';
  8. my $xy = "$data_dir$file";
  9.  
  10. &excel();
  11. &sftp();
  12.  
  13. print "hi there";
  14.  
  15. sub excel {
  16.   use Spreadsheet::ParseExcel;
  17.   my $oExcel = new Spreadsheet::ParseExcel;
  18.   my $field1 = "Production";
  19.   my $field2 = "World Total";
  20.   my $field3 = "Ref Cu";
  21.   my $excel = Spreadsheet::ParseExcel::Workbook->Parse("$xy");
  22.  
  23.   open (FILE, ">$data_dir$dat") or die "Cannot creat file: $!\n";
  24.   for my $sheet (@{$excel->{Worksheet}}) {
  25.     for my $row ($sheet->{MinRow} .. $sheet->{MaxRow}) {
  26.       my $cell = $sheet->{Cells}[$row][1];
  27.       if ($sheet->{Cells}[$row][0]->{Val} eq $field1 && $sheet->{Cells}[$row][1]->{Val} eq $field2 && $sheet->{Cells}[$row][4]->{Val} eq $field3) {
  28.     my $last_col = $sheet->{MaxCol} || 0;
  29.     for (5..$last_col) {
  30.       my $cell1 = $sheet->{Cells}[0][$_]->{Val};
  31.       my $cell2 = $sheet->{Cells}[$row][$_]->{Val};
  32.       if (($cell2 =~ /([-]\d{0,5})/g) || ($cell2 =~ /(^\d\d\d\d\d$)/g)) {
  33.       exit 0;
  34.          }
  35.  
  36.     print FILE "WBMS         $cell1         Cu_prod        $cell2\n";
  37.  
  38.        }
  39.      }
  40.    }
  41.   }
  42.  
  43. close FILE;
  44. }
  45.  
  46. sub sftp {
  47.  
  48.   $ftp_cmds = "";
  49.   $tempfile = $data_dir . $dat;
  50.   $ftp_cmds .= "put " . "$tempfile" ." ". $gaa_daily.$dat."\n";
  51.  
  52. # COnvert from unix to DOS format
  53.   $convert_filelist[0]='WBMS.dat';
  54.   $rc=toolkit::convert2dos("$data_dir", \@convert_filelist);
  55.  
  56. #  Perform the sftp
  57. # Add retry sftp once
  58.   $rc = toolkit::sftp($ftp_cmds);
  59.   if ($rc != 0) {
  60.     print("\n***SFTP failed on the first attempt.  Retrying. ***\n");
  61.     $rc = toolkit::sftp($ftp_cmds);
  62.   }
  63.   if ($rc != 0) {
  64.     print("\nError unable to retrieve the raw Datastream files for processing.");
  65.     exit -1;
  66.   } else {
  67.     print ("\nSFTP sucessfully retrived raw Datastream files.");
  68.   }
  69.  
  70. }
  71.  
Sep 26 '07 #1
1 1526
KevinADC
4,059 Expert 2GB
remove this line :

exit 0;

that causes the script to terminate.
Sep 27 '07 #2

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

Similar topics

4
by: Michael Farber | last post by:
Not sure if this is the right group for this but anyways... I've got an ASP web application that uses a Visual Basic component to do some work. I instantiate the component in asp and then...
3
by: Scott | last post by:
What is the proper syntax for sending an argument from a form contol to a subroutine in a module? For instance, from a textbox on a form I call a module subroutine from the textbox's OnUpdate...
7
by: Richard Grant | last post by:
Hi. In c/C++ i can pass the address of a subroutine to another subroutine as an actual parameter How do I do that in VB .NET What should be the syntax for a parameter to receive the address of a...
2
by: singlal | last post by:
Hi, my question was not getting any attention because it moved to 2nd page; so posting it again. Sorry for any inconvenience but I need to get it resolved fast. Need your help! ...
1
by: dgr7 | last post by:
hello, I have a file BLURG.txt in a subdirectory D:\B HC\NewB that I'd like to, using a VB6 subroutine, pass as a variable to the subroutine the name of the file & directory where it can be...
10
by: nasau | last post by:
Perl, I have a main program which calls two subroutines (depending upon the report names).In the subroutine I am printing the data from CSV file using the format variable, Format_top prints the...
1
by: peterv6 | last post by:
I'm using a "package" type subroutine, called test_package.pl. I'm calling it from a script called split0.pl. I want to pass the $0 variable, use the subroutine to split out just the filename, and...
4
by: otterbyte | last post by:
Hi, I have a bit of code which is confusing me to no end. Here are the basics: 1) The class module is being used in the module of a form. 2) There is an instance of the object declared at the...
3
by: sangith | last post by:
Hi, I have question on processing the file handle in a subroutine. Here is my program without subroutine: open FH1, "<outfile" or die "cannot open the file for reading: $!\n"; while...
3
shrek123
by: shrek123 | last post by:
How can I pass output of some perl subroutine to a subroutine? I have Subroutine1 and wanna pass the return value of this subroutine as an argument to another subroutine. I tried this; ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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,...

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.