[10866] in Perl-Users-Digest
Perl-Users Digest, Issue: 4467 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Dec 20 14:07:40 1998
Date: Sun, 20 Dec 98 11:00:24 -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 Sun, 20 Dec 1998 Volume: 8 Number: 4467
Today's topics:
Re: Color Editor (Tuomas Angervuori)
Re: Color Editor <r28629@email.sps.mot.com>
Re: Execute multi commands in one line <rick.delaney@home.com>
Re: How do I catch this eval exception? <due@murray.fordham.edu>
Re: How do I catch this eval exception? (Maurice Aubrey)
Re: How do I catch this eval exception? <due@murray.fordham.edu>
Re: How do I catch this eval exception? <r28629@email.sps.mot.com>
Re: How do I catch this eval exception? (Mark-Jason Dominus)
Re: Is it possible with perl? (Bart Lateur)
Re: Mac, Perl, uploading, help! (Kevin Reid)
Re: Nested sorting (Bill Moseley)
Re: Nested sorting (Ronald J Kimball)
Re: Nested sorting (Larry Rosler)
Re: Passing Multiple Arrays (Kevin Reid)
Re: Quick Substitution Question (Larry Rosler)
regex wack (Jaya_Kanajan)
Re: replacement question <jamesht@idt.net>
Re: replacement question <groans@mailexcite.com>
Re: Script that faxes <jamesht@idt.net>
Re: Splitting a line at |'s (Adam Levy)
Re: Splitting a line at |'s <rick.delaney@home.com>
Re: Splitting a line at |'s (Matthew Bafford)
Re: Splitting a line at |'s <r28629@email.sps.mot.com>
Re: Syntax Error...Not able to find. (Kevin Reid)
Re: Why Is Perl not a Language? (Bart Lateur)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 20 Dec 1998 16:36:19 GMT
From: tumppi@icon.fi (Tuomas Angervuori)
Subject: Re: Color Editor
Message-Id: <Un3NuHgI1diW-pn2-QUBP5m2SgRXN@ameeba.dyn.icon.fi>
On Sun, 20 Dec 1998 14:29:51, "Brad" <roclimb@yahoo.com> wrote:
> I am new to Perl, but not new to programming. I have been writing
> everything in Notepad. I am used to having a color editor for certain
> words in the code of a program e.g. in Visual Studio when you type int it
> changes color and when you type bool or class those change color as
> well....So what I leading up to is.
>
> Is there a color editor like this for Perl? If so could you please give the
> name of it or the url to the page.
>
> If there isn't such a thing I would be interested in hearing what other
> people are using for editors and what they think about them.
I use fte which is freeware. You can download the DOS(?) version at
http://home.icon.fi/~tumppi/ften46b5.zip The official homepage is
located at http://ixtas.fri.uni-lj.si/~markom/fte/ You can download
OS/2, Windows95 and Linux versions from there.
-Tumppi
------------------------------
Date: Sun, 20 Dec 1998 12:03:44 -0500
From: Tk Soh <r28629@email.sps.mot.com>
Subject: Re: Color Editor
Message-Id: <367D2DE4.49E001F0@email.sps.mot.com>
Allan M. Due wrote:
> My favorite Windoze editor is UltraEdit32. Here is what I had to say about
> this last week (and the week before....).
> -----
> Well, I say this all the time but I quite like UltraEdit32. Macros, keyboard
> mapping, column mode, colored syntax, automatic indenting, match braces, view
> html your are editing with your browser from within the editor, regular
> expression searches, hex editing, file size limit 2G, 100,000 word spell
> checker, yada yada yada. Plus it is easy to set up a tool that allows you to
> run perl from within UltraEdit32 and then capture the output to either a list
> box or a new file in the editor. You can also run DOS commands from within
> the editor so you can run perl scripts with command line input. It is
> shareware and times out after 45 days, registration cost: $30.00. For me, it
> is well worth the money. Oh, new feature, it now has it's own FTP capability.
> Just my $.02. www.ultraedit.com
you really should automate these replies ;-)
-TK
------------------------------
Date: Sun, 20 Dec 1998 18:39:55 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Execute multi commands in one line
Message-Id: <367D463D.A1850C05@home.com>
[posted & mailed]
Victor B Wagner wrote:
>
> mbrich@my-dejanews.com wrote:
>
> : cvs status | $ grep 'Status:' | grep -v 'Up-to-date'
> : | awk '{print $2}'
...
>
> open F,"cvs status|";
> while (<F>) {
> if (/Status:/&&!/Up-to-date/) {
> print (split /\s+/)[1];
^^^^^
> }
> }
Splitting on /\s+/ is not the same as what awk does since it will create
a first null field for a string with leading spaces. To get awk's
behaviour, one should use:
split ' ';
perldoc -f split
--
Rick Delaney
rick.delaney@shaw.wave.ca
------------------------------
Date: 20 Dec 1998 16:16:22 GMT
From: "Allan M. Due" <due@murray.fordham.edu>
Subject: Re: How do I catch this eval exception?
Message-Id: <75j7sm$md9$0@206.165.146.38>
Mark-Jason Dominus wrote in message <75j54u$fl1$1@monet.op.net>...
|In article <75j12r$9cm$0@206.165.165.141>,
|Allan M. Due <due@murray.fordham.edu> wrote:
|>$code = qq( use strict; $try = 'foo' );
|
|Could you explain what you were thinking here?
|To me it looks like the answer to an entirely different question.
Here is my thinking, I welcome any and all attempts to disabuse me of
incorrect notions.
At first I thought the answer to his problem was just that he needed to have
my in front of his $try. But then I decided he has trying to trap the
exception (even though he used the word catch).
In this example, the lack of my is a compile-time exception and you can't trap
a compile-time exception in a block. This is a compile-time exception because
"use" is a compile-time event. To catch the compile-time error you need use
eval "$string". eval '$string' would not work for obvious reasons. Anyway,
$code = "use strict; $try = 'foo'"; would have been fine too, I just used qq
becuase he used q. I may well have misunderstood his problem and/or
misunderstood the above but the code works as expected for me.
#!/usr/bin/perl
$code = q(use strict; $try = 'foo');
eval $code; warn "Huston we have a problem : $@" if $@;
produces:
Global symbol "$try" requires explicit package name at (eval 1) line 1.
While
#!/usr/bin/perl
$code = qq(use strict; $try = 'foo');
eval $code; warn "Huston we have a problem : $@" if $@;
produces:
Huston we have a problem : syntax error at (eval 1) line 1, near "; ="
Which is what I thought the author was after.
AmD
------------------------------
Date: Sun, 20 Dec 1998 16:30:25 GMT
From: maurice@hevanet.com (Maurice Aubrey)
Subject: Re: How do I catch this eval exception?
Message-Id: <slrn77q9h3.uq.maurice@we-24-130-58-139.we.mediaone.net>
Hi Allan. Thanks for responding.
On 20 Dec 1998 16:16:22 GMT, Allan M. Due <due@murray.fordham.edu> wrote:
>Mark-Jason Dominus wrote in message <75j54u$fl1$1@monet.op.net>...
>|In article <75j12r$9cm$0@206.165.165.141>,
>|Allan M. Due <due@murray.fordham.edu> wrote:
>|>$code = qq( use strict; $try = 'foo' );
>|
>|Could you explain what you were thinking here?
>|To me it looks like the answer to an entirely different question.
>
>
>Here is my thinking, I welcome any and all attempts to disabuse me of
>incorrect notions.
>
>At first I thought the answer to his problem was just that he needed to have
>my in front of his $try. But then I decided he has trying to trap the
>exception (even though he used the word catch).
>
>In this example, the lack of my is a compile-time exception and you can't trap
>a compile-time exception in a block.
^^^ but it isn't the block form.
> This is a compile-time exception because
>"use" is a compile-time event. To catch the compile-time error you need use
>eval "$string". eval '$string' would not work for obvious reasons. Anyway,
>$code = "use strict; $try = 'foo'"; would have been fine too, I just used qq
>becuase he used q. I may well have misunderstood his problem and/or
>misunderstood the above but the code works as expected for me.
>
>#!/usr/bin/perl
>$code = q(use strict; $try = 'foo');
>eval $code; warn "Huston we have a problem : $@" if $@;
>
>produces:
>Global symbol "$try" requires explicit package name at (eval 1) line 1.
>
>While
>#!/usr/bin/perl
>$code = qq(use strict; $try = 'foo');
>eval $code; warn "Huston we have a problem : $@" if $@;
>
>produces:
>Huston we have a problem : syntax error at (eval 1) line 1, near "; ="
>
>Which is what I thought the author was after.
No, that isn't my problem.
>From my reading of the Camel, it says that the expression form of
eval doesn't get examined until run-time. So it seems like a
compile-time error, using this form of eval, should be trappable.
Am I mistaken?
- Maurice
------------------------------
Date: 20 Dec 1998 17:03:01 GMT
From: "Allan M. Due" <due@murray.fordham.edu>
Subject: Re: How do I catch this eval exception?
Message-Id: <75jak5$rbv$0@206.165.146.38>
Allan M. Due wrote in message <75j7sm$md9$0@206.165.146.38>...
|Mark-Jason Dominus wrote in message <75j54u$fl1$1@monet.op.net>...
||In article <75j12r$9cm$0@206.165.165.141>,
||Allan M. Due <due@murray.fordham.edu> wrote:
||>$code = qq( use strict; $try = 'foo' );
||
||Could you explain what you were thinking here?
||To me it looks like the answer to an entirely different question.
[snip my clearly inaccurate and muddled headed thinking]
Clearly I am confused as I could be. Please excuse me as I crawl back under
my rock where I will weather the anticipated (and much deserved) storm of
abuse.
Sorry to muddle the waters.
AmD
------------------------------
Date: Sun, 20 Dec 1998 12:00:20 -0500
From: Tk Soh <r28629@email.sps.mot.com>
Subject: Re: How do I catch this eval exception?
Message-Id: <367D2D19.AAEA996E@email.sps.mot.com>
Allan M. Due wrote:
[snip]
> #!/usr/bin/perl
> $code = qq(use strict; $try = 'foo');
> eval $code; warn "Huston we have a problem : $@" if $@;
>
> produces:
> Huston we have a problem : syntax error at (eval 1) line 1, near "; ="
you need q() to retain $try in the $code qq() causes the $try to be
interpolated (into nothing), that's how you get the syntax error into $@, as
promised by eval():
If there is a syntax error or runtime error,
or a die() statement is executed, an undefined
value is returned by eval(), and $@ is set to
the error message.
However, assuming q() is used, 'use strict' somehow changes (how?) this
property of eval, and $@ never get the error message, but I still managed the
trap the error by checking the return value of eval():
---------------------------------------------------
#!/usr/bin/perl
$code = q(use strict; print 'xxx'; $try = 'foo');
eval $code or warn 'there is a problem in eval()';
warn "Houston we have a problem : $@" if $@;
Output:
Global symbol "$try" requires explicit package name at (eval 1) line 1.
there is a problem in eval() at trial.pl line 4.
---------------------------------------------------
BTW, the 'GLobal.." message may be surpressed using $SIG{__WARN__} handler.
-TK
------------------------------
Date: 20 Dec 1998 13:43:06 -0500
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: How do I catch this eval exception?
Message-Id: <75jgfq$odg$1@monet.op.net>
In article <slrn77otlo.n3v.maurice@we-24-130-58-139.we.mediaone.net>,
Maurice Aubrey <maurice@hevanet.com> wrote:
>#!/usr/bin/perl
>$code = q( use strict; $try = 'foo' );
>eval $code;
>
>produces:
>Global symbol "$try" requires explicit package name at (eval 1) line 1.
>
>How can I catch that exception?
For some reason, that message is a warning, even though it is
generated in the absence of -w and even though it causes the
compilation to fail. This is probably a bug.
You can catch it with
$SIG{__WARN__} = sub { my $warning = shift; ... }
------------------------------
Date: Sun, 20 Dec 1998 17:02:29 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Is it possible with perl?
Message-Id: <36802d21.3475324@news.skynet.be>
Ys_Kim wrote:
>Is it possible to submit a form to multiful cgi scripts at the same time
>and each script located in different places?
No, I don't think so. One submit, one URL. But you can have a CGI script
that passes submits on to the other CGI's (eh, "URL's"). LWP (libwww)
might help.
Bart.
------------------------------
Date: Sun, 20 Dec 1998 12:52:34 -0500
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: Mac, Perl, uploading, help!
Message-Id: <1dkb4sr.1yeld6117n9om2N@slip-32-100-246-98.ny.us.ibm.net>
Kent <maxilious@earthlink.net> wrote:
> Everytime I try to ulpoad a perl script with FETCH to my server the people
> at the isp say it is corrupted.
>
> Now when I upload my html to my regular dirs I have no problems with fetch
> (set to raw data). I edit in BBedit light, should I be saving in a specific
> format?
Send the file as text, so the line endings get converted properly.
--
Kevin Reid. | Macintosh.
"I'm me." | Think different.
------------------------------
Date: 20 Dec 1998 16:49:24 GMT
From: moseley@best.com (Bill Moseley)
Subject: Re: Nested sorting
Message-Id: <367d2a94$0$228@nntp1.ba.best.com>
In article <x7lnk4mzfa.fsf@sysarch.com>, uri@sysarch.com says...
>before your sort, scan all your data and build some sort structure,
>maybe an array of arrays with the first sub element being the original
>data and otehr sub elements being keys which sort up or down. youcan
>organize those keys in some way in ths sub arrays so the compare code
>know which is up and which is down. that is the common code that is doen
>during the preprocessing.
>then the sort routine does a simple multilevel
>sort on the proprocessed arrays and it doesn't have to determine whether
>a key is sorted up or down e.g. key[1] is up and key[2] is down, etc.
Uri,
I'm doing as much as this as I think I can. I just don't see how to set
up my keys ahead of time so the sort routine doesn't have to check if,
say, key number three out of a five level sort should be sorted in reverse.
Now, I could invert numbers in preprocessing to force reverse sorting on
that key (although I wonder a bit on smaller sorts if the floating point
compare wouldn't be more expensive than the test-and-swap I use).
But what I guess I'm missing from your posts is how I "inverse" a string
in pre-processing to make it sort in reverse in the normal sort routine.
If I understood this then I could stringify and then do only one compare
in the sort routine.
And back to my original post:
Now, if I've pre-processed as much as I can, is it my loop structure
that is the pokey part of this? And if so, how can it be improved?
sub list_sort {
my $compare;
# Loop through all the sort keys
for (1..$#{$a} ) {
# get local copys of the dat (incase need to reverse)
my $aa = $a->[$_];
my $bb = $b->[$_];
# Reverse sort order if '!' is first char
($bb, $aa) = ($aa, $bb) if substr($aa,0,1) eq '!';
# Compare by number, else by string
$compare = (
$aa <=> $bb
or
$aa cmp $bb
);
# Return if they don't match
return $compare if $compare;
}
0; # return something if falls through or if no sort keys.
}
--------------
Bill Moseley
moseley@best.com
------------------------------
Date: Sun, 20 Dec 1998 13:35:06 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Nested sorting
Message-Id: <1dkc78c.nx92v6buhglsN@bay1-423.quincy.ziplink.net>
Bill Moseley <moseley@best.com> wrote:
> # Reverse sort order if '!' is first char
>
> ($bb, $aa) = ($aa, $bb) if substr($aa,0,1) eq '!';
>
>
> # Compare by number, else by string
>
> $compare = (
> $aa <=> $bb
> or
> $aa cmp $bb
> );
I hope that you never have to do a reverse sort order when the values
are numbers and not strings. A string beginning with '!', which you use
to signify reverse sort order, always has a numeric value of zero.
That means $aa <=> $bb will always evaluate to 0 when both arguments
start with '!'.
So, if you have an array of values such as qw(!1 !2 !10), they will be
sorted in descending order, but as strings and not numbers: !2 !10 !1.
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Sun, 20 Dec 1998 10:32:39 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Nested sorting
Message-Id: <MPG.10e6e2a54c9389bc98996b@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and copy mailed.]
In article <367d2a94$0$228@nntp1.ba.best.com> on 20 Dec 1998 16:49:24
GMT, Bill Moseley <moseley@best.com> says...
...
> I'm doing as much as this as I think I can. I just don't see how to set
> up my keys ahead of time so the sort routine doesn't have to check if,
> say, key number three out of a five level sort should be sorted in reverse.
>
> Now, I could invert numbers in preprocessing to force reverse sorting on
> that key (although I wonder a bit on smaller sorts if the floating point
> compare wouldn't be more expensive than the test-and-swap I use).
It would be less expensive, by a lot! One perl OP (<=>) compared to
several perl OPs (test-and-swap). The underlying speed of the
operations is almost irrelevant (and in modern hardware, floating-point
compare is fast, anyway).
> But what I guess I'm missing from your posts is how I "inverse" a string
> in pre-processing to make it sort in reverse in the normal sort routine.
>
> If I understood this then I could stringify and then do only one compare
> in the sort routine.
Yes, you could. Here is how to invert a string in preprocessing:
First, make a pass through all the strings and compute the maximum
length. Next, in the pass to compute the sort keys, xor every string
that is to be reverse-sorted with "\xFF" x $maxlen. In essence, this
creates a bit-wise one's-complement of the string, which will serve as
its negative in comparison.
Here is a small test program that complements all the strings. You can
add your own logic to be selective on the leading '!' (which you should
cut out before computing the length or the inverse).
#!/usr/local/bin/perl -w
use strict;
my @data = ('a' .. 'f', 'aa' .. 'af', 'aaa' .. 'aaf');
my $maxlen = 0;
foreach (@data) { $maxlen = length if $maxlen < length }
my $invert = "\xFF" x $maxlen;
# The conventional reverse alphabetical sort.
print join(' ', sort { $b cmp $a } @data), "\n";
# Schwartz Transform version.
print join(' ', map $_->[0]),
sort { $a->[1] cmp $b->[1] }
map { [ $_, $_ ^ $invert ] } @data), "\n";
# Stringified default sort (most efficient).
print join(' ', map substr($_, $maxlen),
sort
map { ($_ ^ $invert) . $_ } @data), "\n";
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sun, 20 Dec 1998 12:52:31 -0500
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: Passing Multiple Arrays
Message-Id: <1dk8c65.1xu1t0n1d9otxqN@slip-32-100-246-98.ny.us.ibm.net>
Jacque Weddle <jacque@netleaf.com> wrote:
> Hello,
>
> I have, what I hope will be, a simple question. How are multiple arrays
> and hashes passed into a function. (They must be passed, I can't just
> make them global) For example:
>
> MyFunction(@array1,@array2,%hash1)
>
>
> sub
> MyFunction {
> local(@array1,@array2,%hash1) = @_;
> ...
> code
> ...
> }
>
> All of the data exists in @_ but I don't know how to make sure the data
> coming into the function is split into separate arrays and not interpeted
> as belonging all to the first array.
The arguments must be passed as references:
#!perl -w
sub MyFunction {
my ($arrayref1, $arrayref2, $hashref1) = @_;
print "$arrayref1->[0]\n";
print "$arrayref2->[1]\n";
print "$hashref1->{c}\n";
}
@ArrayA = qw(a b c);
@ArrayB = qw(d e f);
%HashA = (a => 'b', c => 'd', e => 'f');
MyFunction(\@ArrayA, \@ArrayB, \%HashA);
__END__
You can use a prototype to automatically create the references:
#!perl -w
sub MyFunction (\@\@\%) {
my ($arrayref1, $arrayref2, $hashref1) = @_;
print "$arrayref1->[0]\n";
print "$arrayref2->[1]\n";
print "$hashref1->{c}\n";
}
@ArrayA = qw(a b c);
@ArrayB = qw(d e f);
%HashA = (a => 'b', c => 'd', e => 'f');
MyFunction(@ArrayA, @ArrayB, %HashA);
__END__
The prototype (\@\@\%) specifies that the arguments must be 2 arrays and
a hash, and are to be converted into references.
--
Kevin Reid. | Macintosh.
"I'm me." | Think different.
------------------------------
Date: Sun, 20 Dec 1998 08:47:33 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Quick Substitution Question
Message-Id: <MPG.10e6c9ff1e37f3e098996a@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and copy mailed.]
In article <367CACE0.ADE0950A@savalas.com> on Sun, 20 Dec 1998 07:53:38
GMT, Jesse Rosenberger <jesse@savalas.com> says...
> $textstring = "$4Rat$.%23%";
>
> Now, what do we need to run that string through to get:
>
> $textstring = "4.23";
...
> What can be done to keep the period (and only the period) in there along
> with the numbers?
Someone else suggested
s/[^\d\.]//g;
which works (and the backslash before the dot is unnecessary).
The following works considerably better (i.e., faster):
tr/0-9.//cd;
You can use the Benchmark module to find out just how much better (i.e.,
faster).
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 20 Dec 1998 16:49:31 GMT
From: jkanajan@ets.cis.brown.edu (Jaya_Kanajan)
Subject: regex wack
Message-Id: <75j9qr$np6@cocoa.brown.edu>
hi,
i ran into a little problem with a script i was writing. i've been trying to replace input that looks like "load_maf_" with "load\_maf\_" for use as included LaTeX.
so my regex for this was s/\_+/\\\_/;
is this incorrect, i thought it to mean, match if _ occurs more than replace it each time with \_.
here's the whole script: perhaps someone can also comment on how ot make it more efficient.
thanks,
jaya
#!/usr/local/bin/perl -w
# by jkk@lems.brown.edu 20 Dec 1998
use Text::Wrap;
$outfile = $ARGV[-1];
$infile = $ARGV[-2];
open(CODE,"<$infile") || die "'$infile' not openable";
open(OUT,">$outfile") || die "'$outfile' not openable";
$infile =~ s/\_/\\\_/;
print OUT "{\n\\centerline{\\underline{\\bf{$infile}}}\n { \small\n";
while (<CODE>) {
s/\\+/\\verb+\\+/; # a slash in code has to become verb \
s/\~+/\\verb+~+/;
s/\^+/\\verb+^+/;
s/\015+//;
s/\#+/\\\#/;
s/\$+/\\\$/;
s/\%+/\\\%/;
s/\&+/\\\&/;
s/\_+/\\\_/;
s/\{+/\\\{/;
s/\}+/\\\}/;
unless (/\S/) {
next if $blanks++;
} else {
undef $blanks;
}
print OUT wrap("",'',$_);
}
print OUT "\n}\n}\n";
close(CODE);
close(OUT);
------------------------------
Date: Sun, 20 Dec 1998 11:28:28 -0500
From: jamesht <jamesht@idt.net>
To: me <groans@mailexcite.com>
Subject: Re: replacement question
Message-Id: <367D25AB.24692EBF@idt.net>
Hello,
You can use LWP and the related modules to do it. You'll have to remember
the request which you used to get the page, so that you'll know the host and
relative path for the links (of course).
This is from the hip, so please be kind...
use HTML::Parse;
# and a couple others, if you're going to use LWP::UserAgent,
HTTP::Request,
# HTTP::Response, etc...
#
#
# get the html
#
$html = $get_it_any_way_you_can;
#
# I use the LWPuserAgent...
#
#$http_response_object =
$LWP_userAgent_object->request($http_request_object);
#$html = $http_response_object->content;
#
# create a HTML::TreeBuilder object base on that html
#
$parsed_html = $HTML::Parse::parse_html($html);
#
# use that object to get the links (doesn't seem to get frame links for
me, though, so you might
# have to get them by hand)
#
# the links are HTML::Element objects.
#
@links = $parsed_html->extract_links();
#
# The links are refs to arrays with two fields. The first is the link as
text, and the second is an
# HTML::Element object based on that tag in the html.
#
#
# from here, you can match the link text to the html and replace...
#
foreach $link (@links) {
#
# this regexp probably fails somehow, but like I said, this is only a
sketch...
#
$html =~
s/$link->[0]/${proxy_address}${host_and_path_for_this_link}link->[0]/g;
}
#
# that's it.
#
#You can get the $host_and_path_for_this_link from:
#
# get the absolute url
#
$host_and_path_for_this_link = $http_request_object->url->abs;
#
# take off the file part
#
(too obvious to continue)
I hate to say it, but there might be a problem if there's a
<BASE HREF="http://otherhost/or/otherpath"> tag in the html. I'm not sure
whether or not the parser takes this into account when creating the links...
Does anyone out there know?
hth, sorry about the rough outline of it, but it's better than nothing, I
hope...
James
------------------------------
Date: Sun, 20 Dec 1998 10:46:08 -0800
From: me <groans@mailexcite.com>
Subject: Re: replacement question
Message-Id: <367D45F0.525068B7@mailexcite.com>
Hola,
Thanks for responding. I have not had too much success with LWP and the modules
(each time my script references one, it says that the module needs other
modules. When I put them where they are supposed to be, it tells me I need even
more. SOme I have not been able to find, so I just gave up). Perhaps I will
take this time to revisit them . . . Thanks again!
~Prime
jamesht wrote:
> Hello,
>
> You can use LWP and the related modules to do it. You'll have to remember
> the request which you used to get the page, so that you'll know the host and
> relative path for the links (of course).
>
> This is from the hip, so please be kind...
>
> use HTML::Parse;
> # and a couple others, if you're going to use LWP::UserAgent,
> HTTP::Request,
> # HTTP::Response, etc...
> #
>
> #
> # get the html
> #
> $html = $get_it_any_way_you_can;
> #
> # I use the LWPuserAgent...
> #
>
> #$http_response_object =
> $LWP_userAgent_object->request($http_request_object);
> #$html = $http_response_object->content;
>
> #
> # create a HTML::TreeBuilder object base on that html
> #
> $parsed_html = $HTML::Parse::parse_html($html);
> #
> # use that object to get the links (doesn't seem to get frame links for
> me, though, so you might
> # have to get them by hand)
> #
> # the links are HTML::Element objects.
> #
> @links = $parsed_html->extract_links();
> #
> # The links are refs to arrays with two fields. The first is the link as
> text, and the second is an
> # HTML::Element object based on that tag in the html.
> #
>
> #
> # from here, you can match the link text to the html and replace...
> #
> foreach $link (@links) {
> #
> # this regexp probably fails somehow, but like I said, this is only a
> sketch...
> #
> $html =~
> s/$link->[0]/${proxy_address}${host_and_path_for_this_link}link->[0]/g;
> }
>
> #
> # that's it.
> #
>
> #You can get the $host_and_path_for_this_link from:
> #
> # get the absolute url
> #
> $host_and_path_for_this_link = $http_request_object->url->abs;
> #
> # take off the file part
> #
> (too obvious to continue)
>
> I hate to say it, but there might be a problem if there's a
> <BASE HREF="http://otherhost/or/otherpath"> tag in the html. I'm not sure
> whether or not the parser takes this into account when creating the links...
>
> Does anyone out there know?
>
> hth, sorry about the rough outline of it, but it's better than nothing, I
> hope...
>
> James
------------------------------
Date: Sun, 20 Dec 1998 10:52:32 -0500
From: jamesht <jamesht@idt.net>
To: erik@caid.com
Subject: Re: Script that faxes
Message-Id: <367D1D3F.DEC911C6@idt.net>
Hello,
I know of no way to do it from Perl, but you can use HylaFAX on unix as a
helper program.
hth
James
------------------------------
Date: Sun, 20 Dec 1998 11:38:16 -0600
From: adrade@wwa.com (Adam Levy)
Subject: Re: Splitting a line at |'s
Message-Id: <adrade-2012981138160001@pool2-053.wwa.com>
In article <x3y7lvuwhua.fsf@tigre.matrox.com>, Ala Qumsieh
<aqumsieh@matrox.com> wrote:
> hdiwan@diwanh.stu.rpi.edu () writes:
>
> >
> > In article <750lds$sp2$1@readme.online.no>, Asbjorn Gjemmestad wrote:
> > >I've got a plain text data file with several lines containing three pieces
> > >of data.
> > >The data is separated with |'s, making the data entires
value1|value2|value3
> > >
> > >I need to split these entries into three different variables. I know I need
> > >to use the split function, but I'm not quite sure about how to make the
> > >statement.
> > while (<IN>) {
> > @A=split /|/;
> > $value1=@A[0]; $value2=@A[1];$value3=@A[2];
> > }
> > There you are... that should work.
>
> Unless you use the '-w' flag which would generate all sorts of
> warnings.
>
> $value1 = $A[0]; # not @A[0]
>
> PS. Make sure you use your values before the next iteration of the
> while loop or else they'll be over-written.
i'd use:
($one,$two,$three) = split(/|/,$vartobesplit,3);
------------------------------
Date: Sun, 20 Dec 1998 18:06:03 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Splitting a line at |'s
Message-Id: <367D3E44.FDA9C016@home.com>
[posted & mailed]
Adam Levy wrote:
>
> i'd use:
> ($one,$two,$three) = split(/|/,$vartobesplit,3);
Why would you ever use that?? If you want to put the first two
characters of $vartobesplit into $one and $two, and the rest of the
string into $three then for clarity you should use:
($one,$two,$three) = split(//,$vartobesplit,3);
Or perhaps you could use substr().
What you have written makes it look like you want to split on '|', which
of course would be written as:
($one,$two,$three) = split(/\|/,$vartobesplit,3);
--
Rick Delaney
rick.delaney@shaw.wave.ca
------------------------------
Date: Sun, 20 Dec 1998 13:09:27 -0500
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: Splitting a line at |'s
Message-Id: <MPG.10e7075e6e95cd7a989769@news.scescape.net>
In article <adrade-2012981138160001@pool2-053.wwa.com>, adrade@wwa.com
says...
=> i'd use:
=> ($one,$two,$three) = split(/|/,$vartobesplit,3);
You would?
% perl -e 'print "[", join("][",split(/|/,"This|Has|Four|In|It")), "]"'
[T][h][i][s][|][H][a][s][|][F][o][u][r][|][I][n][|][I][t]
%
Not exactly what we want. :)
Try:
% perl -e 'print "[", join("][",split(/\|/,"This|Has|Four|In|It")), "]"'
[This][Has][Four][In][It]
%
Or:
% perl -e 'print "[", join("][",split(/[|]/,"This|Has|Four|In|It")), "]"'
[This][Has][Four][In][It]
%
HTH!
--Matthew
------------------------------
Date: Sun, 20 Dec 1998 12:07:54 -0500
From: Tk Soh <r28629@email.sps.mot.com>
To: Adam Levy <adrade@wwa.com>
Subject: Re: Splitting a line at |'s
Message-Id: <367D2EDE.F7142731@email.sps.mot.com>
[posted to clpm and coyp emailed]
Adam Levy wrote:
[...]
> i'd use:
> ($one,$two,$three) = split(/|/,$vartobesplit,3);
^^^
What happen when you try it?
-TK
------------------------------
Date: Sun, 20 Dec 1998 12:52:26 -0500
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: Syntax Error...Not able to find.
Message-Id: <1dk72dk.1cj9kcqutpj7kN@slip-32-100-246-98.ny.us.ibm.net>
Uri Guttman <uri@ibnets.com> wrote:
> G> unlink (resellers.lock);
> ^^^^^^^^^^^^^^
> bareword for a file name. are you using -w?
It's not just a bareword, it's two barewords concatenated with the '.'
operator - which means the . disappears.
--
Kevin Reid. | Macintosh.
"I'm me." | Think different.
------------------------------
Date: Sun, 20 Dec 1998 16:58:22 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Why Is Perl not a Language?
Message-Id: <367f2bcb.3132702@news.skynet.be>
David Jacoby wrote:
>53 pier 5:12am ~ % grep foo
>Since it reacts to what i'm typing, it seems interactive to me.
No it's not. You're not typing *IN* grep. You're typing in the shell,
which passes what you typed on to grep.
I'm not saying that this is worse; just different. On the contrary, it
does make automating far easier to do.
Bart.
------------------------------
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 4467
**************************************