Like cat command
This script behaves like cat command. You input something file. And it will display list of files.
use strict; use warnings; my $somefile = $ARGV[0]; sub read_dir { my $sef = shift; my @list; $sef =~/\./ || die "no dott!!\n"; opendir(DIR,'.') || die "can not open dir"; while(my $dir = readdir(DIR)){ if($dir=~/($sef)/){ push(@list,$dir); } } closedir(DIR); return @list; } sub read_f { my @file = @_; my $num = 0; my $sele; foreach my $obj (@file){ print $num.":".$obj."\n"; $num++; } print "\ninput number\n"; $sele = <STDIN>; &displa($sele,@file); } sub displa { my($selected,@file) = @_; open(IN,$file[$selected]); my @line = <IN>; close(IN); print @line; } if(@ARGV != 1 ){ die "no argv. it needs one argv at least like this .txt\n"; } my @file_list = &read_dir($somefile); &read_f(@file_list);