[19618] in Perl-Users-Digest
Perl-Users Digest, Issue: 1813 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 25 14:06:02 2001
Date: Tue, 25 Sep 2001 11:05:11 -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: <1001441111-v10-i1813@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 25 Sep 2001 Volume: 10 Number: 1813
Today's topics:
Re: $0 and Win NT <ron@indra.com>
Re: $0 and Win NT <bart.lateur@skynet.be>
Re: Creating modules (Anno Siegel)
Re: Creating modules <ilya@martynov.org>
Re: Creating modules (Anno Siegel)
Re: Creating modules <bart.lateur@skynet.be>
Re: Creating modules nobull@mail.com
Re: current dir. (David Wall)
Re: current dir. (Mark Jason Dominus)
Re: current dir. <simon.oliver@umist.ac.uk>
Re: current dir. <simon.oliver@umist.ac.uk>
Re: current dir. nobull@mail.com
Re: current dir. <bart.lateur@skynet.be>
Re: Dump raw data <bart.lateur@skynet.be>
Re: Dump raw data (Mark Jason Dominus)
Re: Dump raw data (Anno Siegel)
Re: Getting NULLS after a lockup from using up memory (Xeno Campanoli)
Re: Goto and global variables (Mark Jason Dominus)
Re: Goto and global variables (Tramm Hudson)
Re: Handling two lines (Mark Jason Dominus)
Re: How do I compare strings? (Dimitri)
Re: How to send a cookie from perl to perl? <mdudley@execonn.com>
Re: multipul http connections <mbudash@sonic.net>
Re: non-persistent cookies management <ljb_fr@yahoo.fr>
Re: Please Help with Sockets! nobull@mail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 25 Sep 2001 09:14:25 -0600
From: Ron Reidy <ron@indra.com>
Subject: Re: $0 and Win NT
Message-Id: <3BB09F51.418B7F4D@indra.com>
Horst Fickenscher wrote:
>
> I'm using FindBin.pm to get the directory where
> a script was started. As far as I can see FindBin.pm
> uses $0.
>
> Say, we call the script findbin.pl from the
> directory e:\mastertools. Then:
>
> $0 is 'E:\MASTE~3W\findbin.pl'
>
> Actually E: is a Samba share and mastertools
> should be passed to a remote process on a linux
> box, so the 8.3 name is useless.
>
> This is perl, version 5.005_02 built for winnt4.
> I know how to get the long file name from the
> 8.3 name, but I'm just curious.
>
> I'm pretty sure that I got the long file name in
> $0 some weeks ago (yes, before my holidays).
>
> Yes, I know, that's not a perl question:
>
> Are there any settings (registry) or circumstances
> that could lead to this different behaviour?
>
> Any hints or suggestions welcome. Cheers
>
> --
> Horst
In Windoze...
use Win32;
$path = join("", Win32::GetFullPathName($0));
--
Ron Reidy
Oracle DBA
Reidy Consulting, L.L.C.
------------------------------
Date: Tue, 25 Sep 2001 16:36:24 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: $0 and Win NT
Message-Id: <9hc1rt8emqmqu8uvm1u32sska3ivim2rck@4ax.com>
Horst Fickenscher wrote:
>Say, we call the script findbin.pl from the
>directory e:\mastertools. Then:
>
>$0 is 'E:\MASTE~3W\findbin.pl'
>
>Actually E: is a Samba share and mastertools
>should be passed to a remote process on a linux
>box, so the 8.3 name is useless.
Check out the functions available under the Win32:: hierarchy. You want
Win32::GetLongPathName(PATHNAME).
--
Bart.
------------------------------
Date: 25 Sep 2001 15:24:35 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Creating modules
Message-Id: <9oq7jj$e3k$1@mamenchi.zrz.TU-Berlin.DE>
According to Bart Lateur <bart.lateur@skynet.be>:
> GunneR wrote:
>
> >Im having trouble creating a simple module (just to get started). I've
> >had a bit of trouble finding good documentation on creating modules.
> >Anyone know any informative sites?
>
> Start you module file with
>
> package Foo::Bar;
>
> if Foo::Bar is the name of the module you'd like to write, thus
> Foo/Bar.pm is the file name/path; and end it with
>
> 1;
>
> Save the file. You now have got an empty module that does nothing ,wbut
> which works.
>
> If you don't need import(), i.e. no exportable functions/variables, for
> example if it's a pure OO module, just leave it like this, just add you
> variable declarations and subs, and initialisation if that is needed. If
> you do, look at the docs for Exporter.
>
> It can be that simple.
Speaking of exportation, that has become a little simpler too.
For plain export of symbols it is no longer required to "use Exporter".
Just set @ISA = qw( Exporter) and define @EXPORT_OK appropriately.
Apparently you need the full Exporter module only if you want to use
%EXPORT_TAGS. I haven't seen documentation on this yet; in fact, "use
Exporter" is prescribed everywhere.
Does anyone know what is going on?
Another thought about exportation: It transplants symbols from one
stash to another anyway, why can't let it rename the symbol in the
process, so that the user can decide what name to import a function
under? This would mean that in a name clash it isn't necessarily
the user who's gotta give, the module can yield too. You may even
want to import a generically named function (extract_min from a heap
module, say) with a more specific name for a particular application
(dequeue, perhaps). Not that "dequeue" is a particularly attractive
name, it's a bitch to type :)
In fact, I was investigating Export.pm with this in mind when I
discovered that you can export without it.
Anno
------------------------------
Date: 25 Sep 2001 19:41:53 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Creating modules
Message-Id: <87bsjz6zwe.fsf@abra.ru>
>>>>> On 25 Sep 2001 15:24:35 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) said:
AS> Speaking of exportation, that has become a little simpler too.
AS> For plain export of symbols it is no longer required to "use Exporter".
AS> Just set @ISA = qw( Exporter) and define @EXPORT_OK appropriately.
AS> Apparently you need the full Exporter module only if you want to use
AS> %EXPORT_TAGS. I haven't seen documentation on this yet; in fact, "use
AS> Exporter" is prescribed everywhere.
AS> Does anyone know what is going on?
I think it is better to add 'use Exporter' always. What are you doing
is working by accident: Exporter module is loaded by Perl default
because it is used by some default modules. It is that it will be load
by default in future versions of Perl.
Nobody can promise you that it will work say in 5.8.1.
AS> [..skip..]
AS> In fact, I was investigating Export.pm with this in mind when I
AS> discovered that you can export without it.
You are still export *with* it.
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: 25 Sep 2001 16:17:15 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Creating modules
Message-Id: <9oqamb$ff9$2@mamenchi.zrz.TU-Berlin.DE>
According to Ilya Martynov <ilya@martynov.org>:
> >>>>> On 25 Sep 2001 15:24:35 GMT, anno4000@lublin.zrz.tu-berlin.de
> (Anno Siegel) said:
>
> AS> Speaking of exportation, that has become a little simpler too.
>
> AS> For plain export of symbols it is no longer required to "use Exporter".
> AS> Just set @ISA = qw( Exporter) and define @EXPORT_OK appropriately.
> AS> Apparently you need the full Exporter module only if you want to use
> AS> %EXPORT_TAGS. I haven't seen documentation on this yet; in fact, "use
> AS> Exporter" is prescribed everywhere.
>
> AS> Does anyone know what is going on?
>
> I think it is better to add 'use Exporter' always. What are you doing
> is working by accident: Exporter module is loaded by Perl default
> because it is used by some default modules. It is that it will be load
> by default in future versions of Perl.
>
> Nobody can promise you that it will work say in 5.8.1.
If that is how it gets loaded you are of course right. Though,
considering that UNIVERSAL.pm exports stuff, I don't think it's
going anywhere anytime soon :)
> AS> [..skip..]
>
> AS> In fact, I was investigating Export.pm with this in mind when I
> AS> discovered that you can export without it.
>
> You are still export *with* it.
When I was looking at it (some Version before 5.6.1), there was a second,
simplified Exporter.pm someplace that was loaded by default. That's how
I remember the situation. I see that now the standard Exporter is loaded.
Anno
------------------------------
Date: Tue, 25 Sep 2001 16:56:07 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Creating modules
Message-Id: <1kd1rtcgob504jhjgb6vpesbh20ar89e56@4ax.com>
Ilya Martynov wrote:
>>>>>> On 25 Sep 2001 15:24:35 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) said:
>
>AS> Speaking of exportation, that has become a little simpler too.
>
>AS> For plain export of symbols it is no longer required to "use Exporter".
>AS> Just set @ISA = qw( Exporter) and define @EXPORT_OK appropriately.
>AS> Apparently you need the full Exporter module only if you want to use
>AS> %EXPORT_TAGS. I haven't seen documentation on this yet; in fact, "use
>AS> Exporter" is prescribed everywhere.
>
>AS> Does anyone know what is going on?
>
>I think it is better to add 'use Exporter' always. What are you doing
>is working by accident: Exporter module is loaded by Perl default
>because it is used by some default modules. It is that it will be load
>by default in future versions of Perl.
>
>Nobody can promise you that it will work say in 5.8.1.
Aha.
It only works because you only need
require Exporter;
because this is an OO based module that doesn't export anything, or
anything useful, by itself. Once it's loaded, it's loaded. And that's
good enough for any practical use.
>AS> [..skip..]
>
>AS> In fact, I was investigating Export.pm with this in mind when I
>AS> discovered that you can export without it.
>
>You are still export *with* it.
It's "Exporter.pm".
--
Bart.
------------------------------
Date: 25 Sep 2001 18:26:36 +0100
From: nobull@mail.com
Subject: Re: Creating modules
Message-Id: <u9elovw59v.fsf@wcl-l.bham.ac.uk>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> ... "use Exporter" is prescribed everywhere.
Really? Are you sure? Everywhere I've looked talks about "require
Exporter". I have created a modified version of Exporter where "use
Exporter" actually does something ( namely lets you set the @EXPORT
and @EXPORT_OK and %EXPORT_TAGS at compile time without all the ugly
BEGIN{} stuff). It also pushes Exporter into the caller's @ISA.
--- /usr/lib/perl5/5.00503/Exporter.pm Sat Aug 5 22:56:06 2000
+++ /home/bam/perl/Exporter.pm Tue Mar 20 13:27:22 2001
@@ -179,7 +179,16 @@
sub import {
my $pkg = shift;
my $callpkg = caller($ExportLevel);
- export $pkg, $callpkg, @_;
+ if ($pkg eq __PACKAGE__) {
+ push @{"${callpkg}::ISA"}, $pkg;
+ my %arg = @_;
+ *{"${callpkg}::EXPORT"} = \@{$arg{EXPORT} || []} ;
+ *{"${callpkg}::EXPORT_OK"} = \@{$arg{EXPORT_OK} || []};
+ my $tags = $arg{EXPORT_TAGS} || {};
+ *{"${callpkg}::EXPORT_TAGS"} = ref($tags) eq 'ARRAY' ? { @$tags} : \%$tags;
+ } else {
+ export $pkg, $callpkg, @_;
+ }
}
@@ -266,6 +275,14 @@
@EXPORT = qw(...); # symbols to export by default
@EXPORT_OK = qw(...); # symbols to export on request
%EXPORT_TAGS = tag => [...]; # define names for sets of symbols
+
+Or
+
+ package ModuleName;
+ use Exporter
+ EXPORT => [ qw(...) ],
+ EXPORT_OK => [ qw(...)],
+ EXPORT_TAGS => [ tag => [...] ];
In other files which wish to use ModuleName:
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 25 Sep 2001 15:05:52 -0000
From: darkon@one.net (David Wall)
Subject: Re: current dir.
Message-Id: <Xns912770C609902darkononenet@207.126.101.97>
Jeffrey Porter <jeff@metadyne.uk.com> wrote on 25 Sep 2001:
> I'm trying to write a perl program to go through each directory and list
> the files in it & the path to that file.
>
> I've managed to write the code to list/change directories & list the
> files in them.
>
> What I can't work out is how to get the full path of the current
> directory I am in.
Take a look at the File::Find module -- it will make this MUCH easier, as
it's designed for just the sort of thing you describe. (plus much more)
It's a standard module, included with Perl; no need to visit CPAN.
If all you want is the path/filename, this will do it:
use File::Find;
find( sub {
print "$File::Find::name\n";
},
'/directory/goes/here'
);
See the docs for more info.
--
David Wall
darkon@one.net
------------------------------
Date: Tue, 25 Sep 2001 15:23:10 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: current dir.
Message-Id: <3bb0a15e.71f2$1f4@news.op.net>
In article <3BB08955.81D08C63@metadyne.uk.com>,
Jeffrey Porter <jeff@metadyne.uk.com> wrote:
>I've managed to write the code to list/change directories & list the
>files in them.
>
>What I can't work out is how to get the full path of the current
>directory I am in.
Keep track of it yourself as you go down the directory structure.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Tue, 25 Sep 2001 15:16:42 +0100
From: "Simon Oliver" <simon.oliver@umist.ac.uk>
Subject: Re: current dir.
Message-Id: <3bb0956f$1@news.umist.ac.uk>
use Cwd;
$dir = cwd;
--
Simon
------------------------------
Date: Tue, 25 Sep 2001 16:48:42 +0100
From: "Simon Oliver" <simon.oliver@umist.ac.uk>
Subject: Re: current dir.
Message-Id: <3bb0aac9$1@news.umist.ac.uk>
You should really update your version of Perl - it's way out of date. Get
5.6.1 from cpan - it included the Cwd module.
But here's a sub that might solve your problem:
sub do_dir {
my $dir= shift or return;
$dir .= '/' unless $dir =~ m{/$};
return unless (opendir DH, $dir);
my @subs;
while (my $item = readdir DH) {
next if $item =~ /^.{1,2}$/;
my $path = $dir . $item;
push @subs if (-d $path);
# do something with the file
}
}
do_dir($_) for @subs;
}
--
Simon Oliver
----- Original Message -----
From: "Jeffrey Porter" <jeff@metadyne.uk.com>
To: "Simon Oliver" <simon.oliver@umist.ac.uk>
Sent: Tuesday, September 25, 2001 3:47 PM
Subject: Re: current dir.
>
>
> That command seems to be unknown.
>
> I'm running Solaris 2.8. Perl 5.0.4.2
>
> The commands....
>
>
> pwd;
> pwd();
> getCwd();
> getcwd;
> getcwd();
>
> no not seems to exist either.
>
>
> Can you suggest anything?
>
>
> JP.
>
>
>
> Simon Oliver wrote:
>
> > use Cwd;
> >
> > $dir = cwd;
> >
> > --
> > Simon
>
> -- it builds, quick ship it!
>
>
>
------------------------------
Date: 25 Sep 2001 17:38:16 +0100
From: nobull@mail.com
Subject: Re: current dir.
Message-Id: <u9r8svw7if.fsf@wcl-l.bham.ac.uk>
Jeffrey Porter <jeff@metadyne.uk.com> writes:
> What I can't work out is how to get the full path of the current
> directory I am in.
Others have addressed your _immediate_ problem (how to get the full
path of the current directory) it would be more helpful to you in the
long run to address your underlying problem (the fact that you
couldn't work out how to do this).
Can you please explain how it was that your Usenet search failed to
find the thread "How to get the path of current directory in perl"
from 4 days ago or "finding out working directory" from 8 days ago?
Perhaps, then, we can advise you on a better approach to using Usenet.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 25 Sep 2001 16:59:02 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: current dir.
Message-Id: <ord1rtcrto80ns9qdi22vphdu31d3erutj@4ax.com>
Jeffrey Porter wrote:
>I'm trying to write a perl program to go through each directory and list
>the files in it & the path to that file.
Don't. Use File::Find.
use File::Find;
use Cwd;
find sub {
-f and print "$File::Find::name\n";
}, cwd;
--
Bart.
------------------------------
Date: Tue, 25 Sep 2001 15:05:27 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Dump raw data
Message-Id: <p471rt897m9matat8u8i5brrn03pmlti6u@4ax.com>
Philippe PERRIN wrote:
>I need to regularly dump a whole hash on disk, and reload it later. Is
>there a way to write its "raw data" on a file descriptor (I mean the way
>Perl stores it in memory) ?
Check out the module Storable. It's as close as it gets.
--
Bart.
------------------------------
Date: Tue, 25 Sep 2001 15:21:46 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Dump raw data
Message-Id: <3bb0a109.71eb$2a9@news.op.net>
In article <3BB032C7.D149A04C@sxb.bsf.alcatel.fr>,
Philippe PERRIN <philippe.perrin@sxb.bsf.alcatel.fr> wrote:
>I need to regularly dump a whole hash on disk, and reload it later. Is
>there a way to write its "raw data" on a file descriptor (I mean the way
>Perl stores it in memory) ?
That is impossible, because the hash and its contents are not stored
in a contiguous segment of memory.
You should probably look into usnig the 'Storable' module,
which isusually very fast.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: 25 Sep 2001 16:02:17 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Dump raw data
Message-Id: <9oq9q9$ff9$1@mamenchi.zrz.TU-Berlin.DE>
According to Mark Jason Dominus <mjd@plover.com>:
> In article <3BB032C7.D149A04C@sxb.bsf.alcatel.fr>,
> Philippe PERRIN <philippe.perrin@sxb.bsf.alcatel.fr> wrote:
> >I need to regularly dump a whole hash on disk, and reload it later. Is
> >there a way to write its "raw data" on a file descriptor (I mean the way
> >Perl stores it in memory) ?
>
> That is impossible, because the hash and its contents are not stored
> in a contiguous segment of memory.
>
> You should probably look into usnig the 'Storable' module,
> which isusually very fast.
An alternative would be to use a tied hash, either as a vehicle to
and from disk, but once in place I'd try to use the tied hash directly.
If that is still fast enough, it has the advantage of keeping the
disk image up to date all the time.
Anno
------------------------------
Date: 25 Sep 2001 16:56:37 GMT
From: xeno@eskimo.com (Xeno Campanoli)
Subject: Re: Getting NULLS after a lockup from using up memory
Message-Id: <9oqd05$frq$1@eskinews.eskimo.com>
Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote:
: According to Xeno Campanoli <xeno@eskimo.com>:
: >
: > I'm finding that frequently, in my Perl program that I mentioned here
: > before, I get a catestrophic failure at the call to waitpid (this is
: > with either the zero, or the WNOHANG parameter in use) such that I
: > literally get a stream of nulls of varying length output to STDERR at
: > that point, at least when I'm using STDERR print statements to trace my
: > progress.
: Well, *what* are you printing to STDERR? Also, what are "nulls"?
: > There seems to be no other reason for this than just running
: > out of resources, and it makes sense that I fail at waitpid since I
: > spend more time there when memory is getting used up (once in a while it
: > fails elsewhere, but usually there at the waitpid) but it is curious
: > that I get this stream of nulls. I was wondering if you had any idea
: > why this is? Have you ever seen that?
: There is no chance of answering that unless you say what data becomes
: "nulls" in this situation. However, after a memory shortage, virtually
: everything can happen. I don't think there's much use in worrying why
: a program shows this or that behavior.
That's unfortunate. Certainly a reasonable goal would be to have such catestrophic
failure be mitigated by regular behavior when possible, and given such, it seems
you'd want to be able to know about the behavior. You seem to be implying that
the operating system doesn't help you and the Perl suite has no anticipatory ability
to let you know anything when running out of memory. I wish there was more information
about this. Perhaps I need to read something on Linux. Is there any README out there on
this kind of failure for Linux or Unices in general?
: Anno
------------------------------
Date: Tue, 25 Sep 2001 15:56:59 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Goto and global variables
Message-Id: <3bb0a94a.72be$8@news.op.net>
In article <ower7.12876$Tv6.66631@news1.rdc1.nsw.optushome.com.au>,
David Scarlett <dscarlett@REMOVETHIS.optushome.com.au> wrote:
>Firstly, just what does the "goto &NAME" call do? The description wasn't
>very good, but from what I can tell, it calls a subroutine from within the
>current subroutine, but when this sub finishes, instead of returning to the
>sub it was called from, it returns to wherever that sub was called from. Is
>this correct?
Yes. The most common use is in conjunction with another feature
called an 'autoloader'. If your program tries to call a fnuction that
doesn't exist, Perl normally dies. But if there is a function named
AUTOLOAD, it is called instead as a last resort.
One thing an AUTOLOAD fnuction can do is figure out the name of the
function you were *trying* to call, define it, and then transfer
control there as if it had been there all along.
'goto &function' performs the 'transfer of control' part.
The AUTOLOAD fnuction can use it to transfer control to the new
function, and from the new function's ponit of view everything looks
perfectly normal; when the new function returns, it returns not to
AUTOLOAD but to the part of the orignial program code that was trying
to call this function in the first place.
>"If you have a thing for parentheses, then LISP is the programming language
>for you!"
> -My Computing Fundamentals lecturer
That's silly. Perl probably uses almost as many parentheses as Lisp.
Perl uses a complicated operator precedence system to resolve the
meaning of ambiguous expressions, so fewer parentheses are required in
expressions. And you don't notice the remaninig parentheses as much
because Perl uses eight different kinds of parentheses ([<{}>])
instead of only ().
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: 25 Sep 2001 16:50:57 GMT
From: hudson@swcp.com (Tramm Hudson)
Subject: Re: Goto and global variables
Message-Id: <9oqclh$cbd$1@sloth.swcp.com>
[ Posted and cc'd to cited authors ]
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>According to Philip Newton <nospam.newton@gmx.li>:
>
>[...]
>
> > But you probably don't have to worry about goto &NAME, since its primary
> > use AIUI is inside AUTOLOAD subroutines -- it's not something (sane)
> > people use in everyday programming.
>
> "goto &sub" is also useful in handler chaining. [ .... ]
>
> No, this isn't exactly everyday programming either.
Nor is my favorite use of this construct -- tail recursion. I mostly
use it to demonstrate the similarities between Perl and LISP or Scheme.
Such as this contrived example:
sub my_map
{
my $user = shift;
my $func;
$func = sub {
return unless @_;
my $value = shift;
$user->( $value );
goto &$func;
};
goto &$func;
}
my_map( sub { print "@_\n" }, 10..20 );
Not everyday programming in C or Perl. Nor really in Scheme, since
the compiler automatically detects tail recursive function calls and
optimizes them. Without explict looping, programmers tend to pay more
attention to the tail recursion and write code to be cleanly tail
recursive. There are transformations that will make anything properly
tail recursive, but programmer time is so much cheaper than machine time.
Or something like that...
Older BASIC programmers probably wonder what we're going on about.
The GOTO and GOSUB keywords (in some variants) have the same sort of
semantics of bypassing or maintaining the call stack. It's a
flexibility that most modern languages don't provide other than
inside a single function. setjmp(3)/longjmp(3) don't really count.
Trammell
--
o hudson@swcp.com O___|
/|\ http://www.swcp.com/~hudson/ M 240.476.1373 /\ \_
<< KC5RNF H 505.315.5133 \ \/\_\
0 U \_ |
------------------------------
Date: Tue, 25 Sep 2001 15:40:37 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Handling two lines
Message-Id: <3bb0a573.7267$20b@news.op.net>
On 25 Sep 2001, whatafish@hotmail.com (David Djajaputra) wrote:
>I'm trying to write a perl script that can help me convert my
>Fortran77 programs into Fortran90. My question is about multiline
>statement.
In article <o5u0rt06hg56ohpg8rg0hlrgnn5b14bsof@4ax.com>,
=?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de> wrote:
>#!/usr/bin/perl -w
>
>[14 line program omitted]
I don't nuderstand why this requires so much code.
I don't know much about Fortran 90 syntax, so I can't vouch for the
correctness of this program:
#!/usr/bin/perl
$\ = "\n";
while (<>) {
chomp;
if (substr($_, 5, 1) !~ /\s/) { # continuation character
print $prev, " &" if defined $prev;
substr($_, 0, 6) = ''; # substr($_, 5, 1) = ' ' perhaps?
} else {
print $prev;
}
$prev = $_;
}
print $prev;
But for the test case you gave, the output is the same, except that
mine correctly terminates the final line and yours doesn't.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: 25 Sep 2001 08:06:54 -0700
From: mauroid@csi.forth.gr (Dimitri)
Subject: Re: How do I compare strings?
Message-Id: <a3ebf7b8.0109250706.d961ed6@posting.google.com>
Works perfect, and it's lightning fast! Thank you Bart.
-Dimitri
Bart Lateur <bart.lateur@skynet.be> wrote in message news:<ba4vqto422aj579pspgu8bg4imj51m0oii@4ax.com>...
> Dimitri wrote:
>
> >I have two very long strings, which I need to compare. I am looking for
> >the position of the first mismatching character :
> >
> >$str1: abcdefghijklmn....
> >$str2: abcdefghiXklmn..
> >$pos : 9
> >
> >How can I find this position, short of writing a for loop that will go
> >through each string and use substr to compare character by character?
>
> One name for this is "common prefix length". And the mechanism that
> seems best accepted by perl geeks, is doing bitwise xor (with ^ ) on the
> strings, and getting the length of the leading prefix of null bytes.
>
> ("$str1" ^ "$str2") =~ /^(\0*)/;
> $pos = length $1;
>
> Note: $str1 and $str2 MUST be strings. If there's any chance that one of
> them is a number, i.e. last used as a number, for example by using it in
> a mathematical expression, the bitwise xor will work on the numerical
> values, and not on the bytes that make up the strings. That is why I
> sstringify them here, just to make sure.
------------------------------
Date: Tue, 25 Sep 2001 13:01:08 -0400
From: Marshall Dudley <mdudley@execonn.com>
Subject: Re: How to send a cookie from perl to perl?
Message-Id: <3BB0B854.5D8CDB16@execonn.com>
Nope, that does not do it, already been down that road. But I DID finally figured
out how to do it. Since I found over a dozen newsgroup postings by others over the
years asking the same question, and no correct answers from anybody, I am posting
the code that works:
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$req = HTTP::Request->new(GET =>
"$URL_of_affiliate?total=$total&subtotal=$subtotal");
if ($id) {
$req->header('Cookie' => "AFFILIATE=$id"); #put the cookie in the header
if $id exists
}
$res = $ua->request($req);
Strange that no one else has ever been able to figure that out.
Marshall
Chris Fedde wrote:
> In article <3BAF6453.8647CE12@execonn.com>, Marshall Dudley
> <mdudley@execonn.com> wrote:
> >How do you send a cookie from one perl script to another.
> >
> >http://www.cis.ohio-state.edu/cgi-bin/rfc/rfc2109.html indicates that
> >you put the following syntax in the header:
> >
> >Cookie: $Version="1"; name="value";
> >
> >But that does not seem to work at all. I am unable to use normal
> >cookies because cookies cannot be passed between domains. So in a blind
> >GET request I need to pass the ID cookie so the 3rd party affiliate
> >program will know the affiliate ID.
> >
>
> I'd recommend abandoning the flat coding style and make use of the LWP
> module available on CPAN. This is a tried and true way to bypass the
> complexities of the HTTP protocol and get down to doing the task at hand.
>
> Among other things the lwpcook manual page includes the following:
>
> COOKIES
> Some sites like to play games with cookies. By default
> LWP ignores cookies provided by the servers it visits.
> LWP will collect cookies and respond to cookie requests if
> you set up a cookie jar.
>
> use LWP::UserAgent;
> use HTTP::Cookies;
>
> $ua = LWP::UserAgent->new;
> $ua->cookie_jar(HTTP::Cookies->new(file => "lwpcookies.txt",
> autosave => 1));
>
> # and then send requests just as you used to do
> $res = $ua->request(HTTP::Request->new(GET => "http://www.yahoo.no"));
> print $res->status_line, "\n";
>
> As you visit sites that send you cookies to keep, then the
> file lwpcookies.txt" will grow.
> --
> This space intentionally left blank
------------------------------
Date: Tue, 25 Sep 2001 17:07:04 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: multipul http connections
Message-Id: <mbudash-F3F9DD.10070625092001@news.sonic.net>
In article <9opuom$fn9j$1@reader02.wxs.nl>, "Edwin B"
<edwin@notthis.com> wrote:
> I want to fetch content from the web but as it's quite a bit and
> from different url's I am looking for a way to open multiple
> connections.
>
> I have looked at the fork function but I am not sure if this is
> what I should use.
>
> Can anybody help me a bit and give some pointers into
> the right direction?
this looks interesting...:
http://www.perl.com/CPAN-local/modules/by-module/LWP/ParallelUserAgent-2.
51.readme
hth-
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: 25 Sep 2001 16:19:15 GMT
From: ljb <ljb_fr@yahoo.fr>
Subject: Re: non-persistent cookies management
Message-Id: <2001925-181915-456564@foorum.com>
thank you, I will test
------
User of http://www.foorum.com/. The best tools for usenet searching.
------------------------------
Date: 25 Sep 2001 17:42:02 +0100
From: nobull@mail.com
Subject: Re: Please Help with Sockets!
Message-Id: <u9ofnzw7c5.fsf@wcl-l.bham.ac.uk>
"Raj" <oneconcept@yahoo.co.uk> writes:
> <nobull@mail.com> wrote in message news:u9d74gwmwo.fsf@wcl-l.bham.ac.uk...
> >
> > > while (<S>) {
> >
> > Random shot in the dark: it may be that the protocol you are
> > implementing requires that you recognise some sort of end-of-data
> > signal other than an EOF on the socket.
> But Nobull, you're right, I need to recognise a period (".") at the end of
> the data set which looks like this:
>
> STATUS=ACTIVE
>
> STATUS_FLAGS=
[snip]
> .
>
> Using
>
> while (<S> ne ".") {
>
> blah...
>
> }
>
> doesn't seem to work though. Can someone please shed some light?
A few problems here.
1) The <> operator returns un-chomp()ed data so you would need to
compare with ".\n" or /^.$/ (The latter is marginally slower but I
think looks neater).
2) The magic auto assignment of $_ by <> inside while() only applies
there's nothing else in the while() condition.
3) You probably do not want your program to go into an infinite loop
if the socket closes prematurely so you mustn't remove the EOF
condition as a possible loop termination condition.
"Raj" <oneconcept@yahoo.co.uk> writes:
> while (<S>) {
> print "<P>".$_;
> ($key, $value) = /^BILL:(.*?)=(.*)?\n/;
> $address{$key} = $value;
> }
> close(S);
> return 1;
my $ok;
local $_;
while (<S>) {
if ( /^.$/ ) {
$ok++;
last;
}
print "<P>$_";
if (my($key, $value) = /^BILL:(.+?)=(.*)/) {
$address{$key} = $value;
}
}
close(S);
return $ok;
Note: I've removed the redundant ? after (.*) because a pattern that
can match the null string cannot fail to match.
Note: I've checked the pattern match succeeds - you don't really want
a $address{undef()}=undef() entry in %address do you?
Note: I've limited the scope of the temporary varaibles because it is
quite simply pathological not to do so.
Note: I've local()ized $_ because failure to do so when using the
while(<>) will sooner or later come back and burn you.
Note: I've assumed you want to consider premature termination of the
data to be a failure, and futher I've assumed that this should be
denoted by returning undef.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
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 1813
***************************************