Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Format headers and filehandles

by socketdave (Curate)
on Mar 24, 2006 at 14:21 UTC ( [id://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.

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://539024]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-03-29 10:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found