NAME DB::LineCache

DB::LineCache - package to read and cache lines of a Perl program.


The LineCache package allows one to get any line from any file, caching lines of the file on first access to the file. Although the file may be any file, the common use is when the file is a Perl script since parsing of the file is done to figure out where the statement boundaries are.

The routines here may be is useful when a small random sets of lines are read from a single file, in particular in a debugger to show source lines.

  use DB::LineCache;
  $lines = DB::LineCache::getlines('/tmp/')
  # The following lines have same effect as the above.
  $: << '/tmp'
  Dir.chdir('/tmp') {$lines = DB::LineCache::getlines('')

  $line = DB::LineCache::getline('/tmp/', 6)
  # Note lines[6] == line (if /tmp/ has 6 lines)

  DB::LineCache::update_cache   # Check for modifications of all cached files.