[18750] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 918 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 16 21:05:43 2001

Date: Wed, 16 May 2001 18:05:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <990061513-v10-i918@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 16 May 2001     Volume: 10 Number: 918

Today's topics:
    Re: \nhelp <mirvine@esatclear.ie>
    Re: \npeter (Craig Berry)
        aol proxy <joycefive@earthlink.net>
        aol proxy <joycefive@earthlink.net>
    Re: aol proxy <joe+usenet@sunstarsys.com>
    Re: Bits and bytes (James Weisberg)
        Connecting to MS Access with an Apache Server??? <ryan@tuitions.com>
    Re: Connecting to MS Access with an Apache Server??? <bart.lateur@skynet.be>
    Re: form <mischief@velma.motion.net>
        help needed in regex alternation <sherlock@genome.stanford.edu>
    Re: help needed in regex alternation (Eric Bohlman)
    Re: help needed in regex alternation <bart.lateur@skynet.be>
    Re: HELP.....Need help with Perl Script (Craig Berry)
    Re: How to check validity of a credit card? <rebelvideo@hotmail.com>
    Re: How to invoke another script in a CGI script? <rebelvideo@hotmail.com>
    Re: How to invoke another script in a CGI script? (Eric Bohlman)
    Re: How to invoke another script in a CGI script? <mischief@velma.motion.net>
    Re: How to invoke another script in a CGI script? <kim.saunders@mercuryit.com.au>
    Re: How to invoke another script in a CGI script? (Craig Berry)
    Re: looking for a Perl solution <mischief@velma.motion.net>
    Re: map only when defined? (Craig Berry)
    Re: Measuring the time <godzilla@stomp.stomp.tokyo>
    Re: Newbie needing help... <mischief@velma.motion.net>
        Parse::RecDescent returning array ref (Sweth Chandramouli)
    Re: Random Numbers Script <mischief@velma.motion.net>
    Re: Sending wav-file through perl-script <rebelvideo@hotmail.com>
    Re: Simple sorting problem (Jay Tilton)
    Re: Simple sorting problem <bigrich318@yahoo.com>
        uniq users <joycefive@earthlink.net>
    Re: Visual Basic and Perl <rebelvideo@hotmail.com>
    Re: Visual Basic and Perl <bart.lateur@skynet.be>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 16 May 2001 23:07:25 GMT
From: "Mark Irvine" <mirvine@esatclear.ie>
Subject: Re: \nhelp
Message-Id: <NKDM6.32863$PF4.63392@news.iol.ie>

In article <3B02ED26.84971366@courrier.usherb.ca>, "jtjohnston"
<jtjohnston@courrier.usherb.ca> wrote:


> I have certain lines that start with "&&4;" I would like to attach these
> lines to the previous line as follows. But I don't know how. I figure I
> have to search and replace for "\n&&4;" but ... ?

No,

The line you are looking for does not have a newline character at the start.
You simply want to search for &&4. It's that simple...
try: 
m/^&&4/

(i don't think '&' chars have any special meaning in regex, anybody know
better?)

Good luck,
Mark


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

Date: Wed, 16 May 2001 22:23:33 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: \npeter
Message-Id: <tg5vf54fs1k39e@corp.supernews.com>

jtjohnston (jtjohnston@courrier.usherb.ca) wrote:
: I am parsing the contents of a text file.
: I have certain lines that start with "&&4;" I would like to attach these
: lines to the previous line as follows. But I don't know how. I figure I
: have to search and replace for "\n&&4;" but ... ?

If your file can fit in memory as a whole, just slurp it into a single
scalar using any of the standard idioms, and then do

  $text =~ s/\n(?=&&4;)//g;

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "God becomes as we are that we may be as he is."
   |               - William Blake


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

Date: Thu, 17 May 2001 00:09:22 GMT
From: "Patrick Joyce" <joycefive@earthlink.net>
Subject: aol proxy
Message-Id: <SEEM6.10227$gc1.927036@newsread1.prod.itd.earthlink.net>

i have a problem. what is up with aols proxy servers i have written a perl
script that needs a uniqe host name. but with aol proxy the hostnames change
often, how do i fix this and or why is this






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

Date: Thu, 17 May 2001 00:09:26 GMT
From: "Patrick Joyce" <joycefive@earthlink.net>
Subject: aol proxy
Message-Id: <WEEM6.10228$gc1.927036@newsread1.prod.itd.earthlink.net>

i have a problem. what is up with aols proxy servers i have written a perl
script that needs a uniqe host name. but with aol proxy the hostnames change
often, how do i fix this and or why is this




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

Date: 16 May 2001 20:48:26 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: aol proxy
Message-Id: <m3n18cztph.fsf@mumonkan.sunstarsys.com>

"Patrick Joyce" <joycefive@earthlink.net> writes:

> i have a problem. what is up with aols proxy servers i have written a perl
> script that needs a uniqe host name. but with aol proxy the hostnames change
> often, how do i fix this and or why is this

Although TCP is part of the HTTP protocol, IP isn't. Proxy servers are 
under no obligation to pass along IP addresses.  However, this issue is
off-topic for perl newsgroups, so it would be better to ask in the 
comp.infosystems.www* heirarchy.

HTH
-- 
Joe Schaefer   "The very ink with which all history is written is merely fluid
                                         prejudice."
                                               --Mark Twain


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

Date: Wed, 16 May 2001 23:17:25 GMT
From: chadbour@wwa.com (James Weisberg)
Subject: Re: Bits and bytes
Message-Id: <9UDM6.5425$DW1.236277@iad-read.news.verio.net>

Dave Bailey <dave@sydney.daveb.net> wrote:
>On Wed, 16 May 2001 16:02:58 GMT, James Weisberg <chadbour@wwa.com> wrote:
>>   Right, but I need a decoding function for the bitstring I am
>>constructing. The above was just an example of how that might work
>>once I know how many bits I need to sift thru to calculate a value.
>
>I see.  You should still be able to use vec instead of split and unpack,
>but I'm not sure how well the methods compare.

   I'm not sure I can even use vec() given the way I am creating the
vector in the first place. Like I said in my original post, I wanted
to arrange for the bitstring to be encoded such that when I determine
how many more bits are needed to calculate a value, that I can assume
the bits are laid out in powers of two, and not whatever byte/word
order my machine picks.
   To that end, the storage function is probably slower than it needs
to be, because it lays out one bit at a time. I will show that below.
It should be said that I don't care about the speed of storing data as
that is done once. Retrieving data is what I want to optimize.

[...]
>>   The problem with the fetch function, in terms of how I need to use it,
>>is that the caller must know a priori how many bits need fetching (for $b).
>
>But in your scheme, that can determined by the result of a previous
>vec_fetch, right?

   Yeah, I think so. I would have to call vec_fetch() from the function
which is decoding the bitstring with the correct offset to get the HH
value. Then once I know that, I will know how many more bits to read
and I can call vec_fetch() a second time with a new offset and however
many bits HH told me to read.
   However, one catch is that vec() only supports a BITS argument that
are powers of 2. So I would have to change change my last instruction to
store 32 bits instead of 24.

>Of course, vec_store and vec_fetch would have to be
>modified to operate 2 bits at a time.  This being the case, perhaps the
>best solution would be to implement the encoding and decoding in C, then
>glue it to Perl using XS.

   I haven't used XS before. That might be out of my league. What
would need to happen is that the C function would decode the bitstring
but the results must somehow wind up in a Perl array.

>>My scheme above encodes 2, 4, 8, 16, and 24. The storage function is called
>>to store data to disk; and then the fetch function is used by a completely
>>independent program to retreive the data. So the size of the data element
>>must be encoded in the bitstring itself. What I have achieved above is
>>some pretty good compression, at the expense of some processing. Now I
>>just want to see if I can process a bit faster. If you are interested, I
>>can post both pieces of code and explain how they work.
>
>Sure.  Perhaps you could benchmark your encoding and decoding functions on
>the following arrays, as well:

   Before I get to the benchmarking, let me first post the code and maybe
you can offer some suggestions. I'm afraid this is going to get more involved
than either of us may have hoped.

   I'll start by saying something about the nature of the data that is
being encoded. For the most part, they are small values. I am letting a
-1 represent the initialized value of a field. The number of fields in a
record is variable, and I am encoding the record size as well. Finally,
each record is tied to a date, which I call the "Interval Reporting Date"
or ird for short. Overall, a reporting date can represent information for
an "open" time period or a "closed" time period. If it is open, I encode
the date as YYYYMMDD (e.g. 20010314); and if it closed, I encode the date
as -YYYYMMDD. So if I make a query for "open" records, I can ignore any
that don't have a positive ird. To that end, the ird is packed in 4 bytes
at the beginning. It does not get encoded as a bitstring. After the ird
comes the packet size, and then the data.

   Here is what I have coded so far:

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

my $vector = dbrec_pack(@ARGV);
my @packet = dbrec_unpack($vector);
$"=","; print "[$#packet] packet: (@packet)\n";

sub dbrec_pack {
   my $ird = pack("l", shift);
   my $i   = 8;   my $v = 0; vec($v,  0,$i)=2+$#{@_};                # recsize

   if($_[0])            {
   if($_[0] > 16)       {     $v= 0; print"$_[0] overflow\n"; exit }
      else              { vec($v, 2,  4)=2; vec($v, 3,  4)=$_[0]-1;} # recflag
   }  else              {
      my(@bits,$m,$o);
     for(@_) {
            $_ = -1 if not defined $_;
         if($_ ==-1)    { vec($v,$i++,1)=1; vec($v,$i++,1)=0; }
      elsif($_ == 0)    { vec($v,$i++,1)=0; vec($v,$i++,1)=0; }
      else              { vec($v,$i++,1)=1; vec($v,$i++,1)=1;
         if($_<17)      { vec($v,$i++,1)=0; vec($v,$i++,1)=0; $m= 4; $o=    1 }
      elsif($_<273)     { vec($v,$i++,1)=1; vec($v,$i++,1)=0; $m= 8; $o=   17 }
      elsif($_<65809)   { vec($v,$i++,1)=0; vec($v,$i++,1)=1; $m=16; $o=  273 }
      elsif($_<16843025){ vec($v,$i++,1)=1; vec($v,$i++,1)=1; $m=24; $o=65809 }
      else              {     $v= 0; print "$_ overflow.\n"; exit }
               my $l = 0; vec($l, 0, 32)=$_ - $o;
               @bits = reverse split(//, unpack("B*", $l));       # portable?
         for(  my $b = 0; $b < $m; $b++   ) {
            vec($v,$i++,1) = $bits[$b];      # copy m-bits of array into v
         }
   }  }  }

   return $ird.$v;                           # concatenate ird and vector
}

sub dbrec_unpack {
   my($ird,$sz,$bits) = unpack("lCb*", $_[0]);
   my @packet = (-1) x $sz;                                       # initialize
   my @s = split(//,$bits);

   print "ird=$ird, size=$sz, length=", length($_[0]),"\nbitstr: ($bits)\n";

   my $i=0; my $n = 0;
               $packet[$n++] = $ird;
   if($s[1] && $s[0] == 0) {                                      # II = 01
               $packet[$n++] = $s[$i+4]+2*$s[$i+5]+4*$s[$i+6]+8*$s[$i+7]+1;
   }else {
      for(  my $m; $n < $sz;) {
            if($s[$i++] == 0) {$packet[$n++] =  0; $i++; next; }  # II = 00
            if($s[$i++] == 0) {$packet[$n++] = -1;       next; }  # II = 10
            if($s[$i++])      {
               if($s[$i++])   {$m = 24; $o = 65809}               # HH = 11
                        else  {$m =  8; $o =    17}               # HH = 10
            } else            {
               if($s[$i++])   {$m = 16; $o =   273}               # HH = 01
                        else  {$m =  4; $o =     1}               # HH = 00
            }
            my $v = $s[$i++];                                     # II = 11
      for(  my $p = 2, my $j =  1; $j < $m; $j++, $p <<= 1 ) {
               $v|= $p if($s[$i++]);                              # fiddle 2^p
         }     $packet[$n++] = $v + $o;                           # value + 1
   }  }

   return @packet;
}

Let me show a couple examples:

# -> ./encode.pl 20010315 0 1 10 100 1 00 0 -1
ird=20010315, size=8, length=11
bitstr: (001100000011001001111011001010111011001010001000)
[7] packet: (20010315,0,1,10,100,100,0,-1)
# -> ./encode.pl 20010315 9 1 10 100 1 00 0 -1
ird=20010315, size=8, length=6
bitstr: (01000001)
[7] packet: (20010315,9,-1,-1,-1,-1,-1,-1)

The first argument is the ird, and the second argument is a status flag for
the entire record. As you can see, if the flag is nonzero, I encode a string
which keeps the flag intact and I get a packet of -1s back. This instruction
is the II = 01 instruction from what I described in my previous post.

That's all I have for the moment. Let me know if you want any more info
or have any suggestions on where to procede from here. And thanx for your
comments so far.

-- 
World's Greatest Living Poster


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

Date: Wed, 16 May 2001 16:36:07 -0600
From: "Ryan" <ryan@tuitions.com>
Subject: Connecting to MS Access with an Apache Server???
Message-Id: <9duv5t$ajf$1@news.xmission.com>

Our web site is running on an remote apache server and we have a MS access
database that we would like copy up to a directory and to be able to simply
exctract information from and show it in an HTML format.  Here is the start
of my code.

#!/usr/bin/perl
use DBI;
$dbh = DBI->connect("dbi:ODBC:'driver=Microsoft Access Driver (*.mdb);
dbq=major.mdb'",'','');
#do stuff...
$dbh->disconnect;

Im having trouble connecting to our database I keep getting this error:

Can't locate loadable object for module DBD::ODBC in @INC (@INC contains:
/usr/local/lib/perl5/5.00503/sun4-solaris
/usr/local/lib/perl5/5.00503
/usr/local/lib/perl5/site_perl/5.005/sun4-solaris
/usr/local/lib/perl5/site_perl/5.005 .) at
/home/users/f/fmg/public_html/cgi-bin/test/test2.pl line 3 BEGIN
failed--compilation aborted at
/home/users/f/fmg/public_html/cgi-bin/test/test2.pl line 3.

Any help on what I am doing wrong or the correct way to connect to the
database online would be great.
Thanks,
Ryan




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

Date: Wed, 16 May 2001 23:05:13 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Connecting to MS Access with an Apache Server???
Message-Id: <2e16gtsu57d6686353llp1odhg35b5ddqj@4ax.com>

Ryan wrote:

>Our web site is running on an remote apache server and we have a MS access
>database that we would like copy up to a directory and to be able to simply
>exctract information from and show it in an HTML format.

It looks to me as if you're trying this on a Solaris machine. Jeezes,
some people succeed to really amaze me.

AFAIK, MS Access is readable on a Win32 platform only, and even then,
you need to have the proper parts of MS Access, the program, installed
on your machine (they're called "Jet") or it still won't work.

You have to get a database engine running that does work on your
machine, and import the data into that database. With the proper DBD
driver, you should be able to get a connection, and extract the data, as
you intended.

For example, mySQL (<http://www.mysql.com/downloads/os-solaris.html>).

p.s. The fact that you're running Apache looks totally irrelevant to me.
The fact that your machine is Solaris, which you didn't mention but
which I can deduce from you @INC paths, does matter.

-- 
	Bart.


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

Date: Wed, 16 May 2001 23:29:05 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: form
Message-Id: <tg63a1mhu870e5@corp.supernews.com>

Barry <edge3d@wanadoo.nl> wrote:
> I have made a mailingform with formmail.pl

Please don't. Go to http://groups.google.com and search for
'Matt Wright'. Read what people think of his code. I should say
in his defense that I've read he wrote most of those scripts as
a hobby while in high school.

> When sending a message the script generates a standard content:
> Below is the result of your feedback form. It was submitted by
> (Barry) on Monday, May 14, 2001 at 11:12:57
> --------------------------------------------------------------------------
> message:

> Submit: Send Message
> --------------------------------------------------------------------------


> I only want the message in the body and not the "Below is the result
> of........."
> How can I do this????

Search for and remove these lines (I use the tilde to show left
margin, since the first line wraps. There are only two lines.):

   ~print MAIL "Below is the result of your feedback
     form.  It was submitted by\n";
   ~print MAIL "$Config{'realname'} ($Config{'email'}) on $date\n";

If the part of a program which performs a function is removed,
that function tends to stop working.

Chris

-- 
Where there's a will, there's a lawyer.



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

Date: Wed, 16 May 2001 16:30:49 -0700
From: Gavin Sherlock <sherlock@genome.stanford.edu>
Subject: help needed in regex alternation
Message-Id: <160520011630490555%sherlock@genome.stanford.edu>

Hi,
   I have some line of text that I want to check for matches, that eg
may be like:

p53||p53 encoding protein||tp53

and then say I have some input, p53, that I want to match against that
text, but only to a whole entry, where whole entries are delimited by
double pipes.  I did try:

if ($text =~ /\b$input\b/){ #stuff }

but this still gets the middle guy, when I only want the first one. 
Really, want I want to say is just before the regex, either be the
start of the string, or be a pipe, and after the regex, either be a
pipe, or the end of the string.  It seems that I can't have an
alternation between a pipe and the beginning/end of a string, eg,
something like:

if ($text =~ /(^|\|)\b$input\b(\||$)/){ #stuff }

but obviousy you can't alternate caret or dollar to get them to mean
beginning or end.  Is there a way I can do this?

I do know that I can split my string on double-pipes first, but I have
many thousands of lines to go through.  With my 'not-quite-right'
regex, it takes about 2 seconds to go through the file, doing the
split, and checking each element takes about 10 fold-longer.

Any suggestions?

Cheers,
Gavin


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

Date: 17 May 2001 00:00:46 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: help needed in regex alternation
Message-Id: <9dv4be$20q$2@bob.news.rcn.net>

Gavin Sherlock <sherlock@genome.stanford.edu> wrote:
> Hi,
>    I have some line of text that I want to check for matches, that eg
> may be like:

> p53||p53 encoding protein||tp53

> and then say I have some input, p53, that I want to match against that
> text, but only to a whole entry, where whole entries are delimited by
> double pipes.  I did try:

> if ($text =~ /\b$input\b/){ #stuff }

> but this still gets the middle guy, when I only want the first one. 

[snip tricky regex stuff]

> I do know that I can split my string on double-pipes first, but I have
> many thousands of lines to go through.  With my 'not-quite-right'
> regex, it takes about 2 seconds to go through the file, doing the
> split, and checking each element takes about 10 fold-longer.

> Any suggestions?

I'd say the path of least resistance is a two-stage test: use your 
original regex to see if the value being searched for exists in the string 
at all (actually, it might be faster to use index() then a regex match); 
if it does, then, and only then, split the string and do a sequence of 
exact comparisons (probably using grep()).



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

Date: Thu, 17 May 2001 00:19:56 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: help needed in regex alternation
Message-Id: <ea66gtglb9f4slb47kvemn6st8jq1od2rg@4ax.com>

Gavin Sherlock wrote:

>   I have some line of text that I want to check for matches, that eg
>may be like:
>
>p53||p53 encoding protein||tp53
>
>and then say I have some input, p53, that I want to match against that
>text, but only to a whole entry, where whole entries are delimited by
>double pipes.  I did try:
>
>if ($text =~ /\b$input\b/){ #stuff }
>
>but this still gets the middle guy, when I only want the first one. 

Perhaps the problem is that you need to group the alternatives? Hint:
use parentheses. As it is, the \b will become part of the first resp.
last alternatives.

-- 
	Bart.


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

Date: Wed, 16 May 2001 22:42:38 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: HELP.....Need help with Perl Script
Message-Id: <tg60iug3mbrj38@corp.supernews.com>

Steve Jones (carsonmtv@MailAndNews.com) wrote:
: I am trying to create yet another paid to read email program and am having 
: trouble with the script.

You'd be considered trendier if you were having trouble with the business
model. :)

: What I am actually using is a preexisting click affiliate script.  That
: is, a program that users signup for, and are emailed their code so they
: can put that code on a webpage of their own.  They will recieve credits
: in thier account, for unique ip address clicks.  The problem is that,
: the script logs their ip address, so as too not pay them for clicking 
: the link on their own webpage.

This can't possibly work the way you want.  Not only is it utterly trivial
to circumvent (how many clicks would it take to pay for a $15/month second
account?), it will fail to catch cheaters with dynamically assigned IP
addresses (dialup users, for example) even if they just use the same
machine as they registered with.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "God becomes as we are that we may be as he is."
   |               - William Blake


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

Date: Thu, 17 May 2001 10:12:02 +0930
From: Chris <rebelvideo@hotmail.com>
Subject: Re: How to check validity of a credit card?
Message-Id: <3B031E5A.4275AE83@hotmail.com>


I have a credit card checking routine if you want it

It was written before there was any such module
and I can't get modules added to my ISP's server. 

so if its not in the standard distribution I write it myself

-- 
Regards

Chris
rebelvideo@hotmail.com


Lars wrote:
> 
> can anybody tell me how to check a creditcards validity?
> please do not refer to any module. maybe there is another possibility
> to include some code to my cgi script directly.
> 
> thx in advance,
> Lars


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

Date: Thu, 17 May 2001 09:24:16 +0930
From: Chris <rebelvideo@hotmail.com>
Subject: Re: How to invoke another script in a CGI script?
Message-Id: <3B031328.8047D30C@hotmail.com>



I assume the script you are trying to run is called find.pl? yes?

if so this will work
 $all_files = `./find.pl .`;

coming from windows I have no idea why the script needs the "./" before
it 
as you can run normal commands (executables) without it.
the ./ just means current directory, which one would assume is the first
place the shell looks for the command!

Another trick that will be VERY BENEFICIAL is to add  2>&1 to the
backtick command
this will allow you to capture STDERR and give you a better idea of
whats going on

e.g. 

	$all_files = `./find.pl . 2>&1`;



kalasend at YAHOO dot COM wrote:
> 
> hi,
> 
>     I found that in a CGI script, statements like these won't work:
>             system("X Y Z") && die "$!\n";
>     or,
>             $all_files = `find .`;
> 
>     Problem could be that the CGI script is not associated with any shell?
> (I made this assumption because the same CGI script works well when I did
> "perl -w XXX.cgi" on the command line)
> 
>     Then how can I invoke other scripts when running as CGI?
> 
> thanks,
> ben

-- 
Regards

Chris
rebelvideo@hotmail.com


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

Date: 17 May 2001 00:51:54 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: How to invoke another script in a CGI script?
Message-Id: <9dv7ba$20q$6@bob.news.rcn.net>

In comp.lang.perl.misc Chris <rebelvideo@hotmail.com> wrote:
> I assume the script you are trying to run is called find.pl? yes?

> if so this will work
>  $all_files = `./find.pl .`;

> coming from windows I have no idea why the script needs the "./" before
> it 
> as you can run normal commands (executables) without it.
> the ./ just means current directory, which one would assume is the first
> place the shell looks for the command!

Unix shells, by default, do *not* search the current directory for 
executables, and setting your shell up to do so is widely regarded as a 
security risk (it makes it easier to run Trojan horse programs).



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

Date: Thu, 17 May 2001 00:55:38 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: How to invoke another script in a CGI script?
Message-Id: <tg68cat0d8tg74@corp.supernews.com>

In comp.lang.perl.modules Chris <rebelvideo@hotmail.com> wrote:


> I assume the script you are trying to run is called find.pl? yes?

> if so this will work
>  $all_files = `./find.pl .`;

> coming from windows I have no idea why the script needs the "./" before
> it 
> as you can run normal commands (executables) without it.

If they are in your path. It's a path issue. Unix has been around
longer than MeSsyDOS.

> the ./ just means current directory, which one would assume is the first
> place the shell looks for the command!

Unless you're root, and your user has a program in his directory
called 'ls' or 'ps' or somesuch. Unix and derivatives are designed
around multiple users. Imagine logging in as root to look at a
user's directory, because he has been using a lot of processor
time. You might do something like this:

    $ cd ~user
    $ ls

And your user might have this file living at ~user/ls :

    #!/usr/bin/perl
    system('rm -rf /');

Would you want the current directory to be the first place
to look for executable files?

If you really want, you can add '.' to your PATH variable.
If you really want, you can give my friend Bobo your root
user's RSA key and the IP address to which he needs to
secure shell.

This isn't really Perl, but it's an important security
issue that some Windows users just don't understand at
first when moving to Unixy OSes.

As Henry Spencer once said, "Those who do not understand
Unix are condemned to reinvent it, poorly".

When DOS 2.0 had subdirectories sidebagged on, they were
implemented to be "somewhat like in Unix". It must be
remembered that for all of NT's shortcomings, it has come
a long way from the quickly hacked CPM that was
QDOS / MS-DOS 1.0 over twenty years ago. Unfortunately,
there are many places where Gates and Co. could have
been Posix compliant and even Unix compliant if it wasn't
for arrogance, shortsight, and marketing. ActivePerl
wouldn't have been such an undertaking if DOS had followed
the strong lead Unix was presenting at the time.

Chris

-- 
Product shown enlarged to make you think you're getting more.



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

Date: Thu, 17 May 2001 10:33:52 +1000
From: "Kim Saunders" <kim.saunders@mercuryit.com.au>
Subject: Re: How to invoke another script in a CGI script?
Message-Id: <9dv6b1$hvf$1@thebe.syd.dav.net.au>

> coming from windows I have no idea why the script needs the "./" before
> it
> as you can run normal commands (executables) without it. the ./ just
> means current directory, which one would assume is the first place the
> shell looks for the command!

One would only assume that if one were used to windows/command.com as a
shell.

Unix style shells look in $PATH (just like windows) and $PATH only for
the command, and not in the current directory. If you put the current
directory (./) in the $PATH then it will behave more like command.com.

This is basically a good thing, primarily because there are a lot more
commands, both shell and external in Unix, and it is quite likely that if
your script has a simple, single word name, it will already exist
somewhere else on the system (eg "mail", or something). Just another case
where Unix does exactly what it is told, instead of assuming what you
want and doing that, regardless of whether it is infact what you want.

KimS


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

Date: Thu, 17 May 2001 01:04:16 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: How to invoke another script in a CGI script?
Message-Id: <tg68sgi5aqkv0c@corp.supernews.com>

Chris (rebelvideo@hotmail.com) wrote:
: I assume the script you are trying to run is called find.pl? yes?
: 
: if so this will work
:  $all_files = `./find.pl .`;

That will work if the other script isn't depending on being run in the CGI
environment, needs no parameters, etc.

: coming from windows I have no idea why the script needs the "./" before
: it as you can run normal commands (executables) without it.
: the ./ just means current directory, which one would assume is the first
: place the shell looks for the command!

There are good security reasons for not including . in the path.  Lots of
people do it anyway, of course.  But it's not the default under Unix.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "God becomes as we are that we may be as he is."
   |               - William Blake


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

Date: Wed, 16 May 2001 22:10:25 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: looking for a Perl solution
Message-Id: <tg5umh4r0tmhb9@corp.supernews.com>

Bernhard Sept, BHS Schulungen <b-sept@gmx.de> wrote:

> Hi there,
> I am looking for a source of a Perl Script, that allows me to
> 1. admin a little database (using a admin_user and a admin_password)
> 2. that forwards known users (which have been given an ok by the admin (#1)
> to a HTML page and
> 3. that offers a form to register for unknown (new) users.

Anyone who advertises themselves as a Perl consultant should
be a good source for this. Please take a look at
jobs@perl.org for your search, since comp.lang.perl.* are
technical fora and are not intended to be classified ads.

> After scanning several www pages - should I use (learn) PHP to do that job?

PHP can do HTML and can do databases. It is designed for
non-programmers to make dynamic web pages. It is, however,
a different language and therefore you will not be likely
to find out much about it in a Perl newgroup.

> I think, that that could exist already.

Many sites use such programs. I am not aware of a freely
available solution. One may exist. A few minutes searching
with Google or Northern Light may help more than posting
to a newsgroup. This newsgroup does not specialize in
location and publicity of stock solutions. This is a
techinical forum.

> Have a nice week

I wish you the same. Good luck with your search.

Chris

-- 
Programming is a tool. A tool is neither good nor evil. It is
the user who determines how it is used and to what ends.



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

Date: Wed, 16 May 2001 22:20:13 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: map only when defined?
Message-Id: <tg5v8t4q6tav66@corp.supernews.com>

Phil R Lawrence (prlawrence@lehigh.edu) wrote:
: I'm  currently saying:
:     my_function(
:         map {
:                 (defined $args->{$_})
:                   ? ($_, $args->{$_})
:                   : ''
:             }
:             qw/ -w -lpp -ms -o -s -c /
:     );
: 
: But this results in:
:     my_function('', '', '-ms', 'letter', '-o', 'portrait', '', '')
: 
: What I *really* want is:
:     my_function('-ms', 'letter', '-o', 'portrait')
: 
: Any ideas on what I might put in the map block that would accomplish
: this?

Evaluating to an empty list effectively skips that element:

  @vowels = map { /[aeiou]/ ? $_ : () } ('a'..'z');
  print join(':', @vowels), "\n";

Output is 'a:e:i:o:u'.

So simply replacing your '' with () should do the trick.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "God becomes as we are that we may be as he is."
   |               - William Blake


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

Date: Wed, 16 May 2001 15:29:01 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Measuring the time
Message-Id: <3B02FF2D.1F359517@stomp.stomp.tokyo>

Craig Berry wrote:
 
> Godzilla! wrote:

(unnoted snippage by Berry)

> : I am somewhat dismayed you have no objection to his
> : referring to many here as a "...band of assholes...."
 
> I didn't like it, but I also didn't get upset enough to warrant a public
> or private response.  The rhetorical device of using comparisons with the
> annihilation of six million human beings comprising an entire culture to
> make points about niceties of usenet etiquette is vastly more
> objectionable.


Only you have mentioned the Holocaust. Why is this?

My presumption is I can waltz in here and cuss like
a drunken sailor or a two-bit whore working Skid Row,
and you will not object.

However, if I utter the word "Hitler" or utter the
word "Nazi" or utter an analogy which indirectly
references either, you will become totally unglued
and shout, "Inappropriate social behavior!"

For your edification and enlightment, I will refer
you to Hitler's newly formed National Socialist
German Worker's Party, circa 1920 - 1945. One of
his early (1920 - 1923) party platforms was the
vehement denouncement of Bolshevism, which was
taunted by Hitler and his followers as a vast
conspiracy of Jewish financers and merchants. 
The Nazi Party paraphrased philosophy, during
these early stages, is well known amongst
academics and is one of,

 "This band of Jewish peoples is a disruptive
  force to our German economic well being."

This is how the brainwashing all started,
long before your mentioned Holocaust events.
Actually, it wasn't until nearly ten years
later, persecution of Jews was legitimized
by German laws.

"...to the band of assholes who seem intent on
 disrupting any attempt to produce clear and 
 concise posting guidelines...."

Clearly an analogous brainwashing is in action
evidenced by innumerable articles posted by the
Tad Cult denouncing the very character of those
whom do not agree with their philosophy and,
this Tad Cult's splitting of this group into
two distinct factions, one of which is wrong
and are to be considered, disruptive assholes.

Watch your step, Mr. Berry. Your style of thinking,
logic and method of rationalization beguile you.
Others cannot but I am able to see clearly what is
behind your mask.


Godzilla!


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

Date: Thu, 17 May 2001 00:15:18 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Newbie needing help...
Message-Id: <tg660m10cg4l9b@corp.supernews.com>

Clinton A. Pierce <clintp@geeksalad.org> wrote:
> [Posted and mailed]

> In article <9ds9fu$fa6$1@newsg3.svr.pol.co.uk>,
> 	"J Houston" <james@houston73.freeserve.co.uk> writes:
>> "Cant locate subparseform.lib in @INC (@INC contains
>> H:/perl/lib H:/perl/site/lib .) at C:\Inetpub\wwwroot\cgi-bin\testing2.pl
>> line 2."
>> 
>> Perl is installed on my (partitioned) H: drive and testing2.pl is the
>> file I'm trying to run. This file runs fine on my Colleges unix
>> server, but I'm lost with this stuff. Please email me if you
>> can help. Thanks in advance.

> Apparently your college's unix server has this file installed and your 
> perl script is require'ing or use'ing it (probably at line 2).  This isn't 
> a core module, and it's misnamed for a module.  Find the file, install 
> it and try again.

Since it has the '.lib' extension and Perl knows this, it's
probably being loaded with require instead of use. That
would make it a Perl 4 style library, for which there are
usual extensions but no real standard.

The crux of the matter, though, is that if the user can't
figure out why Perl isn't finding a library or module, he
shouldn't be using a custom CGI form parser. That's why
CGI.pm is in the core distribution.

Chris

-- 
Even in the worst of times, there is always someone who's
never had it better. Even in the best of times, there is
always someone who's never had it worse.



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

Date: Thu, 17 May 2001 00:10:47 GMT
From: sweth+perl@gwu.edu (Sweth Chandramouli)
Subject: Parse::RecDescent returning array ref
Message-Id: <bGEM6.1271$G5.366159@news1.rdc1.md.home.com>

	I'm trying to build some parsers with Parse::RecDescent;
as a learning exercise, after I had some serious problems with some
more convoluted attempts, I decided to build a simple CSV parser.  A
stripped down version of that code, now intended to just return the
last CSV value for each line passed to it, is below; rather than
returning the CSV value that I _think_ I'm setting $return to, however,
my parser instead returns an array ref.  Enabling RD_TRACE shows that
the parsing itself is happening correctly, I think, so the problem
seems to be with the setting of $return; I'm manually setting that to
a scalar value for every subrule that isn't a terminal, however, so I
can't see where the array ref is coming from.  (For input, I'm
currently just piping this script the output of an
echo '"one","two","three"'; it does the same thing with real-world
data as well.)
	Could someone enlighten me here?  

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

use strict;
use Parse::RecDescent;

#$::RD_HINT = 1;
#$::RD_WARN = 1;
#$::RD_TRACE = 1;

my $csv_grammar = q{
   CSVLine:
      NonFinalToken(s?) QuotedText
      { $return = $item[-1] }
   NonFinalToken: 
      QuotedText Comma
      { $return = $item[1] }
   QuotedText: 
      DoubleQuote TextChar(s?) DoubleQuote
      { $return = join ('', @item[2..scalar(@item)-2]) }
   Comma:
      ','
   DoubleQuote:
      '"'
   TextChar:
      ( DoubleQuote DoubleQuote | /[^"]/ )
      { $return = $item[1] }
};

my $csv_parser = Parse::RecDescent->new ($csv_grammar);

while (my $line = <ARGV>) {
   chomp ($line);
   my $last_token = $csv_parser->CSVLine ($line);
   print $last_token, "\n";
};

	-- Sweth.

-- 
Sweth Chandramouli ; <sweth+perl@gwu.edu>


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

Date: Thu, 17 May 2001 00:34:44 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Random Numbers Script
Message-Id: <tg67544sakj3f8@corp.supernews.com>

sas <saras@gj.net> wrote:
> Does anyone have a script that will generate random numbers? Someone told me
> I could do it with Perl but I don't know where to start. It must be a 5
> digit random number which will be associated with a specific name, (an "ID"
> number), I want to check against a log file to be sure the number hasn't
> been used already and then add the number and associated name to that log
> file.  Any help will be greatly appreciated.

This takes a lot of time if there is no match and even more (due to
retrying) if there is one. Why not serialize your numbers? 

If you really need numbers that can't be guessed by surrounding
numbers and serialization therefore won't work, then create a
sequential list of random numbers, then assign them serially.
An array of random numbers (or a flat text file with one random
number per line for CGI programs perhaps) should work.

You can even keep a separate index of where you have left
off in the sequence. This can be a simple scalar.

You really do need to look at your problem differently in order
to solve your problem. Simply implementing your original solution
will be a nightmare of inefficiency and complexity.

Chris

-- 
For the pleasure of others, please adhere to the following
rules when visiting your park:
    No swimming.  No fishing.  No flying kites.  No frisbees.
    No audio equipment. Stay off grass.  No pets. No running.



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

Date: Thu, 17 May 2001 09:44:42 +0930
From: Chris <rebelvideo@hotmail.com>
Subject: Re: Sending wav-file through perl-script
Message-Id: <3B0317F2.837E4CA1@hotmail.com>

Hi

to get around the "inherent problem' (see below) and still process the
wave file with your script

you could try calling the script in this fashion

http://mydomain.com/cgi-bin/waveprocess.pl?sound.wav

the browser sees the last .wav and uses that as the file extension and
therefore the helper program gets a proper extension

I am not sure if this will work with all browsers on all platforms, but
give it a try


-- 
Regards

Chris
rebelvideo@hotmail.com


P.S. 

	If you are calling the script from a form and wish to process other
information make sure you POST it
that way your URL won't get messed up.




"Godzilla!" wrote:
> 
> Tim Lauterborn wrote:
> 
> > I would like to send a wav-file "through" a perl-script. Reading and
> > printing in binary mode is no problem.
> 
> > Unfortunately "Content-type: audio/wav\n\n" does not work. The browser does
> > not recognize the file as a wav-file.
> 
> > Does someone know the right content-type description?
> 
> 
> You have the right content type. Actually there are two
> types but yours should be recognized by most browsers.
> 
> audio/x-wav
> audio/wav
> 
> Yours seems the most often used.
> 
> In a generic nutshell....
> 
> There is an inherent problem, least with Mozilla. A browser
> downloads a sound file, wav, midi, au, whatever, then stores
> it in a browser cache. Unfortunately, .pl and .cgi files
> are not stored in a cache, not in a true sense, there is
> no related extension in most cases, which is really how
> it should be. A browser downloads an audio file via a script
> just fine but does not assign an audio extension because it
> originates through a script. A helper application is executed
> and is referenced to this sound file in cache, but there is no
> extension or, in rare cases, a wrong extension. It cannot be
> played; the sound application cannot recognize what type of
> audio file is present. Most often, this results in a download
> "unknown type" dialog message box.
> 
> All which happens is clearly more technical but this will give
> you a simplified overview. If you look close at your error message,
> look in your cache and look at your location bar when this happens,
> you can better surmise events; your browser is confused on what
> it should do, there is an extension conflict.
> 
> I use a work around which might be of help. If your intent
> is to have a user remain at the same page, or similar, you
> can print a location redirect. However, for a sound file,
> no true redirect takes place. A browser remains where it
> is and, loads the sound file via a helper application,
> with a page remaining in the background, unless one of
> those "dumb" plug-ins like Crescendo is used, which pops
> an annoying new window.
> 
> Try this as an experiment. Be patient, all of my midi files
> are files I personally recorded here at home, and are a bit
> on the large size. This should take a little less than a
> minute for an average server.
> 
> Include this in a test script and decide if this will
> satisfy your unique needs,
> 
> print "Location: http://la.znet.com/~callgirl3/bornwild.mid\n\n";
> 
> You are welcomed to download this midi file and use it
> on your local system for testing, if you wish.
> 
> A word of caution. A print location method is not compatible
> with an html print nor any other print which is preceeded by
> a Content-type print. You cannot mix Content-type with a
> Location print. You can call a script via Server Side Includes
> which can print a Content-type or Location. This is the method
> I use described above. Another problem comes into play though,
> you cannot make a SSI call via script printed html.
> 
> Final analysis, consider using a standard html embed tag to
> include sounds in your page. This is quick and easy. Takes
> less than a minute to type in needed tags and url location.
> You might want to look at options for this, such as size and
> style of player, looping, volume and so forth. Works nice!
> 
> Read about and research, Content-type, Location, Server
> Side Includes and browser protocal, if you wish to jump
> into hardcore details on this most annoying problem.
> 
> Godzilla!

-- 
Regards

Chris
rebelvideo@hotmail.com


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

Date: Wed, 16 May 2001 22:07:04 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Simple sorting problem
Message-Id: <3b02f87e.307529571@news.erols.com>

On Wed, 16 May 2001 15:26:35 -0400, Young Chi-Yeung Fan
<yf32@cornell.edu> wrote:

>for $trip (sort { $a <=> $b } keys %DATA) { ... }
>B, A, 1, 2, ..., 15, 16
>
>for $tripnum (sort keys %VM) { ... }
>1, 10, 11, ..., 15, 16, 2, 3, 4, ... , 8, 9, A, B
>
>What I want is this:
>1, 2, 3, ..., 14, 15, 16, A, B
>
>What do I have to do to get that result? Thanks a lot for your help!

You could split the list into two--one with the integers, one with the
non-integers.  Sort each separately then mush them into a final sorted
list.

  @sorted = (
    ( sort {$a <=> $b} grep !/\D/, @array ),
    ( sort {$a cmp $b} grep  /\D/, @array )
  );


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

Date: Wed, 16 May 2001 17:14:45 -0500
From: "Rich" <bigrich318@yahoo.com>
Subject: Re: Simple sorting problem
Message-Id: <tg5up6gtued3d6@corp.supernews.com>


"Young Chi-Yeung Fan" <yf32@cornell.edu> wrote in message
news:3B02D46B.6A27560C@cornell.edu...
> Hi,
>
> I'm trying to sort key-value pairs read in from a DBM file. The keys
> are:
> 1, 2, 3, ..., 14, 15, 16, A, B
>
> Using this loop:
>
> for $trip (sort { $a <=> $b } keys %DATA) { ... }
>
> I get this sorted result:
> B, A, 1, 2, ..., 15, 16
>
> Using this loop:
>
> for $tripnum (sort keys %VM) { ... }
>
> I get this sorted result:
> 1, 10, 11, ..., 15, 16, 2, 3, 4, ... , 8, 9, A, B
>
>
> What I want is this:
> 1, 2, 3, ..., 14, 15, 16, A, B
<snip>

Separate what you want to sort numerically from what you want to sort
ASCIIbetically.

sort numerics (numerically)
@nums = sort {$a <=> $b} grep /^\d+$/, keys %DATA;

sort everything else (ASCIIbetically)
@ascii = sort grep /^\d*\D/, keys %DATA;


foreach (@nums,@ascii) {
 ..do something with the sorted data..
}


Rich





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

Date: Thu, 17 May 2001 00:20:02 GMT
From: "Patrick Joyce" <joycefive@earthlink.net>
Subject: uniq users
Message-Id: <SOEM6.10260$gc1.929804@newsread1.prod.itd.earthlink.net>

i have a problem. i have a perl program and i need to get unique information
from every user that gos to my site. before i used the ip address or
hostname but i need it to work with proxy servers. what uniqu information
can i get from them.




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

Date: Thu, 17 May 2001 09:14:31 +0930
From: Chris <rebelvideo@hotmail.com>
Subject: Re: Visual Basic and Perl
Message-Id: <3B0310DF.47C42A6A@hotmail.com>

Hi

take a look at perlembed docs in your distribution

you should find the clues you need there

the other choice is to simply call perl as an external program
this of course depends on what you are trying to do with the perl
portion


Jeffrey Mercer wrote:
> 
> Have anyone used VB and Perl together?
> I want to use VB as a GUI layer and link to a Perl obj library.
> Much like the Glade/ Perl on Gnome Platforms.
> 
> I've seen the MS Windows modules on CPAN and they don't seem to do what
> I'm looking for.
> 
> I should be able to declare an perl obj within the VB GUI code and use
> it there. OLE?
> 
> Any thoughts on this appreciated...
> 
> --
> Best Regards,
> 
> Jeff @ Industrial House

-- 
Regards

Chris
rebelvideo@hotmail.com


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

Date: Thu, 17 May 2001 00:17:46 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Visual Basic and Perl
Message-Id: <6g56gtcdgs18b7cc7e0lig6uttvotu303a@4ax.com>

Jeffrey Mercer wrote:

>Have anyone used VB and Perl together?
>I want to use VB as a GUI layer and link to a Perl obj library.
>Much like the Glade/ Perl on Gnome Platforms.
>
>I've seen the MS Windows modules on CPAN and they don't seem to do what
>I'm looking for.
>
>I should be able to declare an perl obj within the VB GUI code and use
>it there. OLE?
>
>Any thoughts on this appreciated...

Search ActiveState's website for:

	PerlEZ
	PerlCOM and PerlCtrl, both part of the PDK (AKA "Perl Dev Kit")

-- 
	Bart.


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.  

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 V10 Issue 918
**************************************


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