Click here to get back home

Can I iterate through a file on a CGI page?

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Can I iterate through a file on a CGI page? Rich Grise 04-01-2008
Posted by Rich Grise on April 1, 2008, 9:05 pm
Please log in for more thread options
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



Posted by David Filmer on April 1, 2008, 9:41 pm
Please log in for more thread options
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).




Posted by xhoster on April 2, 2008, 12:07 am
Please log in for more thread options
> 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.

Posted by Rich Grise on April 2, 2008, 3:53 pm
Please log in for more thread options
On Wed, 02 Apr 2008 04:07:42 +0000, xhoster 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.

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



Posted by Jim Gibson on April 2, 2008, 6:53 pm
Please log in for more thread options

>
> 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 Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Similar ThreadsPosted
iterate the A B C August 16, 2006, 4:58 am
Iterate through words in a string January 4, 2007, 1:57 pm
executing a bat file from a web page April 21, 2006, 10:13 pm
File statistics from web page files December 19, 2004, 3:41 pm
LWP user agent grabs the intermediate wait page after POST intead of the actual result page February 12, 2008, 12:50 am
How to upload a file from a local pc to a web server from a html page???? August 18, 2004, 6:40 pm
How to get the DOM from a XML page November 27, 2006, 6:54 am
How to automatically log in a web page? October 8, 2004, 8:53 am
How do I parse this page? October 26, 2004, 2:25 pm
Page can not be displayed... December 17, 2004, 11:18 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap