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:

my $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;
--njcodewarrior

In reply to Re: accessing specific data in a file by njcodewarrior
in thread accessing specific data in a file by phoenixQueen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.