[11861] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5461 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 23 04:07:22 1999

Date: Fri, 23 Apr 99 01:00:20 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 23 Apr 1999     Volume: 8 Number: 5461

Today's topics:
    Re: -n switch vs open (Ronald J Kimball)
    Re: -n vs open (Alan Barclay)
        Changing multiple lines in a file <john.wilkinson@soton.sc.philips.com>
        child's output corrupted by parent's output (Kesey)
    Re: Database file locking... <not@gonna.tell>
    Re: FAQ 3.9: Is there an IDE or Windows Perl Editor? <Philip.Newton@datenrevision.de>
    Re: FAQ 4.15: How do I find yesterday's date? <Philip.Newton@datenrevision.de>
    Re: Generating a unique string for order number (Ronald J Kimball)
    Re: Generating a unique string for order number (Bart Lateur)
    Re: Is there a shorter way? <Philip.Newton@datenrevision.de>
    Re: Is there a shorter way? <Philip.Newton@datenrevision.de>
    Re: newbie with a "howto" question (Tad McClellan)
        NN? ['Nother Newbie Question] <marksteg@teleport.com>
        Perling into Paradox .db file <winfieldh@mindspring.com>
        Problems with the connect function <jsinglet@jaguar.ir.miami.edu>
    Re: Problems with the connect function <uri@sysarch.com>
    Re: Reading in password from <STDIN> (Tad McClellan)
    Re: Reading in password from <STDIN> (Tad McClellan)
        regex: I see THAT it works, but I don't see WHY sstarre@my-dejanews.com
    Re: regex: I see THAT it works, but I don't see WHY <uri@sysarch.com>
    Re: regex: I see THAT it works, but I don't see WHY <dgris@moiraine.dimensional.com>
    Re: regex: I see THAT it works, but I don't see WHY <dgris@moiraine.dimensional.com>
    Re: regex: I see THAT it works, but I don't see WHY <uri@sysarch.com>
    Re: Sending binary values? (Neil Cherry)
    Re: Sending binary values? (Larry Rosler)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Fri, 23 Apr 1999 00:42:56 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: -n switch vs open
Message-Id: <1dqoru4.1sreyii17h3tpcN@p54.block2.tc3.state.ma.tiac.com>

James W. Sandoz <sandoz@umbc.edu> wrote:

> If I include the -n switch at the shebang line and run
>   while(<>){
>      $tot++;
>      $comments++ if m/^\s*#/;
>      $blank++ if m/^\s\n/;
>      }
> The script doesn't count the shebang line and I'm wondering why.

> from perldoc perlrun
>  -n   causes Perl to assume the following loop around your
>       script, which makes it iterate over filename arguments
>       somewhat like sed -n or awk:
>             while (<>) { ...
>               # your # script # goes # here
>             }
> I've got the 'problem' worked out, but I'm hoping someone will explain
> the difference to me.

Your script is:

    while(<>){
        $tot++;
        $comments++ if m/^\s*#/;
        $blank++ if m/^\s\n/;
    }

and you execute that with -n, which adds a while loop...
So the full Perl script being executed is:

while (<>) {
    while(<>) {
        $tot++;
        $comments++ if m/^\s*#/;
        $blank++ if m/^\s\n/;
    }
}

Do you see the problem?  The -n switch adds its own while loop to your
script.  You're providing a second, unwanted while loop.


Try this instead:

#!perl -n
$tot++;
$comments++ if m/^\s*#/;
$blank++ if m/^\s\n/;
__END__


HTH!


-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: 23 Apr 1999 02:52:10 GMT
From: gorilla@elaine.drink.com (Alan Barclay)
Subject: Re: -n vs open
Message-Id: <924835912.348195@elaine.drink.com>

In article <7fokh4$839te@umbc7.umbc.edu>,
James W. Sandoz <sandoz@umbc.edu> wrote:
>Greetings!
>I've constructed a pretty simple script that is supposed to determine
>how many code lines there are in a Perl script as opposed to comment
>lines and blank lines.
>
>If I include the -n switch at the shebang line and run
>	while(<>){
>	   $tot++;
>	   $comments++ if m/^\s*#/;
>	   $blank++ if m/^\s*\n/;
>	   }
>The script doesn't count the shebang line and I'm wondering why.
perldoc perlrun

  -n   causes Perl to assume the following loop around your
            script, which makes it iterate over filename
            arguments somewhat like sed -n or awk:

                while (<>) {
                    ...             # your script goes here
                }

Your script also includes a <>, so your program becomes

while(<>){
  while(<>){
  ...
  }
}


The first <> reads the shebang into $_.
The second <> reads the second line into $_.
you do your counting, but at this point, you've already discarded the shebang
The loop proceeds with the second <> until the end of file, correctly counting
the remainder of the lines.


BTW, your comment counter won't be accurate, while # is the most common
way to handle comments in perl, it's not the only way: e g

=for comment

this is a long comment section, which won't be included in the program, or
in pod output either.

=cut

"
This is a string comment, produces a warning if enabled, but it can also
span multiple lines, which is sometimes useful.

";


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

Date: Fri, 23 Apr 1999 07:25:20 GMT
From: John Wilkinson <john.wilkinson@soton.sc.philips.com>
Subject: Changing multiple lines in a file
Message-Id: <3720205F.B23F8F6B@soton.sc.philips.com>

Hi all,
I am a newie to this perl stuff, so excuse my ignorance.
I have a file that will need to have several lines of text changed.
I have saved the changes in a seperate file as
s/old text/new text/
as I have done in the past when I wrote this as a SED script.
I was under the impression that I could use this file and, after reading

in the file to change, operate on it with this other file  somehow.
But I cant figure out how.

I am sure there must be a better way in perl, could someone help me
please.

Thanks,
John.





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

Date: 23 Apr 1999 03:35:12 GMT
From: kesey@globe.ece.utexas.edu (Kesey)
Subject: child's output corrupted by parent's output
Message-Id: <KESEY.99Apr22223512@globe.ece.utexas.edu>

I'm seeing some odd behavior using a pipe between a child and parent
process.  My script that isolates the problem is here:

--------------------cut--------------------
#!/usr/local/bin/perl5.005

print "perl version $]\n\n";

for (1 .. 2)
{
    print "CALL $_\n";
    &forkPrintKid ();
    print "\n";
}

sub forkPrintKid
{
    print " parent_0\n";
    print " parent_1 ";

    while (my $kidString = <KID>)   # read output of last kid
    {
        print "kidString = $kidString\n";
        print "length (kidString) = ", length ($kidString), "\n";
        close KID;
    }
    print " parent_2 ";

                                    # start up new kid
    $::kidPid = open (KID, '-|');
    unless (defined $::kidPid)
    {
        die "wasn't able to fork";
    }
    unless ($::kidPid)
    {
                                    # child here
        print " kid_output ";
        exit;
    }
    print " parent_3 ";
}
--------------------cut--------------------

When I run this, I get the following output:

    perl version 5.00502
     
    CALL 1
     parent_0
     parent_1  parent_2  parent_3 
    CALL 2
     parent_0
     parent_1 kidString =  parent_1  parent_2  kid_output 
    length (kidString) = 32
     parent_2  parent_3 

Somehow the print statements of the parent are finding their way into
the output of the child.
     parent_1 kidString =  parent_1  parent_2  kid_output 
                           ^^^^^^^^^^^^^^^^^^^
I thought maybe that when printing $kidString I was also seeing the
output of a child process that hadn't died, so I also printed out the
length of $kidString, and sure enough, it had the parent's print
statements in it.

Note that the print " parent_0\n" does not appear in $kidString - only
the prints of parent_1 and parent_2.  Experimentation shows that the
newline somehow separates what finds it's way into $kidString.

Is this a bug or am I doing something wrong?

-John


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

Date: Fri, 23 Apr 1999 00:45:14 -0400
From: "Doug Crabtree" <not@gonna.tell>
Subject: Re: Database file locking...
Message-Id: <7fotqc$d8r$1@nntp8.atl.mindspring.net>

ROTFCMSCHBLOL.  Well, I got so sick of spam on an old e-mail, I don't dare
post my e-mail in any newsgroup header.  If you truly wanted to respond, you
can at:

crabtda (at) mindspring.nospam.com (make @ change and nospam -- of course).

TTFN,
Doug

Tom Christiansen <tchrist@mox.perl.com> wrote in message
news:371f7e00@cs.colorado.edu...
>
> In comp.lang.perl.misc, "Doug Crabtree" <Not@gonna.tell> writes:
> :My question is, using MLDBM, do I have to worry about two users on a
> :web site reading/writing from this file at the same time?
>
> Private reply sent via email to avoid clogging newsgroup.  Enjoy.
>
> --tom
> --
>     I'm sure that that could be indented more readably, but I'm scared of
>     the awk parser.             --Larry Wall in
<6849@jpl-devvax.JPL.NASA.GOV>




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

Date: Fri, 23 Apr 1999 08:55:35 +0200
From: Philip Newton <Philip.Newton@datenrevision.de>
Subject: Re: FAQ 3.9: Is there an IDE or Windows Perl Editor?
Message-Id: <37201967.1A6D9564@datenrevision.de>

Jonathan Stowe wrote:
> 
> Kevin Reid <kpreid@ibm.net> wrote:
> > Tom Christiansen <perlfaq-suggestions@perl.com> wrote:
> >
> >>     with a proper toolbox on the so-called copmlete system that you
> >                                              ^^^^^^^^
> 
> Yeah I dont think the toolbox includes ispell ;-}
         ^^^^

