Re: newbie need help

2003-01-16 Thread Laird Shaw
The problem is that it is printing something for each line regardless of 
whether it has already found a match.  What you need to do is save whether 
you have found a match or not in a variable, then selectively print, ie:
a) set your variable to be false - ie indicating that you haven't found a 
match yet,
b) don't print anything if a particular line doesn't match - wait until the 
end of the loop to print that a match wasn't found (by checking that your 
variable is still false),
c) print that you have found a match when a particular line matches, store 
in your variable that you have found a match, and then *exit the loop* 
because you don't need to check any more.

I am not sure why you are passing in a password as you don't seem to be 
checking it anywhere.  I am assuming that $field3 is NOT the password - in 
fact I couldn't see any possible password in your file.  Are you checking 
the password at all???

Also, I'm not sure you really want to be using the regular expression you 
are using.  If you use one at all, I would have thought you would want it 
the other way around, ie ($field2 =~ /\b$username\b/).  This means if the 
line in the file read:

user: user1*^ realm: my.domain.com mech:PLAIN

then entering $username='user1' would match this line.
With your regular expression of ($username =~ /\b$field2\b/) you are 
matching
$username='user1*^'
to the line in the file:

user: user1 realm: my.domain.com mech:PLAIN

I don't know your needs but it seems to me that you would be better off 
without a regexp at all, just using ($username eq $field2).  I have modified 
the code accordingly and put in the stuff I explained in a, b, c above (note 
that as we are not checking password, this will only match the first 
$username found in the file):

#!/usr/bin/perl
use CGI qw(param);

$username = param('username');
$password = param('password');

$file= /home/user/public_html/file.txt;
print Content-type: text/plain\n\n;
#we haven't found a match yet
my $foundmatch=0;
open (F1,$file);
foreach (F1) {
 chomp;
 ($field1,$field2,$field3,$field4,$field5,$field6) = split /\s/, $_;
 if ($username eq $field2) {
   #only print when we find a match
   print OK\n;
   print $username and $password\n;
   #store that we have found a match so we don't print oops try again at 
the end
   $foundmatch=1;
   #exit the loop as we don't need to check anymore
   last;
 }
}
close(F1);
if (not $foundmatch) {
 #we didn't find a match as $foundmatch is still false
 print oops try again\n;
}

Glynn S. Condez [EMAIL PROTECTED] wrote:

Hi it works now but why is it that it prints a lot of results and it seems
that it reads the
file line by line and do the output. Sorry i forgot to mention that the 
file
contains duplicate entries
of username, it something like:

snip
user: user1 realm: my.domain.com mech:PLAIN
user: user2 realm: my.domain.com mech:PLAIN
user: user1 realm: my.domain.com mech: DIGEST-MD5
user: user3 realm: my.domain.com mech:PLAIN
user: user2 realm: my.domain.com mech:DIGEST-MD5
---snip---

so if the file contents 10 lines of entries it display 10 lines of output,
here's the real output

if match is found, browser prints:
oppss try again
OK, user1 found
oppss try again
oppss try again
OK, user1 found
oppss try again
oppss try again
oppss try again
oppss try again
oppss try again

if no match found, browser prints:
oppss try again
oppss try again
oppss try again
oppss try again
oppss try again
oppss try again
oppss try again
oppss try again
oppss try again
oppss try again

Is it possible not to display all the entry that match and doesn't match,
just only print OK, user1 found and opps try again?

what should be added or changed on the code?

TIA
glen







 On Wed, 15 Jan 2003 15:54:02 +0800, [EMAIL PROTECTED] (Glynn
 S. Condez) wrote:

 i have a web form that users can input a username and password and 
check
if
 the username is valid by parsing or extracting the contents of a file,
here
 the web form html:

 I'm not sure what you are trying to do with just the username,
 don't you want to check the password too?

 #!/usr/bin/perl
 use CGI qw(param);
 
 $username = param('username');
 $password = param('password');
 
 $file= /home/user/public_html/file.txt;
 print Content-type: text/plain\n\n;
 open (F1,$file);
 foreach (F1) {
 chomp;
 ($field1,$field2,$field3,$field4,$field5,$field6) = split /\s/, $_;
 
 if ($username =~ /\b$field2\b/) {
 if (($username =~ /\b$field2\b/)and ($password =~ /\b$field3\b/)) {
 print OK\n;
 print $username and $password\n;

 }else{
 print oops try again\n;
   }
 }
 close(F1);

 
 and this is the content of the file.txt:
 snip
 user: user1 password my.domain.com mech:PLAIN

 user: user2 realm: my.domain.com mech:PLAIN
 user: user3 realm: my.domain.com mech:PLAIN
 user: user4 realm: my.domain.com mech:PLAIN
 ---snip---
 
 my problem with this script is, it doesnt display if the
 username is valid or not but valid usernames display
 OK, $username and 

Making script case insensitive

2003-01-16 Thread Bob Williams
How can this script compare two lists and save the matched components while
being insensitive to case? This script compares a subscription list against
the standard list and removes the emails not in the standard list. It works,
but if cases do not match in every detail, it fails. Thanks.

%bingo_subscribers = {}; open(BINGO, $BINGO_SUBSCRIPTION_FILENAME);
while(BINGO){
  chomp($_); $bingo_subscribers{$_} = 1; } @valid_bingo_subscribers = ();
open(MASSMAIL1, $MASS_MAIL_FILENAME);
while(MASSMAIL1){   chomp($_);
($user_email, $user_name) = split(/:/, $_);
  if ($bingo_subscribers{$_} == 1)  {push(@valid_bingo_subscribers,
$user_email);  }
} open(BINGO_VALID, $VALID_BINGO_SUBSCRIPTION_FILENAME);
foreach $valid_subscriber (@valid_bingo_subscribers)
{  print BINGO_VALID $valid_subscriber .\n; }


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Weekly list FAQ posting

2003-01-16 Thread casey
NAME
beginners-faq - FAQ for the beginners-cgi mailing list

1 -  Administriva
  1.1 - I'm not subscribed - how do I subscribe?

Send mail to [EMAIL PROTECTED]

You can also specify your subscription email address by sending email to
(assuming [EMAIL PROTECTED] is your email address):

[EMAIL PROTECTED].

  1.2 -  How do I unsubscribe?

Now, why would you want to do that? Send mail to
[EMAIL PROTECTED], and wait for a response. Once you
reply to the response, you'll be unsubscribed. If that doesn't work,
find the email address which you are subscribed from and send an email
like the following (let's assume your email is [EMAIL PROTECTED]):

[EMAIL PROTECTED]

  1.3 - There is too much traffic on this list. Is there a digest?

Yes. To subscribe to the digest version of this list send an email to:

[EMAIL PROTECTED]

To unsubscribe from the digest, send an email to:

[EMAIL PROTECTED]

  1.4 - Is there an archive on the web?

Yes, there is. It is located at:

http://archive.develooper.com/beginners-cgi%40perl.org/

  1.5 - How can I get this FAQ?

This document will be emailed to the list once a month, and will be
available online in the archives, and at http://beginners.perl.org/

  1.6 - I don't see something in the FAQ, how can I make a suggestion?

Send an email to [EMAIL PROTECTED] with your suggestion.

  1.7 - Is there a supporting website for this list?

Yes, there is. It is located at:

http://beginners.perl.org/

  1.8 - Who owns this list?  Who do I complain to?

Casey West owns the beginners-cgi list. You can contact him at
[EMAIL PROTECTED]

  1.9 - Who currently maintains the FAQ?

Kevin Meltzer, who can be reached at the email address (for FAQ
suggestions only) in question 1.6

  1.10 - Who will maintain peace and flow on the list?

Casey West, Kevin Meltzer and Ask Bjoern Hansen currently carry large,
yet padded, clue-sticks to maintain peace and order on the list. If you
are privately emailed by one of these folks for flaming, being
off-topic, etc... please listen to what they say. If you see a message
sent to the list by one of these people saying that a thread is closed,
do not continue to post to the list on that thread! If you do, you will
not only meet face to face with a XQJ-37 nuclear powered pansexual
roto-plooker, but you may also be taken off of the list. These people
simply want to make sure the list stays topical, and above-all, useful
to Perl/CGI beginners.

  1.11 - When was this FAQ last updated?

Sept 07, 2001

2 -  Questions about the 'beginners-cgi' list.
  2.1 - What is the list for?

A list for beginning Perl programmers to ask questions in a friendly
atmosphere. The topic of the list is, of course, CGI with Perl.

  2.2 - What is this list _not_ for?

* SPAM
* Homework
* Solicitation
* Things that aren't Perl related
* Non Perl/CGI questions or issues
* Lemurs
  2.3 - Are there any rules?

Yes. As with most communities, there are rules. Not many, and ones that
shouldn't need to be mentioned, but they are.

* Be nice
* No flaming
* Have fun
  2.4 - What topics are allowed on this list?

Basically, if it has to do with Perl/CGI , then it is allowed. If your
question has nothing at all to do with Perl/CGI, it will likely be
ignored.

  2.5 - I want to help, what should I do?

Subscribe to the list! If you see a question which you can give an
idiomatic and Good answer to, answer away! If you do not know the
answer, wait for someone to answer, and learn a little.

  2.6 - Is there anything I should keep in mind while answering?

We don't want to see 'RTFM'. That isn't very helpful. Instead, guide the
beginner to the place in the FM they should R :)

  2.7 - I don't want to post a question if it is in an FAQ. Where should I
look first?

Look in the FAQ! Get acquainted with the 'perldoc' utility, and use it.
It can save everyone time if you look in the Perl FAQs first, instead of
having a list of people refer you to the Perl FAQs :) You can learn
about 'perldoc' by typing:

