1
#! /usr/local/bin/perl -w
3
##############################
7
# Queries a data structure #
8
# using the STAR::DataBlock #
11
# Wolfgang Bluhm, SDSC #
13
##############################
24
my $data = STAR::DataBlock->new($ARGV[0]); # 1-arg constructor
26
#this just retrieves an already blessed
27
#object, so ok even if it's a Dictionary
28
#which inherits from DataBlock
30
# could also replace the above one-liner
31
# with the following two lines:
33
# my $data = STAR::DataBlock->new; # no-arg constructor
34
# $data = STAR::DataBlock::retrieve($ARGV[0]);
37
$dict = 1 if $data->type eq "dictionary";
41
print "Query dictionary by save block and item name.\n";
42
print "save can be: - (not in a save block),\n";
43
print " A_CATEGORY (e.g. ENTITY),\n";
44
print " _an_item (e.g. _entity.id)\n";
45
print "Capitalization may vary with dictionary.\n";
46
print "Item examples: _dictionary.version ",
47
"_dictionary_history.revision\n";
48
print " _category.description ",
49
"_category_examples.case\n";
50
print " _item_linked.child_name ",
51
"_item_description.description\n";
52
print "For items with multiple values: ",
53
"choose index (e.g.: 1, 4-6)\n";
58
print "Query ",$data->title," by item name.\n";
59
print "For items with multiple values: ",
60
"choose index (e.g.: 1, 4-6)\n";
76
@item_data = $data->get_item_data( -save=>$s, -item=>$i );
78
if ( $#item_data < 0 ) { # returned null, item doesn't exist
79
print "item $i doesn't exist\n";
82
if ( $#item_data > 0 ) {
83
print "index (range: 0..", $#item_data, "): ";
84
chomp ( $string = <STDIN> );
85
@selected = selection();
91
print "[$_] " unless ( $#item_data == 0 );
96
} while (print("Continue with query? ") && <STDIN> =~ /\by/i);
101
while ( $string =~ /\d+/ ) {
102
if ( $string =~ /^\D*(\d+)\-(\d+)(.*)/ ) { #range (e.g. 1-3)
103
push @selected, ($1..$2);
106
elsif ( $string =~ /^\D*(\d+)(.*)/ ) { #one number
116
This script provides a simple interactive query interface to the data structure
117
of a file of dictionary (.cob files). Query is by item only (for a data file),
118
or by save block and item (for a dictionary file).
122
perl query.pl <data.cob or dict.cob>