[16613] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4025 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 15 14:10:30 2000

Date: Tue, 15 Aug 2000 11:10:17 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <966363017-v9-i4025@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 15 Aug 2000     Volume: 9 Number: 4025

Today's topics:
    Re: Perl ? - How to do a count? <arthur.haas@westgeo.com>
    Re: Perl ? - How to do a count? <memmett@fraser.sfu.ca>
    Re: Perl ? - How to do a count? <mjcarman@home.com>
    Re: Perl ? - How to do a count? (Brandon Metcalf)
    Re: Perl, CGI, Linux and Forms, need help, urgent <Bulent@khio.no>
    Re: Problem with IIS4 <fb@ltec.ch>
    Re: sample terminal game for newbie <cboyd@holyrood.ed.ac.uk>
    Re: sample terminal game for newbie <spetey@umich.edu>
        Search problems: Van Gogh site (David)
    Re: Search problems: Van Gogh site (Marcel Grunauer)
    Re: Someone help!!! <timewarp@shentel.net>
    Re: Subroutine being redefined in module nobull@mail.com
    Re: tag parsing. <bkennedy99@home.com>
    Re: What's the best way to overwrite a string with '*? (Teodor Zlatanov)
    Re: What's the best way to overwrite a string with '*? <alex.buell@tahallah.clara.co.uk>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 15 Aug 2000 10:29:19 -0500
From: Art Haas <arthur.haas@westgeo.com>
Subject: Re: Perl ? - How to do a count?
Message-Id: <lrya1ylf00.fsf@h130p254.wg.waii.com>

louis@aol.com (Louis) writes:

> Hi.  I was hoping someone might be able to help me out with how to
> do something in perl.
> 
> Let's say I have a text file that looks like this, with thousands of
> entries?
> John     www.somewhere.com 
> Mary     www.jodesigner.com  
> Tom      www.tomsplace.com
> John     www.somewhere.com
> 
> What I want to do is aggragate all the names and display it or write
> it to a file.
> 
> Total unique users:  1234
>     john       34
>    Mary     10
>    Tom        1
>    Sarah     12
> 
> Total unique urls:    35
>     www.somewhere.com   432
>     www.yahoo.com    345
> 
> Can anyone show me how to do this?  If you could send me email with
> an example, I would greatly appreciate it.
> 

I'm feeling generous this morning, but if you post a message here your
response goes here.

$ cat trash.txt
John     www.somewhere.com 
Mary     www.jodesigner.com  
Tom      www.tomsplace.com
John     www.somewhere.com
$ cat count.pl
#!/usr/local/bin/perl

use strict;

my %people = ();
my %urls = ();

my $datafile = 'trash.txt';

open(DATAFILE,"<$datafile") || die "Can't open `$datafile'! $!\n";
while(<DATAFILE>) {
	chomp;
	my @fields = split(' ');
	$people{$fields[0]}++;
	$urls{$fields[1]}++;
}
close(DATAFILE);

my @people = sort keys %people;
print "Total unique users: ", scalar(@people), "\n";
foreach my $person (@people) {
	print "\t$person: $people{$person}\n";
}

my @urls = sort keys %urls;
print "Total unique urls: ", scalar(@urls), "\n";
foreach my $url (@urls) {
	print "\t$url: $urls{$url}\n";
}
$ perl count.pl
Total unique users: 3
        John: 2
        Mary: 1
        Tom: 1
Total unique urls: 3
        www.jodesigner.com: 1
        www.somewhere.com: 2
        www.tomsplace.com: 1
$

The perl documentation  on your computer should provide you with more
than enough info to explain any of the above code.

-- 
###############################
# Art Haas
# (713) 689-2417
###############################


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

Date: 15 Aug 2000 09:03:31 -0700
From: Matthew Emmett <memmett@fraser.sfu.ca>
Subject: Re: Perl ? - How to do a count?
Message-Id: <yvw9r97qtsto.fsf@fraser.sfu.ca>

louis@aol.com (Louis) writes:

> Can anyone show me how to do this?  If you could send me email with
> an example, I would greatly appreciate it.

Do you have any idea's on how to solve this problem yourself?  Perhaps
you could share them with us.

> Total unique users:  1234
>     john       34
>    Mary     10
>    Tom        1
>    Sarah     12

I think a hash table would be useful here.  Use the name of the user
as a key, and the number of times they're listed as the value.

> Total unique urls:    35
>     www.somewhere.com   432
>     www.yahoo.com    345

Same idea as above.


How does that sound?  Now you just have to figure out how to read in
the lines and extract the names and urls.

Matt


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

Date: Tue, 15 Aug 2000 10:33:38 -0500
From: Michael Carman <mjcarman@home.com>
To: Louis <louis@aol.com>
Subject: Re: Perl ? - How to do a count?
Message-Id: <399962D2.6C35BA21@home.com>

[Posted and CC'd, per request]

Louis wrote:
> 
> Hi.  I was hoping someone might be able to help me out with how to 
> do something in perl.

I don't want to sound condescending, but this is a pretty trivial use of
hashes. If doing something like this is a challenge for you, you're
probably pretty new to Perl, and should head down to your local
bookstore and pick up a nice introductory text. Look at "Learning Perl"
or "Learning Perl for Win32 Systems" first.

> Let's say I have a text file that looks like this, with thousands
> of entries?
> John     www.somewhere.com
> Mary     www.jodesigner.com
> Tom      www.tomsplace.com
> John     www.somewhere.com
> 
> What I want to do is aggragate all the names and display it or 
> write it to a file.
> 
> Total unique users:  1234
>     john       34
>    Mary     10
>    Tom        1
>    Sarah     12
> 
> Total unique urls:    35
>     www.somewhere.com   432
>     www.yahoo.com    345

Just make a couple hashes containing counts of how many times you've
seen a particular user or URL:

#!/usr/local/bin/perl -w
use strict;

my (%user_visits, %url_visits);

while (<DATA>) {
    chomp;
    my ($user, $url) = split;

    $user_visits{$user}++;
    $url_visits{$url}++;
}

printf ("Total unique users: %d\n", scalar keys %user_visits);
foreach (sort keys %user_visits) {
    print "    $_: $user_visits{$_}\n";
}
print "\n";

printf ("Total unique URLs: %d\n", scalar keys %url_visits);
foreach (sort keys %url_visits) {
    print "    $_: $url_visits{$_}\n";
}
print "\n";

__DATA__
John     www.somewhere.com 
Mary     www.jodesigner.com  
Tom      www.tomsplace.com
John     www.somewhere.com

Reading/writing from a file is left as an exercise for the reader. :)
 
> Can anyone show me how to do this?  If you could send me email 
> with an example, I would greatly appreciate it.

I'll Cc you a copy, since you asked, but in general responses should be
directed to the newsgroup, so that others may benefit. :)

-mjc


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

Date: 15 Aug 2000 16:30:17 GMT
From: bmetcalf@nortelnetworks.com (Brandon Metcalf)
Subject: Re: Perl ? - How to do a count?
Message-Id: <8nbr6p$bh1$1@bcrkh13.ca.nortel.com>

louis@aol.com writes:

 > Let's say I have a text file that looks like this, with thousands of entries?
 > John     www.somewhere.com 
 > Mary     www.jodesigner.com  
 > Tom      www.tomsplace.com
 > John     www.somewhere.com
 > 
 > What I want to do is aggragate all the names and display it or write it to a
 > file.
 > 
 > Total unique users:  1234
 >     john       34
 >    Mary     10
 >    Tom        1
 >    Sarah     12
 > 
 > Total unique urls:    35
 >     www.somewhere.com   432
 >     www.yahoo.com    345

No need for Perl.  You can do this with uniq and sort.

Brandon


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

Date: Tue, 15 Aug 2000 18:04:17 +0200
From: Bulent Sarinc <Bulent@khio.no>
Subject: Re: Perl, CGI, Linux and Forms, need help, urgent
Message-Id: <39996A01.FA101AA0@khio.no>

thanx, i made it at last :)


David Efflandt wrote:

