DB2 Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDB2 Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old August 11th, 2006, 04:44 PM
evg2004 evg2004 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 41 evg2004 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 8 m 47 sec
Reputation Power: 5
Array subscript in perl script on AS400

Hello everybody,

We're trying to break a string file into fields for our DB2 using perl script. Here is a piece of code that gives us trouble:

PHP Code:
if (@fields[1eq 'SDQ'
# Detail record processing.
my $l scalar @fields;            # Get the number of records in this collection (max 10 pairs) 

printf(OUT "%2s%2s", (@fields[2], @fields[3]));    # Add the two core fields "UNITS" and the "ID"
for ($k 4$k $l$k += 2){      # Set up a loop to go through the store/units pair values
printf(OUT ">%4s%3s", (@fields[$k], @fields[$k+1]));       # Add the STORE and UNITS values to the string for each one present
}
print(
OUT "\n");              # Add a line feed to the end of the detail record
#die;



It works fine on PC and gives out the right values. However, the same code on AS400 outputs the incorrect results. It looks like $k in the for-loop is not evaluated correctly or is not evaluated at all.
On PC, @fields[$k] gives a string and on AS400 produces blank(undef).

If on AS400 we hardcode each iteration like :
PHP Code:
for ($k 4$k $l$k +=2){ # Set up a loop to go

   
if ($k == 4){                                      

   
printf(OUT "%4s%3s", (@fields[4], @fields[5]));}   

   if (
$k == 6){                                      

   
printf(OUT "%4s%3s", (@fields[6], @fields[7]));}   

   if (
$k == 8){                                      

   
printf(OUT "%4s%3s", (@fields[8], @fields[9]));}   

   if (
$k == 10){                                     

   
printf(OUT "%4s%3s", (@fields[10], @fields[11]));} 

   if (
$k == 12){                                     

   
printf(OUT "%4s%3s", (@fields[12], @fields[13]));}

 

etc…





...then it gives the same output as if it ran on PC.

Is there anything specific about loops in perl script when running on AS400?

Thank you very much.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDB2 Development > Array subscript in perl script on AS400


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway