[16432] in Perl-Users-Digest
Perl-Users Digest, Issue: 3844 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 29 14:10:32 2000
Date: Sat, 29 Jul 2000 11:10:17 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <964894217-v9-i3844@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 29 Jul 2000 Volume: 9 Number: 3844
Today's topics:
Re: I Am An Idiot <dave@dave.org.uk>
Re: I Am An Idiot <gellyfish@gellyfish.com>
Re: I Am An Idiot <godzilla!@stomp.stomp.tokyo>
Re: I Am An Idiot <dave@dave.org.uk>
Re: I Am An Idiot <godzilla!@stomp.stomp.tokyo>
Re: I Am An Idiot <dave@dave.org.uk>
Re: I Am An Idiot <godzilla!@stomp.stomp.tokyo>
Re: I Am An Idiot (Andrew Johnson)
Re: I need help <dave@dave.org.uk>
Re: Is "exit()" really necessary? <uri@sysarch.com>
Re: Problems with next; in subroutines <noemail@nodomain.com>
Re: Problems with next; in subroutines (Keith Calvert Ivey)
Re: Programmer - PERL - JAVA - JS - HTML - DreavWeaver <uri@sysarch.com>
Re: Programmer - PERL - JAVA - JS - HTML - DreavWeaver <dave@dave.org.uk>
RAM info <haggi@tappe.net>
Re: RAM info (Abigail)
Re: RAM info <nospam.tom@hotmail.com>
Re: RAM info (Clinton A. Pierce)
Re: search.cgi >How do I? (Marcel Grunauer)
Re: search.cgi >How do I? (Abigail)
Re: Should truncate length be 0? <bart.lateur@skynet.be>
small regex problem hamed53@my-deja.com
Re: small regex problem <kjetilskotheim@iname.com>
Re: small regex problem <gellyfish@gellyfish.com>
Re: small regex problem <godzilla!@stomp.stomp.tokyo>
Re: Split Help mwhaley@my-deja.com
Re: Suggestion for syntax change <uri@sysarch.com>
Re: taking subroutine name as a parameter <bart.lateur@skynet.be>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 29 Jul 2000 14:37:55 +0100
From: Dave Cross <dave@dave.org.uk>
Subject: Re: I Am An Idiot
Message-Id: <2en5oscvi259tagf65lcda6ouuk77rc9no@4ax.com>
On Sat, 29 Jul 2000 11:56:14 GMT, "Tim Kosmider"
<tkosmider@mgfairfax.rr.com> wrote:
>There are many ways, depends on the kinds of data you are reading.
>
>open (FILE, "myfile.txt");
You should _always_ check the return value from a call to open.
open(FILE, 'myfile.txt') or die "Can't open file:$! \n";
>while (<FILE>) {
> chomp;
> print "$_\n"; # line from file is in special variable $_
>}
Why remove the newline with chop, simply to add it on again on the
next line?
hth,
Dave...
--
<http://www.dave.org.uk> SMS: sms@dave.org.uk
yapc::Europe - London, 22 - 24 Sep <http://www.yapc.org/Europe/>
"There ain't half been some clever bastards" - Ian Dury [RIP]
------------------------------
Date: 29 Jul 2000 15:44:59 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: I Am An Idiot
Message-Id: <8luqlb$fnu$1@orpheus.gellyfish.com>
On Sat, 29 Jul 2000 11:56:14 GMT Tim Kosmider wrote:
> There are many ways, depends on the kinds of data you are reading.
>
> open (FILE, "myfile.txt");
>
You will want to check the success of this open and report the reasons
for any failure :
open(FILE,'myfile.txt') || die "Could'nt open 'myfile.txt' : $!\n";
> while (<FILE>) {
> chomp;
> print "$_\n"; # line from file is in special variable $_
> }
>
> If the file you want to read is comma delimited. You can put the line into
> an array.
>
> open (FILE, "myfile.txt");
>
> while (<FILE>)
>
> chomp;
> @flds = split(","); #create array from input line, separate line at
the first argument to split() is a regular expression - it is probably
less confusing to the beginner to make that explicit ( split /,/ ).
/J\
--
yapc::Europe in assocation with the Institute Of Contemporary Arts
<http://www.yapc.org/Europe/> <http://www.ica.org.uk>
------------------------------
Date: Sat, 29 Jul 2000 07:27:05 -0700
From: "Godzilla!" <godzilla!@stomp.stomp.tokyo>
Subject: Re: I Am An Idiot
Message-Id: <3982E9B9.B75A82E9@stomp.stomp.tokyo>
Dave Cross wrote:
> Tim Kosmider wrote:
> > There are many ways, depends on the kinds of data you are reading.
> > open (FILE, "myfile.txt");
> You should _always_ check the return value from a call to open.
> open(FILE, 'myfile.txt') or die "Can't open file:$! \n";
(snipped)
Jonathan Stowe wrote in another article:
> You will want to check the success of this open and report
> the reasons for any failure :
> open(FILE,'myfile.txt') || die "Could'nt open 'myfile.txt' : $!\n";
No, you should not. For many scripts this is the absolute
worst thing to do. You should check for file opening within
many scripts, but as needed, not _always_ as so many harp.
Use of die will kill your program under circumstances where
you would rather have your script continue running and not
produce results for certain open calls or produce results
based on a failed open, intentionally.
As a clear example,
open (POKERLOG, "+<$poker_log");
$read_poker = <POKERLOG>;
close (POKERLOG);
if (!($read_poker))
{
open (POKERLOG2, ">$poker_log");
print POKERLOG2 "500";
close (POKERLOG2);
$player_cash = "500";
}
if ($read_poker)
{ $player_cash = $read_poker; }
Many rounds of poker are played, player cash
is tracked and tallied. Final total of player
cash is recorded much later or a special error
message is created in my private log records,
if all open calls in my script fail. A visitor
gets to play poker regardless of an open error.
With die included, my visitor would not be able
to play poker, at all, if a failure occurs and,
my visitor would experience unwarranted problems.
Use of die, with this script, is to doom my program
to failure if a single open call fails. Without
open error checking, my script is guaranteed to
run successfully.
Checking for opening should be used wisely,
not pedantically. When I read this "always"
dogma, this sends me a message, which is true
for literally every regular within this group,
"Here is a person with little programming experience."
Godzilla!
--
@© = (a .. z); @® = qw (7 15 4 26 9 12 12 1 18 15 3 11 19);
srand(time() ^ ($$ + ($$ << 15)));
sub G { rand(1000) < 500 ? "\u$1" : "\l$1" ; }
foreach $¿ (@®) { $¢ = $©[$¿-1]; $¢ =~ s/([a-z])/G($1)/gie;
if ($¢ =~ /($©[0])/i) { $¢ = "$¢ "; } print $¢; }
print "!"; exit;
------------------------------
Date: Sat, 29 Jul 2000 15:39:35 +0100
From: Dave Cross <dave@dave.org.uk>
Subject: Re: I Am An Idiot
Message-Id: <spq5oscapcn5r0643nhq2bh1lhl43ifve3@4ax.com>
On Sat, 29 Jul 2000 07:27:05 -0700, "Godzilla!"
<godzilla!@stomp.stomp.tokyo> wrote:
>Dave Cross wrote:
>
>> Tim Kosmider wrote:
>
>> > There are many ways, depends on the kinds of data you are reading.
>
>> > open (FILE, "myfile.txt");
>
>
>> You should _always_ check the return value from a call to open.
>
>> open(FILE, 'myfile.txt') or die "Can't open file:$! \n";
>
>
>(snipped)
>
>Jonathan Stowe wrote in another article:
>
>> You will want to check the success of this open and report
>> the reasons for any failure :
>
>> open(FILE,'myfile.txt') || die "Could'nt open 'myfile.txt' : $!\n";
[snip advice not to check the result of an 'open' call]
Kira,
You feel free to go ahead and write your programs however you want.
I'll stick with following acknowledged best practices and advising
newbies to do the samething.
>Checking for opening should be used wisely,
>not pedantically. When I read this "always"
>dogma, this sends me a message, which is true
>for literally every regular within this group,
>
>"Here is a person with little programming experience."
When I see people advocating _not_ checking the return value from a
system call this sends a meesage which is true for you,
"Here is a pperson that I would _never_ let near any of my production
code."
Dave...
--
<http://www.dave.org.uk> SMS: sms@dave.org.uk
yapc::Europe - London, 22 - 24 Sep <http://www.yapc.org/Europe/>
"There ain't half been some clever bastards" - Ian Dury [RIP]
------------------------------
Date: Sat, 29 Jul 2000 08:29:05 -0700
From: "Godzilla!" <godzilla!@stomp.stomp.tokyo>
Subject: Re: I Am An Idiot
Message-Id: <3982F841.EF2D00C9@stomp.stomp.tokyo>
Dave Cross blathered and lied:
> Godzilla! wisely wrote:
> >Dave Cross wrote:
> >> Tim Kosmider wrote:
> >> > There are many ways, depends on the kinds of data you are reading.
> >> > open (FILE, "myfile.txt");
> >> You should _always_ check the return value from a call to open.
> >> open(FILE, 'myfile.txt') or die "Can't open file:$! \n";
> >(snipped)
> >Jonathan Stowe wrote in another article:
> >> You will want to check the success of this open and report
> >> the reasons for any failure :
> >> open(FILE,'myfile.txt') || die "Could'nt open 'myfile.txt' : $!\n";
> [snip advice not to check the result of an 'open' call]
This is a lie.
> Kira,
> You feel free to go ahead and write your programs however you want.
I do not need nor recognize your sexist permission to do as I wish.
> I'll stick with following acknowledged best practices and advising
> newbies to do the samething.
I will elect to continue giving good and realistic advice.
> >Checking for opening should be used wisely,
> >not pedantically. When I read this "always"
> >dogma, this sends me a message, which is true
> >for literally every regular within this group,
> >"Here is a person with little programming experience."
> When I see people advocating _not_ checking the return
> value from a system call this sends a meesage which
> is true for you,
I have not advocated "not" checking for open errors.
You are simply lying to massage your bruised ego.
I have found, in Life, liars to weak-kneed no counts.
Having elected to lie, twice, you have also elected to
reduce your personal credibility to absolute zero,
chilling thought, yes?
> "Here is a pperson that I would _never_ let near any
> of my production code."
I suspect you have written few, if any good programs,
based on this very poor advice you and others promulgate.
This lying of yours is most repugnant. I am ethically offended.
Godzilla!
--
I will violoncello rock you.
http://la.znet.com/~callgirl3/highway.mid
------------------------------
Date: Sat, 29 Jul 2000 17:56:39 +0100
From: Dave Cross <dave@dave.org.uk>
Subject: Re: I Am An Idiot
Message-Id: <jq26os8ljbfcf1cgehpdasgleak6dlbpq5@4ax.com>
On Sat, 29 Jul 2000 08:29:05 -0700, "Godzilla!"
<godzilla!@stomp.stomp.tokyo> wrote:
>This is a lie.
and
>I do not need nor recognize your sexist permission to do as I wish.
and
>You are simply lying to massage your bruised ego.
>I have found, in Life, liars to weak-kneed no counts.
>Having elected to lie, twice, you have also elected to
>reduce your personal credibility to absolute zero,
>chilling thought, yes?
and
>This lying of yours is most repugnant. I am ethically offended.
You're absolutely right of course Kira. I've had people round here
fooled for a few years now, but there's no way I can fool someone as
switched on as you.
I am, of course, a lying misogynistic script-kiddie who wouldn't know
piece of decent Perl code if it jumped up and down in front of me
waving a sign saying "Look! I'm a well-written piece of Perl code".
Ah well, my cover is broken. I shall have to retire from the Perl
community and go back to my first love - Visual Basic.
It's been average.
Bye y'all,
Dave...
--
<http://www.dave.org.uk> SMS: sms@dave.org.uk
yapc::Europe - London, 22 - 24 Sep <http://www.yapc.org/Europe/>
"There ain't half been some clever bastards" - Ian Dury [RIP]
------------------------------
Date: Sat, 29 Jul 2000 10:32:44 -0700
From: "Godzilla!" <godzilla!@stomp.stomp.tokyo>
Subject: Re: I Am An Idiot
Message-Id: <3983153C.C252490F@stomp.stomp.tokyo>
Dave Cross wrote:
> Godzilla! chastised:
(snipped)
> >This lying of yours is most repugnant. I am ethically offended.
(snipped)
> I am, of course, a lying misogynistic script-kiddie who wouldn't know
> piece of decent Perl code if it jumped up and down in front of me
> waving a sign saying "Look! I'm a well-written piece of Perl code".
Dealing with misogynists is easy. I am well experienced with
this problem as an aggressively assertive woman. However,
those who elect to deliberately tell lies with an intent to
personally offend, this really does rasp my daddle. You told
some lies, you collected your consequences. Deal with it,
Big Boy.
> It's been average.
> Bye y'all,
Ahhh... po' babe. You are breaking my wittle heart,
truly you are. Ever get a hankering again to get a
butt blistering for lying, come on back.
Godzilla!
--
$godzilla = "godzilla rocks!";
srand(time() ^ ($$ + ($$ << 15)));
sub randcase
{ rand(40) < 20 ? "\u$1" : "\l$1" ; }
$godzilla =~ s/([a-z])/randcase($1)/gie;
print $godzilla; exit;
------------------------------
Date: Sat, 29 Jul 2000 17:45:03 GMT
From: andrew-johnson@home.com (Andrew Johnson)
Subject: Re: I Am An Idiot
Message-Id: <zKEg5.16788$k5.170555@news1.rdc1.mb.home.com>
In article <jq26os8ljbfcf1cgehpdasgleak6dlbpq5@4ax.com>,
Dave Cross <dave@dave.org.uk> wrote:
[snip]
! I am, of course, a lying misogynistic script-kiddie who wouldn't know
! piece of decent Perl code if it jumped up and down in front of me
! waving a sign saying "Look! I'm a well-written piece of Perl code".
It's true -- I once bought a piece of decent Perl code, from a
reputable dealer, 'cause like, I couldn't write one, and I gave it
that very sign, a plane ticket to England and some pocket money, and
I told it to find Dave and jump up and down and wave the sign and to
send word back if Dave ever figured out what it was. Well, I never
heard from that code again so obviously Dave doesn't have a clue. My
friends suspect that it was a far cleverer piece of code than I'd
imagined and that it traded in its ticket and is now sipping umbrella
drinks on a beach in Tahiti, but I don't think so ... I think it's
jumping up and down in front of Dave right now ...
! Ah well, my cover is broken. I shall have to retire from the Perl
! community and go back to my first love - Visual Basic.
I wonder if there's still time to register for Euro-yavbc.
:-)
andrew
--
Andrew L. Johnson http://members.home.net/andrew-johnson/
Optimist: The glass is half full.
Pessimist: The glass is half empty.
Engineer: The glass is twice as big as it needs to be.
------------------------------
Date: Sat, 29 Jul 2000 14:32:45 +0100
From: Dave Cross <dave@dave.org.uk>
Subject: Re: I need help
Message-Id: <gtm5oso89anjri3hukhp3c4f0oj24150nc@4ax.com>
On Fri, 28 Jul 2000 16:06:03 -0700, nikita <nikitta@ica.net> wrote:
>sub parse_form {
> read(STDIN, $cache, $ENV{'CONTENT_LENGTH'});
> if (length($cache) < 5) {
> $buffer = $ENV{QUERY_STRING};
> }
>
> @pairs = split(/&/, $cache);
> foreach $pair (@pairs) {
> ($name, $value) = split(/=/, $pair);
>
> $value =~ tr/+/ /;
> $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>
> $FORM{$name} = $value;
> }
>}
I really wish I had a pound for every time I'd seen a hand-written CGI
parameter parsing routine with the same bug in that yours exhibits.
If you're going to write your own CGI parameter parser (and I don't
know why you wuold do that given that you're using CGI.pm anyway),
then you should read the CGI specs to understand what situations your
routine needs to handle.
For example, have you considered what would happen if this routine had
to deal with a (completely valid) query string that looked like this:
key1=val2&key2=val2a&key2=val2b
Your %FORM hash would contain the values key1 => 'val1', key2 =>
'val2b'. Where is the val2a value for key2? Nowhere because you
overwrote the value by assuming that each key in a CGI query string
can only have one value.
Please use the tools that you have been given.
hth,
Dave...
--
<http://www.dave.org.uk> SMS: sms@dave.org.uk
yapc::Europe - London, 22 - 24 Sep <http://www.yapc.org/Europe/>
"There ain't half been some clever bastards" - Ian Dury [RIP]
------------------------------
Date: Sat, 29 Jul 2000 16:00:37 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Is "exit()" really necessary?
Message-Id: <x766pp53kr.fsf@home.sysarch.com>
>>>>> "JS" == Jonathan Stowe <gellyfish@gellyfish.com> writes:
JS> There might be perfectly valid reasons for occasioning a normal
JS> termination from a program somewhere other than at the end, though
JS> most people will just use flow control to do this rather than just
JS> jumping straight out of the program, though why if we are quite
JS> happy to sling 'die' around in the program we eschew exit does
JS> seem a little strange.
jeez, doesn't anyone here have any imagination? exit is a perfectly
useful call to make you program look better among other things. i use
this style sometimes:
foo() ;
bar() ;
exit ;
INIT {
foo init stuff
}
sub foo {
}
INIT {
bar init stuff
}
sub bar {
}
makes it easy to read, tells you that after the calls there is no more
inline code, just sub defs.
one related trick i show is to put initializations after the exit but in
INIT blocks. theyget executed after all compilation is done but before
main line executions starts. this is unlike BEGIN blocks which get
executed as soon as they are seen by the compiler. the INIT blocks are
used so if you have a late compiler bug, you won't execute some heavy
duty stuff that you stuffed in a BEGIN block like slurping in lots of
data.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Sat, 29 Jul 2000 15:21:52 GMT
From: "Dave A." <noemail@nodomain.com>
Subject: Re: Problems with next; in subroutines
Message-Id: <kECg5.11159$Mt.149477@nnrp1.ptd.net>
: > foreach $port (@ports) {
: > $SIG{"ALRM"} = sub {
: > print "Timed Out connecting to port: $port\n";
: > if ($socket) { close ($socket); }
: > next;
: > };
: [snip]
:
: That "next" is inside the anonymous subroutine, which doesn't
: contain a loop. The code in the anonymous subroutine isn't part
: of the code outside it. I don't understand what you're trying
: to accomplish with the "next", so I can't advise you further.
foreach is the loop.
for each port in @ports, do the following...
The problem is, let's say the server stops responding.
Or, the router between the program, and the server starts to
'drop' packets, and not deny them..
When attempting to connect to a port, on the server,
you will not get a response, at all. Therefor, the program
will wait forever for an answer, unless you set a timeout
value.
Now, IO::Socket has a Timeout => parameter,
that does not work. I have seen many posts about it
before. The work around, was the alarm (); function.
So, when the alarm $timeout is reached, it runs it's own
sub routine. next; should tell the program to move along
to the next port in the foreach command, since it is the inner-most
loop at our current position in the program.
(side note)
The alarm function works perfectly, if I make use of raw socket
commands, e.g;
<alarm functions here>
socket(S,$AF_INET,$SOCK_STREAM,$proto) or die "Cannot build socket: $! \n";
connect(S,$server) or die "Cannot connect to server $host : $! \n";
and not use IO::Socket.
But I was hoping to shorten the code with the use of
IO::Socket.
Does this make more sense?
David
------------------------------
Date: Sat, 29 Jul 2000 15:57:30 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Problems with next; in subroutines
Message-Id: <3984fb9c.45780537@news.newsguy.com>
"Dave A." <noemail@nodomain.com> wrote:
>So, when the alarm $timeout is reached, it runs it's own
>sub routine. next; should tell the program to move along
>to the next port in the foreach command, since it is the inner-most
>loop at our current position in the program.
That makes sense. Sorry about misunderstanding before. But
aren't you missing an "alarm 0;" after the socket connection
line? You don't want the alarm subroutine to be triggered
unless you're in that loop; otherwise, who knows what loop
you'll be nexting out of 5 seconds later when there isn't a
timeout.
And shouldn't you be using eval {} and localizing $SIG{ALRM},
as in perlipc?
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: Sat, 29 Jul 2000 17:12:12 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Programmer - PERL - JAVA - JS - HTML - DreavWeaver
Message-Id: <x73dks6ety.fsf@home.sysarch.com>
>>>>> "T" == TeleComMuter <TeleComMuter@WeBProgrammersInternational.net> writes:
T> 15 TO 40 HOURS PER WEEK
T> $15.00 to $25.00 per hour commensurate with experience.
wow! a job for purlmoron! with a pay rate commensurate with her skills!
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Sat, 29 Jul 2000 18:14:39 +0100
From: Dave Cross <dave@dave.org.uk>
Subject: Re: Programmer - PERL - JAVA - JS - HTML - DreavWeaver
Message-Id: <7646oss1p901htejlvcu206qqns07vf7o0@4ax.com>
On Sat, 29 Jul 2000 17:04:40 GMT,
TeleComMuter@WeBProgrammersInternational.net wrote:
[a job advert]
use dha::Job::Posting::Rant qw(:standard);
--
<http://www.dave.org.uk> SMS: sms@dave.org.uk
yapc::Europe - London, 22 - 24 Sep <http://www.yapc.org/Europe/>
"There ain't half been some clever bastards" - Ian Dury [RIP]
------------------------------
Date: Sat, 29 Jul 2000 16:35:09 +0200
From: "haggi@work" <haggi@tappe.net>
Subject: RAM info
Message-Id: <3982EB9D.E15A929C@tappe.net>
is there anywhere a perl function which can give me info about
the RAM of the machine on which perl is running?
haggi
--
---------------------------------------------------------
haggi
www.haggi.de
haggi@haggi.de
haggi`s visual effects & animation
---------------------------------------------------------
------------------------------
Date: 29 Jul 2000 13:14:56 EDT
From: abigail@foad.org (Abigail)
Subject: Re: RAM info
Message-Id: <slrn8o6486.vcg.abigail@alexandra.foad.org>
haggi@work (haggi@tappe.net) wrote on MMDXXIV September MCMXCIII in
<URL:news:3982EB9D.E15A929C@tappe.net>:
:)
:) is there anywhere a perl function which can give me info about
:) the RAM of the machine on which perl is running?
No.
Retrieving such info is highly system dependent. You might actually
have to open your box and look up the parts numbers of your RAM.
Abigail
--
perl -wle 'print "Prime" if (0 x shift) !~ m 0^\0?$|^(\0\0+?)\1+$0'
------------------------------
Date: Sun, 30 Jul 2000 00:48:43 +0800
From: DT <nospam.tom@hotmail.com>
Subject: Re: RAM info
Message-Id: <MPG.13ed8bc4c9fb8f86989685@news.newsguy.com>
In article <3982EB9D.E15A929C@tappe.net>, haggi@tappe.net says...
>
> is there anywhere a perl function which can give me info about
> the RAM of the machine on which perl is running?
>
>
> haggi
>
use top
------------------------------
Date: Sat, 29 Jul 2000 17:22:24 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: RAM info
Message-Id: <kpEg5.54608$fR2.507354@news1.rdc1.mi.home.com>
In article <3982EB9D.E15A929C@tappe.net>,
"haggi@work" <haggi@tappe.net> writes:
>
> is there anywhere a perl function which can give me info about
> the RAM of the machine on which perl is running?
bash-2.01$ perl -e '@a=(1..1_000_000_000);'
Out of memory!
This tells you that there isn't enough RAM. :))
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours!
clintp@geeksalad.org for details see http://www.geeksalad.org
"If you rush a Miracle Man,
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: Sat, 29 Jul 2000 13:02:02 GMT
From: marcel@codewerk.com (Marcel Grunauer)
Subject: Re: search.cgi >How do I?
Message-Id: <slrn8o5lpc.kpp.marcel@gandalf.local>
On Sat, 29 Jul 2000 13:52:02 +0100, Rich <rock.ice@bigfoot.com> wrote:
>If I add say the second line here for example:
>===============================
>print "Below are your search results:<p></center><hr size=7
>width=75%><p>\n";
>print "<font=arial>\n";
>foreach $key (keys %include) {
> if ($include{$key} eq 'yes') {
> print "<li><a href=\"$baseurl$key\">$titles{$key}</a>\n";
> }
> }
> print "</ul>\n";
>=================================
>The script won't work. If I remove the 2nd line it works again. How so?
>Should I do this offline in Windows before I dos2unix and chmod or online
>afterwards with FTP Pro?
What does "won't work" mean? Does it just sit there? Does it produce an
error? If yes, which one?
Your second line given above (ITYM the second statement) is just a print
statement, so it shouldn't cause the program to stop working (for some
values of 'working').
If you have a problem with a CGI program, you can do several things:
Test it on the command line. Providing you use the CGI module (you do,
don't you?) you can simulate query string parameters by giving the
program command-line arguments (cf. CGI documentation - perldoc CGI).
Also, you can test it on your local webserver. See what it does, check
the error logs.
Check the error log of the remote web server.
Use the CGI::Carp module, which allows run-time errors to appear on the
resulting web page. making it somewhat more obvious what has gone wrong.
Maybe it's just your HTML which doesn't work. Try constructing the
desired output page by hand until it looks like you want it to, then
feed the results back into the script.
Good luck with it!
--
Marcel
sub AUTOLOAD{($_=$AUTOLOAD)=~s;^.*::;;;y;_; ;;print} Just_Another_Perl_Hacker();
------------------------------
Date: 29 Jul 2000 13:36:18 EDT
From: abigail@foad.org (Abigail)
Subject: Re: search.cgi >How do I?
Message-Id: <slrn8o65g7.vcg.abigail@alexandra.foad.org>
Rich (rock.ice@bigfoot.com) wrote on MMDXXIV September MCMXCIII in
<URL:news:8lujsc$km5$1@newsg1.svr.pol.co.uk>:
'' If I add say the second line here for example:
'' ===============================
'' print "Below are your search results:<p></center><hr size=7
'' width=75%><p>\n";
'' print "<font=arial>\n";
'' foreach $key (keys %include) {
'' if ($include{$key} eq 'yes') {
'' print "<li><a href=\"$baseurl$key\">$titles{$key}</a>\n";
'' }
'' }
'' print "</ul>\n";
'' =================================
'' The script won't work. If I remove the 2nd line it works again. How so?
'' Should I do this offline in Windows before I dos2unix and chmod or online
'' afterwards with FTP Pro?
"Won't work" is extremely vague, and highly dependent on what you _think_
is proper behaviour.
And I seriously doubt your claim. If I remove the second line in the
fragment above, what results is not valid Perl. And with the second line
there, you are not generating valid HTML; but that's outside of the
scope of this newsgroup.
Abigail
--
perl -wle 'eval {die ["Just another Perl Hacker"]}; print ${$@}[$#{@${@}}]'
------------------------------
Date: Sat, 29 Jul 2000 14:10:29 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Should truncate length be 0?
Message-Id: <2dn5oss4gqc9ei32rn1o8d0gcb2haalgo5@4ax.com>
Katia Hayati wrote:
>Does that mean that truncate() can be trusted to work only with a 2nd
>argument of 0?
No, truncate can be trusted with any value that is at most the current
length of the file. The problem is that sometimes, internally, some file
manipulating words, like print() will interfere with the proper working
of truncate(). I think it's related to file buffering.
On some palatforms, a script like this may fail:
print `perl -v`;
open OUT, "+>test.txt";
print OUT "Hello\n" x 1000;
seek OUT, 0, 0;
print OUT "New contents!\n";
truncate OUT, tell OUT;
close OUT;
print -s "test.txt";
If it doesn't print 14 or 15, something went wrong. And although it
succeeds on most platforms I tried, on the DJGPP DOS port or 5.005_02,
the result is 30.
If I insert
seek OUT, 0, 1;
in between the "print" statement and the "truncate" statement, it works.
--
Bart.
------------------------------
Date: Sat, 29 Jul 2000 13:19:07 GMT
From: hamed53@my-deja.com
Subject: small regex problem
Message-Id: <8lulk9$aad$1@nnrp1.deja.com>
Hi everyone...
I have this string:
$string = "[10] OutBound Digits : 111111 ";
i want to extract: "10" and "OutBound Digits" and "111111" from it.
I have written small regex myself, but it seems it only extracts a word
"OutBound" and not the second word "Digits" where it should extract all
words between "[10]" and ":"
heres the code i've written
$string =~ /^\[\s*(\d+)\] (\w*)\s+\: (.*)/;
print "$1\n";
print "$2\n";
print "$3\n";
Thanks for your help
Hamed
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sat, 29 Jul 2000 16:17:45 +0200
From: "KjetilSkotheim@iname.com" <kjetilskotheim@iname.com>
Subject: Re: small regex problem
Message-Id: <8lup2c$6eu$1@readme.uio.no>
Try:
$string =~ /^\[\s*(\d+)\]\s*([\w\s]*\w+)\s*\:\s*(.*)/;
Because \w do not match space.
hamed53@my-deja.com skrev i meldingen <8lulk9$aad$1@nnrp1.deja.com>...
>$string = "[10] OutBound Digits : 111111 ";
>
>i want to extract: "10" and "OutBound Digits" and "111111" from it.
>
>I have written small regex myself, but it seems it only extracts a word
>"OutBound" and not the second word "Digits" where it should extract all
>words between "[10]" and ":"
>
>$string =~ /^\[\s*(\d+)\] (\w*)\s+\: (.*)/;
>print "$1\n";
>print "$2\n";
>print "$3\n";
>
>Hamed
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.
------------------------------
Date: 29 Jul 2000 18:05:25 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: small regex problem
Message-Id: <8lv2sl$b6i$1@orpheus.gellyfish.com>
On Sat, 29 Jul 2000 13:19:07 GMT hamed53@my-deja.com wrote:
> Hi everyone...
>
> I have this string:
> $string = "[10] OutBound Digits : 111111 ";
>
> i want to extract: "10" and "OutBound Digits" and "111111" from it.
>
> I have written small regex myself, but it seems it only extracts a word
> "OutBound" and not the second word "Digits" where it should extract all
> words between "[10]" and ":"
>
Without spending too much effort on it -
$string = "[10] OutBound Digits : 111111 ";
if ( $string =~ /^\[\s*(\d+)\s*\]\s+(.+?)\s*:\s+(\d+)/ )
{
print "$1 - $2 - $3\n";
}
/J\
--
yapc::Europe in assocation with the Institute Of Contemporary Arts
<http://www.yapc.org/Europe/> <http://www.ica.org.uk>
------------------------------
Date: Sat, 29 Jul 2000 08:50:29 -0700
From: "Godzilla!" <godzilla!@stomp.stomp.tokyo>
Subject: Re: small regex problem
Message-Id: <3982FD45.3DF1A5EC@stomp.stomp.tokyo>
hamed53@my-deja.com wrote:
> I have this string:
> $string = "[10] OutBound Digits : 111111 ";
> i want to extract: "10" and "OutBound Digits" and "111111" from it.
> I have written small regex myself, but it seems it only extracts
> a word "OutBound" and not the second word "Digits" where it should
> extract all words between "[10]" and ":"
> heres the code i've written
> $string =~ /^\[\s*(\d+)\] (\w*)\s+\: (.*)/;
> print "$1\n";
> print "$2\n";
> print "$3\n";
Your article is one of poorly disguised deceit.
Only fools so foolish as to not test your givens
would be fooled by you.
TEST SCRIPT:
____________
#!/usr/local/bin/perl
print "Content-Type: text/plain\n\n";
$string = "[10] OutBound Digits : 111111 ";
print "My Code Method:\n\n";
print " Input:\n $string\n\n";
$string =~ s/\[\d+\] ([\w\s]+) : (\d+).*/$1$2/i;
print " Output:\n $string\n\n";
print "\n\nYour Code Method:\n\n";
$string = "[10] OutBound Digits : 111111 ";
print " Input:\n $string\n\n";
$string =~ /^\[\s*(\d+)\] (\w*)\s+\: (.*)/;
print " Output:\n";
print " $1\n";
print " $2\n";
print " $3\n";
exit;
PRINTED RESULTS:
________________
My Code Method:
Input:
[10] OutBound Digits : 111111
Output:
OutBound Digits 111111
Your Code Method:
Input:
[10] OutBound Digits : 111111
Output:
OutBound Digits
111111
______________________________________
Godzilla!
--
$godzilla = "godzilla rocks!";
srand(time() ^ ($$ + ($$ << 15)));
sub randcase
{ rand(40) < 20 ? "\u$1" : "\l$1" ; }
$godzilla =~ s/([a-z])/randcase($1)/gie;
print $godzilla; exit;
------------------------------
Date: Sat, 29 Jul 2000 15:15:48 GMT
From: mwhaley@my-deja.com
Subject: Re: Split Help
Message-Id: <8lusf1$eqq$1@nnrp1.deja.com>
Thanks for your help. Finally determined that my build of Perl is bad.
Later
In article <x7k8e87e2x.fsf@home.sysarch.com>,
Uri Guttman <uri@sysarch.com> wrote:
> >>>>> "m" == mwhaley <mwhaley@my-deja.com> writes:
>
> m> I'm trying to split a scalar read in from a file into parts based
on a
> m> \r (Carriage Return) located within the input line.
>
> and this is running on what platform? \r (or \015 for nit pickers) is
> the line separator for mac files. and it will be in the cr/lf of
> winblows files as well. it is a poor choice for a field separator.
>
> m> For some reason it seems like split isn't able to handle this.
It
> m> returns the whole string with the \r's stripped out in the array
> m> position [0].
>
> where is some sample input data? make sure it is cut and pasted
> cleanly.
>
> m> open INFILE, "ad046922.001";
> m> open OUTFILE, ">ad046922.out";
>
> always check the return of open calls.
>
> m> while (<INFILE>) {
>
> depending on $/ that could be eating the \r.
>
> m> chop;
>
> chomp is better.
>
> m> @fields = split /\r/;
> m> printf OUTFILE "%s\n", $fields[0];
>
> why the printf? just print "$fields[0]\n" ;
>
> a better test is to print all the fields with a very visible
separator:
>
> print OUTFILE "Record\n", map "[$_]\n", @fields ;
>
> then you can see exactly what was split (or not).
>
> uri
>
> --
> Uri Guttman --------- uri@sysarch.com ----------
http://www.sysarch.com
> SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX
Consulting
> The Perl Books Page -----------
http://www.sysarch.com/cgi-bin/perl_books
> The Best Search Engine on the Net ----------
http://www.northernlight.com
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sat, 29 Jul 2000 15:41:21 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Suggestion for syntax change
Message-Id: <x7bszh54gw.fsf@home.sysarch.com>
>>>>> "AJ" == Andrew Johnson <andrew-johnson@home.com> writes:
AJ> (Uri said I was warped, and implicated Manning authors ... he's
AJ> probably half right :-)
at least that much! :-)
AJ> (list)[0,1] -> return elements 0 and 1 from list
AJ> (list)[^0,1] -> return all *but* elements 0 and 1 from list
propose this to perl6. it would make more sense there than in perl5.
it seems to have its merits.
AJ> OK -- I've certainly had more than my share of beer, so if anyone
AJ> wants to stomp all over me now's the time (I won't mind, I'll be
AJ> sleeping).
as long as it was free beer, it is ok.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Sat, 29 Jul 2000 15:42:55 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: taking subroutine name as a parameter
Message-Id: <tiu5os8jceqcucr4244hc88hpoesae34kk@4ax.com>
Eyal Ben-David wrote:
>Why maintain a dispatch table when Perl already has one?
Because even though a sub f3 may exist, you may want to avoid people
from actually calling it. They can call any sub in your script through
symbolic references!
nb: the fact that the sub is called f1, and the string to call it is f1,
is pure coincidence. Well alright, I made it that way.
--
Bart.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 3844
**************************************