perldoc perldoc

At your command prompt. You can also view documentation online at:

http://www.perldoc.com and http://www.perl.com

3 - Other Resources
  3.1 - What other websites may be useful to a beginner ?

* Perl Home Page - http://www.perl.com
* PerlMonks - http://www.perlmonks.org
* Perldoc - http://www.perldoc.com
* Perl Archives - http://www.perlarchives.com
  3.2 - What resources may be harmful to a beginner?

Beware of Perl4-like code-- You might find some script archives and
unauthorized mirrors with old Perl4 versions of Selena Sol and Matt
Wright scripts. Don't use those scripts. They are outdated and may even
in some cases contain bugs or security problems since many may not have
been updated in 

Re: HTTP headers

2003-01-16 Thread William McKee
Hi Philip,

I looked at the script. How are you running it? From the command
line or from a web server? It works fine on the comand line and from the
server for me. What server are you using to display it? I'm using Apache. 

If you are running it from the server you may need to include -nph = 1 to
tell the server not to generate headers because you are doing it
yourself. I've never had a need to do this myself.

Good luck,
William

-- 
Knowmad Services Inc.
http://www.knowmad.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: cgi.pm generate html vs. print EndOfHTML;

2003-01-16 Thread Hughes, Andrew
Thanks for the feedback.  Before I get started on the html::template
tutorial, I wanted to try a quick sample page using html::template.
However, when I try it, I cannot get the tag in the html to process.  Could
someone take a look and let me know what you think I am doing incorrectly?



This is the .pl file

#! /usr/bin/perl -w
# nationalConsumerShoppingSurveyResults.pl

use strict;
use lib qw(/home/ahughes/myLibrary);
use CGI qw(:standard escape escapeHTML);
use CGI::Carp qw(fatalsToBrowser);
use HTML::Template;


