Loading ...
Sorry, an error occurred while loading the content.

RE: [PBML] foreach help ?

Expand Messages
  • Smith, Sheldon
    Sure. You are reading the first item from the @date list, then working with the entire file. When you get the second next item from the @date list,
    Message 1 of 1 , Mar 1 7:41 PM
    • 0 Attachment
      Sure. You are reading the first item from the "@date" list, then working
      with the entire <FSTAB> file. When you get the second next item from the
      "@date" list, the <FSTAB> file is already used up.

      Either put your FSTAB open and close in the foreach loop, or first read the
      useful parts of the FSTAB file into a second list so you have both lists in
      memory.

      -----Original Message-----
      From: Barazani [mailto:bara_zani@...]
      Sent: Thursday, March 01, 2001 10:43 AM
      To: Perl-Beginners
      Subject: [PBML] foreach help ?


      Hi ,
      I am having trouble with this script (see script below ....) .
      bascilly i want to get some vars from one file (DUMPS)
      and check if they exist on the other file (VFSTAB)
      the problem is inside the foreach loop .
      it will only process the while loop once .
      so if i have in dumpdates ->

      hda1 0
      hda2 0
      hda3 0


      and in vfstab ->

      hda1 rhda1
      hda2 rhda2
      hda3 rhda3
      hda4 rhda4

      it will output ->
      hda1
      hda1
      *********
      rhda1
      hda1
      *********
      rhda2
      hda1
      *********
      rhda3
      hda1
      *********
      rhda4
      hda2
      hda3

      instead of doing the same with hda2 and jda3 ?
      why is that ?
      any idea's ?
      thanks
      barazani




      #!/usr/local/bin/perl
      use strict;
      my @date=();
      #############################
      #open the files needed
      #############################
      open("FSTAB","/etc/vfstab") || die "cannot open vfstab";
      open("DUMPS","/etc/dumpdates") || die "cannot open dumpdates";
      #############################
      while(<DUMPS>){
      if(/\b0\b/){
      my @rawdev=split(/\s+/,$_);
      push(@date,$rawdev[0]);
      }
      }
      my $slice=" ";
      foreach $slice (@date) {
      while(<FSTAB>){
      print "$slice \n";
      print "*********\n";
      my @dev=split(/\s+/,$_);
      print "$dev[1]\n";
      }
      }
      #############################
      close(DUMPS);
      close(FSTAB);
      #############################
    Your message has been successfully submitted and would be delivered to recipients shortly.