Dear all,

First post to this list! Hope I do it right!

I'm looking for a way to print to a temporary filehandle or something
without having to open a file to print to.

I am running some substitutions on a file which has a distinctive record
structure. Each record is printed to the output filehandle in turn after
the substitutions have been performed. Once all records are printed out
I need to go back over them i.e. go back to the top and do some further
work on the OUT filehandle. I am currently using SEEK and while (<OUT>)
and a temporary file connected to OUT to achieve this. Is there a way to
go back over the output without using a temporary file?

        $/ = "</rec>"
        while (<CUTLINK>)
                
                {
                s/\r//g;
                
                $last_id = $current_id;
                $last_level = $current_level;

                if (/<id>(.*)<\/id>\n<level>([0-9]+)<\/level>/)

                        {
                        $current_id = $1;
                        $current_level = $2;
                        $splice_position = $2 - 1;
                        $parent_position =$2 - 2;
                        #print STDOUT
"$current_id\t$current_level\t$splice_position\n";
                        splice (@parents, $splice_position, 1,
$current_id);
                        #print $parents[$splice_position];
        
s/<body>/<parent>$parents[$parent_position]<\/parent>\n<body>/;
                        #print $parents[$parent_position];
                        }

                print OUT;
                }




Richard

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to