[24392] in Perl-Users-Digest
Perl-Users Digest, Issue: 6580 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 19 03:05:47 2004
Date: Wed, 19 May 2004 00:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 19 May 2004 Volume: 10 Number: 6580
Today's topics:
Re: aggregating single IP addresses into CIDRs? <josef.moellers@fujitsu-siemens.com>
Re: Can't build GD.pm on Solaris8 <mgjv@tradingpost.com.au>
How do I scope a variable if the variable name contains (David Filmer)
Re: How do I scope a variable if the variable name cont <jtc@shell.dimensional.com>
Re: How do I scope a variable if the variable name cont <uri@stemsystems.com>
Re: IO::Socket problem <someone@somewhere.com>
Meaning of Orthogonality <ewijaya@singnet.com.sg>
Re: Meaning of Orthogonality <nospam@bigpond.com>
Re: Meaning of Orthogonality <spam-collector@pense-online.de>
Re: My Example - Regex for "not any words(lines) precee <josef.moellers@fujitsu-siemens.com>
Re: Passing variables from Perl to other programs (Efialtis)
Re: Passing variables from Perl to other programs <postmaster@castleamber.com>
Re: Password scheme/Persistent session... <jurgenex@hotmail.com>
performance questions (Charlie)
Re: Perl apache <nospam@bigpond.com>
Re: Perl apache <spamtrap@dot-app.org>
Re: Perl apache <xuxu_18@yahoo.com>
Re: Perl apache <xuxu_18@yahoo.com>
Re: perlmagick and image size <mgjv@tradingpost.com.au>
SOLVED: How do I scope a variable if the variable name <IneverReadAnythingSentToMe@hotmail.com>
Re: SOLVED: How do I scope a variable if the variable n <uri@stemsystems.com>
Storing downloaded webpages into files (PuZzLeD)
Re: Storing downloaded webpages into files <usenet@morrow.me.uk>
Re: Testing whether given file is open? <tassilo.parseval@rwth-aachen.de>
Re: Testing whether given file is open? <wherrera@lynxview.com>
Re: Testing whether given file is open? <tassilo.parseval@rwth-aachen.de>
Re: XML::Simple Example perl help needed <jtc@shell.dimensional.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 19 May 2004 08:39:15 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: aggregating single IP addresses into CIDRs?
Message-Id: <c8eva1$em6$3@nntp.fujitsu-siemens.com>
Gerald Jones wrote:
> Is there a perl way to take a list of IP unordered addresses in dotted =
quad
> format and group them into more compact CIDR format?
How about:
Convert to integer (doable if IPv4)
Or into one integer
Find the least significant "1".
Done
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: 18 May 2004 23:38:53 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Can't build GD.pm on Solaris8
Message-Id: <slrncal7kd.mhn.mgjv@verbruggen.comdyn.com.au>
On Tue, 18 May 2004 07:31:45 GMT,
Jure Simsic <jure.simsic@mobitel.si> wrote:
> I cant't build GD-1.41 on Solaris 8. When building, I get:
^^^^^^^
> I'm using
> - v5.8.3 built for sun4-solaris
> - gcc version 3.2.3
> - libgd gd-2.0.23 with jpeg & png & freetype
^^^^^^
The underlined version numbers are your problem. The GD module with
versions starting with 1 require a libgd version starting with 1. The
libgd versions starting with 2 are matched by a GD version starting
with 2. The main reason for this is that the library and its API
changed considerably when libgd version 2 was released. The GD
module's interface hasn't changed that much.
> I've asked my friend Google about this and the only time this has
> happened was, when someone tried to compile GD.pm with old libgd (pre
> 1.8)..
You're trying to compile an old GD with a new libgd. Reverse problem,
but similar result.
Martien
--
|
Martien Verbruggen | I used to have a Heisenbergmobile. Every time
Trading Post Australia | I looked at the speedometer, I got lost
|
------------------------------
Date: 18 May 2004 17:56:02 -0700
From: IneverReadAnythingSentToMe@hotmail.com (David Filmer)
Subject: How do I scope a variable if the variable name contains a variable?
Message-Id: <e4c916dd.0405181656.5d92e96e@posting.google.com>
I can do this:
my @bar; #explicit name - fine
but not this:
my $foo = 'bar'; #fine
my @{$foo}; #oops
Perl complains, "Can't declare array dereference..."
Does anybody know the syntax to scope a variable name that includes a variable?
Thanks!
------------------------------
Date: 18 May 2004 19:11:13 -0600
From: Jim Cochrane <jtc@shell.dimensional.com>
Subject: Re: How do I scope a variable if the variable name contains a variable?
Message-Id: <slrncald1l.jke.jtc@shell.dimensional.com>
In article <e4c916dd.0405181656.5d92e96e@posting.google.com>, David Filmer wrote:
> I can do this:
>
> my @bar; #explicit name - fine
>
> but not this:
>
> my $foo = 'bar'; #fine
> my @{$foo}; #oops
The above is how you deference a reference, which you can define with,
e.g.:
my $f = [1, 2, 3];
and use, e.g.:
print "@{$f}\n";
or, in this case:
print "@$f\n";
Is this what you're looking for?
>
> Perl complains, "Can't declare array dereference..."
>
> Does anybody know the syntax to scope a variable name that includes a variable?
>
> Thanks!
--
Jim Cochrane; jtc@dimensional.com
[When responding by email, include the term non-spam in the subject line to
get through my spam filter.]
------------------------------
Date: Wed, 19 May 2004 04:15:07 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: How do I scope a variable if the variable name contains a variable?
Message-Id: <x73c5xqchh.fsf@mail.sysarch.com>
>>>>> "JC" == Jim Cochrane <jtc@shell.dimensional.com> writes:
JC> In article <e4c916dd.0405181656.5d92e96e@posting.google.com>, David Filmer wrote:
>> I can do this:
>>
>> my @bar; #explicit name - fine
>>
>> but not this:
>>
>> my $foo = 'bar'; #fine
>> my @{$foo}; #oops
JC> my $f = [1, 2, 3];
JC> print "@{$f}\n";
JC> print "@$f\n";
JC> Is this what you're looking for?
he is looking for the evil symrefs, which luckily you didn't provide.
to the OP:
use a hash. see the many threads (google for them) on this. we get this
asked every week.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 18 May 2004 23:08:39 GMT
From: "Bigus" <someone@somewhere.com>
Subject: Re: IO::Socket problem
Message-Id: <24e99c69514175352b4f4e4ddbe7a59f@news.teranews.com>
"Thomas Kratz" <ThomasKratz@REMOVEwebCAPS.de> wrote in message
news:40a8ef05.0@juno.wiesbaden.netsurf.de...
> Bigus wrote:
>
> >
> > I can't seem to get it to work.. I'll hunt around for some more
examples.
>
> Try this [modified original script]:
> (untested)
>
> ====================
> use strict;
> use warnings;
> my $email = "blah\@blah.com";
> my $cmd = "some command";
>
> # Connect to Listserv
> use IO::Socket;
> my $lsv = new IO::Socket::INET( PeerAddr => 'localhost',
> PeerPort => 2306,
> Proto => 'tcp');
> $lsv or die "Connection problem :$!";
>
> # Send command header & check return code
> my $len = length($email)+length($cmd)+1;
> my $bin =
>
pack("a*CCCa*","\r\n",int($len/256),$len-(int($len/256)*256),length($email),
> $email);
> $lsv->print("1B".$bin);
> my $msg = $lsv->getline;
> exit if $msg !~ /^250/;
>
> use IO::Select;
> my $sel = IO::Select->new();
> $sel->add($lsv);
>
> # Send command
> $lsv->print("$cmd\n");
>
> my @lines;
> while ( $sel->can_read(0.1) ) {
> last if $lsv->eof;
> my $line = $lsv->getline;
> push @lines, $line;
> }
>
> print "@lines";
>
> # Close socket
> close $lsv;
> ====================
>
> This should not block and print all lines available.
Thanks but unfortunately not.. it exits after the first line and prints that
out. I suspect that an eof marker is being sent at the end of each line of
output from the mailing list system. Actually, just tried commenting out the
"last if.. eof" line and it still prints out the first line and exits.
Regards
Bigus
------------------------------
Date: Wed, 19 May 2004 08:43:13 -0000
From: Edward Wijaya <ewijaya@singnet.com.sg>
Subject: Meaning of Orthogonality
Message-Id: <opr78nubyeuj0cst@news.singnet.com.sg>
Perl is said to be an "orthogonal" programming language.
What does it mean?
Regards
Edward WIJAYA
SINGAPORE
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
------------------------------
Date: Wed, 19 May 2004 11:05:10 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Meaning of Orthogonality
Message-Id: <6461687.pkFTbbq1S8@GMT-hosting-and-pickle-farming>
Edward Wijaya wrote:
> Perl is said to be an "orthogonal" programming language.
> What does it mean?
>
> Regards
> Edward WIJAYA
> SINGAPORE
>
The computer science meaning is derived from the matematical meaning.
The simplest meaning is "at right angles". Think of walking along and
throwing a ball in the air - you can do one, or either, or both.
One thing does not effect the other, and the two combinations are possible
at the same time.
http://en.wikipedia.org/wiki/Orthogonal
The computer science meaning is
- a set of basic constructs
- there are many combinations of the basic constructs allowed.
For example, many of Perl's functions work on both scalars and arrays.
gtoomey
------------------------------
Date: Wed, 19 May 2004 07:35:57 +0200
From: Joachim Pense <spam-collector@pense-online.de>
Subject: Re: Meaning of Orthogonality
Message-Id: <c8ero4$jga$00$1@news.t-online.com>
Edward Wijaya wrote <opr78nubyeuj0cst@news.singnet.com.sg>:
> Perl is said to be an "orthogonal" programming language.
> What does it mean?
>
The meaning of "orthogonal" is explained by Gregory in this thread. But who
said Perl was an orthogonal language? It is non-orthogonal by design, which
is generally considered an advantage.
Joachim
------------------------------
Date: Wed, 19 May 2004 08:35:31 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: My Example - Regex for "not any words(lines) preceeded by spaces"
Message-Id: <c8ev33$em6$2@nntp.fujitsu-siemens.com>
Paul Lalli wrote:
> On Tue, 18 May 2004, Sundaram Ramasamy wrote:
>=20
>=20
>>>Edward Wijaya <ewijaya@singnet.com.sg> wrote in comp.lang.perl.misc:
>>>
>>>[please don't to-post]
>>>
>>>
>>>>This is the example of the input (verbatim).
>>>>
>>>>AGATTAGT
>>>>GCATTAGT
>>>>AGGGTAGT
>>>>GGAGTAGG
>>>> A C G T Info Ptn Pattern
>>>> TOTAL INFORMATION CONTENT
>>>>
>>>>
>>>>I just want to remove the last two lines (that comes
>>>>with spaces before it).
>>
>>Here is another method.
>>
>> perl -ne 'print if /^[A-Z]+/' a.out
>>
>>
>> perl -ne 'print if /^\w+/' a.out
>>
>=20
>=20
> Neither of those meet the specs the OP specified.
> perl -ne 'print if /^\S/' a.out
Nitpicking (and showing that TMTOWTDI):
Your solution does not meet the specs of the OP either:
perl -ne 'print unless /^\s+/' file
!!Josef B-{)
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: 18 May 2004 15:44:00 -0700
From: efialtis@efialtis.com (Efialtis)
Subject: Re: Passing variables from Perl to other programs
Message-Id: <8a4d8b33.0405181444.6959f1cb@posting.google.com>
I am using this like to call Perl from VBA
Shell ("perl.exe -d C:\TaskComplete.pl --TASK=EnterBorrowerData
--URL=QA")
The perl goes through and does a lot of things, and at the end, I end
up with a string that VBA needs to continue.
I have tried outputting this string into a TXT file, but because of
the application of the VBA and the program we are working with, it
will not work to go this rout.
------------------------------
Date: Tue, 18 May 2004 23:05:52 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Passing variables from Perl to other programs
Message-Id: <40aadd20$0$213$58c7af7e@news.kabelfoon.nl>
Efialtis wrote:
> I am using this like to call Perl from VBA
>
> Shell ("perl.exe -d C:\TaskComplete.pl --TASK=EnterBorrowerData
> --URL=QA")
>
> The perl goes through and does a lot of things, and at the end, I end
> up with a string that VBA needs to continue.
>
> I have tried outputting this string into a TXT file, but because of
> the application of the VBA and the program we are working with, it
> will not work to go this rout.
VBA as in Visual Basic for applications? Why not call the program using
COM from Perl? (The other way around)? I have called Excel from Perl
several times in the past.
If VBA calls Perl, it is IMHO possible to talk back to Excel using COM.
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
------------------------------
Date: Wed, 19 May 2004 00:54:30 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Password scheme/Persistent session...
Message-Id: <afyqc.85540$sK3.12505@nwrddc03.gnilink.net>
krakle wrote:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
> news:<c82i7e$n92$1@mamenchi.zrz.TU-Berlin.DE>...
>> krakle <krakle@visto.com> wrote in comp.lang.perl.misc:
>>> Thank you. However, the whole point to my post was to see if I could
>>> do a session with out cookies...
>>
>> ...which is way off topic for clpm. Why ask that here?
>
> Because I wanted to know how to maintain state IN perl
Well, Perl is a procedural programming language, so yes, it does have
states. As long as you don't exit it will maintain the state of all it's
variables. Well, at least those defined globally. Where is the problem?
> without utilizing cookies.
Cookies? Cookies? That doesn't sound like anything related to Perl at all.
Perldoc says:
No documentation for perl FAQ keyword `cookie' found
No documentation for perl function `cookie' found
Wild guess: are you by any chance talking about CGI/web programming/HTML?
> It seems like a miscellaneous perl question that
> fits right in with comp.lang.perl.misc (note: Comp = Computer. Lang =
> Language. Perl = duh!. Misc = Miscellaneous). So, how doesn't a
> miscellaneous perl question belong here?
If you are talking about CGI/web programming/HTML, then what makes you think
your question is a perl/Perl question?
If you are not talking about CGI/web programming/HTML then I appolize and
would appreciate any pointer to the Perl documentation that describes Perl
cookies resp. says the a Perl program does not have a state.
jue
------------------------------
Date: 18 May 2004 21:57:06 -0700
From: cji_work@yahoo.com (Charlie)
Subject: performance questions
Message-Id: <1dc70d61.0405182057.12540fca@posting.google.com>
Hi folks,
I am working on the Web application testing these days, and I have
some questions need to clear.
Basically the application that I am testing is using the
Apache/cgi-bin, the back end database is mysql. From user point of
view, it is a website where you can place several "business" Orders.
The way that I am doing the testing is also by using the
Apache/cgi-bin( a seperate Apache running on different platform),
basides, I have used a list of modules get from www.cpan.org, such as
WWW.Mechanize, Threads, etc. I have created my perl file to simulate
realtime users' interaction, filling the text area, picking the radio
box, etc, till at last to push the submit button to have the order
submitted.
What I really interested is once the final submition button is pushed,
when the confirmation page is desplayed to the uses, (in
Perl/Mechanize, when "mech->submit()" is finished), while there are
tens, houdreds users doing the same thing concurrently.
So far I have created some testcases to test two kinds of orders. The
first one takes about 20 mi-seconds for that period of time, while the
second one takes about 20,000 mi-seconds. To create those two kinds of
orders, it may needs some extra informations for the second one than
the first one.
So based on the above description, can I necessarily say that the
performance of the second one is not as good as the first one ???
Do you see any overhead on this test module? the time consumed by the
Apache, perl/cgi-bin, not consumed by the real transaction ?
thanks a lot for any tips
CJ
------------------------------
Date: Wed, 19 May 2004 10:30:09 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Perl apache
Message-Id: <2414732.HVFdhGPCeX@GMT-hosting-and-pickle-farming>
Profetas wrote:
> I didn't know where to go.
> If this question shouldn't be posted here, just ignore it
>
> I have been trying to config perl and apache.
> My apache has been running for a while.
> and I already had perl installed,
but I guessed
> a new installation would be better.
Why?
when I start to install
> it ask for the apache src. and I can't find the apache src
> I eve downloaded the leatest version to check that out.
>
> then I jumped this stage. later on the documentation say
> that I should add a Include conf/mod_perl.conf but I can't
> find the conf file.
>
> Thanks
What are in the Apache log files?
To run cgi you need at least the following ing httpd.conf
LoadModule cgi_module modules/mod_cgi.so
Options Indexes FollowSymLinks ExecCGI
and in .htaccess you probably need need
Options +ExecCGI +Includes
gtoomey
------------------------------
Date: Tue, 18 May 2004 20:54:08 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Perl apache
Message-Id: <9-OdnZI8i-WsLTfdRVn-hQ@adelphia.com>
Profetas wrote:
> and I already had perl installed, but I guessed
> a new installation would be better.
Define "better". Have you been bitten by a bug that you know has been fixed
in a newer version? Have you benchmarked a newer version against your
scripts, and found it runs them faster?
Why are you guessing about something that can be measured?
> when I start to install
> it ask for the apache src. and I can't find the apache src
> I eve downloaded the leatest version to check that out.
You should "check out" the instructions. Building mod_perl as a DSO, outside
of the Apache source tree, is clearly documented.
> then I jumped this stage.
Whatever for? Do you seriously believe you can simply skip anything you
don't understand, and somehow wind up with a working installation anyway?
Who are you, Harry Potter?
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Wed, 19 May 2004 01:20:22 -0400
From: "Profetas" <xuxu_18@yahoo.com>
Subject: Re: Perl apache
Message-Id: <68b64042779a20f316941a046941988c@localhost.talkaboutprogramming.com>
>Whatever for? Do you seriously believe you can simply skip >anything you
As I said it was asking for the apache src. and I couldn't find in my
installation.
>don't understand, and somehow wind up with a working >installation
anyway?
How do you know?
Are you David Blain?
>Who are you, Harry Potter?
I didn't want you to find that out but I prob.. gave away
------------------------------
Date: Wed, 19 May 2004 01:23:15 -0400
From: "Profetas" <xuxu_18@yahoo.com>
Subject: Re: Perl apache
Message-Id: <692fe055bd75e68b68ccd817f90e4c07@localhost.talkaboutprogramming.com>
>> a new installation would be better.
>Why?
If that is too diff for you to get.
Is because you don't know what in which order the perl apache have been
installed. nor you know how as it had been done by the OS.
>What are in the Apache log files?
It seems that I came to the wrong place.
Thanks anyway
------------------------------
Date: 19 May 2004 04:03:32 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: perlmagick and image size
Message-Id: <slrncaln4j.mhn.mgjv@verbruggen.comdyn.com.au>
On Tue, 18 May 2004 04:37:39 GMT,
rossz <rosszNOSPAM@vamos-wentworth.org> wrote:
> I've been trying to use the perlmagick module to do the following, but
> haven't been having much luck.
>
> I need to adjust an image to a minimum size, but without distoring it,
> so I basically want to add space evenly around the existing image.
> Using Resize is out since that will distort the image, so I gave
> "Composite" a shot, though there doesn't seem to much in the way of docs
> for this. My attempt results in this error message:
>
> "Exception 410: reference is not my type `Image::Magick' at ./img.pl
> line 23."
>
> That's the "Composite" line.
>
> Any suggestions on how to get this done would be appreciated. I have a
> few thousand images I need to process so I would rather avoid doing this
> manually. Useless and broken code follows (simplified). Both
> ImageMagick and PerlMagick are the latest (afaik).
>
> #!/usr/bin/perl
You really, really need
use warnings;
use strict;
It would have caught your problem.
> use Image::Magick;
>
> $img = new Image::Magick;
>
> $img->Read('test1.jpg');
You should store this somewhere, presumably in $p.
You should also check for errors.
[snip]
> $z = $new->Composite(image=>$p, compose=>atop, gravity=>"SouthEast",
> x=>$x, y=>$y);
Where did $p come from?
Try the following:
use Image::Magick;
use strict;
use warnings;
my $im = Image::Magick->new();
my $bg = Image::Magick->new(size => "200x400");
my $rc = $bg->Read("xc:white");
$rc = $im->Read($ARGV[0]);
die $rc if $rc;
$rc = $im->Resize("200x400");
warn $rc if $rc;
$rc = $bg->Composite(gravity => "Center", image => $im);
warn $rc if $rc;
$rc = $bg->Write("foo.png");
die $rc if $rc;
Martien
--
|
Martien Verbruggen |
Trading Post Australia | 42.6% of statistics is made up on the spot.
|
------------------------------
Date: Wed, 19 May 2004 05:54:15 GMT
From: DavidFilmer <IneverReadAnythingSentToMe@hotmail.com>
Subject: SOLVED: How do I scope a variable if the variable name contains a variable?
Message-Id: <bECqc.78074$iF6.6596044@attbi_s02>
Uri Guttman wrote:
> use a hash. see the many threads (google for them) on this. we get this
> asked every week.
Hmmm. Either the question is not asked nearly as often as Uri recalls,
or else my Google search terms are far too general (I get over 1000 hits
with: perl scope variable hash my symref - bad signal to noise ratio).
Anyway, I didn't find the question answered, but one posting I found
mentioned:
perldoc -q 'variable as a variable'
(which is a perfectly natural perldoc topic name, though I would have
never thought of it).
Anyway, it didn't specifically answer this question, but I was able to
figure it out easily enough with Uri's remarks and the perldocs. For the
benefit of those who may Google this posting, I offer this simple-case
solution:
use strict;
my %array; #this is the hash that Uri mentioned
my $foo = 'bar';
@{$array{$foo}} = qw/a b c d e f g/; #or whatever
print @{$array{$foo}}; #same as: @{$array{'bar'}}
------------------------------
Date: Wed, 19 May 2004 06:18:39 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: SOLVED: How do I scope a variable if the variable name contains a variable?
Message-Id: <x7oeolos75.fsf@mail.sysarch.com>
>>>>> "D" == DavidFilmer <IneverReadAnythingSentToMe@hotmail.com> writes:
D> Uri Guttman wrote:
>> use a hash. see the many threads (google for them) on this. we get this
>> asked every week.
D> Hmmm. Either the question is not asked nearly as often as Uri recalls,
D> or else my Google search terms are far too general (I get over 1000
D> hits with: perl scope variable hash my symref - bad signal to noise
D> ratio).
try symrefs or symbolic references or soft references
use the words *I* mentioned.
D> Anyway, I didn't find the question answered, but one posting I found
D> mentioned:
D> perldoc -q 'variable as a variable'
D> (which is a perfectly natural perldoc topic name, though I would have
D> never thought of it).
D> Anyway, it didn't specifically answer this question, but I was able to
D> figure it out easily enough with Uri's remarks and the perldocs. For
D> the benefit of those who may Google this posting, I offer this
D> simple-case solution:
D> use strict;
D> my %array; #this is the hash that Uri mentioned
D> my $foo = 'bar';
D> @{$array{$foo}} = qw/a b c d e f g/; #or whatever
D> print @{$array{$foo}}; #same as: @{$array{'bar'}}
and you fell into the trap of the evil symref. do not go there if you
value your coding career. there lies deamons you don't want to release.
and here is my standard rant on this:
symbolic references use the symbol table to allow the creation and
access to variables with dymamically created names. but the symbol table
is really just a hash tree with special side effects. so why would you
use a specialized hash tree for this when a regular hash would work just
as well? and a regular hash has many advantages. it can be passed around
by reference, it can be stored in a lexical variable, it can be private
(a symbolic ref variable is always global and accessible).
so go ahead, pick the evil way which looks easy but is nasty, or the
nice and clean proper way which is as easy but requires a little
more understanding and will be used much more often.
and my final rules:
don't use the symbol table until you know when to not use it. the symbol
table is for managing symbols, it is not a general purpose data
structure.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 18 May 2004 17:17:51 -0700
From: tolavan@yahoo.com (PuZzLeD)
Subject: Storing downloaded webpages into files
Message-Id: <71f6d6c6.0405181617.1fa0281d@posting.google.com>
Hi,
I have a problem here. I am supposed to be saving downloaded web pages
on to a a local cache. I have written a forking proxy server that
reads the request frm the browser and passes the request to the
Internet Gateway and then gets back the data from the internet gateway
and then passes it on to the browser. I need to save the files that
are associated with each request into a local cache. I have attached
the server code below...
server_listenport = IO::Socket::INET->new(
LocalPort => $server_listenport,
Listen => $listen_queuesize)
or die "couldnt be a tcp server on port $server_listenport:
$@\n";
while($browser_request=$server_listenport->accept())
{
if (fork == 0)
{
#child
print " \n\nUsing Child Proceess...\n";
close ($server_listenport);
sysread($browser_request,$req_webpage,2048);
$date_stamp= `date`;
$internet_gateway =IO::Socket::INET->new(
PeerPort=>$IGway_listenport,
PeerAddr=>$IGway_hostname) or die " cannot
connect to gateway";
syswrite($internet_gateway,$req_webpage);
while(sysread($internet_gateway, $recv_webpage, 20480) > 0)
{
syswrite($browser_request,$recv_webpage);
}
print "\n\n\tWeb page is now downloaded!!\n\n";
close($internet_gateway);
exit;
}
}
else
{
#parent
print " \n\nUsing Parent Process...\n";
close($browser_request);
}
} #end of while
Can some1 help me ?
------------------------------
Date: Wed, 19 May 2004 00:43:15 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Storing downloaded webpages into files
Message-Id: <c8eaj3$40$1@wisteria.csv.warwick.ac.uk>
Quoth tolavan@yahoo.com (PuZzLeD):
> Hi,
> I have a problem here. I am supposed to be saving downloaded web pages
> on to a a local cache. I have written a forking proxy server that
> reads the request frm the browser and passes the request to the
> Internet Gateway and then gets back the data from the internet gateway
> and then passes it on to the browser. I need to save the files that
> are associated with each request into a local cache. I have attached
> the server code below...
What is your problem? You don't know how to save the data?
You should rewrite this using HTTP::Daemon and LWP, or indeed
HTTP::Proxy.
Ben
--
The cosmos, at best, is like a rubbish heap scattered at random.
- Heraclitus
ben@morrow.me.uk
------------------------------
Date: Wed, 19 May 2004 06:54:47 +0200
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Testing whether given file is open?
Message-Id: <2h07kpF7gdfiU1@uni-berlin.de>
Also sprach Charles Packer:
> A large data file is being pushed to us via FTP. We can assume that as
> long as the file is open, the FTP transfer hasn't completed. How do we
> test whether the file is still open? We know about fuser and lsof, but
> we (my colleague, at least, who has to code the Perl) would prefer
> using a purely Perlish approach. Is there a Perl module out there
> somewhere that performs such a test?
There is Linux::Fuser. You can't have done a very thorough search if you
didn't find it.
Other than that, there might be other ways. If the FTP server is locking
the file (and it really should do so), then you could try acquiring a
lock from Perl and see whether you get one. If you do, the file is not
open any longer:
use Fcntl qw/:flock/;
...
open F, "/incoming/file" or die $!;
if (flock F, LOCK_SH|LOCK_NB) {
print "/incoming/file no longer opem";
flock F, LOCK_UN;
...
}
If the FTP server does not lock the incoming file, you're out of luck
with this approach. Also see the particular pitfalls as described in
'perldoc -f flock'.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Tue, 18 May 2004 22:54:32 -0600
From: Bill <wherrera@lynxview.com>
To: Charles Packer <mailbox@cpacker.org>
Subject: Re: Testing whether given file is open?
Message-Id: <40AAE888.2020605@lynxview.com>
Charles Packer wrote:
> A large data file is being pushed to us via FTP. We can assume that as
> long as the file is open, the FTP transfer hasn't completed. How do we
> test whether the file is still open? We know about fuser and lsof, but
> we (my colleague, at least, who has to code the Perl) would prefer
> using a purely Perlish approach. Is there a Perl module out there
> somewhere that performs such a test?
Depends a _lot_ on the FTP program, but try to see if the file can be
opened for appending, which _should_ fail til it is closed, I believe-- eg
while ( ! open(FTPF, '>>', $name) ) {
print "still downloading\n"; sleep 10;
}
close FTPF;
------------------------------
Date: Wed, 19 May 2004 08:15:47 +0200
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Testing whether given file is open?
Message-Id: <2h0ccmF7g5jfU1@uni-berlin.de>
Also sprach Bill:
> Charles Packer wrote:
>> A large data file is being pushed to us via FTP. We can assume that as
>> long as the file is open, the FTP transfer hasn't completed. How do we
>> test whether the file is still open? We know about fuser and lsof, but
>> we (my colleague, at least, who has to code the Perl) would prefer
>> using a purely Perlish approach. Is there a Perl module out there
>> somewhere that performs such a test?
>
> Depends a _lot_ on the FTP program, but try to see if the file can be
> opened for appending, which _should_ fail til it is closed, I believe-- eg
>
> while ( ! open(FTPF, '>>', $name) ) {
> print "still downloading\n"; sleep 10;
> }
> close FTPF;
On many (most?) systems you can happily open a file for appending while
it is still written to by another process. So I doubt that your
suggestion would work.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 18 May 2004 16:51:11 -0600
From: Jim Cochrane <jtc@shell.dimensional.com>
Subject: Re: XML::Simple Example perl help needed
Message-Id: <slrncal4r3.895.jtc@shell.dimensional.com>
In article <xCvqc.288$ri.35893@dfw-read.news.verio.net>, David Staschover wrote:
> Not sure how not to top post.. Deleting the text below..
>
> Although I rtfm'd, I have no idea what they're talking about :) The example
> below worked.. thanks!
Not top posting means to respond to a paragraph or phrase below that
paragraph, as in this example. Top posting means to respond at the
beginning of your post, above the text you are responding to (as you
did), making it harder for people to figure out the context to which
you are responding.
The further down the page the text you are responding to is, the more out
of context your top post is and the harder it is for people to figure
out what you're talking about. Remember, a human mind, though amazing
and powerful, is not a computer - some simple processing tasks are very
taxing for it (unless, perhaps one is autistic).
>>
>> for (@{ $struct->{top}[0]{top1}[0]{field} }) {
>>
>> The reason you need the extra [0] is almost certainly because of the
>> 'forcearray => 1' you specified. Do you read the docs for the modules
>> you use?
>>
>> Ben
>>
>> --
>> I've seen things you people wouldn't believe: attack ships on fire off
>> the shoulder of Orion; I watched C-beams glitter in the dark near the
>> Tannhauser Gate. All these moments will be lost, in time, like tears in
> rain.
>> Time to die.
> ben@morrow.me.uk
>
>
--
Jim Cochrane; jtc@dimensional.com
[When responding by email, include the term non-spam in the subject line to
get through my spam filter.]
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 6580
***************************************