ITYM " don't " :)

HTH, HAND

Cheers,
Philip


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

Date: Fri, 23 Apr 1999 09:33:30 +0200
From: Philip Newton <Philip.Newton@datenrevision.de>
Subject: Re: FAQ 4.15: How do I find yesterday's date?
Message-Id: <3720224A.AFD3C067@datenrevision.de>

Bernie Cosell wrote:
> 
> This isn't quite correct.  There is an ugly-to-program-around problem
> dealing with daylight savings time.  The problem is fairly limited: only
> arises if you happen to be running your program right after midnight (local
> time) of the day after the change *to* daylight savings time (so it is
> daylight savings time now, but was *not* daylight savings time yesterday at
> this time).  In that case, subtracting 24 hrs from the current time will
> get you to right after 11PM *two*days*ago*, not -yesterday-.  Maybe an
> algorithm that only fails for one hour per year is "close enough"...:o)

- *two* hours per year: when you're changing *from* daylight savings time,
you might end up with today's date if you run the program very late in
the day

- not everyone switches to/from DST at midnight. 2 am is also a popular
time. When we had a similar thread a couple of weeks back, someone
posted something showing when different countries switched. All sorts
of times are actually popular.

Cheers,
Philip


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

Date: Fri, 23 Apr 1999 00:42:57 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Generating a unique string for order number
Message-Id: <1dqot69.t8cbnnj873qcN@p54.block2.tc3.state.ma.tiac.com>

