Undefine

tony summerfelt [mailto:snowzone5@hotmail.com] :

What about the logic of your code or design depends on the
'existence' of a variable? What problem is it you're trying to
solve with this approach?

just makes the code shorter. here's an excerpt of a log trimming
program in perl (for the format that binkd generates) [...]

while(<binkd>)
{
    # date parsing code was here
  @diff = Delta_DHMS(@binkdate,@today) if /(\[\d+\])/;
  print $trimmed $_ if $diff[0] < $ARGV[1] && defined(@diff);
  next if defined(@diff);
  print $trimmed $_ if ! /(\[\d+\])/;
  undef(@diff);
}

Okay. Here's a partial reimplementation. Some of it is
pseudo-codeish, because I don't know what your implementation is for
certain items, but:

  binkd.each do |line|
    if link =~ /(\[\d+\])/o
      diff = Delta_DHMS(binkdate, today)
      if diff
        puts "#{trimmed} #{line}" if diff[0] < ARGV[1]
        next
      end
    else
      puts "#{trimmed} #{line}"
      diff = nil
    end
  end

You don't actually need to make the *variable* diff go away, but the
value referred to by diff. I have made the code a bit longer for
readability (and a small bit of performance improvement; it reduces
the number of comparisons because it isn't compared against the
regexp more than once and doesn't have to test the non-nil nature of
diff more than once).

-austin

···

On Tue, 15 Jun 2004 05:31:30 +0900, you wrote:

--
austin ziegler * austin.ziegler@evault.com

i must be doing something right, that' pretty close to what i ended
up with when i initially ported it from the perl version...

···

On Wed, 16 Jun 2004 02:44:34 +0900, you wrote:

Okay. Here's a partial reimplementation. Some of it is
pseudo-codeish, because I don't know what your implementation is for
certain items, but: