[23779] in Perl-Users-Digest
Perl-Users Digest, Issue: 5983 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 27 11:05:40 2003
Date: Sat, 27 Dec 2003 08:05:07 -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 Sat, 27 Dec 2003 Volume: 10 Number: 5983
Today's topics:
Re: Binary program? <mgjv@tradingpost.com.au>
Cygwin problem with 'print' (Fiaz Idris)
Re: Cygwin problem with 'print' <kuujinbo@hotmail.com>
Re: Cygwin problem with 'print' (Fiaz Idris)
Re: Cygwin problem with 'print' <gnari@simnet.is>
Re: I don't know what's wrong here ! (Jay Tilton)
Re: I don't know what's wrong here ! <noreply@gunnar.cc>
Re: I don't know what's wrong here ! <laie@wing_this_etsolutions.com>
Re: I don't know what's wrong here ! <gnari@simnet.is>
Re: I don't know what's wrong here ! <groleau@freeshell.org>
Re: I don't know what's wrong here ! <groleau@freeshell.org>
Re: I don't know what's wrong here ! <groleau@freeshell.org>
Re: I don't know what's wrong here ! <noreply@gunnar.cc>
Re: I don't know what's wrong here ! <gnari@simnet.is>
Re: I don't know what's wrong here ! <groleau@freeshell.org>
Re: I don't know what's wrong here ! <groleau@freeshell.org>
incrementing file names <roland@diku.dk>
Re: incrementing file names <gnari@simnet.is>
Re: incrementing file names <no_spam_for_jkeen@verizon.net>
Re: LWP with proxy problem (Woogie)
Problem with email <ningli2000@worldnet.att.net>
Re: Problem with email <noreply@gunnar.cc>
Re: Problem with email <gnari@simnet.is>
Re: why this code shots up memory usage <a_madhur@vsnl.net>
Re: why this code shots up memory usage <bik.mido@tiscalinet.it>
Re: why this code shots up memory usage <a_madhur@vsnl.net>
Re: why this code shots up memory usage <gnari@simnet.is>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 27 Dec 2003 17:38:53 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Binary program?
Message-Id: <slrnbuqa7t.61a.mgjv@martien.heliotrope.home>
On Fri, 26 Dec 2003 15:18:51 +0800,
Just in <goth1938@hotmail.com> wrote:
> Theres this old Apollo Unix station that runs a cronjob that actually does
> something, that I'm supposed to help identify.
>
> What the cronjob calls is what I assume to be a Perl program, because the
> first line has the path perl on it with old shebang hash in front of it.
What does the crontab line look like? Does it invoke perl with the
script as argument, or does it dorectly invoke the script?
> What miffs me is what follows after it - binary characters without any EOL
> termination.
It might have been treated with some sort of source filter. Is there
anything before the binary characters? If not, does
$ perl -MO=Deparse name_of_script
show you something decent? If it has been treated with a source filter,
that might show you what it really does.
> I assume this is encrypted, or even compiled. But I'm not so sure how perl
> is interpreting the binary.
No one can be sure without actually seeing anything.
> I know it would help if I posted an example, but I can't as it is
> confidential information to my company.
Well, I guess you'll have to figure it out yourself, then.
Martien
--
|
Martien Verbruggen | Unix is user friendly. It's just selective
| about its friends.
|
------------------------------
Date: 26 Dec 2003 22:10:52 -0800
From: ifiaz@hotmail.com (Fiaz Idris)
Subject: Cygwin problem with 'print'
Message-Id: <93c1947c.0312262210.3fe57dcf@posting.google.com>
I am using Win98SE and cygwin
$ uname -a
CYGWIN_98-4.10 fiaz 1.5.5(0.94/3/2) 2003-09-20 16:31 i686 unknown unknown Cygwin
Say, I have a file 'stations.txt'
ABBEY WOOD
ABERGELE & PENSARN
CILMERI
CITY THAMESLINK
CLACTON
WATERINGBURY
WATERLOO (MERSEYSIDE)
and the following perlscript
while (<>) {
chomp;
$curr = $_;
$scurr = join '', (sort split //, $curr);
$scurr =~ s/\W//g;
# Behaviour inconsistent between ActivePerl5.8 & Cygwin Perl
# $curr although printed can't be seen.
print "$curr and $scurr\n";
}
The expected CORRECT result according to ActivePerl 5.8.0 is
ABBEY WOOD and ABBDEOOWY
ABERGELE & PENSARN and AABEEEEGLNNPRRSamp
CILMERI and CEIILMR
CITY THAMESLINK and ACEHIIKLMNSTTY
CLACTON and ACCLNOT
WATERINGBURY and ABEGINRRTUWY
WATERLOO (MERSEYSIDE) and ADEEEEILMOORRSSTWY
But, the cygwin perl version
(This is perl, v5.8.2 built for cygwin-thread-multi-64int)
gives the following WRONG result.
and ABBDEOOWY
and AABEEEEGLNNPRRSamp
and CEIILMR
and ACEHIIKLMNSTTY
and ACCLNOT
and ABEGINRRTUWY
and ADEEEEILMOORRSSTWY
that is the first variable $curr is not shown. Although it is printed
somehow it gets backtracked and deletes and prints only from the space
and after.
Am I missing something? Is it a bug with Cygwin perl? Can someone please advise.
------------------------------
Date: Sat, 27 Dec 2003 20:20:00 +0900
From: ko <kuujinbo@hotmail.com>
Subject: Re: Cygwin problem with 'print'
Message-Id: <bsjq57$743$1@pin3.tky.plala.or.jp>
Fiaz Idris wrote:
> I am using Win98SE and cygwin
> $ uname -a
> CYGWIN_98-4.10 fiaz 1.5.5(0.94/3/2) 2003-09-20 16:31 i686 unknown
unknown Cygwin
>
> Say, I have a file 'stations.txt'
[snip code]
> The expected CORRECT result according to ActivePerl 5.8.0 is
[snip AS output]
> But, the cygwin perl version
> (This is perl, v5.8.2 built for cygwin-thread-multi-64int)
>
> gives the following WRONG result.
[snip Cygwin output]
> that is the first variable $curr is not shown. Although it is printed
> somehow it gets backtracked and deletes and prints only from the space
> and after.
>
> Am I missing something? Is it a bug with Cygwin perl? Can someone
please advise.
This isn't a Perl problem, its a result Cygwin reading the text file in
DOS/Windows format. Copy and paste the original text file into another
text file from the Cygin shell using vi or whatever text editor you use
and try reruning the script.
You should also start all of your scripts like so:
use strict;
use warnings;
HTH - keith
------------------------------
Date: 27 Dec 2003 04:48:54 -0800
From: ifiaz@hotmail.com (Fiaz Idris)
Subject: Re: Cygwin problem with 'print'
Message-Id: <93c1947c.0312270448.521a1d2c@posting.google.com>
I happen to solve the problem myself and here is how.
But only if someone has any input on the following, please advise.
When 'vi stations.txt' i see the following line at the bottom.
"stations.txt" [dos]
That is the file is in [dos] format.
When I ':set', the 'fileformat=dos' can be seen.
So, what I did is ':set fileformat=unix' and the perl script works
as expected giving out both the $curr and $scurr.
When I ':l' on a line for example, I see no difference between
both 'dos' and 'unix' formats. So, what actually does the 'fileformat'
command do.
Thanks
------------------------------
Date: Sat, 27 Dec 2003 12:06:37 -0000
From: "Ragnar Hafsta" <gnari@simnet.is>
Subject: Re: Cygwin problem with 'print'
Message-Id: <bsjsl5$ibs$1@news.simnet.is>
"Fiaz Idris" <ifiaz@hotmail.com> wrote in message
news:93c1947c.0312262210.3fe57dcf@posting.google.com...
> I am using Win98SE and cygwin
> while (<>) {
> chomp;
cygwin uses NL as end of file marker, and chomp will remove that
however, you input file is probably a windows text file, where
lines are terminated with CR+NL, so you now have your line
with an extra CR at the end. try:
s/\r//g;
> $curr = $_;
>
> $scurr = join '', (sort split //, $curr);
> $scurr =~ s/\W//g;
>
> # Behaviour inconsistent between ActivePerl5.8 & Cygwin Perl
> # $curr although printed can't be seen.
>
> print "$curr and $scurr\n";
the CR in print on terminal has the effect to move the cursor to beginning
of line,
so the " $scurr" overwrites the $curr
> }
gnari
------------------------------
Date: Sat, 27 Dec 2003 05:09:48 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: I don't know what's wrong here !
Message-Id: <3fed12f3.615310737@news.erols.com>
Wes Groleau <groleau@freeshell.org> wrote:
: "Ragnar Hafsta" wrote:
: >> /^\s*(\d+)\s+(@\S+@)?\s*(\S+)\s+(.*)/;
: >
: > look at this a bit:
: > (your input is '0 HEAD')
: > ^\s* zero or more whitespace. ok
: > (\d+) one ore more digits. ok matches '0', the rest is ' HEAD'
: > \s+ one or more ws. matches ' ', rest is 'HEAD'
: > (@\S+@)? maches ''
: > \s* matches ''
: > (\S+) matches 'HEAD' rest is ''
: > \s+ does not match . oooooops
: > (.*)/;
: >
: > maybe your previous input contained space at the end of the '0 HEAD' line
:
: OK, I see that. Thanks. Maybe there was a space.
:
: However, if the regexp doesn't match, why was
: it able to get the $Level and leave the other
: parts undefined?
You are probably seeing a stale value that was captured from a prior
iteration. The values in $1, $2, etc. are not reset when a match fails,
and the code does not verify that the match is successful before using
those variables.
------------------------------
Date: Sat, 27 Dec 2003 07:47:15 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: I don't know what's wrong here !
Message-Id: <bsja2r$dgggt$1@ID-184292.news.uni-berlin.de>
Wes Groleau wrote:
> Gunnar Hjalmarsson wrote:
>> Wes Groleau wrote:
>>>
>>> /^\s*(\d+)\s+(@\S+@)?\s*(\S+)\s+(.*)/;
>> --------------------------------^^^
>
> Sorry, I was unclear. The only way to determine the end of the Tag
> is by whitespace. But as someone else pointed out, if there is no
> text, then there may be a line-end instead of white space. Perhaps
> this is what you are saying?
Yes, that is what I mean.
>> It's better written as:
>>
>> /^\s*(\d+)\s+(@\S+@)?\s*(\S+)(?:\s+(.+))?/;
>> ---------------------------------^^^-------^^
>
> So here, $4 matches the _inner_ parentheses?
Yes.
> I don't know what ?: means in this context.
http://www.perldoc.com/perl5.8.0/pod/perlre.html#%28--pattern%29
>> Basically I think your code can be shortened to:
>>
>> while (<FILE>) {
>> chomp;
>
> Oh, I definitely need to convert line ends on files from other
> platforms. (Mac/Win/Unix) But as John pointed out, I did it
> wrong.
I just thought that that is better handled when transferring between
file systems (using "ASCII" or "Text" transfer mode). But maybe it's
wise to explicitly remove all trailing whitespace as well...
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 27 Dec 2003 09:21:25 GMT
From: =?UTF-8?b?TMSByrtpZSBUZWNoaWU=?= <laie@wing_this_etsolutions.com>
Subject: Re: I don't know what's wrong here !
Message-Id: <94213915d100ce30a00d33624ac4fac1@news.teranews.com>
On Fri, 26 Dec 2003 23:48:24 -0500, Wes Groleau wrote:
> For the curious, what I am doing is reformatting a GEDCOM file, AND
> splitting it into multiple files. Have to open a new file every time a
> Level = 0 line comes in, with the filename determined by parts of the
> line.
That's what I thought when I read your original post. BTW, why reinvent
the wheel? Download the Gedcom module from CPAN. I'm sure that module
does most of what you want.
Hau'oli Makahiki Hou!
La'ie Techie
------------------------------
Date: Sat, 27 Dec 2003 11:58:12 -0000
From: "Ragnar Hafsta" <gnari@simnet.is>
Subject: Re: I don't know what's wrong here !
Message-Id: <bsjs5c$i95$1@news.simnet.is>
"Wes Groleau" <groleau@freeshell.org> wrote in message
news:zLOdneKKDZmLlHCiRVn-jw@gbronline.com...
>
> However, if the regexp doesn't match, why was
> it able to get the $Level and leave the other
> parts undefined?
>
you should try to use print statements to help you debug.
a couple of them in the if/else blocks would have shown you
that $1 was indeed undefined, you set $Level=0, and test that later.
as the value '0' happened to be the value in the line, you just assumed
that it 'got' the $Level.
gnari
------------------------------
Date: Sat, 27 Dec 2003 09:29:41 -0500
From: Wes Groleau <groleau@freeshell.org>
Subject: Re: I don't know what's wrong here !
Message-Id: <bKOdnTBO6_vJCnCiRVn-vg@gbronline.com>
Jay Tilton wrote:
> : However, if the regexp doesn't match, why was
> : it able to get the $Level and leave the other
> : parts undefined?
>
> You are probably seeing a stale value that was captured from a prior
> iteration. The values in $1, $2, etc. are not reset when a match fails,
> and the code does not verify that the match is successful before using
> those variables.
Ah, that's useful info, thanks. However, in this case,
it was after the first line in a new invocation.
But I will have to explicitly undefine them each time.
--
Wes Groleau
Alive and Well
http://freepages.religions.rootsweb.com/~wgroleau/
------------------------------
Date: Sat, 27 Dec 2003 09:33:30 -0500
From: Wes Groleau <groleau@freeshell.org>
Subject: Re: I don't know what's wrong here !
Message-Id: <mLKdnaKZj-qnBXCiRVn-jA@gbronline.com>
"Ragnar Hafsta��������������������" wrote:
> you should try to use print statements to help you debug.
> a couple of them in the if/else blocks would have shown you
> that $1 was indeed undefined, you set $Level=0, and test that later.
> as the value '0' happened to be the value in the line, you just assumed
> that it 'got' the $Level.
Ouch. I put the print statements later and "assumed"
it got the level because the diagnostic "no level"
wasn't there. But the reason it wasn't there is the
"no tag" diagnostic overwrote it! :-)
I need to find a boook and learn how to use the debugger.
I've used it before, but without the book, I could only
single-step and that was a royal pain.
--
Wes Groleau
----
The man who reads nothing at all is better educated
than the man who reads nothing but newspapers.
-- Thomas Jefferson
------------------------------
Date: Sat, 27 Dec 2003 09:38:16 -0500
From: Wes Groleau <groleau@freeshell.org>
Subject: Re: I don't know what's wrong here !
Message-Id: <7uSdnVyVh7zFBHCiRVn-uQ@gbronline.com>
Gunnar Hjalmarsson wrote:
> Wes Groleau wrote:
>> Oh, I definitely need to convert line ends on files from other
>> platforms. (Mac/Win/Unix) But as John pointed out, I did it
>> wrong.
>
> I just thought that that is better handled when transferring between
> file systems (using "ASCII" or "Text" transfer mode). But maybe it's
You're right. Unfortunately, I may not always be the one
doing the transfer. :-)
> wise to explicitly remove all trailing whitespace as well...
Again, unfortunately, in GEDCOM there is a construct that allows
the writer (usually a program) to concatenate two lines of Text
where spaces at the end of the first line are supposed to be kept.
I never use that feature myself, but I may get input from others
who have used it.
--
Wes Groleau
Nobody believes a theoretical analysis -- except the guy who did it.
Everybody believes an experimental analysis -- except the guy who did it.
-- Unknown
------------------------------
Date: Sat, 27 Dec 2003 15:48:58 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: I don't know what's wrong here !
Message-Id: <bsk6bb$bn1jr$1@ID-184292.news.uni-berlin.de>
Wes Groleau wrote:
> Jay Tilton wrote:
>> You are probably seeing a stale value that was captured from a
>> prior iteration. The values in $1, $2, etc. are not reset when a
>> match fails, and the code does not verify that the match is
>> successful before using those variables.
>
> Ah, that's useful info, thanks. However, in this case, it was
> after the first line in a new invocation. But I will have to
> explicitly undefine them each time.
I don't think that you can undefine those variables explicitly. This
is how you typically do it instead:
if (/^\s*(\d+)\s+(@\S+@)?\s*(\S+)(?:\s+(.+))?/) {
# It matched - do something
} else {
# It did not match - do something else
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 27 Dec 2003 14:45:04 -0000
From: "Ragnar Hafsta" <gnari@simnet.is>
Subject: Re: I don't know what's wrong here !
Message-Id: <bsk5u7$ili$1@news.simnet.is>
"Wes Groleau" <groleau@freeshell.org> wrote in message
news:mLKdnaKZj-qnBXCiRVn-jA@gbronline.com...
>
> I need to find a boook and learn how to use the debugger.
> I've used it before, but without the book, I could only
> single-step and that was a royal pain.
in this kind of case, simple print statements would do the trick
gnari
------------------------------
Date: Sat, 27 Dec 2003 10:56:47 -0500
From: Wes Groleau <groleau@freeshell.org>
Subject: Re: I don't know what's wrong here !
Message-Id: <ZtOdnRGfdYwiNnCiRVn-uw@gbronline.com>
Gunnar Hjalmarsson wrote:
> I don't think that you can undefine those variables explicitly. This
> is how you typically do it instead:
>
> if (/^\s*(\d+)\s+(@\S+@)?\s*(\S+)(?:\s+(.+))?/) {
> # It matched - do something
> } else {
> # It did not match - do something else
> }
Isn't "undef" a predefined 'constant' that can be
assigned to a variable? I haven't tried it, but
it seems I've read that somewhere...
I may also try the 'if' but I'd prefer it to
match every line because if the syntax is bad
I'd like to use what I can in the diagnostic
messages.
--
Wes Groleau
"Would the prodigal have gone home if
the elder brother was running the farm?"
-- James Jordan
------------------------------
Date: Sat, 27 Dec 2003 10:59:55 -0500
From: Wes Groleau <groleau@freeshell.org>
Subject: Re: I don't know what's wrong here !
Message-Id: <ZtOdnRCfdYzkMXCiRVn-uw@gbronline.com>
Lāʻie Techie wrote:
> That's what I thought when I read your original post. BTW, why reinvent
> the wheel? Download the Gedcom module from CPAN. I'm sure that module
> does most of what you want.
Looked at it long ago, and did a little with it
but eventually rejected it for reasons I can't
remember. Maybe I should take another look.
OTOH, it _feels_ like I'm so close now....
(which is what many programmers say for the
last six months of their project.)
:-)
--
Wes Groleau
-----------
Curmudgeon's Complaints on Courtesy:
http://www.onlinenetiquette.com/courtesy1.html
(Not necessarily my opinion, but worth reading)
------------------------------
Date: Sat, 27 Dec 2003 13:29:47 +0100
From: Lars Tackmann <roland@diku.dk>
Subject: incrementing file names
Message-Id: <Pine.LNX.4.58.0312271322250.10791@brok.diku.dk>
Hi.
I am creating a perl script that will rename a file called
SEGEyyyyyyy.dat (yyyyyyy is a number) to Oxxxxxddmm (where xxxxx is a
number that is incremented by one for each file and ddmm is the day and
the month).
My problem is now that the files are send via ftp and deleted from this
machine (where the scipt has to run). So I need some way to keep track
on my xxxxx numbers - without searing the file names on the disk -
Thanks.
------------------------------
Date: Sat, 27 Dec 2003 13:37:58 -0000
From: "Ragnar Hafsta" <gnari@simnet.is>
Subject: Re: incrementing file names
Message-Id: <bsk20d$igp$1@news.simnet.is>
"Lars Tackmann" <roland@diku.dk> wrote in message
news:Pine.LNX.4.58.0312271322250.10791@brok.diku.dk...
> I am creating a perl script that will rename a file called
> SEGEyyyyyyy.dat (yyyyyyy is a number) to Oxxxxxddmm (where xxxxx is a
> number that is incremented by one for each file and ddmm is the day and
> the month).
>
> My problem is now that the files are send via ftp and deleted from this
> machine (where the scipt has to run). So I need some way to keep track
> on my xxxxx numbers - without searing the file names on the disk -
whats wrong with keeping your current xxxxx in a data file along with the
script?
gnari
------------------------------
Date: Sat, 27 Dec 2003 14:10:23 GMT
From: "Jim Keenan" <no_spam_for_jkeen@verizon.net>
Subject: Re: incrementing file names
Message-Id: <jpgHb.6678$lt.3607@nwrdny02.gnilink.net>
"Lars Tackmann" <roland@diku.dk> wrote in message
news:Pine.LNX.4.58.0312271322250.10791@brok.diku.dk...
> Hi.
>
> I am creating a perl script that will rename a file called
> SEGEyyyyyyy.dat (yyyyyyy is a number) to Oxxxxxddmm (where xxxxx is a
> number that is incremented by one for each file and ddmm is the day and
> the month).
>
> My problem is now that the files are send via ftp and deleted from this
> machine (where the scipt has to run). So I need some way to keep track
> on my xxxxx numbers - without searing the file names on the disk -
>
You will almost certainly have to store _something_ on disk; otherwise you
would have to go to the ftp site to see what the next number to be assigned
is.
But what you store could be as simple as a file containing a hash keyed by
'mmdd' (or, for greater flexibility, 'yyyymmdd') which increments a counter
for each key:
file: date.config
%dateconfig = (
20031226 => 00005,
20031227 => 00003,
...
)
... in your main package:
our (%dateconfig);
require date.config;
Then increment the number and date and format accordingly with 'sprintf'.
Jim Keenan
------------------------------
Date: 27 Dec 2003 07:21:38 -0800
From: kent_zunker@bmc.com (Woogie)
Subject: Re: LWP with proxy problem
Message-Id: <4a31f52f.0312270721.55b1f0ca@posting.google.com>
spamtotrash@toomuchfiction.com (Kevin Collins) wrote in message news:<a6882f32.0312241132.55fb4a0f@posting.google.com>...
> kent_zunker@bmc.com (Woogie) wrote in message news:<4a31f52f.0312231243.25828446@posting.google.com>...
> > When running the sample code below without a proxy the GET returns the
> > expected data. When run with the $proxy uncommented the GET returns
> > the content of the login page for the site being accessed. The site
> > in the code is valid for ease of testing. I also am including the LWP
> > debug info for each attempt.
> >
> > Can anyone explain this behavior and what can I do to correct it?
> >
> > Thanks in advance
> >
> > Trace without proxy:
> >
> > LWP::UserAgent::new: ()
> > LWP::UserAgent::request: ()
> > LWP::UserAgent::send_request: GET
> > https://squid.servebeer.com/getservices.do?user=Guest&password=JustLooking&format=csv
> > LWP::UserAgent::_need_proxy: Not proxied
> > LWP::Protocol::http::request: ()
> > LWP::Protocol::collect: read 28 bytes
> > LWP::UserAgent::request: Simple response: OK
> >
> > Home
> > PE
> >
> >
> > Trace with proxy:
> >
> > LWP::UserAgent::new: ()
> > LWP::UserAgent::proxy: https http://148.245.207.85:8080
> > LWP::UserAgent::request: ()
> > LWP::UserAgent::send_request: GET
> > https://squid.servebeer.com/getservices.do?user=Guest&password=JustLooking&format=csv
> > LWP::UserAgent::_need_proxy: Proxied to http://148.245.207.85:8080
> > LWP::Protocol::http::request: ()
> > LWP::Protocol::collect: read 236 bytes
> > LWP::Protocol::collect: read 594 bytes
> > LWP::Protocol::collect: read 416 bytes
> > LWP::Protocol::collect: read 450 bytes
> > LWP::Protocol::collect: read 1017 bytes
> > LWP::Protocol::collect: read 443 bytes
> > LWP::Protocol::collect: read 643 bytes
> > LWP::UserAgent::request: Simple response: OK
> >
> > <html lang="en">
> >
> > <!-- Start Head -->
> > <head>
> > <title>
> >
> > Error
> >
> > </title>
> > <script language="JavaScript">
> > ...
> >
> >
> >
> > Here is the sample code:
> >
> >
> > #!/usr/bin/perl -w
> >
> > use LWP::UserAgent;
> > use HTTP::Request;
> > use HTTP::Response;
> > use Crypt::SSLeay;
> >
> > LWP::Debug::level('+');
> >
> > $url = "https://squid.servebeer.com/getservices.do?user=Guest&password=JustLooking&format=csv";
> > #$proxy="http://xxx.xxx.xxx.xxx:8080";
> >
> > $ua = LWP::UserAgent->new();
> >
> > if (defined $proxy)
> > {
> > $ENV{HTTPS_PROXY} = $proxy;
> >
> > # initialize from environment variables
> > $ua->env_proxy;
> > }
> >
> > $req = HTTP::Request->new(GET => $url);
> > $response = $ua->request($req);
> > if ($response->is_error())
> > {
> > printf " %s\n", $response->status_line;
> > }
> >
> > else
> > {
> > $content = $response->content();
> > print $content;
> > }
> >
> > exit;
>
> Your code has the definition of $proxy commented out, so I am not sure
> your example is relevant to your output.
>
> BUT, if it were uncommented, you are not including the ID and password
> in the proxy URL (as you are in the "real" URL), so it makes some
> sense that are being prompted for it.
>
> Additionally, why do you want to redirect your request through a proxy
> when you can get to it directly?
>
> Kevin
As stated in the comments at the beginning I provided output with and
without the $proxy set. The example trace outputs were derived from
two different environments. The first where a proxy was not required
and the second where one was.
As far as the ID and password are concerned, the code was intended to
support multiple environments, the proxy I was behind for the example
did not require ID or password.
While it is true that the request can be accessed in an open
environment directly, there are times when the code will be run in an
environment that has a proxy to the web. I've tried to write a
relatively generic solution.
Kent
------------------------------
Date: Sat, 27 Dec 2003 06:30:17 GMT
From: "Ning li" <ningli2000@worldnet.att.net>
Subject: Problem with email
Message-Id: <ZF9Hb.245368$Ec1.8548393@bgtnsc05-news.ops.worldnet.att.net>
Hi,
I am trying to send email to multiple recipients using CGI and form. In
the program, I check for the citycodes in the HTML form using subroutine
"check_citycode()". All the form entries will be emailed to different
recipients depending on the city code entered. The problem is, I always get
the message of "No recipient addresses found in the header", though I know I
put the addresses in the perl script.
Thanks in advance for your help.
Nick Li
The code is as the follow:
#!/usr/local/bin/perl
$mailprog = '/usr/lib/sendmail -i -t';
# Process query string
if( $ENV{'REQUEST_METHOD'} eq "POST" )
{
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}
else
{
$buffer = $ENV{"QUERY_STRING"};
}
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$IN{$name} = $value;
}
$my_citycode = check_citycode();
# Print the page header
print "Content-type: text/html\r\n\r\n";
sub mailComment
{
open(MAIL,"|$mailprog");
# The parameter array contains one hash reference. Assign it to a local
variable.
my ($hashReference) = @_;
# Iterate over the hash entries and print them out in the order of the
keys
if ($my_citycode eq "NY")
{
foreach $key (sort keys %$hashReference)
{
print MAIL "To: jsmith\@hotmail.com\n";
print MAIL "From: Operations\@tools.com\n";
print MAIL "Subject: ";
print MAIL "Information Request\n\n";
print MAIL "Here is the message\n");
}
close (MAIL);
}
if ($my_citycode eq "LA")
{
foreach $key (sort keys %$hashReference)
{
print MAIL "To: ldoe\@hotmail.com\n";
print MAIL "From: Operations\@tools.com\n";
print MAIL "Subject: ";
print MAIL "Information Request\n\n";
print MAIL "Here is the message\n");
}
close (MAIL);
}
}
sub check_citycode
{
my ($hashReference) = @_;
my $citycode = "";
foreach $key (sort keys %$hashReference)
{
if ($key eq "CityCode" && ($$hashReference{$key} eq "NY"))
{
$citycode = 'NY';
}
if ($key eq "CityCode" && ($$hashReference{$key} eq "LA"))
{
$citycode = 'MOPS';
}
}
}
------------------------------
Date: Sat, 27 Dec 2003 08:26:53 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Problem with email
Message-Id: <bsjcd4$di00j$1@ID-184292.news.uni-berlin.de>
Ning li wrote:
> The problem is, I always get the message of "No recipient addresses
> found in the header", though I know I put the addresses in the perl
> script.
Nobody here is able to help you based on the information you posted.
Besides, the script seems to be very old, and the question is if
someone would be willing to assist even if you provided the relevant
info.
I'd suggest that you ask the script author for help.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 27 Dec 2003 12:14:01 -0000
From: "Ragnar Hafsta" <gnari@simnet.is>
Subject: Re: Problem with email
Message-Id: <bsjt31$ibu$1@news.simnet.is>
"Ning li" <ningli2000@worldnet.att.net> wrote in message
news:ZF9Hb.245368$Ec1.8548393@bgtnsc05-news.ops.worldnet.att.net...
snipped problem and most of a script that can't possibly work
> $my_citycode = check_citycode();
>
> ...
> sub check_citycode
> {
> my ($hashReference) = @_;
now what is the value of $hashReference?
gnari
------------------------------
Date: Sat, 27 Dec 2003 11:11:24 +0530
From: "Madhur" <a_madhur@vsnl.net>
Subject: Re: why this code shots up memory usage
Message-Id: <bsj6bo$ddbkv$1@ID-81175.news.uni-berlin.de>
Thank you very much!
--
Winners dont do different things, they do things differently.
Madhur Ahuja
India
email : madhur<underscore>ahuja<at>yahoo<dot>com
Jay Tilton <tiltonj@erols.com> wrote in message
news:3fec749d.574770708@news.erols.com...
> "Madhur" <a_madhur@vsnl.net> wrote:
> : Jay Tilton <tiltonj@erols.com> wrote in message
> : news:3feb17a4.485419583@news.erols.com...
>
> : > while ( <MYFILE> ) {
> : > s/^\d+://;
> : > print;
> : > }
> : > close MYFILE;
> :
> : Could you please explain me,this. what does while(<MYFILE>)
> : means.
>
> This is explained in the "I/O Operators" subsection of perlop.
The
> "while(<MYFILE>) { ... }" construct reads single records from
the MYFILE
> filehandle into the $_ scalar until all records have been read.
>
> : One more think, this is the code from the faq:
> : Stringification also destroys arrays.
> :
> : @lines = `command`;
> : print "@lines"; # WRONG - extra blanks
> : print @lines; # right
> :
> : Does it mean that value of @lines is changed.
>
> No. Stringification does not change the array in any way. It
does change
> the arguments given to a function, operator, or subroutine.
For example:
>
> foo( "@array" );
>
> is equivalently written as:
>
> foo( join($", @array) );
>
> That passes a single string to the foo() subroutine. It is
very different
> from:
>
> foo( @array )
>
> which will pass a list containing the individual values from
@array to the
> foo() subroutine.
>
> : Will the @lines contain now 2 elements 'command' and ' '.
>
> No, but you misunderstand what the statement "@lines =
`command`;" does.
> The backticks are not normal quotes. They invoke an external
command and
> capture its output. See " qx/STRING/ " in the "Quote and
Quote-like
> Operators" subsection of perlop.
>
------------------------------
Date: Sun, 28 Dec 2003 10:08:35 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: why this code shots up memory usage
Message-Id: <i0lruv40qd52dvf1057d567894mus8bak9@4ax.com>
On Fri, 26 Dec 2003 10:45:08 +0530, "Madhur" <a_madhur@vsnl.net>
wrote:
>> 1. Using global variables $i and @input instead of lexically
>> declaring them with my().
>
>The code was part of main program rather than a procedure. Can i
>use *my* in the main code?
You *can* and, most importantly, you *should*. Wether the code is part
of a "procedure" or not is not relevant!
>> 2. Useless use of quotes in the print() statement. See "What's
>> wrong with always quoting ``$vars''? " in perlfaq4.
>
>Indeed I agree, I won't never use them in future.
"You will never" or "you won't ever"...
;-)
>> while ( <MYFILE> ) {
>> s/^\d+://;
>> print;
>> }
>> close MYFILE;
>>
>Could you please explain me,this. what does while(<MYFILE>)
>means.
You knew what @input=<MYFILE> means, now this is just about the same
thing apart that it is evaluated in scalar context and C<while> adds
some magic! But then, better than I could ever explain you, 'perldoc
perlop' does: search for "I/O Operators"!
>One more think, this is the code from the faq:
>Stringification also destroys arrays.
>
> @lines = `command`;
> print "@lines"; # WRONG - extra blanks
> print @lines; # right
>
>Does it mean that value of @lines is changed. Will the @lines
>contain now 2 elements 'command' and ' '.
No and no.
Just try yourself (and do not bother with backticks!):
perl -le '@a=qw/a b c/; print "@a"; print @a;'
Michele
--
# This prints: Just another Perl hacker,
seek DATA,15,0 and print q... <DATA>;
__END__
------------------------------
Date: Sat, 27 Dec 2003 20:12:35 +0530
From: "Madhur" <a_madhur@vsnl.net>
Subject: Re: why this code shots up memory usage
Message-Id: <bsk5oe$dtrf3$1@ID-81175.news.uni-berlin.de>
Thanks!
Another thing, I have seen this type of code:
for (@result){ print;}
for my $i(@result) {....}
As far as I know, for loop requires 3 arguments, and even if one
argument is given, the 2 semicolons must be there.
I have checked my book and the perl docs but haven't found the
reference about this.
--
Winners dont do different things, they do things differently.
Madhur
India
email : madhur<underscore>ahuja<at>yahoo<dot>com
Michele Dondi <bik.mido@tiscalinet.it> wrote in message
news:i0lruv40qd52dvf1057d567894mus8bak9@4ax.com...
> On Fri, 26 Dec 2003 10:45:08 +0530, "Madhur"
<a_madhur@vsnl.net>
> wrote:
>
> >> 1. Using global variables $i and @input instead of lexically
> >> declaring them with my().
> >
> >The code was part of main program rather than a procedure. Can
i
> >use *my* in the main code?
>
> You *can* and, most importantly, you *should*. Wether the code
is part
> of a "procedure" or not is not relevant!
>
> >> 2. Useless use of quotes in the print() statement. See
"What's
> >> wrong with always quoting ``$vars''? " in perlfaq4.
> >
> >Indeed I agree, I won't never use them in future.
>
> "You will never" or "you won't ever"...
> ;-)
>
> >> while ( <MYFILE> ) {
> >> s/^\d+://;
> >> print;
> >> }
> >> close MYFILE;
> >>
> >Could you please explain me,this. what does while(<MYFILE>)
> >means.
>
> You knew what @input=<MYFILE> means, now this is just about the
same
> thing apart that it is evaluated in scalar context and C<while>
adds
> some magic! But then, better than I could ever explain you,
'perldoc
> perlop' does: search for "I/O Operators"!
>
> >One more think, this is the code from the faq:
> >Stringification also destroys arrays.
> >
> > @lines = `command`;
> > print "@lines"; # WRONG - extra blanks
> > print @lines; # right
> >
> >Does it mean that value of @lines is changed. Will the @lines
> >contain now 2 elements 'command' and ' '.
>
> No and no.
>
> Just try yourself (and do not bother with backticks!):
>
> perl -le '@a=qw/a b c/; print "@a"; print @a;'
>
>
> Michele
> --
> # This prints: Just another Perl hacker,
> seek DATA,15,0 and print q... <DATA>;
> __END__
------------------------------
Date: Sat, 27 Dec 2003 14:48:33 -0000
From: "Ragnar Hafsta" <gnari@simnet.is>
Subject: Re: why this code shots up memory usage
Message-Id: <bsk64o$ilo$1@news.simnet.is>
"Madhur" <a_madhur@vsnl.net> wrote in message
news:bsk5oe$dtrf3$1@ID-81175.news.uni-berlin.de...
> Thanks!
> Another thing, I have seen this type of code:
> for (@result){ print;}
> for my $i(@result) {....}
>
> As far as I know, for loop requires 3 arguments, and even if one
> argument is given, the 2 semicolons must be there.
> I have checked my book and the perl docs but haven't found the
> reference about this.
these are called foreach loops
perldoc perlsyn
gnari
------------------------------
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 5983
***************************************