Philip Newton <Philip.Newton@datenrevision.de> wrote:

> Ronald J Kimball wrote:
> > 
> > What's wrong with a simple counter?  Implement it just like a CGI
> > counter, with file locking.  You won't get repeating numbers if you
> > simply increment.  :)
> 
> Hmm, but with integers, he'll have a problem after 2^32 orders, and with
> floats, he'll get funny order numbers like 2.132e24 after a (long)
> while...

So reset the counter at midnight, and prepend the date.  :)
(Unless he plans on getting more than forty-nine thousand orders a
second. ;)  In fact, you could almost get away with resetting the
counter just once a year!

-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Fri, 23 Apr 1999 07:33:40 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Generating a unique string for order number
Message-Id: <37221c04.2512269@news.skynet.be>

Jeff Zucker wrote:

>Ronald J Kimball wrote:
>> 
>> Greg McCann <gregm@well.com> wrote:
>>> $$ (process id) - May be good concatenated with time.
>>
>> Another bad idea.  The numbers do repeat eventually.  Process ids are
>> unique, but they have a temporary lifespan.  Using them for 
>> permanently unique numbers doesn't make sense.
>
>Yes, process ids repeat, but (except in science fiction and on horribly
>misconfigured machines) time doesn't.  Two things may be submitted at
>the same time, but then their PID would be different.  Two things may be
>submitted with the same PID, but then their time would be different. So
>concatenating time and process id would give a unique id wouldn't it?

Is a PID garanteed to be unique for as long as the process runs? Or
could there possibly be an "evil twin" running around with the same ID?
I guess not. I'd rather expect the system to refuse to launch yet
another process.

In case all behaves well, just do a 

	sleep 1;

at the end of your unique-ID generating script (time+PID). That way, the
time (in seconds) will have changed before the PID is released, and
possibly gets reused.

Here's another completely differnet idea: use the size of the order log
file at the time the session is initiated -- and logged.

	Bart.


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

Date: Fri, 23 Apr 1999 09:36:05 +0200
From: Philip Newton <Philip.Newton@datenrevision.de>
Subject: Re: Is there a shorter way?
Message-Id: <372022E5.2208A68C@datenrevision.de>

Bart Lateur wrote:
> 
> pingouino@my-dejanews.com wrote:
> 
> >The best we came up with (with all unnnecessary spaces removed) was:
> >
> >perl -e'$_=$ENV{USER};print$_."x"x(6-split//)'
> 
>         perl -e "print $_=$ENV{USER},'x'x(6-length)"
                        ^
lose a space here.

Cheers,
Philip


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

Date: Fri, 23 Apr 1999 09:49:19 +0200
From: Philip Newton <Philip.Newton@datenrevision.de>
Subject: Re: Is there a shorter way?
Message-Id: <372025FE.4AB489BE@datenrevision.de>