my $bar = 'World';
my $template = HTML::Template-new(filename = 'results.tmpl');
$template-param(SECRET_MESSAGE = $bar);
print $template-output;



This is the .tmpl file:

!-- results.tmpl --
html
head
titleUntitled Document/title
meta http-equiv=Content-Type content=text/html; charset=iso-8859-1
/head

body bgcolor=#FF text=#00
h1Hello TMPL_VAR NAME=SECRET_MESSAGE/h1

/body
/html



When I view the source of results I see the tag TMPL_VAR
NAME=SECRET_MESSAGE where I expect to see World.

Any thoughts?

Andrew


-Original Message-
From: fliptop [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 16, 2003 7:07 AM
To: Hughes, Andrew
Cc: '[EMAIL PROTECTED]'
Subject: Re: cgi.pm generate html vs. print EndOfHTML;


On Wed, 15 Jan 2003 at 21:11, Hughes, Andrew opined:

HA:does anyone have any strong feelings (know of tutorials) toward an
HA:altrnative method like html::template or html::mason?  Any and all
HA:suggestions are greatly appreciated.

http://www.peacecomputers.com/addressbook/step5.html

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: cgi.pm generate html vs. print EndOfHTML;

2003-01-16 Thread fliptop
On Thu, 16 Jan 2003 at 11:49, Hughes, Andrew opined:

HA:Thanks for the feedback.  Before I get started on the html::template
HA:tutorial, I wanted to try a quick sample page using html::template.
HA:However, when I try it, I cannot get the tag in the html to process.  Could
HA:someone take a look and let me know what you think I am doing incorrectly?
HA:
HA:my $template = HTML::Template-new(filename = 'results.tmpl');
HA:$template-param(SECRET_MESSAGE = $bar);

you should probably

print Content-type:  text/html\n\n;

here.

HA:print $template-output;
HA:
HA:
HA:
HA:This is the .tmpl file:
HA:
HA:!-- results.tmpl --
HA:html
HA:head
HA:titleUntitled Document/title
HA:meta http-equiv=Content-Type content=text/html; charset=iso-8859-1
HA:/head
HA:
HA:body bgcolor=#FF text=#00
HA:h1Hello TMPL_VAR NAME=SECRET_MESSAGE/h1
HA:
HA:/body
HA:/html
HA:
HA:
HA:
HA:When I view the source of results I see the tag TMPL_VAR
HA:NAME=SECRET_MESSAGE where I expect to see World.

are you pointing to the perl script with your browser (and not the
template file)?



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: HTTP headers

2003-01-16 Thread Philip Pawley
Thanks William,

The server is Apache. I was calling the script using an SSI in an html page:
!--#include virtual=/cgi-bin/test.cgi --

I just tried calling the script directly with the browser and that did work. I suppose 
this means that you can't alter the headers using a script called with a virtual 
include. Is that right?

Actually, this brings me to my reason for messing with HTTP headers: I want to create 
Expires: HTTP headers for the server response when it is dishing out image files 
(also for javascript and css files). Server-side includes would be no use for this 
anyway. How would I do it?

Thanks again,


At 16/01/03 11:03 -0500, William McKee wrote:
Hi Philip,

I looked at the script. How are you running it? From the command
line or from a web server? It works fine on the comand line and from the
server for me. What server are you using to display it? I'm using Apache. 

If you are running it from the server you may need to include -nph = 1 to
tell the server not to generate headers because you are doing it
yourself. I've never had a need to do this myself.

Good luck,
William

Philip Pawley


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: cgi.pm generate html vs. print EndOfHTML;

2003-01-16 Thread Hughes, Andrew
I added the content header line, and it does not work with that in there.

I am pointing to the results.tmpl file which is in the same folder as the
the .pl script.  I found another test script on the web on another website,
and I have the same problem -- the tags are not replaced with the
information in the script.  Could it be a permission issues on the .tmpl
file or the .pl file?

-Original Message-
From: fliptop [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 16, 2003 12:59 PM
To: Hughes, Andrew
Cc: '[EMAIL PROTECTED]'
Subject: RE: cgi.pm generate html vs. print EndOfHTML;


On Thu, 16 Jan 2003 at 11:49, Hughes, Andrew opined:

HA:Thanks for the feedback.  Before I get started on the html::template
HA:tutorial, I wanted to try a quick sample page using html::template.
HA:However, when I try it, I cannot get the tag in the html to process.
Could
HA:someone take a look and let me know what you think I am doing
incorrectly?
HA:
HA:my $template = HTML::Template-new(filename = 'results.tmpl');
HA:$template-param(SECRET_MESSAGE = $bar);

you should probably

print Content-type:  text/html\n\n;

here.

HA:print $template-output;
HA:
HA:
HA:
HA:This is the .tmpl file:
HA:
HA:!-- results.tmpl --
HA:html
HA:head
HA:titleUntitled Document/title
HA:meta http-equiv=Content-Type content=text/html; charset=iso-8859-1
HA:/head
HA:
HA:body bgcolor=#FF text=#00
HA:h1Hello TMPL_VAR NAME=SECRET_MESSAGE/h1
HA:
HA:/body
HA:/html
HA:
HA:
HA:
HA:When I view the source of results I see the tag TMPL_VAR
HA:NAME=SECRET_MESSAGE where I expect to see World.

are you pointing to the perl script with your browser (and not the
template file)?


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Making script case insensitive

2003-01-16 Thread Octavian Rasnita
You need to transform the variable using the lc function (or the uc).


Teddy,
Teddy's Center: http://teddy.fcc.ro/
Email: [EMAIL PROTECTED]

- Original Message -
From: Bob Williams [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, January 16, 2003 2:13 PM
Subject: Making script case insensitive


How can this script compare two lists and save the matched components while
being insensitive to case? This script compares a subscription list against
the standard list and removes the emails not in the standard list. It works,
but if cases do not match in every detail, it fails. Thanks.

%bingo_subscribers = {}; open(BINGO, $BINGO_SUBSCRIPTION_FILENAME);
while(BINGO){
  chomp($_); $bingo_subscribers{$_} = 1; } @valid_bingo_subscribers = ();
open(MASSMAIL1, $MASS_MAIL_FILENAME);
while(MASSMAIL1){   chomp($_);
($user_email, $user_name) = split(/:/, $_);
  if ($bingo_subscribers{$_} == 1)  {push(@valid_bingo_subscribers,
$user_email);  }
} open(BINGO_VALID, $VALID_BINGO_SUBSCRIPTION_FILENAME);
foreach $valid_subscriber (@valid_bingo_subscribers)
{  print BINGO_VALID $valid_subscriber .\n; }


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: newbie need help

2003-01-16 Thread Glynn S. Condez
From: Laird Shaw [EMAIL PROTECTED]

Hi Laird,

Your email help me alot on how to handle this kind of problem.
actually, i solved the problem by adding a variable and additional if:

my $see = 'N';

if ($see eq 'N') {
  if ($username =~ /\b$field2\b/) {
$see = 'Y';
}
   else{
$see = 'N';
}
}
}
if ($see eq 'Y') {
  print OK;
}
else
{
 print Please try again;
}

I tried your code and it works, thanks again.

glynn


 The problem is that it is printing something for each line regardless of
 whether it has already found a match.  What you need to do is save whether
 you have found a match or not in a variable, then selectively print, ie:
 a) set your variable to be false - ie indicating that you haven't found a
 match yet,
 b) don't print anything if a particular line doesn't match - wait until
