Situation1: when I tried to associate with the write function another filehandle t +han STDOUT to make it write the report to a file it tells me the file +handle isn't defined, uncomment the lines 32 and 33 to see that.
I couldn't recognize where I went wrong for the first situation, and for the other situation I could not figure how to manipulate the $%, $= and $- variables. So I would welcome your suggestions .Situation2: for every run of the report I wanted to make the program start a new e +pisode on another page (i.e it starts a new episode at page 3 if it s +topped at page 2)
#!/usr/local/bin/perl use strict; use warnings; my($title,$num1, $num2, $result); format report_TOP= @||||||||||||||@>>>>>>>> $title , "Page $%" --------------------------------- NUMBER1 || NUMBER2 || ADDITION --------------------------------- . format report= @###@#########@############ $num1, $num2, $result . $~="report"; $^="report_TOP"; $title = "Some Report"; START: print "Please Enter a text containing pairs of numbers\n"; while(<>){ if(/^(exit|quit)$/){exit;} ($num1, $num2) = (/(\d+)/g) for ($_); add($num1, $num2); } sub add{ # open FILE,'>REPORT.txt' or die "could not open it $!\n"; # select FILE; for(my $index=0;$index<100;$index++){ $result = $num1 + $num2; write; $num1++; $num2++; } print "another Pair of numbers? Y N\n"; if(<> =~ /^N$/i){ exit; }else{ print "Please Enter a text containing pairs of numb +ers\n"; "START"; } }
In reply to Writing to a file using Formats by biohisham
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |