[17542] in Perl-Users-Digest
Perl-Users Digest, Issue: 4962 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 24 14:10:36 2000
Date: Fri, 24 Nov 2000 11:10:15 -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: <975093015-v9-i4962@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 24 Nov 2000 Volume: 9 Number: 4962
Today's topics:
Re: newbie pipe question <shallow@mail.com>
Re: newbie pipe question <W.Hielscher@mssys.com>
Re: newbie pipe question <thing1fl.spam.me.not@bigfoot.com>
Re: Perl "save file" formatting text ... please assist <ducott@intergate.ca>
Re: Perl "save file" formatting text ... please assist (Tad McClellan)
Re: Perl "save file" formatting text ... please assist (Tad McClellan)
Re: perl options (Flint Slacker)
Re: perl options (Tad McClellan)
Re: perl options (Flint Slacker)
Re: perl parser embedding nobull@mail.com
Re: perl parser embedding nobull@mail.com
perl sysadmin script <razorlines@hotmail.com>
Read File into Array? (was Re: newbie pipe question) (abuse@newsguy.com)
Re: Regex question about \x$1 theredviper@my-deja.com
Re: Regex question about \x$1 <W.Hielscher@mssys.com>
Re: Regex question about \x$1 <jeffp@crusoe.net>
Re: Regex question re: \x$1 <bart.lateur@skynet.be>
Re: Regex question re: \x$1 (Tad McClellan)
Re: Script Request (Tad McClellan)
Re: Socket connection - TCP client. (Mark W. Schumann)
Re: splitting a string into an array and preserving the (Rafael Garcia-Suarez)
Re: splitting a string into an array and preserving the (Tad McClellan)
Stripping carriage returns <marcus@allinonemortgage.com>
Re: test post - dont read (Tad McClellan)
Welcome to Tri-State Perl Jobs triperljobs-owner@egroups.com
Re: Welcome to Tri-State Perl Jobs (Randal L. Schwartz)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 24 Nov 2000 14:30:02 -0000
From: Shallowen <shallow@mail.com>
Subject: Re: newbie pipe question
Message-Id: <t1surah4fhn825@corp.supernews.com>
Why not read the file into an array:
open(FILE,"myfile");
@array = FILE;
foreach $line (@array) {
$line =~ s/\\/\\/gi;
}
This will do it, albeit ina few more lines, and has the added advantage of
having a regexp that no-one will understand and which also looks like a
giant W. What more could you ask for? =)
-S
nobull wrote:
>
>
> satkinson@skydesk.com writes:
>
> > I have a UNIX perl script where I want to convert UNIX style paths to
> > DOS style path in a pipe. From the shell I'd do something like this:
> >
> > cat myfile | tr '/' '\'
>
> Would you really? Gives me an error must be you have a different
> shell. Does it actually work though?
>
> And would you really go for the "useless use of cat award"?
>
> > However, I can't get the following to work in perl:
> >
> > open(FILE,"cat myfile | tr '/' '\' |");
>
> If it doesn't work at the shell prompt then I would not expect it to
> work when called from Perl.
>
> > If get not translations when I read from the pipe. What am I doing
> > wrong?
>
> You mean appart from using the external tr program when there's a
> perfectly good Perl builtin function to do the same thing and which
> even has the same name?
>
> --
> \\ ( )
> . _\\__[oo
> .__/ \\ /\@
> . l___\ # ll l\ ###LL LL\
--
Posted via CNET Help.com
http://www.help.com/
------------------------------
Date: Fri, 24 Nov 2000 16:23:43 +0100
From: Wolfgang Hielscher <W.Hielscher@mssys.com>
Subject: Re: newbie pipe question
Message-Id: <3A1E87FF.ED5D754C@mssys.com>
Shallowen wrote:
> Why not read the file into an array:
For many reasons:
- the file might be really big
- you have to write the modified contents back to disk
- you don't have to
- ...
And please stop posting wrong code.
Always "use strict"!
> open(FILE,"myfile");
Always check the return value of open, like
open(FILE,"myfile") or die "Can't open file for reading: $!";
> @array = FILE;
Having used "strict" you'd have been noticed that FILE is interpreted as
a bareword. With "no strict" this line assigns the string FILE to the
first emlemet of @array. Probably you intended
@array = <FILE>;
> foreach $line (@array) {
> $line =~ s/\\/\\/gi;
Substitute '\' with '\', heh?!
And why using the /i modifier. I'm really interested in the difference
between an uppercase an a lowercase '\'.
The OP wasn't that wrong by chosing tr. This by the way this was also
mentioned by .nobull whose posting you quoted for no reason in
jeopardy-style
> This will do it,
This code won't do anything, because it's wrong. And even if it was
"corrected", it reads up the file, modifies it in memory without writing
it back, so the original file isn't modified at all.
> and has the added advantage of
> having a regexp that no-one will understand and which also looks like a
> giant W.
Wrong again, I don't think anyone has any problem of understanding the
regexp "\\", it's simply a literal backslash. And a giant W looks
different to me.
> What more could you ask for? =)
For example for a posting that isn't that wrong...
Slowly I'm beginning to belive that there really is a correlation
between jeopardy-style and the contents of usenet postings in this group
At least two lines for the OP:
perl -i.bak -p -e "tr|/|\\|" myfile
But as nobull pointed out that if you have tr on the commandline, why
don't you use it?!
Cheers
Wolfgang
------------------------------
Date: Fri, 24 Nov 2000 12:57:39 -0500
From: "Thing 1" <thing1fl.spam.me.not@bigfoot.com>
Subject: Re: newbie pipe question
Message-Id: <rWxT5.7789$Kk.400344@news1.mia>
You said:
> $line =~ s/\\/\\/gi;
I think you meant:
$line =~ s/\//\\/g;
Broken apart:
s/ # start the substitution
\/ # replace a "/"
/ # what follows is replacement
\\ # replace with "\"
/ # end
g # do this globally (i.e., more than once per line)
You had an "i" after the "g", which means case-insensitive, but that's not
necessary in this case since "/" has no upper or lower case. ;-)
Hope this helps,
Thing 1
"Shallowen" <shallow@mail.com> wrote in message
news:t1surah4fhn825@corp.supernews.com...
> Why not read the file into an array:
>
> open(FILE,"myfile");
> @array = FILE;
> foreach $line (@array) {
> $line =~ s/\\/\\/gi;
> }
>
> This will do it, albeit ina few more lines, and has the added advantage of
> having a regexp that no-one will understand and which also looks like a
> giant W. What more could you ask for? =)
>
> -S
>
> nobull wrote:
> >
> >
> > satkinson@skydesk.com writes:
> >
> > > I have a UNIX perl script where I want to convert UNIX style paths to
> > > DOS style path in a pipe. From the shell I'd do something like this:
> > >
> > > cat myfile | tr '/' '\'
> >
> > Would you really? Gives me an error must be you have a different
> > shell. Does it actually work though?
> >
> > And would you really go for the "useless use of cat award"?
> >
> > > However, I can't get the following to work in perl:
> > >
> > > open(FILE,"cat myfile | tr '/' '\' |");
> >
> > If it doesn't work at the shell prompt then I would not expect it to
> > work when called from Perl.
> >
> > > If get not translations when I read from the pipe. What am I doing
> > > wrong?
> >
> > You mean appart from using the external tr program when there's a
> > perfectly good Perl builtin function to do the same thing and which
> > even has the same name?
> >
> > --
> > \\ ( )
> > . _\\__[oo
> > .__/ \\ /\@
> > . l___\ # ll l\ ###LL LL\
>
> --
> Posted via CNET Help.com
> http://www.help.com/
------------------------------
Date: Fri, 24 Nov 2000 07:10:36 -0800
From: "Robert Valcourt" <ducott@intergate.ca>
Subject: Re: Perl "save file" formatting text ... please assist
Message-Id: <3a1e84d7$1@newsserver1.intergate.ca>
Yikes! I have no idea what that meant! Below is the simple code I use to
write the contents to the file ... maybe you could modify it? :) Super
thanx!
My write code :
open(TOFILE,">../special.dat");
print TOFILE $FORM_DATA{"special"};
close(TOFILE);
"Bernard El-Hagin" <bernard.el-hagin@lido-tech.net> wrote in message
news:slrn91srmn.cag.bernard.el-hagin@gdndev25.lido-tech...
> On Fri, 24 Nov 2000 05:23:31 -0800, Robert Valcourt <ducott@intergate.ca>
wrote:
> >Hello,
>
> Hiyah.
>
> [snip]
>
> >As you can see, SSI ignored the line breaks, and I guess thats to be
> >expected. Here is where I need your help. I'm guessing I need to modify
the
> >perl scripts to ad <br> to all recorded line breaks from the form ... so
the
> >following would occur :
>
> perl -i.bak -pe 's/\n/<br>\n/' <input_file>
>
> Cheers,
> Bernard
> --
> perl -le '$#="Just Another Perl Hacker"; print \Bernard'
------------------------------
Date: Fri, 24 Nov 2000 11:44:12 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Perl "save file" formatting text ... please assist
Message-Id: <slrn91t6ms.uth.tadmc@magna.metronet.com>
Robert Valcourt <ducott@intergate.ca> wrote:
>I have a big problem,
But it is an HTML problem, not a Perl problem.
>Here
>is the problem. SSI won't read the line breaks as illustrated below :
>
>If I type this in the form :
>
> The dog ran fast
>
> The cat ran slow
>
>Perl saves that info to the text file exactly as I wrote it, line breaks and
>all.
>But when I use the SSI command to call the file, the contents get printed
^^^^^^^^^^^
Eh?
How is the output from your SSI getting to a printer?
It usually goes to a web browser or something.
>like this :
>
>The dog ran fastThe cat ran slow
>
>As you can see, SSI ignored the line breaks,
No it didn't.
(I'll bet the web browser ignored them though)
Do a "view source" for what the server sent to the browser. I'll
bet the line breaks are in there just fine...
>and I guess thats to be
>expected.
Right. Browsers are _supposed_ to ignore linebreaks, so SSI is
doing what you told it to do, and the browser is doing what is
is supposed to do.
All that is broken is your code that is called via SSI. It should
be marking line breaks the way line breaks are marked in HTML.
>Here is where I need your help. I'm guessing I need to modify the
>perl scripts to ad <br> to all recorded line breaks from the form
Oh. So you already knew that :-)
s/\n/<br>\n/g; # add a <br> at the end of each line
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 24 Nov 2000 12:32:38 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Perl "save file" formatting text ... please assist
Message-Id: <slrn91t9hm.vbj.tadmc@magna.metronet.com>
[ Please put your comments *following* the quoted text that
you are commenting on.
Please do not quote entire articles. Quote only enough to
establish the context for your comments.
Please do not quote .signatures.
Please limit your line lengths to the conventional 70-72 characters.
Please visit news.announce.newusers
Jeopardectomy performed.
]
Robert Valcourt <ducott@intergate.ca> wrote:
>"Bernard El-Hagin" <bernard.el-hagin@lido-tech.net> wrote in message
>news:slrn91srmn.cag.bernard.el-hagin@gdndev25.lido-tech...
>> On Fri, 24 Nov 2000 05:23:31 -0800, Robert Valcourt <ducott@intergate.ca>
>wrote:
>> I need to modify
>the
>> >perl scripts to ad <br> to all recorded line breaks from the form ... so
>the
>> >following would occur :
>>
>> perl -i.bak -pe 's/\n/<br>\n/' <input_file>
>Yikes! I have no idea what that meant!
Perl's command line switches are documented in the perlrun.pod doc.
The s/// operator is documented in the perlop.pod doc.
(see also perlre.pod)
Go read about them and vanquish ignorance!
>Below is the simple code I use to
>write the contents to the file ... maybe you could modify it? :) Super
>thanx!
>
>My write code :
>
>open(TOFILE,">../special.dat");
$FORM_DATA{special} =~ s/\n/<br>\n/g;
> print TOFILE $FORM_DATA{"special"};
>close(TOFILE);
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 24 Nov 2000 15:02:41 GMT
From: flint@flintslacker.com (Flint Slacker)
Subject: Re: perl options
Message-Id: <3a2081fd.744669@news.tcn.net>
No reason to be an asshole Tad!
Flint
On Thu, 23 Nov 2000 14:03:44 -0500, tadmc@metronet.com (Tad McClellan)
wrote:
>Flint Slacker <flint@flintslacker.com> wrote:
>
>>can improve performance by turning off certain things
> ^^^^^^^^^^^
>>like syntax checking
> ^^^^^^^^^^^^^^^
>
>Is that a joke?
>
>(if so, you forgot the smiley. if not, then you have a severe
> dearth of knowledge about how programming computers works.
>)
------------------------------
Date: Fri, 24 Nov 2000 12:20:43 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: perl options
Message-Id: <slrn91t8rb.vbj.tadmc@magna.metronet.com>
[ Jeopardectomy performed ]
Flint Slacker <flint@flintslacker.com> wrote:
>On Thu, 23 Nov 2000 14:03:44 -0500, tadmc@metronet.com (Tad McClellan)
>wrote:
>
>>Flint Slacker <flint@flintslacker.com> wrote:
>>
>>>can improve performance by turning off certain things
>> ^^^^^^^^^^^
>>>like syntax checking
>> ^^^^^^^^^^^^^^^
>>
>>Is that a joke?
>>
>>(if so, you forgot the smiley. if not, then you have a severe
>> dearth of knowledge about how programming computers works.
>>)
>No reason to be an asshole Tad!
I guess then, that I can imply that you did not forget a smiley?
In that case, we could help you out by describing why "turning
off syntax checking" is an absurd concept.
But I'm disinclined to help now anyway, you seem determined to
maintain your current level of knowledge.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 24 Nov 2000 18:54:46 GMT
From: flint@flintslacker.com (Flint Slacker)
Subject: Re: perl options
Message-Id: <3a20b63e.14123617@news.tcn.net>
You didn't help Tad, you tried to make an ass of me for asking a
question about perl in comp.lang.perl.misc, am I in the wrong group?
Flint
On Fri, 24 Nov 2000 12:20:43 -0500, tadmc@metronet.com (Tad McClellan)
wrote:
>
>[ Jeopardectomy performed ]
>
>
>Flint Slacker <flint@flintslacker.com> wrote:
>>On Thu, 23 Nov 2000 14:03:44 -0500, tadmc@metronet.com (Tad McClellan)
>>wrote:
>>
>>>Flint Slacker <flint@flintslacker.com> wrote:
>>>
>>>>can improve performance by turning off certain things
>>> ^^^^^^^^^^^
>>>>like syntax checking
>>> ^^^^^^^^^^^^^^^
>>>
>>>Is that a joke?
>>>
>>>(if so, you forgot the smiley. if not, then you have a severe
>>> dearth of knowledge about how programming computers works.
>>>)
>
>>No reason to be an asshole Tad!
>
>
>I guess then, that I can imply that you did not forget a smiley?
>
>In that case, we could help you out by describing why "turning
>off syntax checking" is an absurd concept.
>
>But I'm disinclined to help now anyway, you seem determined to
>maintain your current level of knowledge.
------------------------------
Date: 24 Nov 2000 17:44:30 +0000
From: nobull@mail.com
Subject: Re: perl parser embedding
Message-Id: <u98zq9e03l.fsf@wcl-l.bham.ac.uk>
obscuremu@riftsmux.dhs.org writes:
> This may or may not be appropriate to this group. But here is the
> deal.
It is.
> I program/code on what is nown as a MUSH. It stands for
> multi-user-shared-hallucination. What it is is an internet based multiuser
> play/chat area, text only. Within the code has pretty extensive ways of
> 'programming' it to do what you want, unfortunatly many of these 'programs' are
> far from being anything neat, especially for prototyping or upkeeping the code.
>
> What I want to do is add a perl interpeter to the program that would handle perl
> scripts in the same way a webserver would.
When you say "add a perl interpeter to the program ... in the same way
a webserver would" this is somewhat of a non-sequitur.
In general web servers communicate with Perl scripts by starting the
scripts as separate processes and passing information through the
STDIN/STDOUT/STDERR file descriptors and through the environment
variables. The standard describing how this is done is called CGI.
Because the scripts are run as separate processes the server neither
knows nor cares what language the CGI scripts are written in.
The alternative approach really is to integrate the perl interpeter
with the program - as is done in Apache+mod_perl.
> What I would like to do is be able to call scripts within the parser via
> functions utilised within the server that could reach out and use the
> information from within the MUSH's database and return the result without
> blocking the MUSH. Just like what a CGI does when you send a request to a web
> server.
Once again you are contradicting yourself. What CGI does is isolate
the script from the server. You cannot get at the server's internals
from the script because you are running in a separate process. You
probably mean "Just like what mod_perl does when you send a request to an
Apache server"
> If anyone could lead me in the right direction, I would be grateful.
perldoc perlembed
You may also what to look at how Apache+mod_perl works.
Note, rather than embedding Perl in your application it may be more
appropriate to compile your whole application into a library which is
loaded as a module in Perl.
> Hard information-
>
> MUSH3.0 is written in C
> I know almost no C
> I have the source code as well as the meens to compile a new binary.
You are probably going to need to hire a programmer - we _are_ talking
rocket science here!
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 24 Nov 2000 17:46:36 +0000
From: nobull@mail.com
Subject: Re: perl parser embedding
Message-Id: <u97l5te003.fsf@wcl-l.bham.ac.uk>
bernard.el-hagin@lido-tech.net (Bernard El-Hagin) writes:
> On Fri, 24 Nov 2000 09:12:00 GMT, obscuremu@riftsmux.dhs.org
> <obscuremu@riftsmux.dhs.org> wrote:
> >This may or may not be appropriate to this group.
>
> It may not.
>
> comp.infosystems.www.authoring.cgi may or may not find it to be more
> appropriate.
Eh? There's nothing about WWW or CGI in this thread.
The OP _mentions_ CGI as an analogy. He wants his program to be able
use scripts written in Perl as an extension mechanism which in his
mind is similar to what HTTP servers do with CGI. His choice of
analogy is poor but that's not the issue here.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 24 Nov 2000 13:12:19 -0800
From: Term <razorlines@hotmail.com>
Subject: perl sysadmin script
Message-Id: <48mt1tk7no6p41fnf9srcf7bgomskk3fp1@4ax.com>
request for a script:
I am looking to locate a script that does any of the following things,
that can be tweaked into doing exactly what I need (of course, the
less tweaking a stock system needs to run this, the better). I'm
looking to keep track of things like memory usage, i/o wait, disk
usage, load average, maybe at some point I'll want to track
mutex spins, context shifts and such, but not right now. I will then
be making the script output to a file in comma delimited format. What
I am seeking, kind perl gurus, is a script that does any of this,
that I can have permission to either mess with directly, or just look
at for inspiration. If anyone would be so kind as to assist me in this
endeavor, I would be much appreciative.
Logan
if you wish to send something to me directly, use "termm at mindspring
dot com" and thanks again.
------------------------------
Date: 24 Nov 2000 10:09:55 -0800
From: Fake Name/Address (abuse@newsguy.com)
Subject: Read File into Array? (was Re: newbie pipe question)
Message-Id: <8vmatj01q7e@edrn.newsguy.com>
In article <3A1E87FF.ED5D754C@mssys.com>, Wolfgang says...
>
>Shallowen wrote:
>> Why not read the file into an array:
>For many reasons:
> - the file might be really big
I've done this for small files (~200 lines, one line per array element), but I'm
embarking on a project with files as long as 250,000 lines. Is there a point
beyond which it's practical to slurp a file into an array like this? Is this a
RAM issue? Or should it NEVER be done?
> - you don't have to
What is the alternative? Is it better just to process each line as it's read in?
Thanks for any advice/info.
Steve
funyon
AT
macconnect
DOT
com
------------------------------
Date: Fri, 24 Nov 2000 15:19:49 GMT
From: theredviper@my-deja.com
Subject: Re: Regex question about \x$1
Message-Id: <8vm0uj$3nf$1@nnrp1.deja.com>
Oh well,
So much for doing the conversion all in the regex. I'm sure there is a
way to do it without the extra perlcode. I gave up searching and just
used this.
$myvar = "he says %27if it works use it%27";
while ($myvar =~ m/%(..)/){
$my_temp = chr hex($1);
$myvar =~ s/%../$my_temp/;
}
In article <8vln9b$tj5$1@nnrp1.deja.com>,
theredviper@my-deja.com wrote:
> I have what is probably a simple question. Why will the following
> regex not work properly in perl?
>
> s/%(..)/\x$1/g
>
> It kinda seems like this would take %1A and convert the hex 1A to its
> ascii equivilant. Changing the substitution value to \x027 takes the
> literal hex value 27 and replaces the matches accordingly, but I want
> to use the value in $1. I searched dejanews for an example and looked
> in the Mastering Regular Expressions book, but haven't had any luck
> finding an answer. Thanks for any help.
>
> -theredviper
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 24 Nov 2000 16:53:36 +0100
From: Wolfgang Hielscher <W.Hielscher@mssys.com>
Subject: Re: Regex question about \x$1
Message-Id: <3A1E8F00.5580A459@mssys.com>
theredviper@my-deja.com wrote:
> I'm sure there is a
> way to do it without the extra perlcode.
Yes, check out the /e modifier of s///:
my $myvar = "he says %27if it works use it%27";
$myvar =~ s/%(..)/chr hex($1)/ge;
Cheers
Wolfgang
------------------------------
Date: Fri, 24 Nov 2000 11:09:41 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Regex question about \x$1
Message-Id: <Pine.GSO.4.21.0011241101010.714-100000@crusoe.crusoe.net>
On Nov 24, theredviper@my-deja.com said:
>So much for doing the conversion all in the regex. I'm sure there is a
>way to do it without the extra perlcode. I gave up searching and just
>used this.
You could have used a module like CGI or URI::Escape to do the URI
encoding for you. The standard means (sans module) is:
s/%([a-fA-F0-9]{2})/pack "H2", $1/eg;
>while ($myvar =~ m/%(..)/){
> $my_temp = chr hex($1);
> $myvar =~ s/%../$my_temp/;
>}
Use of .. instead of [a-fA-F0-9]{2} is not safe -- URI escape sequences
are only defined for hexadecimal numbers.
And often, when you see yourself in a
if (m/pattern/) { s/pattern/replacement/ }
situtation, chances are you should just avoid the m/pattern/.
>> s/%(..)/\x$1/g
Had you done
s/%([a-fA-F0-9]{2})/"\"\\x$1\""/eeg;
or more readably:
s/%([a-fA-F0-9]{2})/qq!"\\x$1"!/eeg;
it would have worked. The /e modifier means "evaluate the right-hand side
as Perl code" and doubling it means "evaluate it AGAIN, dammit!" (more or
less).
So the first /e creates the code "\x7E" (or whatever $1 held), and the
second /e evaluates THAT to return the character '~'.
But it's probably easier to use the pack() method, though. Less work.
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
PerlMonks - An Online Perl Community http://www.perlmonks.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
------------------------------
Date: Fri, 24 Nov 2000 17:47:09 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Regex question re: \x$1
Message-Id: <q9at1tg6hthb9lqpd0clk1p6k2t3utet4g@4ax.com>
theredviper@my-deja.com wrote:
>I have what is probably a simple question. Why will the following
>regex not work properly in perl?
>
>s/%(..)/\x$1/g
>
>It kinda seems like this would take %1A and convert the hex 1A to its
>ascii equivilant.
Because it only works with literals. The conversion must be done at
compile time, and at that time, $1 isn't set yet. This doesn't "work"
either:
$a = "1A";
print "\x$a";
Try:
s/%(..)/chr hex $1/ge;
--
Bart.
------------------------------
Date: Fri, 24 Nov 2000 09:09:15 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Regex question re: \x$1
Message-Id: <slrn91stkb.uth.tadmc@magna.metronet.com>
theredviper@my-deja.com <theredviper@my-deja.com> wrote:
>I have what is probably a simple question. Why will the following
>regex not work properly in perl?
It does work properly.
Maybe you meant "why doesn't this do what I want?" instead?
>s/%(..)/\x$1/g
Since dot can match any character, what would you want it to do with:
%..
%zz
%%%
%~+
??
>It kinda seems like this would take %1A and convert the hex 1A to its
>ascii equivilant. Changing the substitution value to \x027 takes the
>literal hex value 27 and replaces the matches accordingly, but I want
>to use the value in $1.
The replacement part of s/// is a double quoted string (so is
the pattern part), so it's the same as:
"\x$1"
You only get "one round" of variable interpolation, so the
first round would replace $1 with its value. There is no
second round to interpolate again and pick up the hex escape.
That is what is _supposed_ to happen given your code (ie. you
need different code).
>I searched dejanews for an example
There should be an example already on your hard disk!
See the unescape() function in CGI.pm:
$todecode =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge;
You shouldn't be trying to decode URLs yourself, there are
already modules that will do it (correctly).
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 24 Nov 2000 00:24:58 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Script Request
Message-Id: <slrn91ruta.uei.tadmc@magna.metronet.com>
PotatoeHead <jaymz@nucentrix.net> wrote:
>I'm looking for a script,
So you have already tried a bunch of search engines then?
>Java and/or cgi,
Err, this here is the Perl newsgroup.
If you want something else, post in a newsgroup appropriate to them.
>Any idea as to where I can find something like this?
Wouldn't be too hard to write in Perl, but you appear to
be requiring Java as the implementation language (you
can't write a program in an interface, so "in CGI" is
impossible).
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 24 Nov 2000 11:51:54 -0500
From: catfood@apk.net (Mark W. Schumann)
Subject: Re: Socket connection - TCP client.
Message-Id: <8vm6ba$96f@junior.apk.net>
In article <H14T5.2$nT1.564@vic.nntp.telstra.net>,
Rob <kalinabears@hdc.com.au> wrote:
>Can anyone tell me why the following script always dies at line 10 ?
>$@ gives a 'bad service http' error and $! returns an 'unknown error'.
>If I change "http(80)" to "daytime(13)" it works fine - as long as I
>restrict $host to being either www.hdc.com.au (our proxy server) or
>www.kalinabears.com.au (our website, hosted by hdc) - can't connect to the
>outside world at any port. BTW, I have other standard scripts (using Socket)
>that will open, write to and close connections at port 80 (kalinabears & hdc
>only), but will hang if set to receive anything .
You're right, it's probably a proxy problem.
Have you looked at the LWP modules? They already "know" about proxies.
------------------------------
Date: Fri, 24 Nov 2000 14:18:56 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: splitting a string into an array and preserving the "\n"
Message-Id: <slrn91su7n.q2n.rgarciasuarez@rafael.kazibao.net>
Bernie Cosell wrote in comp.lang.perl.misc:
! rgarciasuarez@free.fr (Rafael Garcia-Suarez) wrote:
!
! } Eric Smith wrote in comp.lang.perl.misc:
! } > I want to split a multi-line scalar into an array. I want each element of
! } > the array to have a line terminated by a "\n".
! } > Problem is that when I split on "\n", then this newline character is lost.
! } >
! } > Of course I can loop through the array and stick it back on again but I
! } > want to do it right when I create the array.
! }
! }
! } my @array = split /(?<=\n)/, $multi_line_string;
! }
! } see the perlre manpage for details.
!
! I just looked and I can't find any docs on '(?<=' in perlre. We're on
! 5.004_004 [I'm hoping to upgrade fairly soon, but I don't have a say in
! that kind of thing].. is this some 5.6 cleverness or did I miss something
! in the 5.4 perlre?
It's here in 5.00503. From perlre:
A zero-width positive lookbehind assertion. For example, /(?<=\t)\w+/
matches a word following a tab, without including the tab in $&. Works
only for fixed-width lookbehind.
--
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Fri, 24 Nov 2000 11:52:04 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: splitting a string into an array and preserving the "\n"
Message-Id: <slrn91t75k.uth.tadmc@magna.metronet.com>
Bernie Cosell <bernie@fantasyfarm.com> wrote:
>rgarciasuarez@free.fr (Rafael Garcia-Suarez) wrote:
>} my @array = split /(?<=\n)/, $multi_line_string;
>}
>} see the perlre manpage for details.
>
>I just looked and I can't find any docs on '(?<=' in perlre. We're on
>5.004_004
perldelta.pod says it was added at 5.005.
>[I'm hoping to upgrade fairly soon, but I don't have a say in
>that kind of thing]
3 years old is an awful lot in "computer years".
It's a bummer having to work with silly people, isn't it :-)
But m///g in list context should work with geriatric perls.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 24 Nov 2000 10:29:02 -0800
From: "Marcus" <marcus@allinonemortgage.com>
Subject: Stripping carriage returns
Message-Id: <GmyT5.4462$FO1.145352@brie.direct.ca>
I am fairly new to perl and I am modifying an exsisting script. It is an
open source shopping cart found at extropia.com. I had the script up and
running on my previous server, but it seems to give an error on my new
server with the same version of perl and both servers are unix based. All
the permissions have been set correctly and all the files are there. I
checked the error log and this is the error:
Illegal character \015 (carriage return) at ./Library/web_store.setup.db
line 4.
(Maybe you didn't strip carriage returns after a network transfer?)
Here is line 4 in the main script:
&require_supporting_libraries (__FILE__, __LINE__,
"./Library/web_store.setup.db");
Does this make any sense to anyone. It is probably something I am
overlooking. Any help or direction appreciated. If you need more info please
let me know. Thanks.
------------------------------
Date: Fri, 24 Nov 2000 11:54:08 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: test post - dont read
Message-Id: <slrn91t79g.uth.tadmc@magna.metronet.com>
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> <Joe@nowhere.com> wrote in comp.lang.perl.misc:
>>test
>
>There are newsgroups for testing. They have "test" in their name.
And you don't get killfiled for making test posts in those newsgroups.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 24 Nov 2000 12:23:18 -0500
From: triperljobs-owner@egroups.com
Subject: Welcome to Tri-State Perl Jobs
Message-Id: <3A1EA405.7191B56D@egroups.com>
=> Looking for a Perl Programmer in the tri-state area?
=> Looking for a Perl Job in the tri-state area?
=> A place where tri-state companies and recruiters can post available
Perl Programming positions, both full time and contract.
=> A place where tri-state Perl job seeking candidates can come to find
available positions and post their resumes and/or portfolios.
To subscribe to the list, send en email to:
triperljobs-subscribe@egroups.com
After you subscribe, to post your job or resume, send to:
triperljobs@egroups.com
http://www.egroups.com/group/triperljobs
------------------------------
Date: 24 Nov 2000 09:30:24 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Welcome to Tri-State Perl Jobs
Message-Id: <m17l5tuvkf.fsf@halfdome.holdit.com>
>>>>> "triperljobs-owner" == triperljobs-owner <triperljobs-owner@egroups.com> writes:
triperljobs-owner> => Looking for a Perl Programmer in the tri-state area?
/me ponders, "which three states?"
Solid, Liquid, Gas?
/me marks this post down in the "loser" column.
:-)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
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 V9 Issue 4962
**************************************