Hi all,
I'm trying to get the follwoing to work:
what I am aiming to do is the following:
1. Read a file
2. Regex the df file and look for the line which contains "Used".
Problem:
- part 1 reads the file, confirmed, because I output this to the screen
- Part 2 Is where the problem is, as I connot get in to the while loop
while ($line = <DATA>)
I think the syntax is ok, could some one confirm this
Code below.
Thanks in Advance
Pat
#!/usr/bin/perl
use strict;
use warnings;
my $data_file = 'df.';
print "$data_file \n";
# Open the file for reading.
open (DATA, "$data_file") or die "can't open $data_file $!";
my @array_of_data = <DATA>;
print "this is the file: \n";
print @array_of_data;
print "\n";
#chomp($line);
my $line;
while ($line = <DATA>)
{
# any action here will be applied to each line of the file.
print "in While loop \n";
# chomp($line);
foreach my $line (@array_of_data)
{
# Start an if statement, the condition of which is
# "If this particular line contains the word dangerous."
if ($line =~ m/ Used/i)
{
# If the line contains "dangerous" then print the line out.
print "This line contains the word dangerous: $line\n";
} # End the if condition here.
} # End the foreach loop here.
}
close (DATA);