in reply to Re: GLOB function
in thread GLOB function

Thanks for help, you have understood the problem quite well, I have to sort files with same basename present in different directory and subdirectories according to their mtime such that only latest modified file would come in @filelist. Later I have to work on these files separately to fetch some particular data which is working fine for me.I have done changes as per your code but on terminal these errors are coming. Please resolve this issue as I am working on a shared workspace so I can't install any package in linux.

Use of uninitialized value $arg in stat at /user/s5e7420/local/lib/per +l5/5.18.0/File/stat.pm line 206. Use of uninitialized value $name in index at /user/s5e7420/local/lib/p +erl5/5.18.0/Symbol.pm line 118. Use of uninitialized value $name in pattern match (m//) at /user/s5e74 +20/local/lib/perl5/5.18.0/Symbol.pm line 121. Use of uninitialized value $name in hash element at /user/s5e7420/loca +l/lib/perl5/5.18.0/Symbol.pm line 121. Use of uninitialized value $name in concatenation (.) or string at /us +er/s5e7420/local/lib/perl5/5.18.0/Symbol.pm line 129. Can't call method "mtime" on an undefined value at script.pl line 13.

Replies are listed 'Best First'.
Re^3: GLOB function
by thanos1983 (Parson) on Jun 19, 2018 at 09:13 UTC

    Hello again rahu_6697,

    Fellow Monk haukex have provided a full answer to your question, but I just wanted to add something here. You wrote: Please resolve this issue as I am working on a shared workspace so I can't install any package in linux.

    Programming and troubleshooting is part of the learning curve. Even if the fellow Monk haukex will solve the problem that you have today for you what you have learned? He also gave you a hint in the sample of code Data::Dumper module is for debugging purposes. Did you tried to debug your code? It is part of fun/hell debugging and troubleshooting.

    Regarding the part that you are not able to install modules, Data::Dumper, File::stat and File::Find are core modules.

    #!/usr/bin/env perl use strict; use warnings; use Module::CoreList; my @moduleList = ("Data::Dumper", "File::stat", "File::Find"); foreach my $module (@moduleList) { if (Module::CoreList::is_core($module)) { print "".$module." is a core module and it was released:"; print Module::CoreList->first_release($module) . "\n"; } else { print "".$module." it is not core module!\n"; } } __END__ $ perl test.pl Data::Dumper is a core module and it was released:5.005 File::stat is a core module and it was released:5.004 File::Find is a core module and it was released:5

    Hope this helps, BR.

    Seeking for Perl wisdom...on the process of learning...not there...yet!
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^3: GLOB function (updated)
by haukex (Archbishop) on Jun 19, 2018 at 08:07 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!

      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.