> On Thu, 10 Aug 2000 10:35:31 +0200, Erdal Sarinc <erdal@khio.no> wrote:
> >Hi,
> >
> >I need help to solve an attachment problem due to a application form.
> >
> >I want people/users to attach their files to the application form, just
> >as you do at www.hotmail.com but i cant figure out how to this.
> >I need to know the code beyond these scripts: attach, doattach
>
> In your console or xterm type:  perldoc CGI
>
> Use the CGI module to create and process the form and file upload, and
> grab the MIME::Lite module from your favorite CPAN site (or
> http://www.perl.com/) to e-mail the uploaded attachment.  Once you install
> MIME::Lite you can read about it with 'perldoc MIME::Lite'.
>
> --
> David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
> http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
> http://hammer.prohosting.com/~cgi-wiz/  http://cgi-help.virtualave.net/



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

Date: Tue, 15 Aug 2000 17:48:07 +0200
From: "Felix Brack" <fb@ltec.ch>
Subject: Re: Problem with IIS4
Message-Id: <39996697@news.datacomm.ch>

Many thanks to you, this did help!

--
-----------------------------------
Felix Brack
LTEC AG
Dorfgasse 10
CH-4435 Niederdorf
SWITZERLAND
Internet: http://www.ltec.ch

Tel. +41 61 963 14 14
Fax. +41 61 963 14 13
E-Mail: fb@ltec.ch
"Dr. Peter Dintelmann" <Peter.Dintelmann@dresdner-bank.com> wrote in message
news:8nbikm$2ls3@intranews.dresdnerbank.de...
>     Hi,
>
> Felix Brack schrieb in Nachricht <39991cfb@news.datacomm.ch>...
> >I just setup Perl on a IIS4 server. When I type the name of
> >a perl script at the commandline on the server, perl.exe takes
> >the script and everything comes out fine.
> >When I want to run the same perl script from within a html page,
> >perl.exe does not seem to run, since the data returned is just
> >the contents of the perl script, not the output perl.exe should generate
> >from my script.
>
>     this is a webserver configuration issue.
>     Attached find a MS WinWord document
>     (you are running Windows anyway ;-)
>     how the app config has to look like.
>
>     Best regards,
>
>         Peter Dintelmann
>
>
>
>




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

Date: 15 Aug 2000 16:14:20 GMT
From: Chris Boyd <cboyd@holyrood.ed.ac.uk>
Subject: Re: sample terminal game for newbie
Message-Id: <8nbq8s$i47$1@scotsman.ed.ac.uk>

Steve Petersen <spetey@umich.edu> wrote:

: I'm hoping to learn Perl and work up a terminal game at the same time. 
: I've been through the llama book and I'd like to try a real program. 
: Can anyone recommend a good GPL'd terminal game in Perl (along the lines
: of the BSD "mille" version of mille bourne, say) to get me started?

Don't know about GPL, but take a look at
http://language.perl.com/ppt/what.html.  Classic Unix games (e.g. 
hangman) implemented in Perl are shown in italics, with links to their
sources. 

Also, try searching for "Eliza" at http://search.cpan.org/.

However, I would suggest you'd be better off getting the pseudocode for
a simple game algorithm and translating that into Perl as you learn it. 


Best wishes,
-- 
Chris Boyd                      | from, but \    Medical Genetics Section
Chris.Boyd@ed.ac.uk             | not for,  /    MMC, Edinburgh Uni.,
http://www.ed.ac.uk/~cboyd                       EH4 2XU, SCOTLAND


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

Date: Tue, 15 Aug 2000 13:19:35 -0400
From: Steve Petersen <spetey@umich.edu>
Subject: Re: sample terminal game for newbie
Message-Id: <39997BA7.40C1BDB@umich.edu>

I'll take a look, thanks very much!

Chris Boyd wrote:
> 
> Steve Petersen <spetey@umich.edu> wrote:
> 
> : I'm hoping to learn Perl and work up a terminal game at the same time.
> : I've been through the llama book and I'd like to try a real program.
> : Can anyone recommend a good GPL'd terminal game in Perl (along the lines
> : of the BSD "mille" version of mille bourne, say) to get me started?
> 
> Don't know about GPL, but take a look at
> http://language.perl.com/ppt/what.html.  Classic Unix games (e.g.
> hangman) implemented in Perl are shown in italics, with links to their
> sources.
> 
> Also, try searching for "Eliza" at http://search.cpan.org/.
> 
> However, I would suggest you'd be better off getting the pseudocode for
> a simple game algorithm and translating that into Perl as you learn it.
> 
> Best wishes,
> --
> Chris Boyd                      | from, but \    Medical Genetics Section
> Chris.Boyd@ed.ac.uk             | not for,  /    MMC, Edinburgh Uni.,
> http://www.ed.ac.uk/~cboyd                       EH4 2XU, SCOTLAND


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

Date: Tue, 15 Aug 2000 16:54:56 GMT
From: brooksd@interlog.com (David)
Subject: Search problems: Van Gogh site
Message-Id: <iqem5.13140$Lg1.218005@cac1.rdr.news.psi.ca>

