2

私はperlを初めて使用し、いくつかのデータをハッシュに挿入しようとしていますが、立ち往生しています。助けていただければ幸いです....

私は次のデータを持っています

Catalog database partition number          = 0
Snapshot timestamp                         = 02/23/2013 21:02:08.262661
Number of automatic storage paths          = 1
      File system ID                       = 2304
      Storage path free space (bytes)      = 1385955328
      File system used space (bytes)       = 26495475712
      File system total space (bytes)      = 27948539904
High water mark for connections            = 82
Application connects                       = 32747
Secondary connects total                   = 3
Applications connected currently           = 22
Appls. executing in db manager currently   = 1
Agents associated with applications        = 24
Maximum coordinating agents                = 82
Locks held currently                       = 6
Lock waits                                 = 172
Lock list memory in use (Bytes)            = 33264
Deadlocks detected                         = 2
Lock escalations                           = 0
Exclusive lock escalations                 = 0
Agents currently waiting on locks          = 0
Lock Timeouts                              = 87
Number of indoubt transactions             = 0
Total Private Sort heap allocated          = 0
Total Shared Sort heap allocated           = 45
Shared Sort heap high water mark           = 36412
Total sorts                                = 44986014
Sort overflows                             = 4928
Active sorts                               = 1
Buffer pool data logical reads             = 137473219
Buffer pool data physical reads            = 6403328
Buffer pool temporary data logical reads   = 9360028
Buffer pool temporary data physical reads  = 7684
Asynchronous pool data page reads          = 6031755
Buffer pool data writes                    = 1477714
Asynchronous pool data page writes         = 6667
Buffer pool index logical reads            = 7386632979
Buffer pool index physical reads           = 418928
Buffer pool temporary index logical reads  = 0
Buffer pool temporary index physical reads = 0
Asynchronous pool index page reads         = 26653
Buffer pool index writes                   = 127741
Asynchronous pool index page writes        = 103030
Buffer pool xda logical reads              = 4
Buffer pool xda physical reads             = 4
Buffer pool temporary xda logical reads    = 0
Buffer pool temporary xda physical reads   = 0
Buffer pool xda writes                     = 0
Asynchronous pool xda page reads           = 0
Asynchronous pool xda page writes          = 0
Total buffer pool read time (milliseconds) = 39674360
Total elapsed asynchronous read time       = 33908937
Total elapsed asynchronous write time      = 1806167
Asynchronous data read requests            = 5770802
Asynchronous index read requests           = 2997
Asynchronous xda read requests             = 0
No victim buffers available                = 6679989
LSN Gap cleaner triggers                   = 162
Dirty page steal cleaner triggers          = 1150
Dirty page threshold cleaner triggers      = 118
Time waited for prefetch (ms)              = 18934507
Unread prefetch pages                      = 2147
Direct reads                               = 126622020
Direct writes                              = 43430
Direct read requests                       = 228012
Direct write requests                      = 3441
Direct reads elapsed time (ms)             = 1732753
Direct write elapsed time (ms)             = 12100
Database files closed                      = 0
Commit statements attempted                = 118401
Rollback statements attempted              = 1128
Dynamic statements attempted               = 352842
Static statements attempted                = 36096602329
Failed statement operations                = 26388
Select SQL statements executed             = 21659801876
Xquery statements executed                 = 0
Update/Insert/Delete statements executed   = 549460
DDL statements executed                    = 906
Inactive stmt history memory usage (bytes) = 0
Internal automatic rebinds                 = 42
Internal rows deleted                      = 9428
Internal rows inserted                     = 44
Internal rows updated                      = 117
Internal commits                           = 39840
Internal rollbacks                         = 104
Internal rollbacks due to deadlock         = 17
Rows deleted                               = 6225
Rows inserted                              = 295031
Rows updated                               = 12347
Rows selected                              = 14447342482
Rows read                                  = 656654938
Binds/precompiles attempted                = 27
Log space used by the database (Bytes)     = 3750726
Maximum secondary log space used (Bytes)   = 0
Maximum total log space used (Bytes)       = 40319972
Secondary logs allocated currently         = 0
Log pages read                             = 5561
Log read time (sec.ns)                     = 5.000000004
Log pages written                          = 89962
Log write time (sec.ns)                    = 3046.000000004
Number write log IOs                       = 74822
Number read log IOs                        = 696
Number partial page log IOs                = 22821
Number log buffer full                     = 0
Log data found in buffer                   = 152701
Appl id holding the oldest transaction     = 11
Log to be redone for recovery (Bytes)      = 3765430
Log accounted for by dirty pages (Bytes)   = 3765430
File number of first active log            = 3691
File number of last active log             = 3740
File number of current active log          = 3691
Package cache lookups                      = 185429597
Package cache inserts                      = 9486
Package cache overflows                    = 0
Package cache high water mark (Bytes)      = 52494336
Application section lookups                = 1737096759
Application section inserts                = 173693
Catalog cache lookups                      = 737785
Catalog cache inserts                      = 960
Catalog cache overflows                    = 0
Catalog cache high water mark              = 4521984
 Shared high water mark                    = 0
 Corresponding shared overflows            = 0
 Total shared section inserts              = 0
 Total shared section lookups              = 0
 Private high water mark                   = 13232700
 Corresponding private overflows           = 0
 Total private section inserts             = 173693
 Total private section lookups             = 2927458754
