Article View: pl.comp.lang.perl
Article #52241Re: Polaczenie informacji z dwoch tablic hash
From: Szymon Sokół
Date: Sun, 05 Jun 2011 13:08
Date: Sun, 05 Jun 2011 13:08
39 lines
2586 bytes
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
Technical Details
Message-ID:
<7wiysz6jqyx9.dlg@falcon.sloth.hell.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.cyf-kr.edu.pl!agh.edu.pl!news.agh.edu.pl!.POSTED!dustpuppy.sloth.hell.pl!not-for-mailReferences:
<8f691faa-4f4a-43af-b3b8-5f2d3916fcb1@k17g2000vbn.googlegroups.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.cyf-kr.edu.pl!agh.edu.pl!news.agh.edu.pl!.POSTED!dustpuppy.sloth.hell.pl!not-for-mail
From: Szymon Sokół
<szymon@bastard.operator.from.hell.pl>
Newsgroups: pl.comp.lang.perl
Subject: Re: Polaczenie informacji z dwoch tablic hash
Date: Sun, 5 Jun 2011 15:08:38 +0200
Organization: Guy Fawkes Society
Lines: 39
Sender: szymon@news.agh.edu.pl
Message-ID: <7wiysz6jqyx9.dlg@falcon.sloth.hell.pl>
References: <8f691faa-4f4a-43af-b3b8-5f2d3916fcb1@k17g2000vbn.googlegroups.com>
NNTP-Posting-Host: 89-79-74-119.dynamic.chello.pl
Mime-Version: 1.0
X-Trace: news.agh.edu.pl 1307279755 31763 89.79.74.119 (5 Jun 2011 13:15:55 GMT)
X-Complaints-To: abuse@agh.edu.pl
NNTP-Posting-Date: Sun, 5 Jun 2011 13:15:55 +0000 (UTC)
User-Agent: 40tude_Dialog/2.0.15.1 Hamster/2.1.0.11
X-Face: xic?6f"rD)k-tM.]L]A6l4W7_aGt({}&{D,hiRI.8cPtf,1F.w@Qkl!vr23o1UY-BfXO$p< hk5>ijB?eBy)?!C<@)+%U\&`1X)MJ>.i.qgkY]4mvL62j<|xJRG/5:7:l8q]x;v!)Bz^r/!yG8DxoD -@fnC,g]BAXj
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit