2013-02-23 50 views
2

我新的Perl和IM試圖插入一些數據散列,但卡住,幫助表示讚賞....我如何將它插入散列?

,我有以下數據

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 

現在我要如何插入到這散列

方式Im做是

%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', 
      ' 

你看到一些數字是在左邊,我希望所有的數字到右側,這樣我想與哈希執行一些算術運算...幫助是讚賞

回答

5

你的問題是你正在使用的正則表達式,和無限的分裂。由於您只查找關鍵字和值,因此您應該(可能)將分隔限制爲兩個字段。如果你應該有一個字段分裂成更少或更多的字段,你的散列分配將被破壞。你也應該只在分隔符上分割,這是一個被空白包圍的等號。

你的正則表達式:

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

將分裂的「空白後跟一個等號後面的空格後面跟着一個數字」。該數字將被刪除。假設一條線如foo = 0,那麼您將得到結果列表"foo", ""

你需要的是:

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

這會剝奪等號周圍的任何空白,並且只返回最多兩個字段(key和value,大概)的。你仍然會發現一些領域包含領先的空白,但我認爲這是可以接受的。

使用map語句的缺點是它返回一個完整的列表,正如您看到列表可能會損壞一樣。一個更明智的方法是使用一個for循環:

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

有了這個代碼,也容易插入控制語句,防止空白鍵/值的插入,防止重複,做其他各種測試你想。

+0

它工作的感謝人,我認爲我應該在處理這種文件時處理正則表達式 – mviswa 2013-02-23 16:01:03

+0

@mViswa沒有比在真實世界的數據上嘗試它們更好的方式來訓練正則表達式。一定要使用'使用警告;嚴格使用;',因爲它們將提供寶貴的幫助。此外,您知道您可以通過點擊旁邊的複選標記來接受您的問題的答案。 – TLP 2013-02-23 16:05:38

+0

非常感謝很多人,根據您的建議不客氣 – mviswa 2013-02-23 16:10:20