Uri Guttman wrote:
> 
> echo '' | perl -pe '$_=sprintf"%-6s",$ENV{USER};y/ /x/'

You can save a few characters (at least on my system) with:

echo|perl -pe'$_=sprintf"%-6s",$ENV{USER};y/ /x/'

echo by itself outputs a blank line. On CP/M-descended systems, add a
dot immediately after echo: echo.|perl etc.etc.

Cheers,
Philip


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

Date: Thu, 22 Apr 1999 17:42:25 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: newbie with a "howto" question
Message-Id: <145of7.h48.ln@magna.metronet.com>

derose@my-dejanews.com wrote:

: I'm new at Perl, and don't really have the patience's to find the answers in
: my books, so I thought I would ask some experts.


   As if experts have plenty of time to read the book to you?


: I have two questions really
: 1. Is there a comparable command or module to unix's uniq?  


      perl -ne 'print unless $seen{$_}; $seen{$_}++' $file1  > $outfile


: If I were to do this in shell I would say something like:
: cat $file1 | sort | uniq > $outfile


   No UUOC's please.

   Do it with one process instead of three:

      sort -u $file1  > $outfile


: 2. Is there a module or function that will parse a line in a text file?  I
: have a file with four individual columns, and I want to read each line on at
: a time and have each word placed in an individual variable.  


   Well you kinda ought to tell us how the columns can be identified.

   Are they fixed length?   ( perldoc -f unpack )

   Are the separated by something?   ( perldoc -f split )


: If I were to do
: this in shell, I would have used awk to parse the lines.


   So write it in awk, and then run it thru a2p (awk2perl) that
   came with your perl distribution, and examine the generated
   Perl code.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 22 Apr 1999 21:38:44 -0700
