[25762] in Perl-Users-Digest
Perl-Users Digest, Issue: 8001 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 21 09:05:26 2005
Date: Thu, 21 Apr 2005 06:05:14 -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 Thu, 21 Apr 2005 Volume: 10 Number: 8001
Today's topics:
Re: $q->self_url Unreliable <mikeh@perusion.net>
Re: $q->self_url Unreliable <postmaster@castleamber.com>
Re: Cgi.pm and CSS <hackeras@gmail.com>
Re: How to call the remains of a pattern match <tadmc@augustmail.com>
Re: How to test if a string is already in a array marc.eggenberger@itc.alstom.com
Re: How to test if a string is already in a array marc.eggenberger@itc.alstom.com
Re: How to test if a string is already in a array <postmaster@castleamber.com>
Re: How to test if a string is already in a array <tadmc@augustmail.com>
Re: How to test if a string is already in a array <tadmc@augustmail.com>
Re: How to test if a string is already in a array <spamtrap@dot-app.org>
Re: More cognitive dissonance... (Dave in Dallas)
Re: Perl and vmstat <joe@inwap.com>
Re: Problem with multiple instances of a module <devnull@post4.tele.dk>
Re: Q on BEGIN and INIT <jkrugman345@yahbitoo.com>
Using Bind Params in MySQL <hillmw@charter.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 21 Apr 2005 11:09:30 -0000
From: Mike Heins <mikeh@perusion.net>
Subject: Re: $q->self_url Unreliable
Message-Id: <slrnd6f2f9.ccn.mikeh@bill.heins.net>
On 2005-04-21, Jrgen Exner <jurgenex@hotmail.com> wrote:
> Julia De Silva wrote:
>> Is there a 100% reliable way to return the current URL of the script.
>> I have used $q->self_url but this doesn't seem to work on all
>> servers. I'd rather use cgi.pm than $ENV{} if poss.
>
> Did you check the specification of the Common Gateway Interface if this
> information is required?
Is there an official specification now? There wasn't as of several
years ago -- it was just sort of defined by the behavior of the NSCA
(then Apache) server behavior, plus a little web page at ncsa.uiuc.edu.
There is some question as to what is meant by current URL. Is it
the SCRIPT_NAME without PATH_INFO? Does it include the QUERY_STRING?
The CGI.pm url() method would seem to be what you want, as it can
do any of the above combinations.
--
Mike Heins
Perusion -- Expert Interchange Consulting http://www.perusion.com/
Be patient. God isn't finished with me yet. -- unknown
------------------------------
Date: 21 Apr 2005 11:25:05 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: $q->self_url Unreliable
Message-Id: <Xns963F40F7B96ABcastleamber@130.133.1.4>
Mike Heins wrote:
> On 2005-04-21, Jrgen Exner <jurgenex@hotmail.com> wrote:
>> Julia De Silva wrote:
>>> Is there a 100% reliable way to return the current URL of the
>>> script. I have used $q->self_url but this doesn't seem to work on
>>> all servers. I'd rather use cgi.pm than $ENV{} if poss.
>>
>> Did you check the specification of the Common Gateway Interface if
>> this information is required?
>
> Is there an official specification now? There wasn't as of several
> years ago -- it was just sort of defined by the behavior of the NSCA
> (then Apache) server behavior, plus a little web page at
> ncsa.uiuc.edu.
>
> There is some question as to what is meant by current URL. Is it
> the SCRIPT_NAME without PATH_INFO?
no
> Does it include the QUERY_STRING?
yes
The current URL would be in my opinion what one sees in the addressbar
when the script is called.
"self_url() will return a URL, that, when selected, will reinvoke this
script with all its state information intact. "
If self_url excludes either PATH_INFO or QUERY_STRING it's wrongly
implemented IMNSHO, or the documentation is incorrect (I consider
PATH_INFO state information too).
" Semicolon-delimited query strings are always accepted, but will not
be emitted by self_url() and query_string() unless the -
newstyle_urls pragma is specified.
This became the default in version 2.64."
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Thu, 21 Apr 2005 13:46:33 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: Cgi.pm and CSS
Message-Id: <d480ai$58q$1@nic.grnet.gr>
johnh wrote:
> Nikos, you seem like a nice guy, but you keep asking questions which
> make us think you don't understand what's really going on.
>
> I want to tell you what everyone else has told you: if you want to
> display web pages with Perl, use a templating system, and
> HTML::Template is recommended.
>
> If I was working with you, I'd tell you this:
>
> * get your HTML and CSS right first;
> * don't produce your HTML via CGI.pm and Perl;
> * produce them as an HTML file;
>
> That's stage one. And, you know what? Get someone else to do it if you
> want. They don't have to understand Perl at all. Just get a friend
> who's good at HTML/CSS to do you a good-looking page.
>
> * when that file is the way you want it, come back to the Perl
> newsgroups;
> * then we will transform your HTML file into an HTML::Template file;
> * then we will write a Perl script to display the Template with the
> information in it;
>
> This is the whole point of a Templating system. The HTML and the CSS
> are in one place, and the script is in another. Different people can
> work on different parts.
>
Thank you John for persistant will to help, i appreciate that.
Yes i confess that i was confused about the HTML::Templating system.
What i wanted to tell you is that from the very moment i decided to use
Perl not only as a high-level language but as a way to design web pages
and especially mine i needed a way of not getting my hands dirty with
html. I really dont like html but in order to make a webpage this is
unavoidable since i have to produce it somehow.
Thats why i choosed to use Perl's cgi.pm module functions to produce
html output.
All went good but then i noticed that my webpage although it did not
contained any pure html code it was still filled with stuff like:
print table( {border=>1, -width=>'80%', -align=>'center',
-style=>'border: thick groove Orange',
-background=>'../data/images/swirl.jpg'},
Tr( {-align=>'center'},
td( {-width=>'25%'}, font( {-size=>4, -color=>'Cyan'},
$row->{onoma} ) ),
td( {-width=>'50%'}, font( {-size=>4,
-color=>'Orange'}, $row->{email} ) ),
td( {-width=>'25%'}, font( {-size=>4,
-color=>'AquaMarine'}, $row->{xronos} ) ) ),
so it was messy with formating directives.
I though of a moment why not seperate the Perl code from the actual html
code.
Problem is that to do that i must create a html file with the design of
the webpage and then another perl file that would fill values to it by
replacing 'tmlp_var names=value' with the appropriate vaules.
Thats good but i dont want to create an html file but since i have the
index.pl by running it on the browser i then get the html output.
I try to convert it but i couldn manage it but since you are willing to
help convert it ic an paste it to you.
Man iam scared enouph just by looking at it :)
here is is btw as cgi.pm produced it:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"
xml:lang="en-US"><head><title>Ψυχωφελή Πνευματικά Κείμενα!</title>
<link rel="stylesheet" type="text/css" href="../style.css" />
</head><body><form method="post" action="index.pl"
enctype="application/x-www-form-urlencoded">
<p align="center"><font color="Lime" size="5">Λόγος Ψυχωφελής και
Θαυμάσιος => </font> <select name="select">
<option value="Ένα μήνυμα σε όλους τους άπιστους">Ένα μήνυμα σε όλους
τους άπιστους</option>
<option value="Αγιος Ιωάννης ο Δαμασκηνός -- Περί Παθών">Αγιος Ιωάννης ο
Δαμασκηνός -- Περί Παθών</option>
<option value="Αγιος Νείλος ο Ασκητής -- Περί Αντιχρίστου">Αγιος Νείλος
ο Ασκητής -- Περί Αντιχρίστου</option>
<option value="Ευφυολογήματα -- Κάποιοι Κάπου Κάποτε">Ευφυολογήματα --
Κάποιοι Κάπου Κάποτε</option>
<option value="Εφραίμ Κατουνακιώτης -- Περί Ευχής">Εφραίμ Κατουνακιώτης
-- Περί Ευχής</option>
<option value="Η Θρησκεία στο Δωδεκάθεο">Η Θρησκεία στο Δωδεκάθεο</option>
<option value="Η αλήθεια για τις ψυχές των κεκοιμημένων">Η αλήθεια για
τις ψυχές των κεκοιμημένων</option>
<option value="Θανάσιμα αμαρτήματα">Θανάσιμα αμαρτήματα</option>
<option value="Θεόκλητος Διονυσιάτης -- Περί Δαιμόνων">Θεόκλητος
Διονυσιάτης -- Περί Δαιμόνων</option>
<option value="Ιωσήφ Ησυχαστής -- Περί Ευχής Νο1">Ιωσήφ Ησυχαστής --
Περί Ευχής Νο1</option>
<option value="Ιωσήφ Ησυχαστής -- Περί Ευχής Νο2">Ιωσήφ Ησυχαστής --
Περί Ευχής Νο2</option>
<option value="Λατρευτικό Εγχειρίδιο -- Περί Ευχής">Λατρευτικό
Εγχειρίδιο -- Περί Ευχής</option>
<option value="Λατρευτικό Εγχειρίδιο -- Περί Σκανδαλισμού">Λατρευτικό
Εγχειρίδιο -- Περί Σκανδαλισμού</option>
<option value="Μετεμψύχωση">Μετεμψύχωση</option>
<option value="Οι πάπυροι της Νεκράς Θάλασσας">Οι πάπυροι της Νεκράς
Θάλασσας</option>
<option value="Πίστευε και μη ερεύνα">Πίστευε και μη ερεύνα</option>
<option value="Περιπέτεις ενός Προσκυνητή -- Περί Προσευχής">Περιπέτεις
ενός Προσκυνητή -- Περί Προσευχής</option>
<option value="Πού πάμε μετά θάνατο;">Πού πάμε μετά θάνατο;</option>
<option value="Πρόσεχε την ψυχή σου">Πρόσεχε την ψυχή σου</option>
<option value="Σχέση Χριστιανού με κοσμικότητα">Σχέση Χριστιανού με
κοσμικότητα</option>
</select> <input type="submit" name="ok" value="ok"
/></p><div></div></form><br /><html><head><title></title>
<script type='text/javascript'>
var textToShow = "Καλώς ήρθες dell.lan! Χαίρομαι πολύ που σε
ξαναβλέπω!\nΤελευταία φορα ήρθες εδώ ως dell.lan στις 18 Apr, 16:6
!!\nΑυτή είναι η 325 φορά που επισκέφτεσαι την σελίδα μου και χαίρομαι
πολύ που την βρίσκεις ενδιαφέρουσα !!!\nΤην τελευταία φορά διάβασες το
κείμενο [ Λατρευτικό Εγχειρίδιο -- Περί Σκανδαλισμού ]\nΠοιo λόγο θα
ήθελες να μελετήσεις αυτήν τη φορά ?!?";
var tm;
var pos = 0;
var counter = 0;
function init()
{ tm = setInterval("type()", 45) }
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>
<body onload=init()>
<center>
<div id="DivText" align="Left" style="
background-image: url(../data/images/kenzo.jpg);
border: Ridge Orange 5px;
width: 850px;
height: 500px;
color: LightSkyBlue;
font-family: Times;
font-size: 18px;">
</div
><br /><br /><br /><form method="post" action="show.pl"
enctype="application/x-www-form-urlencoded">
<table class="user"><tr><td>Πώς σε λένε αδελφέ?</td> <td><input
type="text" name="onoma" /></td></tr> <tr><td>Ποιά είναι η γνώμη σου
για την ευχούλα
*Κύριε Ιησού Χριστέ Ελέησον Με* ?</td> <td><textarea
name="euxoula" rows="4" cols="25"></textarea></td></tr> <tr><td>Μοιράσου
μαζί μας μία κατά τη γνώμη σου
θαυμαστή προσωπική πνευματική εμπειρία από
κάποιον γέροντα προς ώφελος των υπολοίπων
αδελφών (αν φυσικά έχεις :-)</td> <td><textarea
name="sxolio" rows="6" cols="25"></textarea></td></tr> <tr><td>Ποιό
είναι το e-mail σου?</td> <td><input type="text" name="email"
/></td></tr> <tr><td><input type="submit" name="Εμφάνιση όλων των
απόψεων" value="Εμφάνιση όλων των απόψεων" /></td> <td><input
type="submit" name="Αποστολή" value="Αποστολή"
/></td></tr></table><div></div></form><br /><br /><table
class="quote"><tr><td># Μην αισθάνεσαι ποτέ τύψεις για αυτά που έχεις
σκεφτεί για την γυναίκα σου. Αυτή έχει σκεφτεί πολύ χειρότερα για σένα.
(Jean Rostand)
</td></tr></table><br /><table class="info"><tr><td>dell.lan</td></tr>
<tr><td>21 Apr, 13:38</td></tr> <tr><td>1327</td></tr></table><br /><a
href="games.pl"><img src="../data/images/games.gif" /></a><p
align="right"><a href="show.pl?onoma=showlog"><font color="Lime"
size="2"><b>Last Update: 18/4/2005</b></font></a></p>
If you still want to help me please do and if you actually decide to,
please if you see something you dont like or can be written better make
changes at your wish.
After all its my personal webpage where you can see also see it runnign
at my host http://www.nikolas.tk/
Here is also the index.pl that produced the above html output:
#!/usr/bin/perl -w
use CGI::Carp qw(fatalsToBrowser);
use CGI::Cookie;
use CGI qw(:standard);
use DBI;
use DBD::mysql;
@months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
'Sep', 'Oct', 'Nov', 'Dec');
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime;
$xronos = "$mday $months[$mon], $hour:$min";
$ip = $ENV{'REMOTE_ADDR'};
@numbers = split (/\./,$ip);
$address = pack ("C4", @numbers);
$host = gethostbyaddr ($address, 2) || $ip;
$host = "ÁÖÅÍÔÉÊÏ" if ( ($host eq "localhost") or ($host eq
"dslcustomer-221-228.vivodi.gr" or $host eq "dell") );
print header( -charset=>'iso-8859-7' );
print start_html( -style=>'../style.css', -title=>'Øõ÷ùöåëÞ ÐíåõìáôéêÜ
Êåßìåíá!' );
$db = ($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 print font({-size=>5, -color=>'Lime'}, $DBI::errstr) and exit 0;
#*******************************************************************************
@files = <../data/text/*.txt>;
@display_files = map( /([^\/]+)\.txt/, @files );
print start_form(-action=>'index.pl');
print p( {-align=>'center'}, font( {-size=>5, -color=>'Lime'},
'Ëüãïò Øõ÷ùöåëÞò êáé ÈáõìÜóéïò => ' ),
popup_menu( -name=>'select',
-values=>\@display_files ),
submit('ok'));
print end_form(), br();
$keimeno = param('select') or "Áñ÷éêÞ Óåëßäá";
$st = $db->prepare( "SELECT host FROM logs" );
$st->execute();
while( $row = $st->fetchrow_hashref ) {
if( $host eq $row->{host} ) {
$hostmatch = 1;
}
}
if( param('select') and param('select') !~ /\.\./ )
{
open(FILE, "<../data/text/$keimeno.txt") or die $!;
@data = <FILE>;
close(FILE);
$data = join('', @data);
$db->do( "UPDATE logs SET keimeno='$keimeno' WHERE host='$host'" )
or die $db->errstr;
}
elsif( $hostmatch == 1 )
{
$db->do( "UPDATE logs SET visits = visits + 1 WHERE host='$host'" )
or die $db->errstr;
$st = $db->prepare( "SELECT * FROM logs WHERE host='$host'" );
$st->execute();
$row = $st->fetchrow_hashref;
$data = "Êáëþò Þñèåò " .$host. "! ×áßñïìáé ðïëý ðïõ óå îáíáâëÝðù!\n" .
"Ôåëåõôáßá öïñá Þñèåò åäþ ùò " .$row->{host}. " óôéò "
.$row->{xronos}. " !!\n" .
"ÁõôÞ åßíáé ç " .$row->{visits}. " öïñÜ ðïõ åðéóêÝöôåóáé ôçí
óåëßäá ìïõ êáé ÷áßñïìáé ðïëý ðïõ ôçí âñßóêåéò åíäéáöÝñïõóá !!!\n" .
"Ôçí ôåëåõôáßá öïñÜ äéÜâáóåò ôï êåßìåíï [ "
.$row->{keimeno}. " ]\n" .
"Ðïéo ëüãï èá Þèåëåò íá ìåëåôÞóåéò áõôÞí ôç öïñÜ ?!?";
}
elsif( $hostmatch != 1 )
{
if ( $host ne "ÁÖÅÍÔÉÊÏ" )
{
$data = "Êáëþò üñéóåò " .$host. "!\n" .
"ÁõôÞ åéíáé ç 1ç óïõ åðßóêåøç åäþ ðÝñá! Åëðßæù íá óïõ
áñÝóåé!\n" .
"Áíïßãïíôáò ôï ðáñáðÜíù drop-down menu åðÝëåîå ôï êåßìåíï
ðïõ èá Þèåëåò íá äéáâÜóåéò...";
$db->do( "INSERT INTO logs VALUES (null, '$host', '$xronos',
'$text', 1)" ) or die $db->errstr;
}
else
{
$data = "Ôé ÷áìðÜñéá $host :-) ÈõìÞèçêåò íá ìå ðåñéðïéçèåßò êáé
åìÝíá ëéãÜêé !?!";
}
}
$data =~ s/\n/\\n/g;
$data =~ s/"/\\"/g;
$data =~ tr/\cM//d;
#*******************************************************************************
print <<ENDOFILETML;
<html><head><title></title>
<script type='text/javascript'>
var textToShow = "$data";
var tm;
var pos = 0;
var counter = 0;
function init()
{ tm = setInterval("type()", 45) }
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>
<body onload=init()>
<center>
<div id="DivText" align="Left" style="
background-image: url(../data/images/kenzo.jpg);
border: Ridge Orange 5px;
width: 850px;
height: 500px;
color: LightSkyBlue;
font-family: Times;
font-size: 18px;">
</div
ENDOFILETML
#*******************************************************************************
print br(), br(), br();
print start_form(-action=>'show.pl');
print table( {class=>'user'},
Tr( td( 'Ðþò óå ëÝíå áäåëöÝ?' ),
td( textfield( 'onoma' ))),
Tr( td( 'ÐïéÜ åßíáé ç ãíþìç óïõ ãéá ôçí åõ÷ïýëá
*Êýñéå Éçóïý ×ñéóôÝ ÅëÝçóïí Ìå* ?' ),
td( textarea( -name=>'euxoula', -rows=>4, -columns=>25 ))),
Tr( td( 'ÌïéñÜóïõ ìáæß ìáò ìßá êáôÜ ôç ãíþìç óïõ
èáõìáóôÞ ðñïóùðéêÞ ðíåõìáôéêÞ åìðåéñßá áðü
êÜðïéïí ãÝñïíôá ðñïò þöåëïò ôùí õðïëïßðùí
áäåëöþí (áí öõóéêÜ Ý÷åéò :-)' ),
td( textarea( -name=>'sxolio', -rows=>6, -columns=>25 ))),
Tr( td( 'Ðïéü åßíáé ôï e-mail óïõ?' ),
td( textfield( 'email' ))),
Tr( td( submit( 'ÅìöÜíéóç üëùí ôùí áðüøåùí' )),
td( submit( 'ÁðïóôïëÞ' ))),
);
print end_form(), br(), br();
open(FILE, "<../data/text/tips") or die $!;
@tips = <FILE>;
close(FILE);
@tips = grep { !/^\s*\z/s } @tips;
$tip = $tips[int(rand(@tips))];
print table( {class=>'quote'},
Tr( td( $tip ))
);
$db->do( "UPDATE counter SET counter = counter + 1" ) if ($host ne
"ÁÖÅÍÔÉÊÏ");
$st = $db->prepare( "SELECT counter FROM counter" );
$st->execute();
$row = $st->fetchrow_hashref;
print br();
print table( {class=>'info'},
Tr( td( $host )),
Tr( td( $xronos )),
Tr( td( $row->{counter} ))
);
print br(), a( {href=>'games.pl'},
img{src=>'../data/images/games.gif'} );
print p( {-align=>'right'}, a( {href=>'show.pl?onoma=showlog'}, font(
{-size=>2, -color=>'Lime'}, b( 'Last Update: 18/4/2005' ))));
You can see that in my index.pl i dont any more have the long-lines
prints with width,height afont stuff since i created the style.css
here it is also btw:
/* style.css */
body {
background-image : url(../data/images/night.gif);
position : relative;
margin : 0px;
padding : 0px;
width : 100%;
}
table.user {
background-image : url(../data/images/swirl.jpg);
width : 55%;
color : lime;
text-align : center;
font : 18px times;
border : 5px ridge magenta;
border-collapse: : collapse;
}
table.quote {
background-image : url(../data/images/nebula.jpg);
width : 80%;
color : yellow;
text-align : center;
font : 18px comic;
border : 3px ridge lime;
border-collapse: : collapse;
}
table.info {
background-image : url(../data/images/nebula.jpg);
width : 25%;
color : cyan;
text-align : center;
font : 18px comic;
border : 3px ridge orange;
border-collapse: : collapse;
td {
border : 2px inset yellow;
}
td.tip {
font-style : bold;
color : white;
}
td.host {
font-style : bold;
color : yellow;
}
td.xronos {
font-style : bold;
color : lime;
}
td.counter {
font-style : bold;
color : white;
}
Its up to you now if you want to make the covertion.
ps. Sorry for the long copy/pastes but i dont know how to attach files
in usenet.
------------------------------
Date: Thu, 21 Apr 2005 07:18:46 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: How to call the remains of a pattern match
Message-Id: <slrnd6f6h6.8u6.tadmc@magna.augustmail.com>
Jure Simsic <jure.simsic@mobitel.si> wrote:
> Tad McClellan wrote:
>
>> Jim Gibson <jgibson@mail.arc.nasa.gov> wrote:
>> > In article <Fzv9e.11590$F6.2306405@news.siol.net>, Jure Simsic
>>
>> >> &sub( ${what's left of $a} )
>>
>>
>> > 2. There is no need to put ampersand (&) in front of function call.
>>
>>
>> Unless you've been so silly as to use a reserved word as the
>> function name, like this OP did.
>
> In fact I didn't.
Yes you did, it is quoted above for all to see.
> It was just a code example,
It was a code example that used a reserved word as the function name.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 21 Apr 2005 03:26:11 -0700
From: marc.eggenberger@itc.alstom.com
Subject: Re: How to test if a string is already in a array
Message-Id: <1114079171.147734.287720@o13g2000cwo.googlegroups.com>
ok ... I changed it .. but when I run my new script it prints adresses
more than once .. why is that?
Here's my code:
#!/usr/bin/perl
use strict;
use warnings;
my $textfile = 'empfaenger.txt';
open(EMPFAENGER, $textfile) || die("Could not open file $textfile");
my @raw_data = <EMPFAENGER>;
my %ad_hash;
foreach my $line (@raw_data)
{
my @fields = split(/ /, $line);
my @fields2 = split(/=/, $fields[6]);
my $address = $fields2[1];
$address = substr($address,1,length($address) - 3);
if(index($address,"domain.ch") > 0)
{
$ad_hash{$address} = 1;
}
foreach my $key(keys(%ad_hash))
{
print $key . "\n";
}
}
close(EMPFAENGER);
------------------------------
Date: 21 Apr 2005 03:36:19 -0700
From: marc.eggenberger@itc.alstom.com
Subject: Re: How to test if a string is already in a array
Message-Id: <1114079779.141628.59020@z14g2000cwz.googlegroups.com>
Argl ....
my last foreach shouldn't be in the foreach loop ...
stupid me ;)
------------------------------
Date: 21 Apr 2005 10:36:40 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: How to test if a string is already in a array
Message-Id: <Xns963F38C29ECA3castleamber@130.133.1.4>
wrote:
> ok ... I changed it .. but when I run my new script it prints adresses
> more than once .. why is that?
because you print the keys inside the loop
> Here's my code:
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> my $textfile = 'empfaenger.txt';
>
> open(EMPFAENGER, $textfile) || die("Could not open file $textfile");
open my $fh, $textfile or die "Can't open '$textfile': $!";
$! = why it didn't work, if you don't print that, you get quite a
meaningless error
> my @raw_data = <EMPFAENGER>;
if you do this, you can close now, not after the loop, or:
my %ad_hash;
while ( my $line = <$fh> ) {
> my %ad_hash;
>
> foreach my $line (@raw_data)
> {
> my @fields = split(/ /, $line);
> my @fields2 = split(/=/, $fields[6]);
> my $address = $fields2[1];
> $address = substr($address,1,length($address) - 3);
this probably could be done in a shorter way :-D
> if(index($address,"domain.ch") > 0)
> {
> $ad_hash{$address} = 1;
> }
$ad_hash{ $address } = 1 if index( $address, "domain.ch") > 0;
}
or:
index( $address, "domain.ch" ) > 0 and $ad_hash{ $address } = 1;
}
or:
index( $address, "domain.ch" ) > 0 or next;
$ad_hash{ $address } = 1;
}
then close:
close $fh or die "Can't close '$textfile': $!";
> foreach my $key(keys(%ad_hash))
> {
> print $key . "\n";
> }
You can write the print as:
print "$key\n";
a shorter way to write the print all:
print "$_\n" for keys %add_hash;
or
print map { "$_\n } keys %add_hash;
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Thu, 21 Apr 2005 07:25:19 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: How to test if a string is already in a array
Message-Id: <slrnd6f6tf.8u6.tadmc@magna.augustmail.com>
marc.eggenberger@itc.alstom.com <marc.eggenberger@itc.alstom.com> wrote:
> if(index($address,"domain.ch") > 0)
What would index() return if
$address = 'domain.ch';
??
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 21 Apr 2005 07:24:09 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: How to test if a string is already in a array
Message-Id: <slrnd6f6r9.8u6.tadmc@magna.augustmail.com>
Marc Eggenberger <marc.eggenberger@itc.alstom.com> wrote:
> I havent done perl coding for some years now and forgot a lot so bear
> with me ...
You are still expected to check the Perl FAQ *before* posting.
> a lot of dublicate mail addresses. I only need each
> emailaddress once
The answer is easy to find once you spell the search term correctly:
perldoc -q duplicate
How can I remove duplicate elements from a list or array?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 21 Apr 2005 09:03:50 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: How to test if a string is already in a array
Message-Id: <AoCdnffOXtErOfrfRVn-gA@adelphia.com>
Tad McClellan wrote:
> Marc Eggenberger <marc.eggenberger@itc.alstom.com> wrote:
>
>>a lot of dublicate mail addresses.
> The answer is easy to find once you spell the search term correctly:
>
> perldoc -q duplicate
There's a "dubya" joke in there somewhere... :-)
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Thu, 21 Apr 2005 12:11:17 GMT
From: daveindallasNOSPAM@comcast.nut (Dave in Dallas)
Subject: Re: More cognitive dissonance...
Message-Id: <42679835.42326750@decaxp.HARVARD.EDU>
On Wed, 20 Apr 2005 14:29:48 -0500, "Rudeney" <rudeney@mickeypics.com>
wrote:
>Dave in Dallas wrote:
>> Disapointed that the fake Dave in Dallas isn't getting your clothes
>> really sparkeling clean? Accept no substitutes. There is only one Dave
>> in Dallas. Look for the Good Housekeeping seal of approval.
>>
>> Dave in Dallas - The one and only.
>
>Yes, the "real" Dave is like Certified Angus Beef. This other guy is
>another by-product of cattle.
I bet you would like me better if you were the recipient of my
patented "deep throat" technique.
------------------------------
Date: Thu, 21 Apr 2005 03:21:54 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Perl and vmstat
Message-Id: <DoSdnXZRDvdY4_rfRVn-rw@comcast.com>
usaims wrote:
> my @memusage = system("vmstat -n 1 | awk '{print \$14}'");
>
> If I have missed something in FAQ, apologies in advance.
The behavior of system() is a FAQ.
unix% perldoc -q "output of a command"
-Joe
------------------------------
Date: Thu, 21 Apr 2005 12:08:58 +0200
From: "Kim H. Jensen" <devnull@post4.tele.dk>
Subject: Re: Problem with multiple instances of a module
Message-Id: <42677bb2$0$239$edfadb0f@dread11.news.tele.dk>
Anno Siegel wrote:
> Kim H. Jensen <devnull@post4.tele.dk> wrote in comp.lang.perl.misc:
>
>>Hi, i thought i had this OO thing figured out, but apparantly not.
>>
>>I have a module i want to make multiple instances of
>>
>>All goes well with the first instance until i create a second instance,
>>then the first instance seems to be overwritten.
>>
>>I have made a small test module to demonstrate the problem
>>--------------------------------------------
>># perl module Testobject.pm
>>package Testobject;
>>
>>sub new
>>{
>>my $class=shift;
>>my $self={};
>>$self{'id'}=shift;
>>bless ($self, $class);
>>print "New $self{'id'} - Self: $self\n";
>>return $self;
>>}
>>
>>
>>sub showid
>>{
>>my $self=shift;
>>my $caller=shift;
>>print "ID: $self{'id'} - Caller: $caller - Self: $self\n";
>>}
>>
>>
>>sub DESTROY
>>{
>>print "Bye-bye $self{'id'}\n";
>>}
>>
>>1;
>>--------------------------------------------
>>
>>
>>And a small test program
>>--------------------------------------------
>>#!/usr/bin/perl -w
>>
>>use Testobject;
>>
>>$inst_1=Testobject->new("Inst-1");
>>$inst_1->showid("Inst_1");
>>
>>$inst_2=Testobject->new("Inst-2");
>>$inst_1->showid("Inst_1");
>>$inst_2->showid("Inst_2");
>>
>>undef($inst_2);
>>$inst_1->showid("Inst_1");
>>--------------------------------------------
>>
>>
>>When i run the program it outputs:
>>--------------------------------------------
>>New Inst-1 - Self: Testobject=HASH(0x2850e0)
>>ID: Inst-1 - Caller: Inst_1 - Self: Testobject=HASH(0x2850e0)
>>New Inst-2 - Self: Testobject=HASH(0x2851a0)
>>ID: Inst-2 - Caller: Inst_1 - Self: Testobject=HASH(0x2850e0)
>>ID: Inst-2 - Caller: Inst_2 - Self: Testobject=HASH(0x2851a0)
>>Bye-bye Inst-2
>>ID: Inst-2 - Caller: Inst_1 - Self: Testobject=HASH(0x2850e0)
>>Bye-bye Inst-2
>>--------------------------------------------
>>
>>When instance 2 is created, instance 1 takes on the identity of instance 2.
>>
>>What have i overlooked?
>
>
> You are not using strict, which allows you to use package variables
> by mistake. Also, you are trying to access a hashref like a hash
> "$hashref{ key}" when you should use "$hashref->{ key}".
>
> Add "use strict" and see for yourself. You'll notice that some of your
> variables aren't what you think they are. I believe you'll be able to
> fix the program with the help of the messages you'll see.
>
> Anno
Yes, i see what you mean. I have my test program running now.
The realworld module also has som filehandles wich needs to be passed
around, but i think i have that worked out now, thanks to this page:
http://www.stonehenge.com/merlyn/LinuxMag/col10.html
Rgds Kim
------------------------------
Date: Thu, 21 Apr 2005 12:43:48 +0000 (UTC)
From: J Krugman <jkrugman345@yahbitoo.com>
Subject: Re: Q on BEGIN and INIT
Message-Id: <d48764$dse$1@reader1.panix.com>
Thanks! Much appreciated.
I have come across a couple of passing mentions to the effect that
"INIT is broken", and I wonder if it has anything to do with the
quote from the mod_perl book. I'm trying to get to the bottom of
it; I guess I'll have to start "wading through the deltas". :)
jill
--
To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
------------------------------
Date: 21 Apr 2005 05:29:30 -0700
From: "mike" <hillmw@charter.net>
Subject: Using Bind Params in MySQL
Message-Id: <1114086570.631506.246940@g14g2000cwa.googlegroups.com>
I am using MySQL and this was working, but all of sudden it is not. I
suspect that I have some kind of error, but my error logic must not be
working.
I am getting "Insert - Complete", but no data is getting inserted to
the table.
$sql = "insert into my_posts ( type, head, head_date, msg, trans_date,
poster ) values ( ?, ?, ?, ?, ?, ? )";
$sth = $dbh->prepare( $sql );
if ( !defined $sth )
{
print "Cannot prepare statement: $DBI::errstr\n";
}
else
{
$sth->bind_param('1', $type); $sth->bind_param('2', $head);
$sth->bind_param('3', $head_date); $sth->bind_param('4', $msg);
$sth->bind_param('5', $trans_date); $sth->bind_param('6', $poster);
eval { $sth->execute; };
if ( $@ )
{
print "Error in the database: $@";
}
else
{
# execute worked was success
print "<center><b>Insert - Complete</b></center>\n";
}
}
Any help is appreciated.
Mike
------------------------------
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 8001
***************************************