Can I iterate through a file on a CGI page?

R

Rich Grise

Apologies to Perl purists - comp.infosystems.www.authoring.cgi doesn't
work on my newsreader, and this is a CGI question:

What I want to do is, I've got a large collection of image files:
$ wc gallery-pix
37448 62619 3218967 gallery-pix

and what I'd like to do is look at each of the 37488 image files on
some kind of page, with buttons like "Keep", "Skip", and "Quit",
so I can page through all of these images, which are strewn all
over the Samba server, and decide which ones might look good on
the website.

So, is it possible to do something like (in pseudocode):

for each $line in <file> {
show webpage with <img> tag, and the three buttons;
get button response, decide what to do with file;
if button == "Quit", save place in source file;
next;

or so?

Thanks,
Rich
 
X

xhoster

Rich Grise said:
Apologies to Perl purists - comp.infosystems.www.authoring.cgi doesn't
work on my newsreader, and this is a CGI question:

What I want to do is, I've got a large collection of image files:
$ wc gallery-pix
37448 62619 3218967 gallery-pix

and what I'd like to do is look at each of the 37488 image files on
some kind of page, with buttons like "Keep", "Skip", and "Quit",
so I can page through all of these images, which are strewn all
over the Samba server, and decide which ones might look good on
the website.

So, is it possible to do something like (in pseudocode):

for each $line in <file> {

In CGI, your program won't survive for the loop to iterate. Unless
you are making one page with all 37448 files on it.
show webpage with <img> tag, and the three buttons;
get button response, decide what to do with file;

What would you do with the file in each case?
if button == "Quit", save place in source file;
next;

Make one directory with all the files (or with a symbolic links for each
file). Each time the program is invoked, take the first entry in the
directory and display it. Based on the response, either move it to the
accept directory or the reject directory (or move it to accept vs delete
it, whatever.) Since the file is no longer there, place is inherently
saved. Quit doesn't have to do anything, nor even have to exist--closing
the browser without responding is a form of quiting.

Or use a database.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
R

RedGrittyBrick

Rich said:
Apologies to Perl purists - comp.infosystems.www.authoring.cgi doesn't
work on my newsreader, and this is a CGI question:

What I want to do is, I've got a large collection of image files:
$ wc gallery-pix
37448 62619 3218967 gallery-pix

and what I'd like to do is look at each of the 37488 image files on
some kind of page, with buttons like "Keep", "Skip", and "Quit",
so I can page through all of these images, which are strewn all
over the Samba server, and decide which ones might look good on
the website.

So, is it possible to do something like (in pseudocode):

for each $line in <file> {
show webpage with <img> tag, and the three buttons;
get button response, decide what to do with file;
if button == "Quit", save place in source file;
next;

or so?

Surely, looking at 37448 separate images one by one and making
subjective judgements about them is going to take a human a long long
time. If you can make a judgement in a second then it would take over
ten hours without a break to view all of them. This kind of monotonous
task would drive me crazy after a few hundred images.

I'd expect there are lots of similar images and that they may not be
naturally grouped together - which makes selecting the best of a kind
impossible, you're bound to later encounter a "better" image than one
you'd selected to "keep" yesterday or a week ago. Which means more
passes through the "keep" collection.

If I had to do it, I'd first categorise the images, then display
thumbnails for each category and pick ones to keep from each category.

Better to pay a graphics artist to produce a new consistent set for a
website?
 
R

Rich Grise

In CGI, your program won't survive for the loop to iterate. Unless
you are making one page with all 37448 files on it.


What would you do with the file in each case?


Make one directory with all the files (or with a symbolic links for each
file). Each time the program is invoked, take the first entry in the
directory and display it. Based on the response, either move it to the
accept directory or the reject directory (or move it to accept vs delete
it, whatever.) Since the file is no longer there, place is inherently
saved. Quit doesn't have to do anything, nor even have to exist--closing
the browser without responding is a form of quiting.

Thanks - I really like this answer - I hadn't even consider loading up
a directory with symlinks.

I'm going to try this next, as a way to avoid slurping the whole file.

So, anybody got a quick and dirty script that will make 38,000 symlinks?
;-)

I'm not too worried about how long it will take - I'm doing this in
my "spare" time, and the boss doesn't bother me much as long as I look
busy. :)

Thanks!
Rich
 
J

John W. Krahn

Jim said:
for my $i ( 1..38000 ) {
symlink( '/path/to/somefile', sprintf("symlink%5.5d",$i));
}

for my $name ( 'aaaaaa' .. 'aacefn' ) {
symlink '/path/to/somefile', $name;
}


John
 
R

Rich Grise

for my $name ( 'aaaaaa' .. 'aacefn' ) {
symlink '/path/to/somefile', $name;
}

Thanks for these. :)

