[23783] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 5987 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 29 03:05:39 2003

Date: Mon, 29 Dec 2003 00:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 29 Dec 2003     Volume: 10 Number: 5987

Today's topics:
        Calling a scalar from another script using "require" <arthur0421@163.com>
    Re: Calling a scalar from another script using "require <noreply@gunnar.cc>
    Re: Calling a scalar from another script using "require (David Efflandt)
    Re: Calling a scalar from another script using "require (Tad McClellan)
    Re: How to write a script that takes input from the scr (Poppy Gerard)
    Re: installing mod manually <jwillmore@remove.adelphia.net>
    Re: looking for help with a counting algorithm <nospam@bigpond.com>
    Re: looking for help with a counting algorithm <news3@earthsong.null.free-online.co.uk>
    Re: looking for help with a counting algorithm <news3@earthsong.null.free-online.co.uk>
    Re: retrieve webpage with POST (Tad McClellan)
    Re: retrieve webpage with POST <noreply@gunnar.cc>
    Re: retrieve webpage with POST <matthew.garrish@sympatico.ca>
    Re: retrieve webpage with POST (Tad McClellan)
    Re: retrieve webpage with POST <noreply@gunnar.cc>
    Re: retrieve webpage with POST <dean.banko@globalnet.hr>
        Use a Perl_Interpreter and NOT call it my_perl?  Use TW <tmohr@s.netic.de>
    Re: Use a Perl_Interpreter and NOT call it my_perl?  Us <nospam@bigpond.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 29 Dec 2003 10:26:40 +0800
From: "Regent" <arthur0421@163.com>
Subject: Calling a scalar from another script using "require"
Message-Id: <bso3dq$1kul$1@mail.cn99.com>

Hi, friends,

Although I read several books before posting this, I still don't know how to declare a scalar in "common.pl" and use it directly in "script.pl":

common.pl

$root = "/root";


script.pl

require "common.pl"; # this line works
print "$root";       # Global symbol "$root" requires explicit package name

PS: I habitually use the -wT switch

             Regent
             arthur0421@163.com



------------------------------

Date: Mon, 29 Dec 2003 03:58:37 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Calling a scalar from another script using "require"
Message-Id: <bso5ll$embvf$1@ID-184292.news.uni-berlin.de>

Regent wrote:
> Although I read several books before posting this,

Those cannot have been Perl books... ;-)

> I still don't know how to declare a scalar in "common.pl" and use
> it directly in "script.pl":
> 
> common.pl
> 
> $root = "/root";
> 
> 
> script.pl
> 
> require "common.pl"; # this line works
> print "$root";       # Global symbol "$root" requires
>                      # explicit package name
> 
> PS: I habitually use the -wT switch

Good. Since you get that error message, you are obviously using
strictures too, which is also good. :)

These are two ways to do what you want:

     our $root;             # declares $root as a package global
     require "common.pl";
     print $root;

or

     require "common.pl";
     print $main::root;     # explicit package name

(There is no need to quote the variable in the print statement.)

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



------------------------------

Date: Mon, 29 Dec 2003 03:53:17 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Calling a scalar from another script using "require"
Message-Id: <slrnbuv99d.8uf.efflandt@typhoon.xnet.com>

On Mon, 29 Dec 2003 10:26:40 +0800, Regent <arthur0421@163.com> wrote:
> Hi, friends,
> 
> Although I read several books before posting this, I still don't know 
> how to declare a scalar in "common.pl" and use it directly in 
> "script.pl":

Typically require inserts the contents of the required script at the point
of the require statement.  However, I noticed that if I used "my $root",
it only seemed to be in scope in the required script, and was
uninitialized in main script.

> common.pl
> 
> $root = "/root";
> 
> 
> script.pl
> 
> require "common.pl"; # this line works
> print "$root";       # Global symbol "$root" requires explicit package name
> 
> PS: I habitually use the -wT switch
> 
>              Regent
>              arthur0421@163.com

If I just used -w switch (and put a newline in print "$root\n";), 
I got:

Name "main::root" used only once: possible typo at ./mytest line 3.
/root

Inserting a use vars line got rid of the warning:

use vars ('$root');
require "common.pl";
print "$root\n"

If I used -wT, "." (current dir) was apparently excluded from @INC, so I 
had to use a full path to common.pl (same output).

