[11507] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5107 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 11 03:17:47 1999

Date: Thu, 11 Mar 99 00:00:24 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 11 Mar 1999     Volume: 8 Number: 5107

Today's topics:
    Re: Can a PARENT NOT wait on a CHILD Process? HOW? <varnavas@iname.com>
    Re: cobol line seq. file - one very long line - (Larry Rosler)
        FAQ 3.29: Where can I learn about linking C with Perl?  <perlfaq-suggestions@perl.com>
    Re: flock / sysopen / open confusion (Larry Rosler)
    Re: Help with basic perl problems. <varnavas@iname.com>
    Re: how do i format a forwarded letter (Larry Rosler)
        MAKE utility for Windows98 witless@my-dejanews.com
    Re: Missing CGI Environment Variables (Larry Rosler)
    Re: Newbie question about references/deferencing <aqumsieh@matrox.com>
    Re: Newbie question about references/deferencing <aqumsieh@matrox.com>
    Re: Ok, this is a weird phenomenon... (Larry Rosler)
    Re: perl and personal web server (Martin Vorlaender)
    Re: perl form and Netscape 4.5 problem? (Larry Rosler)
    Re: Perl scripts written for UNIX. Will they work on NT (Larry Rosler)
        perl-to-c converter for linux? Where do I find it? <sbharvey@syv.com>
    Re: Printing in Perl (Larry Rosler)
    Re: RegEx extended ASCII problem (Larry Rosler)
    Re: standard input and standard error <zenin@bawdycaste.org>
        test if a string is in an array? <dalambert@rocketmail.com>
    Re: URGENT: Problem with Bitwise AND (Larry Rosler)
    Re: URGENT: Problem with Bitwise AND <emschwar@mail.uccs.edu>
    Re: Why 'use CGI' syntax works offline but not online? (Martin Vorlaender)
    Re: Why 'use CGI' syntax works offline but not online? <emschwar@mail.uccs.edu>
    Re: Writing to a file <zenin@bawdycaste.org>
        Zero-pad an integer (Was: Re: cobol line seq. file - on (Larry Rosler)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Thu, 11 Mar 1999 02:31:02 -0500
From: Frank Varnavas <varnavas@iname.com>
To: global3@my-dejanews.com
Subject: Re: Can a PARENT NOT wait on a CHILD Process? HOW?
Message-Id: <36E77136.5BAB9EB3@iname.com>

I don't know what the 'parent' is doing after the print occurs but the
printed data may be bufferred up because:

  - you didn't set the handle to be non-bufferred
  - you didn't put a \n at the end of the data

frank v

global3@my-dejanews.com wrote:
> 
> tried using the pipe() function. Here  is the code from my script that I've
> tried without success:
> 
> $add = "title=$title&url=$url&email=$email&section=$section";
> 
> open(LPR,"|$subprog") || die "can't fork $subprog: $!\n";
> print LPR $add;
> 
> Best regards,
> Alan
> 
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own


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

Date: Tue, 9 Mar 1999 22:47:01 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: cobol line seq. file - one very long line -
Message-Id: <MPG.114fb53e432c8221989718@nntp.hpl.hp.com>

In article <1dof8zv.1bynfqe1f0ylc0N@bay2-453.quincy.ziplink.net> on Tue, 
9 Mar 1999 23:50:57 -0500, Ronald J Kimball <rjk@linguist.dartmouth.edu 
>says...
 ...
> In other words, printf "%010", $var;

You mean "%010d".  Tough night at the keyboard, Ronald?

Remember, though, that that's a 0 flag followed by a decimal number, 10;  
in other contexts, '010' represents an octal number that has the decimal 
value 8.

This particular foulness was inherited from C, where it was retained for 
backward compatibility.  I much prefer what I posted:

   '%.10d'

which has the advantage that you can also include an optional field 
width, if you wish:

   '%20.10d'

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personl/Larry_Rosler/
lr@hpl.hp.com


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

Date: 11 Mar 1999 00:16:53 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 3.29: Where can I learn about linking C with Perl? [h2xs, xsubpp]  
Message-Id: <36e76de5@csnews>

(This excerpt from perlfaq3 - Programming Tools 
    ($Revision: 1.33 $, $Date: 1998/12/29 20:12:12 $)
part of the standard set of documentation included with every 
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq3.html
if your negligent system adminstrator has been remiss in his duties.)

  Where can I learn about linking C with Perl? [h2xs, xsubpp]

    If you want to call C from Perl, start with the perlxstut
    manpage, moving on to the perlxs manpage, the xsubpp manpage, and
    the perlguts manpage. If you want to call Perl from C, then read
    the perlembed manpage, the perlcall manpage, and the perlguts
    manpage. Don't forget that you can learn a lot from looking at
    how the authors of existing extension modules wrote their code
    and solved their problems.

-- 
"Though a program be but three lines long,
someday it will have to be maintained."


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

Date: Tue, 9 Mar 1999 22:38:05 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: flock / sysopen / open confusion
Message-Id: <MPG.114fb3271be8ea3a989717@nntp.hpl.hp.com>

In article <1dof9k4.h4z98gq5cxisN@bay2-453.quincy.ziplink.net> on Tue, 9 
Mar 1999 23:50:59 -0500, Ronald J Kimball <rjk@linguist.dartmouth.edu 
>says...
 ...
> It's too late to lock the file if you've already changed the file
> contents.  Instead, you need to open the file with a mode of "+>", which
> does not clobber the file contents.

Oh, yes it does.  You meant to write "+<".

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personl/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 11 Mar 1999 02:40:18 -0500
From: Frank Varnavas <varnavas@iname.com>
To: David Dodd <honky@best.com>
Subject: Re: Help with basic perl problems.
Message-Id: <36E77362.AAEE9795@iname.com>

does it run from the command line?
is mode 750 really what you want for a cgi script?


David Dodd wrote:
> 
> Hi,
> 
> I am just starting out and can not get my first perl script running.  This
> is what I have done.
> 
>
> Set the rights on the .cgi script
> chmod 750 Test.cgi
> 
> Tried to run the script and I can not figure out how to get it to run.  Is
>


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

Date: Wed, 10 Mar 1999 08:23:08 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: how do i format a forwarded letter
Message-Id: <MPG.11503c3dbec0d53c98971a@nntp.hpl.hp.com>

In article <ebohlmanF8DxtJ.5nI@netcom.com> on Wed, 10 Mar 1999 15:32:07 
GMT, Eric Bohlman <ebohlman@netcom.com >says...
> Larry Rosler <lr@hpl.hp.com> wrote:
> : All these problems could be fixed by something like this (UNTESTED):
> 
> :   #!/usr/local/perl -w
> :   use strict;
> 
> :   my $file = 'fix-letter';
> 
> :   open FILE, "+<$file" or die "Can't open $file: $!\n";
> :   { local $/; $_ = <FILE> }
> :   s/^>//gm;
> :   seek FILE, 0, 0 or die "Can't rewind $file: $!\n";
> :   print FILE;
> :   close FILE;
> 
> That will leave junk at the end of the file, since the new contents will 
> be shorter than the old contents.  trunc(FILE,0) before the seek should 
> fix that.

I said that the code was UNTESTED, didn't I?  :-)

But so is your correction.

  truncate FILE, 0 or die "Can't truncate $file: $!\n";

Unlike Unix-derived C, where the system call 'create' is spelled 
'creat', in Perl the system call 'truncate' is spelled 'truncate'.  And 
all system calls should be checked for success.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personl/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 11 Mar 1999 07:26:10 GMT
From: witless@my-dejanews.com
Subject: MAKE utility for Windows98
Message-Id: <7c7r6c$cch$1@nnrp1.dejanews.com>

I come acros an Perl installation module with the following installation
instructions:

   gunzip <Net_SSLeay.pm-1.03.tar.gz | tar xvf -
   cd Net_SSLeay.pm-1.03
   ./Makefile.PL -t     # builds and tests it
   make install         # You probably have to be root to do this
   perldoc Net::SSLeay  # optional, but highly recommended

Where can I get the 'make' utility to execute the 'make install' line? I am
using Windows98 and ActiveState Perl.





-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Wed, 10 Mar 1999 14:54:53 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Missing CGI Environment Variables
Message-Id: <MPG.1150981afc5a02e098971c@nntp.hpl.hp.com>

In article <36E6A053.C849BC32@atrieva.com> on Wed, 10 Mar 1999 08:39:47 
-0800, Jerome O'Neil <jeromeo@atrieva.com> says...
 ...
> Here is a  less verbose method.
> 
> foreach(keys(%ENV)){
> 	print $_, q{=}, $ENV{$_}, qq{\n};
> }
> 
> Saves many keystrokes, and is guaranteed to show you exactly what's in
> %ENV.

Well, I would save even more keystrokes this way (but I would add the 
'sort' for sanity):

  print map "$_=$ENV{$_}\n", sort keys %ENV;

-- 
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 10 Mar 1999 18:09:01 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Newbie question about references/deferencing
Message-Id: <x3yyal5djsi.fsf@tigre.matrox.com>


sstark@informix.com (Scott Stark) writes:

> 
> I'm a newbie learning about references, and I'm having trouble
> passing a value 
> from a subroutine using references. I'm not sure what I've done wrong here.

Have you read perlref ? If not, you should.

> Here's a code snippet:
> 
> 	&check_flags2(\$preserve);
> 	print "The value of preserve is " . ${$preserve} . ".\n";
> 
> 	sub check_flags2 {
> 	 my($preserveP)=@_;
> 	 $$preserveP=1;
> 	}
> 
> When I run it I get the following message (line 20 is the print line):
> 
>  	Can't use string ("1") as a SCALAR ref while 
> 	"strict refs" in use at getargsP.pl line 20.

Ok .. here you don't give us too much information, but I can (almost)
see your problem. $preserve is a scalar. It is not a reference to a
scalar. But you attempt to treat it as so.

When you call &check_flags2, you pass a reference to $preserve. Since
you modify what the reference points to, you actually modify
$preserve, making it 1.

In the print statement, you are treating $preserve (which now has the
value of 1) as a reference to a scalar. From the code you give,
$preserve is not a reference. So Perl complains.

If there is something else (perhaps in a code that you didn't post)
you think can shed more light on the problem, then please let us know
more.

But, my suggestion for you at this point is to read perlref thoroughly
and rethink your strategy.

HTH,
Ala



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

Date: Wed, 10 Mar 1999 18:33:26 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Newbie question about references/deferencing
Message-Id: <x3yww0oex89.fsf@tigre.matrox.com>


Jay Glascoe <jglascoe@giss.nasa.gov> writes:

[snip]

> >         print "The value of preserve is " . ${$preserve} . ".\n";

[snip]

> >         The value of preserve is .
> 
> interesting.  You must have captured the text "." using
> a regular expression earlier?

Nope .. it is part of the print statement (see above). $1 is actually
undefined.



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

Date: Wed, 10 Mar 1999 17:37:37 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Ok, this is a weird phenomenon...
Message-Id: <MPG.1150be359b2cbf4998971d@nntp.hpl.hp.com>

In article <7c6ea6$psr$1@engnews2.Eng.Sun.COM> on 10 Mar 1999 18:40:06 
GMT, Nobody <nobody@dewpoint.eng.sun.com >says...
 ...
> 10	sub first_step;
                    ^
> 11	{
> 12	        printf("You're in first_step routine.\n");
> 13	}
 ...
> 	Undefined subroutine &main::first_step called at weird line 7.
 ...
> Why is this happening?  What is wrong with the "first_step" subroutine?  This
> is definitely weird.

There is no subroutine body for sub first_step, just a declaration of 
its name.

Even using '-w' and 'use strict;' wouldn't have helped, just sharper 
eye-ball debugging.  But use them anyhow in the future!

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personl/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 11 Mar 1999 06:15:41 +0100
From: martin@RADIOGAGA.HARZ.DE (Martin Vorlaender)
Subject: Re: perl and personal web server
Message-Id: <36e7517d.524144494f47414741@radiogaga.harz.de>

J. Parsons (gsx97@usa.net) wrote:
: That registry entry should read  "c:\perl\bin\perl.exe %s%s"

Make that

  c:\perl\bin\perl.exe -w "%s" "%s"

Quoting covers any blank-in-filepath issues.

Possibly add -T.

cu,
  Martin
--
                        | Martin Vorlaender | VMS & WNT programmer
 VMS is today what      | work: mv@pdv-systeme.de
 Microsoft wants        |       http://www.pdv-systeme.de/users/martinv/
 Windows NT 8.0 to be!  | home: martin@radiogaga.harz.de


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

Date: Tue, 9 Mar 1999 23:03:47 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: perl form and Netscape 4.5 problem?
Message-Id: <MPG.114fb92f3c26b61c989719@nntp.hpl.hp.com>

In article <36DE9822.9F9F32E5@lovergirl.com> on Thu, 04 Mar 1999 
22:26:42 +0800, Yule Show <webmaster@lovergirl.com >says...
> Try convert first three line to:
> print (".....\n\n");
> I tryed, it is ok.
> yours Yule Show
> 
> Clay Irving wrote:
> > On Tue, 23 Feb 1999 18:50:56 -0800, Bill Bukowski wrote:
 ...
> > >   print "Content-Type: text/html";
> > >   print "\n";
> > >   print "\n";

Assuming the '.....' in your suggestion is 'Content-type: text/html', it 
makes absolutely no difference whether the two succeeding new-lines are 
issued in the same or in succeeding print statements.  Sorry...

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personl/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 10 Mar 1999 21:35:52 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Perl scripts written for UNIX. Will they work on NT?
Message-Id: <MPG.1150f613d18afc7d989720@nntp.hpl.hp.com>

In article <36E68C16.7D786A6A@ford.com> on Wed, 10 Mar 1999 10:13:26 -
0500, Clinton Pierce <cpierce1@ford.com >says...
 ... 
> If the perl scripts are well written, only very small changes might be
> needed.  Such as, anywhere you do pathname manipulation (because your
> separator changes from "/" to "\").  There's even portable ways of doing
> this, because you can query Perl for the OS's pathname separator (use Config
> I think).

Ignore this advice.  Do not use '\' as the pathname separator.  It is 
error-prone and unnecessary.

> > or is as simple as changing the file names/references?
> 
> If they're well written, it should be simple, even transparent.

Unnecessary for relative paths; easily localizable for absolute paths.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personl/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 11 Mar 1999 06:26:51 +0000
From: Scott Harvey <sbharvey@syv.com>
Subject: perl-to-c converter for linux? Where do I find it?
Message-Id: <36E7622A.6D76F965@syv.com>

Hello,

I am just getting involved with perl.  Where can I get a hold of
perl-to-c module.  The version of perl I have is  5.004_04.  I tried
running the command perl -M0=C test.pl > test.c.  This did not work.
If this option/module is not available  how do you compile perl into
machine executable form?

Scott Harvey



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

Date: Wed, 10 Mar 1999 20:48:49 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Printing in Perl
Message-Id: <MPG.1150eb0c4e8dae0d98971f@nntp.hpl.hp.com>

In article <36e9d863.2049032@news.skynet.be> on Wed, 10 Mar 1999 
20:57:00 GMT, Bart Lateur <bart.lateur@skynet.be >says...
> Larry Rosler wrote:
> 
> >Why 'a seriously outdated concept'?
> 
> Because it looks so unprofessional. Unreadable. If books were printed in
> fixed pitch font, people would read A LOT less than they do now.

But we read programs here, not books.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personl/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 10 Mar 1999 20:44:44 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: RegEx extended ASCII problem
Message-Id: <MPG.1150ea11dea9496698971e@nntp.hpl.hp.com>

[Posted and a courtesy copy sent.]

In article <7c6lhm$blf$1@nnrp1.dejanews.com> on Wed, 10 Mar 1999 
20:43:36 GMT, desprem@statcan.ca <desprem@statcan.ca >says...
 ...
> $TestString = "L'Idifice gouvernementale";
> $TestString =~ /\bIdifice\b/;     # Match 1
> $TestString =~ /Idifice\b/;       # Match 2
> $TestString =~ /\bdifice\b/;      # Match 3
> 
> Oddly enough, match 1 fails. This is my problem.
> Match 2 succeeds, as expected.
> Match 3 also succeeds. Also very odd (in least to me).
> 
> There's never a problem when the accented character is not the first character
> of the string (for example, maching for "rialiti" works fine).

>From perlre:

A word boundary (\b) is defined as a spot between two characters that 
has a \w on one side of it and a \W on the other side of it (in either 
order), counting the imaginary characters off the beginning and end of 
the string as matching a \W.

    \w  Match a "word" character (alphanumeric plus "_")
    \W  Match a non-word character

If use locale is in effect, the list of alphabetic characters generated 
by \w is taken from the current locale. See the perllocale manpage.

___

As you are not using 'use locale;' the \w characters are (only)
[a-zA-Z0-9_], so \b is working as documented.  You might try using a 
French locale to get the behavior you want.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personl/Larry_Rosler/
lr@hpl.hp.com


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

Date: 11 Mar 1999 05:51:42 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: standard input and standard error
Message-Id: <921131760.884220@thrush.omix.com>

[posted & mailed]

Chim Kin Sang <mecks@ust.hk> wrote:
: The problem I engaged is that when I am using the command system. I cannot
: put the standard output and standard error into the same file. for
: example, C-shell handle it by something.exe >&! outfile
:         Can anyone tell me how PERL handle the same thing. I am new to
: PERL.

	Perl calls system() stuff using /bin/sh not C-shell (be thankful,
	really).

	system ("some_command > outfile 2>&1");

	See `man sh'

-- 
-Zenin (zenin@archive.rhps.org)           From The Blue Camel we learn:
BSD:  A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts.  Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.)  The full chemical name is "Berkeley Standard Distribution".


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

Date: 11 Mar 1999 07:21:26 GMT
From: "David Lambert" <dalambert@rocketmail.com>
Subject: test if a string is in an array?
Message-Id: <7c7qtm$8jo@bgtnsc03.worldnet.att.net>

What is the most efficient way to test for the occurrence of a string in an
array?  I want to use an if statement to take some action if the value of
$hostname is anywhere in an array called @etchosts, which was input from the
file /etc/hosts and looks like a typical /etc/hosts file.

Thanks,
David Lambert





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

Date: Wed, 10 Mar 1999 14:07:48 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: URGENT: Problem with Bitwise AND
Message-Id: <MPG.11508d0a725994ea98971b@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <7c65uk$snh$1@nnrp1.dejanews.com> on Wed, 10 Mar 1999 
16:17:35 GMT, slamda@hotmail.com <slamda@hotmail.com> says...
+ I'm using hashtables to store both namedata and mask data which I then
+ AND together.
+ 
+ However - when I do this I get the unexpected results of producing
+ zero's...i.e some sample output from my script:
+ 
+ CLUB: Fencing Club FIELD :activity DATA: 2368 MASK: 2048 R: 0
+ 
+ Now output shown is simply the result of...
+ 
+     $r=($clubdata{'Fencing Club'} & $mask{'activity'});
+ 
+ which equates to 2368 & 2048 ....which should yield 2048 not 0 - my
+ results are the same whatever field/mask combinations are used.
+ 
+ I have a sneaking suspicion that the hashtable's are not storing my
+ values as numbers and hence my bitwise AND is being performed on
+ strings?
+ 
+ Can anybody help me - i need the bitwise and to be done on the NUMBERS
+ stored in the hashtable NOT on the numbers as strings!?

>From your code, it would appear that they should be stored as numbers.  
However, to ensure that the AND operation takes place on numbers, force 
them to be numbers:

      $r = ($clubdata{'Fencing Club'} + 0) & ($mask{'activity'} + 0);

+ ####### FULL CODE HERE #################################

Much too full!  A little snippet of the data would have served as well.
 
+ #!/usr/bin/perl

Use '-w'.  You will find out if any non-numerical entries get added to 0 
in the above statement.

 ...

+ $clubdata{"Canoeing Club"}=61056;

These would be much easier to understand and maintain if you replaced 
the decimal values by the sums or ors of octal or hex values for each of 
the bits you want to set.

 ...
+ print("Content-type: text/html\n\n"); print"<html><body>"; foreach 
$clubname
+ (keys(%clubdata)) {  ##iterate through clubnames  foreach $fieldname
+ (keys(%mask)) {  ##iterate through fields to mask 
+ $result=($clubdata{$clubname} & $mask{fieldname});  print("CLUB: 
$clubname
+ FIELD :$fieldname DATA: $clubdata{$clubname} MASK: $mask{$fieldname} 
R:
+ $result\n");  }  } #@hello=$query->param; #print join("<br>",@hello);
+ print"</body></html>";

This formatting is illegible.  I assume your code doesn't look that way, 
and that this is just an artifact of posting.

-- 
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 10 Mar 1999 15:08:47 -0700
From: Eric The Read <emschwar@mail.uccs.edu>
Subject: Re: URGENT: Problem with Bitwise AND
Message-Id: <xkfzp5lj8uo.fsf@valdemar.col.hp.com>

slamda@hotmail.com writes:
> However - when I do this I get the unexpected results of producing
> zero's...i.e some sample output from my script:
>
> CLUB: Fencing Club FIELD :activity DATA: 2368 MASK: 2048 R: 0
> 
> Now output shown is simply the result of...
> 
>     $r=($clubdata{'Fencing Club'} & $mask{'activity'});
>
> I have a sneaking suspicion that the hashtable's are not storing my values as
> numbers and hence my bitwise AND is being performed on strings?

I have a sneaky suspicion that something's wrong in your code.  Perl
converts between numbers and strings as appropriate.  The only time you
should care is deciding when to use == or eq.

> Can anybody help me - i need the bitwise and to be done on the NUMBERS stored
> in the hashtable NOT on the numbers as strings!?

It is-- but you're not giving it the right numbers.

> #!/usr/bin/perl

tsk, tsk.  No -w.  Or "use strict".  Consider these mandatory.  Use them
in all your programs, *especially* CGIs.  If you had, you would have
seen something interesting, namely:

Use of uninitialized value at /tmp/foo.perl line 66.

> print("Content-type: text/html\n\n"); print"<html><body>"; foreach $clubname
> (keys(%clubdata)) {  ##iterate through clubnames  foreach $fieldname
> (keys(%mask)) {  ##iterate through fields to mask 
> $result=($clubdata{$clubname} & $mask{fieldname});  print("CLUB: $clubname
> FIELD :$fieldname DATA: $clubdata{$clubname} MASK: $mask{$fieldname} R:
> $result\n");  }  } #@hello=$query->param; #print join("<br>",@hello);
> print"</body></html>";

This mess is not only unreadable, it's unparseable.  Please watch your
cut and paste next time.  The relevant line 66, after I cleaned it up is: 

foreach $fieldname (keys(%mask)) {
        ^^^^^^^^^^
    $result=($clubdata{$clubname} & $mask{fieldname});
                                          ^^^^^^^^^
 .
 .
 .
}

I do not think you are indexing based on what you think you are indexing
based on.

In general, whenever you think something is wrong with the way perl is
handling your data, using '-w' and "use strict" will show you where you
made the mistake.  I can count on the fingers of my left foot the number
of times perl has been responsible for this sort of thing.

-=Eric


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

Date: Thu, 11 Mar 1999 04:52:09 +0100
From: martin@RADIOGAGA.HARZ.DE (Martin Vorlaender)
Subject: Re: Why 'use CGI' syntax works offline but not online?
Message-Id: <36e73de9.524144494f47414741@radiogaga.harz.de>

Changheng Du (duch@cig.mot.com) wrote:
: My CGI scripts once worked with 'use my_needed_mod'. However recently
: they work offline but not online. 'Server Error' message will generate
: when using Online.

1. See the please-don't-be-offended-by-the-name "Idiot's Guide to
   Solving Perl CGI Problems" document at CPAN,
   http://www.perl.com/CPAN/doc/FAQs/cgi/idiots-guide.html

2. Check the webserver's error log to see what causes the 'Server Error'.

3. Put a line "use CGI::Carp qw(fatalsToBrowser);" right after the shebang
   line at the top of your script. That way, all errors generated by the
   script will show up in the browser.

cu,
  Martin
--
                        | Martin Vorlaender | VMS & WNT programmer
 VMS is today what      | work: mv@pdv-systeme.de
 Microsoft wants        |       http://www.pdv-systeme.de/users/martinv/
 Windows NT 8.0 to be!  | home: martin@radiogaga.harz.de


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

Date: 10 Mar 1999 16:40:28 -0700
From: Eric The Read <emschwar@mail.uccs.edu>
Subject: Re: Why 'use CGI' syntax works offline but not online?
Message-Id: <xkfww0okj6b.fsf@valdemar.col.hp.com>

Changheng Du <duch@cig.mot.com> writes:
> I want to know this is due to Web server or 'use module' or both
> interact?

What are the error messages in your web server's error log?  In general,
if something works from the command-line, but not when invoked by CGI,
then the problem is *usually* in the web server's configuration.  If you
post your error messages, and the code that generates them, we will be
better able to help you.

-=Eric


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

Date: 11 Mar 1999 05:57:11 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Writing to a file
Message-Id: <921132089.853475@thrush.omix.com>

[posted & mailed]

Mark D. Sholund <msholund@bigfoot.com> wrote:
: I just tried this and it prints error everytime (I am setting
: $bookLocation to an existing file).

	What is the error?

: The way he tried to open the file (+>) is the correct way for reading and
: writing to the file.

	+> == O_RDWR | O_TRUNC | O_EXCL

	Notice that O_TRUNC flag there.  It says "as soon as you open this
	file, nuke any and all data that is contained in it".

	Since he said, "I tried to open a file for writing. The unfortunate
	result is always that the entire file is erased", I assumed he
	didn't want to be using a file open option that explicitly nuked
	his data when he used it.

	If he wants to keep his data, +> is not what he wants to use.

: Reading and writing to a file at the same time can get a bit tricky
: however as this example seems to prove.

	True, but the first part of his problem is simply not nuking his
	data upon open as +> does.

-- 
-Zenin (zenin@archive.rhps.org)           From The Blue Camel we learn:
BSD:  A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts.  Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.)  The full chemical name is "Berkeley Standard Distribution".


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

Date: Tue, 9 Mar 1999 20:35:29 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Zero-pad an integer (Was: Re: cobol line seq. file - one very long line -)
Message-Id: <MPG.114f966930bd2723989716@nntp.hpl.hp.com>

In article <36E58224.77AC8FA6@ix.netcom.com> on Tue, 09 Mar 1999 
14:18:44 -0600, Dale Phillips <dphi@ix.netcom.com >says...
> Do happen to know how to Zero pad a $var? 
> 
> printf "%10s",$var;
> 
> where var is only 3 digits but needs to be 10 with leading zeros?

That just right-prints in a 10-character field, with leading spaces.  To 
zero-pad, you need this:

  printf '%.10d', $var;

`perldoc -f sprintf`

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personl/Larry_Rosler/
lr@hpl.hp.com


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 5107
**************************************

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