Reading and printing file contents using Perl -


can body me in reading files of particular format directory line line , should print on screen.

and request include command lines in program itself.

then when ever simple ran program , should display content of files. below program wrote can body me please....

#!/usr/local/bin/perl $filepath="/home/hclabv"; opendir(dir,"$filepath"); @files=grep{/\.out$/} readdir(dir); closedir(dir); $c = 0; ($c=0 ; while ($c <= @files) { $cmd = "perlsc11 $files[$c]"; system($cmd); if($#argv != 0) {    print stderr "you must specify 1 argument.\n"; exit 4; } else { print ("$files[$c]\n");   # open file. open(infile, $argv[0]) or die "cannot open $argv[0]: $!.\n"; while(my $l = <infile>) { print $l; } close infile; } $c++; } 

you can use glob feature in perl list of filenames ".out" extension in specified directory. can open these files 1 one using loop , print contents screen. here's code,

# file-names ".out" extension array @outfiles = glob "/home/hclabv/*.out";  # loop through list of file names in array foreach $outfilename ( @outfiles ) {     # open file processing     open $outfile, '<', $outfilename or die "unable open file reading : $!";      # iterate through each line in file     while ( $line = <$outfile> )     {         # print individual line         print "$line\n";     }      # close file     close $outfile; } 

please clarify mean "including command lines", can further.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -