[8650] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2267 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 7 14:07:30 1998

Date: Tue, 7 Apr 98 11:01:39 -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           Tue, 7 Apr 1998     Volume: 8 Number: 2267

Today's topics:
    Re: Perl-to-C++ translator tool ?... gold_bag@yahoo.com
    Re: Q: Dynamic namespace change? (V. Ilyushchenko)
    Re: Q: Dynamic namespace change? (Andy Wardley)
    Re: Q: Dynamic namespace change? (Bart Lateur)
    Re: setUID script <rootbeer@teleport.com>
        Socket connection problems (new) <support@webhot.dk>
    Re: Socket problems! <rootbeer@teleport.com>
    Re: Sorting in multi-line records. (Mark-Jason Dominus)
    Re: text::soundex for Win32 <henry@sprucemt.com>
        Variable interpolation problems <sbekman@ilx374.iil.intel.com>
        Wanted: Amoo to stop my sysadmin from whining <andrewf@cp.pathfinder.com>
        Win::ODBC, Using "GROUP BY" SQL to output webmistress@chicweb.com
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Tue, 07 Apr 1998 10:11:02 -0500
From: gold_bag@yahoo.com
To: Oke Uwechue <uwechue@puma.att.com>
Subject: Re: Perl-to-C++ translator tool ?...
Message-Id: <352A4206.58F2@yahoo.com>

there is perl to C translator and than you can compile to get the
binary. It is mentioned in the perl site -
	http://language.perl.com/info/software.html
Look for 'The Perl Compiler' here.

Also a great perl resource is at -
http://www.yahoo.com/Computers_and_Internet/Programming_Languages/Perl/
This provides all pointers. Save this url for future use!!

See also -
	http://reference.perl.com/

Oke Uwechue wrote:
> 
> Does anyone know of a tool that does automatic conversion of Perl
> scripts to either C or C++ ?
> Also, is it possible for Perl code to use C/C++ libraries directly?
> thanks in advance,
> 
> -uwechue@puma.att.com


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

Date: Tue, 07 Apr 1998 18:51:41 +0400
From: "Simon (V. Ilyushchenko)" <simonf@rrg.msk.su>
Subject: Re: Q: Dynamic namespace change?
Message-Id: <352A3D7D.5580384D@rrg.msk.su>

Randal Schwartz wrote:
> Simon> Here a goes a Tough Question. Suppose I need a module (call it A) that
> Simon> would be called from module B with a code string as a parameter. Then
> Simon> module A will want to 'eval' that string using variable namespace of
> Simon> module B. How is this possible?

> Notice that the coderef passed in has access to all the lexical vars
> defined at the time, as well as being in package A as a default.  Also
> notice that we can pass vars from B to A, and even pass in vars from A
> to B.  And finally, notice that the code is compiled *once* instead of
> every time it gets passed.  This is a Big Win.

Thanks. This would be The Smalltalk Way. But my situation is 
a bit different. I am imitating SSI in a CGI script (don't tell me
I should not :). Suppose I call a script "date.cgi". It will read a file
that contains some HTML formatting plus some 'variables', perform
'variable substitution' (replace $date with the result of 'eval $date')
and output pure HTML.

The way I figured it is: I will have a custom CGI that will set all
the vars I need, then call a module Subst.pm that will do this
'variable substitution' in the namespace of the calling CGI.
So the code to be eval'ed is not known at compile time. 
That's why I want to pass it as a string.

Is it still doable, or is it getting too ugly? Or both? :)

Simon

-- 

 _________                Simon (Vsevolod ILyushchenko)
|       x |
| y = e   |     simonf@rrg.msk.su                   Life is file...
|_________|   

Disclaimer: This is not me. This is just my mailer talking to your
mailer...


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

Date: Tue, 7 Apr 1998 17:00:30 GMT
From: abw@cre.canon.co.uk (Andy Wardley)
Subject: Re: Q: Dynamic namespace change?
Message-Id: <Er1z8v.Grz@cre.canon.co.uk>

Simon (V. Ilyushchenko) <simonf@rrg.msk.su> wrote:
>Thanks. This would be The Smalltalk Way. But my situation is 
>a bit different. I am imitating SSI in a CGI script (don't tell me
>I should not :). 

I won't tell you that you shouldn't, but you might want to look at 
Text::MetaText which could save you a lot of time.  It sounds like it'll
do what you want based on what you've described.

Check out the 'Features' file for a description of other similar packages
that might do the trick if MetaText doesn't.  There are at least 3 
others available from CPAN.

CPAN: /modules/by-authors/Andy_Wardley/Text-MetaText-<ver>.tar.gz


A



--
Andy Wardley <abw@kfs.org> http://www.kfs.org/~abw    
Signature lost in transit.  We apologise for any inconvenience caused.


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

Date: Tue, 07 Apr 1998 16:14:29 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: Q: Dynamic namespace change?
Message-Id: <352b4fbb.2755752@news.tornado.be>

Simon (V. Ilyushchenko) wrote:

>The way I figured it is: I will have a custom CGI that will set all
>the vars I need, then call a module Subst.pm that will do this
>'variable substitution' in the namespace of the calling CGI.

I don't think you actually need it.

What I have done before, and what I would advice you to do in this case,
is simply build a hash containing the "variables" and their values. You
can't use Perl's built-in interpolation, but build your own. It's
actually quite easy to do, and almost just as fast.

    sub interpolate ($\%) {
        local($_, *val) = @_;
        s/\\(\\|\{)|\{(\w+)\}/defined $1?$1:$val{$2}/ge;
        $_;
    }

This function will replace a string like '{name}' with $val{'name'},
'\{' with '{' (in case you need it literally) and '\\' with '\'.

Example:
print &interpolate("My name is {name}, I'm from {country} \\{That's in
{continent}, in case you were wondering}.\n",{'name' => 'Bart',
'country' => 'Belgium', 'continent' => 'Europe'});

HTH,
Bart.


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

Date: Tue, 7 Apr 1998 10:41:48 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Bart Lateur <bart.mediamind@tornado.be>
Subject: Re: setUID script
Message-Id: <Pine.GSO.3.96.980407103859.1034I-100000@user2.teleport.com>

On Tue, 7 Apr 1998, Bart Lateur wrote:

> As far as I understand: you can set the setUID bit for a script, and
> then it will be run under the owner of the script's UID. The two special
> variables contain UID's:
> 
> 	$<	who launched the script ("nobody")
> 	$>	who owns the script (site owner)

Sounds right to me.

> But what am I to do with it? 

Whatever you want. :-)   In general, you can just pretend that the site
owner (in this case) is the one who started the script running, with taint
checks on.

> What I reconsider doing is:
> 
>  * Place a normal CGI script in my cgi-bin directory
>  * Place a setUID script in a directory that cannot possibly be accessed
> from the WWW
>  * Launch this setUID script from within the CGI script.
>  * Use a pipe to pass the data to write, through to the setUID script.

Shouldn't need to do all that. Your set-id script may do the updating
itself. Just ensure that it never trusts any data that your user supplied. 
Double-check everything the user sent. Hope this helps! 

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Tue, 07 Apr 1998 17:53:39 +0200
From: Web-Hotel Danmark <support@webhot.dk>
Subject: Socket connection problems (new)
Message-Id: <352A4C02.EE8BF92B@webhot.dk>

Hi again...

I've still got problems getting a file by HTTP using a socket
connection, the only result I get, is the main-page from the HTTP-server
running on the same machine I execute the script on!!

Please help me with this:

-Palle Nielsen

----------------------------------------------------------------------
The mainscript, calling a library-file
#!/usr/bin/perl
require "http-lib.pl";
$url="www.webhot.dk";
@res=&HTTPGet("/",$url,80,"");
print @res;
exit 0;
--------------------------------------------
And the libraryfile called "http-lib.pl"

#!/usr/bin/perl
use Socket;
$http_os = "UNIX";

sub HTTPGet {
    local($url, $hostname, $port, $in) = @_;
    local($form_vars, $x, $socket);
    local ($buf);
    $socket = &OpenSocket($hostname, $port);


    $form_vars = &FormatFormVars($in);

print  $socket <<__END_OF_SOCKET__;
GET $url HTTP/1.0
Accept: text/html
Accept: text/plain
User-Agent: Mozilla/1.0


__END_OF_SOCKET__



$buf = &RetrieveHTTP($socket);
$buf;

} #end of HTTPGet


sub RetrieveHTTP {
    local ($socket) = @_;
    local ($buf,$x, $split_length);

    $buf = read_sock($socket, 6);
    if ($buf =~ /200/) {
        while(<$socket>) {
            $buf .= $_;
        }
    }

    $x = index($buf, "\r\n\r\n");
    $split_length = 4;

    if ($x == -1) {
        $x = index($buf, "\n\n");
        $split_length = 2;
    }

    if ($x > -1) {
        $buf = substr($buf,$x + $split_length);
    }

    close $socket;

$buf;
} # End of RetrieveHTTP


sub OpenSocket {
    local($hostname, $port) = @_;

    local($ipaddress, $fullipaddress, $packconnectip);
    local($packthishostip);
    local($AF_INET, $SOCK_STREAM, $SOCK_ADDR);
    local($PROTOCOL, $HTTP_PORT);

    $AF_INET = AF_INET;
    $SOCK_STREAM = SOCK_STREAM;
    $SOCK_ADDR = "S n a4 x8";


    $PROTOCOL = (getprotobyname('tcp'))[2];
    $HTTP_PORT = $port;
    $HTTP_PORT = 80 unless ($HTTP_PORT =~ /^\d+$/);
    $PROTOCOL = 6 unless ($PROTOCOL =~ /^\d+$/);

    $ipaddress = (gethostbyname($hostname))[4];
    $fullipaddress = join (".", unpack("C4", $ipaddress));
    $packconnectip = pack($SOCK_ADDR, $AF_INET,
     $HTTP_PORT, $ipaddress);
    $packthishostip = pack($SOCK_ADDR,
    $AF_INET, 0, "\0\0\0\0");

    socket (S, $AF_INET, $SOCK_STREAM, $PROTOCOL) ||
 &web_error( "Can't make socket:$!\n");

    bind (S,$packthishostip) ||
 &web_error( "Can't bind:$!\n");

    connect(S, $packconnectip) ||
 &web_error( "Can't connect socket:$!\n");

    select(S);
    $| = 1;
    select (STDOUT);

S;
} # End of OpenSocket


sub read_sock {
    local($handle, $endtime) = @_;
    local($localbuf,$buf);
    local($rin,$rout,$nfound);

    $endtime += time;
    $buf = "";
    $rin = '';
    vec($rin, fileno($handle), 1) = 1;
    $nfound = 0;
read_socket:
while (($endtime > time) && ($nfound <= 0)) {
    $length = 1024;
    $localbuf = " " x 1025;
    $nfound = 1;
    if ($http_os ne "NT") {
 $nfound = select($rout=$rin, undef, undef,.2);
     }
}

    if ($nfound > 0) {
 $length = sysread($handle, $localbuf, 1024);
 if ($length > 0) {
     $buf .= $localbuf;
     }
    }
$buf;
}

1;






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

Date: Tue, 7 Apr 1998 10:29:46 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Web-Hotel Danmark <support@webhot.dk>
Subject: Re: Socket problems!
Message-Id: <Pine.GSO.3.96.980407102911.1034G-100000@user2.teleport.com>

On Tue, 7 Apr 1998, Web-Hotel Danmark wrote:

> I've tried for several days now to get e script to call a HTTP-server by
> using a socket-connection, but no matter what site I try to call, the
> only result I get is the default-page from the HTTP-server running om
> the same machine I execute the script on...
> 
> What do I do now ?

Use LWP, instead of trying (and failing) to do it yourself. :-)

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 7 Apr 1998 13:26:14 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Sorting in multi-line records.
Message-Id: <6gdnjm$hj0$1@monet.op.net>

In article <6gcv4n$rg8$1@nnrp1.dejanews.com>,  <lawm@hotmail.com> wrote:
>Header1
>Header2
>SEPARATOR (some string &l26a1H)
>.......6 lines
>Key ( text identifier used for sorting)
>.......n lines
>SEPARATOR
>.......6 lines
>Key
>.......n lines
>PATTERN get repeated a few thousand times
>EOF
>
>What I want to do is get the separator and all the text till next separator
>into a large array for all separators till EOF
>Then sort this large arrays by Key, Key will be the first string in the 8th
>line of the array.

First, you should read the records into an array, with one record perl
array element; normally the easiest way to do that involves setting
the special $/ variable to the separator string, because then the
<HANDLE> operator will read one entire record at a time.

Now you have an array of records.  First write a utility function to
extract the key; it might look something like this:

	sub key_of_record {

	  # Split record into lines:
	  my @lines = split /\n/, $record;

	  # Get first word from eighth line
	  my ($key) = split /\s+/, $lines[7];
	  return $key;
	}

then you simply use

	@records = 	
	  sort { key_of_record($a) cmp key_of_record($b) } @records;


################################################################

Now, since you have a lot of records, that will be inefficient,
because you extract the same keys over and over.  This is a good time
to use the Schwartzian Transform.  The Schwartzian Transform is easy,
because it's always exactly the same:

	# Just memorize this
	@records = map {$_->[1]}
	           sort {$a->[0] cmp $b->[0]}
	           map {[THING YOU WANT TO SORT ON, $_]}
	           @records;

Here THING YOU WANT TO SORT ON is `key_of_record($_)'.  This code
sorts the records by key, as before, but more efficiently.

################################################################

What does this do?  Let's suppose you have a list of names.

	Bill
	Randal
	Grodd
	Barbara
	Ed

You want to sort them by length, shortest first.  
You could write simply:
	sort {length($a) <=> length($b)} @records;

except that this computes and re-computes the length of every name
several times, which is wasteful.  The Schwartzian Transform
eliminates this waste.

The THING YOU WANT TO SORT ON is `length($_)', so you will use

	@names = map {$_->[1]}
	         sort {$a->[0] <=> $b->[0]}
	         map {[length($_), $_]}
	         @names;

The bottom `map' takes the original list and makes a list of pairs
from it.  The first item in each pair is the length; the second item
is the original name:
	
	[4, Bill]
	[6, Randal]
	[5, Grodd]
	[7, Barbara]
	[2, Ed]

The `sort' in the middle says to sort the resulting list of pairs by
comparing the first item in each pair; that's what ->[0] means: to get
the first item from a pair.  I changed `cmp' to `<=>' because the
lengths are numbers and not strings.

	[2, Ed]
	[4, Bill]
	[5, Grodd]
	[6, Randal]
	[7, Barbara]

Last, the `map' takes the sorted list pairs and extracts the second
item from each pair; that's what ->[1] means: get the second item from
a pair.  That leaves us with just

	Ed
	Bill
	Grodd
	Randal
	Barbara

which is precisely what we wanted.

That's the Schwartzian Transform.  



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

Date: Tue, 07 Apr 1998 11:01:39 -0400
From: Henry Hartley <henry@sprucemt.com>
Subject: Re: text::soundex for Win32
Message-Id: <352A3FD3.DE6DD66E@sprucemt.com>

Thanks for the e-mailed answer to this.  It is indeed included in the
standard package so this question is indeed stupid.

Henry


Henry Hartley wrote:

> A client would like to include a soundex feature in a site I'm working
> on.  I know there is a text::soundex module but I need something for
> Win32 (the client's server).
>
> Does anyone know if this module will work (make?) easily on Win32?  Or
> better yet, is there a premade Win32 version of this module?
>
> I've got the source of the module from CPAN but don't really know how to
> proceed.  Are there general instructions anywhere for porting a module
> to Win32?  Is it a difficult task?
>
> Thanks for your help.
>
> Henry Hartley





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

Date: Tue, 7 Apr 1998 19:48:18 +0300
From: Stas Bekman <sbekman@ilx374.iil.intel.com>
Subject: Variable interpolation problems
Message-Id: <Pine.A41.3.96.980407194338.38434A-100000@ilx374.iil.intel.com>

Hi,

I'm trying to make the following. But in vain...

$abc = 345;
$a = 'This is $abc';
$b = eval {$a};
print $b,"\n";

I want to get :
This is 345
but I get 
This is $abc

I tried many other ways: sprintf, eval and other but none of them seems to
work...

Any ideas, how do I take the one quote delimited string ans then get its
internals interpolated?

Thanks a lot!
______________________________________________________________________
Stas Bekman mailto:sbekman@iil.intel.com http://www.eprotect.com/stas
A must visit: http://www.eprotect.com/stas/TULARC (Java,CGI,PC,Linux)
Linux receives a 'Product of the Year Award' for Best Technical Support
http://www.infoworld.com/cgi-bin/displayTC.pl?97poy.supp.htm



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

Date: Tue, 7 Apr 1998 13:42:29 -0400
From: "Andrew F. Lee" <andrewf@cp.pathfinder.com>
Subject: Wanted: Amoo to stop my sysadmin from whining
Message-Id: <Pine.GSO.3.95.980407133218.12330B-100000@cp.pathfinder.com>

Hello,

We have Perl 5.002 (which has been around about 2 years) and very limited
set of modules.  I am groaning to my sysadmin to UPGRADE, but no one wants
to do anything unless the building is on fire.

I gave the following example as a Perl5.004 vs. Perl5.002 idiosyncracy:

#!/usr/local/bin/perl5   # yes, perl->perl4 .. just in case ...
sub greet {
    my $name = shift;
    if ($name) { print "Hello, $name\n";}
    else { print "Hello, person\n"; }
}
$rsub = \&greet;
#$rsub->("Andrew");   # Not in 5.002
&$rsub("Andrew");     # Uglier, but works in both

Now, this alone is not about to convince my draconian and somewhat dull
sysadmin that I need the LATEST release or Perl (and as many modules as
possible).  Since I am doing a LOT of CGI and Sybase, I thought I might
try that argument.

Please:  Any or examples of Perl code that did not compile in 5.002 but do
in 5.004 are graciously welcome (even if you don't know but suspect that
it won't compile in 5.002, I'll provide the proof).

Also:  What's new in SybPerl and CGI that I can beat my sysadmin over the
head with? 

-------------------------------------------------------------
Andrew F. Lee                 |                              |
Software Engineer             |  parenttime.com              |
email: andrewf@pathfinder.com |  1271 Avenue of the Americas |
Phone: (212) 522-2769         |  New York, N.Y. 10020        |
-------------------------------------------------------------
        When I say, "Ignore the man behind the curtain."   
        That is because there is no man behind the curtain.



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

Date: Tue, 07 Apr 1998 10:53:58 -0600
From: webmistress@chicweb.com
Subject: Win::ODBC, Using "GROUP BY" SQL to output
Message-Id: <6gdi6n$egb$1@nnrp1.dejanews.com>

Greetings : 
I would think that it would be really easy to output the
results of an SQLlike the following : 
SELECT Count(ReportID), ServerName,
ReportName, WeekEnd, ReportPathFROM Reports
GROUP BY ServerName, ReportName,
WeekEndHAVING ServerName IN ($serverlist) AND WeekEnd>=#$selected_date#

The
output of the query is correct meaning that I get the correct query datain
the correct order, but I find no easy way to output the information inthe
manner that would make sense. 
Here's what I want to output : 

<loop over
all ServerNames in $serverlist>ServerName
  <loop over all ReportNames for
ServerName>  ReportName
  <loop over all WeekEnd dates for ReportName>
 
ReportPath for WeekEnd  </end loop over all WeekEnd dates for ReportName>
 
</end loop over all ReportNames for ServerName></end loop over all
ServerNames>
So you can see, the innermost loop should loop around for all
of theReportPath for WeekEnd for that ReportName, the next loop should
loop
around for all of the ReportNames for that ServerName, and theoutermost loop
should loop around for all of the ServerNames in the list. 
I do a lot of
this stuff in Cold Fusion and it's very easy to use a "GROUP BY"in the
<OUTPUT> tag but I don't see anything similar for Win::ODBC. I cansee I
could do it by checking for 1. check for unique server name andlooping, 2.
check for unique ReportName and looping and3. output all ReportPath for
Weekend but this seems harder thanit should be. 

Maybe there is a trick
using Win::ODB I don't know about. Does anyonehave any ideas?

Thanks in
advance. Laura
ps I thought I'd put "URGENT MESSAGE" in the subject but
thought betterof it when I saw the thread on the group. hahahaha

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.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 2267
**************************************

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