[17619] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5039 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 5 18:05:59 2000

Date: Tue, 5 Dec 2000 15:05:13 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <976057513-v9-i5039@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 5 Dec 2000     Volume: 9 Number: 5039

Today's topics:
        A sort of another color -- a Tale, not a question ;) <nospam@nospam.com>
    Re: A sort of another color -- a Tale, not a question ; (Chris Fedde)
    Re: array of unique random numbers <iltzu@sci.invalid>
        Beginner's question <square-sun@terra.es>
        Can I submit the contents of a form into the same cgi s <vrdoljak@uclink.berkeley.edu>
    Re: Counting bits. <mischief@velma.motion.net>
    Re: DBI insert problem <cak@xxx.putzl.com>
        dumb question? - how do i find out current script name <tdwong@powertv.com>
    Re: dumb question? - how do i find out current script n (Tim Hammerquist)
    Re: Escape sequence \u (Tad McClellan)
    Re: form-to-mail not working properly <peter.sundstrom@eds.com>
        help getting started with Active perl win32 <people@geartechnology.com>
    Re: help getting started with Active perl win32 <flavell@mail.cern.ch>
    Re: Help with dbm locking requested (James Kufrovich)
    Re: how to call a dos excutable file by 'system'? nobull@mail.com
        how to check if there is text in an input text field? alazarev1981@my-deja.com
    Re: how to check if there is text in an input text fiel alazarev1981@my-deja.com
    Re: how to check if there is text in an input text fiel alazarev1981@my-deja.com
    Re: how to check if there is text in an input text fiel (Tad McClellan)
    Re: Perl FORMAT Into variable? <nospam.newton@gmx.li>
    Re: Perl string converter <rayers@answerlogic.com>
        perlcc static? <thijs@abzurd.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 5 Dec 2000 19:59:51 GMT
From: The WebDragon <nospam@nospam.com>
Subject: A sort of another color -- a Tale, not a question ;)
Message-Id: <90jhfn$kca$0@216.155.33.40>

Having a huge body of data along the lines of this: 
($gametype $filename $title $size $review $rating)

utassault\tas-abasery.zip\tAS-Abasery\t1218\t/nalicity/review.asp?Id=6940
\t7\n
utassault\tas-abraxasassault.zip\tAS-Abraxasassault\t1287\t/nalicity/revi
ews/as-abraxasassault.html\t8\n
utassault\tas-airportterror.zip\tAS-Airportterror\t922\t/nalicity/reviews
/as-airportterror.html\t4.5\n
utassault\tas-alcatraz.zip\tAS-Alcatraz\t378\t-1\t-1\n
utctf\tctf-airraid!.zip\tCTF-AirRaid!\t1593\t-1\t-1\n
utctf\tctf-airraid2!.zip\tCTF-AirRaid2!\t1341\t-1\t-1\n
utctf\tctf-aldenax.zip\tCTF-Aldenax\t537\t/nalicity/reviews/ctf-aldenax.h
tml\t5.5\n
utdm\tdm-monkstower.zip\tDM-Monkstower\t1205\t-1\t-1\n
utdm\tdm-monks-town.zip\tDM-Monks-Town\t523\t-1\t-1\n
utdm\tdm-moonbase.zip\tDM-Moonbase\t3137\t/nalicity/reviews/dm-moonbase.h
tml\t8\n
utdomination\tdom-anka.zip\tDOM-Anka\t533\t-1\t-1\n
utdomination\tdom-arcanetemple.zip\tDOM-Arcanetemple\t607\t-1\t-1\n
utdomination\tdom-arcturo.zip\tDOM-Arcturo\t476\t/nalicity/review.asp?Id=
6561\t7.5\n
(edited slightly -- it's tab-deliniated)

File is currently 2783 lines long

Data was/is imported into a complex hash of the form :

$master_maps_list{$gametype}{ $filename } = [$filename, $title, $size, 
$review, $rating];

I wanted to figure out how to add a sort algorithm to my cgi file that 
would allow me to sort BY rating as well as by map title (so that all 
the 7.5's wuld be sorted alphabetically for example) instead of just by 
title, as it was before. I figured this would require some sort of 
custom sort algorithm but couldn't see how this would be possible unless 
I also re-wrote the cgi to handle the html output section differently 
depending on how I wanted to sort. 

I didn't want to do that, SO I waited for inspiration. 

Then one day whilst eating my first Cajun Blackened Filet Mignon (part 
time work in a restaurant does have it's perks) and reading the 
Programming Perl book (I'm weird like that), I stumbled across this 
small passage towards the end that immediately sent a lightning bolt of 
epiphany and inspiration through my system. Chapter 8, Efficiency 
section: 

    "Sorting on a manufactured key array may be faster than using a 
fancy sort algorithm (BOOM the light went off! =:). A given array value 
may participate in several sort comparisons, so if the sortsub as to do 
much recalculation, it's better to factor out that calculation to a 
separate pass before the actual sort."

After a few postings to the MacPerl mailing list, to see whether I was 
dreaming or if my idea would actually work, we came up with the 
following.

Some code snippets:

 ...

my %replace = ();
# Nice trick, Bart :)
@replace{'a' .. 'z'} = reverse 'a' .. 'z';
@replace{'0' .. '9'} = reverse '0' .. '9';

 ...

# coerce the rating value to a special format to aid in a sort transform
sub coerce2 { sprintf '%04.1f', int(shift()*2+.5)/2 }

 ...(this section's large so you can see how the data is imported and 
perhaps give me any other pointers for shortening things, but I think I 
have it as streamlined as possible for what it does)

open(IN, "<$input_File") || die "Can't open $input_File: $!";
    chomp( @data = <IN> );  # need those parens
close IN;

my $totalcount   = 0;
my $ratedcount   = 0;
my $unratedcount = 0;
foreach (@data) {
  my($gametype, $filename, $title, $size, $review, $rating) = split /\t/;
  ++$totalcount;
  if ($rating == '-1') {++$unratedcount} else {++$ratedcount};
  $filename =~ /(.*?).zip/o;
  # I did this because the database this output is drawn from truncates 
the titles :/ and I wanted full filenames. 
  ($title = $1) =~ tr/A-Z/a-z/;
  (my $coercename = $filename) =~ tr/A-Z/a-z/;

# uses %replace hash here: * 
  $coercename =~ s/([a-z0-9])/$replace{$1}/g;
# * basically this does 
# $coercename =~ 
tr/abcdefghijklmnopqrstuvwxyz0123456789/zyxwvutsrqponmlkjihgfedcba9876543
210/;
# but in a much neater fashion and without a terrible processor time hit.
# thanks to Bart Lateur for the tip. =;)

# by making the sort keys both use $coercename, I can use the same 
# sort down below and have it still work. :-)
# This has the added benefit of forcing mapnames that begin with 
numerics and []-type characters to be sorted to the bottom in either 
case. Serves the lamers right for trying to force their maps to the top 
of the list.
  if (param() && (param('sortby') eq 'rating') ) {
      $master_maps_list{$gametype}{ &coerce2($rating) . $coercename } = 
    [$filename, $title, $size, $review, $rating];
  } else {
      $master_maps_list{$gametype}{ $coercename } = 
    [$filename, $title, $size, $review, $rating];
  }
}

 ...

# then later down in the html output section I can do this for EITHER 
kind of sort =8)

foreach my $sort_by_title ( reverse sort keys %{$master_maps_list{ 
$GameType }} ) {
    my( $file_location, $Title, $size, $review, $rating ) = 
@{$master_maps_list{ $GameType }{ $sort_by_title }};

 ... etc etc 

I don't remember which "transform" this refers to, although I can recall 
one name .. Guttman-Rosler Transform .. is that the one ? There seems to 
be yet another transform title floating around in my memory, but I can't 
recall it at the moment. Correct me if I'm wrong so I can get it 
straight :) 

SO basically, what I did was 'create a manufactured key to sort the hash 
on in a single pass, using the standard sort() function rather than a 
custom sort' which yields vastly increased sort times. Such a thing can 
be mission critical in the cases where a .cgi will be taking some 
4000-70000 hits per day. (or more) 

I hope this is helpful to anyone who is stumbling around like I was 
before the transform idea occurred to me upon reading that short 
paragraph.

-- 
send mail to mactech (at) webdragon (dot) net instead of the above address. 
this is to prevent spamming. e-mail reply-to's have been altered 
to prevent scan software from extracting my address for the purpose 
of spamming me, which I hate with a passion bordering on obsession.  


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

Date: Tue, 05 Dec 2000 20:36:14 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: A sort of another color -- a Tale, not a question ;)
Message-Id: <2lcX5.77$T3.170845184@news.frii.net>

In article <90jhfn$kca$0@216.155.33.40>,
The WebDragon  <nospam@nospam.com> wrote:
> Having a huge body of data along the lines of this: 
> ($gametype $filename $title $size $review $rating)
>
> utassault\tas-abasery.zip\tAS-Abasery\t1218\t/nalicity/review.asp?Id=6940
> \t7\n
> utassault\tas-abraxasassault.zip\tAS-Abraxasassault\t1287\t/nalicity/revi
> ews/as-abraxasassault.html\t8\n
> utassault\tas-airportterror.zip\tAS-Airportterror\t922\t/nalicity/reviews
> /as-airportterror.html\t4.5\n
> utassault\tas-alcatraz.zip\tAS-Alcatraz\t378\t-1\t-1\n
> utctf\tctf-airraid!.zip\tCTF-AirRaid!\t1593\t-1\t-1\n
> utctf\tctf-airraid2!.zip\tCTF-AirRaid2!\t1341\t-1\t-1\n
> utctf\tctf-aldenax.zip\tCTF-Aldenax\t537\t/nalicity/reviews/ctf-aldenax.h
> tml\t5.5\n
>
> [...]
>
> SO basically, what I did was 'create a manufactured key to sort the hash 
> on in a single pass, using the standard sort() function rather than a 
> custom sort' which yields vastly increased sort times. Such a thing can 
> be mission critical in the cases where a .cgi will be taking some 
> 4000-70000 hits per day. (or more) 
>
> I hope this is helpful to anyone who is stumbling around like I was 
> before the transform idea occurred to me upon reading that short 
> paragraph.
>

Do you need to sort the 'huge body of data' each time that it is
accessed?  If you write out the 'manufactured key' array as a flat
file can it be re-loaded faster than it can be regenerated?

chris
-- 
    This space intentionally left blank


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

Date: 5 Dec 2000 19:13:22 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: array of unique random numbers
Message-Id: <976039986.23027@itz.pp.sci.fi>

In article <slrn92ntqh.vnu.abigail@tsathoggua.rlyeh.net>, Abigail wrote:
>++ 
>++   sub unique_random_ints {
>++       my ($n, $lim) = @_;
>++       my (@res, %buf);
>++       while (@res < $n) {
>++           my $rn = int rand $lim--;
>++           push @res, $buf{$rn} || $rn;
>++           $buf{$rn} = $buf{$lim} || $lim;
>++       }
>++       return @res;
>++   }
>++ 
>++ There.  Both the running time and the memory usage are proportional to
>++ $n even in the worst case, and completely independent of $lim.
>++ 
>++ Should this be in the FAQ?  Can anyone suggest improvements?
>
>This works quite well, but depends heavily on the fact integers are a
>countable set. How would you do it with reals, with strings, or with
>a selector that isn't uniform?

I don't see much hope for nonuniform selectors.  The algorithm is
still a Fisher-Yates shuffle underneath, and therefore assumes a
uniform distribution.  I can think of no simple way to change that.

As for domains other than integer ranges, there are two general cases
in which most situations fall.  If the domain is conceptually finite,
one could just use the algorithm to generate a sequence of integers
and then map them to the desired domain.

On the other hand, for conceptually infinite domains, such as reals in
the range ]0,1], one could argue that the uniqueness requirement is
meaningless anyway, since even if two random floating point numbers
happen to have an identical representation, the probability that the
two "infinite precision reals" which they are supposed to approximate
would be precisely equal is still zero.

