Can someone write me a simple Perl script for a few bucks?

M

mikeand1

Can someone out there write me a little Perl script? It'd be a dead
simple program, and I can pay you for your time and trouble.

Basically all it has to do is look at the contents of a directory, and
output a text file whose exact contents would depend on the names and
numbers of files in that directory. Bonus points if it can do this for
multiple subdirectories in a directory. I'll give you the specs for the
file if you want to see it before taking on the job.

This would be done on a Windows PC (I'd be working from DOS I suppose.)


Anyone? This would probably take 10 minutes for a decent programmer to
write, I suppose, but I'll pay $50, or whatever it's worth to you,
within reasonable limits depending on how hard it is to do.

Thanks,
Mike
 
J

Jürgen Exner

Can someone out there write me a little Perl script? It'd be a dead
simple program, and I can pay you for your time and trouble.

Basically all it has to do is look at the contents of a directory,

perldoc -f opendir
perldoc -f readdir
and
output a text file
perldoc -f open
whose exact contents would depend on the names and
numbers of files in that directory.

perldoc -f print
Bonus points if it can do this for
multiple subdirectories in a directory. I'll give you the specs for

perldoc -f File::Find

jue
 
M

mikeand1

It's a little more complicated than that:

You can assume the directory is called DirectoryName, and contains
files of only two types: .txt files, and .tif files. The directory
will contain files something like this:

FileName1.txt
FileName1.tif

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

FileName5.txt
FileName5.tif
FileName6.tif
FileName7.tif
FileName8.tif

There is always a .txt file associated with one or more .tif files.

For example, FileName1.txt is obviously associated with FileName1.tif.


But there are three .tif files associated with FileName2.txt:
FileName2.tif, FileName3.tif, and FileName4.tif.

And there are four .tif files associated with FileName5.txt:
FileName5.tif, FileName6.tif, FileName7.tif, and FileName8.tif

The name of a .txt file always corresponds exactly to the name of the
first .tif file associated with it (excepting for the file extension,
of course).

There can be any number of .tif files associated with a .txt file. You
can assume the .tif files associated with a .txt file are always
numbered in sequence, starting with the number of the .txt file.

However, you should assume that the number of .tif files associated
with a .txt file increases with the number of .txt files, as in my
example. The first .txt file might have five .tif files with it, the
second .txt file might have only one .tif file associated with it, and
so on.

The outputted text file should have the following format for the above
group of files:

@FULLTEXT DOC

; Record 1
@C BEGDOC# FileName1
@C ENDDOC# FileName1
@C PGCount 1
@T FileName1
@D @I\DirectoryName\
FileName1.tif

; Record 2
@C BEGDOC# FileName2
@C ENDDOC# FileName4
@C PGCount 3
@T FileName2
@D @I\DirectoryName\
FileName2.tif
FileName3.tif
FileName4.tif

; Record 3
@C BEGDOC# FileName5
@C ENDDOC# FileName8
@C PGCount 4
@T FileName5
@D @I\DirectoryName\
FileName5.tif
FileName6.tif
FileName7.tif
FileName8.tif

You can see that after BEGDOC#, you put the file name corresponding to
the first .tif file that corresponds to a .txt file, and after ENDDOC#,
you put the name of the last .tif file corresponding to that .txt file.
After PGCount, you put the number of .tif files that correspond to
that .txt file. After @T, you put the name of the .txt file (minus the
extension). And then below the @D file, you list all the .tif files
that correspond to that .txt file.

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.
 
X

Xicheng

It's a little more complicated than that:

You can assume the directory is called DirectoryName, and contains
files of only two types: .txt files, and .tif files. The directory
will contain files something like this:

FileName1.txt
FileName1.tif

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

FileName5.txt
FileName5.tif
FileName6.tif
FileName7.tif
FileName8.tif

There is always a .txt file associated with one or more .tif files.

For example, FileName1.txt is obviously associated with FileName1.tif.


But there are three .tif files associated with FileName2.txt:
FileName2.tif, FileName3.tif, and FileName4.tif.

And there are four .tif files associated with FileName5.txt:
FileName5.tif, FileName6.tif, FileName7.tif, and FileName8.tif

The name of a .txt file always corresponds exactly to the name of the
first .tif file associated with it (excepting for the file extension,
of course).

There can be any number of .tif files associated with a .txt file. You
can assume the .tif files associated with a .txt file are always
numbered in sequence, starting with the number of the .txt file.

However, you should assume that the number of .tif files associated
with a .txt file increases with the number of .txt files, as in my
example. The first .txt file might have five .tif files with it, the
second .txt file might have only one .tif file associated with it, and
so on.

The outputted text file should have the following format for the above
group of files:

@FULLTEXT DOC

; Record 1
@C BEGDOC# FileName1
@C ENDDOC# FileName1
@C PGCount 1
@T FileName1
@D @I\DirectoryName\
FileName1.tif

; Record 2
@C BEGDOC# FileName2
@C ENDDOC# FileName4
@C PGCount 3
@T FileName2
@D @I\DirectoryName\
FileName2.tif
FileName3.tif
FileName4.tif

; Record 3
@C BEGDOC# FileName5
@C ENDDOC# FileName8
@C PGCount 4
@T FileName5
@D @I\DirectoryName\
FileName5.tif
FileName6.tif
FileName7.tif
FileName8.tif

You can see that after BEGDOC#, you put the file name corresponding to
the first .tif file that corresponds to a .txt file, and after ENDDOC#,
you put the name of the last .tif file corresponding to that .txt file.
After PGCount, you put the number of .tif files that correspond to
that .txt file. After @T, you put the name of the .txt file (minus the
extension). And then below the @D file, you list all the .tif files
that correspond to that .txt file.
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;

my $dirname = "My_dir";
local $/='';
my $record;
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";
$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
 
M

mikeand1

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.

Thanks,
Mike
 
K

Keith Keller

I have a large number of directories to process in this manner, so if
you want to build a script
^^^

If you are posting here, *you* are building the script. If you're
posting job offers, you should not be posting here. Posting to
both here and jobs.perl.org is impolite at best.

--keith
 
M

mikeand1

Keith said:
If you are posting here, *you* are building the script. If you're
posting job offers, you should not be posting here. Posting to
both here and jobs.perl.org is impolite at best.

--keith


OK - sorry, thought someone would want to make a couple bucks, didn't
know the netiquette.

Now people are responding to me, feel like I should say something back.
 
M

mikeand1

Thanks - but isn't there some way to do this without having to put the
_DATA_ in each perl script file?

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.

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
 
X

Xicheng

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
 
X

Xicheng

Xicheng said:
(e-mail address removed) 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.
 
X

Xicheng

Xicheng said:
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";
=====

====
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
 
A

A. Sinan Unur

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
 
M

mikeand1

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.
 
U

Uri Guttman

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

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

you don't get it. this group is about discussing perl, not writing perl
programs for people whether they offer money or not. it would be like a
group about legal advice that you frequented and offered some legal
points here and there. but would you take on a complete case in the
group when the rules were to only discuss legal points? this group sets
its own rules and asking writing complete programs is not encouraged and
offering paid jobs is strictly forbidden. if we allowed it, we would get
inundated (it has happened) with them. that is one reason
why the perl jobs list was created (and i created it), to have a place
specifically where anyone could offer perl jobs of all sorts. so we have
a robot here called david adler who rebukes ALL job postings from anyone
and redirects them to jobs.perl.org. it makes no difference about the
size, pay or importance of the perl job, offering it here is NOT WANTED,
PERMITTED OR CONDONED.

that is not a high horse but a set of rules. being a lawyer you should
understand that. now get off your high horse and accept it. your pro
bono work and the desparate need of your clients have no bearing about
allowing you (or anyone else) to break the rules this group has set for
itself. if you can understand that you should be able to properly
apologize without the conditions, sarcasm, whining, etc. i for one don't
feel you did it properly. and you DID get a perl hacker for your project
from the jobs list so a thank you to me wouldn't be a bad thing
either. or to the people here who directed you to that list.

have a nice day,

uri
 
D

David H. Adler

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.

You have posted a job posting or a resume in a technical group.

Longstanding Usenet tradition dictates that such postings go into
groups with names that contain "jobs", like "misc.jobs.offered", not
technical discussion groups like the ones to which you posted.

Had you read and understood the Usenet user manual posted frequently to
"news.announce.newusers", you might have already known this. :) (If
n.a.n is quieter than it should be, the relevent FAQs are available at
http://www.faqs.org/faqs/by-newsgroup/news/news.announce.newusers.html)
Another good source of information on how Usenet functions is
news.newusers.questions (information from which is also available at
http://www.geocities.com/nnqweb/).

Please do not explain your posting by saying "but I saw other job
postings here". Just because one person jumps off a bridge, doesn't
mean everyone does. Those postings are also in error, and I've
probably already notified them as well.

If you have questions about this policy, take it up with the news
administrators in the newsgroup news.admin.misc.

http://jobs.perl.org may be of more use to you

Yours for a better usenet,

dha
 
X

Xicheng

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

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

you don't get it. this group is about discussing perl, not writing perl
programs for people whether they offer money or not. it would be like a
group about legal advice that you frequented and offered some legal
points here and there. but would you take on a complete case in the

You may forget one thing, in the technical world, there exist open
source and commercial. in some communities, there are things beyond
making money or showing mercy to others.

Best,
Xicheng
 
T

Tad McClellan

OK... I get the point already...


If you say so...

(what point? Please quote some context in followups like everybody else does.)

I apologize, truly and sincerely. I will never do it again.


Then that should be an end to it.

I just
needed a little program to do something, and wanted to make it worth
someone's time to do it.


If one person does it, then two people will do it.

Then more people will do it.

Then our discussion group will become a job-posting group and we
won't have a place to discuss Perl programming.

It has happened before. We've seen it. We guard against it because
we don't want the purpose of our newsgroup changed.

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.


Then that should be an end to it.

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.


But, it is apparently not yet ended, you appear to have a continuing
need to vent and whine.

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.


Oh yeah?

Well my dad can beatup your dad!

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


Who needn't get self-righteous about it?

Please quote some context in followups like everybody else does.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top