Reading arrays and txt files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • markoj
    New Member
    • Jul 2007
    • 11

    Reading arrays and txt files

    Hi,
    Iam new to perl and new to programming full stop
    I am writing in perl to read a file no problem then i have parsed the large txt file to read the data I want no problems but I am having severe difficulty with the last piece this is going to be ran daily it is going to check the percentage levels of each disk if it is above 80% i need it to issue a warning
    I have parsed all lines containing % sign i have tried split, tried to move these lines to a new array but cannot get anything to work can anybody help me with this here is what I have done for the last part

    [CODE=perl]
    foreach my $lines (@array_of_data ) {
    if ($lines =~ m/[%]/i) {
    print "$lines\n";

    #push ($line,@array)
    #print "@array [4]\n";
    #print "@array\n";
    #@array = split(/[ ]+/, $line);
    #tr\%\ d;

    if ($array_of_data[4]>80 ) {
    print "Please look at this disk immediately\n";
    } else {
    print "Disk levels are ok\n";
    }
    }
    }
    [/CODE]
  • miller
    Recognized Expert Top Contributor
    • Oct 2006
    • 1086

    #2
    [CODE=perl]
    foreach my $line (@array_of_data ) {
    if ($line =~ m{(\d+)%}i) {
    my $percentage = $1;
    print "$line\n";
    if ($percentage > 80 ) {
    print "Please look at this disk immediately\n";
    } else {
    print "Disk levels are ok\n";
    }
    }
    }
    [/CODE]

    - Miller

    Comment

    • KevinADC
      Recognized Expert Specialist
      • Jan 2007
      • 4092

      #3
      Nice not to have to ask: what have you tried so far?

      MIller has posted a working solution so give it a study.

      Comment

      • markoj
        New Member
        • Jul 2007
        • 11

        #4
        Thanks Millar thats great I had made an attempt earlier in the week at what you done but I got it all the wrong way round thanks so much for your help

        Comment

        • miller
          Recognized Expert Top Contributor
          • Oct 2006
          • 1086

          #5
          Your welcome,

          - Miller

          Comment

          Working...