Strange problem with substr() function and right aligned fields



I must process the output of an SQL query using Perl.

I know the column position of the data in the output file, which means
that I am able to calculate the width of each field.

All of the data in the file is left-aligned to the field, except for one
column.

Basically, in the output of the SQ query, the right-aligned colum looks
like this:
NODE_UL
=============
146
281
985
So both the data and Field Title are right-aligned to the column.
I am using a function cal of the form:
$field_value=substr( $input_line , $field_start, $field_width ) ;
Where:
$input_line : line read from the source data file
$field_start : fixed value read from a table (array)
$field_width : calculated value of the field width, from the field
boundary definitions in the table
$field_value: value retruned by the function
However, for some strange reason, the Perl substr() function is unable
to read the right-most character of a right-aligned field. So in the
output data the above numbers would be 14, 28, 98.
I have extended the boundary column number in the field definition
table, so that substr() uses a bigger field width. But this has not
solved the problem. Extending the field boundary to the right has no
effect, even if I use a ridiculous value.
Does this sound like some sort of bug?? The substr() function has no
problem processing left-aligned fields and I have have said, increasing
the field width does not solve the problem either.
I am using Perl 5.8.4 on Solaris.
I know I could probably fix this by tweaking the SQL query but it would
still be nice to know what exactly is going on here.
Thanks in advance for any help you can give.

Regards,
Bill Harpley






Relevant Pages

  • Re: first book about python
    ... For me automated log file alerting, ... SQL query parsing, SQL table updates, Internet file ... Perl is likely the ... recommend Python or Ruby over Perl. ...
    (comp.lang.python)
  • RE: Optimization for faster select...
    ... Although its a cute idea to create a function based index on SUBSTR ... I tried to see whether the SUBSTR could be replaced with Perl formatting ... the possibility of writes delaying the extract. ... So, ladies and gets, everything comes down to using RowCacheSize attribute. ...
    (perl.dbi.users)
  • Re: Time Complexity for substr() function
    ... :Is it under linear time? ... perl knows the length of strings. ... substr() is thus constant-time with respect to the length of the ...
    (comp.lang.perl.misc)
  • Re: substr()
    ... in dem ich einen Showcase fuer die ... Anfang August wurde ein Fehler in Perl mit substr, ...
    (de.comp.lang.perl.misc)
  • Re: Spurious "Use of uninitialized value" with -w, redux
    ... dejanews@email.com (Sam Denton) writes: ... > # perl unix_replica.pl ... Use of uninitialized value in substr at -e line 1. ... None of the code above seems to be a pattern match, ...
    (comp.lang.perl.misc)