Tested in perl v5.6.1 built for i586-linux and v5.8.0 built for 
i586-linux-thread-multi

-- 
David Efflandt - All spam ignored  http://www.de-srv.com/
PS: All mail referencing [1-9]63\.(com|net) is automatically dropped due
to excessive uncontrolled spam.


------------------------------

Date: Sun, 28 Dec 2003 23:01:22 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Calling a scalar from another script using "require"
Message-Id: <slrnbuvd92.cht.tadmc@magna.augustmail.com>

David Efflandt <efflandt@xnet.com> wrote:

> However, I noticed that if I used "my $root",
> it only seemed to be in scope in the required script, and was
> uninitialized in main script.


That is what my() is _supposed to do.


   perldoc -f my

   ... local (lexically) to the enclosing block, file ...


$root will only be in the scope of the "required file" since
my() variables can never cross file boundaries.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: 28 Dec 2003 17:31:43 -0800
From: poppy2173@hotmail.com (Poppy Gerard)
Subject: Re: How to write a script that takes input from the screen and writes a number to a text file?
Message-Id: <dc7a50cc.0312281731.2d300ff8@posting.google.com>

Many thanks for all these replies, and for the suggestions.  I shall
check out some of the ideas for FAQs etc and look into this some more.
 Thank you once again.  With all good wishes for 2004! :-)  Kindest
regards - Poppy G.



tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnbuj9ea.8vh.tadmc@magna.augustmail.com>...
> Poppy Gerard <poppy2173@hotmail.com> wrote:
> 
> > I am not sure if PERL 
> 
> 
> The name of the language is "Perl".
> 
> The name of the interpreter is "perl".
> 
> It is not an acronym.
> 
>    perldoc -q difference
> 
> 
> > is the right way to do this - but I
> > am trying to generate a simple script that will run at a Website and
> 
> 
> You want to write a "CGI program".
> 
> You can write a CGI program in just about any programming language
> that you choose.
> 
> Many many people do happen to choose to use Perl for their CGI programs.
> 
> 
> > accept a numerical input typed in on the screen, 
> 
> 
> There is no "screen" in a CGI program.
> 
> A CGI program gets it input from the web server[1], and sends its
> output to the web server[2].
> 
> 
> > and write the number
> > to a simple ASCII text file.
> > 
> > Does anyone know how one can do this with PERL, or is there a better /
> > easier way to generate such a program on-line?
> 
> 
> People write programs.
> 
> Programs generate programs.
> 
> Their is no general purpose program-generator, you will need to
> _write_ a program. To so that, you will need to learn a programming
> language, perhaps Perl, perhaps anything else you might like.
> 
> If you chose to write that program using Perl, then it might
> look something like this (untested):
> 
> ----------------------------------------------
> #!/usr/bin/perl
> use strict;
> use warnings;
> use CGI qw/:standard/;
> use CGI::Carp;
> 
> open FILE, '>simple_ASCII.txt' or 
>    carp "could not open 'simple_ASCII.txt' $!";
> print FILE param('the_number_from_the_form'), "\n";
> close FILE or carp "problem closing file $!";
> 
> print "Content-Type: text/plain\n\n";
> print param('the_number_from_the_form'), " has been written to the file\n";
> ----------------------------------------------
> 
> 
> That's it!
> 
> 
> (except a Real CGI Program would need to deal with multitasking and
>  do some form of file locking.
> )
> 
> 
> > I would be grateful for any help / advice that people may be able to
> > offer.
> 
> 
> There are a bazillion Perl FAQs about what you want to do, all you need
> are some good search terms:
> 
>    perldoc -q CGI
>        How can I make my CGI script more efficient?
>        Where can I learn about CGI or Web programming in Perl?
>        What is the correct form of response from a CGI script?
>        My CGI script runs from the command line but not the
>           browser.  (500 Server Error)
>        How can I get better error messages from a CGI program?
>        How do I make sure users can't enter values into a form
>           that cause my CGI script to do bad things?
>        How do I decode a CGI form?
> 
>    perldoc -q "\block"
>        How can I lock a file?
>        Why can't I just open(FH, ">file.lock")?
>        I still don't get locking.  I just want to increment the 
>           number in the file.  How can I do this?
> 
> 
> 
> See also the Posting Guidelines that are posted here frequently.
> 
> 
> 
> 
> [1] the web server in turn may have gotten the values from a <form> 
>     filled out in a client program (eg. browser).
> 
> [2] the web server in turn may forward the output to a client program.


