Connecting Tech Pros Worldwide Help | Site Map

Incorrect Format value return from the subroutine

Newbie
 
Join Date: Apr 2007
Posts: 6
#1: Apr 18 '07
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????
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#2: Apr 19 '07

re: Incorrect Format value return from the subroutine


how can we help without seeing your code?
Newbie
 
Join Date: Apr 2007
Posts: 6
#3: Apr 19 '07

re: Incorrect Format value return from the subroutine


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.
Newbie
 
Join Date: Apr 2007
Posts: 6
#4: Apr 24 '07

re: Incorrect Format value return from the subroutine


Can anybody please help with this!!!!
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#5: Apr 24 '07

re: Incorrect Format value return from the subroutine


I can't tell from what you posted what the problem might be. Post the code, with the second subroutine, and some sample data.
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#6: Apr 24 '07

re: Incorrect Format value return from the subroutine


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.
Newbie
 
Join Date: Apr 2007
Posts: 6
#7: Apr 24 '07

re: Incorrect Format value return from the subroutine


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.
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#8: Apr 24 '07

re: Incorrect Format value return from the subroutine


Are you using a really old vesion of perl?
Newbie
 
Join Date: Apr 2007
Posts: 6
#9: Apr 24 '07

re: Incorrect Format value return from the subroutine


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.
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#10: Apr 25 '07

re: Incorrect Format value return from the subroutine


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?
Newbie
 
Join Date: Apr 2007
Posts: 6
#11: May 1 '07

re: Incorrect Format value return from the subroutine


yes, i guess that a copy paste problem. Thanks for your help.
Reply