Boucle WHILE qui fonctionne pas (débutant)

Résolu
bheadman Messages postés 105 Date d'inscription   Statut Membre Dernière intervention   -  
PeterPeterPeter Messages postés 202 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

Bonjour,
J'ai un soucis avec une boucle WHILE
Voici un code qui fonctionne
while ( <IPNUM>  )  {
 chomp;
 if ( $_ =~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/) {
   push (@ipconf,split(/\D+/,$_));
 }
}


Et voici le même code un peu modifier mais là ça ne fonctionne pas : /

while ( <PASSWD>  )  {
 chomp;
 if ( $_ =~ /bin/) {
   push (@listepwd,$_);
 }
}

5 réponses

bheadman Messages postés 105 Date d'inscription   Statut Membre Dernière intervention  
 
Voici le code et l'erreur
[root@srv41001 root]# cat test2.pl
#!/usr/bin/perl -w

# Open the dump file
open(PASSWD,"/etc/passwd") || die "Can't open /etc/passwd...$!\n";

my @listepwd = ()
# Parse out the lines with ip numbers
while ( <PASSWD>  )  {
 chomp;
 if ( $_ =~ /bin/) {
   push (@listepwd,$_);
 }
}
close(IPNUM);

print "@listepwd\n"


[root@srv41001 root]# ./test2.pl
syntax error at ./test2.pl line 10, near ") {"
syntax error at ./test2.pl line 15, near "}"
Execution of ./test2.pl aborted due to compilation errors.
0
bheadman Messages postés 105 Date d'inscription   Statut Membre Dernière intervention  
 
et voici le cpde qui fonctionne


[root@srv41001 root]# cat test.pl
#!/usr/bin/perl -w
# Generate the IP#, router, and subnet mask by running the "ipconfig" command.
# Run ipconfig and dump its contents to ipdump.

my @t = ();
open(IPNUM,"|ifconfig > ipdump") || die "Can't run 'ifconfig'...$!\n";
close(IPNUM);

# Open the dump file
open(IPNUM,"ipdump") || die "Can't open ipdump...$!\n";

# Parse out the lines with ip numbers
while ( <IPNUM>  )  {
 chomp;
 if ( $_ =~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/) {
   push (@ipconf,split(/\D+/,$_));
 }
}
close(IPNUM);

my $IPAdws2;
my $SubnetMsk2;
my $Router2;
$IPAdws2 = join(".",@ipconf[1...4]);
$SubnetMsk2 = join(".",@ipconf[5...8]);
$Router2 = join(".",@ipconf[9...12]);
print "Adresse ip : \t$IPAdws2\nBcast : \t$SubnetMsk2\nMasque : \t$Router2\n"



[root@srv41001 root]# ./test.pl
Adresse ip : 192.78.90.4
Bcast : 192.78.90.255
Masque : 255.255.255.0
0
PeterPeterPeter Messages postés 202 Date d'inscription   Statut Membre Dernière intervention   30
 
my @listepwd = ()


T'as oublié ; :)
0
bheadman Messages postés 105 Date d'inscription   Statut Membre Dernière intervention  
 
GGGRRRrrr

J'ai du mal avec ces ";" !

MERCI
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
PeterPeterPeter Messages postés 202 Date d'inscription   Statut Membre Dernière intervention   30
 
De rien, ça saute aux yeux quand t'en as oublié des centaines :)

Amuse toi bien maintenant !
0