[25777] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8016 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 26 14:05:32 2005

Date: Tue, 26 Apr 2005 11:05:12 -0700 (PDT)
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, 26 Apr 2005     Volume: 10 Number: 8016

Today's topics:
        [solved] Re: using CGI::Carp <moritz.karbach@desy.de>
        ANN: A new scripting language Tao 0.9.0 beta released! (Fu Limin)
        Converting my index.pl(cgi) to html::template one <hackeras@gmail.com>
    Re: Converting my index.pl(cgi) to html::template one <mark.clementsREMOVETHIS@wanadoo.fr>
    Re: Converting my index.pl(cgi) to html::template one <hackeras@gmail.com>
    Re: Converting my index.pl(cgi) to html::template one <tadmc@augustmail.com>
    Re: Converting my index.pl(cgi) to html::template one <hackeras@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 26 Apr 2005 17:46:20 +0200
From: Moritz Karbach <moritz.karbach@desy.de>
Subject: [solved] Re: using CGI::Carp
Message-Id: <d4lnob$2m1nq$1@claire.desy.de>

Hi,

finally I figured out how to update the module. And it works :-)

Thanks for your help,

- Moritz



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

Date: 26 Apr 2005 08:41:37 -0700
From: fu.limin.tao@gmail.com (Fu Limin)
Subject: ANN: A new scripting language Tao 0.9.0 beta released!
Message-Id: <b35444fb.0504260741.226944fb@posting.google.com>

Dear all,

I am glad to announce in this forum that the lastest version of a new
scripting language Tao has come
out. Welcome to try it out!

=======================
Here are some details:
=======================

==========
Summary:
==========
Tao is an object-oriented scripting language with dynamic-typing
variables supporting complex data structures. It has powerful text
processing ability such as string regular expression matching. It
provides built-in numerical data types such as complex number and
multi-dimensional numeric array, and their corresponding operations
and computations are very convenient in Tao. It can be easily extended
with C++, through a simple and transparent interface.

===============
Key Features:
===============
1. Object-oriented ( syntax slightly similar to C++ ).
2. String regular expression with syntax support ( similar to Perl ).
3. Numeric types and their operations ( slightly similar to Matlab ).
4. Extendable with C++ through a simple and transparent interface.

================
ChangeLog:
================
+ : added
! : changed
* : fixed
- : removed

Release: tao_0.9.0_beta:

! Matrix type is generalized to numeric array supporting arbitrary
dimensions and different precisions including byte, short, int, float
and double. Many operations are also provided for numeric array.

+ Some convenient and powerful built-in functions are implemented to
manipulate numeric arrays, including numarray(), apply(), noapply()
and which() etc. Basic mathematical functions are also supported for
numeric arrays.

+ A feature called transient variable is implemented for convenient
parameter passing in some situations.

+ Some "magic" functions which may take expressions with transient
variables as parameters to do some computions on arrays and numeric
arrays without explicit looping and subindexing. These functions
include numarray(), apply() and noapply() for numeric array; iterate()
and iterget() for normal array; and which() for both.

+ Some C++ types are provided for transparent passing Tao types to C++
modules, so that only two C++ header files("taoCpptype.h" &
"taoPlugin.h") are required to develop C++ modules loadable by Tao
without linking to any additional libraries.

! The base class for TaoPlugin is changed from TaoBase to TcBase, so
that the developing of Tao plugins only requires another header file
"taoCpptype.h".

+ Basic string operations such as substring, insert, replace and erase
by subindexing. And a few functions are added such as number(), pack()
and unpack().

+ Added string regular expression matching for alternate and grouping
such as /(\d|\w)(@1:\D|\c)/.

+ Substring substitution by regular expressions.

! Embedding expression in regular expressions is changed.

+ More convenient subindexing is supported for array and hash.

+ Local variables.

+ yield statement to use routine as generator.

+ Many operators such composite assignment (+=, -=, *=, /=,etc.), type
comparision operators(=?,!?), right operators( .#,.@,.%, etc.)

+ eval(): evaluate a block of codes represented as a string.

+ Loop control: for(e1,e2,e3), logic control: e1 ? e1:e2; 

+ Other functions such as repeat(), about(), import(), load(), time(),
astime() and asctime() etc.

! Many changes including keywords: sub->routine, continue->skip.
commenting symbols are also changed.

* Some bugs fixed.

===============
Download:
http://prdownloads.sourceforge.net/taoscript/tao_0_9_0_beta.tar.gz?download

Document:
http://taoscript.sourceforge.net/An_Introduction_to_Tao_Language.pdf

HomePage:
http://taoscript.sourceforge.net

Contact:
Limin Fu: fu [dot] limin [dot] tao [at] gmail [dot] com


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

Date: Tue, 26 Apr 2005 18:03:57 +0300
From: Nikos <hackeras@gmail.com>
Subject: Converting my index.pl(cgi) to html::template one
Message-Id: <d4ll8r$mq0$2@nic.grnet.gr>

!!! Finally i made it !!!
I accept congratulations :-)

Here is th html template version of my index.pl which troubled me many 
ma days! After reading and reading what you told me  i finally get 
succeeded!

Here it is:

<html>
<head>
         <meta http-equiv="content-type" content="text/html; 
charset=iso-8859-7" />
         <title>Ψυχωφελή Πνευματικά Κείμενα!</title>
         <link rel="stylesheet" type="text/css" 
href="../data/css/style.css" />
<script type="text/javascript" language="javascript">
// <![CDATA[
var textToShow = "<TMPL_VAR name=data>";
var tm;
var pos = 0;
var counter = 0;

function init()
{ tm = setInterval("type()", 50) }

function type()
{
     if (textToShow.length != pos)
     {
        d = document.getElementById("DivText");
        c = textToShow.charAt(pos++);

        if (c.charCodeAt(0) != 10)
           d.appendChild(document.createTextNode(c));
        else
           d.appendChild(document.createElement("br"));

        counter++;

        if (counter >= 1800 && (c.charCodeAt(0) == 10 || c == "."))
        {
           d.appendChild(document.createElement("br"));
           d.appendChild(document.createTextNode("Press any key..."));
           counter = 0;
           clearInterval(tm);
           document.body.onkeypress = function ()
           {
		     document.getElementById("DivText").innerHTML = '';
			 tm = setInterval("type()", 50);
			 document.body.onkeypress = null;
		  };
        }
     }
     else
        clearInterval(tm);
}
// ]]>
</script>
</head>


<body onload=init()>
<div id=page>

<br>

<div id=select_form>
<form action="index.pl">Διάλεξε ένα από τα κείμενα για να διαβάσεις =>
<select name="select">
<TMPL_LOOP name=files>
         <option value="<TMPL_VAR name=file>"><TMPL_VAR name=file></option>
</TMPL_LOOP>
</select>
<input type="submit" name="select" value="Επιλογή" />
</form>
</div>

<div id="DivText"></div>

<div id=user_form>
<form action="show.pl">
<table class="user">
<tr><td>Πώς σε λένε αδελφέ?</td><td class="two"><input name="onoma" 
type="text" /></td></tr>
<tr><td>Ποιά είναι η γνώμη σου για την ευχούλα »Κύριε Ιησού Χριστέ, 
Ελέησον Με« ?</td><td class="two"><textarea name="euxoula" rows="4" 
cols="25"></textarea></td></tr>
<tr><td>Περιέγραψε μας, μία προσωπική σου πνευματική εμπειρία από 
κάποιον γέροντα, προς ώφελος των υπολοίπων αδελφών ( αν φυσικά έχεις 
:-)</td><td class="two"><textarea name="sxolio" rows="6" 
cols="25"></textarea></td></tr>
<tr><td>Ποιό είναι το email σου?</td><td class="two"><input name="email" 
type="text" /></td></tr>
<tr><td><input type="submit" name="show" value="Εμφάνιση όλων των 
απόψεων" /></td><td class="two"><input type="submit" name="send" 
value="Αποστολή" /></td></tr>
</table>
</form>
</div>

<div id=tip><TMPL_VAR NAME=tip></div>

<div id=info><table>
<tr><td class="host"><TMPL_VAR NAME=host></td></tr>
<tr><td class="xronos"><TMPL_VAR NAME=xronos></td></tr>
<tr><td class="counter"><TMPL_VAR NAME=counter></td></tr>
</table>
</div>

<div id=links>
<a href="games.pl"><img src="../data/images/games.gif" /></a>
<p><a href="show.pl?onoma=showlog" name="showlog">Last Update: 
25/4/2005</a></p>
</div>

</div>
</body>
</html>

and here is the index.pl file now in a pure format written since its 
only code and with subs this time :-)

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

use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use DBI;
use HTML::Template;
use vars qw ($sec $min $hour $mday $mon $year $wday $yday $isdst);

print header;

my @months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 
'Sep', 'Oct', 'Nov', 'Dec');
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime;
my $xronos = "$mday $months[$mon], $hour:$min";


my $dbh = ($ENV{'SERVER_NAME'} ne 'nikolas.50free.net')
         ? DBI->connect('DBI:mysql:nikos_db',            'root',     '')
         : DBI->connect('DBI:mysql:nikos_db:50free.net', 'nikos_db', 
'********')
         or die $DBI::errstr;

my ($match, $host) = get_host( $ENV{'REMOTE_ADDR'} );

my $data;
if( param('select') ) {
         $data = open_keimeno( $host, param('select') );
} elsif( $match ) {
         $data = welcome_old( $host );
} else {
         $data = welcome_new( $host );
}

$data =~ s/\n/\\n/g;
$data =~ s/"/\\"/g;
$data =~ tr/\cM//d;

my $sth;
my $row;

$dbh->do( "UPDATE logs SET page = page + 1" ) if ($host ne "Íßêïò");
$sth = $dbh->prepare( "SELECT page FROM logs" );
$sth->execute();
$row = $sth->fetchrow_hashref;

my $tmpl = HTML::Template->new(filename=>'./index.html');
$tmpl->param(
         files   => &select_form(),
         tip     => &tips(),
         data    => $data,
         host    => $host,
         xronos  => $xronos,
         counter => $row->{'counter'}
);
print $tmpl->output;

sub get_host {
         my ($url) = @_;

         my @numbers = split (/\./,$url);
         my $address = pack ("C4", @numbers);
         my $host = gethostbyaddr ($address, 2) || $url;
         $host = "Íßêïò" if ( ($host eq "localhost") or ($host eq 
"dslcustomer-221-228.vivodi.gr") or ($host eq "dell") );

         my $ref = $dbh->selectall_hashref( "SELECT host FROM logs", 
'host');
         if (exists $ref->{$host}) {
                 return (1, $host);
         } else {
                 return (0, $host);
         }
}