From: "Mark Stegemeyer" <marksteg@teleport.com>
Subject: NN? ['Nother Newbie Question]
Message-Id: <cPST2.54891$A6.27044982@news1.teleport.com>

Geez, I hope this works. I'd hate to ask a stupid question *and* screw up my
first post.
 Step 1. Check the documentation. Did this.
 Step 2. Check DejaNews. Did this.
 Step 3. Repeat Steps 2 & 3. Did this.
 Step 4. Check relavancy of post. Did this (I think).

Can someone point me in the direction of answers to two questions? I have
checked the above sources, but can't seem to find the info I require.
Perhaps I just don't know what index listing to search?
I am using a file upload input tag to request a family photo for a genealogy
page I'm putting together. No problem the data comes to the script via a
'post' to standard $var=$in{}; notation ok, but without a name (more
importantly- without extension). How can I get a file type? I have been
successful using two upload boxes and assigning type by box, however this
seems messy and unprofessional. Also, some extended family speaks poor
English (read as: none) and a single box seems less confusing.
Second concern: One the same page I use a textarea tag to allow posters to
add a caption/ explanation to the picture. I read some months ago in
comp.perl.lang that it's possible to issue commands from inputted text, but
for the life of me can't find it now. Will someone re-post and/or explain
the ramifications and precautions I need to take to avoid this?
Using Apache server and perl 5.


  TIA - from my *entire* family!

PS- Anybody know if Randal Schwartz went to Gladstone High School? I went
there with one, but it sounds so much like a bad pick-up line I'm
embarrassed to ask him directly!




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

Date: Thu, 22 Apr 1999 23:12:44 -0400
From: "Winfield Henry" <winfieldh@mindspring.com>
Subject: Perling into Paradox .db file
Message-Id: <7foo85$v6v$1@nntp6.atl.mindspring.net>

Hi,
Could someone point me in the direction of how to access a paradox .db file
from a perl program. I'm using paradox 8. Thank you. Winfield




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

Date: Thu, 22 Apr 1999 21:03:12 -0400
From: John L Singleton <jsinglet@jaguar.ir.miami.edu>
Subject: Problems with the connect function
Message-Id: <Pine.OSF.4.05.9904222101540.28285-100000@jaguar.ir.miami.edu>






everything up to the -- connect function seems to work...
can you please help me...the program just performs a finger on a
destionation computers user.

(some things are a little out of place due to a cut-n-paste)
thanks



#!/usr/bin/perl






&GetFormInput;

#
$username = $field{'username'} ;	 
my($Server) = 'jaguar.ir.miami.edu'; 
print "Content-type: text/html\n\n";
print "<HTML>\n" ;
print "<HEAD>\n" ;
print "<TITLE></TITLE>\n" ;
print "\n" ;
print "</HEAD>\n" ;
print "<BODY BGCOLOR=FFFFFF TEXT=000000 LINK=0000FF VLINK=800080>\n" ;
print '<font face="Arial" size="2">Your selected user IS logged in. Below
you have the option to '."\n" ;
print "send them email or to send them an IM  (instant message) as they
are logged in. The\n" ;
print "IM will appear on their screen as they are working.\n" ;
print "\n" ;
print "<br>\n" ;
print "".$username."\n" ;
print "<br>\n" ;
print "<HR>\n" ;
print "<BR>\n" ;
print "<BR>\n" ;
print '<font face="Arial" size="+1">the UM IM via JSEND: (the im
sender)</font>'."\n" ;
print "<BR>\n" ;
print '<FORM  METHOD="GET"
ACTION="http://www.getfreepress.com/cgi-bin/jaguar.pl">'."\n" ;
print 'Username : <INPUT TYPE="text" NAME="user"  SIZE="15" MAXLENGTH="30"
> &nbsp Server Name: &nbsp <INPUT TYPE="text" NAME="mailServer"  SIZE="15"
MAXLENGTH="30" >'."\n" ;
print " \n" ;
print " \n" ;
print " <BR>\n" ;
print "<BR>\n" ;
print "\n" ;
print '	<CENTER><TEXTAREA  NAME="message"  ROWS="10"  COLS="50"
></TEXTAREA></CENTER><br>'."\n" ;
print "	\n" ;
print "\n" ;
print "\n" ;
print '<CENTER><INPUT TYPE="submit" NAME="submit" VALUE="submit">'."\n" ;
print '	<INPUT TYPE="reset" VALUE="Clear My Work"></CENTER>'."\n" ;
print "</FORM>\n" ;
print "<br>\n" ;
print "<br>\n" ;
print "<BR>\n" ;
print "<BR>\n" ;
print '<FORM  METHOD="GET"
ACTION="http://getfreepress.com/cgi-bin/emailer.pl">'."\n" ;
print '<font face="Arial" size="+1">EMAIL JSEND: (the
Web-emailer)</font><br>'."\n" ;
print 'TO: &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
&nbsp<INPUT TYPE="text" NAME="email"  SIZE="25" MAXLENGTH="30" ><br>'."\n"
;
print 'From: &nbsp(optional)&nbsp<INPUT TYPE="text" NAME="from"  SIZE="25"
MAXLENGTH="30" ><br>'."\n" ;
print 'Sub: &nbsp(optional)&nbsp  &nbsp<INPUT TYPE="text" NAME="subject"
SIZE="25" MAXLENGTH="30" ><br>'."\n" ;
print "\n" ;
print "<br>\n" ;
print "<BR>\n" ;
print '	<CENTER><TEXTAREA  NAME="emailtext"  ROWS="10"  COLS="50"
></TEXTAREA></CENTER><br>'."\n" ;
print "\n" ;
print '<CENTER><INPUT TYPE="submit" NAME="submit" VALUE="submit">'."\n" ;
print '	<INPUT TYPE="reset" VALUE="Clear My Work"></CENTER>'."\n" ;
print "</FORM>\n" ;
print "</font>\n" ;
print "\n" ;
print "</BODY>\n" ;

sub GetFormInput {

	(*fval) = @_ if @_ ;

	local ($buf);
	if ($ENV{'REQUEST_METHOD'} eq 'POST') {
		read(STDIN,$buf,$ENV{'CONTENT_LENGTH'});
	}
	else {
		$buf=$ENV{'QUERY_STRING'};
	}
	if ($buf eq "") {
			return 0 ;
		}
	else {
 		@fval=split(/&/,$buf);
		foreach $i (0 .. $#fval){
			($name,$val)=split (/=/,$fval[$i],2);
			$val=~tr/+/ /;
			$val=~ s/%(..)/pack("c",hex($1))/ge;
			$name=~tr/+/ /;
			$name=~ s/%(..)/pack("c",hex($1))/ge;

			if (!defined($field{$name})) {
				$field{$name}=$val;
			}
			else {
				$field{$name} .= ",$val";
				
				#if you want multi-selects to goto into an
array change to:
				#$field{$name} .= "\0$val";
			}


		   }
		}
return 1;
}



#finger protocol that works on jaguar

use Socket;
use strict;



#for the example


my($proto)      = getprotobyname("tcp")        || 6;
my($port)       = 79;
my($serverAdd) = (gethostbyname($Server));



socket(jacko, AF_INET(), SOCK_STREAM(), $proto)
    or die("socket: $!");

#my($packFormat) = 'S n a4 x8';   # Windows 95, SunOs 4.1+
my($packFormat)= 'S n c4 x8';   # SunOs 5.4+ (Solaris 2)


#printf("I am COnnecting john\n\n\n");