------------------------------

Date: Mon, 29 Dec 2003 02:47:09 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: installing mod manually
Message-Id: <20031228214709.307eb4ae.jwillmore@remove.adelphia.net>

On Sun, 28 Dec 2003 04:48:15 -0500
lucas <aolblowz@yahoo.com> wrote:

> James Willmore wrote:
> 
> 
> > You're welcome.  And, have you emailed the author so this
> > modification is available to all?
> 
> Been off on holidays, away from this computer, but that sounds like
> a plan.  I'll send one out

As I type, I have been home now a total of 60 minutes.  I don't think
it's critical that it be sent out *right now* :-)

Enjoy!

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
Fuch's Warning:  If you actually look like your passport photo,
you aren't well enough to travel. 


------------------------------

Date: Mon, 29 Dec 2003 11:35:17 +0100
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: looking for help with a counting algorithm
Message-Id: <bso08s$eto4o$1@ID-202028.news.uni-berlin.de>

Andy Baxter wrote:
> I'm working on a web-based database project written in perl, which is a
> virtual library for people in the town where I live to share details of
> books and videos they have - the idea is if you find a book you like you
> click on 'borrow', and you are given details of how to contact the person
> who owns it.
> 
> I'm not sure exactly where to ask for this, as I'm looking for help with
> finding a good algorithm, rather than details of coding, but I've chosen
> this group as it's written in perl, and more of a coding problem than a
> cgi problem.
> 
> I have decided on a categorisation system for the items, where each item
> can belong to many categories, and each category can also be grouped as a
> subcategory under one or more higher level categories. Everything is
> stored in a mysql database, and the links between books and categories,
> and between categories and higher level categories are done through two
> linking tables, which have entries like:
> 
> CategoryMembership
> ------------------
> CatID	ItemId 	
> 1	1	
> 2	1
> 1	2
> 1	3
> 3	3
> 1	4
> 4	4
> 7	5
> 
> CategoryGrouping
> ----------------
> CatID	SubCatId 	SortOrder	Stop
> 1	2		1
> 1	3		2
> 1	4		3		
> 3	4		1		1 (yes.)
> 4	5		1
> 4	6		2
> 4	7		3
> 
> 
> I.e. item 1 is in cats 1 & 2, item 2 is in cat 1, item 3 is in cat 3, and
> item 4 is in cats 1 & 4. Categories 2 and 3 are in Cat 1, and Category 4
> is in cat 3 and cat 1 etc.
> 
> I want any set of category memberships or groupings of categories that can
> be represented like this without leading to loops to be allowed. (I.e. the
> only thing that isn't allowed is things like category 1 is grouped under
> cat 2 which is grouped under cat 3 which is grouped under cat 1, and more
> complex variations on this.)
> 

That's called a directed acyclic graph, or DAG.

> I have written some code which reads these tables and generates a
> tree-like data structure, where each category is represented by a hash
> like this:
> 
> {Name=>"category name",
>  Id=>"Id on database",
>  DownList=>ref of array with list of links to subcategories,
>  UpList=>ref of array with list of links to higher categories
> }
> 
> The links between categories are hashes like this:
> {Up=>ref to category hash,
>  Down=>ref to (sub) category hash,
>  Stop=>stop listing subcategories at this point?,
>  Sort=>sort order when displaying this subcategory}
> 
> This structure is then used by the scripts which render the pages
> displaying the categories. This bit is working fine.
> 
> The bit I'm finding difficult is how to count how many items there are
> under a given category, so that a count can be shown in the category index
> page. 
> 
> The code I have at the moment is here: (This code is in a module called
> LibMod.pm)
> 
> sub CountCatItems($$) {
> # Count how many items there are under this category, either directly or indirectly.
> 	my ($mod,$pCat,    # pointer to the category hash.
> 	    $pStack        # pointer to stack which
> 	    )= @_;
> 	my ($query,        # query handle.
> 	    $catId,        # category Id no.
> 	    $pLink         # ref to link between cats.
> 	   );
> 
> 	$catId=${$pCat}{Id};
> 	DPrint "counting ${$pCat}{Name} - $catId = ";
> 	$query=$db->prepare("select count(ItemId) from CategoryMembership where " .
> 	                    "CategoryId=$catId group By CategoryId");
> 	$query->execute;
> 	my ($dCount) = $query->fetchrow_array();
> 	$query->finish;
> 	${$pCat}{CountDirect}=$dCount;
> 	DPrint "$dCount<br>"; # debug print.
> 	foreach $pLink ( @{${$pCat}{DownList}} ) {
> 	  LibMod->CountCatItems(${$pLink}{Down}); # call self recursively
> 	  };
> 	};
> 
> This works, but only counts the number of items directly included in a
> category, not the ones which belong to a subcategory.
> 
> The thing that makes it hard is the multiple category membership plus
> multiple category grouping, but I want to keep this if I possibly can,
> because one of the problems with traditional non-computerised indexes is
> that you can't do this even though books can be relevant to several
> different topics.
> 
> My thoughts at the moment are either:
> 
> - give each category a hash where the keys are all the items included in
> the category. Read these in from the database, then each time a
> subcategory is counted, the code goes back up the tree to the root, adding
> the items that belong to it to all the higher level categories. When the
> recursive calls to subcategories return, (i.e. end of this code fragment),
> then count the keys in the hash. This would work I think, but it would
> involve retrieving all the category memberships from the database, rather
> than just the counts, and it might cause speed and memory problems if a
> lot of items were added to the system.
> 
> - or when you put an item in a category, category memberships are
> automatically created in the database for all the higher level categories.
> This would be quicker to count, but I'm thinking that if someone has
> chosen to put an item in a given subcategory, and then later on I decide
> to move that subcategory to a different group, the category memberships
> should shift to follow this, whereas with this system the item would stay
> in the old top-level categories.
> 
> Finally - my questions are:
> - does anyone know of an algorithm for working out the counts just from
> the counts in each category - i.e. without having to get details of
> exactly which items belong to each category? (I have a feeling this may be
> impossible)

You have to write a recursive algorithm, which you can precompute.

SQL has a "start with" and "connect by" syntax for this sort of thing, 
but mysql does to implement it. Oracle implement this  recursion for 
you. eg See http://www.adp-gmbh.ch/ora/sql/connect_by.html
It would be a bit of a nightmare to do it yourself.


> - or generally, and maybe more useful in the long run, a good place to
> start looking on the web for answers to problems like this when they crop
> up. 

Its called "graph theory", and has been well studied for decades.

> - also if you have any thoughts on either of the solutions I've
> described, or can think of a better way of doing it, I'd appreciate it.
> 
> andy.
> 



------------------------------

Date: Mon, 29 Dec 2003 02:14:34 +0000
From: Andy Baxter <news3@earthsong.null.free-online.co.uk>
Subject: Re: looking for help with a counting algorithm
Message-Id: <pan.2003.12.29.02.14.30.820986@earthsong.null.free-online.co.uk>

At earth time Mon, 29 Dec 2003 11:35:17 +0100, the following transmission
was received from the entity known as Gregory Toomey:

> Andy Baxter wrote:
>> I'm working on a web-based database project written in perl, which is a
>> virtual library for people in the town where I live to share details of
>> books and videos they have - the idea is if you find a book you like you
>> click on 'borrow', and you are given details of how to contact the person
>> who owns it.
>> 
>> I'm not sure exactly where to ask for this, as I'm looking for help with
>> finding a good algorithm, rather than details of coding, but I've chosen
>> this group as it's written in perl, and more of a coding problem than a
>> cgi problem.
>> 
 ...
