[22177] in Perl-Users-Digest
Perl-Users Digest, Issue: 4398 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 14 00:05:45 2003
Date: Mon, 13 Jan 2003 21:05:06 -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 Mon, 13 Jan 2003 Volume: 10 Number: 4398
Today's topics:
Book Question <ningli2000@worldnet.att.net>
Re: Can't get CGI script to work locally (Tad McClellan)
Re: Can't get CGI script to work locally <bart.lateur@pandora.be>
Re: Can't get CGI script to work locally <wsegrave@mindspring.com>
Re: command-line args style flags from a file (Kevin Newman)
Re: finding largest repeat values in array Andrew Lee
Re: FULL VERSION: Hi all gurus. What is wrong in my s <usenet@tinita.de>
How to execute a perl script from within a perl script <torvill@trolldata.no>
Re: My, our, etc. <goldbb2@earthlink.net>
NEW TO mod_perl: how to configure a perl filter to work (speedo goo)
overriding subroutines (David S April)
Re: overriding subroutines (Ben Morrow)
Re: Perl command line processing, Windows/dos style ? (Ben Morrow)
Re: Perl command line processing, Windows/dos style ? <pkent77tea@yahoo.com.tea>
Re: Perl command line processing, Windows/dos style ? <bongie@gmx.net>
Re: Perl command line processing, Windows/dos style ? <wksmith@optonline.net>
Perl Golf on my Mind (Boris Alexeev)
Re: Perl Golf on my Mind <uri@stemsystems.com>
Re: Perl Golf on my Mind <goldbb2@earthlink.net>
Re: search and replace problem <goldbb2@earthlink.net>
Re: sleep aborts script <flavell@mail.cern.ch>
The "default thing" (Bruce McKenzie)
Re: Using Expect to telnet to port 80 (not Expect::Simp <jay@rgrs.com>
Re: Why does this NOT work?? (Andrew Allaire)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 14 Jan 2003 01:50:33 GMT
From: "Ning li" <ningli2000@worldnet.att.net>
Subject: Book Question
Message-Id: <J1KU9.109942$hK4.8929539@bgtnsc05-news.ops.worldnet.att.net>
Hi,
I am new to Perl and I have used awk and sed for quite some time. I
would like to use Perl mainly for file manipulation and formatting. Can
someone suggest a good Perl book with focus on this topic?
Thanks in advance.
Nick Li
------------------------------
Date: Mon, 13 Jan 2003 17:12:27 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Can't get CGI script to work locally
Message-Id: <slrnb26hur.4j5.tadmc@magna.augustmail.com>
Daniel Murphy <danmurph@worldnet.att.net> wrote:
>
> I'm trying to get the following trivial code to work on my Win95 machine
> with IE 5.50, but I can't get the browser to display anything. The same Perl
> code works OK when run from the command line. I have Perl/CGI experience on
> Unix systems, but am I missing something obvious here?
You make no mention of a web server. Are you running one?
(sorry if that seems a silly question, but it happens nearly daily...)
> print "Content-type: text/html\n\n";
^^^^
> print "Hello";
HTML has lots of angle brackets in it. That doesn't look like HTML.
Did you mean to say text/plain instead?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 14 Jan 2003 00:06:18 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Can't get CGI script to work locally
Message-Id: <k3l62vcmditnfcqvutats5ad1j60dbru1e@4ax.com>
Daniel Murphy wrote:
>I have Perl/CGI experience on
>Unix systems, but am I missing something obvious here?
A lack of a web server.
--
Bart.
------------------------------
Date: Mon, 13 Jan 2003 19:06:17 -0600
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Can't get CGI script to work locally
Message-Id: <avvnvi$fme$1@slb6.atl.mindspring.net>
"Daniel Murphy" <danmurph@worldnet.att.net> wrote in message
news:XhHU9.109696$hK4.8912907@bgtnsc05-news.ops.worldnet.att.net...
>
> I'm trying to get the following trivial code to work on my Win95 machine
> with IE 5.50, but I can't get the browser to display anything. The same
Perl
> code works OK when run from the command line. I have Perl/CGI experience
on
> Unix systems, but am I missing something obvious here?
Download and install IndigoPerl, available free from www.indigostar.com,
which will give you a pre-configured Perl, Apache, and GUI package manager.
Point your browser to http://localhost/ to see if you get the success page.
If you succeed, all you have to do is drop your scripts in
c:\indigoperl\cgi-bin\ and your web pages in c:\indigoperl\htdocs\. Your
'Hello' script might look something like:
#!perl -w
# description of your script - hello.pl ...
use strict;
use CGI qw(-no_xhtml :standard);
print header, start_html, h1('Hello'), end_html;
Put the above script in cgi-bin as hello.pl and point your browser to
http://localhost/cgi-bin/hello.pl. See 'Hello' in browser. Don't forget to
start the Apache server first.
Cheers.
Bill Segraves
------------------------------
Date: 13 Jan 2003 20:46:39 -0800
From: knewman00@earthlink.net (Kevin Newman)
Subject: Re: command-line args style flags from a file
Message-Id: <4c8e4398.0301132046.404596ee@posting.google.com>
Stephen Patterson <s.patterson@freeuk.com> wrote in message news:<slrnb243fi.3lc.s.patterson@seagoon.localdomain>...
> On 12 Jan 2003 16:41:31 -0800, Kevin Newman wrote:
> > I have a script that I would like to control the behavior from the
> > command-line or a file. For example, let's say that I want to
> > compress a file:
> > myscript.pl -c -f <inputfile> -o <outputfile>
>
> I'd expect the App::Config hierarchy to be able to handle this,
> although given your example file...
>
> use English;
>
> unless (@ARGV) {
> open CFG, $file;
> @args = <CFG>;
> } else {
> @args = @ARGV
> }
>
> and its great posting code from an editor which nuderstands perl :)
I'll take a look at App::Config.
Thanks,
kln
------------------------------
Date: Mon, 13 Jan 2003 19:49:04 -0500
From: Andrew Lee
Subject: Re: finding largest repeat values in array
Message-Id: <5an62v8m89trlqdak8pv0072tl4iule6mj@4ax.com>
On 13 Jan 2003 16:52:43 GMT, ctcgag@hotmail.com wrote:
>Andrew Lee wrote:
>> On 07 Jan 2003 16:44:36 GMT, ctcgag@hotmail.com wrote:
>>
>> >hugo <hugo@geoinformex.com> wrote:
>> >> Hi
>> >>
>> [question snipped]
>>
>> >You need to reset repeat, and capture the greatest value.
>> >
>> >my $most=-1;
>> >my $repeat=1;
>> >for my $i (1..@myArray) {
>> > if (myArray[$i] eq myArray[$i -1]) {
>> > $repeat++;
>>
>> Ack!!!
>>
>> That won't work unless you have reset $[ (a soon to be deprectaed
>> "feature").
>
>Other than the missing $s, which $[ won't affect, why won't it work?
Ok. But, it will give a warning.
I am particularly wary of running past the end of an array. (old C
habits never die).
------------------------------
Date: 14 Jan 2003 00:52:39 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: FULL VERSION: Hi all gurus. What is wrong in my script?
Message-Id: <tinh8oi95$2zk$tina@news01.tinita.de>
Tad McClellan <tadmc@augustmail.com> wrote:
>> if ($size1 = 0) {
>> will give you:
>> Found = in conditional, should be == at untitled1.pl line x.
> Testing agains a constant _does_ look suspicious, so now
> it _can_ (unambiguously) issue a warning.
> We know that the above will always be false, even without
> knowing anything about $size1's value (that is going to
> get overwritten anyway).
OTOH, defining a constant with the constant pragma and
then doing
if ($size = SIZE) {...}
seems to be a bit more plausible, but it also gives
you a warning.
but i'd say this construct ("if $x = <something>") is
more useful for cases, where <something> is not
known before and for example changes with every call.
therefor i think it is good that perl warns here.
regards, tina
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://PerlQuotes.tinita.de/ \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: Tue, 14 Jan 2003 03:51:05 +0100
From: "Anders Torvill Bjorvand" <torvill@trolldata.no>
Subject: How to execute a perl script from within a perl script and return info
Message-Id: <1042511554.625941@a217-118-32-43.bluecom.no>
This is the situation:
I have two scripts a.cgi and b.cgi residing the following places on the
server:
/home/www/myserver/a.cgi
/home/www/myserver/mydir/b.cgi
Both scripts are executable (755).
This is the simplified code of a.cgi:
------------
#!/usr/bin/perl
$content = `/home/www/myserver/mydir/b.cgi`;
print "Content-type:text/html\n\n";
print $content;
exit;
------------
This is the simplified code of b.cgi:
------------
#!/usr/bin/perl
print "Content-type:text/html\n\n";
print "This is the output from b";
exit;
------------
When running a.cgi, it should produce the output from b.cgi, but a.cgi
outputs nothing.
Changing line 2 in a.cgi to:
$content = ` perl /home/www/myserver/mydir/b.cgi`;
does not seem to change anything.
Why doesn't this work, and how can I get it to work?
Sincerely,
Anders T. B.
------------------------------
Date: Mon, 13 Jan 2003 23:18:36 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: My, our, etc.
Message-Id: <3E238F9C.D7EEDF6B@earthlink.net>
Richard S Beckett wrote:
[snip]
> my $entry = $frame -> Entry (
> -validatecommand => \&valid_routine,
> -invalidcommand => sub {
> print "invalid entry, try again\n";
> $entry -> focus;}
> ) -> pack ();
Change to either:
my $entry = $frame -> Entry(
-validatecommand => \&valid_routine,
-invalidcommand => [ sub {
print "invalid entry, try again\n";
shift() -> focus;}, Ev('W') ]
) -> pack ();
Or:
my $entry; $entry = $frame -> Entry(
-validatecommand => \&valid_routine,
-invalidcommand => sub {
print "invalid entry, try again\n";
$entry -> focus;},
) -> pack ();
(The first form is prefferred, since it avoids a circular reference
loop, which could hinder later garbage collection).
[both code pieces are untested]
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: 13 Jan 2003 18:38:50 -0800
From: speedo@shenglong.com.cn (speedo goo)
Subject: NEW TO mod_perl: how to configure a perl filter to work
Message-Id: <3b2475d9.0301131838.e4f8fcc@posting.google.com>
hi, everyone
i'm new to mod_perl although i have some experiences on both Perl and
Windows ISAPI filter programming. i have a lot of small data files
stored as less-so-many zip files in a directory, i try to write a Perl
class so that when i browse to one zip file i can view the file list
inside. i did write the pl file ok, but only works for zip files in
/var/www/perl. not for other places, even a subdir.
i know there are a lot of IfModule/File/Alias lines to config. i tried
but failed. can anyone tell me all the lines i need to write in that
.conf file?
thanks in advance
speedo goo
------------------------------
Date: 13 Jan 2003 15:18:33 -0800
From: april@syclo.com (David S April)
Subject: overriding subroutines
Message-Id: <5ebde59.0301131518.7833e194@posting.google.com>
Hi all -
I'm confused over how and when subroutines are parsed.
If I have 3 files, test1.pl, test2.pl, test3.pl:
#--------------------------
#!/usr/bin/perl
#
# test1.pl
sub test() {
print "in test1.pl\n";
}
sub test() {
print "in test1.pl v2\n";
}
test();
1;
#--------------------------
#!/usr/bin/perl
#
# test2.pl
sub test() {
print "in test2.pl\n";
}
1;
#--------------------------
#!/usr/bin/perl
#
# test3.pl
require "test2.pl";
sub test() {
print "in test3.pl\n";
}
test();
1;
#--------------------------
and I run test1.pl and test3.pl, the output will be
test1.pl - "in test1.pl v2" <-- as expected.
test3.pl - "in test2.pl" <-- not expected.
why doesn't the subroutine in test3.pl override the earlier
declaration from the "require" statement?
Thanks in advance.
Dave
------------------------------
Date: Mon, 13 Jan 2003 23:40:40 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: overriding subroutines
Message-Id: <avvipo$591$1@wisteria.csv.warwick.ac.uk>
april@syclo.com (David S April) wrote:
>Hi all -
>
>I'm confused over how and when subroutines are parsed.
<snip test1.pl>
>#--------------------------
>#!/usr/bin/perl
>#
># test2.pl
use warnings;
use strict;
>
>sub test() {
^^
Do not put these on unless you know what they do.
It probably isn't what you expect.
perldoc perlsub (section "Prototypes").
> print "in test2.pl\n";
>}
>
>1;
>#--------------------------
>#!/usr/bin/perl
>#
># test3.pl
use warnings;
use strict;
>
>require "test2.pl";
>
>sub test() {
> print "in test3.pl\n";
>}
>
>
>test();
>
>1;
>#--------------------------
>and I run test1.pl and test3.pl, the output will be
>test1.pl - "in test1.pl v2" <-- as expected.
>test3.pl -
Subroutine test redefined at test2.pl line
in test2.pl
> <-- not expected.
>
>why doesn't the subroutine in test3.pl override the earlier
>declaration from the "require" statement?
Because it's not earlier.
1. Perl reads test3.pl, and compiles it. It defines a sub called 'test' and
compiles code for it to print "in test3\n".
2. Perl starts running this compiled code. It hits 'require "test2.pl"'.
3. Perl goes back into compile mode, reads test2.pl and compiles it. It
attempts to define a sub called 'test', finds there's already one there,
issues a warning (because _of_course_ you _always_ run with use warnings; and
use strict;, _don't_ _you_?), and replaces it with a new one which prints
"in test2\n";
4. Perl carrys on running where it left off, and hits 'test();', which makes
it print "in test2\n";
Moral of the story: always use warnings; and strict;. Either that or read the
Posting Guidelines, which say the same thing. :)
What are you actually trying to do, that you need to redefine subs? Or are you
just trying to learn how Perl does things?
Ben
------------------------------
Date: Mon, 13 Jan 2003 23:20:57 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: Perl command line processing, Windows/dos style ?
Message-Id: <avvhkp$4rg$1@wisteria.csv.warwick.ac.uk>
bugs.bunny@carrot.inc (Bugs Bunny) wrote:
>Hi,
>
>I'm trying to get a perl script to behave more like other windows
>command line tools, and it is driving me NUTS that I cannot get perl
>to simply give me the command line as-is.
>
>As is normal under unix, perl expands the command line automatically.
>For instance, when invoking 'scipt.pl' with as option '*', you'll
>get a list of all files in the current directory as arguments.
>
>So I already got used to enclose the arguments with double quotes to
>prevent expansion. Not too bad, because if you want to pass paths with
>embedded spaces, you have to enclose these with double quotes anyway
>to keep the parts together.
>But you forget you're dealing with a perl script, and forget the
>double quotes, well, anything can happen, as your script gets
>arguments that he does not expect.
>
>So you try to be carefull, and use double quotes. But then you try to
>pass the argument C:\ as an argument enclosed by double quotes, so as
>"C:\". Doesn't work. The sequence \" is replaced by single quote, and
>the argument is concatenated with the next argument: the \" is a way
>to include a double quote in a double quoted String. AAARRRGGGGHHHH
>
>I JUST WANT THE COMMANDLINE THE WAY THE USER ENTERS IT!!!!
Might I ask why? :)
I believe that the expansion of *->filenames (etc.) is not done by perl per se
but by the startup code in the CRT it uses. This means there's not much you
can do about it, unless a batch file of the form
@echo off
perl.exe script.pl "%*"
will work. Your perl script should then get one argument only, with the entire
command line on; which you can then deal with any way you please.
Ben
------------------------------
Date: Tue, 14 Jan 2003 03:20:03 GMT
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: Perl command line processing, Windows/dos style ?
Message-Id: <pkent77tea-86D536.02482514012003@[10.1.1.10]>
In article <3e2341c1.13839359@news.hccnet.nl>,
bugs.bunny@carrot.inc (Bugs Bunny) wrote:
> I'm trying to get a perl script to behave more like other windows
> command line tools, and it is driving me NUTS that I cannot get perl
> to simply give me the command line as-is.
When you says 'foo.pl *' to a shell on Unix the shell will expand the
'*' because it's a shell metacharacter [note: there are many shells, and
they all potentially glob things differently and have different
metacharacters. you could write a shell that did no globbing, if you
wanted.] So, _before_ the perl binary is exec()'d the '*' has been
changed to, most likely, all things in the current directory. That's the
shell doing it. Perl doesn't even _get_ the '*'. It has no idea that's
what the user typed. I don't _know_ what happens in the windows shell
but it appears to be the same sort of deal.
It sounds like you want the "non interpolating" quotes in your shell, so
that whatever is quoted will not be expanded by the shell... which
you'll need to check the docs about, and also you want to know how to
escape such quotes - that'll also be in the docs.
> I JUST WANT THE COMMANDLINE THE WAY THE USER ENTERS IT!!!!
It is possible to alter the action associated with your .pl files,
although whether that affects shell metacharacters or not I couldn't say.
So if a user types in:
foo.pl wibble\ bar * " go on< foo.txt
what should the perl script get as its args? One long string containing
the entire command line verbatim? Split on spaces into a number of small
strings? Should the '\ ' be interpreted as a space to split options on,
or not? Should the 'foo.pl ' be removed from the start?
I think the best thing is to see a n example. Have you an example
command line that you want to experiment with? I've got Win2k at work
with activeperl so I can try stuff there, if that's any use.
P
--
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply
------------------------------
Date: Tue, 14 Jan 2003 04:58:55 +0100
From: "Harald H.-J. Bongartz" <bongie@gmx.net>
Subject: Re: Perl command line processing, Windows/dos style ?
Message-Id: <1257689.LlUsk5FnHt@nyoga.dubu.de>
pkent wrote:
> When you says 'foo.pl *' to a shell on Unix the shell will expand the
> '*' because it's a shell metacharacter [note: there are many shells,
> and they all potentially glob things differently and have different
> metacharacters. you could write a shell that did no globbing, if you
> wanted.]
I want to add that common shells (here under Linux) can do different
things if a match fails, and this may even depend on configuration.
[using bash in an empty dir]
$ perl -e 'print shift' *
*
$ shopt -s nullglob
$ perl -e 'print shift' *
$
[using tcsh in an empty dir]
> perl -e 'print shift' *
perl: No match.
> set nonomatch=1
> perl -e 'print shift' *
*
(Some newlines inserted for readability.)
So, bash will (per default) happily hand over a non-matching asterisk to
the called program, while the tcsh (per default) issues an error.
Well, I prefer the second behaviour in interactive context, but YMMV.
Ciao,
Harald
--
Harald H.-J. Bongartz <bongie@gmx.net>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Interesting Error Messages #6:
USER ERROR: replace user and press any key to continue.
------------------------------
Date: Tue, 14 Jan 2003 04:26:56 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: Perl command line processing, Windows/dos style ?
Message-Id: <kkMU9.126894$FT6.25127237@news4.srv.hcvlny.cv.net>
"pkent" <pkent77tea@yahoo.com.tea> wrote in message
news:pkent77tea-86D536.02482514012003@[10.1.1.10]...
> In article <3e2341c1.13839359@news.hccnet.nl>,
> bugs.bunny@carrot.inc (Bugs Bunny) wrote:
>
> > I'm trying to get a perl script to behave more like other windows
> > command line tools, and it is driving me NUTS that I cannot get perl
> > to simply give me the command line as-is.
>
> When you says 'foo.pl *' to a shell on Unix the shell will expand the
> '*' because it's a shell metacharacter [note: there are many shells,
and
> they all potentially glob things differently and have different
> metacharacters. you could write a shell that did no globbing, if you
> wanted.] So, _before_ the perl binary is exec()'d the '*' has been
> changed to, most likely, all things in the current directory. That's
the
> shell doing it. Perl doesn't even _get_ the '*'. It has no idea that's
> what the user typed. I don't _know_ what happens in the windows shell
> but it appears to be the same sort of deal.
>
I believe that you have to do the globbing yourself in windows.
perl -e"print @ARGV" *
prints the '*' when run in a dos window of ME.
Bill
------------------------------
Date: 13 Jan 2003 17:16:40 -0800
From: kaif@uga.edu (Boris Alexeev)
Subject: Perl Golf on my Mind
Message-Id: <c200470a.0301131716.4a2b95f7@posting.google.com>
Here's a Perl golf challenge:
Design a non-empty (so to speak) Perl script that prints itself out,
i.e. a literal ASCII representation of itself. It should be executable
on the command line, and hence it shouldn't read/write from any files.
If there's a trivial way of doing this (e.g. some global Perl
variable), then scratch the idea. Otherwise, I was wondering what
could be done.
- Boris.
------------------------------
Date: Tue, 14 Jan 2003 01:22:31 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Perl Golf on my Mind
Message-Id: <x74r8c7cfg.fsf@mail.sysarch.com>
>>>>> "BA" == Boris Alexeev <kaif@uga.edu> writes:
BA> Design a non-empty (so to speak) Perl script that prints itself out,
BA> i.e. a literal ASCII representation of itself. It should be executable
BA> on the command line, and hence it shouldn't read/write from any files.
that is known as a quine and you can search google for perl and quine
and find a bunch of hits on this.
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class
------------------------------
Date: Tue, 14 Jan 2003 00:12:28 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Perl Golf on my Mind
Message-Id: <3E239C3C.7B3A72C1@earthlink.net>
Boris Alexeev wrote:
>
> Here's a Perl golf challenge:
>
> Design a non-empty (so to speak) Perl script that prints itself out,
> i.e. a literal ASCII representation of itself. It should be executable
> on the command line, and hence it shouldn't read/write from any files.
What about file(handle)s which perl itself already opened for reading?
Eg:
seek DATA, 0, 0; print <DATA>;
(Most definitions of quine consider this illegal, but yours doesn't
*quite* say so.)
> If there's a trivial way of doing this (e.g. some global Perl
> variable), then scratch the idea. Otherwise, I was wondering what
> could be done.
Of course it can be done, in any sufficiently complex programming
language.
It's called a quine.
The shortest perl quine is an empty file.
For more interesting quines...
printf($x,39,$x='printf($x,39,$x=%c%s%c,39);',39);
$_=q{$_=q{Q};s/Q/$_/;print};s/Q/$_/;print
$_=q(print"\$_=q($_);eval;");eval;
Or, *really* clever, put the following in a file named '/tmp/p' :
Illegal division by zero at /tmp/p line 1.
And then run 'perl /tmp/p'.
Hmm... I wonder if I could make a quine using the structure that my
mail/news signature uses. Naah.
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: Mon, 13 Jan 2003 23:52:50 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: search and replace problem
Message-Id: <3E2397A2.2506D693@earthlink.net>
Urs Klingsporn wrote:
[snip]
Try this:
my @lc_keys = map lc, keys %entry;
my %lc_entry;
@lc_entry{@lc_keys} = values %entry;
my $mask = '§(' .
join('|', sort { length($b) <=> length($a) } @lc_keys)
. ')§';
$output =~ s/$mask/$entry{lc $1}/gim;
[untested]
Note that with this code, there should be no need for a foreach() loop.
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: Tue, 14 Jan 2003 00:05:16 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: sleep aborts script
Message-Id: <Pine.LNX.4.40.0301132359290.10976-100000@lxplus071.cern.ch>
On Jan 13, Marshall Dudley tries to lecture one of our local experts:
> > "Browser"? Is this a stealth-CGI question? If so you presumably mean
> > "HTTP server" not "browser".
>
> There is a connection from the browser to the http server then from the http
> server to perl.
It's not as simple as that. The relationship between the two
connections is not as direct as you seem to think.
> They both get broken, like hanging up a phone. I normally
> say I hung up on the party that called,
Hmmm. If the phone suddenly stops responding because the
company disconnected, it'll take a few moments for you to realise
what's gone wrong, then you'll maybe curse, then you'll hang up the
phone.
Will you then report that what happened was that you "hung up" on the
other party? I think not.
> not the phone company, since the
> phone company is the means by which the connection is made.
And this is where you stand to learn something, since when the
script goes to sleep, it's the "phone company" (in this case, the
web server) that does the hanging-up on you.
> > I suggest you fork your task completely into the background (see FAQ).
>
> That worked.
That's what FAQs are for ;-}
--
"DO NOT READ WHILST THE BOX IS OPEN!" - warning
printed on the underside of a product package. (honestly!)
------------------------------
Date: 13 Jan 2003 20:44:56 -0800
From: mckenzie@bigmultimedia.com (Bruce McKenzie)
Subject: The "default thing"
Message-Id: <bd848f76.0301132044.ecc11cb@posting.google.com>
In the Chapter 14.1 of Programming Perl, there is an example of how to
create a package for tying a scalar:
#!/usr/bin/perl
package Centsible;
sub TIESCALAR { bless \my $self, shift }
sub STORE { ${ $_[0] } = $_[1] } # do the default thing
sub FETCH { sprintf "%.02f", ${ my $self = shift } } # round value
This package is "used" as follows:
package main;
tie $bucks, "Centsible";
$bucks = 45.00;
$bucks *= 1.0715; # tax
$bucks *= 1.0715; # and double tax!
print "That will be $bucks, please.\n";
I don't understand the shorthand in "the default thing." I guess it
means that the value referenced by the tied object is now the new
value. But I don't see where the $_[1] comes from. It's second element
of an array ?? I couldn't find examples like it elsewhere in the book
or the manpages. Could someone point me to where this is explained for
slower individuals like me.
Thanks
------------------------------
Date: 13 Jan 2003 18:14:51 -0500
From: Jay Rogers <jay@rgrs.com>
Subject: Re: Using Expect to telnet to port 80 (not Expect::Simple)
Message-Id: <kwp8yxoiqvo.fsf@panix5.panix.com>
Martien Verbruggen <mgjv@tradingpost.com.au> writes:
> On 30 Dec 2002 11:12:46 -0800,
> ATB <funky_breaks_2000@msn.com> wrote:
> > Apologies for those who have read my Expect::Simple query, but after
> > slogging through the documentation for both, I think Expect will be a
> > better fit than Expect::Simple.
>
> I think that the LWP modules would be an even better fit. Failing that,
> IO::Socket would be my next choice. Net::Telnet I find a little hard to
> get to work correctly.
Obviously LWP is the right choice, but it's very easy to use
Net::Telnet to grab all or just a portion of a http doc that
you're interested in.
With Net::Telnet you can set the time-out to be some wall time in
the future - meaning you can restrict the maximum running time of
your program to say 10 seconds.
The waitfor() method makes it easy to look for data of interest
in a document without having to read the entire document.
Here's how to get the header and body (failing if longer than 10
secs):
use Net::Telnet;
$http = new Net::Telnet (Timeout => time + 10);
$http->open(Host => "www.perl.org", Port => 80);
$http->print("GET / HTTP/1.0\n\n");
$http->input_record_separator("\n\n");
$header = $http->getline;
$http->input_record_separator("\n");
@body = $http->getlines;
print $header, @body;
Here's how to pick out a stock quote without having to read the
entire document (failing if quote doesn't show up within 10
secs):
use Net::Telnet;
$http = new Net::Telnet (Timeout => time + 10);
$http->open(Host => "finance.yahoo.com", Port => 80);
$http->print("GET /q?s=^DJI&d=t HTTP/1.0\n\n");
$http->waitfor('/Last Trade.+?<b>/');
($amount) = $http->waitfor('/<\/b>/');
print "DJIA = $amount\n";
--
Jay Rogers
jay@rgrs.com
------------------------------
Date: 13 Jan 2003 17:07:42 -0800
From: Andrew.Allaire@na.teleatlas.com (Andrew Allaire)
Subject: Re: Why does this NOT work??
Message-Id: <6bdb91de.0301131707.21f690c7@posting.google.com>
ashokc@qualcomm.com (ashok) wrote in message news:<c13619fd.0301131138.604c62a2@posting.google.com>...
> Hi,
>
> I have the following 'test' code that works fine as follows.
>
> #!/usr2/bin/perl -w
> #
>
> use strict qw(subs refs) ;
>
> %hash = () ;
> $number = 0 ;
> while ($number < 5) {
> $number++ ;
> @list = ('a' . $number ,'b' . $number,'c' . $number) ;
> $hash{$number} = \@list ;
> print "\t\t$number : @{$hash{$number}}\n" ;
> }
>
> Prints:
>
> 1 : a1 b1 c1
> 2 : a2 b2 c2
> 3 : a3 b3 c3
> 4 : a4 b4 c4
> 5 : a5 b5 c5
>
> But the same idea split into a main code & a module does not!
>
> The Module:
>
> package test;
>
> use Exporter;
> @ISA = qw(Exporter) ;
> @EXPORT_OK = qw() ;
>
> use 5.004;
> use strict qw(subs refs) ;
>
> sub new {
> my $proto = shift ;
> $class = ref($proto) || $proto ;
> my $self = {} ;
> bless ($self, $class) ;
> return $self ;
> }
>
> sub getHashRef() {
> my $self = shift ;
>
> %hash = () ;
> $number = 0 ;
> while ($number < 5) {
> $number++ ;
> @list = ('a' . $number ,'b' . $number,'c' . $number) ;
> $hash{$number} = \@list ;
> }
> return \%hash ;
> }
>
> 1 ;
>
> The code:
>
> #!/usr/bin/perl -w
> #
>
> use Carp ;
> use lib qw(/usr2/ashokc/myperl/lib/dev) ;
> use test ;
>
> use strict qw(subs refs) ;
>
> $Test = new test() ;
>
> $hashref = $Test->getHashRef() ;
>
> foreach $key (sort keys %{$hashref}) {
> print "$key\n" ;
> foreach $item ( @{$hashref{$key}} ) {
> print "$item\n" ;
> }
> }
>
> I get:
>
> 1
> 2
> 3
> 4
> 5
>
> It seems that the array reference "$hashref{$number}" is undefined. Why is that?
> Thanks
>
> - ashok
You are refering to @list by reference. In the first example you are
printing the current contents of @list, but in the packaged edition of
the code you are storing the reference and returning it when it is
empty. One solution would be to use an anonymous array constructor to
construct distinct array references. While doing so use "my" to limit
the scope.
my $list = [ 'a' . $number ,'b' . $number,'c' . $number ] ;
$hash{$number} = $list ;
or simply:
$hash{$number} = [ 'a' . $number ,'b' . $number,'c' . $number ] ;
Note that the brackets return a distinct array refernce each time, by
contrast \@list returns the same array refernce each time.
------------------------------
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 4398
***************************************