connect(jacko, pack($packFormat,AF_INET(), $port, "\201\253\40\12"))
   or die("connect: $!");
#printf("connected\n\n\n");



my($inpBuf) = '';


   

#send(jacko,  "-i ",0);
send(jacko,  "$username\r\n'",0 );
#read(jacko, $inpBuf,500);
recv(jacko, $inpBuf, 100000, 0);
close(jacko);
#printf("closed socket!\n\n");
#print("$inpBuf\n\n");

sub GetFormInput {

	(*fval) = @_ if @_ ;

	local ($buf);
	if ($ENV{'REQUEST_METHOD'} eq 'POST') {
		read(STDIN,$buf,$ENV{'CONTENT_LENGTH'});
	}
	else {
		$buf=$ENV{'QUERY_STRING'};
	}
	if ($buf eq "") {
			return 0 ;
		}
	else {
 		@fval=split(/&/,$buf);
		foreach $i (0 .. $#fval){
			($name,$val)=split (/=/,$fval[$i],2);
			$val=~tr/+/ /;
			$val=~ s/%(..)/pack("c",hex($1))/ge;
			$name=~tr/+/ /;
			$name=~ s/%(..)/pack("c",hex($1))/ge;

			if (!defined($field{$name})) {
				$field{$name}=$val;
			}
			else {
				$field{$name} .= ",$val";
				
				#if you want multi-selects to goto into an
array change to:
				#$field{$name} .= "\0$val";
			}


		   }
		}
return 1;
}



*-------------------------*--------------------------------------------*
* John Lawrence Singleton *                singleto@ocala.cs.miami.edu *
*  Computer Engineering   *               jsinglet@coeds.eng.miami.edu *
*   University of Miami   *               jsinglet@jaguar.ir.miami.edu *
*    (305)-689-9850       *                      johnsingleton@usa.net *
*-------------------------*--------------------------------------------*






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

Date: 23 Apr 1999 03:13:16 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Problems with the connect function
Message-Id: <x77lr3byib.fsf@home.sysarch.com>


<snip of ugly cgi program>

a few comments:

why did you post the entire program when you mention where it is
breaking. we hate to see html here (especially in mime!) but this is
almost as bad. 66 lines of print html statements. just what i need to scan.

learn about here docs (<<TOKEN).

i hate multiple print statements. why don't newbies learn string
literals first thing? what about interpolation?

this is a lovely line of code. who taught you how to append to a null string?

	print "".$username."\n" ;

use CGI ;	no more hand rolling of cgi parsing.

use IO::Socket ;

$sock = IO::Socket::INET->new( "$host:$port" );

there, %90 of you work is done for you. now go rewrite this dreck and
get a better grade. i would give you an f for not using the resources
that are out there.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Thu, 22 Apr 1999 18:45:28 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Reading in password from <STDIN>
Message-Id: <8q8of7.a98.ln@magna.metronet.com>

Tim Armbruster (t-armbruster@ti.com) wrote:

: Save this with a *.html extension, and open it in your browser:
                                                    ^^^^^^^^^^^^
                                                    ^^^^^^^^^^^^

   Uh oh, here we go again...


[snip HTML]


   Perl is not synonymous with CGI programming.

   (although CGI programming does seem to be nearly synonymous
    with Perl programming.
   )

   The original poster made no mention of even _having_
   a browser, nor of CGI, nor any mention of the WWW.

   You have answered some question other than the one that
   was asked...


: Micah G. Cook wrote in message <371F9321.672C@ic.delcoelect.com>...
: >I have looked through several man pages and dont see
: >anything in my only "Learning Perl" book.
: >I want to read in a users password from <STDIN> but
: >want to display ****'s while they type it in.
: >Right now it displays what they type. <-Bad



--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 22 Apr 1999 18:42:16 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Reading in password from <STDIN>
Message-Id: <8k8of7.a98.ln@magna.metronet.com>

Micah G. Cook (mgcook@ic.delcoelect.com) wrote:

: Is there an archive of post
: somewhere?


   http://www.dejanews.com


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Fri, 23 Apr 1999 04:09:10 GMT
From: sstarre@my-dejanews.com
Subject: regex: I see THAT it works, but I don't see WHY
Message-Id: <7forp4$t7c$1@nnrp1.dejanews.com>

Hello & salutations:

I don't understand how '?' works in a regex. The simple program below works
fine, but WHY? It seems to me intuitively that the substitution line should be
something like:

  $s1 =~ s/(\:\:(.*)\:\:)?/$h{$1}/g; # **