>> The thing that makes it hard is the multiple category membership plus
>> multiple category grouping, but I want to keep this if I possibly can,
>> because one of the problems with traditional non-computerised indexes is
>> that you can't do this even though books can be relevant to several
>> different topics.
>> 
>> My thoughts at the moment are either:
>> 
>> - give each category a hash where the keys are all the items included in
>> the category. Read these in from the database, then each time a
>> subcategory is counted, the code goes back up the tree to the root, adding
>> the items that belong to it to all the higher level categories. When the
>> recursive calls to subcategories return, (i.e. end of this code fragment),
>> then count the keys in the hash. This would work I think, but it would
>> involve retrieving all the category memberships from the database, rather
>> than just the counts, and it might cause speed and memory problems if a
>> lot of items were added to the system.
>> 
>> - or when you put an item in a category, category memberships are
>> automatically created in the database for all the higher level categories.
>> This would be quicker to count, but I'm thinking that if someone has
>> chosen to put an item in a given subcategory, and then later on I decide
>> to move that subcategory to a different group, the category memberships
>> should shift to follow this, whereas with this system the item would stay
>> in the old top-level categories.
>> 
>> Finally - my questions are:
>> - does anyone know of an algorithm for working out the counts just from
>> the counts in each category - i.e. without having to get details of
>> exactly which items belong to each category? (I have a feeling this may be
>> impossible)
> 
> You have to write a recursive algorithm, which you can precompute.
> 
> SQL has a "start with" and "connect by" syntax for this sort of thing, 
> but mysql does to implement it. Oracle implement this  recursion for 
> you. eg See http://www.adp-gmbh.ch/ora/sql/connect_by.html
> It would be a bit of a nightmare to do it yourself.

Thanks for this - I didn't know you could do this sort of thing in sql. 
 
>> - or generally, and maybe more useful in the long run, a good place to
>> start looking on the web for answers to problems like this when they crop
>> up. 
> 
> Its called "graph theory", and has been well studied for decades.

OK, I'll have a look about.

I've tried doing the first method I thought of, and it's not working out
as slow as I thought - I added 10000 items to the dataset and it slowed
the page loading by just over a second, which isn't as bad as I thought.
This was on a 1.3 GHz machine doing nothing else though.

Precomputing the algorithm might help - thanks.

I think I needn't have posted about this - I just felt like I'd hit a
brick wall thinking about how to do it, then writing the posting helped me
put my thoughts together, but having written all that I wanted to post it
anyway and see if anyone had any suggestions.

For what it's worth, the code I've written now looks like this: (in module
LibMod.pm) Any comments welcome, as I'm still quite new to perl, and
probably not making best use of the language.

andy.

sub ReadCategories($$$) {
# Read in list of categories from database into Id index and tree structure.
	my ($mod,$pRoot, # a pointer to an empty hash which will be filled with the
	                 # category tree structure.
	    $pIdIndex,   # a pointer to an empty hash which will be filled with the
	                 # category Id index.
	    $pFlags      # ref to a hash with flags saying what info to include in the
	                 # tree.
	                 # CountItems=>defined  - count items belonging to that category.
	                 # Contains=>defined    - mark whether this category includes an
	                 #                        item.
	                 # ItemId=>num          - Id of item to check for.
	    )=@_;
	my ($query,     # query handle.
	    $pCats,     # ref to results from category query.
	    $pCatRow,   # ref to single row of results.
	    $pCat,      # ref to individual category entry in the data structure.
	    $pGroups,   # ref to results from category grouping query.
	    $pGroupRow, # ref to row from cat group query.
	    $pGroupCat, # ref to category that this one is grouped under.
	    $pLink      # ref to a grouping link between two categories.
	    );
	DPrint ("sub: ReadCategories<br>");
	$query=$db->prepare("select Id,Name from Category");
	$query->execute;
	$pCats=$query->fetchall_arrayref;
	$query->finish;

	# fill the category Id index with entries, each of which is a pointer to a hash
	# containing a category name and Id.
	foreach $pCatRow ( @$pCats ) {
		$pCat={Name=>$$pCatRow[1], # Category name.
		       Id=>$$pCatRow[0],   # Category Id.
		       UpList=>[],         # List of links to cats this is grouped under.
		       DownList=>[],       # List of links to cats grouped under this one.
		       };
		${$pIdIndex}{$$pCatRow[0]}=$pCat;
		if ( exists ${$pFlags}{CountItems} ) {
			$$pCat{Items}={};
			};
		};

	# Now read in the category groupings to generate a tree structure.

	# first generate a root category to build the tree from. There is no
	# category in the database with Id 0, but all the top level categories
	# have a CategoryGrouping entry with Id 0.
	${$pRoot}{Name}="root";
	${$pRoot}{Id}=0;
	${$pRoot}{UpList}=undef;
	${$pRoot}{DownList}=[];
	${$pIdIndex}{0}=$pRoot;

	# Read all the category groupings into a hash in memory:
	$query=$db->prepare("select GroupId,MemberId,SortOrder,Stop ".
	                    "from CategoryGrouping");
	$query->execute;
	$pGroups=$query->fetchall_arrayref;
	$query->finish;

	# Now go through all the groupings, and add links to the categories to make
	# a tree structure.
	foreach $pGroupRow (@$pGroups) {
		$pCat=${$pIdIndex}{$$pGroupRow[1]};
		$pGroupCat=${$pIdIndex}{$$pGroupRow[0]};
		$pLink={Down=>$pCat,           # ref to sub-category.
		        Up=>$pGroupCat,        # ref to group category.
		        Sort=>$$pGroupRow[2],  # sort order of this link.
		        };
		if ($$pGroupRow[3] ) {
			# if Stop is defined, don't display these subcategories.
			${$pLink}{Stop}=${$pGroupRow}[3];
			};
		# add link to up and down lists for the two categories.
		push @{${$pCat}{UpList}}, $pLink;
		push @{${$pGroupCat}{DownList}}, $pLink;
		};

	if ( exists ${$pFlags}{CountItems} ) {
		# count how many items belong to each category.
		# This means adding three keys to the category hash:
		#   CountDirect - How many belong to this category directly.
		#   CountUnique - How many belong to this category and none of its subcategories.
		#   CountTotal  - How many belong to this category and any of its subcategories.
		DPrint "Counting<br>";
		LibMod->CountCatItems($pRoot);
		}

#	LibMod->ReadCategoryLevel($pRoot,$pIdIndex,$pGroups);
	};