Hello, all: I posted a question about modifying a search results page a week 
or so ago and got some very helpful responses.  I'm posting this follow up 
note today to request additional help.

It was clear from the newsgroup exchanges from my original note that the 
coding in my search.cgi file (original from Matt's Script Archive) is a mess.  
It's been altered and adjusted so many times over the years (mostly by 
others--I confess, I really don't know perl at all) that it's really a 
complete wreck.

As of right now:

- Despite including all directories in the @files = line, many directories are 
being ignored by the search.

- I tried setting up a second search page and this completely failed.

My site is:

http://www.vangoghgallery.com

And my search page can be found at:

http://www.vangoghgallery.com/misc/search_frame.htm

What I'm requesting is for someone to help me work out the problems with my 
search.  I have to admit this will involve some hand-holding and I'm sorry for 
that.  But if anyone is able to help me fix these problems and get the search 
engine stable again, I would be more than happy to link to their site and/or 
acknowledge their assistance in any way.  My Van Gogh site includes 100% of 
Van Gogh's works and letters and is more than 3,500 pages.  It receives 
upwards of 100,000 visitors each month and a stable, reliable search page is 
clearly essential.

If anyone can help in any way, I would be *extremely* grateful.

Best regards,

David Brooks
brooksd@interlog.com


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

Date: Tue, 15 Aug 2000 17:47:01 GMT
From: marcel@codewerk.com (Marcel Grunauer)
Subject: Re: Search problems: Van Gogh site
Message-Id: <slrn8pj0g3.cl4.marcel@gandalf.local>

On Tue, 15 Aug 2000 16:54:56 GMT, David <brooksd@interlog.com> wrote:

>What I'm requesting is for someone to help me work out the problems with my 
>search.  I have to admit this will involve some hand-holding and I'm sorry for 
>that.  But if anyone is able to help me fix these problems and get the search 
>engine stable again, I would be more than happy to link to their site and/or 
>acknowledge their assistance in any way.  My Van Gogh site includes 100% of 
>Van Gogh's works and letters and is more than 3,500 pages.  It receives 
>upwards of 100,000 visitors each month and a stable, reliable search page is 
>clearly essential.


Did you have a look at htdig (www.htdig.org) ?


-- 
Marcel
sub AUTOLOAD{($_=$AUTOLOAD)=~s;^.*::;;;y;_; ;;print} Just_Another_Perl_Hacker();


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

Date: Tue, 15 Aug 2000 11:21:24 -0400
From: Albert Dewey <timewarp@shentel.net>
Subject: Re: Someone help!!!
Message-Id: <39995FF4.FDDBD7D5@shentel.net>

Kevin -

I won't flame you for this but I must say that finding free scripts is
essentially worthless. I have learned that scripts that are free are worth what
you pay for them. I find that it takes more time combing through someone's
publicly available script to figure out what the hell the coder was doing and
then modifying it for my needs takes far more time than starting from scratch
and making a script that performs exactly what I want it to do.

Just a few months ago I didn't know squat about Perl as I only had programmed in
C. I had a friend who was willing to pay for a site that does exactly what you
have asked for. I took the challenge and within three weeks was well on my way
to making this site for him. After 6 weeks I was done and learned a hell of a
lot in the process. Today I could probably make the same thing in a matter of
days instead of weeks. How did I do this? Not by using anyone else's codes or
scripts. I went out and bought several books on programming Perl for the
internet and methodically learned everything I needed while I was creating the
site.

If you are still are looking for a good script that you can 'post and play' on
your site, then I wish you luck. It would be far better for you to join the
programming crowd and learn how to make your own.

As they say, come on in, the water's fine!

Albert Dewey

Kevin Ostrowski wrote:

> I've been trying to find a couple of  free/low-cost script that do these
> things...
>
> script 1.) A user inputs data (name, email, comments, ect...). The user is
> also able to upload an image. This information is then saved via flatfile
> (individual html pages will work too) All this info needs to be displayed in
> a template (needs not be external HTML I don't mind coding it into the
> script, although external would be better) with a table of contents or list
> of each users name, that when clicked on shows that user's info. This
> doesn't seem like it would be that hard to find, but I've had no luck!!! I
> am NOT a perl programmer, so can someone point me in the right direction?
>
> script 2.) This one's a little more advanced, but I need a review script
> similar to the one on Amazon.com where people can review and rate products.
>
> If anyone can help me fine either or both of these, you would be saving my
> life!!! I've looked everywhere, but can't seem to find them!!
>
> Thanks
>
> Kevin



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

