Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Can I iterate through a file on a CGI page?
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



Report this thread to moderator Post Follow-up to this message
Old Post
Rich Grise
04-02-08 03:30 AM


Re: Can I iterate through a file on a CGI page?
Rich Grise wrote:
> for each $line in <file> {

This is gonna be your problem.  CGI is stateless.  Each time you hit one
of the submit buttons you will re-invoke the program, and the new
invocation knows nothing about the state of the previous invocation.  If
you attempted something like you wrote then you would keep showing the
first item over and over again, because it would start at the beginning
of the file each time you invoked the program.

There are several things you can do to get around this issue. My
preference is to use a database instead of a file, and run my CGI under
a mod_perl webserver which is smart enough to cache the database handle.
But maybe that's overkill for what you want to do.

If you are willing to pay the price of opening up your flatfile each
time you invoke the program, you could pass the current (or next) line
number as a hidden() parameter.  Thus the program knows which line of
the file to process next (I would recommend tying the file to an array
so the line number simply becomes the array subscript).




Report this thread to moderator Post Follow-up to this message
Old Post
David Filmer
04-02-08 03:30 AM


Re: Can I iterate through a file on a CGI page?
Rich Grise <rich@example.net> wrote:
> 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.

Report this thread to moderator Post Follow-up to this message
Old Post
xhoster@gmail.com
04-02-08 09:38 AM


Re: Can I iterate through a file on a CGI page?
Rich Grise wrote:
> 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 w 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?

--
RGB

Report this thread to moderator Post Follow-up to this message
Old Post
RedGrittyBrick
04-03-08 11:15 AM


Re: Can I iterate through a file on a CGI page?
On Wed, 02 Apr 2008 04:07:42 +0000, xhoster wrote:
> Rich Grise <rich@example.net> wrote: 
>
> 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



Report this thread to moderator Post Follow-up to this message
Old Post
Rich Grise
04-03-08 11:15 AM


Re: Can I iterate through a file on a CGI page?
In article <pan.2008.04.02.19.52.30.989027@example.net>, Rich Grise
<rich@example.net> wrote:

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

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

--
Jim Gibson

Posted Via mcse.ms Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.mcse.ms

Report this thread to moderator Post Follow-up to this message
Old Post
Jim Gibson
04-03-08 11:15 AM


Re: Can I iterate through a file on a CGI page?
Jim Gibson wrote:
> In article <pan.2008.04.02.19.52.30.989027@example.net>, Rich Grise
> <rich@example.net> wrote:
> 
>
> 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
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

Report this thread to moderator Post Follow-up to this message
Old Post
John W. Krahn
04-03-08 11:15 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Miscellaneous archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 10:01 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.