sub CountCatItems($$) {
# Count how many items there are under this category, either directly or indirectly.
	my ($mod,$pCat,    # pointer to the category hash.
	    $pStack        # pointer to stack which
	    )= @_;
	my ($query,        # query handle.
	    $catId,        # category Id no.
	    $pLink         # ref to link between cats.
	   );
	$catId=${$pCat}{Id};
	DPrint "sub: CountCatItems. Category= ${$pCat}{Name} - Id: $catId.<br>";
	#DPrint "iteration: $i <br>";
	$query=$db->prepare("select ItemId from CategoryMembership where " .
	                    "CategoryId=$catId ");
	$query->execute;
	my $pItems = $query->fetchall_arrayref();
	$query->finish;
	my $row;
	foreach $row (@$pItems) {
		my $itemId=$$row[0];
		FollowCatLinksUp($pCat,\&MarkCatContainsItem,$itemId);
		};
	#${$pCat}{CountDirect}=$dCount;
	#DPrint "$dCount<br>";
	foreach $pLink ( @{${$pCat}{DownList}} ) {
	  LibMod->CountCatItems(${$pLink}{Down});
	  };
	DPrint "CountCatItems: dumping items from $$pCat{Name} - ";
	DumpStruct($$pCat{Items});
	DPrint "<br>";
	$$pCat{Count}=scalar (keys (%{$$pCat{Items}}));
	};

sub MarkCatContainsItem {
# mark this category as contaning a given item.
	my ($pCat,$itemId
	   )=@_;
	${$$pCat{Items}}{$itemId}=1;
	};

sub FollowCatLinksUp {
# follow the upward pointing links from this category to all higher level cats,
# and do something with them.
	my ($pCat, # ref to category.
	    $pSub,        # sub to call on this category.
	    $parm
	    )=@_;
	DPrint "sub: FollowCatLinksUp. Category=$$pCat{Name}<br>";
	# go through each of the up-links:
	if ( not defined ($$pCat{UpList}) ) {
		DPrint "Reached category root. <br>";
		return;
		};
	&$pSub($pCat,$parm); # call the sub.
	my $pLink;
	foreach $pLink ( @{$$pCat{UpList}} ) {
		DPrint "Checking up-link: <br>";
		FollowCatLinksUp($$pLink{Up}, $pSub, $parm);
		};
	};

ReadCategories is called with two empty hash pointers by any of the
scripts that need to work with the category tree, and then this hash, with
the {Count} hash keys filled in for each category, is then passed on to
the function which renders the category listing page.

-- 
http://www.niftybits.ukfsn.org/

remove 'n-u-l-l' to email me. html mail or attachments will go in the spam
bin unless notified with [html] or [attachment] in the subject line. 



------------------------------

Date: Mon, 29 Dec 2003 07:42:08 +0000
From: Andy Baxter <news3@earthsong.null.free-online.co.uk>
Subject: Re: looking for help with a counting algorithm
Message-Id: <pan.2003.12.29.07.42.07.456309@earthsong.null.free-online.co.uk>