That does leave domains that are obviously finite, yet for which no
mapping from integers is known (by the programmer).  I don't think
there's any hope for those either.  FWIW, none of the other solutions
proposed handle these correctly either, though the redo-if-exists hash
solution works if the domain is a subset of all possible hash keys.

-- 
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real!  This is a discussion group, not a helpdesk.  You post
 something, we discuss its implications.  If the discussion happens to
 answer a question you've asked, that's incidental." -- nobull in clpm



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

Date: Tue, 05 Dec 2000 21:11:43 GMT
From: Nick <square-sun@terra.es>
Subject: Beginner's question
Message-Id: <F5wvK7AjAVL6Ewao@terra.es>

Is it possible to get a Perl interpreter to run on a Win98 machine so I
don't have to go online to test scripts?
-- 
   Nick
        news@square-sun.co.uk
                Chainsaw sculpture - Wooden books - Pictures    
                      http://www.square-sun.co.uk


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

Date: Tue, 05 Dec 2000 14:55:48 -0800
From: Gordon Vrdoljak <vrdoljak@uclink.berkeley.edu>
Subject: Can I submit the contents of a form into the same cgi script which  generated the form?
Message-Id: <3A2D7274.84E62568@uclink.berkeley.edu>

Hello,
I was wondering if the following is possible.  I have a form in html which
passes three values to a cgi script.  The cgi script takes these three values,
generates a table form from the values and what it reads from another text
file.  Is it possible to submit the action or results of this table form to the
same cgi script -ie another part of the program?  I tried form action =
subroutine(), but that didn't work...


