Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: A story of a Perl Monk and Problem

by Brovnik (Hermit)
on May 19, 2001 at 20:07 UTC ( [id://81732]=note: print w/replies, xml ) Need Help??


in reply to A story of a Perl Monk and Problem

Seek isn't really for skipping forwards into unknown territory like this unless you know enough about the file format to be able to know exactly where you want to go to. In particular, you can't do a "skip the next 100 files" command.

However, if you do a

push(@tells, $dir->tell());
at the start of each page, it will allow you to use seek later to skip back to any of those particular points later using the values stored in the @tells array. E.G.
# have now read through all files once and stored every # Nth position in @tells my $dirpos = @tells / 2; # start in the middle my $browsing = 1; while ($browsing) { my $action = ""; $f = $dir->seek($tells[$dirpos]); # code to go here to read next N files and display # results to user. # Come back here when we have an submit from the user # and $action set to the result. if ($action eq "pageforwards") { #should check for end $dirpos++; } elsif ($action eq "pagebackwards") { #should check for start $dirpos--; } else { # do other actions $browsing = 0; } }

This way, you only have to store a value for every Nth file, which is a big reduction in storage.

--
Brovnik.

Replies are listed 'Best First'.
Re: Re: A story of a Perl Monk and Problem
by Hero Zzyzzx (Curate) on May 19, 2001 at 20:56 UTC

    But wouldn't it still need to go through the directory on every request from the web? I still think an RDBMS would be better. You'd only loop through the files when you create the table, and the memory requirements would be minimal, beyond the mySQL daemon running.

    After you had your table with filenames, you would then only select the few filenames you needed to create each index page. The list of files is already prepared and stored in the table, there's minimal extra stuff involved to give a user a page.

      Yes, it would. This falls into the "If I were trying to get there, I wouldn't start from here category", but I was answering the specific point about "how do I use seek(POS)" rather than the broader "how do I present 90,000 files to the user".

      I agree with thpfft trying to present them all to the user isn't the way, and a search would be much better.

      Unless the filenames are descriptive (and this is difficult if they are in 8.3 notation), the search needs to be on some content or keywords related to the file as well, so you really should have some sort of persistent Database interface to the directory.
      --
      Brovnik.

      Edit: chipmunk 2001-05-19

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://81732]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-24 02:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found