in reply to Re^3: GLOB function (updated)
in thread GLOB function

I am attaching you the full code that I am executing. Here for every input files I am parsing lines starting with / RULECHECK/ .In each line there are 8 set of entries separated by spaces but i have to insert only 2 and 8th entry in output.txt

#!/usr/local/bin/perl -w open (OUT, ">output.txt"); use warnings; use strict; #use Data::Dump; # Debug use File::Basename qw/fileparse/; use File::stat; my %filelist; for my $file (glob '/user/*/ws/*/BLK_*/*.txt') { my $bn = fileparse($file); my $mtime = stat($file)->mtime; #dd $file, $bn, $mtime; # Debug $filelist{$bn} = [$file,$mtime] unless $filelist{$bn} && $filelist{$bn}[1]>$mtime; } #dd \%filelist; # Debug my @filelist = sort map {$_->[0]} values %filelist; #dd \@filelist; # Debug for my $file (@filelist) { my $fname = substr($file, rindex($file,"/")+1, length($file)-ri +ndex($file,"/")-1); #for printing file name in my output printf OUT $fname; open (IN, "<",$file); while ($line = <IN>){ chomp($line); if ($line =~/ RULECHECK/){ @temp = split (/\s+/,$line); $start = $temp[2]; $count = $temp[8]; if($count > 1000){ printf OUT "%-60s %-10s\n",$start,$count; } } } } system ("gedit output.txt");

Replies are listed 'Best First'.
Re^5: GLOB function
by haukex (Archbishop) on Jun 19, 2018 at 18:16 UTC
    I am attaching you the full code that I am executing.

    This code does not compile, so it can't be the code you're running. If I fix the obvious compilation errors, the code seems to work for me. I'm still confused how you're apparently getting undef values for the filenames - perhaps you could insert the line use Data::Dumper; print Dumper([glob '/user/*/ws/*/BLK_*/*.txt']); before the first for loop and show us the output. Otherwise, please see the three links in my previous post.