Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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.

Replies are listed 'Best First'.
Re^2: Format headers and filehandles
by fmerges (Chaplain) on Mar 24, 2006 at 14:46 UTC


    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...


    fmerges at

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2020-10-28 02:47 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (259 votes). Check out past polls.