in reply to need logic, police edited video
Reading your description, here is my *UNTESTED* code that I think (minus the possibility of small typos) to do what you are requesting:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use File:Basename; use File::Spec; use Getopt::Long; $| = 1; # Next 3 lines are my preference for debugging srand(); $Data::Dumper::Deepcopy = 1; $Data::Dumper::Sortkeys = 1; my %configuration = ( x => 0, y => 0, data_directory => q{g:/Frames as bitmap/}, file_extension => q{txt}, output_file => $0 . q{.output}, delimiter => q{,}, ); GetOptions( q{x_coordinate:s} => \$configuration{x}, q{y_coordinate:s} => \$configuration{y}, q{data_directory:s} => \$configuration{data_directory}, q{file_extension:s} => \$configuration{file_extension}, q{output_file:s} => \$configuration{output_file}, q{help} => \&help_output, ); sub help_output { print qq{Usage:\n\t$0 } . qq{--x_coordinate=nnn --y_coordinate=nnn } . qq{--data_directory=path/to/data/files } . qq{--file_extension=file.extension.to.match } . qq{--output_file=output.file.name\n\n} . qq{\t\t--x_coordinate, --y_coordinate } . qq{\t\t\t- pixel coordinate to match\n} . qq{\t\t--data_directory} . qq{\t\t\t- directory containing data files\n} . qq{\t\t--file_extension } . qq{\t\t\t- file extension to glob(), such as 'txt'\n} . qq{\t\t\t\t(assumes leading '.')\n} . qq{\t\t--output_file - file name to write data to\n\n}; exit; } my @files = sort { $a cmp $b } glob File::Spec->catfile( $configuration{data_directory}, q{*} . q{.} $configuration{file_extension}, ); open my $outf, q{>}, $configuration{output_file} or die $!; my $format_string = join( $configuration{delimiter}, q{%s}, q{%d}, q{%d}, q{%d} ) . qq{\n}; foreach my $fn ( @files ) { my $f_id = File::Basename::basename $fn; $f_id =~ s/\.$configuration{file_extension}.*$//g; open my $inf, q{<}, $fn or die $!; while ( my $line = <$inf> ) { chomp $line; my @data = split /\s+/, $line; # Example input data (x y r g b): # 0 0 113 0 255 next if ( $data[0] != $configuration{x_coordinate} ); next if ( $data[1] != $configuration{y_coordinate} ); # Example output data: nnnnn,nnn,nnn,nnn # 12345,255,032,127 print $outf sprintf $format_string, $f_id, @data[2-4]; last; } close $inf; } close $outf;
Please comment if that does indeed do so, or if your expectations differed from those I understood.
Hope that helps.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: need logic, police edited video
by AwsedreswA (Initiate) on Feb 01, 2014 at 05:53 UTC |