#!/usr/bin/perl opendir (dir, "formatted_data"); @contents = readdir dir; foreach $listitem (@contents) { if($listitem =~/txt/){ open(DAT,"formatted_data/$listitem") || die("could not open $listitem!"); @raw_data= ; close(DAT); # reading from a file $output_file= "readfile.txt"; $dist=0; $wid=0; $tim=0; $end_fixed=0; $endnext=0; open(DAT, ">>$output_file")|| die("could not open file!"); # print DAT "Distance \t Width \t Time \n"; foreach $line (@raw_data) { print "hello"; chop($line); if($line =~/Device used/) { $line = substr($line,14); printf DAT "$line, "; } if($tim==1){ if($line =~/outlier/){ # printf DAT "%-15s \n",$line; $line = substr($line, 8); } $line = trim($line); print DAT "$line, "; $tim=0; } elsif($wid==1){ # printf DAT "%-15s",$line; $wid=0; $tim=1; } elsif($dist==1 && ($line=~/outlier/ || $line !~/[a-zA-Z]/)) { # printf DAT "%-15s",$line; $dist=0; $wid=1; } elsif($line =~/\#/) { if($endnext==1){ last; } # print DAT "$line \n"; $dist=1; $endnext=1; } elsif($line =~ /---------/){ $dist=1; } } } print DAT "*\n"; } sub trim { my $string = shift; $string =~ s/\s//g; return $string; } close(DAT); closedir dir; # writing into a file #open(DAT, ">$data_file") || die("cannot open file"); #print DAT "this was very useless \n"; #close(DAT);\ # chmod u+x learnperl.pl # perl learnperl.pl