-- 
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Gordon Ante Vrdoljak                                  Electron Microscope Lab
ICQ 23243541   http://nature.berkeley.edu/~gvrdolja   26 Giannini Hall
vrdoljak@uclink.berkeley.edu                          UC Berkeley
phone (510) 642-2085                                  Berkeley CA 94720-3330
fax   (510) 643-6207 cell (510) 290-6793


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

Date: Tue, 05 Dec 2000 19:25:31 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Counting bits.
Message-Id: <t2qg9bsgaivd4e@corp.supernews.com>

Tad McClellan <tadmc@metronet.com> wrote:
> Linc Madison <lincmad001@telecom-digest.zzn.com> wrote:
>>In article <e5rm2tkt122qs52aq5gl9isfnttua0htj1@4ax.com>, Bart Lateur
>><bart.lateur@skynet.be> wrote:
>>> Wolfgang Hielscher wrote:

>>> >   my $count = @{[$str =~ m/1/g]};
>>>         $count = () = $str =~ /1/g;
>>
>>Isn't it more efficient to say this instead?
>>
>>   my $count = ($str =~ tr/1/1/);

Just for Ss and Gs, I added a few things to Tad's. My results show
that a high-level language doesn't necessarily save you from yourself.
Cargo cult programming and naive implementations can kill your performance.

Although Perl can (and does) show that it optimizes certain tasks very
well, you must still keep in mind that operators are faster than
hand-rolled loops and that flipping switches on operators doesn't
always help. Use them as documented.

First run:
---------------------
Benchmark: timing 1000000 iterations of absurd, m, mo, s, sl, so, tr, tr2...
    absurd: 97 wallclock secs (97.05 usr +  0.02 sys = 97.07 CPU)
         m: 22 wallclock secs (21.31 usr +  0.00 sys = 21.31 CPU)
        mo: 21 wallclock secs (21.46 usr +  0.00 sys = 21.46 CPU)
         s: 14 wallclock secs (13.24 usr +  0.00 sys = 13.24 CPU)
        sl: 32 wallclock secs (32.25 usr +  0.00 sys = 32.25 CPU)
        so: 12 wallclock secs (13.33 usr +  0.00 sys = 13.33 CPU)
        tr:  3 wallclock secs ( 3.15 usr +  0.00 sys =  3.15 CPU)
       tr2:  2 wallclock secs ( 3.00 usr +  0.00 sys =  3.00 CPU)
---------------------


Second run:
---------------------
Benchmark: timing 1000000 iterations of absurd, m, mo, s, sl, so, tr, tr2...
    absurd: 98 wallclock secs (97.13 usr +  0.01 sys = 97.14 CPU)
         m: 21 wallclock secs (21.29 usr +  0.00 sys = 21.29 CPU)
        mo: 22 wallclock secs (21.41 usr +  0.00 sys = 21.41 CPU)
         s: 13 wallclock secs (13.26 usr +  0.00 sys = 13.26 CPU)
        sl: 31 wallclock secs (32.25 usr +  0.00 sys = 32.25 CPU)
        so: 14 wallclock secs (13.35 usr +  0.00 sys = 13.35 CPU)
        tr:  3 wallclock secs ( 3.19 usr +  0.00 sys =  3.19 CPU)
       tr2:  3 wallclock secs ( 3.02 usr +  0.00 sys =  3.02 CPU)
---------------------


Now, in case you were wondering, here's the code that brings up the
funny numbers:
---------------------
#!/usr/bin/perl
use Benchmark;

