linux - Glob is different value error opening a file and reading -


sub open_files {      @files = @_;     @lines;      foreach (@files){         print "$_\[1\]\n";     }      foreach $f (@files){         print "$f\[2\]\n";         open(my $fh,'<',$f) or die " '$f' $!";             print "$fh\[3\]\n";         push(@lines,<$fh>);         close($fh);     }      return @lines; } 

hi having problems opening files absolute path stored in array.

what want go through array , open each file , store data inside @lines array , close file handle.

however able open .html files stored in first child directory .e.g /a/abc.html or /b/bcd.html not opening (or parsing ) files in sub-child directories such /a/aa/abc.html or /b/bb/bcd.html

i have put in print statements in script , numbered output different print lines e.g. [1] [2] [3].

this result of executing above code:

the full code : pastebin full code

/mnt/hgfs/perl/assignment/test/a/aa/1 - copy - copy (2).htm[1] /mnt/hgfs/perl/assignment/test/a/aa/1 - copy - copy (2).htm[2] glob(0x898ad20)[3] /mnt/hgfs/perl/assignment/test/b/bb/1 - copy - copy (2).htm[1] /mnt/hgfs/perl/assignment/test/b/bb/1 - copy - copy (2).htm[2] glob(0x898ae40)[3] /mnt/hgfs/perl/assignment/test/a/1 - copy - copy (2).htm[1] /mnt/hgfs/perl/assignment/test/b/1 - copy - copy (2).htm[1] /mnt/hgfs/perl/assignment/test/c/1 - copy - copy (2).htm[1] /mnt/hgfs/perl/assignment/test/a/1 - copy - copy (2).htm[2] glob(0x898ae40)[3] /mnt/hgfs/perl/assignment/test/b/1 - copy - copy (2).htm[2] glob(0x898ae40)[3] /mnt/hgfs/perl/assignment/test/c/1 - copy - copy (2).htm[2] glob(0x898ae40)[3] 

if guys need full code here : pastebin full code

use warnings; use strict;  die "usage: $0 (abs path dir) " if @argv != 1;  $dir = shift @argv; our @html_files = ();   file_find($dir); print "html files: @html_files\n";  sub file_find {     $dir = shift;      opendir $dh, $dir or warn "$dir: $!";     @files = grep { $_ !~ /^\.{1,2}$/ } readdir $dh;     closedir $dh;      $file ( @files ) {          $path = "$dir/$file";          push @html_files, $file if $file =~ /\.html$/;         file_find($path) if -d $path;     }    } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -