chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-hackers] substring function and bounds checks


From: Alex Shinn
Subject: Re: [Chicken-hackers] substring function and bounds checks
Date: Fri, 8 Feb 2013 12:12:32 +0900

On Fri, Feb 8, 2013 at 11:50 AM, John Cowan <address@hidden> wrote:
Alex Shinn scripsit:

> If the goal is to take a fixed field you should be taking that.  If
> the format allows either then the format itself is ambiguous, which
> means you have a _much_ bigger problem than whatever language
> idioms you use.

Purism has its place, but is not always the appropriate response
to Real World issues.  In this case, kicking back such records
as "invalid/ambiguous format" simply would not have served the
organization's goals.

I was not suggesting kicking it back.  I was suggesting if it
was the last field then just use substr($line, $n).  That sounds
like the definition of the format you're describing, though you're
not giving a concrete example so I can't be sure.

If there are additional restraints on this field then you should
handle them as well, and if you want to handle those restraints
liberally you can do so.  For example, if the length of the last
field should be no longer than $limit, you can check this:

  if (len($field) > $limit) {
    print STDERR "found trailing junk at end of line: $field";
    $field = substr($field, 0, $limit);
  }

The warning is important, and this again emphasizes that there
are two _unrelated_ functions - extraction and truncation - and
that combining them is a bad idea.

-- 
Alex


reply via email to

[Prev in Thread] Current Thread [Next in Thread]