473,378 Members | 1,444 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,378 software developers and data experts.

Incorrect Format value return from the subroutine

6
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 is my problem:
1. When I run this program the format of second subroutine is displayed for the first subroutine.

2. Output display only the header and data for the first report and for the second subroutine it displays only data, no header is displayed for the second subroutine.

Can any one help me with this????
Apr 18 '07 #1
10 1856
KevinADC
4,059 Expert 2GB
how can we help without seeing your code?
Apr 18 '07 #2
nasau
6
Thanks for the responce, i am a beginner and not much familier with perl.
So here is my one subroutine and the second subroutine is also similar but the only difference is it has more number of columns.

Expand|Select|Wrap|Line Numbers
  1. sub abc() {
  2.     $last_element = @raw_data;
  3.     $report_name = @raw_data[0];
  4.     $column_name = @raw_data[1];
  5.  
  6.     chop($column_name);
  7.     $column_name =~s/"/\ /g;
  8.     ($column_name1, $column_name2, $column_name3, $column_name4) = split(/,/,$column_name);
  9.     write;
  10.  
  11.     foreach $field (@raw_data[2..$last_element]) {
  12.         chop($field);
  13.         $field=~tr/"//d;
  14.         ($Date, $code, $TotalMsg, $Zmsgs) = split(/\,/,$field);
  15.         write;
  16.     }
  17.  
  18.     format STDOUT_TOP =
  19.  
  20. @|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  21. $report_name
  22. @<<<<<<<<<<<@<<<<<<<@<<<<<<<<<<@<<<<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<
  23. $column_name1,$column_name2,$column_name3,$column_name4
  24. ==================================================================
  25. .
  26.  
  27.     format STDOUT =
  28. @<<<<<<<<<<<@<<<<<<<@<<<<<<<<<<@<<<<<<<<<<@
  29. $Date,$code,$TotalMsg,$Zmsgs
  30. .
  31.  
  32. }
  33.  
and in my main program i am calling these two subroutine as shown below, and i am passing the content of the CSV file as a parameter to the subroutine.

Expand|Select|Wrap|Line Numbers
  1. if (@raw_data[0] eq "Counts") {
  2.     &abc(@raw_data);
  3. } else (@raw_data[0] eq "Count1") {
  4.     &abc1(@raw_data);
  5. }
  6.  
I hope this makes things more clear.
Apr 19 '07 #3
nasau
6
Can anybody please help with this!!!!
Apr 24 '07 #4
KevinADC
4,059 Expert 2GB
I can't tell from what you posted what the problem might be. Post the code, with the second subroutine, and some sample data.
Apr 24 '07 #5
KevinADC
4,059 Expert 2GB
actually, this is suspect:

Expand|Select|Wrap|Line Numbers
  1. if (@raw_data[0] eq "Counts")
  2. {
  3. &abc(@raw_data);
  4. }
  5. else (@raw_data[0] eq "Count1")
  6. {
  7. &abc1(@raw_data);
  8. }

the else {} block should not have any conditional statement:

Expand|Select|Wrap|Line Numbers
  1. if (@raw_data[0] eq "Counts")
  2. {
  3. &abc(@raw_data);
  4. }
  5. else 
  6. {
  7. &abc1(@raw_data);
  8. }
if you need to check the value of @raw_data[0] use an elsif condition:

