print
hallo ,
nach einem "print" habe ich folgende ergebniss bekommen
27
35
22
nun will ich mein ergebnis wie folgend bekommen : 27 35 22 .
Gruß
Re: print
MOMO schrieb:
> hallo ,
>
> nach einem "print" habe ich folgende ergebniss bekommen
>
> 27
> 35
> 22
>
> nun will ich mein ergebnis wie folgend bekommen : 27 35 22 .
>
>
> Gruß
Wo hast Du die Daten denn her? Wie machst Du das print?
Wenn die Daten aus einer Datei kommen, hast Du auch ein chomp gemacht?
Oder hast Du bei dem print ein "\n" stehen?
Re: print
hallo ,
die daten kommen aus folgende programm:
____________________________________________________________ ________----
my $session =3D Net::Telnet::Cisco-> new (Host =3D> '10.200.2.100');
$session->login('admin', 'cisco');
# Execute a command
my [at] output =3D $session->cmd('show run');
#print [at] output;
foreach( [at] output)
{
if ( $_ =3D~ "interface ATM" ) {
$interface=3D$_;
#chomp($interface);
#print "$_\t";
}
if ( $_ =3D~ "pvc"){
$pvc=3D$_;
#chomp($pvc);
#print "$_\t";
}
if ( $_ =3D~ "protocol ip " ){
$ip=3D$_;
#print "$_\t";
}
if ( $_ =3D~ "cbr" ){
$cbr=3D$_;
#print "$_\t";
}
print "Int:$interface | PVC:$pvc | IP:$ip |Cbr:$cbr \n";
____________________________________________________________ ______________
wie unten steht will ich mein output in form einen array bekommen aber
ich bekomme folgenede ergebnis :
int | PVC
ip| cbr
aber ich will folgendes
int| Pvc| ip| Cbr
gruß.
Re: print
MOMO:
> print "Int:$interface | PVC:$pvc | IP:$ip |Cbr:$cbr \n";
>
> wie unten steht will ich mein output in form einen array bekommen aber
> ich bekomme folgenede ergebnis :
>
> int | PVC
> ip| cbr
Das kann nicht stimmen - in dem obigen print-Befehl muss als erstes
immer "Int:" ausgegeben werden, egal was danach kommt. In deiner
Ausgabe fehlt das, wie auch die übrigen fixen Teile des Strings.
Gerade du als Akademiker, der sich mit Programmierung beschäftigt,
solltest wissen, dass Genauigkeit bei jeder Fehlersuche das oberste
Gebot ist!
Poste also noch einmal _genau_, wie die Ausgabe des obigen print-
Befehls aussieht.
> aber ich will folgendes
>
> int| Pvc| ip| Cbr
Darüber unterhalten wir uns, wenn wir genau wissen, was du _jetzt_
beokommst... ;-)
LG, Ferry
--
Ing Ferry Bolhar
Magistrat der Stadt Wien - MA 14
A-1010 Wien
E-Mail: bol [at] adv.magwien.gv.at
Re: print
MOMO schrieb:
> wie unten steht will ich mein output in form einen array bekommen aber
> ich bekomme folgenede ergebnis :
>
> int | PVC
> ip| cbr
> aber ich will folgendes
>
> int| Pvc| ip| Cbr
Nun, als Informatiker sollte es Dir nicht schwerfallen zu erkennen,
daß Du Deine Daten offenbar transformieren mußt, und zwar so, daß
sie keine Zeilenwechsel auf dem Terminal verursachen.
Re: print
Hallo Fery!
interface ATM1/0 | PVC:
pvc 22/180 |
pvc 22/180
Int:
interface ATM1/0 | PVC:
pvc 22/180 |
protocol ip 10.200.50.81
Int:
interface ATM1/0 | PVC:
pvc 22/180 |
cbr 128
Int:
interface ATM1/0 | PVC:
pvc 22/190 |
pvc 22/190
Int:
interface ATM1/0 | PVC:
pvc 22/190 |
protocol ip 10.200.50.83
Int:
interface ATM1/0 | PVC:
pvc 22/190 |
cbr 128
Int:
interface ATM1/0 | PVC:
pvc 22/202 |
pvc 22/202
Int:
interface ATM1/0 | PVC:
pvc 22/202 |
Int:
interface ATM1/0 | PVC:
pvc 22/202 | protocol ip 10.200.50.82
Int:
interface ATM1/0 | PVC:
pvc 22/202 |
cbr 128
Int:
interface ATM1/0 | PVC:
pvc 122/202 |
pvc 122/202
Int:
interface ATM1/0 | PVC:
pvc 122/202 |
protocol ip 10.200.51.82
Int:
interface ATM1/0 | PVC:
pvc 122/202 |
cbr 128
hier was ich auf den console bekomme!!
Re: print
Hallo Fery!
interface ATM1/0 | PVC:
pvc 22/180 |
pvc 22/180
Int:
interface ATM1/0 | PVC:
pvc 22/180 |
protocol ip 10.200.50.81
Int:
interface ATM1/0 | PVC:
pvc 22/180 |
cbr 128
Int:
interface ATM1/0 | PVC:
pvc 22/190 |
pvc 22/190
Int:
interface ATM1/0 | PVC:
pvc 22/190 |
protocol ip 10.200.50.83
Int:
interface ATM1/0 | PVC:
pvc 22/190 |
cbr 128
Int:
interface ATM1/0 | PVC:
pvc 22/202 |
pvc 22/202
Int:
interface ATM1/0 | PVC:
pvc 22/202 |
Int:
interface ATM1/0 | PVC:
pvc 22/202 | protocol ip 10.200.50.82
Int:
interface ATM1/0 | PVC:
pvc 22/202 |
cbr 128
Int:
interface ATM1/0 | PVC:
pvc 122/202 |
pvc 122/202
Int:
interface ATM1/0 | PVC:
pvc 122/202 |
protocol ip 10.200.51.82
Int:
interface ATM1/0 | PVC:
pvc 122/202 |
cbr 128
------------------------------------------------------------ ---------------=
------------------------------------------------------------
hier was ich auf den console bekomme!!
Und was habe ich geschrieben ist folgendes:
use Net::Telnet::Cisco;
use strict;
my $linec;
my $line;
my $interface;
my $pvc;
my $array;
my $session =3D Net::Telnet::Cisco-> new (Host =3D> '10.200.2.100');
$session->login('admin', 'cisco');
# Execute a command
my [at] output =3D $session->cmd('show run');
#print [at] output;
print "C:$#output";
$linec=3D0;
while($linec <=3D $#output)
{
if ( $output[$linec] =3D~ "interface ATM" )
{ # Im Interface
$interface=3D$output[$linec];
chomp($interface);
while(!($output[$linec] =3D~ "!") )
{
if ($output[$linec] =3D~ "pvc")
{ # Sub-Interface PVC
$pvc=3D$output[$linec];
chomp($pvc);
while(!($output[$linec] =3D~ "!") )
{
$line=3D$output[$linec];
chomp($line);
print "Int:$interface | PVC:$pvc | $line\n";
$linec=3D$linec+1;
}
}
$linec=3D$linec+1;
}
}
#print "$output[$linec]";
$linec=3D$linec+1;
}
Danke für die MAil!
Gruß
Re: print
MOMO:
> Int:
> interface ATM1/0 | PVC:
> pvc 22/180 |
> protocol ip 10.200.50.81
Siehst du, kaum ist man genau, wird einem schon geholfen!
Dein Problem dürfte sein, dass die Werte mit einem Zeilen-
vorschub _beginnen_. Da hilft chomp, dass nur am _Ende_
Zeilenvorschübe entfernt, natürlich nicht.
Setze in deinem Code statt
chomp($interface);
diesen Befehl ein:
$interface =~ s/^\n//;
Er entfernt ein führenden Zeilenvorschub-Zeichen.
Klappt das nicht, dann probiere es mit \n\r bzw. \r\n;
es hängt davon ab, was genau die Cisco-Software
den Ausgabedaten voranstellt.
Das machst du natürlich auch bei $pvc.
HTH & LG,
Ferry
--
Ing Ferry Bolhar
Magistrat der Stadt Wien - MA 14
A-1010 Wien
E-Mail: bol [at] adv.magwien.gv.at