[23971] in Perl-Users-Digest
Perl-Users Digest, Issue: 6172 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 21 11:05:40 2004
Date: Sat, 21 Feb 2004 08: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 Sat, 21 Feb 2004 Volume: 10 Number: 6172
Today's topics:
Re: can s/// return a new value, rather than modifying <bart.lateur@pandora.be>
Re: help on hash of hashes (Stephen Moon)
Re: how to cut a text file in perl $_@_.%_
html2text but preserving text links (Felix)
Re: html2text but preserving text links <jwillmore@remove.adelphia.net>
Re: I wish buy Perl book <matthew.garrish@sympatico.ca>
Re: I wish buy Perl book <jwillmore@remove.adelphia.net>
Re: IO::Socket::INET: Address already in use (hagen)
Re: Let browser say "done" immediately after parent fin <usenet@morrow.me.uk>
Re: Listbox and passing entries <noreply@gunnar.cc>
Mail::Sender problem <m.boom@con-x-com.nl>
Re: Mail::Sender problem <nospam@bigpond.com>
Re: Mail::Sender problem <m.boom@con-x-com.nl>
Re: perl fileio <toylet@mail.hongkong.com>
Re: perl fileio <tassilo.parseval@rwth-aachen.de>
Re: perl fileio <toylet_at_mail.hongkong.com>
Re: perl fileio <tadmc@augustmail.com>
Re: perl fileio <toylet_at_mail.hongkong.com>
PERL/MySQL tutorial <gp@nospm.hr>
Re: PERL/MySQL tutorial <nospam@bigpond.com>
Re: PERL/MySQL tutorial <exide@comcast.net>
Re: PERL/MySQL tutorial <toylet_at_mail.hongkong.com>
Re: Protecting Source code of a perl script <chatiman@free.fr>
replace unicode characters by &#number; representation <flavell@ph.gla.ac.uk>
Re: replace unicode characters by &#number; representat <usenet@morrow.me.uk>
Re: Unexplained output for PERL print statement <tadmc@augustmail.com>
very strange conditional problem <newz@xoftware.org>
Re: very strange conditional problem <kuujinbo@hotmail.com>
Re: very strange conditional problem <newz@xoftware.org>
Re: very strange conditional problem <newz@xoftware.org>
Re: very strange conditional problem <kuujinbo@hotmail.com>
Re: very strange conditional problem <tadmc@augustmail.com>
WWW::Mechanize error confusion (RP)
Re: WWW::Mechanize error confusion <jwillmore@remove.adelphia.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 21 Feb 2004 15:53:55 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: can s/// return a new value, rather than modifying it's input argument?
Message-Id: <jnve30laenb91ppvqgpmh4dtppe1vaa1lg@4ax.com>
Uri Guttman wrote:
>why do you return the last element of @values in scalar context?
Because that's what the comma operator does.
>wouldn't the first be just as arbitrary?
It would.
--
Bart.
------------------------------
Date: 21 Feb 2004 00:17:23 -0800
From: vibfft@yahoo.com (Stephen Moon)
Subject: Re: help on hash of hashes
Message-Id: <9feadd98.0402210017.6ac5782e@posting.google.com>
Have another question. I fixed the code as you told me to
while ( my $line = <DATA_IN> ) {
chomp($line);
if($line =~ s/^(.*?):\s*//){ <===fixed here
my $who = $1;
$rfwho = \$who;
my $rfrec = {};
$HoH{$who} = $rfrec;
for my $field ( split /\s+/, $line) {
my ($key, $value) = split /=/,$field;
$rfrec->{$key} = $value;
}
}
}
foreach my $family ( sort keys %HoH ) {
printf(DATA_OUT "$family:\n");
foreach my $role ( sort keys %{ $HoH{$family} } ) {
printf(DATA_OUT "$role=$HoH{$family}{$role}\n");
}
}
The output that I get is below:
flintstones:
lead=fred
pal=barney
jetsons:
boy=elroy
lead=george
wife=jane
simpsons:
kid=bart
lead=homer
wife=marge
How can I change the above code so that I can output as below?
flintstones:,jetsons:,simpsons:
lead=fred,boy=elroy,kid=bart
pal=barney,lead=george,lead=homer
,wife=jane,wife=marge
Is this even possible? I have been struggling with this one a bit.
Thanks in advance.
-Steve
------------------------------
Date: Sat, 21 Feb 2004 10:05:28 GMT
From: $_@_.%_
Subject: Re: how to cut a text file in perl
Message-Id: <I3GZb.67862$IF1.22905@nwrdny03.gnilink.net>
>
>actually, this is to _truncate_ a log.
>
>Joseph wrote:
>
>> hi i have a log file that it is increasing to big, how can i keep this
>> file of
>> a certain size, in other words, how can i make sure that the file is
>> only 200 lines long and delete the first lines if longer. i think it
>> would be easier to write this in a shell script. but i have no idea
>> in perl. can anyone tell me how to print the last 200 lines of a file
>> and overwrite the ssame file. thanks.
>
>--
> .~. Might, Courage, Vision. In Linux We Trust.
> / v \ http://www.linux-sxs.org
>/( _ )\ Linux 2.4.22-xfs
> ^ ^ 3:18pm up 15:38 1 user 1.00 1.00
>
if the logfile is one long string on one line, you may need sysread.
otherwise just open the log with a standard filehandle, then read
this into an array. Then you can do a foreach style loop and save
lines untill your counter hits 200.
------------------------------
Date: 21 Feb 2004 06:51:05 -0800
From: google_answers@festmail.com (Felix)
Subject: html2text but preserving text links
Message-Id: <62dd5c5b.0402210651.65107cda@posting.google.com>
The script below tries converting html to text while preserving
textual links. However, with www.news.com it renders many lines all
bunched together as opposed to neatly separated as lynx would do with
the same page (see www.marcfest.com/qxi5/news.cgi to see what I mean).
Anybody know how I can improve the script? Using backticks with lynx
is not an option, btw.
Thank you very much.
Marc
SCRIPT:
#!/usr/bin/perl
use LWP::Simple;
use HTML::TagFilter;
$content = get ("http://www.news.com");
my $tf = HTML::TagFilter->new(strip_comments =>
1,allow=>{a=>{'any'},br=>{'any'},p=>{'any'},script=>{'any'},style=>{'any'}});
$content = $tf->filter($content);
print $content; exit;
------------------------------
Date: Sat, 21 Feb 2004 10:18:24 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: html2text but preserving text links
Message-Id: <pan.2004.02.21.15.18.21.866958@remove.adelphia.net>
On Sat, 21 Feb 2004 06:51:05 -0800, Felix wrote:
> The script below tries converting html to text while preserving
> textual links. However, with www.news.com it renders many lines all
> bunched together as opposed to neatly separated as lynx would do with
> the same page (see www.marcfest.com/qxi5/news.cgi to see what I mean).
> Anybody know how I can improve the script? Using backticks with lynx
> is not an option, btw.
What exactly are you trying to do? I understand the output doesn't look
the greatest, but I'm not seeing your point. Are you trying to extract
just the links? text?
What command line options are you using with lynx? That may help.
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
World War Three can be averted by adherence to a strictly
enforced dress code!
------------------------------
Date: Sat, 21 Feb 2004 09:23:41 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: I wish buy Perl book
Message-Id: <JRJZb.16922$d34.1809396@news20.bellglobal.com>
"toylet" <toylet@mail.hongkong.com> wrote in message
news:4036ff85$1_2@rain.i-cable.com...
> This kind of links could easily be found by google. There are even *.edu
> that did that, Notably in certain 3rd world countries. I had nothing to
> do with the site. DOn't mis-understand.
>
I don't think anyone is blaming you (well, maybe Uri) for posting those
books online. Just be aware that there are people who read this newsgroup,
like Randal, who authored or contributed to those books, so this is not the
forum to be recommending pirated information. Either point people to the
free documentation or suggest they buy a book / subscription.
Matt
------------------------------
Date: Sat, 21 Feb 2004 10:01:55 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: I wish buy Perl book
Message-Id: <pan.2004.02.21.15.01.47.938199@remove.adelphia.net>
On Sat, 21 Feb 2004 14:48:31 +0800, toylet wrote:
[don't top post - it's rude]
[reformated]
>> I wouldn't - this is probably an *illegal* copy of the CD Bookshelf.
>>
>> I'm thinking O'Reilly will thank you for posting this web address on the
>> 'Net. Too bad the best you'll get out of this is good karma :-)
> It's actually found by google.com. I myself has my own stock of web
> server cd shelf. I was not promoting the site. Maybe I should just post
> http://www.google.com
No. You should post the O'Reilly web site - since they already have a way
to view books on line. It's called Safari - and it's the *only* place to
view O'Reilly books on line.
There are, however, a few book that are covered under an open source
license - such as "Free as in Freedom". However, I know of *NO* Perl book
that is covered under an open source license.
Bottom line - go to O'Reilly to view books on line :-)
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Only presidents, editors, and people with tapeworms have the
right to use the editorial "we."
------------------------------
Date: 21 Feb 2004 04:11:00 -0800
From: h.muench@substring.ch (hagen)
Subject: Re: IO::Socket::INET: Address already in use
Message-Id: <1ff2226.0402210411.3984480c@posting.google.com>
James Willmore <jwillmore@remove.adelphia.net> wrote in message news:<pan.2004.02.20.16.12.51.501193@remove.adelphia.net>...
> On Fri, 20 Feb 2004 16:42:03 +0100, chatiman wrote: [Don't top post - it's
> rude]
> [re-ordered to proper format]
>
> > "hagen" <h.muench@substring.ch> a écrit dans le message de news:
> > 1ff2226.0402200735.1f26e6e4@posting.google.com...
> >> I try to write a dhcp-client to get user defined dhcp option.I'm
> >> stranding already with this reduced script:
> >>
> >> #!/usr/bin/perl
> >>
> >> use IO::Socket::INET;
> >>
> >> $sock = IO::Socket::INET->new(ReuseAddr => '1',
> >> LocalPort => '68',
> >> Proto => 'udp') or die "can't bind:
> >> $@\n";
> >>
> >>
>
> Are you using BOOTP on the client? If so, disable it or use another
> port - because port 68 may be in use on your box :-)
>
> >> this dies with: "IO::Socket::INET: Address already in use"
> > If i remember when you close a socket, it stays open for a certain
> > amount of time (a few minutes or seconds).
> > So you have to wait a bit before you open the socket for a second time.
>
> This isn't a true statement. First, the OP is using UDP. The statement
> you made *may* be true if the OP was trying to use TCP instead. UDP is
> connectionless - so, once the packets leaves the client, it's done. Plus,
> the port being used is a reserved port (below 1024). Depending upon
> what's running on the client box, the port may actually be in use. The
> same applies to,say, port 123 (which is the port typically used for NTP).
> If the client was using NTP to sync time, then the above script would fail
> - because the client was, in fact, using port 123 (meaning, it's running
> ntpd or xntpd).
>
Thank you Jim. There was a running DHCP client.
If this is shutted down (ifdown-dhcp eth0), I don't fall in this trap...
bye,
Hagen
------------------------------
Date: Sat, 21 Feb 2004 15:52:07 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Let browser say "done" immediately after parent finish and do not wait child.
Message-Id: <c17ur7$qu0$1@wisteria.csv.warwick.ac.uk>
zdu@cs.nmsu.edu (Zhidian Du) wrote:
> I am writing a CGI program.
>
> Why browsers always wait (saying "transferring data from..." from the
> status bar) until both parent and chilld finish and say "done".
>
> How can I let browser say "done" immediately after parent finish.
>
> I use a query->end_html() in there and it doesn't work.
You need to close STDOUT in the child.
Ben
--
If I were a butterfly I'd live for a day, / I would be free, just blowing away.
This cruel country has driven me down / Teased me and lied, teased me and lied.
I've only sad stories to tell to this town: / My dreams have withered and died.
ben@morrow.me.uk <=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=> (Kate Rusby)
------------------------------
Date: Sat, 21 Feb 2004 14:07:36 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Listbox and passing entries
Message-Id: <c17ld2$1edaf3$1@ID-184292.news.uni-berlin.de>
Joe Smith wrote:
> Old School wrote:
>> I'm at the mercy of my hosting company, and cgi-lib.pl should be
>> able to do the same as CGI.pm in this regard with lower overhead.
>> But it is just returning the last item in the multiple
>> selections.
>
> I see you've run across yet another one of the known bugs in
> cgi-lib.pl.
Since the SplitParam() function is available, OP is apparently using a
version of cgi-lib.pl that handles multiple values. Bearing that in
mind, which "known bug" are you referring to, Joe?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 21 Feb 2004 10:20:22 +0100
From: "Merijn Boom" <m.boom@con-x-com.nl>
Subject: Mail::Sender problem
Message-Id: <4037220e$0$563$e4fe514c@news.xs4all.nl>
Hi there,
I'm trying to create an html mail with embedded pictures in it. I run perl
on Windows and Red Hat but I cannot get your module (Mail::Sender) to work.
I'm just trying to run the examples. Below this message you'll find the perl
example I'm using and the header of the e-mail. What am I doing wrong?
Regards
Merijn Boom
Perl code:
use strict;
use Mail::Sender;
my $recipients = 'm.boom@con-x-com.com';
eval {
(new Mail::Sender)
->OpenMultipart({
to => 'mailto',
FROM => 'mailfrom',
subject => 'Alternatives with images',
# debug => 'c:\temp\zkMailFlow.log',
multipart => 'related',
smtp => '127.0.0.1',
})
->Part({ctype => 'multipart/alternative'})
->Part({ ctype => 'text/plain', disposition
=> 'NONE', msg => 'A long mail message.'})
->Part({ctype => 'text/html', disposition =>
'NONE', msg => '<html><body><h1>A long</h1><p align=center>mail message.<img
src="cid:img1"></p></body></html>'})
->EndPart("multipart/alternative")
->Attach({
description => 'ed\'s GIF',
ctype => 'image/GIF',
encoding => 'base64',
disposition => "inline;
filename=\"apache_pb.gif\";\r\nContent-ID: <img1>",
file => 'apache_pb.gif'
})
->Close();
} or print "Error sending mail: $Mail::Sender::Error\n";
My Header:
To: *
From: *
Subject: Alternatives with images
Date: Sat, 21 Feb 2004 09:57:55 +0100
X-Mailer: Perl script "Perl-1.pl"
using Mail::Sender 0.8.10 by Jenda Krynicky, Czechlands
running on medusa (10.1.0.133)
under account "m.boom"
Message-ID: <20040221_085755_005175.*>
MIME-Version: 1.0
Content-type: multipart/related;
boundary="Message-Boundary-by-Mail-Sender-1077353872"
Return-Path: *
X-OriginalArrivalTime: 21 Feb 2004 08:58:38.0243 (UTC)
FILETIME=[E52FC730:01C3F858]
--Message-Boundary-by-Mail-Sender-1077353872
Content-Type: multipart/alternative;
boundary="Part-Message-Boundary-by-Mail-Sender-1077353872_2"
--Part-Message-Boundary-by-Mail-Sender-1077353872_2
Content-type: text/plain
Content-transfer-encoding: 7BIT
--Part-Message-Boundary-by-Mail-Sender-1077353872_2
Content-type: image/GIF; name="apache_pb.gif"
Content-description: ed's GIF
Content-transfer-encoding: base64
Content-disposition: inline; filename="apache_pb.gif";
Content-ID: <img1>
--Part-Message-Boundary-by-Mail-Sender-1077353872_2--
--Message-Boundary-by-Mail-Sender-1077353872-
My Message:
A long mail message.--Part-Message-Boundary-by-Mail-Sender-1077353872_2
Content-type: text/html
Content-transfer-encoding: 7BIT
<html><body><h1>A long</h1><p align=center>mail message.<img
src="cid:img1"></p></body></html>--Part-Message-Boundary-by-Mail-Sender-1077
353872_2--
------------------------------
Date: 21 Feb 2004 09:41:42 GMT
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Mail::Sender problem
Message-Id: <3246769.3fzmBbvPbA@GMT-hosting-and-pickle-farming>
Merijn Boom wrote:
> Hi there,
>
> I'm trying to create an html mail with embedded pictures in it. I run perl
> on Windows and Red Hat but I cannot get your module (Mail::Sender) to
> work.
Its not my module
> I'm just trying to run the examples. Below this message you'll find the
> perl example I'm using and the header of the e-mail. What am I doing
> wrong?
>
>
Try MIME::Lite instead.
#!/usr/bin/perl
use strict;
require MIME::Lite;
require MIME::Lite::HTML;
my $msg;
$msg = MIME::Lite->new(
To =>'gmtoomey@no-spam-please.com',
From =>'newsletter@spam-me-please.com',
Subject =>'HTML with in-line images!',
Type =>'multipart/related'
);
$msg->attach(Type => 'text/html',
Data => qq{ <body>
Here's <i>my</i> image:
<img src="http://spam-me-please.com/images/spam.gif">
</body> }
);
$msg->send;
gtoomey
------------------------------
Date: Sat, 21 Feb 2004 11:20:59 +0100
From: "Merijn Boom" <m.boom@con-x-com.nl>
Subject: Re: Mail::Sender problem
Message-Id: <40373043$0$576$e4fe514c@news.xs4all.nl>
Gregory,
Many thanks for your advice. I got it working now,
Merijn
"Gregory Toomey" <nospam@bigpond.com> wrote in message
news:3246769.3fzmBbvPbA@GMT-hosting-and-pickle-farming...
> Merijn Boom wrote:
>
> > Hi there,
> >
> > I'm trying to create an html mail with embedded pictures in it. I run
perl
> > on Windows and Red Hat but I cannot get your module (Mail::Sender) to
> > work.
>
> Its not my module
>
> > I'm just trying to run the examples. Below this message you'll find the
> > perl example I'm using and the header of the e-mail. What am I doing
> > wrong?
> >
> >
>
> Try MIME::Lite instead.
>
>
> #!/usr/bin/perl
> use strict;
>
> require MIME::Lite;
> require MIME::Lite::HTML;
>
>
> my $msg;
> $msg = MIME::Lite->new(
> To =>'gmtoomey@no-spam-please.com',
> From =>'newsletter@spam-me-please.com',
> Subject =>'HTML with in-line images!',
> Type =>'multipart/related'
> );
> $msg->attach(Type => 'text/html',
> Data => qq{ <body>
> Here's <i>my</i> image:
> <img src="http://spam-me-please.com/images/spam.gif">
> </body> }
> );
> $msg->send;
>
>
> gtoomey
------------------------------
Date: Sat, 21 Feb 2004 17:19:01 +0800
From: toylet <toylet@mail.hongkong.com>
Subject: Re: perl fileio
Message-Id: <4037227b$1_2@rain.i-cable.com>
> local $/ = \4096;
> while (<INFILE>) {
> ...
> }
In many examples I found from the web, they just $buffer=<INFILE>. What
would happen if INFILE is a big one? Would it hang the server? Would
Perl handle the memory usage properly?
--
.~. Might, Courage, Vision. In Linux We Trust.
/ v \ http://www.linux-sxs.org
/( _ )\ Linux 2.4.22-xfs
^ ^ 5:16pm up 17:36 0 users 1.05 1.02
------------------------------
Date: 21 Feb 2004 10:08:10 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: perl fileio
Message-Id: <c17ama$spb$1@nets3.rz.RWTH-Aachen.DE>
Also sprach toylet:
>> local $/ = \4096;
>> while (<INFILE>) {
>> ...
>> }
>
> In many examples I found from the web, they just $buffer=<INFILE>. What
> would happen if INFILE is a big one? Would it hang the server? Would
> Perl handle the memory usage properly?
It entirely depends. You have to look at $/ when you see <FILEHANDLE>.
When $/ is set to undef, perl reads the whole file in one go. Naturally,
with very large files this will blow your memory. There is nothing that
perl can do about it.
If however $/ is set to something other than undef (see 'perldoc
perlvar' for all the details about $/), then reading happens chunk-wise.
Each read returns one chunk of data. What the chunk will be like is
determined by $/:
local $/ = "\n"; # this is the default
while (<FILE>) {
# $_ now contains one line of the file
}
You very likely wont run out of memory with the above. However, it could
happen. Namely when the file contains ridiculously long lines. This is
extremely unlikely for text files, but it could happen with binary
files. A binary file that doesn't have the byte-sequence "\012" on
UNIXish systems, "\015\12" on Win32 or "\015" on Macintoshs will
necessarily be slurped as a whole because perl doesn't find any newline
in it.
local $/ = undef; # slurp mode
while (<FILE>) {
# whole file in $_
}
# the while loop here is equivalent to
local $_ = <FILE>;
Here you'll run out of memory when the file is larger than your memory
(minus some overhead).
local $/ = \4096;
while (<FILE>) {
# 4096 bytes of data in $_
}
This is harmless. It will always read 4096 or less (at the end of the
file) bytes.
There are some simple rules you can stick to:
- Read text-files linewise (i.e. don't change the value of $/).
- Only slurp whole files into memory (local $/ = undef) when
your algorithm requires it AND the file is not too large.
- Read binary files with a fixed block size (local $/ = \$SIZE)
or use read() for them.
There are some more tricks. One useful one is setting $/ to the empty
string. This is referred to as paragraph-mode. It treats multiple
consecutive empty lines as one empty line. And thus each read will
return the next paragraph. Needless to say, this only makes sense with
text-files.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Sat, 21 Feb 2004 23:20:33 +0800
From: toylet <toylet_at_mail.hongkong.com>
Subject: Re: perl fileio
Message-Id: <40377738$1_1@rain.i-cable.com>
> There are some more tricks. One useful one is setting $/ to the empty
> string. This is referred to as paragraph-mode. It treats multiple
> consecutive empty lines as one empty line. And thus each read will
> return the next paragraph. Needless to say, this only makes sense with
> text-files.
I don't under the paragraph, but there shouldn't be any need for it in
my near future. Knowing the reaplcement for fget() and fgets() is good
enough.
--
.~. Might, Courage, Vision. In Linux We Trust.
/ v \ http://www.linux-sxs.org
/( _ )\ Linux 2.4.22-xfs
^ ^ 11:18pm up 23:38 1 user 1.03 1.00
------------------------------
Date: Sat, 21 Feb 2004 07:52:54 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: perl fileio
Message-Id: <slrnc3eolm.73u.tadmc@magna.augustmail.com>
toylet <toylet@mail.hongkong.com> wrote:
> In many examples I found from the web, they just $buffer=<INFILE>. What
> would happen if INFILE is a big one? Would it hang the server?
What server?
You don't need a server to run Perl programs.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 21 Feb 2004 23:57:34 +0800
From: toylet <toylet_at_mail.hongkong.com>
Subject: Re: perl fileio
Message-Id: <40377fe5_2@rain.i-cable.com>
>> In many examples I found from the web, they just $buffer=<INFILE>. What
>> would happen if INFILE is a big one? Would it hang the server?
> What server?
> You don't need a server to run Perl programs.
you do. The server could be a localhost, which could be Windows, Linux.
I should have used the word "machine" or "operating system".
--
.~. Might, Courage, Vision. In Linux We Trust.
/ v \ http://www.linux-sxs.org
/( _ )\ Linux 2.4.22-xfs
^ ^ 11:56pm up 1 day 16 min load average: 1.00 1.00 0.99
------------------------------
Date: Sat, 21 Feb 2004 12:17:39 +0100
From: "PHP2" <gp@nospm.hr>
Subject: PERL/MySQL tutorial
Message-Id: <c17en7$lqc$1@ls219.htnet.hr>
I can not find too much good PERL/MySQL tutorials... Do you know someone
about good PERL/MySQL tutorials on the web..?
------------------------------
Date: 21 Feb 2004 12:17:54 GMT
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: PERL/MySQL tutorial
Message-Id: <12540675.fUAf2NSEv0@GMT-hosting-and-pickle-farming>
PHP2 wrote:
> I can not find too much good PERL/MySQL tutorials... Do you know someone
> about good PERL/MySQL tutorials on the web..?
See http://dbi.perl.org/
gtoomey
------------------------------
Date: Sat, 21 Feb 2004 06:54:53 -0800
From: Exide Arabellan <exide@comcast.net>
Subject: Re: PERL/MySQL tutorial
Message-Id: <bMCdncf5d-nf7KrdRVn-uw@comcast.com>
Gregory Toomey wrote:
> PHP2 wrote:
>
>
>>I can not find too much good PERL/MySQL tutorials... Do you know someone
>>about good PERL/MySQL tutorials on the web..?
>
>
> See http://dbi.perl.org/
>
> gtoomey
http://www.mysql.com/doc/en/
http://www.perldoc.com/
Exide Arabellan
www.arabellan.com
------------------------------
Date: Sat, 21 Feb 2004 23:26:04 +0800
From: toylet <toylet_at_mail.hongkong.com>
Subject: Re: PERL/MySQL tutorial
Message-Id: <40377883$1_1@rain.i-cable.com>
>> See http://dbi.perl.org/
> http://www.mysql.com/doc/en/
> http://www.perldoc.com/
Is there a good search string that could help one to find more live
examples of using the DBI::Mysql interface? Most examples I found are
merely scratching the surface.
--
.~. Might, Courage, Vision. In Linux We Trust.
/ v \ http://www.linux-sxs.org
/( _ )\ Linux 2.4.22-xfs
^ ^ 11:24pm up 23:44 1 user 1.00 1.00
------------------------------
Date: Sat, 21 Feb 2004 13:22:49 +0100
From: "chatiman" <chatiman@free.fr>
Subject: Re: Protecting Source code of a perl script
Message-Id: <40374d9d$0$28104$626a14ce@news.free.fr>
"Robert" <bobx@linuxmail.org> a écrit dans le message de news:
Vp6dnf_uyPm7EKvdRVn-gQ@adelphia.com...
> use PAR;
>
How does PAR protect source code ? From the web site I see that it create a
zipped archive of the source code. Does it do more that simply compressing
the code ?
------------------------------
Date: Sat, 21 Feb 2004 12:53:28 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: replace unicode characters by &#number; representation
Message-Id: <Pine.LNX.4.53.0402211240150.2763@ppepc56.ph.gla.ac.uk>
Suppose I've read-in a line of text which can contain a large
repertoire of characters. Assume that I've done it using Perl's
native unicode support, a la
binmode IN, ':encoding(whatever)';
specifying, of course, the correct external character encoding for
the input file that I'm reading, whatever it might be.
I've come up with this regex[1]
s/([^\0-\177])/'&#'.ord($1).';'/eg;
to replace all non-ASCII characters by their &#number; representation.
Is this indeed the simplest approach, or am I missing some simpler
code than writing ord($1) and using /e to evaluate it?
(Use \377 if the requirement is to retain iso-8859-1 characters and
only to convert the rest).
[1] Yes, I'm aware that - since this appears to be an HTML/XHTML
problem - then the proper place to do this would be in whatever
HTML-processing package/module one is using, but please humour me for
the low-level approach anyway, for the sake of this discussion.
------------------------------
Date: Sat, 21 Feb 2004 16:04:20 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: replace unicode characters by &#number; representation
Message-Id: <c17vi4$qu0$2@wisteria.csv.warwick.ac.uk>
"Alan J. Flavell" <flavell@ph.gla.ac.uk> wrote:
>
> Suppose I've read-in a line of text which can contain a large
> repertoire of characters. Assume that I've done it using Perl's
> native unicode support, a la
>
> binmode IN, ':encoding(whatever)';
>
> specifying, of course, the correct external character encoding for
> the input file that I'm reading, whatever it might be.
>
> I've come up with this regex[1]
>
> s/([^\0-\177])/'&#'.ord($1).';'/eg;
>
> to replace all non-ASCII characters by their &#number; representation.
I would have said [^[:ascii:]] was clearer :).
> Is this indeed the simplest approach, or am I missing some simpler
> code than writing ord($1) and using /e to evaluate it?
>
> (Use \377 if the requirement is to retain iso-8859-1 characters and
> only to convert the rest).
I usually use
use Encode qw/:fallbacks/;
$PerlIO::encoding::fallback = FB_HTMLCREF;
binmode STDOUT, ':encoding(ascii)'; # or iso8859-1, or whatever
which will leave the conversion until the data is output.
Ben
[1] NMF
--
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes, [ Heracles shoots Vulture with arrow. Vulture bursts into ]
/Alcestis/) [ flame, and falls out of sight. ] ben@morrow.me.uk
------------------------------
Date: Sat, 21 Feb 2004 08:35:04 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Unexplained output for PERL print statement
Message-Id: <slrnc3er4o.73u.tadmc@magna.augustmail.com>
Joe Smith <Joe.Smith@inwap.com> wrote:
> When reading a DOS file on Windows, chomp removes both characters.
Not really.
perl's input/output routines do the translation of line endings.
When reading a DOS file on Windows, the input routine removes the
CR and chomp removes the LF.
ie. the CR is gone before chomp() is called.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 21 Feb 2004 10:59:10 GMT
From: Kodeguru <newz@xoftware.org>
Subject: very strange conditional problem
Message-Id: <2SGZb.27067$ac.4342902@news4.srv.hcvlny.cv.net>
** I also posted this in comp.lang.perl **
I just finished debugging a very strange problem, and was wondering if
any of you had ever seen it before. My code is very long, so I will only
post the interesting parts.
ok, so using DBD::Sybase and some other stuff, we do a select query on a
database and store the return like this:
#####------######
$sql = "SELECT blah blah blah";
$sth = $dbh->prepare();
$sth->execute();
while (my $equip_row = $sth->fetchrow_arrayref()){
# ....
# this line prints $equip_row->[16] is (some@email.address)\n
# which is right
print "\$equip_row->[16] is ($equip_row->[16])\n";
if ($equip_row->[16] != undef){ # But then this test fails
# and this line doesn't print at all
print "$equip_row->[16] is not undef, so...\n";
# sends email
# ....
}
}
#####------######
Now if I change the line where the conditional is to
if ($equip_row->[16] =~ /\S+/) {
It works. Both debug lines print like they should and the emails get sent.
The code is working now, because I left it as a regex test, but this is
the craziest thing I've ever seen. I looked at it for hours, and I don't
think I'm missing anything stupid.
Anyone else have any ideas ?
--
Michael O'Malley Jr.
President
Pillar Open Source Technologies, LLC.
------------------------------
Date: Sat, 21 Feb 2004 20:48:21 +0900
From: ko <kuujinbo@hotmail.com>
Subject: Re: very strange conditional problem
Message-Id: <c17gi6$njg$1@pin3.tky.plala.or.jp>
Kodeguru wrote:
>
> ** I also posted this in comp.lang.perl **
>
> I just finished debugging a very strange problem, and was wondering if
> any of you had ever seen it before. My code is very long, so I will only
> post the interesting parts.
>
> ok, so using DBD::Sybase and some other stuff, we do a select query on a
> database and store the return like this:
>
> #####------######
>
> $sql = "SELECT blah blah blah";
>
> $sth = $dbh->prepare();
>
> $sth->execute();
>
> while (my $equip_row = $sth->fetchrow_arrayref()){
>
> # ....
>
> # this line prints $equip_row->[16] is (some@email.address)\n
> # which is right
> print "\$equip_row->[16] is ($equip_row->[16])\n";
>
> if ($equip_row->[16] != undef){ # But then this test fails
------------^^^^^^^^^^^^^^^^^^^^^^^^^^
The != operator expects *numeric* operands/arguments. Both
$equip_row->[16] and undef are converted to numbers. So basically what
happens is:
if ( 0 != 0 ) {
> # and this line doesn't print at all
> print "$equip_row->[16] is not undef, so...\n";
That's why this block never gets executed.
> # sends email
> # ....
>
> }
> }
>
>
> #####------######
[snip]
HTH -keith
------------------------------
Date: Sat, 21 Feb 2004 13:03:24 GMT
From: Kodeguru <newz@xoftware.org>
Subject: Re: very strange conditional problem
Message-Id: <wGIZb.27605$ac.4679239@news4.srv.hcvlny.cv.net>
ko wrote:
>
> The != operator expects *numeric* operands/arguments. Both
> $equip_row->[16] and undef are converted to numbers. So basically what
> happens is:
>
> if ( 0 != 0 ) {
>
>> # and this line doesn't print at all
>> print "$equip_row->[16] is not undef, so...\n";
>
>
> That's why this block never gets executed.
>
>> # sends email
>> # ....
>>
>> }
>> }
>>
>>
>> #####------######
>
>
> [snip]
>
> HTH -keith
I tried it with ne as well, as in
if ($equip_row->[16] ne undef){
and that didn't work either.
--
Michael O'Malley Jr.
President
Pillar Open Source Technologies, LLC.
------------------------------
Date: Sat, 21 Feb 2004 13:08:09 GMT
From: Kodeguru <newz@xoftware.org>
Subject: Re: very strange conditional problem
Message-Id: <ZKIZb.27625$ac.4697758@news4.srv.hcvlny.cv.net>
Kodeguru wrote:
> I tried it with ne as well, as in
>
> if ($equip_row->[16] ne undef){
>
> and that didn't work either.
>
Hmm,
no, perhaps I'm mistaken. Maybe I didn't try it with 'ne'.
Thanks.
--
Michael O'Malley Jr.
President
Pillar Open Source Technologies, LLC.
------------------------------
Date: Sat, 21 Feb 2004 22:34:20 +0900
From: ko <kuujinbo@hotmail.com>
Subject: Re: very strange conditional problem
Message-Id: <c17mov$1h3$1@pin3.tky.plala.or.jp>
Kodeguru wrote:
> Kodeguru wrote:
>
>
>> I tried it with ne as well, as in
>>
>> if ($equip_row->[16] ne undef){
>>
>> and that didn't work either.
>>
>
>
> Hmm,
> no, perhaps I'm mistaken. Maybe I didn't try it with 'ne'.
>
> Thanks.
>
You probably don't want to use this type of construct anyway, since it
triggers a warning - you do have warnings enabled right? :)
Its more common to use something like:
if ( defined $equip_row->[16] ) {
...
keith
------------------------------
Date: Sat, 21 Feb 2004 08:45:21 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: very strange conditional problem
Message-Id: <slrnc3ero1.73u.tadmc@magna.augustmail.com>
ko <kuujinbo@hotmail.com> wrote:
> Kodeguru wrote:
>> if ($equip_row->[16] != undef){ # But then this test fails
> ------------^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> The != operator expects *numeric* operands/arguments. Both
> $equip_row->[16] and undef are converted to numbers. So basically what
> happens is:
>
> if ( 0 != 0 ) {
> That's why this block never gets executed.
You should always enable warnings when developing Perl code!
Kodeguru has wasted a bunch of man-minutes by asking thousands
of people around the world to troubleshoot a problem that a
machine could have spotted in a small part of a single second!
Please do not ask people to do the work of a machine,
they won't like it.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 21 Feb 2004 07:12:17 -0800
From: izco@hotmail.com (RP)
Subject: WWW::Mechanize error confusion
Message-Id: <9e7779b4.0402210712.3979a424@posting.google.com>
I'm just starting using WWW::Mechanize, and I'm having a very strange
error(s). I'm trying to access any web page, then go through the
first link, then display the resulting page (I'm a newbie with this
module). The only url I can get WWW::Mechanize to work with is
amazon.com. I can't get any other url to work?!? What the heck am I
doing wrong? Here's my code:
#!/usr/bin/perl -w
use strict;
use WWW::Mechanize;
my $mech = WWW::Mechanize->new( );
$mech->agent_alias("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
5.0)");
$mech->get("http://www.amazon.com");
die $mech->response->status_line unless $mech->success;
$mech->follow_link( n => 1 );
print $mech->content;
exit;
Like I said, when I put any other url in place of amazon.com it fails
(500 Internal Server Error)... Thanks in advance for any help!
Randy
------------------------------
Date: Sat, 21 Feb 2004 10:26:42 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: WWW::Mechanize error confusion
Message-Id: <pan.2004.02.21.15.26.40.167493@remove.adelphia.net>
On Sat, 21 Feb 2004 07:12:17 -0800, RP wrote:
> I'm just starting using WWW::Mechanize, and I'm having a very strange
> error(s). I'm trying to access any web page, then go through the
> first link, then display the resulting page (I'm a newbie with this
> module). The only url I can get WWW::Mechanize to work with is
> amazon.com. I can't get any other url to work?!? What the heck am I
> doing wrong? Here's my code:
>
> #!/usr/bin/perl -w
> use strict;
>
> use WWW::Mechanize;
>
> my $mech = WWW::Mechanize->new( );
> $mech->agent_alias("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
> 5.0)");
> $mech->get("http://www.amazon.com");
> die $mech->response->status_line unless $mech->success;
> $mech->follow_link( n => 1 );
>
> print $mech->content;
> exit;
>
> Like I said, when I put any other url in place of amazon.com it fails
> (500 Internal Server Error)... Thanks in advance for any help!
Are you running this through a web server? Because the script appears to
work fine on the command line.
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
A long-forgotten loved one will appear soon. Buy the negatives
at any price.
------------------------------
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 6172
***************************************