Reprocessing the same file

Reprocessing the same file

am 08.02.2007 15:38:46 von vjp2.at

Is it possible to open, cycle, close, re-open the same file as in:

(But I want to wrap paragraphs, sep by double space, not just lines)

$columns = 37;
use Text::Wrap;
$Text::Wrap::columns= $columns;

open(file from command line)
open(tempfile1)
open(tempfile2)

while () {
$_=wrap(q(),q(),$_);
print file;
} continue { close ARGV if eof }

open(file from command line)

while () {
if ($.%4==2) {$_ .= qq(\n).(q(-) x $columns).qq(\n)}
elsif ($.%4==0) {$_ .= qq(\n).(q(=) x $columns).qq(\n)}
else {$_ .= qq(\n)};
print file;
} continue { close ARGV if eof }
delete (tempfile1)
delete (tempfile2)



- = -
Vasos Panagiotopoulos, Columbia'81+, Reagan, Mozart, Pindus, BioStrategist
http://ourworld.compuserve.com/homepages/vjp2/vasos.htm
---{Nothing herein constitutes advice. Everything fully disclaimed.}---
[Homeland Security means private firearms not lazy obstructive guards]
[Urb sprawl confounds terror] [Remorse begets zeal] [Windows is for Bimbos]

Re: Reprocessing the same file

am 08.02.2007 16:10:44 von vjp2.at

My PC version is 4.0M4 by Okahata (GNU/DOS) Patchlevel 32.

Does that include Text:Wrap?


- = -
Vasos Panagiotopoulos, Columbia'81+, Reagan, Mozart, Pindus, BioStrategist
http://ourworld.compuserve.com/homepages/vjp2/vasos.htm
---{Nothing herein constitutes advice. Everything fully disclaimed.}---
[Homeland Security means private firearms not lazy obstructive guards]
[Urb sprawl confounds terror] [Remorse begets zeal] [Windows is for Bimbos]

Re: Reprocessing the same file

am 08.02.2007 19:41:29 von Joe Smith

vjp2.at@at.BioStrategist.dot.dot.com wrote:
> Is it possible to open, cycle, close, re-open the same file:

Yes.
my $filename = shift or die "$0: Input file name not specified";
open my $file,'<',$filename or die "$0: Cannot read $filename: $!\n";
while(<$file>) {
do something with $_;
}
open my $file,'<',$filename or die "$0: Cannot read $filename: $!\n";
while(<$file>) {
do something with $_;
}

Note that {close ARGV if eof} is not appropriate here.



> (But I want to wrap paragraphs, sep by double space, not just lines)

You need to look up $/ in 'perldoc perlvar', and pay special
attention to what it does when set to the null string.

> open(file from command line)
> open(tempfile1)
> open(tempfile2)

That's not perl code.
Do you not know the syntax for open() ?
It's like trying to run before you've learned how to crawl.
You really need to learn the basics, not expect us to spoon feed you.

-Joe