bratwiz has asked for the wisdom of the Perl Monks concerning the following question:
--- Some sample data to work with:#! /bin/perl -w ## test to see when/how a file goes out of scope use strict; my $file = 'test.data'; my $frame_marker = 'data'; open(FILE_FD, $file) or die($!); foreach my $loop (1..10) { my $data = get_replay_data(); print "DATA READ:\n", map{ chomp; " VALUE='$_'\n" } @$data; } sub get_replay_data { # read from replay file and return a block of da +ta my $found = 0; my @data = (); die("ERROR -- File handle has closed (why??): $!") if (eof(FIL +E_FD)); foreach my $line (<FILE_FD>) { # pull records from replay file ## wait for begin-marker to capture data if ($line =~ /<$frame_marker>/i) { # wait for start-of +-frame marker $found++; push @data, $line; next; } if (!$found) { next; } ## wait for end-marker & return data if ($line =~ /<\/$frame_marker>/i) { push @data, $line; return \@data; # return xml data if end-of-fra +me marker found } push @data, $line; # otherwise grab frame data } return \@data; } __END__
<data> <string>1 some stuff</string> <string>1 some more stuff</string> <string>1 yet more stuff</string> <string>1 enough stuff</string> </data> <data> <string>2 some stuff</string> <string>2 some more stuff</string> <string>2 yet more stuff</string> <string>2 enough stuff</string> </data> <data> <string>3 some stuff</string> <string>3 some more stuff</string> <string>3 yet more stuff</string> <string>3 enough stuff</string> </data>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Premature End-of-File - Scope problems?
by liverpole (Monsignor) on Feb 15, 2007 at 00:03 UTC | |
by bratwiz (Sexton) on Feb 15, 2007 at 00:43 UTC | |
|
Re: Premature End-of-File - Scope problems?
by GrandFather (Saint) on Feb 15, 2007 at 00:25 UTC | |
by bratwiz (Sexton) on Feb 15, 2007 at 00:40 UTC | |
by GrandFather (Saint) on Feb 15, 2007 at 01:12 UTC | |
by bratwiz (Sexton) on Feb 15, 2007 at 01:37 UTC | |
by graff (Chancellor) on Feb 15, 2007 at 06:26 UTC |