[18000] in Perl-Users-Digest
Perl-Users Digest, Issue: 160 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jan 28 06:05:26 2001
Date: Sun, 28 Jan 2001 03:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <980679907-v10-i160@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 28 Jan 2001 Volume: 10 Number: 160
Today's topics:
Re: Allocating ports in perl ayeletma1@my-deja.com
Re: Calling rsync with "system" does not work (Otto Wyss)
Re: Calling rsync with "system" does not work (Otto Wyss)
Re: Calling rsync with "system" does not work <uri@sysarch.com>
Re: Calling rsync with "system" does not work (Martien Verbruggen)
Re: Calling rsync with "system" does not work (Martien Verbruggen)
Re: Cool way to learn Perl? <jdf@pobox.com>
Re: Cool way to learn Perl? jqcordova@my-deja.com
Re: FAQ status and reposts, was Re: FAQ 1.5: What is <flavell@mail.cern.ch>
Re: help installing libwww-perl-5.50 from pc to host (Martien Verbruggen)
Mysterious inconsistent script behavior (JCDixon)
New Locking problem <johnm@acadiacom.net>
Re: New Locking problem <johnm@acadiacom.net>
Re: New way to learn Perl? jqcordova@my-deja.com
Re: Perl for Windows applications: when <c-kleinheitz@freenet.de>
Re: Quick RegExp Question <jdf@pobox.com>
Re: Reading/displaying a raw character <jdf@pobox.com>
regex question: @ counterpart to $1 et al? <ocschwar@mit.edu>
Re: regex question: @ counterpart to $1 et al? (Martien Verbruggen)
Re: regex question: @ counterpart to $1 et al? <ocschwar@mit.edu>
String functions? <kkk@elrancho.com>
Re: String functions? <kkk@elrancho.com>
Re: String functions? <kkk@elrancho.com>
Re: substition problem <jdf@pobox.com>
Re: substition problem (Martien Verbruggen)
Re: Text:CSV can't handle german characters <monty@primenet.com>
Re: What are some ways to connect to mysql server on a <nospam.newton@gmx.li>
Re: What's wrong with this script? <kkk@elrancho.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 28 Jan 2001 05:25:34 GMT
From: ayeletma1@my-deja.com
Subject: Re: Allocating ports in perl
Message-Id: <950aga$2jc$1@nnrp1.deja.com>
In article <903493374NickCondon@132.146.16.23>,
nickco3@yahoo.co.uk (Nick Condon) wrote:
> ayeletma1@my-deja.com wrote in <94opki$ul6$1@nnrp1.deja.com>:
>
> >I need to allocate a port and check port status from a perl script.
> >Is there a function or a package I can use?
>
> A serial/parallel port? A TCP socket? Tell us more.
>
A TCP socket. I want to be able to find from a perl program which
program use a certain socket and what is the port status.
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Sun, 28 Jan 2001 10:24:46 +0100
From: otto.wyss@bluewin.ch (Otto Wyss)
Subject: Re: Calling rsync with "system" does not work
Message-Id: <1enxv1f.pv8rv114qifcwN%otto.wyss@bluewin.ch>
> > perldoc -q backticks told me I need to look at system
> > perldoc -q system told everthing else but nothing about system()
> > perldoc -f system was not clear enough for me
> > perldoc -q `string` did not work
> > Of course I haven't tried "string" without backticks.
>
> perldoc -f system is the right place to look, and it tells you it does
> the same as exec(), aprt from a fork being done first. perldoc -f exec
> tells you all the things I told you, and also gives a pointer to
> execvp(3).
>
Sorry if I ask a silly question but I'm simply too stupid to figure out
how to use any pointer with brackets (i.e. "execvp(3)"), could you show
me the exact command (or how I could figure it out myself)?
> [1] There are places where you definitely want to split things yourself,
> and pass a list. Whenever user input ends up in what you pass to
> system() you should do the splitting yourself, to avoid dangerous shell
> constructions. See perlsec for details.
>
I have allready used all in one string, I'm just asking since I'd like
to know this.
The problem is just because i wrongly concluded the whitespace inside
"--include-from .listfile" not an ordinary shell whitespace since I
though the option and the parameter belongs together. This isn't perls
fault (as I also wrongly concluded before) but rsync should not chokes
on this. To avoid this trap in my scripts I'm already trying to use a
syntax without whitespace between option and parameter.
O. Wyss
------------------------------
Date: Sun, 28 Jan 2001 10:24:47 +0100
From: otto.wyss@bluewin.ch (Otto Wyss)
Subject: Re: Calling rsync with "system" does not work
Message-Id: <1enxwhv.1px5e4x7mx5zeN%otto.wyss@bluewin.ch>
> I'd like to have a solution where the contents of "$serverdir",
> "$workfile" where directly piped to rsync if it's possible and would
> appreciate if anybody knows how. Or perhabs the content of the
> ".listfile" could be piped. The advantage would be after rsync'ing
> Packages rsync'ing of the rest would imediatly follow with without
> starting rsync each time again.
>
From the answers it seems it's not possible to use a piping solution. Is
there nobody who could give me a confirmation or give me any clue?
O. Wyss
------------------------------
Date: Sun, 28 Jan 2001 09:36:29 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Calling rsync with "system" does not work
Message-Id: <x74rykt3vn.fsf@home.sysarch.com>
>>>>> "OW" == Otto Wyss <otto.wyss@bluewin.ch> writes:
OW> Sorry if I ask a silly question but I'm simply too stupid to figure out
OW> how to use any pointer with brackets (i.e. "execvp(3)"), could you show
OW> me the exact command (or how I could figure it out myself)?
that (3) refers to the section of man pages on a typical unix system
which contains that man page. you sometimes need to use the section
number in a option to man to get the desired page
OW> The problem is just because i wrongly concluded the whitespace inside
OW> "--include-from .listfile" not an ordinary shell whitespace since I
OW> though the option and the parameter belongs together. This isn't perls
OW> fault (as I also wrongly concluded before) but rsync should not chokes
OW> on this. To avoid this trap in my scripts I'm already trying to use a
OW> syntax without whitespace between option and parameter.
you just won't listen. PROGRAMS EXPECT ARGUMENTS TO ALREADY BE WHITE
SPACE SPLIT BY THE SHELL OR CALLING PROGRAM!!!!!
it is not a trap, it is the way ALL UNIX PROGRAMS WORK!!
if it were your way, HOW COULD A PROGRAM TELL THE DIFFERENCE BETWEEN
foo "-x bar"
and
foo -x bar
IS THAT ONE OR TWO ARGUMENTS TO foo?
DO YOU UNDERSTAND YET!!! WHITESPACE SPLITTING MUST BE DONE BEFORE THE
PROGRAM IS EXEC'ED, WHETHER IT IS DONE IN PERL OR THE SHELL.
<my throat is hoarse>
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Sun, 28 Jan 2001 21:30:56 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Calling rsync with "system" does not work
Message-Id: <slrn977t70.vht.mgjv@martien.heliotrope.home>
On Sun, 28 Jan 2001 10:24:46 +0100,
Otto Wyss <otto.wyss@bluewin.ch> wrote:
>> > perldoc -q backticks told me I need to look at system
>> > perldoc -q system told everthing else but nothing about system()
>> > perldoc -f system was not clear enough for me
>> > perldoc -q `string` did not work
>> > Of course I haven't tried "string" without backticks.
>>
>> perldoc -f system is the right place to look, and it tells you it does
>> the same as exec(), aprt from a fork being done first. perldoc -f exec
>> tells you all the things I told you, and also gives a pointer to
>> execvp(3).
>>
> Sorry if I ask a silly question but I'm simply too stupid to figure out
> how to use any pointer with brackets (i.e. "execvp(3)"), could you show
> me the exact command (or how I could figure it out myself)?
It's a reference to the C function execvp in section 3 of your Unix
manuals.
$ man execvp
would show it.
>> [1] There are places where you definitely want to split things yourself,
>> and pass a list. Whenever user input ends up in what you pass to
>> system() you should do the splitting yourself, to avoid dangerous shell
>> constructions. See perlsec for details.
>>
> I have allready used all in one string, I'm just asking since I'd like
> to know this.
Ok. A wish to acquire knowledge, and understanding, is always admirable.
> The problem is just because i wrongly concluded the whitespace inside
> "--include-from .listfile" not an ordinary shell whitespace since I
> though the option and the parameter belongs together. This isn't perls
> fault (as I also wrongly concluded before) but rsync should not chokes
> on this. To avoid this trap in my scripts I'm already trying to use a
> syntax without whitespace between option and parameter.
The standard way to pass arguments to a program on Unix (and on many
other systems) is from the command line. When you type something like
this in your shell:
$ command a1 a2 a3 a4
your program receives those four command line arguments in an array. For
C programs they're passed in argv
int main(int argc, char *argv[])
{
}
and the first element of argv is the program name, and the 2nd, 3rd, 4th
and 5th are "a1", "a2", "a3" and "a4" respectively. Perl programs
receive these arguments in the @ARGV array, and the above invocation
would end up with an @ARGV of ("a1", "a2", "a3", "a4").
Argument processing is built on top of this mechanism. It is not
anything special to the shell, or to the exec calls involved. It's the
program's responsibility to parse arguments. Traditionally, arguments
have started with a - (or with --). Some of these arguments require an
extra argument. The program will read the next command line argument for
that.
$ command -a1 a2 -a3 a4
If the program sees that an argument is -a1, and it expects another
argument for that, it'll read the next command line argument, and use
that. But there are still four arguments passed to the program. The fact
that some of them have a - in front of them means nothing to the shell
or to the exec calls. They're space separated separate arguments.
This is what you need to be aware of when invoking programs with
system() when splitting up the arguments yourself. Now, I am going to
say this for the last time:
Imagine typing the command at the shell prompt. Knowing that the shell
splits lines up by whitespace, and invokes execvp with a list of
arguments, should tell you how to do it for Perl's system().
system("command", "-a1", "a2", "-a3", "a4");
Again: there is nothing special about the relationship between -a1 and
a2, except from the point of view of the program you invoke. And that
program has been designed to take these two as separate arguments.
You can ask why, but that's a non-question; it should be unasked. This
is how it is. This is how it has been for a long, long time. programs
generally don't themselves split up arguments by whitespace, becasue
they would break too many things. They join up things that need to be
joined up, according to predetermined rules. The shells use whitespace
as a separator, and that's how it is.
How do you pass a single argument with a space in it to a program from
your shell?
$ command "Stuff with spaces" other\ stuff\ with\ spaces
The above invokes command with two arguments: "Stuff with spaces" and
"other stuff with spaces".
Now, this has gotten far out of the realms of Perl, and deeply into the
general programming practices on Unix, and the interfaces on Unix. I
suggest you have a bit of a think about it all, before posting again.
alternatively, you could go to comp.unix.programmer, and see if they can
explain it to you any better.
Martien
--
Martien Verbruggen |
Interactive Media Division | That's funny, that plane's dustin'
Commercial Dynamics Pty. Ltd. | crops where there ain't no crops.
NSW, Australia |
------------------------------
Date: Sun, 28 Jan 2001 21:33:06 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Calling rsync with "system" does not work
Message-Id: <slrn977tb2.vht.mgjv@martien.heliotrope.home>
On Sun, 28 Jan 2001 10:24:47 +0100,
Otto Wyss <otto.wyss@bluewin.ch> wrote:
>> I'd like to have a solution where the contents of "$serverdir",
>> "$workfile" where directly piped to rsync if it's possible and would
>> appreciate if anybody knows how. Or perhabs the content of the
>> ".listfile" could be piped. The advantage would be after rsync'ing
>> Packages rsync'ing of the rest would imediatly follow with without
>> starting rsync each time again.
>>
> From the answers it seems it's not possible to use a piping solution. Is
> there nobody who could give me a confirmation or give me any clue?
That depends more on rsync. If rsync can take those pieces of
information from stdin, then yes, it is possible. To find out how, read
perlipc, perlopen, and maybe the entry on open() in perlfunc.
But I honestly don't see why that would make anything any better, or
easier.
Martien
PS. This is the end of this thread for me.
--
Martien Verbruggen |
Interactive Media Division | Failure is not an option. It comes
Commercial Dynamics Pty. Ltd. | bundled with your Microsoft product.
NSW, Australia |
------------------------------
Date: 28 Jan 2001 01:29:45 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: Cool way to learn Perl?
Message-Id: <66j0chpi.fsf@pobox.com>
jqcordova@my-deja.com writes:
> I've spent the last couple of years building well-known e-commerce
> sites using Open Source code.
I see you've added subjects to your sentences. Here's one you might
consider adding:
"I've been killfiled."
*plonk*
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Sun, 28 Jan 2001 07:07:43 GMT
From: jqcordova@my-deja.com
Subject: Re: Cool way to learn Perl?
Message-Id: <950gfu$6ou$1@nnrp1.deja.com>
Uri - I'd like to respond to your remarks.
(1) I'm sorry if my post annoyed you. Consider my last post as the last
top-level thread in this newsgroup.
(2) I didn't see any follow up about the site being broken. Perhaps you
could point me to the posting?
(3) As for taking a refresher course in web design, I've architected
and managed some of the highest-traffic e-commerce sites in the world.
So, I probably know what I'm doing in that area.
(4) My experience is that anything that takes hundreds of pages to
learn is just not worth learning for most people. However, I don't
think Perl falls into that category. In fact, I think Perl programming
is one of the easiest things to learn. Proof of this came in my last
job where I successfully taught jr. programmers to be productive in
under 2 weeks.
(5) Finally, people *do* care about the CodeCity website. It's had an
overwhelming response since being launched a week ago. I'm getting
feedback from many programmers whom I've been mentoring that
they think it's a fun way to climb the learning curve. In the worst
case, they say it's just plain different. However, I'm sure it's not
for everyone. For example, you may not like it.
I'm guessing that by the tone of your response, you consider yourself a
Perl expert. If that's true, I invite you to author some quizzes on
CodeCity and help me teach the 20-something kids how to write Perl code.
Regards,
Jeff C.
In article <x77l3gthg8.fsf@home.sysarch.com>,
Uri Guttman <uri@sysarch.com> wrote:
> >>>>> "j" == jqcordova <jqcordova@my-deja.com> writes:
>
> j> I've spent the last couple of years building well-known e-
commerce
> j> sites using Open Source code. Turns out that I spent a fair
amount of
> j> time teaching Perl to jr. programmers. I found that the most
effective
> j> way to impart knowledge was the so-called Socratic method of
> j> question/answer. I got so tired of going through the
question/answer
> j> ritual with each new engineer, that I put together a website
> j> www.codecity.com to do the job for me. Now, it's taken on a life
of
> j> it's own and I thought I would tell this group about it as you
may find
> j> it useful too. If you could provide some feedback and maybe even
submit
> j> a quiz or two through the site, it would be highly appreciated.
>
> hey, stop spamming this post. you have done this at least 3 times and
no
> one cares about your site. the one followup i saw said your perl test
is
> broken. sounds like you could use a refresher course in web design.
>
> and considering it takes at least 2-300 pages of non-socratic text to
> write even a basic perl tutorial, i wonder how many questions and
> answers you would have to create to cover all of that, let alone the
> 1000 pages of docs that come with perl.
>
> uri
>
> --
> Uri Guttman --------- uri@sysarch.com ----------
http://www.sysarch.com
> SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX
Consulting
> The Perl Books Page ----------- http://www.sysarch.com/cgi-
bin/perl_books
> The Best Search Engine on the Net ----------
http://www.northernlight.com
>
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Sun, 28 Jan 2001 11:17:29 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: FAQ status and reposts, was Re: FAQ 1.5: What is perl6?
Message-Id: <Pine.LNX.4.30.0101281116170.13564-100000@lxplus003.cern.ch>
On Sat, 27 Jan 2001, Chris Fedde wrote:
> Nearly all the changes and recomendations that have been posted or
> mailed to the Faq Server are being integrated into my copy of the
> perlfaq?.pod files. As the modifications come I'm also posting
> patches to the perlfaq-suggestions@perl.com address.
That's excellent. You're a public benefactor ;-)
all the best
------------------------------
Date: Sun, 28 Jan 2001 17:38:20 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: help installing libwww-perl-5.50 from pc to host
Message-Id: <slrn977fis.vht.mgjv@martien.heliotrope.home>
On Sat, 27 Jan 2001 18:57:05 -0800,
whitetigercat <whitetiger@pinc.com> wrote:
> Hi All,
[installing modules]
> I've gleaned over the web looking for ways to get around all this and
> yes it seems I can install this myself. Unfortunately there seems to
> be very little out there about how to do this if you aren't the
> operator (with root access). I understand I can install this module in
> a directory in my own webspace and access it from there.
Yep. You can. It's described in the Perl FAQ, section 8, under the
questions:
How do I install a module from CPAN?
How do I keep my own module/library directory?
How do I add the directory my program lives in to the
module/library search path?
How do I add a directory to my include path at runtime?
The Perl FAQ is installed wherever Perl is installed. It's accessible
with man, perldoc or as HTML, depending on the system you're on.
Martien
--
Martien Verbruggen | Since light travels faster than
Interactive Media Division | sound, isn't that why some people
Commercial Dynamics Pty. Ltd. | appear bright until you hear them
NSW, Australia | speak?
------------------------------
Date: 28 Jan 2001 06:59:00 GMT
From: jcdixon@aol.com (JCDixon)
Subject: Mysterious inconsistent script behavior
Message-Id: <20010128015900.08409.00000790@ng-cg1.aol.com>
First... my apologies. I've already brought this up by piggybacking onto
another thread on what appeared to be a similar problem, but I think it just
confused things.
I have a script that works_almost_all the time. It is a relatively minor
revision of a pretty large CGI script that has been running trouble-free for
several months. It opens a template file (specified as an argument in the URL)
which in turn opens a data file (or files) and creates finished HTML code,
which is passed to the client.
Here's the trouble: it returns the deadly 500 error when I call it from my
machine at home (IE 5.5, Win95), or from the machine at my office (IE 4.0,
Win95) - but_no_where_else! I've called everyone I know this weekend to have
them try it, and_no_one_else_has been able to generate the error - it works
just as expected for everybody.
The web hosting company says the server logs identify the error as "premature
end of script headers." No additional information is available in the log.
Here's what I've already eliminated as possible causes:
1. Content-type: text/HTML\n\n. Yup, it's in there. And I can find no logical
path that would keep it from being returned to the client.
2. Perl path. I've checked it with the folks at the web hosting company.
They've recently moved Perl to a new spot on the server, while keeping it in
the old location for a while, too. I've updated the script with the new
location, but the change did not fix the problem.
3. Corrupted browser or cached error message. Going into this morning, I had
IE 5.0 at home. Just to be on the safe side, I installed IE 5.5 SP1 this
afternoon, so I have a fresh install. And yes... I've repeatedly cleared my
History folder and Temporary Internet Files folder to make sure the dang thing
isn't caching the error message.
4. Script Security. Yes... my script has some security built into it, and both
the affected computers have login privileges that none of the others do. But
the security does one of two things: returns an error page (Golly... you don't
have access to this page, pardner) or simply doesn't merge the secured data.
That does_not_mean the Content-type header is skipped; I've checked to be sure.
5. Al Gore. He may have invented the Internet, but I'm_pretty_sure he had
nothing to do with this! :)
Other than that, I'm out of ideas. My brain is like fried mush from trying to
puzzle this out over the past week, and I could really use a fresh idea to
investigate. Please let me know if I can amplifiy or clarify anything - and
thanks to all!
------------------------------
Date: Sun, 28 Jan 2001 03:16:39 -0600
From: "John Michael" <johnm@acadiacom.net>
Subject: New Locking problem
Message-Id: <3a73e527@news.acadiacom.net>
How can you import both of these methods at the same time.
use Fcntl;
use Fcntl ':flock';
I have a script that uses:
LOCK_EX
LOCK_SH
&
O_RDONLY
It will not work unless I have both use lines in the top of the script.
Is there a way to import all of them with one use statement.
Thanks
John Michael
------------------------------
Date: Sun, 28 Jan 2001 04:19:47 -0600
From: "John Michael" <johnm@acadiacom.net>
Subject: Re: New Locking problem
Message-Id: <3a73f3e3@news.acadiacom.net>
Never Mind.
I found it:
use Fcntl qw(:DEFAULT :flock);
Thanks anyway.
Tremendous thanks to: Garry Williams for all of his previous help.
This list is great.
"John Michael" <johnm@acadiacom.net> wrote in message
news:3a73e527@news.acadiacom.net...
> How can you import both of these methods at the same time.
> use Fcntl;
> use Fcntl ':flock';
> I have a script that uses:
> LOCK_EX
> LOCK_SH
> &
> O_RDONLY
>
> It will not work unless I have both use lines in the top of the script.
> Is there a way to import all of them with one use statement.
> Thanks
> John Michael
>
>
>
------------------------------
Date: Sun, 28 Jan 2001 06:38:13 GMT
From: jqcordova@my-deja.com
Subject: Re: New way to learn Perl?
Message-Id: <950eol$5io$1@nnrp1.deja.com>
There's more than one answer that is correct. I was trying to keep with
the philosophy that there is often more than one way to do things in
Perl. In my opinion, that is one of the things that makes it a neat
language.
In article <Guzc6.6$c_1.23430@news4.rdc1.on.home.com>,
"Studio 51" <leekembel@hotmail.com> wrote:
> <jqcordova@my-deja.com> wrote in message
news:94sqbc$flf$1@nnrp1.deja.com...
> > about it as you may find it useful too. If you could provide some
> > feedback and maybe even submit a quiz or two through the site, it
would
> > be highly appreciated.
>
> QUESTION: How would you initialize an array @a of length 100 to have
all
> values equal -1.
> (a) for( $i=0; $i < 100; $i++ ) {$a[$i] = -1};
> (b) @a = (-1) x 100;
> (c) @a = map {-1} @a;
>
> I answered (a), even though the ';' is misplaced, but I was wrong
(according
> to the quiz anyway). So I hit back and tried the other 2 answers, but
they
> were both wrong as well. After that I decided either the quiz was
rigged, or
> I don't know as much about Perl as I thought I did.
>
> There were a few other questions that wouldn't accept any answer as
well.
>
> LKembel
>
>
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Sun, 28 Jan 2001 09:22:51 +0100
From: Christopher Kleinheitz <c-kleinheitz@freenet.de>
Subject: Re: Perl for Windows applications: when
Message-Id: <3A73D6DB.C2694A64@freenet.de>
Hi,
Mario schrieb:
> Is a visual environment of Perl on the road? Something like borland c++
> builder to be short.
>
> I have read of a Microsoft Visual Perl beta version.
There is Visualperl from ActiveState beta 2. You can find out more at
http://www.ActiveState.com/Products/VisualPerl
But you need first the VisualStudio .Net Beta from Microsoft
http://www.msdn.microsoft.com
HTH
Chris
--
Christopher Kleinheitz Offenburg Germany
http://jahresarbeit.virtualave.net
Die Welt ist eine Datenbank
------------------------------
Date: 28 Jan 2001 01:20:47 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: Quick RegExp Question
Message-Id: <itn0ci4g.fsf@pobox.com>
"Paul Burney" <nospam@nospam.edu> writes:
> I'm trying to write a small filter that will take an HTML file and
> remove the top and bottom. That is, everything until the end of the
> <body> tag and everything after the last </body> tag.
The other answer (from tigra) was excellent. I'll add to it that you
might consider using HTML::Parser for jobs like this.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: 28 Jan 2001 01:26:17 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: Reading/displaying a raw character
Message-Id: <elxochva.fsf@pobox.com>
"Richard Muller" <rlmuller(at)msn.(dot)(deletethis).com> writes:
> print "\nGot response \"" . $c . \"\"\n";
^
Is this really your source code?
Does that really compile?
Didn't you mean
print "\nGot response \"$c\"\n";
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: 28 Jan 2001 01:31:38 -0500
From: Omri Schwarz <ocschwar@mit.edu>
Subject: regex question: @ counterpart to $1 et al?
Message-Id: <oct3de4kx11.fsf@nerd-xing.mit.edu>
Greetings.
I wrote this script in order to sort out these files
I'm automatically generating. It works
for filenames of the regex /\D*(\d+)\D*(\d+)\D*/
variety and sorts them by the two numbers within.
I thought I'd write something that works for
more complex regexs. Hence my question.
Script below:
#!/usr/bin/perl
#
@refs = [];
while (<>) {
chomp;
/\D*(\d+)\D*(\d+)\D*/;
$first = $1; $second = $2;
if (!$refs[$first]) {
$refs[$first] = [];
}
$refs[$first][$second] = $_;
# print "--- $refs[$first][$second]\n";
}
foreach $ref (@refs) {
foreach $item (@{$ref}) {
if ($item) {
print "$item\n";
}
}
}
--
Omri Schwarz ---
Timeless wisdom of biomedical engineering:
"Noise is principally due to the presence of the
patient." -- R.F. Farr
------------------------------
Date: Sun, 28 Jan 2001 17:44:57 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: regex question: @ counterpart to $1 et al?
Message-Id: <slrn977fv9.vht.mgjv@martien.heliotrope.home>
On 28 Jan 2001 01:31:38 -0500,
Omri Schwarz <ocschwar@mit.edu> wrote:
>
> Greetings.
>
> I wrote this script in order to sort out these files
> I'm automatically generating. It works
> for filenames of the regex /\D*(\d+)\D*(\d+)\D*/
> variety and sorts them by the two numbers within.
>
> I thought I'd write something that works for
> more complex regexs. Hence my question.
It wouldn't hurt to repeat the question, a little more elaborately, in
the body of your text:
Subject: Re: regex question: @ counterpart to $1 et al?
You're looking for an array equivalent of all the $<digits> variables,
right? There is none. No bultin at least. But you can do something like:
> @refs = [];
> while (<>) {
>
> chomp;
> /\D*(\d+)\D*(\d+)\D*/;
my @match = /\D*(\d+)\D*(\d+)\D*/;
Now $match[0] will contain the same as $1 would have contained,
$match[135] the same as $136, etc.
Is that what you were looking for?
Martien
--
Martien Verbruggen |
Interactive Media Division | I'm just very selective about what I
Commercial Dynamics Pty. Ltd. | accept as reality - Calvin
NSW, Australia |
------------------------------
Date: 28 Jan 2001 02:36:47 -0500
From: Omri Schwarz <ocschwar@mit.edu>
Subject: Re: regex question: @ counterpart to $1 et al?
Message-Id: <octpuh8b01c.fsf@nerd-xing.mit.edu>
mgjv@tradingpost.com.au (Martien Verbruggen) writes:
> On 28 Jan 2001 01:31:38 -0500,
> Omri Schwarz <ocschwar@mit.edu> wrote:
> >
> > Greetings.
> >
> > I wrote this script in order to sort out these files
> > I'm automatically generating. It works
> > for filenames of the regex /\D*(\d+)\D*(\d+)\D*/
> > variety and sorts them by the two numbers within.
> >
> > I thought I'd write something that works for
> > more complex regexs. Hence my question.
>
> It wouldn't hurt to repeat the question, a little more elaborately, in
> the body of your text:
>
> Subject: Re: regex question: @ counterpart to $1 et al?
>
> You're looking for an array equivalent of all the $<digits> variables,
> right? There is none. No bultin at least. But you can do something like:
>
> > @refs = [];
> > while (<>) {
> >
> > chomp;
> > /\D*(\d+)\D*(\d+)\D*/;
>
> my @match = /\D*(\d+)\D*(\d+)\D*/;
>
> Now $match[0] will contain the same as $1 would have contained,
> $match[135] the same as $136, etc.
>
> Is that what you were looking for?
Yes!
Thank you!
--
Omri Schwarz ---
Timeless wisdom of biomedical engineering:
"Noise is principally due to the presence of the
patient." -- R.F. Farr
------------------------------
Date: Sun, 28 Jan 2001 12:34:09 +0200
From: "Dan" <kkk@elrancho.com>
Subject: String functions?
Message-Id: <950se3$72d$1@news.kolumbus.fi>
I have a couple of newbie questions.. How do I store the first three
characters of a string into another string? And how can I get the length of
a string? Thanks for any help...
------------------------------
Date: Sun, 28 Jan 2001 12:52:58 +0200
From: "Dan" <kkk@elrancho.com>
Subject: Re: String functions?
Message-Id: <950thd$8lb$1@news.kolumbus.fi>
Sorry for the post. I believe I found it in the FAQ.
"Dan" <kkk@elrancho.com> wrote in message
news:950se3$72d$1@news.kolumbus.fi...
> I have a couple of newbie questions.. How do I store the first three
> characters of a string into another string? And how can I get the length
of
> a string? Thanks for any help...
>
>
------------------------------
Date: Sun, 28 Jan 2001 12:55:02 +0200
From: "Dan" <kkk@elrancho.com>
Subject: Re: String functions?
Message-Id: <950tl9$8rs$1@news.kolumbus.fi>
No... Still wondering how to get the length of the string ;)
"Dan" <kkk@elrancho.com> wrote in message
news:950thd$8lb$1@news.kolumbus.fi...
> Sorry for the post. I believe I found it in the FAQ.
>
> "Dan" <kkk@elrancho.com> wrote in message
> news:950se3$72d$1@news.kolumbus.fi...
> > I have a couple of newbie questions.. How do I store the first three
> > characters of a string into another string? And how can I get the length
> of
> > a string? Thanks for any help...
> >
> >
>
>
------------------------------
Date: 28 Jan 2001 01:27:38 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: substition problem
Message-Id: <ae8ccht1.fsf@pobox.com>
Peter <anon@anon.com> writes:
> I'm having trouble substituting these two strings using the substitution
> operator. I'm getting syntax errors, I don't know what needs a backslash
> and what doesn't.
You didn't post your code, so there's no telling where you've gone
wrong.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Sun, 28 Jan 2001 17:47:25 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: substition problem
Message-Id: <slrn977g3t.vht.mgjv@martien.heliotrope.home>
On Sat, 27 Jan 2001 14:12:48 -0800,
Peter <anon@anon.com> wrote:
> I'm having trouble substituting these two strings using the substitution
> operator. I'm getting syntax errors, I don't know what needs a backslash
> and what doesn't.
Neither do we. You haven't shown us your code. You haven't even shown us
the error messages. Nothing. I, personally am not a clairvoyant, and
even though many people here are good at guessing, they need some little
clue at least to guess at.
The perlre documentation can probably guide you along. You migth also
want to have a look at the \Q and \E patterns, and the quotemeta
function, described in perlfunc.
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | "Mr Kaplan. Paging Mr Kaplan..."
NSW, Australia |
------------------------------
Date: 28 Jan 2001 08:22:19 GMT
From: Jim Monty <monty@primenet.com>
Subject: Re: Text:CSV can't handle german characters
Message-Id: <950krr$t5g$1@nnrp1.phx.gblx.net>
Marc Beck <marc.beck@bigfoot.com> wrote:
> I just integrated the Text::CSV::parse method into my Script to convert
> a CSV to a SQL-Table.
>
> The Problem with this module is that it won't handle any strings
> containing =E4, =F6, =FC or any other special german characters.
> How can the CSV module have to be modified so it will work?
It's been done. Use Text::CSV_XS instead.
--
Jim Monty
monty@primenet.com
Tempe, Arizona USA
------------------------------
Date: Sun, 28 Jan 2001 09:22:30 +0100
From: "Philip 'Yes, that's my address' Newton" <nospam.newton@gmx.li>
Subject: Re: What are some ways to connect to mysql server on a remote host?
Message-Id: <s7l77tks2hj9pm0elp11djcl89ol0c0eku@4ax.com>
On 26 Jan 2001 21:30:29 GMT, The WebDragon <nospam@nospam.com> wrote:
> Connecting to a SQL server on a host remote from the local domain group
SQL Server? Or MySQL server? (Microsoft or TcX?)
> (such as a group of local servers at an ISP/service, one web, one SQL,
> etc -- this is 'remote but local' and I'm looking for 'remote but
> remote' more or less :)
>
> A> is it possible?
Yes. I do it frequently. (Condition: the MySQL server is reachable by TCP/IP and
it allows connections from your IP address. The first should be easy to
ascertain, the second depends on your MySQL configuration.)
> B> what am I overlooking in thinking this is possible?
Don't know. All of these work for me:
$dbh = DBI->connect("dbi:mysql:$database:$host", $user, $password, \%attr);
$dbh = DBI->connect("dbi:mysql:$database;$host", $user, $password, \%attr);
$dbh = DBI->connect("dbi:mysql:host=$host;database=$database",
$user, $password, \%attr);
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Sun, 28 Jan 2001 12:36:10 +0200
From: "Dan" <kkk@elrancho.com>
Subject: Re: What's wrong with this script?
Message-Id: <950sht$78a$1@news.kolumbus.fi>
Thanks, I didn't notice that
"Wyzelli" <wyzelli@yahoo.com> wrote in message
news:3l6c6.10$Gf5.4108@vic.nntp.telstra.net...
> "Dan" <kkk@elrancho.com> wrote in message
> news:94pq50$a5e$1@news.kolumbus.fi...
>
> <snip>
>
> Aside from the things that mark has pointed out, it would appear that you
> are printing two headers,...
>
> > #!/usr/local/bin/perl
> > print ("Content-type: text/html\n\n");
>
> Here
>
> > use CGI qw(:standard);
> > my $c = new CGI;
> >
> > ### READ PARAMETER i ###
> >
> > if($c->param())
> > {
> > $id = $c->param('i');
> > }
> >
> > print header;
>
> And Here.
>
> > print start_html('wavetable.net - add plugin');
> > print (start_form,
>
> <snip>
>
> You probably don't need the first one.
>
> Wyzelli
> --
> #Modified from the original by Jim Menard
> for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
> wall,\n";
> print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
> $_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
> wall\n\n";}print'*burp*';
>
>
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 160
**************************************