473,657 Members | 2,420 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

subroutine

9 New Member
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 1535
KevinADC
4,059 Recognized Expert Specialist
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
4964
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 attempt to call the subroutine. The subroutine is actually invoked maybe 2 out of 10 times run. What could possibly be the reason for this?? Why the inconsistency in running the subroutine? Cheers
3
6776
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 event. I want to pass the form's name to the the Module subroutine. What is the proper syntax for the textbox event to pass the form name and what is the correct syntax in the module subroutine to accept the form name as an argument? Thanks Scott
7
9558
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 subroutine Let's say theres a sub that creates buttons and I want it to receive as a parameter the address of the sub that handles the OnClick event for the button being created How do I pass such a parameter Thanks in advance Richar
2
1434
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! **************************************************************************************************** Original Question: -------------------- Has anyone called a COBOL subroutine using COBOL CALL from a COBOL/DB2
1
1471
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 found (for this ex., D:\B HC\NewB\BLURG.txt), then the subroutine will connect to a FTP site, ftp://192.782.32.1 using a username of
10
1878
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 report header and STDOUT prints the report data. Both these subroutine runs fine individually, independent of each other. Now I have included both these subroutine in my main program and I call these subroutine depending upon the name of the report. Here...
1
1903
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 pass that filename value back to the calling script. The subroutine does the processing correctly (I've verified with print statements), but I'm having trouble getting the value passed back to the calling script. Here's the subroutine: package...
4
2601
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 form level, and instantiated in the Load event of the form. This instance holds the "current" values (based on data in a table), and it's called ordCurrent.
3
13616
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 ($line_from_outfile = <FH1>) { chomp $line_from_outfile; print $line_from_outfile;
3
1445
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; &SubroutineA("test",&SubroutineB) but it doest work. Thanks in advance.
0
8395
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
8732
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
8503
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
7330
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
6166
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
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.