sub test($) {
    my @x = split(//, shift);
    my $y = 0;
    foreach my $x (@x) {
        $y++ if $x;
    }
    return $y;
}

$str = '10101100';

timethese 1_000_000, {
   m      => q( my $count = () = $str =~  m/1/g     ; ),
   mo     => q( my $count = () = $str =~  m/1/go    ; ),
   s      => q( my $count =      $str =~  s/1/1/g   ; ),
   so     => q( my $count =      $str =~  s/1/1/go  ; ),
   sl     => q( my $count = @{[  $str =~  m/1/g   ]}; ),
   tr     => q( my $count =      $str =~ tr/1//     ; ),
   tr2    => q( my $count =      $str =~ tr/1/1/    ; ),
   absurd => q( my $count =      &test($str)        ; )
};
---------------------

Okay, so the case of 'absurd' is a bit contrived, but it's no worse
than a character-by-character search on sorted data where binary search
would work (or character-by-character search against text where Boyer-Moore
or some derivation of it would work). Please figure out which data
structures and algorithms work best for you problem. Then figure out how
best to implement them, if there is a chance for this kind of discrepency.
The Benchmark module is your friend.

Chris
--
Christopher E. Stith - mischief@velma.motion.net



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

Date: Tue, 05 Dec 2000 13:41:26 -0800
From: Chris Kantarjiev <cak@xxx.putzl.com>
Subject: Re: DBI insert problem
Message-Id: <3A2D6106.BFF1EAEF@xxx.putzl.com>

John wrote:
> 
> Hi all:
> 
> I am using DBI to write a database program.
> I have prepared an insert SQL command.
> The target database is MS Access.
> Database driver is DBD::ODBC.
> One field of the table is of the type 'memo'.
> When I insert a long string(about 300 characters) into this field, I get an
> error.
> But when I use do to insert the same data, I succeed.
> Everything is ok with short strings.
> WHY?
> 
> Thanks in advance.
> 
> John Hsieh
> john@imining.com.tw

Access doesn't like fields that are more than 255 characters in size.
--
		      Remove xxx. to reply ...
	  Don't just sit there reading news: get active!
http://www.earthjustice.org/join/  http://www.yosemitevalley.org
			http://www.heifer.org


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

Date: Tue, 5 Dec 2000 14:08:29 -0800
From: "David Wong" <tdwong@powertv.com>
Subject: dumb question? - how do i find out current script name
Message-Id: <90jp0v$4jb$1@nntp1.ba.best.com>

Hi there,

This is could be a dumb question, but I have looked all over the place 
and cannot find an answer.

In a perl script, how do I find out the current script name?

In other shell scripting languages, such as sh, csh, ksh, or bash, 
argv[0] is always reserved as the script name.  Same holds true for C, 
C++, and java.  But not for perl 8-(.

I really want to be able to say "Usage: $progname [blah blah blah]" 
without hardcoding the script name inside the script.

How can I achieve this?

Please send your response to tdwong@yahoo.com.  TIA!!!


David <wong>



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

Date: Tue, 05 Dec 2000 22:15:39 GMT
From: tim@degree.ath.cx (Tim Hammerquist)
Subject: Re: dumb question? - how do i find out current script name
Message-Id: <slrn92qqoc.tl0.tim@degree.ath.cx>

David Wong <tdwong@powertv.com> wrote:
> In a perl script, how do I find out the current script name?
> 
> In other shell scripting languages, such as sh, csh, ksh, or bash, 
> argv[0] is always reserved as the script name.  Same holds true for C, 
> C++, and java.  But not for perl 8-(.

This has been roughly translated in Perl to $0 (that's a zero).

eg:

	print "Usage: $0 [options]\n" unless @ARGV;

-- 
-Tim Hammerquist <timmy@cpan.org>

The little I know I owe to my ignorance.
	-- Sacha Guitry


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

Date: Tue, 5 Dec 2000 12:44:42 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Escape sequence \u
Message-Id: <slrn92qaca.o18.tadmc@magna.metronet.com>

twa_web_man@yahoo.com <twa_web_man@yahoo.com> wrote:

>Can someone please give me a concrete example of how and when to
>correctly add the \u escape sequence to make the first character of a
>string Uppercase?
>
>Here is where I have it now (within a "print" statement):
                              ^^^^^^^^^^^^^^^^

That is irrelevant.

What matters is that it is within a "double quotish" context,
since backslash escapes only happen in double quoted strings.


>color\=\"#000033\">\L\u$wind_data\E

>color\=\"#000033\">\u$wind_data

>                        $wind_data = \u$wind_data
                                      ^^
                                      ^^

That is not a backslash escape (because it is not in double quotes
where they are defined). But you could do this instead:

   $wind_data = ucfirst $wind_data



There is no need to clutter everything up with all that other
stuff not germane to your problem. Many will just move on
rather than try and figure it all out.

If you had instead reduced it to a short and complete program
that people could run, then you have a much better chance of
not being ignored:

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

my $wind_data = 'blow the man down';

print "\L\u$wind_data\n";
print "\u$wind_data\n";
----------------------

Those both work fine for me.


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


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

Date: Wed, 6 Dec 2000 09:55:18 +1300
From: "Peter Sundstrom" <peter.sundstrom@eds.com>
Subject: Re: form-to-mail not working properly
Message-Id: <90jknq$bkc$1@hermes.nz.eds.com>


Jody Fedor <Jodyman@usa.net> wrote in message
news:90i5ge$q0i$1@plonk.apk.net...
>
> Mercille wrote in message <3A2C7A23.A947F4@videotron.ca>...
>
> >$recipient = 'fmercille@videotron.ca';
>
>  You must escape @ like you did below:  fmercille\@videotron.ca

Only if it is in double quotes.




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

Date: Tue, 05 Dec 2000 14:25:29 -0800
From: Dan Mackenzie <people@geartechnology.com>
Subject: help getting started with Active perl win32
Message-Id: <3A2D6B59.47E903F5@geartechnology.com>

Hi I am new with perl and have recently downloaded Active
Perl-5.6.0.620-MS WIN32-x86. I have been writing scripts for the web
like the one below. I have been uploading and testing them on my server
(UNIX). then making changes and uploading again. I want to be able to
write and test them on my computer.

What do I put for the #!/usr/local/bin/perl should I put C:/perl/bin or
is the a different way I should start my script? Does anyone know where
I can find simple examples of scripts writen for win32? Any help would
be great.

Thanks Dan

#!/usr/local/bin/perl

if ($ENV{'REQUEST_METHOD'} eq "GET") { $buffer = $ENV{'QUERY_STRING'}; }

else { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); }
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $FORM{$name} = $value;
$cat = $FORM{'category'};
}
$correcturl = "http://www.my_page.com/copage/$cat";
if($cat eq "none.htm") {
   &All;
}
else {&goto_url;
}
exit;

#####subs Go Here###

#####sub for individual companys###

sub goto_url {

    print "Location: $correcturl\n\n";
}
#####sub to list all companies####
sub All{

print "Content-type: text/html\n\n";
open (comp,"leads.txt");
@ary=<comp>;
close(comp);

#####open top half of web page to be displayed########
  open(INF,"page.htm");
  @page = <INF>;
  close(INF);
  print "@page";
##### print out middle half of url then end part of url###
print "<b><font size=+1>Companies</font></b><br><br>";
foreach $line (@ary) {
    chomp($line);
    ($bingo,$company,$contact,$email,$location,$url) =
split(/\|/,$line);
       if ($bingo < 900) {
            print "<A href='http://www.mysite.com/copage/$url'>";
            print "$company </A><B> $location</B><br>";
       }
}

print "</tr></tr></table></body></html>";




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

Date: Tue, 5 Dec 2000 21:43:33 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: help getting started with Active perl win32
Message-Id: <Pine.GHP.4.21.0012052130310.13904-100000@hpplus03.cern.ch>

On Tue, 5 Dec 2000, Dan Mackenzie wrote:

> #!/usr/local/bin/perl

Bzzt!  Howe about some options...?

> if ($ENV{'REQUEST_METHOD'} eq "GET") { $buffer = $ENV{'QUERY_STRING'}; }

have you considered using a peer-reviewed module?

> else { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); }

Looks awfully familiar.

I'd say your first priority is to follow the advice that is frequently
offered on this group by a hard core of reliable informants.

As for your specific question:

The Apache server honours the shebang line, even under Win32,
so use the path to whereever you installed Perl.  Installing it under
/usr/local/bin could make cross-platforming even easier.

If you're not using Apache then ...[why not?]... YMMV.

But don't omit the -wT and the "use strict;", at least while
debugging, or you're toast here.

What to do with those options when you've debugged the scripts is a
different question.  You might want to review Deja for the earlier
discussions on that.

[much clutter omitted]

When you understand as much about this as some people I've read here,
you might be ready to not use CGI.pm, as long as you know why you're
doing it.  I don't think I am ready, and I'm pretty sure you're not.

And _do_ find out about Here-documents, they can make life a lot more
comfortable when you're generating boilerplate HTML.

good luck

Erm, no offence meant, but where are you getting this cargo stuff
from?  It might be useful to warn others against it.




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

Date: Tue, 05 Dec 2000 22:24:22 GMT
From: eggie@REMOVE_TO_REPLYsunlink.net (James Kufrovich)
Subject: Re: Help with dbm locking requested
Message-Id: <slrn92qqus.ire.eggie@melody.mephit.com>

On Mon, 04 Dec 2000 22:51:40 GMT, James Kufrovich
<eggie@REMOVE_TO_REPLYsunlink.net> wrote:

>Hi.
>
>        I'm having a slight problem with file locking.  I'm writing a CGI
>script that has to access a dbm file (MLDBM, since I'm storing complex
>records), and would like to make sure it's locked exclusively whenever
>someone accesses it, or at least when someone writes to it.  But, I can't
>for the life of me figure out how to lock the file, and how to make sure
>it's locked.  Just to test things, I ran the following script:
[snip]

Hi.

	Thanks to all that replied.  Like folks suggested, I used a
separate lockfile, and tested the script by running two processes of the
same script, and it works fine.  Yes, I was getting that "option is not
numeric" error when I had "O_RDWR" in quotes, and the error stopped when I
removed the quotes.  And, if I tried O_EXLOCK without quote, I did indeed
get the "Your vendor has not defined Fcntl macro O_EXLOCK, used at
dbmtest.pl line 11" error message.

	As to where I found that method of using O_EXLOCK within the tie,
one of the places I found it is
http://stason.org/talks/apachecon2000/OR093/html/dbm.html , a mod_perl
tutorial.  I'm sure I saw it in at least one other place, though.  Maybe
somewhere in the Perl CD Bookshelf?  I forget.  No biggie, since this
lockfile method seems to work.

	A few general questions.  What's the "proper" way to go about
getting help with a compilation problem, netiquette-wise?  Specifically,
compiling Taint.pm.  I can't find any docs for the module.  Searching the
usenet archives at deja.com didn't help at all.  I did post my problem to
comp.lang.perl.modules, but there's no reply so far, after a few days.
Would it be a good idea to contact the module's author now, or should I
try other things before bothering him/her?

	And, when I finally finish writing this program (that I needed the
locking help with), I'd like to post it somewhere with lots of comments,
to get suggestions for possibly improving it, or making it more secure
(it's a CGI thing), and stuff like that.  I don't really care if someone
takes it and uses it, as it's mianly a learning experience for me, and I'm
sure it would be better off using DBI, anyway, which I'll try using once
I learn it.  Anyway, would it be a good idea to post the script here or
anywhere else for general suggestions/critique?  

	I'd appreciate any ideas.  Thanks in advance.

Jamie Kufrovich, YAPH-wannabe

-- 
Egg, eggie@sunlink.net
FMSp3a/MS3a A- C D H+ M+ P+++ R+ T W Z+ 
Sp++/p# RLCT a+ cl++ d? e++ f h* i+ j p+ sm+


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

Date: 05 Dec 2000 18:48:04 +0000
From: nobull@mail.com
Subject: Re: how to call a dos excutable file by 'system'?
Message-Id: <u9r93m7li3.fsf@wcl-l.bham.ac.uk>

jin zengxiang <jingzx@sinaman.com> writes:

> I want to call a program which is designed to run in dos
> environment, how can I call the program by the command --"
> system(.....)"?

What happens if you just do it?

> say,the program is placed in C:\ and the name is dos.exe.

system('C:/dos.exe')

> Does anybody know the solution ?

It would help if you'd tell us the problem.

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


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

Date: Tue, 05 Dec 2000 19:09:36 GMT
From: alazarev1981@my-deja.com
Subject: how to check if there is text in an input text field?
Message-Id: <90jeh9$i6c$1@nnrp1.deja.com>

Simple problem:

I've got an html page with:
<input type="text" name="blah">

The form is sent to the process.cgi file that gathers the form
information as such:
$text = cgi->param('text');

Then I want to print that text to a new file if and only if that field
has text in it. So I wrote the following line:
if($text != "") {
  print NEW_FILE "Your new text is here: $text";
}

Everything works except the if condition is never met. I know the $text
variable has the data in it because when i just print it out the text
is there, but my condition to check if the $text vaeiable is NULL must
not be right. Any answers?

Thanks in advance,

Alex Lazarevich
alazarev@itg.uiuc.edu




Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 05 Dec 2000 19:13:35 GMT
From: alazarev1981@my-deja.com
Subject: Re: how to check if there is text in an input text field?
Message-Id: <90jeon$iba$1@nnrp1.deja.com>

Sigh...

I meant to say that my .cgi file reads like such:
$text = $cgi->param('blah');
not
$text = $cgi->param('text);

So thats not the problem.

In article <90jeh9$i6c$1@nnrp1.deja.com>,
  alazarev1981@my-deja.com wrote:
> Simple problem:
>
> I've got an html page with:
> <input type="text" name="blah">
>
> The form is sent to the process.cgi file that gathers the form
> information as such:
> $text = cgi->param('text');
>
> Then I want to print that text to a new file if and only if that field
> has text in it. So I wrote the following line:
> if($text != "") {
>   print NEW_FILE "Your new text is here: $text";
> }
>
> Everything works except the if condition is never met. I know the
$text
> variable has the data in it because when i just print it out the text
> is there, but my condition to check if the $text vaeiable is NULL must
> not be right. Any answers?
>
> Thanks in advance,
>
> Alex Lazarevich
> alazarev@itg.uiuc.edu
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 05 Dec 2000 19:23:53 GMT
From: alazarev1981@my-deja.com
Subject: Re: how to check if there is text in an input text field?
Message-Id: <90jfc0$is9$1@nnrp1.deja.com>

I know, ne instead of != for strings...
man, i should read more often...
thanks anyways.
alex


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 5 Dec 2000 13:39:34 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: how to check if there is text in an input text field?
Message-Id: <slrn92qdj6.o6i.tadmc@magna.metronet.com>

alazarev1981@my-deja.com <alazarev1981@my-deja.com> wrote:

>Then I want to print that text to a new file if and only if that field
>has text in it. So I wrote the following line:
>if($text != "") {
          ^^
          ^^

That is a numeric comparison. There is a different operator
for string comparison (ne).

But I think this is more clear:

   if ( length $text ) {


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


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

Date: Tue, 05 Dec 2000 21:00:41 +0100
From: "Philip 'Yes, that's my address' Newton" <nospam.newton@gmx.li>
Subject: Re: Perl FORMAT Into variable?
Message-Id: <2cgq2tk8s4121jgliofivalvs0rf5ndi7h@4ax.com>

On 2 Dec 2000 03:16:17 GMT, damian@cs.monash.edu.au (Damian Conway) wrote:

> ryanwol2000@my-deja.com writes:
> 
> >Is it possible to create a REPORT or FORMATTED TEXT where the output
> >goes into a variable instead of STDOUT? 
> 
> It's a pain to do with C<format>.

And if you want to submit yourself to the pain, `perldoc -q "into a string"`
points you at the perlform manpage; specifically, the section on "Accessing
Formatting Internals", which has a demo swrite() function.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
If you're not part of the solution, you're part of the precipitate.


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

Date: Tue, 5 Dec 2000 17:28:16 -0500
From: "Robert L. Ayers" <rayers@answerlogic.com>
Subject: Re: Perl string converter
Message-Id: <t1eX5.234$H43.810@client>

Here are two subs I quickly wrote which will:

    1)  take a string and convert it to a unique number

        and

    2) take a any number that results from 1) and convert it back to the
string it represents.

One constraint you didn't mention was one-to-one'ness.  In the code I wrote,
there is a one-to-one mapping from the set of all strings to the set of
integers, but there is not a guarranteed back mapping.  In other words,
there are elements in the set of all integers that don't map back to an
element in the set of all strings.  If this is a stated requirement (it
wasn't), then it can be accomplished too, at the sake of less efficient
code.

Robert L. Ayers

my $a = 'bvfdbd^{[[]}';
print "Start string: $a\n";
$a = UniqueNumber($a);
print "To Number: $a\n";
$a = UniqueString($a);
print "Back to String: $a\n";


sub UniqueNumber {
 return "1" . unpack("b*", shift);
}

sub UniqueString {
 ($_ = shift) =~ s/1//;
 return pack("b*", $_);
}


Bob Walton <bwalton@rochester.rr.com> wrote in message
news:3A272B18.56A2F095@rochester.rr.com...
> designpixs@my-deja.com wrote:
> >
> > I want to be able to pass in a string of any size
> > and return an integer.  The return value is
> > always unique to the string passed in.  (i.e.
> > pass in TEST returns 3452, pass in TESTS returns
> > 234532) The return value MUST be a unique value
> > to the value passed in.  If I pass in TEST and
> > get 1234 and the later pass in TEST I should get
> > 1234.
> ...
> > Drew
> ...
> What you're asking for is technically infeasible.  There are a *lot* of
> strings "of any size" out there, and only a relative handful of integer
> values.  For example, a 100000-character string has 2**800000 possible
> values (which is probably more than the number of electrons in the
> universe), while a standard integer has only 2**32 possible values.  I
> suppose you could use the Math::BigInt package to represent a unique
> number for each such string, but then why not just use the string
> itself, since there would be a 1:1 relationship anyway?
>
> The thing you probably actually want is called a hash function -- but a
> hash function does not meet your stated criterion of uniqueness.  If you
> would like to see the hash function Perl uses for its hashes, take a
> read through:
>
>     perldoc perlguts
>
> --
> Bob Walton




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

Date: Tue, 5 Dec 2000 20:19:30 -0800
From: <thijs@abzurd.com>
Subject: perlcc static?
Message-Id: <90jf7t$k6h$1@dinkel.civ.utwente.nl>

hi , .. i'm afraid i'm adking a bit of a faq here but i couldn't find it
anywhere, ..

i'd like to us perlcc to make statically linked binarys, .
i have a couple of programs that i need to easily distribute between a
couple of linux distros we are running


regards

thijs
--
http://www.abzurd.com




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

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


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 5039
**************************************


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