Date: 15 Aug 2000 17:47:54 +0100
From: nobull@mail.com
Subject: Re: Subroutine being redefined in module
Message-Id: <u9itt2o4hx.fsf@wcl-l.bham.ac.uk>

G <glchyNOglSPAM@email.com.invalid> writes:

> Im getting "Subroutine signoff_html redefined at Validation.pm
> line 173" when i do a # perl -wc Validation.pm but the syntax is
> OK. Using Perl version 5.005_03 built for i386-linux.

> Just wondering what did that mean and also whether it was ok to
> ignore that message....

Impossible to say without more info.

Could be that something other than Validation.pm is also defining
signoff_html.  This may well be a sign that one or more modules are
lacking "package" directives.

Could also be that Validation.pm is getting compiled twice for some
reason.

Could even be that there really are two definitions of signoff_html in
Validation.pm (perl -c does not detect this).

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 15 Aug 2000 16:03:35 GMT
From: "Ben Kennedy" <bkennedy99@home.com>
Subject: Re: tag parsing.
Message-Id: <rRdm5.103748$A%3.1372798@news1.rdc2.pa.home.com>


<johnvert@my-deja.com> wrote in message news:8nald4$825$1@nnrp1.deja.com...
> Could you please clarify what you mean by ``consistently changing your
> parameters with each response provided''?  I have no idea what you
> mean.  The only mistake I've made in this thread was posting the post
> more than once, which happened accidently.  If I did anything else wrong
> I'd like to know.  But please, before throwing accusations around, at
> least tell me what it is that you mean.
>
> thanks,
>  -- john

You haven't done anything wrong - Godzilla often complains because sometimes
when she posts a solution, people respond with "Well, what if the parameters
were X and Y, then your code would fail".  However, she fails to realize
that in many cases, the stated parameters of a problem are just one possible
set of input.  For instance, her original solution could fail if the tags
you were looking for appeared lower case.  Since html tags are case
insensitive, a proper solution should also be case insensitive.  Is case
insensitivity a stated parameter?  No, but I think it should part of a good
solution anyway.

You were astute to realize that HTML parsing can be tricky, and using an
HTML:: based module was a logical solution to your original problem.  There
may be variations in html that you haven't even conceived of, yet by using a
HTML:: module you have effectively accounted for.  A regexp based solution
may work for this particular problem, but an HTML:: based solution will be
guaranteed to work on a wider range of inputs, plus it is XS based it will
run faster.  So, I think you are on the right track.

--Ben Kennedy





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

Date: 15 Aug 2000 11:18:56 -0500
From: tzz@iglou.com (Teodor Zlatanov)
Subject: Re: What's the best way to overwrite a string with '*?
Message-Id: <39995f60$1_2@news.iglou.com>

<spijrqrmkn990@corp.supernews.com>:Greg Bacon (gbacon@HiWAAY.net):comp.lang.perl.misc:Tue, 15 Aug 2000 14:11:06 GMT:quote:
: In article <399947d8$1_2@news.iglou.com>, Teodor Zlatanov <tzz@iglou.com> wrote:
: : # replace all characters in the range 0x01 to 0xFF with '*'
: : $string =~ tr/\x01-\xFF/*/; 
: 
:     $string =~ tr//*/c;

I wanted to allow that he may only want some characters replaced rather than
all, e.g. A-Za-z or some such.  Your way is better in the original example,
of course :)

-- 
Teodor Zlatanov <tzz@iglou.com>
"Brevis oratio penetrat colos, longa potatio evacuat ciphos." -Rabelais


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

Date: Tue, 15 Aug 2000 16:49:13 +0100
From: Alex Buell <alex.buell@tahallah.clara.co.uk>
Subject: Re: What's the best way to overwrite a string with '*?
Message-Id: <jipips0tj227kequkn75hh9158gppgbo3m@4ax.com>

On 15 Aug 2000 11:18:56 -0500, tzz@iglou.com (Teodor Zlatanov) wrote:

>:     $string =~ tr//*/c;
>
>I wanted to allow that he may only want some characters replaced rather than
>all, e.g. A-Za-z or some such.  Your way is better in the original example,
>of course :)

No, it's what I wanted. 

I wanted to replace all characters including white spaces with
asterisks. 

Thanks. 

Cheers,
Alex.
-- 
Bring on the music and lights!


http://www.tahallah.clara.co.uk


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4025
**************************************


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