Leser: 18
1 2 3 4
# Kontrollausgabe print qq~cat /etc/hosts | grep "#village $tmpmainvillage"~; # Kommando ausführen und Ausgabe in @village ablegen @village = qx{ cat /etc/hosts | grep "#village $tmpmainvillage" };
@village = qx{ grep "#village $tmpmainvillage" /etc/hosts};
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#!/usr/bin/perl use strict; use warnings; my $file='/etc/hosts'; my $tmpmainvillage='Entenhausen'; my @list; open(my $fh, '<', $file) or die "Error open $file ($!)\n"; while(my $line=<$fh>) { push(@list,$line) if($line=~m/#village $tmpmainvillage/); } close($fh); print join("\n",@list)."\n";