sub open_keimeno {
         my ($host, $file) = @_;

         my $keimeno = $file;
         open(FILE, "<../data/text/$keimeno.txt") or die $!;
              my @data = <FILE>;
         close(FILE);

         my $data = join('', @data);
         $dbh->do( "UPDATE logs SET keimeno='$keimeno' WHERE 
host='$host'" );
         $data;
}

sub welcome_old {
         my ($host) = @_;

         $dbh->do( "UPDATE logs SET visits = visits + 1 WHERE 
host='$host'" );
         my $sth = $dbh->prepare( "SELECT * FROM logs WHERE host='$host'" );
         $sth->execute();
         my $row = $sth->fetchrow_hashref;

         return "Êáëþò Þëèåò " .$host. "! ×áßñïìáé ðïõ âñßóêåò ôçí 
óåëßäá åíäéáöÝñïõóá!\n".
                "Ôåëåõôáßá öïñÜ Þñèåò åäþ ùò " .$row->{host}. " óôéò " 
 .$row->{xronos}. " !!\n".
                "ÓýíïëéêÝò Þñèåò åäþ " .$row->{visits}. " öïñÝò !!!\n".
                "Ôåëåõôáßá åßäåò ôï êåßìåíï { " .$row->{keimeno}. " }\n".
                "Ðïéü êåßìåíï èá ìåëåôÞóåéò áõôÞí ôçí öïñÜ !?";
}

sub welcome_new {
         my ($host) = @_;

         my $data;
         if ( $host ne "Íßêïò" ) {
                 $data = "Ãåéá óïõ " .$host. "!\n" .
                         "¸ñ÷åóáé ãéá 1ç öïñÜ åäþ !!\n" .
                         "Åëðßæù íá âñåéò ôá êåßìåíá åíäéáöÝñïíôá !!!";
                 my $text;
                 $dbh->do( "INSERT INTO logs VALUES (null, '$host', 
'$xronos', '$text', 1)" );
         } else {
                 $data = "Ãåéá óïõ Íéêüëá, ôé ÷áìðÜñéá !?! :-)";
         }
         $data;
}

sub select_form {
         my @files = </data/text/*.txt>;
         my @display_files = map {file=>/([^\/]+)\.txt/}, @files;
         \@display_files;
}

sub tips {
         open(FILE, '<../data/text/tips') or die $!;
              my @tips = <FILE>;
         close(FILE);

         @tips = grep { !/^\s*\z/s } @tips;
         $tips[int(rand(@tips))];
};

It works ok! Teh only problem is that if i change the relative path from 
this open(FILE, '<../data/text/tips') or die $!;

to this absolute one
open(FILE, '</data/text/tips') or die $!;

then the interpreter gives an error opening the file.... thats funyn 
because other absolute parts work!

Gee, i am so happy i finalyl made it work!


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

Date: Tue, 26 Apr 2005 17:49:01 +0200
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: Converting my index.pl(cgi) to html::template one
Message-Id: <426e62f2$0$11707$8fcfb975@news.wanadoo.fr>

Nikos wrote:
> !!! Finally i made it !!!
> I accept congratulations :-)
> 
> Here is th html template version of my index.pl which troubled me many 
> ma days! After reading and reading what you told me  i finally get 
> succeeded!
I'm glad all your hard work paid off. No, seriously.

<snip>

> sub tips {
>         open(FILE, '<../data/text/tips') or die $!;
>              my @tips = <FILE>;
>         close(FILE);
> 
>         @tips = grep { !/^\s*\z/s } @tips;
>         $tips[int(rand(@tips))];
> };
> 
> It works ok! Teh only problem is that if i change the relative path from 
> this open(FILE, '<../data/text/tips') or die $!;
> 
> to this absolute one
> open(FILE, '</data/text/tips') or die $!;
> 
> then the interpreter gives an error opening the file.... thats funyn 
> because other absolute parts work!
Well: is there such a file as "/data/text/tips"? Can you see it with ls? 
Come to think of it, why am I asking this? You haven't once responded to 
the many questions like this I have asked.

On a point of maintainability: "/data/text/" should be a constant at the 
top of your file, since it is repeated everywhere. I'm not going to 
bother explaining why constants are a good idea, since you won't read or 
take on-board the explanation.

As far as I am concerned, you are now on your own. I give up trying to 
help you.

Mark


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

Date: Tue, 26 Apr 2005 19:02:40 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: Converting my index.pl(cgi) to html::template one
Message-Id: <d4lomv$qh0$1@nic.grnet.gr>

Mark Clements wrote:

> Well: is there such a file as "/data/text/tips"?  

Of course! but it only works if set the path in relative way.
in absolute way it aint working.
The other paths that are absolute too work ok/


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

Date: Tue, 26 Apr 2005 11:07:40 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Converting my index.pl(cgi) to html::template one
Message-Id: <slrnd6spqc.232.tadmc@magna.augustmail.com>

Nikos <hackeras@gmail.com> wrote:

> use vars qw ($sec $min $hour $mday $mon $year $wday $yday $isdst);


   You should always prefer lexical variables over package variables, 
   except when you can't.


And you can, so that should be:

   my($sec $min $hour $mday $mon $year $wday $yday $isdst);


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


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

Date: Tue, 26 Apr 2005 19:17:58 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: Converting my index.pl(cgi) to html::template one
Message-Id: <d4lpjq$rda$1@nic.grnet.gr>

Tad McClellan wrote:
> Nikos <hackeras@gmail.com> wrote:
> 
> 
>>use vars qw ($sec $min $hour $mday $mon $year $wday $yday $isdst);
> 
> 
> 
>    You should always prefer lexical variables over package variables, 
>    except when you can't.
> 
> 
> And you can, so that should be:
> 
>    my($sec $min $hour $mday $mon $year $wday $yday $isdst);

Thank you. its better and quicker this way :-)


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 8016
***************************************


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