since the production that I'm concerned about minimizing is '::string::', not
'string'. (.*?) minimizes the chars BETWEEN the :: delimiters, which have no
ambiguity. The only ambiguity lies in the delimiters themselves- which ones to
choose (inner or outer)? The syntax (below) suggests that it minimizes the
string, not the delimiters, yet somehow it works.

Can someone please explain why? I'm pleased that it's working, but knowing why
would be every better :)

HUG,
S

  ***********************************************
#!/usr/bin/perl -w

my %h;
$h{x1}='favorite';
$h{x2}='colour';
$h{x3}='blue';

my $s='my ::x1:: ::x2:: would have to be ::x3::';
my $s1=$s;

$s1 =~ s/\:\:(.*?)\:\:/$h{$1}/g;

print "string 0 is $s\n";
print "string 1 is $s1\n";

***************************************************
 ./test.pl
string 0 is my ::x1:: ::x2:: would have to be ::x3::
string 1 is my favorite colour would have to be blue

***************************************************

** - which I realize doesn't work

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


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

Date: 23 Apr 1999 01:15:29 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: regex: I see THAT it works, but I don't see WHY
Message-Id: <x7emlbc3ym.fsf@home.sysarch.com>

>>>>> "s" == sstarre  <sstarre@my-dejanews.com> writes:

  s> Hello & salutations:

hi sara.

  s> I don't understand how '?' works in a regex. The simple program
  s> below works fine, but WHY? It seems to me intuitively that the
  s> substitution line should be something like:

  s>   $s1 =~ s/(\:\:(.*)\:\:)?/$h{$1}/g; # **

you are confusing 2 different uses of ? in regexes (and there is a
third!). the oldest use and which you are using above is a quantifier which
is equivilent to {0,1} or 0 or one of the previous things (which can be
a () thing).

the use of ? below is a quantifier MODIFIER which causes the preceding
quantifier to consume the shortest match possible (non-greedy) vs. the
normal behavior of consuming the longest (greedy) match.

  s> since the production that I'm concerned about minimizing is
  s> '::string::', not 'string'. (.*?) minimizes the chars BETWEEN the

true. otherwise the match would consume all the text until the last ::
in the string which is not what you want. you want to see a :: followed
by a string up to the next ::. so non-greedy matching on that internal
string is needed.

  s> :: delimiters, which have no ambiguity. The only ambiguity lies in
  s> the delimiters themselves- which ones to choose (inner or outer)?
  s> The syntax (below) suggests that it minimizes the string, not the
  s> delimiters, yet somehow it works.

it doesn't affect the delimiters at all. it restricts the internal
string to be as short as possible so that only a tight pair of
delimiters will be matched. it lets each of the global matches work
while the broken code above matches only one of them.

  s> $s1 =~ s/\:\:(.*?)\:\:/$h{$1}/g;

also you don't need to backwhack :. it is not special in regexes

	$s1 =~ s/::(.*?)::/$h{$1}/g;
                 ^^			starting delimiter
                    ^^^			shortest string until
                        ^^		ending delimiter

hth,

uri


-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: 23 Apr 1999 00:19:05 -0600
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: regex: I see THAT it works, but I don't see WHY
Message-Id: <m3so9r97vq.fsf@moiraine.dimensional.com>

sstarre@my-dejanews.com writes:

> I don't understand how '?' works in a regex. 

That may be, but you've also misunderstood how s/// works.  
It replaces all of the text that is matched, not just the 
part that you capture with parentheses.

Here's the expression that you expected to work-

>   $s1 =~ s/(\:\:(.*)\:\:)?/$h{$1}/g; # **

What this does is match any sequence of `::' followed by
the most characters possible followed by another `::'.
In the process it captures the entire match, including
the colons, in $1.  The characters matched by .* are
captured in $2--which you never use.  It does this 0
or 1 times.

Then the entire string that was matched is replaced
by $h{$1}.  Since your hash doesn't include keys with
colons, what was matched is replaced by nothing.

Now, even if you had used $h{$2} you'd have had a problem
because the ? is misplaced.  Uri covered this, though, so
I'm not going to make you sit through another explanation :-).

Now, the expression that does work-

>   $s1 =~ s/\:\:(.*?)\:\:/$h{$1}/g;

This matches a literal `::', followed by the smallest number
of characters possible, followed by another literal `::'.
In the process it captures the characters between the colons,
but not the colons themselves, into $1.

Then the entire string that was matched (including the colons)
is replaced by the contents of $h{$1}.  This is what you wanted
to happen.

Hope this helps you understand.

dgris
-- 
Daniel Grisinger          dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print 
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'


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

Date: 23 Apr 1999 00:32:52 -0600
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: regex: I see THAT it works, but I don't see WHY
Message-Id: <m3n1zz978r.fsf@moiraine.dimensional.com>

