🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: pl.comp.lang.perl
2 messages
2 total messages Started by Scottie Sun, 05 Jun 2011 08:55
Polaczenie informacji z dwoch tablic hash
#52240
Author: Scottie
Date: Sun, 05 Jun 2011 08:55
63 lines
3329 bytes
Hej!
Utknalem na dobre :-/ Pomozecie?!

Po wykonaniu backupu Oracle'owym narzedziem RMAN, parsuje plik logu i
tworze dwie tablice hash z wieloma wartosciami na klucz:

%channel  #zbiera informacje z logu specyficzne dla kazdego kanalu
 {ch1}
    ->[0]   allocated channel: ch1
	->[1]   channel ch1: SID=596 device type=DISK
	->[2]   channel ch1: starting compressed full datafile backup set
	->[3]   channel ch1: specifying datafile(s) in backup set
 {ch2}
    ->[0]   allocated channel: ch2
	->[1]   channel ch2: SID=15 device type=DISK
	->[2]   channel ch2: starting compressed full datafile backup set
	->[3]   channel ch2: specifying datafile(s) in backup set

%channel_files #zbiera informacje o plikach zbackupowanych przez dany
kanal
 {ch1}
    ->[0]   input datafile file number=00014 name=/foo/oradata/foo/foo-
data04.dbf
    ->[1]   input datafile file number=00019 name=/foo/oradata/foo/foo-
data05.dbf
 {ch2}
    ->[0]   input datafile file number=00013 name=/foo/oradata/foo/foo-
index03.dbf
    ->[1]   input datafile file number=00012 name=/foo/oradata/foo/foo-
data03.dbf


Chcialbym powiazac informacje z tych dwoch tablic, aby output byl
taki:
============================

Files for channel 'ch1':
  Channel name    Channel type   File Number      File Name
  --------------- -------------- ----------------
---------------------------
  ch1             DISK           00014            /foo/oradata/foo/foo-
data04.dbf
  ch1             DISK           00019            /foo/oradata/foo/foo-
data05.dbf

Files for channel 'ch2':
  Channel name    Channel type   File Number      File Name
  --------------- -------------- ----------------
---------------------------
  ch2             DISK           00013            /foo/oradata/foo/foo-
index03.dbf
  ch2             DISK           00012            /foo/oradata/foo/foo-
data03.dbf

============================

Kombinuje na prawo i lewo, ale w ogole nie wiem jak sie za to zabrac.
Pracuje jako DBA i ten problem wykracza poza moja znajomosc Perla.
Bylbym wdzieczny za udzielona pomoc, abym mogl pojsc dalej.

Pozdrawiam,
--
Scottie
Re: Polaczenie informacji z dwoch tablic hash
#52241
Author: Szymon Sokół
Date: Sun, 05 Jun 2011 13:08
39 lines
2586 bytes
On Sun, 5 Jun 2011 01:55:36 -0700 (PDT), Scottie wrote:

> Kombinuje na prawo i lewo, ale w ogole nie wiem jak sie za to zabrac.

File numbers nie są recyklowane, prawda? To jakoś tak:

my %files;
for my $ch (keys %channel) {
  for my $line (@$ch) {
    if($line =~ /input datafile file number=0*(\d+) name=(\S+)/) {
      $files{$ch}{$1}{'filename'} = $2;
    }
  }
}
for my $ch (keys %channel_files) {
  for my $line (@$ch) {
    if($line =~ /channel \S+: SID=(\d+) device type=(\S+)/) {
      $files{$ch}{$1}{'devicetype'} = $2; # $1 - SID, $2 - type
    }
  }
}
for my $ch (keys %files) {
  printf "Files for channel '%s':\n", $ch;
  print "  Channel name    Channel type   File Number      File Name\n";
  for my $sid (keys %{$files{$ch}}) {
    printf "%10s %15s %6d %s\n", $ch, $files{$ch}{$sid}{'devicetype'}, 
                                $sid, $files{$ch}{$sid}{'filename'};
  }
}

Chyba niczego nie poplądałem, mam nadzieję; 0*(\d+) w regexpie, żeby zera
wiodące pominąć, bo string '000015' i '15' to nie to samo, a widzę, że raz
masz tak, a raz tak. O właściwe formatowanie wyniku zadbaj sam.

-- 
Szymon Sokół (SS316-RIPE) -- Network Manager                                 B
Computer Center, AGH - University of Science and Technology, Cracow, Poland  O
http://home.agh.edu.pl/szymon/ PGP key id: RSA: 0x2ABE016B, DSS: 0xF9289982  F
Free speech includes the right not to listen, if not interested -- Heinlein  H
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads