in reply to Re^2: GLOB function
in thread GLOB function

Use of uninitialized value $arg in stat at /user/s5e7420/local/lib/perl5/5.18.0/File/stat.pm line 206.

It looks like you're passing undef to stat, but I'm not aware of a situation where glob (Update: in list context) might return undef. Could you show the minimal code needed to reproduce this error? (Short, Self-Contained, Correct Example, How do I post a question effectively?, and I know what I mean. Why don't you?)

Replies are listed 'Best First'.
Re^4: GLOB function
by choroba (Cardinal) on Jun 19, 2018 at 15:17 UTC
    > but I'm not aware of a situation where glob might return undef

    $ perl -wE 'say scalar glob "NONEXISTENT*"' Use of uninitialized value in say at -e line 1.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      scalar glob

      Yes, sorry, I wrote too hastily and was thinking in the context of the code I showed, updated. Thanks for pointing that out!

Re^4: GLOB function
by rahu_6697 (Novice) on Jun 19, 2018 at 09:09 UTC

    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");
      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.