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 -
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
Et voici le même code un peu modifier mais là ça ne fonctionne pas : /
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,$_); } }
A voir également:
- Boucle WHILE qui fonctionne pas (débutant)
- Logiciel de programmation pour débutant - Guide
- Logiciel montage vidéo débutant - Guide
- Pc qui s'allume et s'éteint en boucle - Forum Virus
- Tv orange chargement en boucle ✓ - Forum TV & Vidéo
- Xiaomi s'éteint tout seul et se rallume en boucle - Forum Xiaomi
5 réponses
Voici le code et l'erreur
[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.
[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.
et voici le cpde qui fonctionne
[root@srv41001 root]# ./test.pl
Adresse ip : 192.78.90.4
Bcast : 192.78.90.255
Masque : 255.255.255.0
[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
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question