the
 end of the loop to print that a match wasn't found (by checking that your
 variable is still false),
 c) print that you have found a match when a particular line matches, store
 in your variable that you have found a match, and then *exit the loop*
 because you don't need to check any more.

 I am not sure why you are passing in a password as you don't seem to be
 checking it anywhere.  I am assuming that $field3 is NOT the password - in
 fact I couldn't see any possible password in your file.  Are you checking
 the password at all???

 Also, I'm not sure you really want to be using the regular expression you
 are using.  If you use one at all, I would have thought you would want it
 the other way around, ie ($field2 =~ /\b$username\b/).  This means if the
 line in the file read:

 user: user1*^ realm: my.domain.com mech:PLAIN

 then entering $username='user1' would match this line.
 With your regular expression of ($username =~ /\b$field2\b/) you are
 matching
 $username='user1*^'
 to the line in the file:

 user: user1 realm: my.domain.com mech:PLAIN

 I don't know your needs but it seems to me that you would be better off
 without a regexp at all, just using ($username eq $field2).  I have
modified
 the code accordingly and put in the stuff I explained in a, b, c above
(note
 that as we are not checking password, this will only match the first
 $username found in the file):

 #!/usr/bin/perl
 use CGI qw(param);

 $username = param('username');
 $password = param('password');

 $file= /home/user/public_html/file.txt;
 print Content-type: text/plain\n\n;
 #we haven't found a match yet
 my $foundmatch=0;
 open (F1,$file);
 foreach (F1) {
   chomp;
   ($field1,$field2,$field3,$field4,$field5,$field6) = split /\s/, $_;
   if ($username eq $field2) {
 #only print when we find a match
 print OK\n;
 print $username and $password\n;
 #store that we have found a match so we don't print oops try again
at
 the end
 $foundmatch=1;
 #exit the loop as we don't need to check anymore
 last;
   }
 }
 close(F1);
 if (not $foundmatch) {
   #we didn't find a match as $foundmatch is still false
   print oops try again\n;
 }

 Glynn S. Condez [EMAIL PROTECTED] wrote:

 Hi it works now but why is it that it prints a lot of results and it
