in reply to accessing specific data in a file
You're question is a little vague, but I think I understand what your asking.
I'm assuming these are latitude/longitude pairs. If your data file is called 'test.vrml' and has the following contents:
coord Coordinate { 12 23 45, 14 16 65 } coord Coordinate { 13 34 57, 14 17 55 } coord Coordinate { 14 33 34, 14 15 40 }
Then you could use the following to pull out the coordinates:
#! /usr/bin/perl use strict; use warnings; my $filename = './test.vrml'; open my $FH, '<', $filename or die "Can't open $filename for reading: +$!"; my @data = <$FH>; # Read the contents of the file into an array close $FH; my @coordinates; foreach my $line ( @data ) { if ( my ($lat, $lon) = ( $line =~ m/\{\s*(.*), (.*)\s*\}/) ) { push @coordinates, "$1 $2"; } } print "COORDINATES: $_\n" foreach ( @coordinates );
This output the following:
COORDINATES: 12 23 45 14 16 65 COORDINATES: 13 34 57 14 17 55 COORDINATES: 14 33 34 14 15 40
Which could then be written to the output file 'test.cpp' like this:
--njcodewarriormy $output_filename = './test.cpp'; open $OUTPUT, '>', $output_filename or die "Can't open $output_filenam +e for writing: $!"; foreach ( @data ) { print { $OUTPUT } "$_\n"; # Print to file } close $OUTPUT;
|
---|