At earth time Mon, 29 Dec 2003 02:14:34 +0000, the following transmission
was received from the entity known as Andy Baxter:

> At earth time Mon, 29 Dec 2003 11:35:17 +0100, the following transmission
> was received from the entity known as Gregory Toomey:
> 
>> Andy Baxter wrote:
>>> I'm working on a web-based database project written in perl, which is a
>>> virtual library for people in the town where I live to share details of
>>> books and videos they have - the idea is if you find a book you like you
>>> click on 'borrow', and you are given details of how to contact the person
>>> who owns it.
>>> 
>>> I'm not sure exactly where to ask for this, as I'm looking for help with
>>> finding a good algorithm, rather than details of coding, but I've chosen
>>> this group as it's written in perl, and more of a coding problem than a
>>> cgi problem.
>>> 
> ...

> 
> I've tried doing the first method I thought of, and it's not working out
> as slow as I thought - I added 10000 items to the dataset and it slowed
> the page loading by just over a second, which isn't as bad as I thought.
> This was on a 1.3 GHz machine doing nothing else though.
> 

P.S. I just changed the code so that instead of going back up the tree
adding each item to the higher level categories' item lists individually,
it passes a hash with all the items in just once to the sub that goes back
up the tree. This has cut the increase in page loading time for 10000
items from 1064 ms to 383 ms. 

andy.

-- 
http://www.niftybits.ukfsn.org/

remove 'n-u-l-l' to email me. html mail or attachments will go in the spam
bin unless notified with [html] or [attachment] in the subject line. 



------------------------------

Date: Sun, 28 Dec 2003 17:58:07 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: retrieve webpage with POST
Message-Id: <slrnbuurgf.bdn.tadmc@magna.augustmail.com>

Dean Banko <dean.banko@globalnet.hr> wrote:

> I know that must be something like:
>    my $req=HTTP::Request->new(POST=>$url, [field=>'1', valid=>'yes');


   use HTTP::Request::Common;
   $ua = LWP::UserAgent->new;
   $ua->request(POST $url, [field => '1', valid => 'yes']);


> Can anyone help me?


The documentation for HTTP::Request says to see also HTTP::Request::Common.

If you'd paid close attention while reading the docs for the module
that you are using, you wouldn't _need_ anyone else's help.  :-)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Mon, 29 Dec 2003 01:30:05 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: retrieve webpage with POST
Message-Id: <bsnsun$ejjdt$1@ID-184292.news.uni-berlin.de>

Tad McClellan wrote:
> Dean Banko <dean.banko@globalnet.hr> wrote:
>> 
>> I know that must be something like:
>>    my $req=HTTP::Request->new(POST=>$url, [field=>'1', valid=>'yes');
> 
>    use HTTP::Request::Common;
>    $ua = LWP::UserAgent->new;
>    $ua->request(POST $url, [field => '1', valid => 'yes']);
> 
>> Can anyone help me?
> 
> The documentation for HTTP::Request says to see also
> HTTP::Request::Common.

Does it? I for one am not able to find that reference.

Anyway, thanks for the tip. I suppose it results in the same HTTP
request as my suggestion would do.

> If you'd paid close attention while reading the docs for the module
> that you are using, you wouldn't _need_ anyone else's help.  :-)

Hrrrm...

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



------------------------------

Date: Sun, 28 Dec 2003 20:41:06 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: retrieve webpage with POST
Message-Id: <SCLHb.1761$Vl6.430401@news20.bellglobal.com>


"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:bsnsun$ejjdt$1@ID-184292.news.uni-berlin.de...
> Tad McClellan wrote:
> >
> > The documentation for HTTP::Request says to see also
> > HTTP::Request::Common.
>
> Does it? I for one am not able to find that reference.
>

Umm, it's right in the See Also section of the documentation. A quick skim
through Poe's The Purloined Letter might be in order... ; )

Matt




------------------------------

Date: Sun, 28 Dec 2003 22:56:20 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: retrieve webpage with POST
Message-Id: <slrnbuvcvk.cht.tadmc@magna.augustmail.com>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> Tad McClellan wrote:

>> The documentation for HTTP::Request says to see also
>> HTTP::Request::Common.
> 
> Does it? I for one am not able to find that reference.


   http://search.cpan.org/~gaas/libwww-perl-5.76/lib/HTTP/Request.pm


> I suppose it results in the same HTTP
> request as my suggestion would do.


I do not know. I did not see your suggestion.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Mon, 29 Dec 2003 07:55:13 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: retrieve webpage with POST
Message-Id: <bsoji2$etv7f$1@ID-184292.news.uni-berlin.de>

Tad McClellan wrote:
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
>> Tad McClellan wrote:
>>> The documentation for HTTP::Request says to see also 
>>> HTTP::Request::Common.
>> 
>> Does it? I for one am not able to find that reference.
> 
>    http://search.cpan.org/~gaas/libwww-perl-5.76/lib/HTTP/Request.pm

There it is, obviously...  Thanks!

To *not* find it, I searched CPAN for HTTP::Request and ended up at
   http://search.cpan.org/~rse/lcwa-1.0.0/lib/lwp/lib/HTTP/Request.pm
-----------------------------------------------------^^^^^^^^^^^^

I should probably have been more attentive, but...

http://search.cpan.org/~rse/lcwa-1.0.0/ seems to be a 'historical
archive' of past versions of quite a few modules. :(

Is that in accordance with the PAUSE rules?

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



------------------------------

Date: Mon, 29 Dec 2003 09:04:38 +0100
From: "Dean Banko" <dean.banko@globalnet.hr>
Subject: Re: retrieve webpage with POST
Message-Id: <bson6o$jh$1@ls219.htnet.hr>

Hello Gunnar!

I thank you a lot for your assistance!
The syntax that you offered is functional, I've tested it and it works!

Thank you very much!
Happy New Year,
Dean

"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:bsnnce$ekeav$1@ID-184292.news.uni-berlin.de...
> Dean Banko wrote:
> > Does anyone know how to retreive a page generated as form request?
> > I need to post some data like in the row:
> >    my $req=HTTP::Request->new(POST=>$url);
> > but there are also some parameters that I must put into POST, but I
> > don't know the syntax :-(
> > I know that must be something like:
> >    my $req=HTTP::Request->new(POST=>$url, [field=>'1', valid=>'yes');
>
> Assuming you are talking about two fields named 'field' and 'valid',
> and whose values you want to be '1' respective 'yes', I'd try:
>
>      my $req=HTTP::Request->new(POST=>$url);
>      $req->content_type('application/x-www-form-urlencoded');
>      $req->content('field=1&valid=yes');
>
> (untested)
>
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl
>




------------------------------

Date: Sun, 28 Dec 2003 22:36:09 +0100
From: Torsten Mohr <tmohr@s.netic.de>
Subject: Use a Perl_Interpreter and NOT call it my_perl?  Use TWO interpreters?
Message-Id: <bsnic9$5e0$1@schleim.qwe.de>

Hi,

there are examples available on how to allocate a Perl_Interpreter
in a C program and work with it, e.g. let it execute a script.

In these examples, the Perl_Interpreter is always called
my_perl and i noticed that compiling fails when it is given
a different name.

Is it possible to give it a different name?

Is it possible to allovate TWO Perl_Interpreters at a time
and let them execute code?


Best regards,
Torsten.



------------------------------

Date: Mon, 29 Dec 2003 17:59:50 +0100
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Use a Perl_Interpreter and NOT call it my_perl?  Use TWO interpreters?
Message-Id: <bsompl$f4jrn$1@ID-202028.news.uni-berlin.de>

Torsten Mohr wrote:
> Hi,
> 
> there are examples available 
Where? If we can't see code we can't comment

>on how to allocate a Perl_Interpreter

DO you mean fork a process?
> in a C program and work with it, e.g. let it execute a script.
> 
I'm not sure shat "work" means.

> In these examples, the Perl_Interpreter is always called
> my_perl and i noticed that compiling fails when it is given
> a different name.
> 

If you are just forking a subprocess, you can fork as many as you want. 
if you want to call executables different names you can do that too.

> Is it possible to give it a different name?
> 
> Is it possible to allovate TWO Perl_Interpreters at a time
> and let them execute code?
> 
> 
> Best regards,
> Torsten.
> 

Your question is too cryptic. Be specific.

gtoomey



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 5987
***************************************


home help back first fref pref prev next nref lref last post