From: Xicheng on
mikeand1(a)comcast.net wrote:
> Thanks - but isn't there some way to do this without having to put the
> _DATA_ in each perl script file?

sure, that "__DATA__" stuff is used to test code, you can use "open" to
open a file for reading or writing:

my $ifile = "input.dat";
mu $ofile = "output.dat";

open $ifh, '<', '$ifile' or die "cannot open input record file $ifile:
$!";

then replace:
while(<DATA>) {
with
while (<$ifh>) {

=====
To write to a file

open $ofh, '>', '$ofile' or die "cannot open output record file $ofile:
$!";
(you may need to check Perl references about the differences of
read/write modes like '>', '<', '>>'....)
then replace all
print "a,b,c";
to
print $ofh "a,b,c";
=====

> Each directory has a different set of files; the filenames I provided
> above was only an example. I'm trying to set it up to output these
> files automatically, not have to put the filenames in each script.
====
Just found you are using Windows, If I were you, i would do this
separately,

dir/S > in.dat

then parse the file "in.dat" to gather directory and filename
information and organize then as the form of:

Dirname1
FileName1.txt
FileName1.tif

Dirname1
FileName2.txt
FileName2.tif
FileName3.tif
FileName4.tif

Dirname1
FileName5.txt
FileName5.tif
FileName6.tif
FileName7.tif

this should be very easy to do by Perl, then save the data as the input
file of the above scripts(need some modifications).
Good luck,
Xicheng

> Also -- how do I modify that script so that it outputs to a text file,
> as opposed to spitting out the text? I assume there's something like
> C's printf?
>
> Thanks,
> Mike

From: Xicheng on
Xicheng wrote:
> mikeand1(a)comcast.net wrote:

> #!/usr/bin/perl
> use warnings;
> use strict;
=> use Data::Dumper;
this module is just for debugging...
>
> my $dirname = "My_dir";
> local $/='';
=> my $record;
this could be removed
> print "\@FULLTEXT DOC\n";
> while(<DATA>) {
> my @a=();
> print "; Record $.\n";
> push @a,$1 while/^(.+?\.tif)$/mg;
> $a[0]=~/^(\w+?)\.tif$/ and print "\@C BEGDOC# $1\n";
you may need to replace all "\w" to dot '.' coz you may have whitespace
in your filename:
$a[0]=~/^(.+?)\.tif$/ and print "\@C BEGDOC# $1\n";
similar to other cases....
> $a[$#a]=~/^(\w+?)\.tif$/ and print "\@C ENDDOC# $1\n";
> print "\@C PGCount ",scalar@a,"\n";
> /^(\w+)\.txt$/m and print "\@T $1\n";
> print "\@D \@T $dirname\n";
> print "$_\n" for@a ;
> print "\n";
> }
> __DATA__
> FileName1.txt
> FileName1.tif
>
> FileName2.txt
> FileName2.tif
> FileName3.tif
> FileName4.tif
>
> FileName5.txt
> FileName5.tif
> FileName6.tif
> FileName7.tif
>
> ========
> you can use GNU "find" to traverse your dir and subdir, and use perl to
> group filenames into the above form.. you may add dirname to each
> group, just use the similar ways to add into the code...
> Good luck,
>
> Xicheng
>
> > There can be any number of .txt files, sometimes quite large, and any
> > (nonzero) number of .tif files associated with each .txt file.
> >
> > The outputted text file should be called DirectoryName.dii where
> > DirectoryName is the name of the directory holding the files, as above.
> >
> > That's it.
> >
> > I have a large number of directories to process in this manner, so if
> > you want to build a script that automatically searches for
> > subdirectories containing files like this, and creates a .dii file for
> > each such subdirectory, that'd be even better.

From: Xicheng on
Xicheng wrote:
> mikeand1(a)comcast.net wrote:
> > Thanks - but isn't there some way to do this without having to put the
> > _DATA_ in each perl script file?
>
> sure, that "__DATA__" stuff is used to test code, you can use "open" to
> open a file for reading or writing:
>
> my $ifile = "input.dat";
> mu $ofile = "output.dat";
>
> open $ifh, '<', '$ifile' or die "cannot open input record file $ifile:
> $!";
>
> then replace:
> while(<DATA>) {
> with
> while (<$ifh>) {
>
> =====
> To write to a file
>
> open $ofh, '>', '$ofile' or die "cannot open output record file $ofile:
> $!";
> (you may need to check Perl references about the differences of
> read/write modes like '>', '<', '>>'....)
> then replace all
> print "a,b,c";
> to
> print $ofh "a,b,c";
> =====
>
> > Each directory has a different set of files; the filenames I provided
> > above was only an example. I'm trying to set it up to output these
> > files automatically, not have to put the filenames in each script.
> ====
> Just found you are using Windows, If I were you, i would do this
> separately,
>
> dir/S > in.dat
>
> then parse the file "in.dat" to gather directory and filename
> information and organize then as the form of:
>
> Dirname1
> FileName1.txt
> FileName1.tif
>
> Dirname1
> FileName2.txt
> FileName2.tif
> FileName3.tif
> FileName4.tif
>
> Dirname1
> FileName5.txt
> FileName5.tif
> FileName6.tif
> FileName7.tif
>
> this should be very easy to do by Perl, then save the data as the input
> file of the above scripts(need some modifications).
under my WinXP, the following code can roughly parse the file/dir
info.as I mentioned above... (suppose you have only *.txt and *.tif in
your dir/subdir and the windows command "dir/S" gives you the wanted
order)..

dir/S > in.dat

=======================
use warnings;
use strict;
local ($/,$\)=('Directory',"\n");
my $fh;
open $fh,'<','in.dat' or die "cant open $fh: $!";
while(<$fh>) {
my($dir,$files)=/\A\s+of (\S+)(.*)\z/ms;
my @a=();
$files =~ s{^.*?<DIR>.*?$}{}mg;
push @a, $1 while($files=~/^(?:\S+\s+){4}(.*)$/mg);
foreach (@a) {
print "\n$dir" if/\.txt$/;
print;
}
print "\n";
}
close($fh);
========================

Good luck,
Xicheng

>
> > Also -- how do I modify that script so that it outputs to a text file,
> > as opposed to spitting out the text? I assume there's something like
> > C's printf?
> >
> > Thanks,
> > Mike

From: A. Sinan Unur on
"mikeand1(a)comcast.net" <mikeand1(a)comcast.net> wrote in
news:1139038031.089362.93000(a)g47g2000cwa.googlegroups.com:

> BTW, anyone who wants to do this and get paid should notify me first,
> so I don't get more than one person working on it.

Anyone who responds to you based on your job posting in a technical
discussion group will not be among the best people who participate in this
group for the latter have better things to do with their time than to
compete with each other for a couple of bucks from you.

Believe it or not, the value to some of us of offering free help to people
who appreciate it is more than the few dollars we forego by not working
for you.

Sinan

--
A. Sinan Unur <1usa(a)llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

From: mikeand1@comcast.net on
OK... I get the point already... Man... I'm very sorry I tried this.
I apologize, truly and sincerely. I will never do it again. I just
needed a little program to do something, and wanted to make it worth
someone's time to do it. If I'd realized how wrong it was to post
here, I swear to you, I would not have done so. As soon as somebody
corrected me, I went over to jobs.perl.org and found someone who could
help me.

And believe it or not, I do a lot of free work for people too. I'm a
lawyer whose job it is to keep people out of prison, and I've done a
lot of pro bono work to do so.

What's more, I'm willing to guess that the people I help are in far
greater need than the people you help. Just a guess.

So you needn't get self-righteous about it, OK?

Thanks, Xicheng, for your help with this. I think I have what I need at
this point.