Number of hash joins                       = 1418296
Number of hash loops                       = 0
Number of hash join overflows              = 15
Number of small hash join overflows        = 0
Post threshold hash joins (shared memory)  = 0
Active hash joins                          = 0
       Current size (bytes)                    = 655360
       High water mark (bytes)                 = 7733248
       Configured size (bytes)                 = 20512768
       Current size (bytes)                    = 47710208
       High water mark (bytes)                 = 52494336
       Configured size (bytes)                 = 1059061760
       Current size (bytes)                    = 4521984
       High water mark (bytes)                 = 4521984
       Configured size (bytes)                 = 1059061760
       Secondary ID                            = 6
       Current size (bytes)                    = 15073280
       High water mark (bytes)                 = 15073280
       Configured size (bytes)                 = 1059061760
       Secondary ID                            = 5
       Current size (bytes)                    = 69402624
       High water mark (bytes)                 = 69402624
       Configured size (bytes)                 = 1059061760
       Secondary ID                            = 4
       Current size (bytes)                    = 41549824
       High water mark (bytes)                 = 41549824
       Configured size (bytes)                 = 1059061760
       Secondary ID                            = 3
       Current size (bytes)                    = 263454720
       High water mark (bytes)                 = 263454720
       Configured size (bytes)                 = 1059061760
       Secondary ID                            = 2
       Current size (bytes)                    = 8585216
       High water mark (bytes)                 = 8585216
       Configured size (bytes)                 = 1059061760
       Secondary ID                            = 1
       Current size (bytes)                    = 169279488
       High water mark (bytes)                 = 169279488
       Configured size (bytes)                 = 1059061760
       Current size (bytes)                    = 851968
       High water mark (bytes)                 = 851968
       Configured size (bytes)                 = 1059061760
       Current size (bytes)                    = 589824
       High water mark (bytes)                 = 589824
       Configured size (bytes)                 = 1059061760
       Current size (bytes)                    = 458752
       High water mark (bytes)                 = 458752
       Configured size (bytes)                 = 1059061760
       Current size (bytes)                    = 393216
       High water mark (bytes)                 = 393216
       Configured size (bytes)                 = 1059061760
       Current size (bytes)                    = 2490368
       High water mark (bytes)                 = 18284544
       Configured size (bytes)                 = 146800640
       Current size (bytes)                    = 212926464
       High water mark (bytes)                 = 212926464
       Configured size (bytes)                 = 212992000
       Current size (bytes)                    = 15073280
       High water mark (bytes)                 = 25690112
       Configured size (bytes)                 = 105381888
       Current size (bytes)                    = 131072
       High water mark (bytes)                 = 131072
       Configured size (bytes)                 = 20971520

これをハッシュに挿入するにはどうすればよいですか

私のやり方は

%hash = map {chomp ; split /\s+=\s+[0-9]/} (@dblst);

ここで、dblst はデータを含む配列です

私がこれをするとき、私は得ます

