#! /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 data my $found = 0; my @data = (); die("ERROR -- File handle has closed (why??): $!") if (eof(FILE_FD)); foreach my $line () { # 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-frame marker found } push @data, $line; # otherwise grab frame data } return \@data; } __END__ #### 1 some stuff 1 some more stuff 1 yet more stuff 1 enough stuff 2 some stuff 2 some more stuff 2 yet more stuff 2 enough stuff 3 some stuff 3 some more stuff 3 yet more stuff 3 enough stuff