Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

You bet, and for the same thing as you..

by bcole23 (Scribe)
on Mar 11, 2005 at 15:30 UTC ( #438677=note: print w/replies, xml ) Need Help??


in reply to Do you use format and write?

I agree with what the previous monks have said. I use it for tools and being a dba/admin, I have many tools where it is very useful for generating output. For ex:
sub print_logcon { my ($which,$f1,$f2,$f3,$f4) = @_; if ($which eq 'general') { print "$f1"; print LOG_FILE "$f1" or kill_and_clean_up( "Error printing to +$LOG_FILE: $!" ); } elsif ($which eq 'comparison') { my $f1_multi = $f1; format COMP_TOP = File version comparison Type File name Previous New ---------------------------------------------------------------------- +-------- . format COMP = @<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<<<<<<< +<<<<<<<< $f4, $f1, $f2, $f3 ~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $f1 . select(LOG_FILE); $^ = 'COMP_TOP'; $~ = 'COMP'; write LOG_FILE or kill_and_clean_up( "Error printing to $LOG_FILE: + $!" ); $f1 = $f1_multi; # format destroys the variable, so reassign it select(STDOUT); $^ = 'COMP_TOP'; $~ = 'COMP'; write STDOUT; } elsif ($which eq 'file_info') { my $f2_multi = $f2; format FILE_INFO_TOP = File Compilation Information Type File name Version ---------------------------------------------------------------------- +-------- . format FILE_INFO = @<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<< +<<<<<<<<< $f1, $f2, $f3 ~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $f2 . select(LOG_FILE); $^ = 'FILE_INFO_TOP'; $~ = 'FILE_INFO'; write LOG_FILE or kill_and_clean_up( "Error printing to $LOG_FILE: + $!" ); $f2 = $f2_multi; # format destroys the variable, so reassign it select(STDOUT); $^ = 'FILE_INFO_TOP'; $~ = 'FILE_INFO'; write STDOUT; } }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2019-09-19 05:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (240 votes). Check out past polls.

    Notices?