Я новичок в Perl. Я пытаюсь извлечь информацию VLAN, хранящуюся в файле. Содержимое файла,Perl regex не может соответствовать концу строки
VLAN0001
Spanning tree enabled protocol rstp
Interface Role Sts Cost Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
PE8/1 Desg FWD 2 128.2945 P2p Edge
Ta579 Desg FWD 3 128.5761 P2p Edge
VLAN0023
Spanning tree enabled protocol rstp
Interface Role Sts Cost Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
PE8/1 Desg FWD 2 128.2945 P2p Edge
Ta579 Desg FWD 3 128.5761 P2p Edge
ACCOUNT
Spanning tree enabled protocol rstp
Interface Role Sts Cost Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
Ta579 Desg FWD 1 128.5764 P2p
У меня есть PERL код как,
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my $filename = "spanning-tree1.txt";
open my $fh, '<', $filename or die "error opening $filename: $!";
my $data = do { local $/; <$fh> };
my @list = ($data =~ /(^[A-Za-z0-9]+.*?(?=^[A-Za-z0-9]+$|\Z))/msg);
#print Dumper($data);
#print "\n##############################################\n";
print Dumper(\@list);
И его из пут,
$VAR1 = [
'VLAN0001
Spanning tree enabled protocol rstp
Interface Role Sts Cost Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
PE8/1 Desg FWD 2 128.2945 P2p Edge
Ta579 Desg FWD 3 128.5761 P2p Edge
VLAN0023
Spanning tree enabled protocol rstp
Interface Role Sts Cost Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
PE8/1 Desg FWD 2 128.2945 P2p Edge
Ta579 Desg FWD 3 128.5761 P2p Edge
ACCOUNT
Spanning tree enabled protocol rstp
Interface Role Sts Cost Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
Ta579 Desg FWD 1 128.5764 P2p'
];
мне нужен выход (@list
), как,
$VAR1 = [
'VLAN0001
Spanning tree enabled protocol rstp
Interface Role Sts Cost Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
PE8/1 Desg FWD 2 128.2945 P2p Edge
Ta579 Desg FWD 3 128.5761 P2p Edge
',
'VLAN0023
Spanning tree enabled protocol rstp
Interface Role Sts Cost Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
PE8/1 Desg FWD 2 128.2945 P2p Edge
Ta579 Desg FWD 3 128.5761 P2p Edge
',
'ACCOUNT
Spanning tree enabled protocol rstp
Interface Role Sts Cost Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
Ta579 Desg FWD 1 128.5764 P2p'
];
Интересно, что я получаю правильные значения в @list
, когда ввод задан как строка и не читается из файла.
Благодаря обеспечить также ** ваш код perl ** –
Каков ваш ожидаемый результат? – Toto
Это не пусто, см .: http://ideone.com/KT4lJa –