biohisham has asked for the wisdom of the Perl Monks concerning the following question:
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"; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Writing to a file using Formats
by jethro (Monsignor) on Aug 01, 2009 at 18:32 UTC | |
by biohisham (Priest) on Aug 01, 2009 at 23:29 UTC | |
by jethro (Monsignor) on Aug 02, 2009 at 00:22 UTC | |
Re: Writing to a file using Formats
by jwkrahn (Abbot) on Aug 01, 2009 at 23:49 UTC | |
by bowei_99 (Friar) on Aug 02, 2009 at 08:00 UTC | |
Re: Writing to a file using Formats
by Marshall (Canon) on Aug 02, 2009 at 12:41 UTC | |
by biohisham (Priest) on Aug 03, 2009 at 11:14 UTC | |
by Marshall (Canon) on Aug 04, 2009 at 21:22 UTC | |
by biohisham (Priest) on Aug 04, 2009 at 22:25 UTC | |
by Marshall (Canon) on Aug 04, 2009 at 23:56 UTC | |
|