Thread String einlesen und nachfolgendes Wort ausgeben
(20 answers)
Opened by SCORRPiO at 2014-04-15 10:15
Du musst den Punkt hinter \w weglassen, er matcht (fast) jedes Zeichen:
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 use strict; use warnings; while ( my $zeile = <DATA> ) { if ( $zeile =~ /OUT_OF_SYNC/ ) { my $ausgabe = $zeile; # <--- Unnötig, verwende $zeile my ($phy) = $ausgabe =~ /phy\s(\w+)/; my ($state) = $ausgabe =~ /state\s(\w+)/; my ($flags) = $ausgabe =~ /flags\s(\w+)/; printf "phy: $phy, state: $state, flags: $flags\n"; } } __DATA__ ioc0 phy 0 scsi_id 1 HITACHI HUS153014VLS300 A598, 136 GB, state ONLINE, flags OUT_OF_SYNC ioc0 phy 2 scsi_id 1 HITACHI ST3300657SS-H A598, 136 GB, state ONLINE, flags OUT_OF_SYNC Ausgabe: Edit: Sinnfreien /g-Modifier entfernt. Last edited: 2014-04-15 11:18:52 +0200 (CEST) Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it? -- Brian Kernighan: "The Elements of Programming Style"
|