OK, so now I've got $mypath/source-links/symlink00000 through
$mypath/source-links/symlink19634 , and I figured out how to iterate them:
my $thislink=`ls source-links | head -1` , but then when I use the link in
an <img src=... tag, it shows the pic, but how do I get the actual name of
the actual file that the link is pointing to? I suppose I could do an ls
-l and parse the link, but isn't there an easier/quicker/more elegant way
to get that info? (I think they call it "dereferencing", but I'm not sure.)

In other words, I want to show the pic, and show its "real" name, not the
link name; can that be done easily?

Thanks,
Rich




Now, I've got source-links/
 
R

Rich Grise

the actual file that the link is pointing to? I suppose I could do an ls
-l and parse the link, but isn't there an easier/quicker/more elegant way
to get that info? (I think they call it "dereferencing", but I'm not sure.)

Nah:
### start script ###
#!/usr/bin/perl -w

my $line=`ls -l source-links | head -2 | tail -1`;

chomp $line;

my $linkname = substr("$line", 50, 12);
my $targetname = substr("$line", 66);

print("$line\n");

print("name = $linkname, target = $targetname\n");
### end script ###

$ parse-ls
lrwxrwxrwx 1 richgrise users 75 2008-04-07 13:47 symlink00000 -> /C/Documents and Settings/Administrator/My Documents/My Pictures/Sample.jpg
name = symlink00000, target = /C/Documents and Settings/Administrator/My Documents/My Pictures/Sample.jpg
$

Cheers!
Rich
 
J

J. Gleixner

Rich said:
Nah:
### start script ###
#!/usr/bin/perl -w

my $line=`ls -l source-links | head -2 | tail -1`;

chomp $line;

my $linkname = substr("$line", 50, 12);
my $targetname = substr("$line", 66);

print("$line\n");

print("name = $linkname, target = $targetname\n");

Do you have your own print() subroutine? No need for '()'.
### end script ###

$ parse-ls
lrwxrwxrwx 1 richgrise users 75 2008-04-07 13:47 symlink00000 -> /C/Documents and Settings/Administrator/My Documents/My Pictures/Sample.jpg
name = symlink00000, target = /C/Documents and Settings/Administrator/My Documents/My Pictures/Sample.jpg

Not very reliable. If the owner or group change to something
of different length, it could easily return the wrong data. Using
split would be more reliable, but still not very good.

Use the correct function: perldoc -f readlink
 
R

Rich Grise

This should work and doesn't require shelling out to ls:

use strict;
use warnings;
use File::Find;
find(
sub {
my $linkname = $_;
return unless -l $_;
my $targetname = readlink $linkname;
print "name = $linkname, target = $targetname\n";
},
'source-links'
);

OK, I do this, and it shows me _all_ of the links. What have I
missed?

And am I supposed to pass the name of the link I'm looking for? Why
do you initialize $linkname to $_? I want a script that doesn't
have to already know $linkname - it needs to find the next one in
the subdir, whichever one that is.

What am I missing?

Thanks,
Rich



Thanks,
Rich
 
J

J. Gleixner

Rich said:
OK, I do this, and it shows me _all_ of the links. What have I
missed?

And am I supposed to pass the name of the link I'm looking for? Why
do you initialize $linkname to $_? I want a script that doesn't
have to already know $linkname - it needs to find the next one in
the subdir, whichever one that is.

What am I missing?

First, you missed reading the documentation before posting yet
another question. Second, you missed defining to us what
'the next one' means. If there is some order, then you need to
sort the files/directories and do whatever you want with that
information:

perldoc File::Find
perldoc -f stat
perldoc -f sort

Reading those should help you answer your questions.
 
R

Rich Grise

First, you missed reading the documentation before posting yet
another question. Second, you missed defining to us what
'the next one' means. If there is some order, then you need to
sort the files/directories and do whatever you want with that
information:

perldoc File::Find
perldoc -f stat
perldoc -f sort

Reading those should help you answer your questions.

Yeah, you're right, I'm sorry, but I've been reading for going on about
a month now and it's terribly frustrating - it's pretty much the same
problem with all the Linux docs - you have to already know what feature
you're looking for before you know which doc to read, like for example:
`readlink` - how is a person supposed to know that such a thing even
exists, except by asking, or plowing through every possible doc there
is until you stumble upon it? ?:-/

Thanks,
Rich
 
J

Joost Diepenmaat

Rich Grise said:
Yeah, you're right, I'm sorry, but I've been reading for going on about
a month now and it's terribly frustrating - it's pretty much the same
problem with all the Linux docs - you have to already know what feature
you're looking for before you know which doc to read, like for example:
`readlink` - how is a person supposed to know that such a thing even
exists, except by asking, or plowing through every possible doc there
is until you stumble upon it? ?:-/

For *nix programming in general, I really recommend the "advanced
programming in the unix environment, 2nd edition" book from Addisson
Wesley. For perl, get the "programming perl" book from O'Reilly, and for
quick searches, see perldoc perltoc.
 
J

J. Gleixner

Joost said:
For *nix programming in general, I really recommend the "advanced
programming in the unix environment, 2nd edition" book from Addisson
Wesley. For perl, get the "programming perl" book from O'Reilly, and for
quick searches, see perldoc perltoc.

Also you may use the power of the that there Internet. For fun I
searched on "perl symbolic link" and readlink was covered in the
second link of the results.
 
A

A. Sinan Unur

Also you may use the power of the that there Internet. For fun I
searched on "perl symbolic link" and readlink was covered in the
second link of the results.

I also think the most natural place to look first is:

perldoc perltoc

from which one finds out

perlfunc - Perl builtin functions

Then, reading perldoc perlfunc, one notices

Functions for filehandles, files, or directories
"-*X*", "chdir", "chmod", "chown", "chroot", "fcntl", "glob",
"ioctl", "link", "lstat", "mkdir", "open", "opendir", "readlink",
"rename", "rmdir", "stat", "symlink", "sysopen", "umask",
"unlink", "utime"

One can then learn more about the four functions that have 'link' as
part of their names.

perldoc -f link
perldoc -f readlink
perldoc -f symlink
perldoc -f unlink

I would assume that somewhere along this short and painless process,
one would find out what one needs.

Look 'ma: No Google. No UseNet. No books. Just the basic Perl
documentation.

After a while, one can develop a sense of where to find information
with even less searching.

On the other hand, if one can always rely on being handed a fish for
the asking, one will never have an incentive to put one's own time
and effort into researching answers.

Sinan

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
R

Rich Grise

On Thu, 10 Apr 2008 18:28:20 +0000, Rich Grise wrote:

For what it's worth, I've used a lot of the suggestions here, and I
have a successful script - now comes the tedious part - sitting and
looking at 17,000 pictures, one at a time, with a "keep" and "skip"
button. :)

Many Thanks to All!
Rich
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top