Hi All
I was wondering if someone can enlighten me on the following behaviour with regard to a particular code snippet
Code is:
<snip>
$line = pack ("A1170") ; substr ($line, 0, 135) = " " ; substr ($line, 136, 11) = "DATE=${mdy}" ; substr ($line, 147, 6) = "${mdy}" ; substr ($line, 153, 6) = "${hms}" ; substr ($line, 159, 3) = " " ; substr ($line, 162, 17) = " " ; substr ($line, 179, 8) = "G1ADP" ; substr ($line, 187, 3) = "$CLIENT_ID" ; substr ($line, 190, 507) = " " ; substr ($line, 508, 1) = " " ;
<snip>
Basically I deal with outputting various data in fixed width format and like the above method as it references back quite nicely to file definitions that I follow to create the output. For instance, the above is the definition for a file header
But, I've been ignoring a couple of interesting "funnies" with this way of outputting fixed widths. These being:
1) My $line should be 510 spaces long. But if I try to set A510 I get the old substr outside of string at error and for some reason I have to set it to the value of 1170 (found by trial and error).
2) If the last field is space, then I have to add in an extra output to get the file length outputted correctly. As in the above substr ($line, 508, 1) = " " ;.
Can anyone enlighten me on what's occurring? I expect it's user error :-)
Cheers, Jake (aka spudulike)
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |