[22270] in Perl-Users-Digest
Perl-Users Digest, Issue: 4491 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 30 21:05:43 2003
Date: Thu, 30 Jan 2003 18:05:09 -0800 (PST)
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, 30 Jan 2003 Volume: 10 Number: 4491
Today's topics:
Re: $G->add_weighted_edge($u, $w, $v, $a) "the uknown $ (Anno Siegel)
Re: $G->add_weighted_edge($u, $w, $v, $a) "the uknown $ <mgjv@tradingpost.com.au>
Re: $G->add_weighted_edge($u, $w, $v, $a) "the uknown $ <spam@thecouch.homeip.net>
Re: ActivePerl 5.8 / MySQL / Apache Problem <alex@alexbanks.com>
Re: ActivePerl 5.8 / MySQL / Apache Problem <alex@alexbanks.com>
Re: ActivePerl 5.8 / MySQL / Apache Problem <alex@alexbanks.com>
Re: Checking for a file <bongie@gmx.net>
Re: Checking for a file <eric.ehlers@btopenworld.com.nospam>
Re: Checking for a file (Brandon Reddish)
Re: Comparing files with difference percentage (Vinicio Tavares)
creating a binary file with desired size (James Lee)
Creating my own Guestbook. (Brandon Reddish)
Re: Email attachment with IO::Socket <someone@somewhere.nl>
Re: Email attachment with IO::Socket <spam@thecouch.homeip.net>
Re: Email attachment with IO::Socket <noreply@gunnar.cc>
Re: Fetchrow Question (Andrew Allaire)
Re: How to find @INC in a mod_perl compiled httpd binar (Anno Siegel)
Re: How to find @INC in a mod_perl compiled httpd binar <ajglist@izzy.net>
Re: How to search a file (newbie) <ajglist@izzy.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 30 Jan 2003 23:22:21 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: $G->add_weighted_edge($u, $w, $v, $a) "the uknown $a variable"
Message-Id: <b1cc3d$m8f$1@mamenchi.zrz.TU-Berlin.DE>
Alexandros <a_valarakos@hotmail.com> wrote in comp.lang.perl.misc:
> I found the following:
Where?
> "$G->add_weighted_edge($u, $w, $v, $a)
> Adds in the graph $G an edge from vertex $u to vertex $v and the edge
> attribute 'weight' set to $w."
> They forgot to say something about the variable $a?????
>
> Any suggestion?
No, not without knowing the module this is from. If $a is indeed
undocumented, there's only the source. So where is it?
Anno
------------------------------
Date: Fri, 31 Jan 2003 00:43:05 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: $G->add_weighted_edge($u, $w, $v, $a) "the uknown $a variable"
Message-Id: <slrnb3jhko.se5.mgjv@verbruggen.comdyn.com.au>
On Thu, 30 Jan 2003 23:49:52 +0200,
Alexandros <a_valarakos@hotmail.com> wrote:
> I found the following:
>
> "$G->add_weighted_edge($u, $w, $v, $a)
> Adds in the graph $G an edge from vertex $u to vertex $v and the edge
> attribute 'weight' set to $w."
Why do you assume that we all know which module this particular
function is from? Why don't you help us a bit and tell us which module
this is from?
> They forgot to say something about the variable $a?????
They? If this module came from CPAN, these "They: are most likely
mentioned as the authors of the module somewhere. If so, you should
probably ask them. If not, contact the person who provided you with
the module in the first place. The author of the software is always
the best person to contact about this sort of thing.
> Any suggestion?
Yep. See above. This seems to be from the Graph:: modules, available
from CPAN, so I suggest you ask Jarkko Hietaniemi, who is the current
owner of the modules. Alternatively, since these modules were written
as part of "Mastering Algorithms with Perl", you could see whether you
can use that book to find more information (or contact one of the
other authors, if Jarkko is unresponsive (unlikely)).
Yet another alternative is that you look at the source code for the
module, where you can see this:
=pod
=item add_weighted_edge
$G->add_weighted_edge($u, $w, $v, $a)
Adds in the graph $G an edge from vertex $u to vertex $v
and the edge attribute 'weight' set to $w.
=cut
sub add_weighted_edge {
my ($G, $u, $w, $v, $a) = @_;
$G->add_edge($u, $v);
$G->set_attribute('weight', $u, $v, $w);
}
To me it looks like $a is not used for anything. Looks like it's a
bug. They either forgot to use it, or they forgot to fix the
documentation, and clean up the code. Anyway, only the author knows.
Hopefully you'll now be able to do this sort of thing for yourself, in
the future.
Martien
--
|
Martien Verbruggen |
Trading Post Australia | Can't say that it is, 'cause it ain't.
|
------------------------------
Date: Thu, 30 Jan 2003 19:54:29 -0500
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: $G->add_weighted_edge($u, $w, $v, $a) "the uknown $a variable"
Message-Id: <9Pj_9.10468$F75.80197@wagner.videotron.net>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Alexandros wrote:
| I found the following:
|
| "$G->add_weighted_edge($u, $w, $v, $a)
| Adds in the graph $G an edge from vertex $u to vertex $v and the edge
| attribute 'weight' set to $w."
| They forgot to say something about the variable $a?????
... and you forgot to mention which module you're talking about (:
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE+OclFeS99pGMif6wRAnLiAJ41qz1t49+6mpWDlvXyc3Hd9vUMdQCgqhjX
t37U8JsjRZOw4N6yLTi34MY=
=CAIU
-----END PGP SIGNATURE-----
------------------------------
Date: Thu, 30 Jan 2003 23:58:29 -0000
From: "Alex Banks" <alex@alexbanks.com>
Subject: Re: ActivePerl 5.8 / MySQL / Apache Problem
Message-Id: <3e39bc28$0$246$cc9e4d1f@news.dial.pipex.com>
> I'm not quite sure why this seems necessary, but try putting
> the path to your mysql installation dlls (eg, C:\mysql\lib\opt,
> where libmySQL.dll resides) in your PATH environment variable.
Thanks Randy.
I tried this but had no joy unfortunately. I checked that libmySQL.dll was
in the dir you mentioned, then appended to my PATH using the Environmental
variables option under Administrative Tools --> Control Panel. I fired up a
DOS prompt to check that %PATH% still held - it did.
Have you any other ideas?
------------------------------
Date: Fri, 31 Jan 2003 00:17:49 -0000
From: "Alex Banks" <alex@alexbanks.com>
Subject: Re: ActivePerl 5.8 / MySQL / Apache Problem
Message-Id: <3e39c0b0$0$233$cc9e4d1f@news.dial.pipex.com>
> Thanks Randy.
>
> I tried this but had no joy unfortunately. I checked that libmySQL.dll was
> in the dir you mentioned, then appended to my PATH using the Environmental
> variables option under Administrative Tools --> Control Panel. I fired up
a
> DOS prompt to check that %PATH% still held - it did.
>
> Have you any other ideas?
Another snippet of information which might help people to identify my
problem...
#!/perl/bin/perl -w
use DBI;
$dbh = DBI->connect("DBI:mysql:$dbname",$dbuser,$dbpassword);
my $sql = "select statement here";
my $rs = $dbh -> prepare($sql);
$rs->execute;
print "Content-type: text/html\n\n";
print $rs->rows;
Running this from a DOS prompt works fine - I get the result I expect of 10
rows returned. But when I run the script through a browser from the cgi-bin
directory, I get this error in the log... All my non-database web-served
scripts work just fine!
[Fri Jan 31 00:15:25 2003] [error] [client 127.0.0.1] install_driver(mysql)
failed: Can't load 'C:/Perl/site/lib/auto/DBD/mysql/mysql.dll' for module
DBD::mysql: load_file:The specified module could not be found at
C:/Perl/lib/DynaLoader.pm line 229.
[Fri Jan 31 00:15:25 2003] [error] [client 127.0.0.1] at (eval 1) line 3
[Fri Jan 31 00:15:25 2003] [error] [client 127.0.0.1] Compilation failed in
require at (eval 1) line 3.
Any more suggestions would be really helpful.
Alex
------------------------------
Date: Fri, 31 Jan 2003 00:48:10 -0000
From: "Alex Banks" <alex@alexbanks.com>
Subject: Re: ActivePerl 5.8 / MySQL / Apache Problem
Message-Id: <3e39c7ce$0$247$cc9e4d1f@news.dial.pipex.com>
Okay... truly bizarre. I'm having a conversation with myself here, but I
solved the problem anyway so I'm happy.
It's a bit messy, but I copied the \mysql\lib\opt\libmySQL.dll file to
C:/Perl/site/lib/auto/DBD/mysql/ and it worked.
Be interested to know if anyone can explain why!
Thanks all, Alex
------------------------------
Date: Fri, 31 Jan 2003 00:14:26 +0100
From: "Harald H.-J. Bongartz" <bongie@gmx.net>
Subject: Re: Checking for a file
Message-Id: <1346491.DWo4W7O3on@nyoga.dubu.de>
TBN wrote:
> "Michael Lang" <michi@relay3.jackal-net.at> wrote in message
> news:slrnb3ilgh.t72.michi@nuddelaug.jackal-net.at...
>> if (-f "$filename")
>> { do what ever; }
>
> Great Thanks! Your suggestion lead me to some other commands that I
> didn't
> know. Correct me if I'm wrong but it looks like the following code is
> *exactly* what I need...
>
> if (-e $a) { do stuff; }
-e $a tests if $a exists on the file system.
-f $a tests if $a exists *and* is a plain file (and not a directory,
pipe, socket, ...).
Choose the one that best matches your requirement.
Ciao,
Harald
--
Harald H.-J. Bongartz <bongie@gmx.net>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
I'm a great lover, I'll bet. -- Emo Phillips
------------------------------
Date: Thu, 30 Jan 2003 23:26:23 +0000 (UTC)
From: "eric" <eric.ehlers@btopenworld.com.nospam>
Subject: Re: Checking for a file
Message-Id: <b1ccau$i5g$1@sparta.btinternet.com>
"TBN" <ihave@noemail.com> wrote in message
news:sWc_9.27$28.35757@news.randori.com...
> "Michael Lang" <michi@relay3.jackal-net.at> wrote in message
> news:slrnb3ilgh.t72.michi@nuddelaug.jackal-net.at...
> > In article <cxc_9.25$28.33657@news.randori.com>, TBN wrote:
> > > I'm still pretty new to Perl, so bear with me on this probably simple
> > > question.
> > >
> > > I know that I can open a file using the following...
> > > open (CODE, $filename) || &OtherStuff;
> > >
> > > But I'm not really interested in opening this file. It's a trigger
file
> > > that tells me when it is or isn't ok to perform some action. So I
just
> want
> >
> > try using,
> >
> > if (-f "$filename")
> > { do what ever; }
> >
>
> Great Thanks! Your suggestion lead me to some other commands that I
didn't
> know. Correct me if I'm wrong but it looks like the following code is
> *exactly* what I need...
>
> if (-e $a) { do stuff; }
looks good to me. for info -
- $a and $b are special package variables used for sorting (see perlvar) and
if you reuse them unwittingly you can get strange results.
- &OtherStuff is the old-fashioned way to invoke a subroutine, the correct
syntax now is OtherStuff() (see perlsub). the &OtherStuff syntax is still
supported but it disables prototype checking and (in the absence of an
explicit parameter list) causes the current argument list @_ to be passed as
an argument to OtherStuff, unless that's specifically what you want you
shouldn't prepend & to subroutine calls.
- eric
------------------------------
Date: 30 Jan 2003 17:54:26 -0800
From: mechman991@hotmail.com (Brandon Reddish)
Subject: Re: Checking for a file
Message-Id: <60d818b.0301301754.47fb904e@posting.google.com>
Andrew Lee wrote in message news:<7tvi3vcu76thd2t5tqm3tjdvp9t708542s@4ax.com>...
> On Thu, 30 Jan 2003 16:37:29 GMT, "TBN" <ihave@noemail.com> wrote:
>
> >I'm still pretty new to Perl, so bear with me on this probably simple
> >question.
> >
> >I know that I can open a file using the following...
> >open (CODE, $filename) || &OtherStuff;
> >
> >But I'm not really interested in opening this file.
>
> perldoc perlfunc
>
> Look for -X FILEHANDLE ... the list of filetest operators.
Hello,
The easiest way to check to see if a file exists would be;
if (-e file.html)
{
Insert whatever here.
}
This checks to see if the file simply exists. Check this page for more information:
http://pageresource.com/cgirec/ptut17.htm
- Brandon
------------------------------
Date: 30 Jan 2003 16:15:30 -0800
From: vtmcs@terra.com.br (Vinicio Tavares)
Subject: Re: Comparing files with difference percentage
Message-Id: <a165b9fc.0301301615.25bdf712@posting.google.com>
"Bill Smith" <wksmith@optonline.net> wrote in message news:<XTc_9.454383$FT6.92787621@news4.srv.hcvlny.cv.net>...
> "Vinicio Tavares" <vtmcs@terra.com.br> wrote in message
> news:a165b9fc.0301300826.2d1dda98@posting.google.com...
> > I have 2 ascii files: text1.txt and text2.txt.
> >
> > Text1.txt Text2.txt
> > ----------------- --------------------
> > a a
> > b c
> > c c
> > d d
> > e e
> >
> > I want to compare the files returning the difference percentage. How
> > could I do this?
> >
> > In the example above it would return '20%'. As 1 of 5 chars doesn't
> > match.
>
>
>
> Quantifying the difference between files requires much more attention to
> requirements than you posting provides.
>
> How do I treat whitespace characters?
It ignores whitespaces in the end of the lines and blank lines in the
end of the file.
> What if one file has an extra or a missing character? Is everything
> after that mismatched?
> What if one character has been moved?
> What if a block of characters has been moved, possibly with changes
> within the moved block?
>
It compares the lines, if line 2 (file 1) has 1 character that doesn't
match with the character on line 2 (file 2) the lines doesn't match.
I will give a better example now. :-)
Text1.txt Text2.txt
---------------- -----------------
ab c ab c
a b d a b c
ab cd ef ab cd ef
abc abc
ab a b
abc
match: Lines 1, 4
mismatch: Lines 2, 3, 5
The difference percentage will be:
(# of mismaches + # of extra lines in one of the files) / # of
lines of file 1.
In the example:
3+1/6 = 0.66 = 66.6%
Vinicio
> In your example, you are counting only non-whitespace characters. You
> have only one non-whitespace character per line. In general, do you
> want to compare characters or lines?
>
> Finding unambiguous answers to all these questions is much harder that
> it seems. Hopefully, they do not all arise in your application.
>
> Perl is good choice of language to use for the implementation because it
> is so strong in text handling. I expect to see some interesting
> solutions once the requirements are clarified.
>
> Bill
------------------------------
Date: 30 Jan 2003 16:46:44 -0800
From: csejl@yahoo.com (James Lee)
Subject: creating a binary file with desired size
Message-Id: <146277ca.0301301646.62e40a15@posting.google.com>
hi,
i have a script that takes file name and size and creates a file of
the size specified. this is currently done with texts and i was
wondering if i can do this with binary files. thanks for your help in
advance.
-j.
------------------------------
Date: 30 Jan 2003 18:01:59 -0800
From: mechman991@hotmail.com (Brandon Reddish)
Subject: Creating my own Guestbook.
Message-Id: <60d818b.0301301801.2826407@posting.google.com>
I have the following form mail codes .. scroll to the bottom for my
question:
[ PS - This form can be run at http://65.190.228.165/post.html instead
of looking through all this code. Feel free to test it out, but each
new post overwrites any old ones. ]
[ This is the form itself: ]
<html>
<head>
<title>Test</title>
<style>
input, textarea {font-family: verdana,tahoma; font-size:7.5pt;
color:#003366; border-width:1pt; border-style:solid;
border-color:#990000}
body { scrollbar-3d-light-color: #FFFFFF; scrollbar-arrow-color:
#000000; scrollbar-base-color: #990000; scrollbar-dark-shadow-color:
#FFFFFF; scrollbar-face-color: #FFFFFF; scrollbar-highlight-color:
#ffffff; scrollbar-shadow-color: #FFFFFF };
</style>
<script>
function submitonce(theform){
//if IE 4+ or NS 6+
if (document.all||document.getElementById){
//screen thru every element in the form, and hunt down "submit" and
"reset"
for (i=0;i<theform.length;i++){
var tempobj=theform.elements[i]
if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
//disable em
tempobj.disabled=true
}
}
}
</script>
<script>
/*
Form field Limiter script- By Dynamic Drive
For full source code and more DHTML scripts, visit
http://www.dynamicdrive.com
This credit MUST stay intact for use
*/
var ns6=document.getElementById&&!document.all
function restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}
function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] :
document.getElementById(placeholder)
if (window.event||e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}
function displaylimit(theform,thelimit){
var limit_text='<b><span
id="'+theform.toString()+'">'+thelimit+'</span></b> characters
remaining.<br>'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return
restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) {
restrictinput(thelimit,event,theform) }, true);
document.body.addEventListener('keyup', function(event) {
countlimit(thelimit,event,theform) }, true);
}
}
</script>
</head>
<body>
<form name="form" method="post" action="/cgi-bin/testform.cgi"
onSubmit="submitonce(this)">
Name:<br><input type="text" size="15" name="name"></input><br>
<script>
displaylimit('document.form.name',30)
</script>
Age:<br><input type="text" name="age" size="2"><br>
<script>
displaylimit('document.form.age',2)
</script>
Comments:<br><textarea cols="30" rows="7"
name="comments""></textarea><br><br>
<script>
displaylimit('document.form.comments',255)
</script>
<input type="submit" value="Send">
</form>
</body>
</html>
----------[ This is the form that recieves the data and writes it to
an html file: ]
#!/usr/bin/perl
require "cgi-lib.pl";
&ReadParse(*input);
$name= $input{'name'};
$age= $input{'age'};
$comments= $input{'comments'};
$view= "/htdocs/view.html";
$page= "/view.html";
open(DAT,">$view") || die("Cannot Open File");
if (-e $view)
{
print DAT <<ENDHTML;
<html>
<body>
<head>
<title>Results</title>
<style>
input, textarea, table {font-family: verdana,tahoma; font-size:7.5pt;
color:#000000; border-width:1pt;
border-style:solid; border-color:#990000}
</style>
</head>
<table width="250" border="0">
<tr bgcolor="#990000">
<td><font color="#FFFFFF">Name:</font></td>
</tr>
<tr>
<td>$name</td>
</tr>
<tr bgcolor="#990000">
<td><font color="#FFFFFF">Age:</font></td>
</tr>
<tr>
<td>$age</td>
</tr>
<tr bgcolor="#990000">
<td><font color="#FFFFFF">Comments:</font></td>
</tr>
<tr>
<td>$comments</td>
</tr>
</table>
</body>
</html>
ENDHTML
}
close(DAT);
print "Content-type: text/html\n\n";
print <<ENDHTML;
<html>
<head>
<title>Redirect</title>
</head>
<body>
<script>
window.location.replace("/view.html")
</script>
</body>
</html>
ENDHTML
--------[ Lastly, this is what the .cgi form writes: ]
<html>
<body>
<head>
<title>Results</title>
<style>
input, textarea, table {font-family: verdana,tahoma; font-size:7.5pt;
color:#000000; border-width:1pt;
border-style:solid; border-color:#990000}
</style>
</head>
<table width="250" border="0">
<tr bgcolor="#990000">
<td><font color="#FFFFFF">Name:</font></td>
</tr>
<tr>
<td>sdfgsdfg</td>
</tr>
<tr bgcolor="#990000">
<td><font color="#FFFFFF">Age:</font></td>
</tr>
<tr>
<td>sd</td>
</tr>
<tr bgcolor="#990000">
<td><font color="#FFFFFF">Comments:</font></td>
</tr>
<tr>
<td>sdfgsdfg</td>
</tr>
</table>
</body>
</html>
------------------------------------
I am using the cgi-lib.pl to grab the info and send it. Anyways, my
question is, how would I use the form information to append the
information to a file, but only include the <html> tags at the very
top and very bottom of the page, without repeating it? Example:
Someone posts a message. The .cgi writes this file:
<html>
<body>
Test number 1
</body>
</html>
Now, I have the script to write of the file instead of appending to
it. If I append to it, this is what would happen:
<html>
<body>
Test number 1
</body>
</html>
<html>
<body>
Test number 2
</body>
</html>
Notice the repeat of <html> tags and such? I don't want that. This
is what I want to happen:
<html>
<body>
Test number 1
Test number 2
</body>
</html>
You get the idea. How do I have the form to append to the center of a
file? Thanks!
- Brandon
------------------------------
Date: Fri, 31 Jan 2003 00:33:03 +0100
From: "Stefan" <someone@somewhere.nl>
Subject: Re: Email attachment with IO::Socket
Message-Id: <3e39b62e$0$132$e4fe514c@dreader4.news.xs4all.nl>
"ColdCathoids" <mememe@meme.com> schreef in bericht
news:b1c97c$11qmld$1@ID-158028.news.dfncis.de...
> Hello all,
>
> First off thanks to everyone who helped me with my more random then random
> question earlier this week! Works exactly how I wanted. Now I have another
> question.
>
> I am writing a small app that sends out an email when a co-worker moves
> files. The box this runs on is somewhat limited with modules so I was
forced
> to use IO::Socket to send email. It's working fine but I was wondering if
> anyone knew of a way I could send email attachments using the sub below. I
> am not able to install any modules on this box so I have to work with what
I
> got. Any thoughts?
>
>
>
> sub sendMail {
> my ($host, $from, $to, $subject, $message) = @_;
> require IO::Socket;
> my $remote = IO::Socket::INET->new(
> Proto => "tcp",
> PeerAddr => $host,
> PeerPort => "smtp(25)",
> )
> or die $!;
> my $debug = <$remote>;
> print $remote "MAIL FROM: $from\n";
> $debug .= <$remote>;
> print $remote "RCPT TO: $to\n";
> $debug .= <$remote>;
> print $remote "DATA\n";
> $debug .= <$remote>;
> print $remote "From: $from\nTo: $to\nSubject: $subject\n\n";
> print $remote "$message\n";
> print $remote ".\n";
> $debug .= <$remote>;
> close $remote;
> return $debug;
> }
>
The module MIME::Base64 (Base64.pm) contains a sub-routine you can "borrow",
change and include in your source. I'm already using an
email-attachments-without-modules program and I include the necessary parts
in this post. For your convenience and for any future googlers.
The code below is almost ready for you to use. Since you use a
socket-connection, you must change the print-statement but I think you'll
manage. Note that it also add the MIME header. This way, the attachment is
actually treated as such. The rest is commented in the code. Anything
missing or not working properly because its taken out of context, is left as
an excercise for the reader ..... ;)
Bye,
Stefan
# ----- Filename definitions
my($filename) = "the real name of you attachment file";
my($attachment) = "the name of the file as attached";
# ----- MIME email header
print "MIME-Version: 1.0\n";
print "Content-Type: multipart/mixed; ",
"boundary=\"----_=_NextPart_BibServ_Data\"\n";
print "\n";
print "This message is in MIME format. Since your mail reader does not
understand\n";
print "this format, some or all of this message may not be legible.\n";
# ----- Attachment
print "------_=_NextPart_Data\n";
print "Content-Type: application/octet-stream; name=\"$attachment\"\n";
print "Content-Transfer-Encoding: base64\n";
print "Content-Disposition: attachment; filename=\"$attachment\"\n";
print "\n";
# ----- Include a base64 encoded attachment
open(FILE, "< $filename") || die "Error opening $filename - $!\n";
my($buffer);
while (read(FILE, $buffer, 60*57)) { print Encode_Base64($buffer); }
close(FILE);
# ----- Close MIME email-header
print "\n";
print "------_=_NextPart_Data\n";
..... and for the Encode_Base64 routine .....
#
# Encode_Base64 code extracted from MIME/Base64.pm (written by Gisle Aas).
#
sub Encode_Base64 ($;$)
{
my $res = "";
my $eol = $_[1];
$eol = "\n" unless defined $eol;
pos($_[0]) = 0; # ensure start at the beginning
while ($_[0] =~ /(.{1,45})/gs) {
$res .= substr(pack('u', $1), 1);
chop($res);
}
$res =~ tr|` -_|AA-Za-z0-9+/|; # `# help emacs
# fix padding at the end
my $padding = (3 - length($_[0]) % 3) % 3;
$res =~ s/.{$padding}$/'=' x $padding/e if $padding;
# break encoded string into lines of no more than 76 characters each
if (length $eol) { $res =~ s/(.{1,76})/$1$eol/g; }
$res;
}
# --------------------------------------------------------------------------
----
------------------------------
Date: Thu, 30 Jan 2003 19:57:51 -0500
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: Email attachment with IO::Socket
Message-Id: <jSj_9.10470$F75.81246@wagner.videotron.net>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
ColdCathoids wrote:
| Hello all,
|
| First off thanks to everyone who helped me with my more random then random
| question earlier this week! Works exactly how I wanted. Now I have another
| question.
|
| I am writing a small app that sends out an email when a co-worker moves
| files. The box this runs on is somewhat limited with modules so I was forced
| to use IO::Socket to send email. It's working fine but I was wondering if
| anyone knew of a way I could send email attachments using the sub below. I
| am not able to install any modules on this box so I have to work with what I
| got. Any thoughts?
I'm not going to even bother with the snippet of code you posted. Sending
attachments through raw socket calls it too much re-inventing the wheel.
Instead I'll focus on why you can't install modules on the box. Is it because
you do not have root access ? There are several clear documents out there
describing how you can install and use perl modules from your home directory
without requiring root access.
Once that point's resolved, your question can be answered with 1-3 lines using
the appropriate module...
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE+OcoPeS99pGMif6wRAgZ8AKD0YUWqeqv+6IcTGazOT4/L7UD/qgCgg/xK
K+wLsS7B5jQSlLj2E0TEZ3g=
=ymqf
-----END PGP SIGNATURE-----
------------------------------
Date: Fri, 31 Jan 2003 01:20:16 GMT
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Email attachment with IO::Socket
Message-Id: <kbk_9.8356$FF4.518451@newsb.telia.net>
ColdCathoids wrote:
> I am not able to install any modules on this box
Can't you just use a 'local' library for additional modules you'd like
to use? For instance, in this case I'm thinking of the CPAN module
Mail::Sender, which is prepared for sending attachments.
Upload Sender.pm to /cgi-bin/lib/Mail, and include this in your app:
use lib '/path/to/lib';
use Mail::Sender;
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 30 Jan 2003 15:07:19 -0800
From: Andrew.Allaire@na.teleatlas.com (Andrew Allaire)
Subject: Re: Fetchrow Question
Message-Id: <6bdb91de.0301301507.46dce140@posting.google.com>
"Smiley" <smiley@uvgotemail.com> wrote in message news:<v3iv5ob6sa0u36@corp.supernews.com>...
> I've been using the recommended method for accessing data that is described
> in my reference books: fetchrow_array
>
> I was thinking, though, that a hash would be better suited to some of the
> programming I'm doing, and though I couldn't find reference to that in the
> books I have, sources online have led me to believe that I coudl use
> fetchrow_hash.
>
> It doesn't seem to work though, I get the following error in my error log:
>
> Can't locate object method "fetchrow_hash" via package "DBI::st" at
> changedata.cgi line 123.
>
> This is the line I used:
>
> my %userdata=$sth->fetchrow_hash();
>
> Can anybody tell me how I can make this work?
I have never heard of fetchrow_hash. Are you sure it wasn't supposed
to be fetchrow_hashref ?
Seems like fetchrow_hash would not make a lot of sense. ferchrow_array
is misnamed enough already--it does not return an array, it returns a
list.
Note the code:
my %userdata=$sth->fetchrow_hash();
isn't expecting a hash to be returned from the mehtod, it is expecting
a list of keys and values to be returned that is then loaded into the
hash %userdata.
my $rhUserData = $sth->fetchrow_hashref() ;
In this case you get a refernce to a hash. If you wanted to load it
into a hash called %userdate you could then do:
my %userdata = %$rhUserData ;
But why not use it as it comes?
------------------------------
Date: 30 Jan 2003 23:46:08 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How to find @INC in a mod_perl compiled httpd binary?
Message-Id: <b1cdg0$m8f$2@mamenchi.zrz.TU-Berlin.DE>
Kyndig <kyndig@knife-fighting.com> wrote in comp.lang.perl.misc:
> Could someone please help me find the @INC path of mod_perl which is
> already statically compiled into an Apache httpd binary?
>
> I'm upgrading an Apache server, but my newly compiled binary gives me
> a "Can't locate foo.pm in @INC" because the hard coded @INC path is
> aparently different than that of the original binary.
>
> I know the problem can be fixed by setting @INC or perl5libs or "use
> lib ...", but I want to change as little as possible; thus I need to
> know how to find the @INC of the old binary and how to set it(during
> compilation) on the new one to match. As I said, mod_perl is compiled
> in statically. Any help is greatly appreciated !
If you can't run the old Apache any more, tough. Otherwise, the solution
seems trivial: Write a CGI script that prints @INC with appropriate
headers. Or just provoke the "Can't locate..." error and check the log,
whatever works.
Anno
------------------------------
Date: Fri, 31 Jan 2003 00:44:03 GMT
From: Alan Gutierrez <ajglist@izzy.net>
Subject: Re: How to find @INC in a mod_perl compiled httpd binary?
Message-Id: <nFj_9.64504$GX4.2644333@news2.east.cox.net>
Kyndig wrote:
> Could someone please help me find the @INC path of mod_perl which is
> already statically compiled into an Apache httpd binary?
>
> I'm upgrading an Apache server, but my newly compiled binary gives me
> a "Can't locate foo.pm in @INC" because the hard coded @INC path is
> aparently different than that of the original binary.
>
> I know the problem can be fixed by setting @INC or perl5libs or "use
> lib ...", but I want to change as little as possible; thus I need to
> know how to find the @INC of the old binary and how to set it(during
> compilation) on the new one to match. As I said, mod_perl is compiled
> in statically. Any help is greatly appreciated !
After you figure out what is missing in @INC you can update your apache
conf, you don't have to rebuild apache.
Alan Gutierrez - ajglist@izzy.net
------------------------------
Date: Thu, 30 Jan 2003 23:15:41 GMT
From: Alan Gutierrez <ajglist@izzy.net>
Subject: Re: How to search a file (newbie)
Message-Id: <xmi_9.63954$GX4.2626007@news2.east.cox.net>
Helgi Briem wrote:
> On Thu, 30 Jan 2003 15:05:19 +0100, Josef
> =?iso-8859-1?Q?M=F6llers?=
> <josef.moellers@fujitsu-siemens.com> wrote:
>>> >Isn't Helgi's _real_ name Mario Girotti, aka Terence Hill? So ...
>>> No. Who are they? Google doesn't turn up any clpm
>>> posters under those names, although Terence Hill is
>>> a frequent troll in other groups. No one named "Mario
>>> Girotti" appears to have posted on Usenet ever.
>>Mario Girotti aka Terence Hill is an actor and the main
>>character in the Movie "My Name Is Nobody" (he also
>>starred in/as "Lucky Luke").
> Ahh, of course. I never knew Terence Hill's real name
> was Mario Girotti, hence no connection with the film.
> I did see it when I was a child, I think.
See it again. It is good film. I am surprised anyone remembers it. It
was a favorite of mine when I was a kid.
Alan Gutierrez - ajglist@izzy.net
------------------------------
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 4491
***************************************