[21815] in Perl-Users-Digest
Perl-Users Digest, Issue: 4019 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 24 03:05:54 2002
Date: Thu, 24 Oct 2002 00:05:15 -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, 24 Oct 2002 Volume: 10 Number: 4019
Today's topics:
Re: [REPOST] Need advice on a project (wrt to tie'ing t <goldbb2@earthlink.net>
Re: Advice Please (Jay Tilton)
Re: Advice Please <jurgenex@hotmail.com>
Re: alarm interfering with LWP::Request (Bryan Castillo)
ARGV question <mace74@hotmail.com>
Re: ARGV question <tassilo.parseval@post.rwth-aachen.de>
Re: CGI::Minimal does not work with enctype="multipart/ <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Convert Chinese Character to Unicode (not UTF-8)? (Leo Tai)
Re: Convert Chinese Character to Unicode (not UTF-8)? <jurgenex@hotmail.com>
defined() upon aggregates (hashes and arrays) is not gu <spicano@netzero.net>
Re: defined() upon aggregates (hashes and arrays) is no <goldbb2@earthlink.net>
Re: defined() upon aggregates (hashes and arrays) is no <thepoet@nexgo.de>
Re: deleting a file... kill ??? Thanks... <jurgenex@hotmail.com>
Re: deleting a file... kill ??? Thanks... <jurgenex@hotmail.com>
Re: deleting a file... kill ??? <jurgenex@hotmail.com>
Re: Finding words in a string. <s_grazzini@hotmail.com>
HTML <img ...> <agm@socrates.berkeley.edu>
Re: HTML <img ...> <tassilo.parseval@post.rwth-aachen.de>
Re: negation <s_grazzini@hotmail.com>
Newbie Perl script help <pnmurphyNO_SPAM_TODAY_THANK_YOU@cogeco.ca>
Order form script <fpichette@NOSPAMvideotron.ca>
Re: Parallel ForkManger - Multiprocessors ctcgag@hotmail.com
Re: Perl bloggers? <gerardlanois@netscape.net>
Perl Calling C issues?? lefkogt@gppbt.org
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 24 Oct 2002 02:07:11 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: [REPOST] Need advice on a project (wrt to tie'ing to a file and general strategy)
Message-Id: <3DB78E0F.FEA200AF@earthlink.net>
Michele Dondi wrote:
>
> On Tue, 22 Oct 2002 00:12:01 -0400, Benjamin Goldberg
> <goldbb2@earthlink.net> wrote:
>
> >Store the data in a database -- either one created with a tied hash,
> >using one of the modules that comes with perl (DB_File or SDBM_File)
> >or using a "real" database, with DBI, and one of access, or oracle,
> >or SQLite, etc.
>
> I'm currently experimenting with DB_File. This is an 'easy' enough
> solution, from a newbie's point of view.
>
> I still have some questions: as you might have read I had thought of
> using a hash whose values are array refences. In any case it seems
> that I can't have a tied hash of arrays, can I?!?
You can and you can't. You can't, in that if you simply store an
arrayref in a tied database, it gets stringified as something like
"ARRAY(0x12345678)", and of course you can't go from this string back to
an array (especially not between seperate executions of perl). You can,
in that if you install a filter (see perldoc perldbmfilter), you can
have your arrayrefs automatically serialized when stored in the database
and deserialized when retrieved.
Depending on what's in those array references you mentioned, serializing
can be easy or hard.
If they're strings (or numbers and strings), and you know that there're
no "\0" characters in any of them, you could do:
(tied %hash)->filter_store_value(sub { $_ = join "\0", @$_ });
(tied %hash)->filter_fetch_value(sub { $_ = [split /\0/, $_, -1] });
If all the elements of each arrayref are numbers, you could do:
(tied %hash)->filter_store_value(sub { $_ = pack "N*", @$_ });
(tied %hash)->filter_fetch_value(sub { $_ = [unpack "N*", $_] });
If these arrays might contain more complicated structures, Storable.pm
and it's freeze() and thaw() subroutines might be appropriate.
> In connection with this problem, would it be better to use a "real"
> database?
And how would a "real" database cope with the problem of storing arrays?
> >> Notice that I'm aware this strategy won't catch all duplicates
> >> between one run and the other, but I'm sure it would be
> >> nevertheless an enhancement for my purposes...
> >
> >Why wouldn't it?
>
> Most probably I wasn't clear. I was thinking of an algorithm taking
> checksums only of files with the same size.
Why? It seems to me that you would have to keep a list of all the
different possible sizes, then. Also, it sounds like you'd first need
to do one pass to find out what each of the different sizes are, and
then, for each different size, another pass to deal with (find checksums
of) all files of that particular size. This sounds like many, many,
passes through the filesystem.
If you just make one pass through the filesystem, calculating checksums,
that should be sufficient.
> Thus if I run it today it will catch all duplicates in one particular
> basedir; then I will "process" those files somehow, but I will keep
> track of the pairs (size, checksum) for those files for which the
> checksum was calculated. Tomorrow I will run it again and I'll catch
> tomorrow's duplicates along with files that were already duplicates
> today.
>
> But my algorithm won't spot that a certain file that I have today is
> the same as one that I will get tomorrow if that particular file isn't
> duplicate today. However it suffices for me and is suitable for the
> application I need it for.
This seems silly -- my algorithm will find *all* duplicates... well,
unless files are added or removed or changed while it's running, in
which case it might get confused, but that's unavoidable.
> >Suppose that you implement your remove-duplicates thing as follows:
>
> [code snipped]
>
> I'll have to look at the code carefully and it will take some time.
> For sure it will give some insight and some ideas.
>
> >There's no need to check for lengths being the same, since MD5
> >checksums also mix in the length of the data.
>
> My original, gross, shell script used the algorithm roughly described
> above because taking a file size is *much* faster than taking a
> checksum and two files having different sizes is a sufficient
> condition for them to be different (mathematically, it's an
> "invariant", isn't it?).
Hmm. I think I see what you're saying -- if there's only one file of a
particular size, then you can be certain that it's not a duplicate of
any other file.
However, for every size for which there's more than one file of that
size, you have to calculate a checksum of all of those files. So
really, the only point of keeping track of file sizes is that little "if
there's only one file of this size" optomization.
Not that it's a bad optimization, of course, but it doesn't seem like
there's any way to use this and do only one pass through the filesystem.
Ok, here's what I would add to my prior code:
my %sizes;
# First pass, group by size.
find( { no_chdir => 1, wanted => sub {
next unless -f;
++ $sizes{pack "N", -s _};
} }, $path );
while( my ($size, $count) = each %sizes ) {
delete $sizes{$size} if $count == 1;
}
# identify duplicates.
find( { no_chdir => 1, wanted => sub {
next unless -f;
next unless exists $sizes{pack "N", -s _};
.... everything else the same from here onward ...
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Thu, 24 Oct 2002 01:15:11 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Advice Please
Message-Id: <3db74086.462143751@news.erols.com>
"merlin" <merlin@itwizards.sic> wrote:
: I need to change a script so that I only need to input a file name instead
: of the full URL.
That's a mixed bag of terminologies, but the gist of it seems to be
that you'd like to use relative paths, but the program only reacts to
absolute paths.
: I have been told that I would need to,
:
: "You'd also need to alter the webbbs_post.pl script, so that instead of (or
: better yet, in addition to) "blanking out" URL fields which contain only
: the "http://" string, it "blanks out" URL fields which contain only your
: defined default string."
:
: How do I "Blank out" the URL fields?
Can't even guess. The peculiar use of quotes around "blank out"
suggests it's a term the author made up, then neglected to explain.
Perhaps the person who offered that advice can clarify. He seems to
be familiar enough with the workings to offer much better guidance
than we.
: The code I think this refers to is,
:
: $val2 =~ s/([ <>])([\w]+:\/\/[\w\*\+-?&;,#~=\.\/\@]+[\w\/])/$1<A HREF="$2"
: TARGET="_blank">$2<\/A>/g;
[snip]
Ooh, my achin' eyeball!
Somebody needs to introduce the author to alternative s/// delimiters
and the /x modifier.
I am curious enough to see the rest of the program. I do find a
program named WebBBS at http://awsd.com/scripts/ . The author seems
to be locked into a programming style more suited to Perl4, and
*really* likes the copy/paste technique of code reuse.
It's all pretty dreadful stuff, and a maintenance/alteration
nightmare. Definitely not the kind of thing a Perl neophyte would
want to cut his teeth on. Not the kind of thing a guru would
voluntarily do, for that matter.
------------------------------
Date: Thu, 24 Oct 2002 05:35:03 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Advice Please
Message-Id: <bELt9.5220$iV1.1523@nwrddc02.gnilink.net>
merlin wrote:
> I need to change a script so that I only need to input a file name
> instead of the full URL.
That request doesn't make sense. You are comparing apples and oranges.
Files and file names are things on a local computer in a file system (maybe
networked like NFS or others).
URLs are as the name suggests resource locators. They live in the world of
e.g. HTTP, and per se they have nothing to do with files or file names. Some
web servers may map URLs to local file names, but that's just for
convenience and there is no way to tell in which way they are mapped or even
if a URL has points to a file at all.
jue
------------------------------
Date: 23 Oct 2002 16:15:39 -0700
From: rook_5150@yahoo.com (Bryan Castillo)
Subject: Re: alarm interfering with LWP::Request
Message-Id: <1bff1830.0210231515.4e252b79@posting.google.com>
> I need to use alarm in the same script with LWP, and I find that
> the alarm function causes the LWP fetch operation to abort. Is there
> a workaround to this problem?
>
> Here is a demonstration script: The timer handler just outputs a notice
> and disables the alarm. That would seem to have no involvement with the
> LWP operation.
On some operating systems (such as Solaris), the alarm will cause
system calls to return EINTR, while others will return to the system
call after handling the alarm (linux).
It really doesn't make sense anyway (to me) to set an alarm, do an
operation then complain about the alarm stopping your operation. If
you don't like this, don't use the alarm.
Why do you need to use the alarm like this? Is it just so you can log
a message saying that this download is taking too long, but you really
want to continue with the download? There are better ways to handle
that if this is the case. Please elaborate on your "real" program
requirements.
Note:
I thought there might be a way to force restartable system calls using
sigaction and the flag SA_RESTART. However I can not get this to work
on my system. Have I used the POSIX module incorrectly?
Has anyone set up signal handlers in perl on Solaris (SPARC) so that
system calls are restarted, as stated in the manpage for sigaction?
[bryanc@jabba:/users/dp/bryanc]
$ uname -a
SunOS jabba 5.7 Generic_106541-22 sun4u sparc SUNW,Ultra-4
[bryanc@jabba:/users/dp/bryanc]
$ perl -v
This is perl, v5.6.0 built for sun4-solaris
I expected the accept call to be restarted after receiving the alarm
instead of returning error. The read or sysread (tried both) restart
after an alarm, and also restart when using traditional signal
handlers ($SIG{ALRM} = sub{}).
[test]
#!/bin/perl
use strict;
use warnings;
use IO::Socket;
use IO::Socket::INET;
use POSIX;
my $USESIGACTION = 1;
sub handler {
print "Alarm.\n";
}
if ($USESIGACTION) {
print "Signal handler type: sigaction\n";
my $sigset = POSIX::SigSet->new(&POSIX::SIGALRM);
my $sigaction = POSIX::SigAction->new(
'main::handler',
$sigset,
&POSIX::SA_RESTART|&POSIX::SA_SIGINFO);
POSIX::sigaction(&POSIX::SIGALRM, $sigaction) || die;
}
else {
print "Signal handler type: default\n";
$SIG{ALRM} = \&handler;
}
my $port = 5151;
my $server = IO::Socket::INET->new(
LocalPort => $port,
ReuseAddr => 1,
Listen => 5,
Type => SOCK_STREAM,
Proto => 'tcp'
) || die "Error: can't listen to port $port - $!\n";
while (1) {
my $buffer;
my $client;
alarm(5);
print "Waiting for connection\n";
unless ($client = $server->accept) {
print "System Error: $!\n", if ($!);
alarm(0);
next;
}
alarm(0);
print "Connection made\n";
alarm(2);
sysread($client, $buffer, 1024);
if ($!) { print "System Error: $!\n"; }
else { print $buffer, "\n"; }
alarm(0);
last if ($buffer =~ /(quit|bye|exit|adios)/i);
$client->close;
print "Closed client connection\n";
}
if ($!) {
print "System Error: $!\n";
}
$server->close;
[server output]
$ perl test.pl
Signal handler type: sigaction
Waiting for connection
Alarm.
System Error: Interrupted system call
Waiting for connection
Connection made
Alarm.
hello
Closed client connection
Waiting for connection
Alarm.
System Error: Interrupted system call
Waiting for connection
Connection made
Alarm.
quit
System Error: Bad file number
------------------------------
Date: Thu, 24 Oct 2002 19:27:54 +1300
From: "Maxx" <mace74@hotmail.com>
Subject: ARGV question
Message-Id: <ap83rd$ele$1@lust.ihug.co.nz>
Is it possible to write a Perl script that accepts parameters that are not
in fact files? I want to pass in two String values that will be derived in
another script and passed through for use in the second.
Thanks very much for any advice.
------------------------------
Date: 24 Oct 2002 06:38:24 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: ARGV question
Message-Id: <ap84h0$83m$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Maxx:
> Is it possible to write a Perl script that accepts parameters that are not
> in fact files? I want to pass in two String values that will be derived in
> another script and passed through for use in the second.
Yes, sure you can. @ARGV contains whatever you pass to your script (each
array-element contains one field delimited by whitespace).
Whether they are treated as files depends on whether you use the special
operation '<>'. @ARGV itself does not impose that. Are you talking about
oneliners in your shell? If you use the -p or -n switch, then they are
in fact treated as files. So don't use that if you don't want that.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Thu, 24 Oct 2002 08:48:15 +0200
From: Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Subject: Re: CGI::Minimal does not work with enctype="multipart/form-data"?
Message-Id: <newscache$f84h4h$0ti$1@news.emea.compuware.com>
Alex wrote (Wednesday 23 October 2002 16:02):
> Hello,
>
> I was wondering if anyone had any experience with CGI::Minimal.
I use it almost exclusively in favour of CGI.
> I have
> been using it as a light-weight alternative to CGI.pm to retrieve form
> data (I do not need HTML generating capabilities of CGI.pm since using
> templates is a more maintainable solution in most cases anyway).
Same reason here.
> I've been trying to get CGI::Minimal to work with file-upload forms,
> but it does not seem to work at all.
I have not yet had the need to use file uploads. So on that particular issue
I can't comment.
> As soon as I add
> enctype="multipart/form-data" to my form tag, my script that uses
> CGI::Minimal never finishes. I know the problem is in CGI::Minimal,
> because CGI.pm and direct read from STDIN work just fine.
Why? Because it works one but not on the other? That's not a firm argument.
Perhaps it is in your code! CGI::Minimal has proved to me to be a fine
piece of code. I recommend you don't vent your opinion in this way to the
CGI::Minimal author.
> I've
> searched newsgroups for any clues, and I am somewhat surprised that no
> one had ever noticed that CGI::Minimal does not work for form-based
> file uploads, even though it claims to.
That could be an even stronger hint that it is in *your* code instead of
being a CGI::Minimal bug.
> My platform is Windows 2000.
> (The module seems to work on Unix). And I use ActivePerl 5.6.
> CGI::Minimal version is 1.09.
>
> Do you think CGI::Minimal is buggy and does not do file uploads on
> Windows systems, or could it be something else? I would appreciate any
> hints.
>
> Thank you,
>
> Alex
--
KP
------------------------------
Date: 23 Oct 2002 20:05:48 -0700
From: hkleo@yahoo.com (Leo Tai)
Subject: Convert Chinese Character to Unicode (not UTF-8)?
Message-Id: <e4884906.0210231905.49703568@posting.google.com>
Hello All,
Can I convert the chinese character to unicode (not UTF-8) using perl
5.0? Because I have to make a CSV, and import the CSV into English
Excel 2000.
I have tried Unicode::Map and Unicode::String, but they cannot. This
is my code:
#!/usr/local/bin/perl
use Unicode::String;
use Unicode::Map;
my $map = new Unicode::Map('cp950');
$input="中文 chinese";
$utf16=$map->to16($input);
$utf8=Unicode::String::utf16($utf16)->utf8;
print $result;
I tried different parameters, but still cannot.
Can anyone help me?
Thanks You!
Leo Tai
------------------------------
Date: Thu, 24 Oct 2002 05:38:54 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Convert Chinese Character to Unicode (not UTF-8)?
Message-Id: <OHLt9.5224$iV1.3738@nwrddc02.gnilink.net>
Leo Tai wrote:
> Can I convert the chinese character to unicode (not UTF-8) using perl
> 5.0? Because I have to make a CSV, and import the CSV into English
> Excel 2000.
Well, please define "the chinese character".
I guess what you are asking is if you can convert text that is encoded in
Big-5 or some other common encoding for Chinese Characters (there are
several!) into Unicode.
Yes, you can. First determine which encoding is used for your source text.
And then use Text::Iconv to do the conversion.
jue
------------------------------
Date: Wed, 23 Oct 2002 22:26:30 -0700
From: "spicano" <spicano@netzero.net>
Subject: defined() upon aggregates (hashes and arrays) is not guaranteed to produce intuitive results
Message-Id: <ap80a8$6jv$1@news01.intel.com>
From Perlfunc man page:
1030 parentheses. On the other hand, use of defined()
1031 upon aggregates (hashes and arrays) is not
1032 guaranteed to produce intuitive results, and should
1033 probably be avoided.
Basic problem: when checking if a hash key is defined, all higher level hash
keys are created.
I do not want intermediate keys to exist afterwards.
Simple example:
#!/usr/bin/perl
if (defined $a{1}{2}{3}) { print "123 defined first pass.\n"; }
if (defined $a{1}{2}) { print "12 defined second pass.\n"; }
produces:
12 defined second pass.
Checked on perl5.00404 & 5.6.1 on Linux/Solaris.
I do not want intermediate hash keys to be created, and I do not want to
code:
if (defined %a &&
defined $a{1} &&
defined $a{1}{2} &&
defined $a{1}{2}{3}) { .... }
I could code a string function, that tears away at the structure using
eval(), but it cannot
be this difficult to not create intermediate hash references?
Any good ideas?
Thanks,
Silvio
------------------------------
Date: Thu, 24 Oct 2002 02:42:03 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: defined() upon aggregates (hashes and arrays) is not guaranteed to produce intuitive results
Message-Id: <3DB7963B.3CEBF12F@earthlink.net>
spicano wrote:
>
> From Perlfunc man page:
> 1030 parentheses. On the other hand, use of defined()
> 1031 upon aggregates (hashes and arrays) is not
> 1032 guaranteed to produce intuitive results, and should
> 1033 probably be avoided.
>
> Basic problem: when checking if a hash key is defined, all higher level hash
> keys are created.
> I do not want intermediate keys to exist afterwards.
>
> Simple example:
> #!/usr/bin/perl
> if (defined $a{1}{2}{3}) { print "123 defined first pass.\n"; }
> if (defined $a{1}{2}) { print "12 defined second pass.\n"; }
>
> produces:
> 12 defined second pass.
>
> Checked on perl5.00404 & 5.6.1 on Linux/Solaris.
>
> I do not want intermediate hash keys to be created, and I do not want to
> code:
> if (defined %a &&
> defined $a{1} &&
> defined $a{1}{2} &&
> defined $a{1}{2}{3}) { .... }
>
> I could code a string function, that tears away at the structure using
> eval(), but it cannot
> be this difficult to not create intermediate hash references?
sub exists_no_autovivify {
my ($h, @keys) = @_;
my $lastkey = pop @keys;
UNIVERSAL::isa( ($h=$h->{$_}) , "HASH" ) or return
for @keys;
return exists $hashref->{$lastkey};
}
if( exists_no_autovivify( \%a, "1", "2", "3" ) ) {
# true if $a{1}{2}{3} exists.
}
[untested]
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Thu, 24 Oct 2002 08:55:21 +0200
From: "Christian Winter" <thepoet@nexgo.de>
Subject: Re: defined() upon aggregates (hashes and arrays) is not guaranteed to produce intuitive results
Message-Id: <ap8590$5q5$1@newsread1.arcor-online.net>
"spicano" <spicano@netzero.net> wrote in message
news:ap80a8$6jv$1@news01.intel.com...
[...]
> Basic problem: when checking if a hash key is defined, all higher level
hash
> keys are created.
> I do not want intermediate keys to exist afterwards.
>
> Simple example:
> #!/usr/bin/perl
> if (defined $a{1}{2}{3}) { print "123 defined first pass.\n"; }
> if (defined $a{1}{2}) { print "12 defined second pass.\n"; }
[...]
> I do not want intermediate hash keys to be created, and I do not want to
> code:
> if (defined %a &&
> defined $a{1} &&
> defined $a{1}{2} &&
> defined $a{1}{2}{3}) { .... }
Hi,
I'd guess the best solution would be to test for the existance
of the hash key first. Like
if( exists $a{1}{2}{3} && defined $a{1}{2}{3} ) { ... }
exists() doesn't create any keys. defined() always does due to
autovivication. "perldoc -f exists" and "perldoc -q defined"
point this out.
Think you won't get around making both test on the hash item.
Regards
-Christian
------------------------------
Date: Thu, 24 Oct 2002 05:47:07 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: deleting a file... kill ??? Thanks...
Message-Id: <vPLt9.5235$iV1.2571@nwrddc02.gnilink.net>
Helgi Briem wrote:
> On Wed, 23 Oct 2002 01:15:22 GMT, "Jürgen Exner"
> <jurgenex@hotmail.com> wrote:
>
>> G.Doucet wrote:
>>> Wouldn't you think that my book's index would have had an
>>> entry on deleting files?
>>
>> PS: Wouldn't you think that the Perl documentation is a better
>> source for information about a specific function than some book?
>
> On this precise subject I tend to agree with G. Doucet, if
> only because perldoc -q delete does not return anything
> relevant to deleting files.
Right. But checking out "perldoc -f kill" would have told him for sure that
kill is not the function he is looking for. That was my point.
> I still don't really understand why someone decided to call
> it unlink and not rm or delete or remove or something.
Because that is what the function does. "Unlink" does not delete files. It
only removes the link pointing from the directory to the file. Seems to be
quite reasonable to call this function unlink.
And only if this link happens to be the last link pointing to this file,
then the file will be removed by the OS automatically. This is the way how
file systems work.
jue
------------------------------
Date: Thu, 24 Oct 2002 05:50:04 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: deleting a file... kill ??? Thanks...
Message-Id: <gSLt9.5238$iV1.3835@nwrddc02.gnilink.net>
Bart Lateur wrote:
> Helgi Briem wrote:
>
>> I still don't really understand why someone decided to call
>> it unlink and not rm or delete or remove or something.
>
> Because on Unix, it is not garanteed to delete a file. You can have
> more than one hard connections (links) between the name of the file
> in the filesystem, and the contents. and unlink deletes *one* such
> entry. Only if *all* these name entries are deleted, the file
> contents itself gets wiped.
To complicate things yet a bit more: any open file handle to this file
counts as a link, too. Very frequently used to create hidden temporary
files.
jue
------------------------------
Date: Thu, 24 Oct 2002 05:40:41 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: deleting a file... kill ???
Message-Id: <tJLt9.5228$iV1.4227@nwrddc02.gnilink.net>
Bart Lateur wrote:
> G.Doucet wrote:
>
>> if(-e "$obidfil"){kill $obidfil;}
>
> As everybody else is saying, you want unlink(). But I'd like to add
> that you don't have to do the file test, just
>
> unlink $obidfil;
>
> will do.
Well, it might be useful to test if the unlink was successfull
die "Can't unlink $obidfil because $!\n" unless unlink $obidfil;
jue
------------------------------
Date: 23 Oct 2002 18:06:55 -0600
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: Finding words in a string.
Message-Id: <3db7399e@news.mhogaming.com>
Yils Kraabe <krikrok.horse@hotmail.com> wrote:
>
> I have a string and I want to find words in this string
> containing, say, the letter 'e'. I was wondering what
> was the 'optimal' way in perl, since I am not that used
> to it. I produced
>
> $string = "Some text with words";
> @string = split /\s+/, $string;
> @mywords = grep { /e/ } @string;
>
> It takes only 3 lines but I wonder if this is efficient
> to build a temporary list @string. Is there another
> better way to do that?
>
It would be more idiomatic to do it in one stream:
@words = grep /e/, split ' ', $string;
Or you could just use a regex.
@words = $string =~ /\S*e\S*/g;
--
Steve
perldoc -qa.j | perl -lpe '($_)=m("(.*)")'
------------------------------
Date: Wed, 23 Oct 2002 21:47:19 -0700
From: Antonio <agm@socrates.berkeley.edu>
Subject: HTML <img ...>
Message-Id: <Pine.GSO.4.44.0210232146130.10422-100000@socrates.Berkeley.EDU>
I am trying to build a webcounter-type thing, such that a call to an image
in HTML of the form
<img src="server/cgi-bin/counter.pl">
not only compiles some stats based on the environment variables httpd
passes to the CGI, but also actually displays an image, be it a counter,
or just any random thing (better than the missing image icon it presently
shows).
Does anyone know how to make a perl script 'return' an image?
Thanks, A.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Antonio Garcia-Martinez
cryptologia.com
------------------------------
Date: 24 Oct 2002 05:50:27 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: HTML <img ...>
Message-Id: <ap81n3$626$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Antonio:
> I am trying to build a webcounter-type thing, such that a call to an image
> in HTML of the form
>
><img src="server/cgi-bin/counter.pl">
>
> not only compiles some stats based on the environment variables httpd
> passes to the CGI, but also actually displays an image, be it a counter,
> or just any random thing (better than the missing image icon it presently
> shows).
>
> Does anyone know how to make a perl script 'return' an image?
Like any other language would do it. You first print the correct
content-type header and after that send the image-data to stdout:
use CGI qw/:standard/;
...
open IMG, "image.png" or die ...;
binmode IMG; # only needed for Windows-boxes
print header("image/png");
print do { local $/; <IMG> };
You can also create an image within your script. There are a bunch of
modules for that: Image::Magic, GD, GD::Graph etc. Here's a snippet of
something I did a while ago for displaying graphs of some usage
statistics:
use GD::Graph::Data;
use GD::Graph::bars;
...
my @data = ( ... ); # fill this
my $graph = GD::Graph::bars->new(600,400);
$graph->set(
title => 'Usage stats:',
x_label => 'Servers',
y_label => 'Hits',
bar_width => 5,
y_number_format => '%d',
y_tick_number => 10,
show_values => 1,
);
my $format = $graph->export_format;
print header("image/$format");
print $graph->plot(\@data)->$format;
You don't even have to care about the image formats. It'll print the
correct content-type whatever applicable image format the module can
handle.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: 23 Oct 2002 17:49:48 -0600
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: negation
Message-Id: <3db7359b@news.mhogaming.com>
R.Noory <rnoory@videotron.ca> wrote:
>
> My imput is
> stupefy
> qualify
> classify
> affy
>
> I want to create two clusters out of my input
> stupe(fy)
> af(fy)
> qual(ify)
> class(ify)
>
> Ify$ change to (ify)
> non ify$ change (fy)
>
> What is the best way to create two non-overlapping
> clusters with RE.
Don't know what you mean by "non-overlapping clusters",
but based on your examples:
s/(i?fy)$/($1)/;
And you might prefer \z or \b to '$'.
--
Steve
perldoc -qa.j | perl -lpe '($_)=m("(.*)")'
------------------------------
Date: Wed, 23 Oct 2002 21:56:32 -0400
From: Paul Murphy <pnmurphyNO_SPAM_TODAY_THANK_YOU@cogeco.ca>
Subject: Newbie Perl script help
Message-Id: <20021023215632.444ff1b1.pnmurphyNO_SPAM_TODAY_THANK_YOU@cogeco.ca>
I am trying to convert all my shell scripts into perl scripts, but with the attached I am having a problem. I keep getting the following errors no matter what I do ( obviously I'm not doing the right thing ):
[earth] /home/paul: bin/outside-temp.pl
Use of uninitialized value at bin/outside-temp.pl line 22.
Use of uninitialized value at bin/outside-temp.pl line 23.
Use of uninitialized value at bin/outside-temp.pl line 24.
Use of uninitialized value at bin/outside-temp.pl line 16.
the sub strip_html {} I copied from http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/striphtml.gz which works fine as a stand-alone program.
p.s. Did I mention I was a newbie.
--
Cogeco ergo sum
------------------------------
Date: Thu, 24 Oct 2002 00:13:30 -0400
From: "Francois Pichette" <fpichette@NOSPAMvideotron.ca>
Subject: Order form script
Message-Id: <KrKt9.28369$Td.554656@wagner.videotron.net>
Hi, I am setting up a website and I need to create an order form to allow
users to pay for goods via Credit Card.
Is there a FREE CGI/Perl script that allows this?
I have downloaded and installed a so called "free" named REDICART, only to
find that if you want to process credit cards, you have to do it on there
secure server and pay $45/month.
I am not ready to fork out $45/month for avirtual shopping carts until I
know that the web site is profitable, however, I know that security may be
sacrificed.
Thanks
------------------------------
Date: 24 Oct 2002 00:02:40 GMT
From: ctcgag@hotmail.com
Subject: Re: Parallel ForkManger - Multiprocessors
Message-Id: <20021023200240.063$Lt@newsreader.com>
"cakes99" <cakes@doentreply.com> wrote:
> ***** I've searched the documentation and other sources but could not
> find an answer.
>
> Will the Parallel ForkManager utilize a system that contains multiple
> processors?
That's up to the system.
> For instance, I currently am running a program on a machine
> with 1 processor. If I were to move the program to a server with 4
> processors, would their be a difference in time between the two, due to
> the increase in processors?
Try it and see. If you processes are all trying to pull from the same
hard drive controller, and that is the limiting step, they won't
go much faster. If you fork 4 processes which are each CPU bound, and the
system migrates processes across CPUs (and I don't know why you'd have a
4 processor system that doesn't do that), it should be ~4 x faster.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service
------------------------------
Date: 23 Oct 2002 17:07:55 -0700
From: Gerard Lanois <gerardlanois@netscape.net>
Subject: Re: Perl bloggers?
Message-Id: <NGidnVlddv7spCqgXTWQlg@News.GigaNews.Com>
tuglyraisin@aol.commune (Andrew Burton) writes:
> someone in the Perl community who blogs about Perl
http://home.san.rr.com/lanois/perl/
RSS v0.91 feed is http://home.san.rr.com/lanois/perl/site.xml
Homebrew pure Perl CMS, using libxml-perl and Template Toolkit. Email me
if you want a snapshot.
-Gerard
------------------------------
Date: 23 Oct 2002 14:48:59 -0700
From: lefkogt@gppbt.org
Subject: Perl Calling C issues??
Message-Id: <ap75gb01uik@drn.newsguy.com>
Can anyone offer some advice for us on the following?
We have a C program that calls some files specified by command arguments that
retrieve weather data based on latitude and longitude blocks. We have data on
the entire country and so it is located on the AIX servers here. The C program
is also on the server in a different location. The consultant who worked with
the weather data has provided us with a web interface (a perl script) to get the
data and provide it to the user in a web page format. The user will be running
this from his pc. Our problem seems to be that since the webserver runs as
nobody, the process it generates runs as nobody and doesn't have sufficient RW
access to run the C program, read the data files (if the C program were to run)
or to write to a file (given that the first two things happen). We have tried
various ways to get the script to run, including setuid and a program called
cgiwrap, etc. But AIX refuses to allow us to setuid to a file, even when we
have the root level administrators try it.
We have done enough debugging to know that the C program works in it's own area,
and have tested the perl script with our own test scripts to feel comfortable
that it works when we run it where we have sufficient privileges.
Thanks
Gary
------------------------------
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 4019
***************************************