Expand|Select|Wrap|Line Numbers
  1. if ($raw_data[0] eq "Counts")
  2. {
  3. &abc(@raw_data);
  4. }
  5. elsif ($raw_data[0] eq "Count1")
  6. {
  7. &abc1(@raw_data);
  8. else {
  9.    print "error";
  10. }
you should also be using $raw_data[0] instead of @raw_data[0]. $raw_data[0] is a scalar, @raw_data[0] isn't really a scalar but perl will probably treat it as one in that context.
Apr 24 '07 #6
nasau
6
thanks for the responce and here is my second subroutine

Expand|Select|Wrap|Line Numbers
  1.  ##################################### 
  2. #Subroutine for Dealer reports
  3. #####################################
  4.  
  5. sub abc1()
  6. {
  7. local ($report_name,$column_name,$column_name1,$column_name2,$column_name3,$column_name4,$column_name5,$column_name6,$column_name7,$column_name8,$column_name9,$column_name10,$column_name11,$column_name12,$column_name13,$column_name14,$column_name15);
  8. local ($Date,$code,$Plan,$Beg,$Act,$NAct,$Add,$DeAct,$MIN,$Max,$Nadd,$EBal,$AUser,$TMsg,$Zm,$last_el)= 0;
  9.  
  10. $last_element=@raw_data; # to find the total number of elements in the file
  11.  
  12. $report_name = @raw_data[0];
  13. $column_name = @raw_data[1];
  14.  
  15. chop($column_name);
  16. $column_name =~s/"/\ /g;
  17. ($column_name1,$column_name2,$column_name3,$column_name4,$column_name5,$column_name6,$column_name7,$column_name8,$column_name9,$column_name10,$column_name11,$column_name12,$column_name13,$column_name14,$column_name15) = split(/,/,$column_name);
  18. write;
  19.  
  20.  
  21. foreach $field (@raw_data[2..$last_element])
  22. {
  23. chop($field);
  24. $field=~tr/"//d;
  25. ($Date,$code,$Plan,$Beg,$Act,$NAct,$Add,$DeAct,$MIN,$Max,$Nadd,$EBal,$AUser,$TMsg,$Zm,$last_el)=split(/\,/,$field);
  26. write;
  27. }
  28.  
  29. format STDOUT_TOP =
  30.  
  31. @|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  32. $report_name
  33. @<<<<<<<<<<<@<<<<<<<@<<<<<<<<<<@<<<<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<@<<<<<<<<<<@<<<<<<<<<<<<<@<<<<<<<<<<<<<@<<<<<<<<<<<<<<@<<<<<<<<<@<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<@<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<<<<<<<<<
  34. $column_name1,$column_name2,$column_name3,$column_name4,$column_name5,$column_name6,$column_name7,$column_name8,$column_name9,$column_name10,$column_name11,$column_name12,$column_name13,$column_name14,$column_name15
  35. ==============================================================================================================================================================================================================================
  36. .
  37. format STDOUT =
  38. @<<<<<<<<<<<@<<<<<<<@<<<<<<<<<<@<<<<<<<<<<@<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<@<<<<<<<<<<@<<<<<<<<<<<<<@<<<<<<<<<<<<<@<<<<<<<<<<<<<<@<<<<<<<<<@<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<@<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<<<<<<<<<
  39. $Date,$code,$Plan,$Beg,$Act,$NAct,$Add,$DeAct,$MIN,$Max,$Nadd,$EBal,$AUser,$TMsg,$Zm,$last_el
  40. .
  41. }
  42.  
From the main program i am sending the report header and that will avcivate the respective subroutine.
Apr 24 '07 #7
KevinADC
4,059 Expert 2GB
Are you using a really old vesion of perl?
Apr 24 '07 #8
nasau
6
Ok, so do u think that could be the the reason?
Can you please suggest me which version should i use to get read of this problem.
Apr 24 '07 #9
KevinADC
4,059 Expert 2GB
if you are using an old version of perl I think the code would be OK. I never use the "write" function, so I really am at a loss to determine what the problem might be.

Whats with these gaps in the code you posted?

Expand|Select|Wrap|Line Numbers
  1. $column  _name4
  2. $MI  N
just a copy and paste problem?
Apr 24 '07 #10
nasau
6
yes, i guess that a copy paste problem. Thanks for your help.
May 1 '07 #11

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

Similar topics

36
by: Riccardo Rossi | last post by:
Hi all! How does Python pass arguments to a function? By value or by reference? Thanks, Riccardo Rossi.
5
by: J. Muenchbourg | last post by:
IN the code below, I am getting an Incorrect Syntax near "," error (the sql execute line, and it is pointing to position 1 ) (the display formatting here may look different than my script): ...
13
by: NM | last post by:
Sometimes ago I was having a problem in linking between C++ and Fortran program. That was solved (using input from this newsgroup) using the Fortran keyword "sequence" with the derived types (to...
11
by: Mark Findlay | last post by:
Hello Experts! I am attempting to use the OleDbCommand.ExecuteScaler() function within my ASP.NET C# web page to perform a simple validation, but receive the following error: "Incorrect...
7
by: Richiep | last post by:
I am trying to get a UK format date of dd/mm/yyyy. Why does the following subroutine not return a valid date in a web form? The date returned is #12:00:00 AM# but the date I entered into the...
0
by: hudhuhandhu | last post by:
have got an error which says Input string was not in a correct format. as follows.. Description: An unhandled exception occurred during the execution of the current web request. Please review the...
6
by: trevor | last post by:
Incorrect values when using float.Parse(string) I have discovered a problem with float.Parse(string) not getting values exactly correct in some circumstances(CSV file source) but in very similar...
1
by: ndawg123 | last post by:
Hey guys what im trying to do is write a yatzee game with C. And im stuck already and its the start?!?! I want the user to type there 5 numbers. i.e My program so far does this Please...
1
by: TommyC | last post by:
Hi all, I fail to write the image data to binary PGM format (P5). Let's say i have to write a image data into PGM P5 format. I have the information for width, height, Y_min, Y_max, XL, XR and the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.