Boucle WHILE qui fonctionne pas (débutant)

Résolu
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,$_);
 }
}


--
Le cerveau est un muscle, la bibliothèque une salle de musculation et le SMS le Mcdo de l'intelligence !!!
Configuration: Windows XP
Firefox 3.0.1

5 réponses

  1. 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
    1. 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
      1. my @listepwd = ()

        T'as oublié ; :)
        0
        1. GGGRRRrrr

          J'ai du mal avec ces ";" !

          MERCI
          0
          1. De rien, ça saute aux yeux quand t'en as oublié des centaines :)

            Amuse toi bien maintenant !
            0