Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 22c781af90fc090aae3cc45700b5d89a354c4f8c
Ticket: 3546143fffffffffffffffffffffffffffffffff
Extend parray
User & Date: talvo on 2012-07-20 00:00:02
Changes

  1. assignee changed to: "dkf"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    parray is useful for quickly checking values set in an array. However, it has a limitation: It can only do glob matching of array keys.
    
    I'd like to suggest a very minor modification to parray to make it a lot more useful: Allow the match-type flags that [array names] accepts (-glob, -regexp, -exact). The change is minor and totally backwards-compatible, since currently parray only accepts 1 or 2 arguments. Example code:
    
    proc parray {a args} {
    
      set nargs [llength $args]
      if { $nargs > 2 } {
           return -code error "Wrong # of arguments. Should be parray array ?type? ?pattern?"
         }
      upvar 1 $a array
      if { ![array exists array] } {
           error "\"$a\" isn't an array"
         }
      set maxl 0
      set names [lsort [array names array {*}$args]]
      foreach name $names {
        if { [string length $name] > $maxl } {
             set maxl [string length $name]
           }
      }
      set maxl [expr {$maxl + [string length $a] + 2}]
      foreach name $names {
        set nameString [format %s(%s) $a $name]
        puts stdout [format "%-*s = %s" $maxl $nameString $array($name)]
      }
    
    }
    
  4. foundin changed to: "None"
  5. is_private changed to: "0"
  6. priority changed to: "5 Medium"
  7. resolution changed to: "None"
  8. status changed to: "Open"
  9. submitter changed to: "talvo"
  10. subsystem changed to: "18. Commands M-Z"
  11. title changed to: "Extend parray"
  12. type changed to: "RFE"