$VAR1 = {
          '' => '0971520',
          '385955328' => '      File system used space (bytes)',
          'Deadlocks ' => 'detected',
          'triggers' => '18',
          'Catalog cache ' => 'overflows',
          '69279488' => '       Configured size (bytes)',
          'Catalog cache high water ' => 'mark',
          'Internal rows ' => 'updated',
          'Failed statement ' => 'operations',
          'Snapshot ' => 'timestamp',
          '733248' => '       Configured size (bytes)',
          'Rows ' => 'read',
          'written' => '9962',
          'Buffer pool temporary data physical ' => 'reads',
          'reads' => 'Asynchronous pool xda page ',
          'time' => '806167',
          'Number of small hash join ' => 'overflows',
          '31072' => '       Configured size (bytes)',
          '750726' => 'Maximum secondary log space used (Bytes)',
          'Asynchronous pool index page ' => 'writes',
          'Direct ' => 'reads',
          '      File system total space (bytes)' => '',
          'lookups' => '926693856',
          'transactions' => 'Total Private Sort heap ',
          'Log space used by the database (Bytes)' => '',
          'sorts' => 'Buffer pool data logical ',
          '490368' => '       High water mark (bytes)',
          'Buffer pool temporary index physical ' => 'reads',
          '.000000004' => 'Log pages ',
          'inserted' => '95031',
          '684' => 'Asynchronous pool data page ',
          '28012' => 'Direct write ',
          '691' => 'Package cache ',
          'Time waited for prefetch (ms)' => '',
          'rebinds' => '2',
          '059061760' => '       Current size (bytes)',
          'connections' => '2',
          'Database files ' => 'closed',
          '       Current size (bytes)' => '',
          'Log write time (sec.ns)' => '',
          '17' => 'Internal ',
          '7948539904' => 'High water mark for ',
          '7710208' => '       High water mark (bytes)',
          'transaction' => '1',
          '51968' => '       High water mark (bytes)',
          'Log read time (sec.ns)' => '',
          'Update/Insert/Delete statements ' => 'executed',
          'Shared Sort heap high water ' => 'mark',
          'total' => 'Applications connected ',
          '3908937' => 'Total elapsed asynchronous write ',
          '6653' => 'Buffer pool index ',
          'Asynchronous xda read ' => 'requests',
          'joins' => '       Current size (bytes)',
          'Inactive stmt history memory usage (bytes)' => 'Internal automatic ',
          'Commit statements ' => 'attempted',
          '      Storage path free space (bytes)' => '',
          ' Total private section ' => 'inserts',
          'ID' => '       Current size (bytes)',
          'Agents associated with ' => 'applications',
          '765430' => 'Log accounted for by dirty pages (Bytes)',
          'Agents currently waiting on ' => 'locks',
          'Buffer pool temporary index logical ' => 'reads',
          '6412' => 'Total ',
          '1549824' => '       High water mark (bytes)',
          '       Configured size (bytes)' => '',
          '8934507' => 'Unread prefetch ',
          '96' => 'Number partial page log ',
          '585216' => '       High water mark (bytes)',
          '486' => 'Package cache ',
          'Log to be redone for recovery (Bytes)' => '',
          'commits' => '9840',
          '05381888' => '       Current size (bytes)',
          '93216' => '       Configured size (bytes)',
          '46800640' => '       Current size (bytes)',
          'writes' => '3430',
          'Exclusive lock ' => 'escalations',
          'No victim buffers ' => 'available',
          '428' => 'Internal rows ',
          '7' => 'Number of indoubt ',
          'loops' => 'Number of hash join ',
          'mark' => '3232700',
          '52842' => 'Static statements ',
          'Maximum total log space used (Bytes)' => '',
          '72' => 'Lock list memory in use (Bytes)',
          'Buffer pool data ' => 'writes',
          'Total elapsed asynchronous read ' => 'time',
          'currently' => 'Log pages ',
          'Application ' => 'connects',
          'File number of first active ' => 'log',
          'Dirty page steal cleaner ' => 'triggers',
          'agents' => '2',
          'allocated' => '5',
          'Xquery statements ' => 'executed',
          'inserts' => ' Total shared section ',
          ' Corresponding private ' => 'overflows',
          'pages' => '147',
          'Number of hash ' => 'joins',
          '225' => 'Rows ',
          '2747' => 'Secondary connects ',
          'Buffer pool index logical ' => 'reads',
          'Dynamic statements ' => 'attempted',
          'paths' => '      File system ',
          '6388' => 'Select SQL statements ',
          'deadlock' => '7',
          '       High water mark (bytes)' => '',
          '63454720' => '       Configured size (bytes)',
          '26622020' => 'Direct ',
          'IOs' => '2821',
          'attempted' => '7',
          '0319972' => 'Secondary logs allocated ',
          'Asynchronous data read ' => 'requests',
          'executed' => '06',
          'Catalog database partition ' => 'number',
          '403328' => 'Buffer pool temporary data logical ',
          'Direct read ' => 'requests',
          'Number read log ' => 'IOs',
          '477714' => 'Asynchronous pool data page ',
          'Locks held ' => 'currently',
          '046.000000004' => 'Number write log ',
          'Application section ' => 'lookups',
          'overflows' => '5',
          '       Secondary ' => 'ID',
          '03030' => 'Buffer pool xda logical ',
          '49460' => 'DDL statements ',
          '52701' => 'Appl id holding the oldest ',
          '04' => 'Internal rollbacks due to ',
          'Log data found in ' => 'buffer',
          'read' => '561',
          '89824' => '       Configured size (bytes)',
          '732753' => 'Direct write elapsed time (ms)',
          'Package cache ' => 'inserts',
          '18401' => 'Rollback statements ',
          '928' => 'Active ',
          'Sort ' => 'overflows',
          'Appls. executing in db manager ' => 'currently',
          'Direct reads elapsed time (ms)' => '',
          '150' => 'Dirty page threshold cleaner ',
          'Post threshold hash joins (shared memory)' => 'Active hash ',
          '2347' => 'Rows ',
          '37785' => 'Catalog cache ',
          'Internal ' => 'rollbacks',
          'Number log buffer ' => 'full',
          '9402624' => '       Configured size (bytes)',
          '521984' => '       Configured size (bytes)',
          'Buffer pool data physical ' => 'reads',
          '12926464' => '       Configured size (bytes)',
          '2/23/2013 21:01:29.252390' => 'Number of automatic storage ',
          '58752' => '       High water mark (bytes)',
          '5073280' => '       High water mark (bytes)',
          '56654938' => 'Binds/precompiles ',
          'log' => '740',
          '733272267' => 'Application section ',
          'requests' => '441',
          '385867681' => 'Buffer pool index physical ',
          '73693' => ' Total private section ',
          '679989' => 'LSN Gap cleaner ',
          '4' => 'Maximum coordinating ',
          '770802' => 'Asynchronous index read ',
          'Lock ' => 'Timeouts',
          'selected' => '4445812686',
          'File number of current active ' => 'log',
          '

いくつかの数値が左側にあることがわかります。すべての数値を右側に配置して、そのハッシュでいくつかの算術演算を実行したいのですが...助けていただければ幸いです

4

1 に答える 1

5

あなたの問題は、使用している正規表現と無制限の分割です。キーと値のみを探しているので、(おそらく) 分割を 2 つのフィールドに制限する必要があります。少数または多数のフィールドに分割されるフィールドが必要な場合は、ハッシュの割り当てが破損します。また、空白で囲まれた等号である区切り記号でのみ分割する必要があります。

あなたの正規表現:

/\s+=\s+[0-9]/

「空白の後に等号が続き、その後に空白が続き、数字が続く」で分割されます。桁が削除されます。のような行を想定するとfoo = 0、結果として のリストが得られます"foo", ""

必要なものは次のとおりです。

split /\s*=\s*/, $_, 2;

これにより、等号の周りの空白が取り除かれ、最大 2 つのフィールド (おそらくキーと値) のみが返されます。先頭の空白を含むフィールドがまだいくつか見つかりますが、それは許容できると思います。

ステートメントを使用するmapと、リスト全体が返されるという欠点があり、ご覧のとおり、リストが破損する可能性があります。より賢明なアプローチは、for ループを使用することです。

my %hash;
for (@dblst) {
    chomp;
    my ($key, $val) = split /\s*=\s*/, $_, 2;
    $hash{$key} = $val;
}

このコードを使用すると、制御ステートメントを挿入して、空白のキー/値の挿入を防止したり、重複を防止したり、必要な他のあらゆる種類のテストを実行したりすることも簡単になります。

于 2013-02-23T15:49:00.737 に答える