seems
 that it reads the
 file line by line and do the output. Sorry i forgot to mention that the
 file
 contains duplicate entries
 of username, it something like:
 
 snip
 user: user1 realm: my.domain.com mech:PLAIN
 user: user2 realm: my.domain.com mech:PLAIN
 user: user1 realm: my.domain.com mech: DIGEST-MD5
 user: user3 realm: my.domain.com mech:PLAIN
 user: user2 realm: my.domain.com mech:DIGEST-MD5
 ---snip---
 
 so if the file contents 10 lines of entries it display 10 lines of
output,
 here's the real output
 
 if match is found, browser prints:
 oppss try again
 OK, user1 found
 oppss try again
 oppss try again
 OK, user1 found
 oppss try again
 oppss try again
 oppss try again
 oppss try again
 oppss try again
 
 if no match found, browser prints:
 oppss try again
 oppss try again
 oppss try again
 oppss try again
 oppss try again
 oppss try again
 oppss try again
 oppss try again
 oppss try again
 oppss try again
 
 Is it possible not to display all the entry that match and doesn't match,
 just only print OK, user1 found and opps try again?
 
 what should be added or changed on the code?
 
 TIA
 glen
 
 
 
 
 
 
 
   On Wed, 15 Jan 2003 15:54:02 +0800, [EMAIL PROTECTED] (Glynn
   S. Condez) wrote:
  
   i have a web form that users can input a username and password and
 check
 if
   the username is valid by parsing or extracting the contents of a
file,
 here
   the web form html:
  
   I'm not sure what you are trying to do with just the username,
   don't you want to check the password too?
  
   #!/usr/bin/perl
   use CGI qw(param);
   
   $username = param('username');
   $password = param('password');
   
   $file= /home/user/public_html/file.txt;
   print Content-type: text/plain\n\n;
   open (F1,$file);
   foreach (F1) {
   chomp;
   ($field1,$field2,$field3,$field4,$field5,$field6) = split /\s/,