Your logic looks find, and works on my machine (although I made it command
line)

Try switching on warnings  (#!/usr/local/bin/perl -w) and use strict (use
strict;)

Probably most likely is that you script can't read the file. You should
really always check if a file has been opened successfully you've done that
in your first example, but not the CGI example.

But if you file is in the format that you describe, your code should be
working


"Jonathan Musto" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I have a simple perl script as follows which gets a users id number by
> looking in a file.  It already knows the username and uses this to
reference
> to the id.
> The file is in the format:
>
> jbloggs,101
> jdoe,103
> msmith,111
> etc...
>
> The code i'm using is:
>
> #!/usr/local/bin/perl
>
> my $hashfile = "/opt/netcool/webtop/config/cgi-bin/hl_of_user.txt";
> my $username = 'mustoj';
>
> open (USERFILE, $hashfile) || die "Couldn't open hash file: $!\n";
>
> while(<USERFILE>)
> {
> chomp;
> ($key, $data) = split /,/, $_; # or whatever you have to split on
> $userlookup{$key} = $data;
> }
>
> my $usernum = $userlookup{$username};
>
> print "User Name = $username\nUserID = $usernum\n";
> Now this works fine as a perl script, but when i put this in a perl cgi
> script and try to output the values in html the user id is blank.
> I get the output:
> User Name = mustoj User ID =
>
> Does anyone have any idea's on what could be causing this, or can anyone
> think of a more efficient way of looking up the user id from this file??
> Any help would be much appreciated, i've included the cgi script below.
>
> the url is /cgi-bin/sis_home.cgi?un=mustoj, which is how i'm passing the
> username in.
>
> #!/usr/local/bin/perl
> #
> # script name: sis_home.cgi
> #
>
>
> use CGI qw(:standard);
>
>
> my $q = new CGI;
> my $username = $q->param("un");
> open (FH,"<hl_of_users.txt");
>
>
> while(<FH>)
> {
> chomp;
> ($key, $data) = split /,/, $_; # or whatever you have to split on
> $userlookup{$key} = $data;
> }
> my $usernum = $userlookup{$username};
>
> #print the html
> print "Content-type: text/html\n\n";
> print <<__HTML__;
> <HTML>
> <HEAD>
> <TITLE>
> Simple Program
> </TITLE>
> </HEAD>
> <BODY>
> User Name = $username UserID = $usernum
> __HTML__
> print <<__HTML__;
> </BODY>
> </HTML>
> __HTML__
>
>
>
> Jonathan Musto
>
>
>
> BT Ignite Solutions
> Telephone - 0113 237 3277
> Fax - 0113 244 1413
> E-mail - [EMAIL PROTECTED]
> http://www.technet.bt.com/sit/public
<http://www.technet.bt.com/sit/public>
>
>
> British Telecommunications plc
> Registered office: 81 Newgate Street London EC1A 7AJ
> Registered in England no. 1800000
> This electronic message contains information from British
Telecommunications
> plc which may be privileged or  confidential. The information is intended
to
> be for the use of the individual(s) or entity named above. If you  are not
> the intended recipient be aware that any disclosure, copying, distribution
> or use of the contents of  this information is prohibited. If you have
> received this electronic message in error, please notify us by  telephone
or
> email (to the numbers or address above) immediately.
>
>



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

Reply via email to