[21780] in Perl-Users-Digest
Perl-Users Digest, Issue: 3984 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 17 00:05:45 2002
Date: Wed, 16 Oct 2002 21:05:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 16 Oct 2002 Volume: 10 Number: 3984
Today's topics:
Re: [OT] Re: silent detection of cgi completion problem <flavell@mail.cern.ch>
Re: Anything better than eval("\$$class\::x") ? <heather710101@yahoo.com>
Re: array problem (BUCK NAKED1)
Re: attr proposition: function call performed at compil <goldbb2@earthlink.net>
Re: Capitalizing letters in the middle of "word" <wksmith@optonline.net>
Re: Capitalizing letters in the middle of "word" <wsegrave@mindspring.com>
Re: CGI-related error <flavell@mail.cern.ch>
Re: defining subroutines on the fly in a module <keith@tsox.com>
Re: How to know if packed as binary? <goldbb2@earthlink.net>
Re: Image::Magick JPEG=>TIF Conversion (Jay Tilton)
Re: Image::Magick JPEG=>TIF Conversion <mgjv@tradingpost.com.au>
Re: Image::Magick JPEG=>TIF Conversion <mgjv@tradingpost.com.au>
mod_perl or fastcgi for performance boost <swen@news.com>
Re: mod_perl or fastcgi for performance boost <nospam@nospam.com>
Re: New JAPH <goldbb2@earthlink.net>
Newbie help extracting strings (LeshPhilling)
Re: Newbie help extracting strings <mgjv@tradingpost.com.au>
Re: Newbie help extracting strings <nospam@nospam.com>
Re: Newbie help extracting strings <wksmith@optonline.net>
Re: Opinion on using Perl or JavaScript for Web develop (Brian)
Perl and DDE (Ct60)
Re: Perl and MySql <vm.mayer@comcast.net>
Re: Random Character Picker (Sam Holden)
Re: Read a single character from STDIN (W98) <nikogo@nigde.net>
Regex - how do I check for not equal to a multi-charact (Steve Hiner)
Re: Regex - how do I check for not equal to a multi-cha <pinyaj@rpi.edu>
regular expressions... really don't get it! <linux@dds.nl>
Re: regular expressions... really don't get it! <mike_constant@yahoo.com>
Re: regular expressions... really don't get it! <krahnj@acm.org>
Re: regular expressions... really don't get it! <wksmith@optonline.net>
Re: Sleeping until another process finishes? ctcgag@hotmail.com
Re: Two questions about File::Find "preprocess" coderef <nospam@nospam.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 17 Oct 2002 00:59:12 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: [OT] Re: silent detection of cgi completion problem
Message-Id: <Pine.LNX.4.40.0210170048010.11972-100000@lxplus075.cern.ch>
On Oct 16, Jeff Zucker inscribed on the eternal scroll:
> But what we're discussing here is not long-running CGI scripts, rather
> quick CGI scripts which send responses to "long running" DHTML pages.
Indeed...
> > So, going back to the original question "how do I detect that the CGI
> > script has finished?", my answer still is that the client simply
> > awaits the HTTP transaction response - there's no "detection" needed
>
> But if "finished" means that the CGI script
> has finished its task and the server has finished sending the response
> to the client and the client has completely recieved that response, then
> there certainly is a way to detect that state
OK EOD. If we interpret the question as "how can I detect that the
script's response has been completely received?" then you've made your
point.
Until we know more about what real-world problem this is supposed to
solve, I'm inevitably reminded of Heath-Robinson, or Emmett, who
produced magnificently impressive and complex mechanisms whose chief
purpose was to be impressive and complex, no matter the mundane
end-product...
all the best
------------------------------
Date: Wed, 16 Oct 2002 23:10:59 +0000 (UTC)
From: Da Witch <heather710101@yahoo.com>
Subject: Re: Anything better than eval("\$$class\::x") ?
Message-Id: <aokrm3$2k0$1@reader1.panix.com>
In <aoknhg$17h$1@reader1.panix.com> Da Witch <heather710101@yahoo.com> writes:
>In <Pine.A41.3.96.1021016162924.31856A-100000@vcmr-104.server.rpi.edu> Jeff 'japhy' Pinyan <pinyaj@rpi.edu> writes:
>>[posted & mailed]
>>On Wed, 16 Oct 2002, Da Witch wrote:
>>> sub static_x {
>>> my $proto = shift;
>>> my $class = ref $proto || $proto;
>>>
>>> my $x = "\$$class\::x"; # $x holds a string of the form '$Foo::x'
>> # class->some_var(name, [value]);
>> sub some_var {
>> my $class = shift() . "::";
>> my $name = shift;
>> my $var = $::{$class}{$name};
>> $$var = shift if @_;
>> return $$var;
>> }
>>Why do you need this?
>I want to have inheritable methods that can get/set globals in the
>subclass's package.
BTW, thanks to you and to Mike for the help.
h
------------------------------
Date: Wed, 16 Oct 2002 21:53:36 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: array problem
Message-Id: <8734-3DAE2630-123@storefull-2272.public.lawson.webtv.net>
It looks like I have other problems that I have to figure out in my
subroutine in order to fix the problem. Thanks.
--Dennis
------------------------------
Date: Wed, 16 Oct 2002 21:11:33 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: attr proposition: function call performed at compile time
Message-Id: <3DAE0E45.BBD57A1A@earthlink.net>
Daniel Pfeiffer wrote:
>
> Benjamin Goldberg <goldbb2@earthlink.net> skribis:
> > This could probably be accomplished with a source filter.
>
> Haven't come across those (only got 5.8 with SuSE 8.1 last week :-).
> How do they work?
Look at the docs of Filter::Util::Call and Filter::Simple.
They come with 5.8, and are avalable on CPAN for use with earlier
versions of perl.
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Wed, 16 Oct 2002 21:38:46 -0400
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: Capitalizing letters in the middle of "word"
Message-Id: <Fwor9.15705$L42.9390@news4.srv.hcvlny.cv.net>
"Dan Skadra" <dskadra@yahoo.com> wrote in message
news:c1bd7661.0210161027.5ce00f3e@posting.google.com...
> I'm trying to reformat a list of user names in the form 'smith_bob'
> where the first leters of the fist and last names are sometimes
> capitalized, sometimes not. What I'd like to do is find a way to
> capitalize those letters if they aren't already. So, I'd like it to
> look like 'Smith_Bob', no matter how it is capitalized.
Correct capitalization of some names (e.g. surnames beginning with the
prefix 'Mc') requires more complex rules.
>
> I'm fairly new to perl, so I'm having some trouble building an
> expression. I think it can be done with tr/// or s///, just not sure
> how.
>
> Any ideas?
>
--snip--
If your spec is adequate for your application, use one of the solutions
already posted. Otherwise, you must specify all the special cases that must
be handled. Developing that spec is probably more work than writing the
Perl code to implement it.
Bill
------------------------------
Date: Wed, 16 Oct 2002 22:27:27 -0500
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Capitalizing letters in the middle of "word"
Message-Id: <aolanf$2sr$1@slb4.atl.mindspring.net>
"John W. Krahn" <krahnj@acm.org> wrote in message
news:3DADD8AE.CEF957A1@acm.org...
> Dan Skadra wrote:
> >
> > I'm trying to reformat a list of user names in the form 'smith_bob'
> > where the first letters of the first and last names are sometimes
> > capitalized, sometimes not. What I'd like to do is find a way to
> > capitalize those letters if they aren't already. So, I'd like it to
> > look like 'Smith_Bob', no matter how it is capitalized.
>
> $ perl -le'$_ = "smith_bob"; s/([a-z]+)/\u$1/g; print'
> Smith_Bob
Nice, John.
The OP didn't indicate whether he was using a Win32 or **nix OS. On a Win32
system, however,
perl -le "$_ = 'smith_bob'; s/([a-z]+)/\u$1/g; print"
Smith_Bob
might work better.
Bill Segraves
------------------------------
Date: Thu, 17 Oct 2002 01:44:01 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: CGI-related error
Message-Id: <Pine.LNX.4.40.0210170130530.14041-100000@lxplus075.cern.ch>
On Oct 16, Colby inscribed on the eternal scroll:
[...] and returns
> the following errors when run from the command line:
Good move: you tested it out from the command line and found a
problem. Thereby at least initially eliminating the CGI-related part,
no?
So why does the subject line claim nothing more than that you have a
CGI-related error?
This not only provokes the regulars into telling you that you're
probably off-topic, but worse, it makes it so much harder for anyone
coming later with their own problem to recognise any similarity with
the one that was solved before.
So please make better use of your Subject line.
> ...) and found nothing amiss. I haven't run the script through the
> Perl debugger yet and I am not able to do so on the web hosting
> company's server because they don't allow telnet/SSH.
(Well, in addition to what Tad said - if you suspect a Perl version
issue, then old versions of Perl can still be had, maybe you want to
install a back-level version on some handy system and try the script
there. If you're staying with the same provider and they're not
ready to upgrade, that could be a reasonable investment for future
debugging too)
------------------------------
Date: Wed, 16 Oct 2002 17:05:22 -0500
From: "Keith A. Clay" <keith@tsox.com>
To: Ben Kennedy <bkennedy@hmsonline.com>
Subject: Re: defining subroutines on the fly in a module
Message-Id: <3DADE2A2.4010109@tsox.com>
Ben Kennedy wrote:
> "Keith A. Clay" <novalid@email.oops> wrote in message
> news:3dad7ec5$1_4@news.teranews.com...
>
>
> See "perldoc -f eval". Basically you generate the code that contains the
> subroutine, eg $var = "sub your_sub { bleh }". Then just "eval $var" - but
> be sure to check $@ afterwards to diagnose any bugs in your dynamically
> generated code. Aftwerwards, your_sub() is available in the namespace you
> eval'ed in.
Ben,
Thanks for the info. It solved the problem. here is what it looks like
for those who may be interested:
sub cr_user_subs {
my ($self)=@_;
foreach my $ul ( split(':',$self->{'USER_VARS'}) ) {
my $name=lc($ul);
my $sname="set_" . $name;
my $tvar;
my $gname="get_" . $name;
$tvar="sub $sname { my
(\$self,\@arr)=\@_;\$self->change_user_var(\@arr) }";
eval $tvar;
if ( $@ ) {
print "Error creating subroutine '$sname' -- exiting.";
return 1;
}
$tvar="sub $gname { my
(\$self,\@arr)=\@_;\$self->query_user_var(\@arr) }";
eval $tvar;
if ( $@ ) {
print "Error creating subroutine '$gname' -- exiting.";
return 1;
}
}
}
keith
------------------------------
Date: Wed, 16 Oct 2002 21:24:00 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: How to know if packed as binary?
Message-Id: <3DAE1130.96CBD492@earthlink.net>
Philip Taylor wrote:
>
> In article <3DAC1C28.9060500@web.de>, edgue@web.de writes
> >My hope was that pack() would create some "magic type information"
> >that I could use later on.
>
> my $x = unpack F => pack L => 0xffffffff;
> print "$x\n", unpack(H8 => reverse pack F, $x), "\n\n";
> my $y = unpack F => pack L => 0xfffffffe;
> print "$y\n", unpack(H8 => reverse pack F, $y), "\n";
>
> outputs
>
> -1.#QNAN
> ffffffff
>
> -1.#QNAN
> fffffffe
>
> It appears that while $x seems to contain "-1.#QNAN" in both cases,
No. $x contains a 'double' value which happens to stringify to
"-1.#QNAN" (on your system... on other people's systems, it likely will
stringify to something else).
> there must also be some extra data about the original unpacked value
> so that unpack is able to return the original input correctly.
According to the IEEE specifications for floats, there are many
different types of NAN values. Unless you have a very wierd system, all
of them will stringify identically, as some variant of "NAN". However,
even though they stringify the same, they have different binary
representations, and so packing them will produce different strings.
> So pack does hide some information with the variable -- but I'm not
> aware of any way to access it, so it's not all that useful :-(
You would get the same behavior with C or C++. Try the following:
#include <stdio.h>
int main(int arg_count, char *arg_vec[]) {
float f;
*((int*)(void*)&f) = 0xffffffff;
printf("%f %i\n", f, *((int*)(void*)&f) );
*((int*)(void*)&f) = 0xfffffffe;
printf("%f %i\n", f, *((int*)(void*)&f) );
return 0;
}
[untested]
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Thu, 17 Oct 2002 00:04:40 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Image::Magick JPEG=>TIF Conversion
Message-Id: <3dada05c.159500671@news.erols.com>
"Jonas Nilsson" <dzluk8fsxsw0001@sneakemail.com> wrote:
| Among other things, at one stage I want to convert a JPEG picture into TIF
| using Image::Magick. Some problems arise which seems like bugs to me. Here
| is some example code:
|
| #!perl
| use strict;
| use Image::Magick;
| my $file="P4130004.JPG"; #1600x1200 jpeg
| my $res;
| my $p = new Image::Magick;
|
| $res=$p->Read($file); warn "$res" if "$res";
| my $width=$p->Get('width');
| my $height=$p->Get('height');
| my $dim="${width}x$height";
| print "$dim\n";
|
| $res=$p->Write(filename=>"out1.tif"); warn "$res" if "$res";
|
| $p->Set('magick'=>'RGB');
| $res=$p->Write(filename=>"out2.tif"); warn "$res" if "$res";
|
| my $p2=$p->Montage(geometry=>$dim);
| $res=$p2->Write(filename=>"out3.tif"); warn "$res" if "$res";
|
| $p2->Crop($dim);
| $res=$p2->Write(filename=>"out4.tif"); warn "$res" if "$res";
|
| According to me all four tif:s should be identical. However out1.tif and
| out2.tif are impossible to open with my picture viewer and the files are
| very much to small (476 kb).
out1.tif is still JPEG compressed, like the original image was. The
viewer you're using just doesn't support JPEG compression within
TIFFs.
Add
$p->Set( compression => 'None' );
to get out1.tif in the format you expect.
out2.tif is identical to out1.tif.
| Both out3.tif and out4.tif are valid picture
| files (5635 kb and 5645 kb) but out3.tif is 1600x1202 pixels (showing two
| white lines in the bottom) and only out4.tif seems to be correct.
out3.tif is created from scratch. It carries no preconception about
what its compression method should be, so defaults to 'None'. Why
Montage() adds a border, I can't guess. Just don't do that.
------------------------------
Date: Thu, 17 Oct 2002 10:55:29 +1000
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Image::Magick JPEG=>TIF Conversion
Message-Id: <slrnaqs2k1.q36.mgjv@martien.heliotrope.home>
On Wed, 16 Oct 2002 09:35:41 +0200,
Jonas Nilsson <dzluk8fsxsw0001@sneakemail.com> wrote:
[snip of creation of 4 images]
> According to me all four tif:s should be identical.
I don't see how you come to that conclusion. The first two should be
identical, since the jpeg would be RGB already, but I don't see any
reason why the last two should be. Montage() does a lot of work, and I
don't even see why you are calling it.
> However out1.tif and
> out2.tif are impossible to open with my picture viewer and the files are
> very much to small (476 kb).
Then I suggest that they are not really TIFF format, and something went
wrong. What does the identify() tool that comes with ImageMagick tell
you about it? Did you use the image viewer that came with ImageMagick as
well?
> Both out3.tif and out4.tif are valid picture
> files (5635 kb and 5645 kb) but out3.tif is 1600x1202 pixels (showing two
> white lines in the bottom) and only out4.tif seems to be correct.
>
> So why doesn't it work?
>
> I also get some warnings which I don't understand:
>
> Warning 330: no magic configuration file found (magic.mgk) [No such file or
> directory] at cplm.pl line 7.
> Warning 315: no delegates configuration file found (delegates.mgk) [No such
> file or directory] at cplm.pl line 13.
> Warning 315: no delegates configuration file found (delegates.mgk) [No such
> file or directory] at cplm.pl line 16.
> 1600x1200
These three warnings mean that your ImageMagick installation is broken.
Those files tell IM what file formats it knows about, and how to
read/write them. I am not surprised you get odd results if you ignore
these messages.
> I'm using PPM:s Image-Magick [5.26] An objected-oriented Perl interface to
> ImageMagick for Windows 2000.
That's a rather old version. I'd get a newer version first. That might
also fix the rest.
> Also another thing. Is there any good reference or tutorial for
> Image::Magick. The homepage http://www.imagemagick.org is incomplete and
> functions are not very well specified.
That's all you get for free [1]. There is no book available on ImageMagick
specifically [2]. The only books I know of that describe IM are "Programming
Web Graphics with Perl and GNU software", and "Graphics Programming with
Perl". That last one was written by me, so I don't feel entirely
comfortable making any recommendations.
Martien
[1] You should probably have a look in the latest source distribution of
ImageMagick. I know that some of the authors of the package have started
writing more extensive documentation, but I am not entirely certain how
much of that ended up in the distro, and how complete it is, and whether
perl is already covered or not.
[2] although sounds have been made in that direction, John Cristy simply
doesn't have time to write it, and others who could do it, also lack
time. If it is going to happen, it most likely won't be in the next
year.
--
|
Martien Verbruggen | I took an IQ test and the results were
| negative.
|
------------------------------
Date: Thu, 17 Oct 2002 10:58:30 +1000
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Image::Magick JPEG=>TIF Conversion
Message-Id: <slrnaqs2pm.q36.mgjv@martien.heliotrope.home>
On Wed, 16 Oct 2002 09:35:41 +0200,
Jonas Nilsson <dzluk8fsxsw0001@sneakemail.com> wrote:
> Also another thing. Is there any good reference or tutorial for
> Image::Magick. The homepage http://www.imagemagick.org is incomplete and
> functions are not very well specified.
In addition to my other post: There is a mailing list for ImageMagick,
which is quite valuable, and contains lots of information. Details on
the mailig list, and a link to its archive are available from
www.imagemagick.org.
Martien
--
|
Martien Verbruggen | That's funny, that plane's dustin' crops
| where there ain't no crops.
|
------------------------------
Date: Wed, 16 Oct 2002 19:30:00 -0700
From: swen <swen@news.com>
Subject: mod_perl or fastcgi for performance boost
Message-Id: <3DAE20A7.50271AEE@news.com>
Hi, I am a perl developer who has been using plain old cgi for creating
webapps for awhile now and I want to explore other alternatives in the
name of improving the speed of applications.
It seems like the biggest bottleneck for my apps is spawning the perl
process because I've benchmarked the running times for the entire script
and the times are always much smaller than what I have subjectively
judged the total page load time to be(e.g. 3 or 4 seconds compared to
much less than a second). My benchmark could be flawed I guess, all I'm
doing is recording time1 as the first line of code in the script and
then recording the time2 and printing the difference as the last two
lines of code in the script.
Bandwidth is not an issue because I'm testing from a computer on the
same lan(and of course static pages load in the blink of an eye). The
main feature I care about is performance but I also have the
requirements that win2k must be the server platform and I plan to
continue using Perl.
Also I will be porting existing cgi apps, so I'm somewhat concerned with
ease of porting. Also, a straightforward installation would be nice.
I'm not interested in any special advantages beyond a performance
increase. I would like to restrict this discussion to the topic in the
subject line. I am mainly interested in comments about your own
personal opinions of either of these(based on experience using them).
Links are good too. Thanks.
------------------------------
Date: Wed, 16 Oct 2002 20:05:18 -0700
From: "Tan Nguyen" <nospam@nospam.com>
Subject: Re: mod_perl or fastcgi for performance boost
Message-Id: <3dae2861$1_7@nopics.sjc>
"swen" <swen@news.com> wrote in message news:3DAE20A7.50271AEE@news.com...
> Hi, I am a perl developer who has been using plain old cgi for creating
> webapps for awhile now and I want to explore other alternatives in the
> name of improving the speed of applications.
>
> It seems like the biggest bottleneck for my apps is spawning the perl
> process because I've benchmarked the running times for the entire script
> and the times are always much smaller than what I have subjectively
> judged the total page load time to be(e.g. 3 or 4 seconds compared to
> much less than a second). My benchmark could be flawed I guess, all I'm
> doing is recording time1 as the first line of code in the script and
> then recording the time2 and printing the difference as the last two
> lines of code in the script.
>
> Bandwidth is not an issue because I'm testing from a computer on the
> same lan(and of course static pages load in the blink of an eye). The
> main feature I care about is performance but I also have the
> requirements that win2k must be the server platform and I plan to
> continue using Perl.
>
> Also I will be porting existing cgi apps, so I'm somewhat concerned with
> ease of porting. Also, a straightforward installation would be nice.
> I'm not interested in any special advantages beyond a performance
> increase. I would like to restrict this discussion to the topic in the
> subject line. I am mainly interested in comments about your own
> personal opinions of either of these(based on experience using them).
> Links are good too. Thanks.
I've never really looked into fastcgi, so I can't comment on it. However, I
did have a little bit experience with mod_perl (both pre-2.0 and current
stable version). Performance boost of mod_perl compared to plain old CGI is
tremendous provided that you don't have extensively IO bound applications
such as uploading files etc. Depending the size of your CGI applications,
you might or might not find it easy to port them to mod_perl. However, if yo
u go with mod_perl prior to 2.0, you should find things relatively similar
in both ends. In fact, I tested my stuff as CGI scripts and once it worked,
I simply plugged it in a driver module with very little change.
------------------------------
Date: Wed, 16 Oct 2002 20:58:45 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: New JAPH
Message-Id: <3DAE0B45.5C08E01B@earthlink.net>
Malte Ubl wrote:
>
> Jeff 'japhy' Pinyan wrote:
> > Why all that work? You're not changing anything if you get a miss.
> > I'd say:
> >
> > if ("@cur" eq "@list") { print "ok! $i\n" }
>
> Because I only wanted to pay the price of uppercasing $cur[1..3] if I
> had to. I know it could have been prettier, but it works.
The price isn't all that big. Furthermore, if you replaced those nested
ifs with a loop, the code would be much simpler.
Eg:
#!perl
use integer;
my $i = 0;
OUTER: {
srand ++$i;
$_ eq uc chr(65+rand 16) or redo OUTER for qw(J A P H);
print $i;
}
__END__
Which, on ActivePerl produces the number 76450.
(I don't have enough patience to wait for chr(rand 256) to produce a
seed ... there might not even *be* a seed which works, depending on the
RNG.)
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: 16 Oct 2002 19:02:03 -0700
From: lesh_philling@hotmail.com (LeshPhilling)
Subject: Newbie help extracting strings
Message-Id: <efebfff9.0210161802.6ba5b89@posting.google.com>
Hello
I'm not sure how to go about doing this--I know what I have and what I
want done, and I think it should be fairly straightforward, but I
can't seem to figure out how to accomplish what I want. Needless to
say I'm still at a very low level of Perl programming.
I have a text file. It has a lot of lines like this:
<DT><A HREF="http://www.afterstep.org/">AfterStep</A>
<DT><A HREF="http://www.perl.com/">Perl</A>
<DT><A HREF="http://www.gnome.org/">GNOME</A>
I want to run the script on this text file and have the results look
like this:
http://www.afterstep.org
http://www.perl.com
http://www.gnome.org
It seems like it should be simple to strip out everything but the
actual URL. I know that the LWP module would make things much easier,
but I wanted to do this as pattern matching exercise. Is what I'm
trying to do that hard, or am I just a thickie?
Thanks.
LP
------------------------------
Date: Thu, 17 Oct 2002 12:25:41 +1000
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Newbie help extracting strings
Message-Id: <slrnaqs7t5.q36.mgjv@martien.heliotrope.home>
On 16 Oct 2002 19:02:03 -0700,
LeshPhilling <lesh_philling@hotmail.com> wrote:
> Hello
>
> I'm not sure how to go about doing this--I know what I have and what I
> want done, and I think it should be fairly straightforward, but I
> can't seem to figure out how to accomplish what I want. Needless to
> say I'm still at a very low level of Perl programming.
>
> I have a text file. It has a lot of lines like this:
>
><DT><A HREF="http://www.afterstep.org/">AfterStep</A>
> <DT><A HREF="http://www.perl.com/">Perl</A>
> <DT><A HREF="http://www.gnome.org/">GNOME</A>
Looks like HTML. Is it HTML?
> I want to run the script on this text file and have the results look
> like this:
>
> http://www.afterstep.org
> http://www.perl.com
> http://www.gnome.org
If so, then you might be interested in the HTML::LinkExtor module from
CPAN. It extracts links from HTML documents. If you're only interested
in some of those links, then I suggest you use one of the other HTML
modules to parse and query the document.
> It seems like it should be simple to strip out everything but the
> actual URL. I know that the LWP module would make things much easier,
> but I wanted to do this as pattern matching exercise. Is what I'm
> trying to do that hard, or am I just a thickie?
LWP is a set of modules to make HTTP interaction easier. The HTML::*
modules are for HTML documents. I believe that some of the LWP modules
can use and will use some of those HTML::* modules. Some of the tools
that come bundled with LWP certainly do.
Martien
--
|
Martien Verbruggen | In the fight between you and the world, back
| the world - Franz Kafka
|
------------------------------
Date: Wed, 16 Oct 2002 19:53:43 -0700
From: "Tan Nguyen" <nospam@nospam.com>
Subject: Re: Newbie help extracting strings
Message-Id: <3dae25ab$1_7@nopics.sjc>
"LeshPhilling" <lesh_philling@hotmail.com> wrote in message
news:efebfff9.0210161802.6ba5b89@posting.google.com...
> Hello
>
> I'm not sure how to go about doing this--I know what I have and what I
> want done, and I think it should be fairly straightforward, but I
> can't seem to figure out how to accomplish what I want. Needless to
> say I'm still at a very low level of Perl programming.
>
> I have a text file. It has a lot of lines like this:
>
> <DT><A HREF="http://www.afterstep.org/">AfterStep</A>
> <DT><A HREF="http://www.perl.com/">Perl</A>
> <DT><A HREF="http://www.gnome.org/">GNOME</A>
>
> I want to run the script on this text file and have the results look
> like this:
>
> http://www.afterstep.org
> http://www.perl.com
> http://www.gnome.org
>
> It seems like it should be simple to strip out everything but the
> actual URL. I know that the LWP module would make things much easier,
> but I wanted to do this as pattern matching exercise. Is what I'm
> trying to do that hard, or am I just a thickie?
You might consider using HTML::LinkExtor module, not LWP. Something similar
to this [untested]
use strict;
use HTML::LinkExtor;
my $p = new HTML::LinkExtor;
$p->parse_file("yourfile.html") or die "cannot parse yourfile.html: $!\n";
foreach my $entry ($p->links) {
if (lc $$entry[0] eq 'a' && lc $$entry[1] eq 'href') {
print $$entry[2], "\n";
}
}
this simply extracts all links in the document for the "a" tag and "href"
attribute. These links might or might not be absolute path.
Regular expression [also untested]
open(FH, "yourfile.html") or die "cannot open yourfile.html: $!\n";
while (<FH>) {
print $1, "\n" if (/<a\s+href=\"(.*?)\">/);
}
close FH;
------------------------------
Date: Wed, 16 Oct 2002 23:10:42 -0400
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: Newbie help extracting strings
Message-Id: <TSpr9.16539$L42.4871@news4.srv.hcvlny.cv.net>
"LeshPhilling" <lesh_philling@hotmail.com> wrote in message
news:efebfff9.0210161802.6ba5b89@posting.google.com...
> Hello
>
> I'm not sure how to go about doing this--I know what I have and what I
> want done, and I think it should be fairly straightforward, but I
> can't seem to figure out how to accomplish what I want. Needless to
> say I'm still at a very low level of Perl programming.
>
> I have a text file. It has a lot of lines like this:
>
> <DT><A HREF="http://www.afterstep.org/">AfterStep</A>
> <DT><A HREF="http://www.perl.com/">Perl</A>
> <DT><A HREF="http://www.gnome.org/">GNOME</A>
>
> I want to run the script on this text file and have the results look
> like this:
>
> http://www.afterstep.org
> http://www.perl.com
> http://www.gnome.org
>
> It seems like it should be simple to strip out everything but the
> actual URL. I know that the LWP module would make things much easier,
> but I wanted to do this as pattern matching exercise. Is what I'm
> trying to do that hard, or am I just a thickie?
>
In general, it is had (that's what the modules are for).
For your special case, try the code after my signature.
Bill
#! c:\perl\bin\perl.exe -w
use strict;
while (<DATA>){
if(s/^.*HREF=\"(.*)\".*/$1/){
print;
}
else{
print "Failed to match: $_";
}
}
__END__
<DT><A HREF="http://www.afterstep.org/">AfterStep</A>
<DT><A HREF="http://www.perl.com/">Perl</A>
<DT><A HREF="http://www.gnome.org/">GNOME</A>
This is an invalid line
------------------------------
Date: 16 Oct 2002 17:45:16 -0700
From: BChirhart@fnni.com (Brian)
Subject: Re: Opinion on using Perl or JavaScript for Web development
Message-Id: <9d13498b.0210161645.60b0e38f@posting.google.com>
I agree - It is getting a bit off topic. I apologize. Thanks for
your comments Todd (and everyone else) - I realize that I have a long
road ahead for me.
Please though - if anyone else has any ideas, feel free to shoot them
to the address above.
------------------------------
Date: 17 Oct 2002 04:03:11 GMT
From: ct60@aol.com (Ct60)
Subject: Perl and DDE
Message-Id: <20021017000311.19542.00001654@mb-cd.aol.com>
Hello again -
I am wondering if anyone can point me toward documentation that shows how to
use DDE links (such as Reuters and Bloomberg market links) with Perl. Frankly,
it seems hard to beat Excel when it comes to ease of use with these types of
DDE links - but there is an awful lot of flukiness and even instability with
Excel - especially with the kinds of huge spreadsheets we use.
Maybe it's a pipe dream, but it would be such a pleasure to use Perl to create
a nice lightweight app that is fast and processes the data without crashing.
Someone make my day, Please.
Chris (ct60@aol.com)
------------------------------
Date: Wed, 16 Oct 2002 22:09:41 -0400
From: Mike Mayer <vm.mayer@comcast.net>
Subject: Re: Perl and MySql
Message-Id: <vm.mayer-A3D989.22094116102002@news-east.giganews.com>
In article <aokd4q$viu$1@nyytiset.pp.htv.fi>,
"JorkkiS" <jarkko.rantamaki@edu.stadia.no.spam.fi> wrote:
> I have to do a small Sql database project and I was wondering...
>
> I'd greatly appreciate if someone could guide me to the right direction or
> recommend me a good Perl/Sql book or web tutorial?
>
> Cheers
> -Jarkko
You can learn the basics of the DBI module just by reading its
documentation (embedded pod). I also own "Programming the Perl DBI" by
O'Reilly and have found it both useful and informative.
mike
------------------------------
Date: 17 Oct 2002 03:48:20 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Random Character Picker
Message-Id: <slrnaqsco4.10l.sholden@flexal.cs.usyd.edu.au>
On Tue, 15 Oct 2002 17:33:09 -0400,
Benjamin Goldberg <goldbb2@earthlink.net> wrote:
> John W. Krahn wrote:
>>
>> PinkPuppy wrote:
>> >
>> > I'd like to write a script that generated a specified number of
>> > random characters. I want to be able to specify which characters to
>> > choose from.
>> > Can someone show me some simple sample code that does something like
>> > this?
>>
>> my @characters = map chr, 0 .. 255;
>> my $random_character = $characters[rand @characters];
>
> That's just plain silly.
>
> my $random_character = chr rand 256;
It far more accurately answers the posters question though.
"I want to be able to specify which characters to choose from"
Simply replace @characters with something else say:
@characters = qw(a e i o u);
--
Sam Holden
------------------------------
Date: Thu, 17 Oct 2002 02:13:30 GMT
From: "Nemo Oudeheis" <nikogo@nigde.net>
Subject: Re: Read a single character from STDIN (W98)
Message-Id: <e1pr9.8900$1P1.713270@bgtnsc05-news.ops.worldnet.att.net>
Ah, yes, yours is the way to get the right console. Thanks.
Then one need only add the following two calls to suspend the need for an
<ENTER> before making the InputChar call:
my $oldMode = $console->Mode();
$console->Mode( ~(ENABLE_LINE_INPUT|ENABLE_ECHO_INPUT) & $oldMode );
(You can then restore it, if desired.)
~Nemo
Benjamin Goldberg <goldbb2@earthlink.net> wrote in message
news:3DAD9EAF.1A14EB8E@earthlink.net...
<snip>
> Try:
>
> use strict;
> use warnings;
> use Win32::Console;
> my $console = Win32::Console->new(STD_INPUT_HANDLE);
>
> --
> my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
> ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: 16 Oct 2002 18:06:19 -0700
From: spamcatcher@prodigy.net (Steve Hiner)
Subject: Regex - how do I check for not equal to a multi-character string
Message-Id: <54edff92.0210161706.4253901b@posting.google.com>
I'm a regex newbie so I hope this isn't too dumb a question. I've
checked several books and I can't find the answer - it's distinctly
possible that I just don't know what to look for.
I'm writing a regex and I need to be able to set a group to not equal
a string. Specifically I need the regex to match when a particular
group is not equal to "2001" or "3001". I want to use something like
(?<trantype>[^2001|3001]) but as you know that really means not equal
to any character in "2001|3001". I can't use [^2][^0][^0][^1] since
something like "2000" needs to pass the test.
I tried things like [^(2001)] but that doesn't work either. If I
wanted to match I know I could use (?<trantype>(2001|3001)) but since
^ means different things depending on where it is located I can't even
use (?<trantype>^(2001|3001)).
How do I force it to a literal string while negating the whole thing?
If this is the wrong place to ask this question please accept my
apologies, I've heard that Perl programmers tend to know a lot about
regex and I didn't notice any regex specific newsgroups.
Steve
------------------------------
Date: Wed, 16 Oct 2002 21:52:52 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: Regex - how do I check for not equal to a multi-character string
Message-Id: <Pine.A41.3.96.1021016215138.31858E-100000@vcmr-104.server.rpi.edu>
On 16 Oct 2002, Steve Hiner wrote:
>I'm writing a regex and I need to be able to set a group to not equal
>a string. Specifically I need the regex to match when a particular
>group is not equal to "2001" or "3001". I want to use something like
>(?<trantype>[^2001|3001]) but as you know that really means not equal
>to any character in "2001|3001". I can't use [^2][^0][^0][^1] since
>something like "2000" needs to pass the test.
Use a negative look-ahead:
for ("The Year is 2001", "The Year is 2002", "The Year is 3001") {
if (/(?![23]001)(\d{4})/) {
print "valid year ($1)\n";
}
}
--
Jeff "japhy" Pinyan RPI Acacia Brother #734 2002 Acacia Senior Dean
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Thu, 17 Oct 2002 00:35:18 +0200
From: "Evert" <linux@dds.nl>
Subject: regular expressions... really don't get it!
Message-Id: <3dade993$0$46002$8fcfb86b@news.wanadoo.nl>
i really don't get it. i read a few articles about it, and found a good
sample.
for a text file with: '$ 50.41' in it,
if ($content =~ /\$ (\d+\.\d+)/si){
print $1;
}
will give me 50.41
now i have this text:
<!-- maxin d 2596 -->
<!-- maxout d 3179 -->
<!-- avin d 136 -->
<!-- avout d 280 -->
<!-- cuin d 10 --><!-- cuout d 28 --><!-- avmxin d 210 -->
<!-- avmxout d 396 -->
<!-- maxin w 44084 -->
<!-- maxout w 20760 -->
<!-- avin w 624 -->
and i want to have the '28' after 'cuout d'.
but i really don't have a clue how to start. can someone
help me out? perhaps with a good faq or something?
thanks for any help.
Evert
------------------------------
Date: Wed, 16 Oct 2002 16:07:02 -0700
From: "Newbie" <mike_constant@yahoo.com>
Subject: Re: regular expressions... really don't get it!
Message-Id: <aokrel$nikmd$1@ID-161864.news.dfncis.de>
"Evert" <linux@dds.nl> wrote in message
news:3dade993$0$46002$8fcfb86b@news.wanadoo.nl...
>
> i really don't get it. i read a few articles about it, and found a good
> sample.
>
> for a text file with: '$ 50.41' in it,
> if ($content =~ /\$ (\d+\.\d+)/si){
> print $1;
> }
>
> will give me 50.41
>
> now i have this text:
>
> <!-- maxin d 2596 -->
> <!-- maxout d 3179 -->
> <!-- avin d 136 -->
> <!-- avout d 280 -->
> <!-- cuin d 10 --><!-- cuout d 28 --><!-- avmxin d 210 -->
> <!-- avmxout d 396 -->
> <!-- maxin w 44084 -->
> <!-- maxout w 20760 -->
> <!-- avin w 624 -->
>
> and i want to have the '28' after 'cuout d'.
> but i really don't have a clue how to start. can someone
> help me out? perhaps with a good faq or something?
>
> thanks for any help.
> Evert
while (my $line = <FH>) {
print $1 if /cuout d (\d+)/;
}
------------------------------
Date: Wed, 16 Oct 2002 23:55:13 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: regular expressions... really don't get it!
Message-Id: <3DADFC2F.EF8CA3EB@acm.org>
Newbie wrote:
>
> while (my $line = <FH>) {
> print $1 if /cuout d (\d+)/;
> }
Your regex is bound to $_ which isn't being changed because you are
reading the current line into $line.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Wed, 16 Oct 2002 21:09:22 -0400
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: regular expressions... really don't get it!
Message-Id: <f5or9.15450$L42.4734@news4.srv.hcvlny.cv.net>
"Evert" <linux@dds.nl> wrote in message
news:3dade993$0$46002$8fcfb86b@news.wanadoo.nl...
>
> i really don't get it. i read a few articles about it, and
--snip--
Did you read
perldoc perlretut
The on-line documentation supplied with perl is almost always the best
reference source. The documents with names that end in 'tut' are intended
to be tutorials.
Type
perldoc perldoc
(yes, type it twice on the command line) to learn how to
access the documentation.
Bill
found a good
> sample.
>
> for a text file with: '$ 50.41' in it,
> if ($content =~ /\$ (\d+\.\d+)/si){
> print $1;
> }
>
> will give me 50.41
>
> now i have this text:
>
> <!-- maxin d 2596 -->
> <!-- maxout d 3179 -->
> <!-- avin d 136 -->
> <!-- avout d 280 -->
> <!-- cuin d 10 --><!-- cuout d 28 --><!-- avmxin d 210 -->
> <!-- avmxout d 396 -->
> <!-- maxin w 44084 -->
> <!-- maxout w 20760 -->
> <!-- avin w 624 -->
>
> and i want to have the '28' after 'cuout d'.
> but i really don't have a clue how to start. can someone
> help me out? perhaps with a good faq or something?
>
> thanks for any help.
> Evert
>
>
>
------------------------------
Date: 17 Oct 2002 01:20:55 GMT
From: ctcgag@hotmail.com
Subject: Re: Sleeping until another process finishes?
Message-Id: <20021016212055.346$5L@newsreader.com>
laredotornado@zipmail.com (D. Alvarado) wrote:
> I know the $pid of another process, and I want my perl script to sleep
> until the other process (denoted by $pid) is done. Any ideas?
If it is a child process, waitpid.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service
------------------------------
Date: Wed, 16 Oct 2002 20:29:02 -0700
From: "Tan Nguyen" <nospam@nospam.com>
Subject: Re: Two questions about File::Find "preprocess" coderef
Message-Id: <3dae2df2$1_5@nopics.sjc>
"Michele Dondi" <bik.mido@tiscalinet.it> wrote in message
news:gduqqukcv1drmc4pma3up74u8d129c2v4g@4ax.com...
> perldoc File::Find yields the following piece of information:
>
> "preprocess"
> The value should be a code reference. This code reference is used to
> preprocess a directory; it is called after readdir() but before the
> loop that calls the wanted() function. It is called with a list of
> strings and is expected to return a list of strings. The code can be
> used to sort the strings alphabetically, numerically, or to filter
> out directory entries based on their name alone.
>
> Now I have two questions:
>
> (1) How does one really use arguments and return values of the
> "preprocess" coderef? Can I have an example?
Michele,
I quickly browsed through the source code of Find.pm. "preprocess" doesn't
take any arguments from the user. and it must return a list (array) of
filenames in the current directory.
The code looks like this:
......
@filenames = readdir DIR;
closedir(DIR);
@filenames = &$pre_process(@filenames) if $pre_process;
.....
So you can't actually pass any arguments to "preprocess" in your code.
Neither can you get its return values.
> (2) Can there be any issues if I create a subdir (and possibly some
> files in it) with "preprocess"? That is would that directory entry
> (and the files contained therein) be encountered in subsequent
> "wanted" coderefs?
It might or might not, depending on the implementation of the underline OS.
In any case, it's dangerous to do such things (ie. creating or removing
files/directories while in a middle of read directory operation.
> <comment>
> FWIM the question originally arised when I had to process all of the
> files (of a certain kind) in a directory tree and wanted to make .bak
> copies of the original ones.
>
> The problem was that I had some huge directories (500..1000 files
> each) and creating bak copies of their files in the same directories
> was inefficient (working on W98 fs), no matter which method I used.
>
> I thought of partially increasing the speed by creating a bak subdir
> and put copies of the original files in there. BTW: actually I ended
> up modifying the files "directly".
> </comment>
Not really clear on what you like to do though.
------------------------------
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 3984
***************************************