Uri Guttman <uri@sysarch.com> writes:

> you are confusing 2 different uses of ? in regexes (and there is a
> third!).

There are at least 5 different classes of ? use in perl regexes.

1- The simple ?
     /\?/;                    # just a ?

2- The easy to please ?
     /.?/s;                   # nothing, or a little of anything

3- The frugal ?
     /.*?./;                  # just enough to get by

4- The jack-of-all-trades ?
     /(?=.)|(?{1;}|(?:)/;     # look ma, i can do anything

5- The lazy ?
     ?.? ;                    # i'm done for the day

dgris
-- 
Daniel Grisinger          dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print 
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'


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

Date: 23 Apr 1999 02:42:49 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: regex: I see THAT it works, but I don't see WHY
Message-Id: <x7aevzbzx2.fsf@home.sysarch.com>

>>>>> "DG" == Daniel Grisinger <dgris@moiraine.dimensional.com> writes:

  DG> Uri Guttman <uri@sysarch.com> writes:
  >> you are confusing 2 different uses of ? in regexes (and there is a
  >> third!).

  DG> There are at least 5 different classes of ? use in perl regexes.

  DG> 1- The simple ?
  DG>      /\?/;                    # just a ?

not a regex metachar.

  DG> 2- The easy to please ?
  DG>      /.?/s;                   # nothing, or a little of anything

{0,1}

  DG> 3- The frugal ?
  DG>      /.*?./;                  # just enough to get by

non-greedy quantifier modifier.

  DG> 4- The jack-of-all-trades ?
  DG>      /(?=.)|(?{1;}|(?:)/;     # look ma, i can do anything

the third way i referred to, special non-grabbing () variants. or ilya's
favorite way to extend regexes.

  DG> 5- The lazy ?
  DG>      ?.? ;                    # i'm done for the day

who really uses this (it is also deprecated)? and it is not a regex
metachar but a different operator. and it is not supported for s///,
only matching.

so i still only count 3 forms of ? as a regex metachar.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Fri, 23 Apr 1999 04:50:51 GMT
From: njc@dmc.uucp (Neil Cherry)
Subject: Re: Sending binary values?
Message-Id: <slrn7hvv79.ccs.njc@dmc.uucp>

On Thu, 22 Apr 1999 17:56:14 GMT, Neil Cherry wrote:
>First I'm more of an assembly/C language hacker (working under Linux
>on an i86 box).  I have a feeling that I'm not quite undestanding one
>thing in Perl. I've tried to use pack and unpack but I have idea what
>I'm getting out of them.
>
>I have an array filled with such:
>
>$a[0] = 0x24;
>$a[1] = 0x05;
>$a[2] = 0x00;
>$a[3] = 0x01;
>
>Now if I attempt to syswrite these values out to a file I get the string:
>
>3501 (0x33 0x35 0x33 0x31)
>
>I want:
>
>!^E^@^A (that 4 character 0x24 0x05 0x00 0x01).
>
>How do I accomplish this (it's driving me nuts)?
>
>BTW I can send "!^E^@^A" but I have no idea how to create the string
>(I'm getting this from localtime and need to convert it to a string
>with a magic sequence and the the BCD rep of the time values).

First let me apologize for the double post, I'm not sure at this time
why it occured.

Second, I figured out what was going on above. It really helps to use
the correct function when writing out information. I found a
mis-whatever function (I used unpack("C", $a[$j]) instead of pack). I
guess I was just looking too hard for the problem. To make matters
worse I had the correct function in the test code. Yes the 2 code
segments were different which is why I some how made the incorrect
change.

Thank you for your attention.

-- 
Linux Home Automation           Neil Cherry             ncherry@home.net
http://members.home.net/ncherry                         (Text only)
http://meltingpot.fortunecity.com/lightsey/52           (Graphics GB)



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

Date: Thu, 22 Apr 1999 22:31:52 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Sending binary values?
Message-Id: <MPG.1189a5984c53211998991c@nntp.hpl.hp.com>

[Posted and a courtesy copy sent.]

In article <7fnr2i$mrt$24@newsread.f.de.uu.net> on 22 Apr 1999 18:50:58 
GMT, Neil Cherry <njc@dmc.uucp> says...
 ... 
> $a[0] = 0x24;
> $a[1] = 0x05;
> $a[2] = 0x00;
> $a[3] = 0x01;
 ...
> I want:
> 
> !^E^@^A (that 4 character 0x24 0x05 0x00 0x01).

my $packed = pack 'C*', @a; # or 'C4' in this case

But that produces a $ as the first character.  0x21 produces a ! .

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/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 5461
**************************************

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