[11489] in Perl-Users-Digest
Perl-Users Digest, Issue: 5089 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 8 18:07:20 1999
Date: Mon, 8 Mar 99 15:00:22 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 8 Mar 1999 Volume: 8 Number: 5089
Today's topics:
best way to process the file bing-du@tamu.edu
Re: best way to process the file <jglascoe@giss.nasa.gov>
Compiling Perl under Unix -help! <mikej@1185design.com>
Re: Compiling Perl under Unix -help! <dimitrio@fantom.com>
Re: constant in Perl? (Mark-Jason Dominus)
Re: constant in Perl? <yfang@gte.com>
Re: constant in Perl? (Greg Bacon)
Re: constant in Perl? (Bart Lateur)
Re: constant in Perl? <stampes@xilinx.com>
Embedding Perl in multithreaded programs <NOSPAMmikenelatiapetuscom@NOSPAM.ORG>
FAQ 3.6: How do I cross-reference my Perl programs? <perlfaq-suggestions@perl.com>
Re: Finding comments in a file using regular expression (Damian Conway)
getting mime type <marco@binz.cx>
Re: getting mime type <ebohlman@netcom.com>
Re: HELP: Is there a way of flushing the print buffer? <aqumsieh@matrox.com>
Hex character is causing script to exit <davem@nortak.com>
Re: Hex character is causing script to exit <jdf@pobox.com>
Re: make and perl500502 <scotth@sgi.com>
Re: Nonscalar Array Access? <aqumsieh@matrox.com>
Re: open() sing Perl for Win32 <cpierce1@ford.com>
Re: Perl Editors for WinNT? <nospam@hotmail.com>
Perl Thread Tutorials/Examples?? <wells@cedarnet.org>
Persistent Storage of Closures terry@eecs.tulane.edu
Re: POST bug in latest LWP/libwww <jbattikha@highsynth.com>
Re: q// vs. '' (Jari Aalto+mail.perl)
Re: q// vs. '' <jdf@pobox.com>
Re: s/\n\s// don't work (Mark-Jason Dominus)
Re: s/\n\s// don't work <mane@interscape.de>
split? bing-du@tamu.edu
Re: split? <dimitrio@fantom.com>
Re: split? <jglascoe@giss.nasa.gov>
Re: split? <jeromeo@atrieva.com>
Re: split? <jeromeo@atrieva.com>
Re: web browser in Perl? <andrewf@beausys.demon.co.uk>
Win32 ODBC and Topspeed (Eric Smith)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 08 Mar 1999 20:06:41 GMT
From: bing-du@tamu.edu
Subject: best way to process the file
Message-Id: <7c1ak9$lhp$1@nnrp1.dejanews.com>
Hello there,
Scenario
=========
There is a file in this format:
1:value1
2:value2
4:value4
---------------
2:value2
4:value4
5:value5
---------------
next record...
Two records are seperated from each other by a dash line. I need read this
file and process the record one by one.
Question
==========
1. What's the best way to accomplish this?
2. How to put a file's content in an array? Can I do @array = <INPUT>?
Any idea and suggestion will be greatly appreciated.
Bing
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Mon, 08 Mar 1999 16:38:22 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: bing-du@tamu.edu
Subject: Re: best way to process the file
Message-Id: <36E4434E.AAD3AB31@giss.nasa.gov>
[courtesy copy of post sent to cited author]
bing-du@tamu.edu wrote:
>
> Hello there,
>
> Scenario
> =========
>
> There is a file in this format:
>
> 1:value1
> 2:value2
> 4:value4
> ---------------
> 2:value2
> 4:value4
> 5:value5
> ---------------
> next record...
>
> Two records are seperated from each other by a dash line. I need read this
> file and process the record one by one.
if the dashed lines are always "---------------\n",
then you can set the input record separator:
$/ = "---------------\n";
my @records = <FH>;
@records = map { [grep /[^-]/, split "\n"] } @records;
That should work the same as, say:
my @records = ();
until (eof FH) {
my @lines = ();
while (<FH>) {
last if /^-+$/;
chomp;
push @lines, $_;
}
push @records, \@lines;
}
> Question
> ==========
>
> 1. What's the best way to accomplish this?
TMTOWDI
> 2. How to put a file's content in an array? Can I do @array = <INPUT>?
yes, that will split the input up according to
what's in the "$/" variable (usually "\n").
>
> Any idea and suggestion will be greatly appreciated.
>
> Bing
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
Jay Glascoe
--
"It's okay to grow up--just as long as you
don't grow old. Face it... you are young."
--Pulp
------------------------------
Date: Mon, 08 Mar 1999 12:23:00 -0800
From: mikej <mikej@1185design.com>
Subject: Compiling Perl under Unix -help!
Message-Id: <36E431A4.2B97EB96@1185design.com>
Hi,
Im trying to install Perl 5.005 on our Solaris server, and I downloaded
the whole package from CPAN. Im now trying to complile it. Basically it
gives me these instructions:
rm -f config.sh Policy.sh
sh Configure
make
make test
make install
After I do the sh Configure command, it thinks for a second, presumably
sets it up with all default options. Then I do the "make" command and
this is where I get stuck. It gives me this message:
make: Fatal error: No arguments to build
when I try to give it an argument like "make test"
it gives me another error message:
make: Fatal error: Don't know how to make target `test'
Does anyone know what Im doing wrong here? I gotta get Perl running
again.
-mike
------------------------------
Date: Mon, 08 Mar 1999 22:42:59 GMT
From: Dimitri <dimitrio@fantom.com>
Subject: Re: Compiling Perl under Unix -help!
Message-Id: <TnYE2.20$g92.65@198.235.216.4>
mikej <mikej@1185design.com> wrote in <36E431A4.2B97EB96@1185design.com>:
>
Why don't you download Solaris binary from CPAN?
Dimitri Ostapenko
Fantom Technologies Inc.
------------------------------
Date: 8 Mar 1999 15:29:41 -0500
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: constant in Perl?
Message-Id: <7c1bvl$6k4$1@monet.op.net>
In article <36E3F9EA.4E4BDCD7@gte.com>, Yu Fang <yfang@gte.com> wrote:
>I want to define a constant in Perl.
The simplest way is:
sub PI () { 3 }
Then you can write:
$circumference = 2 * $radius * PI;
for example.
You can also say
use constant PI => 3;
which is just syntactic sugar for the `sub' definition.
Another approach is illustrated by my `Locked' module aet
http://www.plover.com/~mjd/perl/Locked/
You say
new Locked PI => 3;
and it creates a scalar variable $PI with the value 3; however, an
attempt to change the value of $PI will abort the program:
Attempt to modify locked variable $main::PI at...
The possible advantage here is that you are allowed to change $PI if
you explicitly unlock it first:
Unlock $PI;
$PI = 22/7; # This will not abort the program
Lock $PI; # Future attempts to modify $PI will fail
------------------------------
Date: Mon, 08 Mar 1999 16:01:13 -0500
From: Yu Fang <yfang@gte.com>
Subject: Re: constant in Perl?
Message-Id: <36E43A99.554D506B@gte.com>
try this --
header.pl:
sub PI () { 3 }
1;
body.pl"
#!/usr/local/bin/perl
require 'header.pl';
print PI, "\n";
It won't work, which means we still can't treat PI as a constant
anywhere we want.
Mark-Jason Dominus wrote:
>
> In article <36E3F9EA.4E4BDCD7@gte.com>, Yu Fang <yfang@gte.com> wrote:
> >I want to define a constant in Perl.
>
> The simplest way is:
>
> sub PI () { 3 }
>
> Then you can write:
>
> $circumference = 2 * $radius * PI;
>
> for example.
>
> You can also say
>
> use constant PI => 3;
>
> which is just syntactic sugar for the `sub' definition.
>
> Another approach is illustrated by my `Locked' module aet
> http://www.plover.com/~mjd/perl/Locked/
>
> You say
>
> new Locked PI => 3;
>
> and it creates a scalar variable $PI with the value 3; however, an
> attempt to change the value of $PI will abort the program:
>
> Attempt to modify locked variable $main::PI at...
>
> The possible advantage here is that you are allowed to change $PI if
> you explicitly unlock it first:
>
> Unlock $PI;
> $PI = 22/7; # This will not abort the program
> Lock $PI; # Future attempts to modify $PI will fail
--
Frank Yu Fang
GTE Internetworking
40 Sylvan Road
Waltham, MA 02451-1128
Phone: 781-466-3351
Fax: 781-466-2650
Pager: 1-800-759-8888 PIN# 1619895 or 1619895@skytel.com
------------------------------
Date: 8 Mar 1999 22:37:00 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: constant in Perl?
Message-Id: <7c1jec$40m$1@info2.uah.edu>
In article <36E43A99.554D506B@gte.com>,
Yu Fang <yfang@gte.com> writes:
: #!/usr/local/bin/perl
: require 'header.pl';
:
: print PI, "\n";
:
: It won't work, which means we still can't treat PI as a constant
: anywhere we want.
Sure you can. Make your header a module and, from it, import whatever
symbols you'd like to be able to see. See the perlmod and Exporter
manpages for the lowdown.
Greg
--
As I stood before the gates I realized that I never want to be as certain
about anything as were the people who built this place.
-- Rabbi Sheila Peltz, on her visit to Auschwitz
------------------------------
Date: Mon, 08 Mar 1999 22:55:06 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: constant in Perl?
Message-Id: <36e452ce.11791189@news.skynet.be>
Yu Fang wrote:
> use constant CONSTANT => 1;
> 1;
>
>body.pl:
> require 'header.pl';
> $const = CONSTANT; # will fail
>
>The second way forbids the constants be accessed by including files. The
>format is cute, though.
>
>Is there a way around?
Hmmm.. Actually, I know of two.
A: Indicate that CONSTANT is a function. Always, every time. Any these
will work:
$const = CONSTANT();
$const = &CONSTANT;
sub CONSTANT ();
$const = CONSTANT;
although this last one will give an (incorrect) warning about "ambiguous
use" for CONSTANT in the sub declaration.
B: make clear that CONSTANT is a sub at compile time. Either put the
"require 'header.pl'" in a BEGIN block, or change the filename to
"Header.pm", and do "use Header".
BEGIN {
require 'header.pl';
}
$const = CONSTANT;
print $const;
or
use Header; # 'Header.pm'
$const = CONSTANT;
print $const;
Bart.
------------------------------
Date: 8 Mar 1999 21:31:02 GMT
From: Jeff Stampes <stampes@xilinx.com>
Subject: Re: constant in Perl?
Message-Id: <7c1fim$7p1@courier.xilinx.com>
Yu Fang <yfang@gte.com> wrote:
: try this --
: header.pl:
: sub PI () { 3 }
: 1;
: body.pl"
: #!/usr/local/bin/perl
: require 'header.pl';
: print PI, "\n";
: It won't work, which means we still can't treat PI as a constant
: anywhere we want.
but it works if you change it to:
print PI(), "\n";
-Jeff
--
Jeff Stampes -- Xilinx, Inc. -- Boulder, CO -- jeff.stampes@xilinx.com
------------------------------
Date: Mon, 8 Mar 1999 15:54:51 -0500
From: "Michael Nelson" <NOSPAMmikenelatiapetuscom@NOSPAM.ORG>
Subject: Embedding Perl in multithreaded programs
Message-Id: <7c1deo$sl2$1@oak.prod.itd.earthlink.net>
I am interested in embedding Perl on Win32 inside of a multithreaded program
where more than one interpreter could be running at the same time. I've got
the embedding part down, but I am having trouble figuring out how to
compile/configure Perl so that multiple interpreters can run simultaneously.
I've tried using -DMULTIPICITY -DUSE_THREADS, but things crash with more
than 1 thread. I've also tried -DPERL_OBJECT to (hopefully) encapsulate
everything, but XS's and the win32.c+win32sck.c files depend on the global
CPerlObj *pPerl.
Is this even possible? If so, does anyone have any tips or examples on how
to do this?
thx,
-mike
------------------------------
Date: 8 Mar 1999 14:43:32 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 3.6: How do I cross-reference my Perl programs?
Message-Id: <36e44484@csnews>
(This excerpt from perlfaq3 - Programming Tools
($Revision: 1.33 $, $Date: 1998/12/29 20:12:12 $)
part of the standard set of documentation included with every
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq3.html
if your negligent system adminstrator has been remiss in his duties.)
How do I cross-reference my Perl programs?
The B::Xref module, shipped with the new, alpha-release Perl
compiler (not the general distribution prior to the 5.005
release), can be used to generate cross-reference reports for
Perl programs.
perl -MO=Xref[,OPTIONS] scriptname.plx
--
"I'm sorry, but you just made me lose my sense of humor, which is deeply
regrettable." --Larry Wall
------------------------------
Date: 8 Mar 1999 21:10:39 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: Finding comments in a file using regular expressions
Message-Id: <7c1ecf$ai1$1@towncrier.cc.monash.edu.au>
mjtg@cus.cam.ac.uk (M.J.T. Guy) writes:
>Damian Conway <damian@cs.monash.edu.au> wrote:
>>
>>You probably wanted:
>>
>> /^\s*[^\#]$/)
>> ^
>> |
>I very much doubt that. That would only match # at the end of the
>line.
D'up! That'll teach me to post at 6am :-)
BTW, if the users task is to extract comments from a Perl program
then no regex is ever going to be sufficiently sophisticated (well,
maybe one of Ilya's experimental mutant ninja regexes would be :-)
If you're dealing with Perl, you're going to have to cope with:
#'s that signify the last index of an array (i.e. $#array)
literal #'s that appear in regexes and strings
#'s that appear as (?#...) regex comments
#'s that signify comments in a /g regex
The first two are also issues in shell scripts.
If these *are* relevant to the application, you might need to look at
the Text::Balanced module (on the CPAN), which can cope with all of
these special cases.
Damian
------------------------------
Date: Mon, 08 Mar 1999 23:08:53 +0100
From: Marco Binz <marco@binz.cx>
Subject: getting mime type
Message-Id: <36E44A74.329D0535@binz.cx>
Hi Gurus!
I tried to get the mime type with head($url) and used the following
code:
use LWP::Simple;
print head("http://www.binz.cx");
It printed "text/html1171916933317Apache/1.2.6 SolNet". So far so good,
but if I try the following
use LWP::Simple;
my $head=head("http://www.binz.cx");
print $head;
I get "HTTP::Response=HASH(0xc0ccc8)". What did I do wrong? Or does
anyone know another (easier/better) way to get the mime type?
cheers
Marco
------------------------------
Date: Mon, 8 Mar 1999 22:33:43 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: getting mime type
Message-Id: <ebohlmanF8As07.HC5@netcom.com>
Marco Binz <marco@binz.cx> wrote:
: I tried to get the mime type with head($url) and used the following
: code:
: use LWP::Simple;
: print head("http://www.binz.cx");
: It printed "text/html1171916933317Apache/1.2.6 SolNet". So far so good,
: but if I try the following
: use LWP::Simple;
: my $head=head("http://www.binz.cx");
: print $head;
: I get "HTTP::Response=HASH(0xc0ccc8)". What did I do wrong? Or does
: anyone know another (easier/better) way to get the mime type?
The difference is that in your first case you're calling head() in list
context, where it returns a list of various goodies, but in your second
case you're calling it in scalar context, where it returns 0 if the
request failed and a nonzero value (which, due to implementation details,
turns out to be a reference to a hash that it uses internally) if the
request succeeded. Re-read the documentation to find out which list
value is the one you need.
------------------------------
Date: Mon, 08 Mar 1999 22:29:02 GMT
From: @l@ <aqumsieh@matrox.com>
Subject: Re: HELP: Is there a way of flushing the print buffer?
Message-Id: <7c1iv2$tc8$1@nnrp1.dejanews.com>
In article <Pine.SOL.3.96.990305193930.12596P-100000@dropzone.tamu.edu>,
Sanjay Joshi <joshi@dropzone.tamu.edu> wrote:
> Periods are printed only if there is a newline
> character "\n". I want all the periods to be printed in the same line. Hos
> is this done?
By reading the fine FAQs.
Checkout the very first question in perlfaq5:
How do I flush/unbuffer a filehandle? Why must I do this?
--Ala
$monger->{montreal}->[0];
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Mon, 8 Mar 1999 16:17:00 -0500
From: "Dave McIntyre" <davem@nortak.com>
Subject: Hex character is causing script to exit
Message-Id: <7c1ere$kv7$1@demon.uunet.ca>
Can someone help me with this please?
I have an ASCII file that contains several instances of
the hex chars x1a and x18 (LINC COBOL highlight commands).
While parsing the file, when we hit one of those chars, the
script just exits, period.
I've tried searching for the char with this:
if (/\x1A|\x18/) {..}
and its control equivalent
if (/\cZ|\cR/) {..}
to no avail, because those expressions don't even
get evaluated. Stepping thru it with the debugger
shows that the it assumes EOF when it hits the char,
so while (<FILE>) fails and therefore we can't do
any testing.
Any advice on how I can stop the script from exiting
when it hits x1A or x18 will be greatly appreciated.
Dave McIntyre
------------------------------
Date: 08 Mar 1999 16:35:57 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: "Dave McIntyre" <davem@nortak.com>
Subject: Re: Hex character is causing script to exit
Message-Id: <m34snvwtoi.fsf@joshua.panix.com>
"Dave McIntyre" <davem@nortak.com> writes:
> Any advice on how I can stop the script from exiting
> when it hits x1A or x18 will be greatly appreciated.
perldoc binmode
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: 08 Mar 1999 14:18:43 -0800
From: Scott Henry <scotth@sgi.com>
Subject: Re: make and perl500502
Message-Id: <yd8aexnfwvw.fsf@hoshi.engr.sgi.com>
>>>>> "R" == Richard Robinson <richardr@ldr.com> writes:
R> I'm having problems making perl on IRIX 6.5.
R> I configured as follows: sh Configure -Dcc=gcc.
R> Then I accepted all the defaults except that when Configure asked me to
R> use nm -- I answered y for yes (instead of n for no, which was default).
R> This gave me a config.sh that had "undef" for libc.
Just a note as to the probable cause: the hints for gcc when
building perl5 (all recent versions) are almost certainly configured
for gcc 2.7.*, which builds -32. Nobody has fixed the hints file to
support gcc 2.8.*, which builds -n32 (and -64).
--
Scott Henry <scotth@sgi.com> / Help! My disclaimer is missing!
IRIX MTS, / GIGO *really* means: Garbage in, Gospel Out
Silicon Graphics, Inc / http://reality.sgi.com/scotth/
------------------------------
Date: Mon, 08 Mar 1999 22:37:49 GMT
From: @l@ <aqumsieh@matrox.com>
Subject: Re: Nonscalar Array Access?
Message-Id: <7c1jfs$tpt$1@nnrp1.dejanews.com>
In article <36E11B8C.25D5C728@technologist.com>,
Brent Michalski <perlguy@technologist.com> wrote:
> print @array_name[2];
>
> This *seemed* to work the exact same as:
> print $array_name[2];
The two are different. In this case they just happen to cause the same effect.
> I was just wondering if this _always_ works or not? Also, WHY does this
> work.
Actually, there is a difference in the context between the two.
$array[2] is a scalar. It is the third element in @array.
@array[2] is an array slice. It is an array with one element, $array[2].
--Ala
$monger->{montreal}->[0];
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Mon, 08 Mar 1999 15:05:28 -0500
From: Clinton Pierce <cpierce1@ford.com>
To: mmueller007@hotmail.com
Subject: Re: open() sing Perl for Win32
Message-Id: <36E42D88.CD9C3AAC@ford.com>
[poster CC'd in E-Mail]
mmueller007@hotmail.com wrote:
>
> I'm working on a little cgi-program (I'm using Perl for Win32) that is
> supposed to open a file, but there seems to be a problem with the
> open-command:
>
> open($PRICE_FILE, "<sys2.txt");
Whenever you open a file, _ALWAYS_ check the exit status of open. Really.
Go fix it now. Shoo. This is important, it will keep you from making Big
Mistakes later.
open(PRICE_FILE, "<sys2.txt") || die "sys2.txt: $!\n";
BTW: the $ is probably your problem. You probably don't really want that.
--
Clinton A. Pierce "If you rush a Miracle Man, you get rotten
clintp@geeksalad.org Miracles." -- Miracle Max, The Princess Bride
http://www.geeksalad.org
------------------------------
Date: Mon, 08 Mar 1999 16:43:40 -0500
From: MicroChip <nospam@hotmail.com>
Subject: Re: Perl Editors for WinNT?
Message-Id: <36E4448C.49AD@hotmail.com>
Ive used textpad as my general purpose editor, including perl and html,
for several years and have had no complaints at all.
MC
Steve Lush wrote:
>
> Is this something specific for NT? Because I've been using UltraEdit and
> EditPad (it's a bit smaller) for some time with no problems and nothing but
> praise.
>
> Scratchie wrote:
>
> > Robert Burris <null@127.0.0.1> wrote:
> > : http://www.textpad.com/
> >
> > What he said. I'm almost starting to like this editor better than BBEdit.
> >
> > --Art
> >
> > --
> > --------------------------------------------------------------------------
> > National Ska & Reggae Calendar
> > http://www.agitators.com/calendar/
> > --------------------------------------------------------------------------
------------------------------
Date: Mon, 08 Mar 1999 22:37:38 +0000
From: Steve Wells <wells@cedarnet.org>
Subject: Perl Thread Tutorials/Examples??
Message-Id: <36E45132.2E24F156@cedarnet.org>
Can anyone direct me to a FAQ, Tutorial or more Examples concerning
perl threads? I have looked in the usual places and checked out the
tests that come with the modules but I need a little more.
TIA -
STEVE
--
-----------
Stephen D. Wells
http://www.iren.net/wellss/
------------------------------
Date: Mon, 08 Mar 1999 22:28:59 GMT
From: terry@eecs.tulane.edu
Subject: Persistent Storage of Closures
Message-Id: <7c1iuv$tc6$1@nnrp1.dejanews.com>
Does anyone know of a way to persistently store closures (e.g. store closures
in a database)?
I've been using MLDBM (with DB_File and Storable | Data::Dumper | FreezeThaw)
but it does not know how to store code refs so that when you retrieve the code
ref from the database at a later date you can invoke the code ref.
Thanks,
Nicole
Nicole Deflaux Terry
Department of EECS
Tulane University
http://www.eecs.tulane.edu/Terry
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Mon, 08 Mar 1999 17:32:39 -0500
From: Jihad Battikha <jbattikha@highsynth.com>
Subject: Re: POST bug in latest LWP/libwww
Message-Id: <36E45007.99628531@highsynth.com>
brian d foy asked:
> what is the smallest bit of code that you can write to
> reproduce the problem?
#!/usr/bin/perl -w
use LWP::UserAgent;
# use LWP::Debug qw(+ -conns); # debug
use HTTP::Cookies;
$ua = new LWP::UserAgent;
$jar = HTTP::Cookies->new;
# to pre-fetch initial cookie ID for subsequent requests
$getrequest = new HTTP::Request(GET, 'http://www.reel.com/');
$getresponse = $ua->request($getrequest);
$jar->extract_cookies($getresponse);
if ($getresponse->is_success) {
&post('http://www.reel.com/cgi-bin/search/nph-movie.exe',
'TYPE=ACTOR&Go=Go&STRING=Tom%20Cruise');
} else {
$result = "\nGET error for $host\n";
}
print $result;
sub post {
my ($url, $encoded) = @_;
my $request = new HTTP::Request(POST, $url);
$request->content_type('application/x-www-form-urlencoded');
$request->content($encoded);
$jar->add_cookie_header($request);
my $response = $ua->request($request); # <- problem here after 2nd
redirect
$jar->extract_cookies($response);
if ($response->is_redirect) { # fails to get all headers in 2nd
redirect
$redir++;
my $location = $response->header("Location");
if ($redir < 10) {
&post($location);
} else {
$result = "\nToo many redirects for $url\n";
}
undef $redir;
} elsif ($response->is_success) { # never gets here
$result = $response->content;
} else {
$result = "\nPOST error for $url\n";
}
}
--
<>>===============================================================<<>
Jihad Battikha <jbattikha@highsynth.com> http://www.highsynth.com
-=< graphics . 2d/3d animation . illustration . web authoring >=-
<>>===============================================================<<>
Before sending me commercial e-mail, the sender must first agree
to my LEGAL NOTICE located at: http://www.highsynth.com/sig.html.
<>>===============================================================<<>
------------------------------
Date: 08 Mar 1999 22:36:50 +0200
From: jari.aalto@poboxes.com (Jari Aalto+mail.perl)
Subject: Re: q// vs. ''
Message-Id: <ptr3e3f67ml.fsf@sinivuokko.i-have-a-misconfigured-system-so-shoot-me>
tadmc@metronet.com (Tad McClellan) writes:
>
> Michael Balenger (MBalenger@worldnet.att.net) wrote:
> : My vote for qw() instead of ""
>
> : I use qw a lot to prevent me from having to put double quotes around my
> ^^^^^^^^^^^^^
> : words and commas between them.
>
>
> You should be using single quotes for those, unless they are
> variables that you want interpolated, or if they contain
> backslash escapes.
>
> You should not ask for variable/backslash escape interpolation
> unless you _need_ it. (when you use double quotes, you are
> asking for those things)
So, perl always Extrapolates if there is double quotes, regardless of the
content inside the string? (could it peek existence of $ ...)
@a = ( "a" , "abc" "def-ghi" );
is more efficient than?
@a = ( 'a' , 'abc', 'def-ghi' );
Wow. Can anyone explain the benchmark results? the qq and q operators
seem to be advantageou.
jari
control: 5 secs ( 4.61 usr 0.00 sys = 4.61 cpu)
double_qq: 9 secs (10.24 usr 0.02 sys = 10.26 cpu)
single_q: 10 secs (10.25 usr 0.01 sys = 10.26 cpu)
single: 15 secs (15.81 usr 0.02 sys = 15.83 cpu)
double: 17 secs (15.80 usr 0.04 sys = 15.84 cpu)
use Benchmark;
timethese 500_000,
{
control => sub { },
double => sub
{
my @a = ( "a" , "abc", "defghi" );
},
single => sub
{
my @a = ( 'a' , 'abc', 'defghi' );
},
double_qq => sub
{
my @a = qq( a abc defghi );
},
single_q => sub
{
my @a = q( a abc defghi );
}
};
------------------------------
Date: 08 Mar 1999 15:47:01 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: jari.aalto@poboxes.com (Jari Aalto+mail.perl)
Subject: Re: q// vs. ''
Message-Id: <m3aexnwvy2.fsf@joshua.panix.com>
jari.aalto@poboxes.com (Jari Aalto+mail.perl) writes:
> double => sub
> {
> my @a = ( "a" , "abc", "defghi" );
> },
> single => sub
> {
> my @a = ( 'a' , 'abc', 'defghi' );
> },
> double_qq => sub
> {
> my @a = qq( a abc defghi );
> },
> single_q => sub
> {
> my @a = q( a abc defghi );
> }
You're comparing unlike things. The first two subs build a list of
three values on the RHS, then assign that list to @a. The second two
subs build a list of one value before assigning it to @a. Perhaps you
meant to benchmark qw// ? Or perhaps you meant
my @a = (q(a), q(abc), q(defghi));
?
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: 8 Mar 1999 16:12:00 -0500
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: s/\n\s// don't work
Message-Id: <7c1ef0$6vu$1@monet.op.net>
In article <36E4267D.33B7611E@interscape.de>,
Manfred Brunner <mane@interscape.de> wrote:
>I tried a lot like the following few samples:
>
>while (<STDIN>) {
> s/\n\s//g;
> print $_;
>}
<STDIN> reads only one line at a time. Each line ends with a \n
character. That means that there is nothing in $_ after the \n
character, so the pattern does not match.
If you want to operate on the entire STDIN as a single string instead
of as a series of lines, you must do it this way:
{ local $/ = undef;
$_ = <STDIN>; # Read entire input into one string
}
s/\n\s//g;
print $_;
------------------------------
Date: Mon, 08 Mar 1999 23:45:00 +0100
From: Manfred Brunner <mane@interscape.de>
Subject: Re: s/\n\s// don't work
Message-Id: <36E452EC.C6BE0E29@interscape.de>
This is a multi-part message in MIME format.
--------------3B2B39B212D1413C0068A929
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Thank you Jay,
but this dont work in my case.
> Manfred Brunner wrote:
> >
> > I just want to substitute from stdin all newline followed by whitespace
> > beginning in the next line, with nothing.
> >
> > The input looks easy like this:
> > ---
> > Here is the first line
> > the second line starts with one space
> > ---
> >
> > I tried a lot like the following few samples:
> >
> > while (<STDIN>) {
> > s/\n\s//g;
> > print $_;
> > }
> Jay Glascoe wrote:
>
> <snip other code>
>
> hi Manfred,
>
> all of your loops are working on the input
> one line at a time. So, the first time through
> the loop, "$_" is "Here is the first line\n".
> This does not match "/\n\s/". Second time through,
> "$_" is " the second [...] one space\n". This
> line does not match "/\n\s/" either.
Maybe not, because i redirect from stdin a whole textfile which go fully into
"$_" (it seems so) and it realy work through the whole file if i only
substitute spaces or newlines or anything else.
> try this:
>
> while (<STDIN>) { # for every line,
> s/^\s+//g; # remove all leading white space,
> print; # and print the result.
> }
No, that don't work because i have to build the lines together who are broken
through newline an space.
Here is an example how the text looks like. I mark newline and space for
reading.
---
This is text which is broken in this line and the second line\n
[]which start with a space.\n
This line is not broken and i have to keep it as is.\n
This is another line which is broken in a first line\n
[]a second line with preceeding space\n
[]and a third line with preceeding space.\n
---
The above text should finaly look like this
---
This is text which is broken in this line and the second line which start
with a space.\n
This line is not broken and i have to keep it as is.\n
This is another line which is broken in a first line a second line with
preceeding space and a third line with preceeding space.\n
---
> Jay Glascoe
> --
> ping.
It seems there are some other things i have to care about.
Manfred
--------------3B2B39B212D1413C0068A929
Content-Type: text/x-vcard; charset=us-ascii;
name="mane.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Manfred Brunner
Content-Disposition: attachment;
filename="mane.vcf"
begin:vcard
n:Brunner;Manfred
tel;cell:0171 700 4457
tel;fax:+49 8034 9139
tel;work:+49 8034 9138
x-mozilla-html:TRUE
url:http://www.augen.de/ds/dosearch/ds.interscape.de?dn=uid%3Dmane%2Co%3DInterscape%20-%20Professioneller%20Internet%20Service%2Cc%3DDE
org:Professioneller Internet Service
adr:;;Dorfstra_e 13;Nu_dorf;;83131;Germany
version:2.1
email;internet:mane@interscape.de
fn:Manfred Brunner
end:vcard
--------------3B2B39B212D1413C0068A929--
------------------------------
Date: Mon, 08 Mar 1999 21:33:36 GMT
From: bing-du@tamu.edu
Subject: split?
Message-Id: <7c1fnh$qbg$1@nnrp1.dejanews.com>
Hello there,
There is a string $test = "3:http://www.test.edu/building.html".
How to split this string to get two parts. One is "3" and the other is
"http://www.test.edu/building.html"?
I tried the command:
($first, $second) = split(/:/,$test);
Then $first is "3". However $second is just "http" instead of
"http://www.test.edu/building.html" which is what I want.
Any idea? Thanks in advance.
Bing
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Mon, 08 Mar 1999 22:07:26 GMT
From: Dimitri Ostapenko <dimitrio@fantom.com>
Subject: Re: split?
Message-Id: <ySXE2.13$g92.313@198.235.216.4>
bing-du@tamu.edu wrote in <7c1fnh$qbg$1@nnrp1.dejanews.com>:
> Hello there,
>
> There is a string $test = "3:http://www.test.edu/building.html".
>
> How to split this string to get two parts. One is "3" and the other is
> "http://www.test.edu/building.html"?
>
> I tried the command:
>
> ($first, $second) = split(/:/,$test);
>
> Then $first is "3". However $second is just "http" instead of
> "http://www.test.edu/building.html" which is what I want.
>
> Any idea? Thanks in advance.
>
> Bing
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
You split on ":", so why are you surprized? There's 2 of them in your
string.
Use another delimiter between url and the rest. Something unique. If you
want to use ":", concatenate strings, but don't forget that there can be
:<port number> in you url.
Dimitri Ostapenko
Fantom Technologies Inc.
------------------------------
Date: Mon, 08 Mar 1999 17:03:20 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: bing-du@tamu.edu
Subject: Re: split?
Message-Id: <36E44928.F3FBA29E@giss.nasa.gov>
[courtesy copy of post sent to cited author]
bing-du@tamu.edu wrote:
>
> Hello there,
>
> There is a string $test = "3:http://www.test.edu/building.html".
>
> How to split this string to get two parts. One is "3" and the other is
> "http://www.test.edu/building.html"?
>
> I tried the command:
>
> ($first, $second) = split(/:/,$test);
>
> Then $first is "3". However $second is just "http" instead of
> "http://www.test.edu/building.html" which is what I want.
You do realize that's a ':' after "http", don't you?
how about:
($first, @rest) = split /:/, $test;
$second = join '', @rest;
OR
($first, $second) = split /:/, $test, 2;
OR
($first, $second) = ($test =~ /(.*?):(.*)/);
OR
($first, $second) = ($test =~ /([^:]*):(.*)/);
Jay Glascoe
--
"Narf!"
--Pinky
------------------------------
Date: Mon, 08 Mar 1999 14:47:56 -0800
From: Jerome O'Neil <jeromeo@atrieva.com>
Subject: Re: split?
Message-Id: <36E4539C.81665835@atrieva.com>
bing-du@tamu.edu wrote:
> There is a string $test = "3:http://www.test.edu/building.html".
>
> How to split this string to get two parts. One is "3" and the other is
> "http://www.test.edu/building.html"?
>
> I tried the command:
>
> ($first, $second) = split(/:/,$test);
>
> Then $first is "3". However $second is just "http" instead of
> "http://www.test.edu/building.html" which is what I want.
This is expected behavior for the way you are splitting this particular
string. However, there is a way you can use split to do exactly what
you want.
($first, $second) = split /:/, $test, 2;
For all the exciting details on split, and other text munging functions,
read the perlfunc manpage supplied with your instalation of perl.
Good Luck!
--
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947
The Atrieva Service: Safe and Easy Online Backup http://www.atrieva.com
------------------------------
Date: Mon, 08 Mar 1999 14:49:08 -0800
From: Jerome O'Neil <jeromeo@atrieva.com>
Subject: Re: split?
Message-Id: <36E453E4.E204A713@atrieva.com>
Dimitri Ostapenko wrote:
>
> > I tried the command:
> >
> > ($first, $second) = split(/:/,$test);
> Use another delimiter between url and the rest. Something unique. If you
> want to use ":", concatenate strings, but don't forget that there can be
> :<port number> in you url.
There can also be another argument to split. See the docs for more
detail.
--
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947
The Atrieva Service: Safe and Easy Online Backup http://www.atrieva.com
------------------------------
Date: Mon, 8 Mar 1999 21:55:35 +0000
From: Andrew Fry <andrewf@beausys.demon.co.uk>
Subject: Re: web browser in Perl?
Message-Id: <xSTTREAXdE52EwPU@beausys.demon.co.uk>
In article <36E025DC.7C46DB3D@alphacrc.com>, Jason Holland
<graphics@alphacrc.com> writes
>
>
>Peter Bismuti wrote:
>>
>> HI, I had the idea of writing a web browser in Perl.
Wasnt there an example of this in Dr.Dobbs some months back ???
I have the
>> O'Reilly book 'Web Client Programming in Perl' and the 'Perl
Cookbook'
>> which has a chapter on web programming. I'm finding that things
don't
>> work as well as they are supposed to. Modern day web pages have
>> java code and tables and other things that the html parser modules
>> cannot handle.
>>
>> Is writing a browser in Perl realistic as a part-time project for one
>> person? What other cool things could be done in Perl as a project
>> involving the web? If anyone has any ideas it would be appreciated.
>> Also, if you have any code that you could send me to get me started
>> I would be very grateful.
>>
>> Thanks
>
>
>
>
>Hello Peter,
>
>That's pretty ambitious, but like you said there's too much extra stuff
>in web pages these days...
>
>Over the last year or so I've been developing a set of classes for doing
>stuff with HTTP. Mostly traversing web sites, doing word counts and such.
>
>I put all this stuff together, partly because I was learning Perl, and
>partly because I wanted to call it my own work; you know, for experience.
>
>A Perl web browser is not a bad idea though, just think you could
>include Perl code in HTML, what a security risk that would be! The
>graphics interface could be created using PerlTK or one of the other
>interface libraries.
>
>
>Good luck!
>
>
>jason.holland@dial.pipex.com
---
Andrew Fry
"Time flies like an arrow. Fruit flies like a banana". (Groucho Marx).
------------------------------
Date: 8 Mar 1999 22:21:36 GMT
From: eric@fruitcom.com (Eric Smith)
Subject: Win32 ODBC and Topspeed
Message-Id: <slrn7e8kag.ea9.eric@plum.fruitcom.com>
Hi
Anyone have any success connecting to a Topspeed Database with David Roth's
ODBC.
"I am getting Topspeed ODBC Driver not Capable"
and
"Topspeed[ODBC]Table not found"
However I successfully establish a connection between Exel and the Topspeed
Database using the same DSN etc.
Thanx for sharing any experiences with me.
--
Eric Smith
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 5089
**************************************