Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Format headers and filehandles

by socketdave (Curate)
on Mar 24, 2006 at 14:21 UTC ( #539024=note: print w/ replies, xml ) Need Help??


in reply to Format headers and filehandles

Add this:

select DM; $- = 0;
after your second open. I'm not intimately familiar with format and write, but this does the trick for me. Maybe someone more experienced could explain the magic, but this basically forces a new page on the next write.


Comment on Re: Format headers and filehandles
Download Code
Re^2: Format headers and filehandles
by fmerges (Chaplain) on Mar 24, 2006 at 14:46 UTC

    Hi,

    Use this, because with the previous the selected output for any print, write,etc will be DM, not the desired, so:

    select( (select (DM), ($- = 0))[0] );

    Will select again the previous output you had before calling select, but assigning the $- variable for that filehandle

    But better is to use lexical variables as filehandles, in the code it seems like you have a register to asign each time, and write to a list of files, why not something like this:

    for my $file (@files) { open my $fh, '<', $file; select(( select($fh), $~ = "DM", $^ = "DM_TOP" )[0] ); # Data adquisition stuff here write $fh; }

    By the way take a look at Perl6::Form, it have a lot of improvements, and not these limitations that Perl 5 formats has.

    And the why this seems to happen, think it is because the DM is a global symbol, and it doesn't get reset the values automatically because when you close the filehandle the DM symbol is not erased...

    Regards,

    fmerges at irc.freenode.net

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://539024]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2014-10-31 23:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (225 votes), past polls