[17993] in Perl-Users-Digest
Perl-Users Digest, Issue: 153 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 26 18:14:13 2001
Date: Fri, 26 Jan 2001 15:10:17 -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: <980550617-v10-i153@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 26 Jan 2001 Volume: 10 Number: 153
Today's topics:
Re: Is Number of Params Limited? *Warning Newbie* <jamas@mindspring.com>
Re: Is Number of Params Limited? *Warning Newbie* <godzilla@stomp.stomp.tokyo>
Re: More efficient than split? whubley@my-deja.com
Re: More efficient than split? <mjcarman@home.com>
New way to learn Perl? jqcordova@my-deja.com
Re: OLE Module for AS Perl 5.6 on NT <carvdawg@patriot.net>
Perl and SQL Programmers Needed-URGENT <jeff@shopclue.com>
Re: Perl Style Guide - uncuddled elses birgitt@my-deja.com
Re: Perl Style Guide - uncuddled elses <uri@sysarch.com>
Please help with the piece of code tuoihong@my-deja.com
Re: Please help with the piece of code <kistler@gmx.net>
Re: POST method problem in a request <junior_s@sympatico.ca>
ps -ef for perl in windows NT keith_paschal@my-deja.com
Re: ps -ef for perl in windows NT <carvdawg@patriot.net>
Re: Regular expression question <godzilla@stomp.stomp.tokyo>
Re: Regular expression question nobull@mail.com
Re: Regular expression question nobull@mail.com
Re: Regular expression question <kjl@inforonics.com>
Re: right place for a mod_perl question? (Gary E. Ansok)
Re: Script to "rotate" the chars in a string. (Christian Kaufhold)
Re: Script to "rotate" the chars in a string. <jdf@pobox.com>
Re: Script to "rotate" the chars in a string. (Abigail)
Re: Script to "rotate" the chars in a string. (James Kufrovich)
Re: sed and Perl <a58289@yahoo.com>
Re: sed and Perl (Greg Bacon)
Re: sed and Perl <jdf@pobox.com>
Re: simple question for probably all of you... about @ <fty@mediapulse.com>
Split losing UTF-8 flag on UTF-8 scalars (Nate Edel)
Re: Syntax Trouble <whataman@home.com>
Re: Syntax Trouble <whataman@home.com>
ternary conditional operator <jhall@ifxonline.com>
Re: ternary conditional operator <uri@sysarch.com>
What are some ways to connect to mysql server on a remo <nospam@nospam.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 26 Jan 2001 15:50:55 -0500
From: Max <jamas@mindspring.com>
Subject: Re: Is Number of Params Limited? *Warning Newbie*
Message-Id: <3A71E32E.824FCBE4@mindspring.com>
<snip>
Kira wrote:
>
> I will treat this issue as html, not Perl. Your
> document source for chemicals, the only page I
> examined, is a mess and barely readable. You have
> nine products listed but two products are each,
> duplicated in your html coding. You actually only
> have seven products, not nine, thus seven key/value
> pairs would be returned, not nine as you expect.
>
> More technical, nine potential returns, but
> two pairs of key/value pairs are duplicated
> thus your program 'sees' only seven products
> which are 'different' from each other.
>
> Your html code is consistently in error as
> well, noted by this snippet:
>
> "$75.<u><sup>.99</sup></u>">
>
> Look at your code following that snippet
> and you will note your error.
>
> So, you have a product page which is not coded
> correctly for actual number of products and,
> your html code contains syntax errors.
>
> My suggestion is you repair your html coding for
> your product listings, test, and discover if you
> don't have better luck, then clean up your
> document source print so it is legible.
>
> Godzilla!
Sheeeesh!
Co-Rupt Data, where oh where are my glasses?
thanks, Kira.
by the by, My code is very readable in my browser, (netscape), and in
my script editor. (WinBatch Studio). But, then again, I have been a
top-down for ten years.
Thanks again:
--
CGI, ASP, PHP, Oh' my,
CGI, ASP, PHP, Oh' my
John M. Smith
------------------------------
Date: Fri, 26 Jan 2001 13:20:49 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Is Number of Params Limited? *Warning Newbie*
Message-Id: <3A71EA31.DD0B281@stomp.stomp.tokyo>
Max wrote:
(Kira wrote:)
(Max wrote:)
> Kira wrote:
> <snip>
> Co-Rupt Data, where oh where are my glasses?
On your face? This is usually where I find my
reading glasses after hours of searching, either
there or under my big butt.
> by the by, My code is very readable in my browser, (netscape), and in
> my script editor. (WinBatch Studio). But, then again, I have been a
> top-down for ten years.
I use a variety of browsers, however, Mozilla/Godzilla
is my favorite as displayed by my header information.
It is my customary habit to generously use newlines,
tabs and spacing for my html documents, rendering my
document source almost textbook perfect. Many forget
document source is a valuable source of information,
especially for debugging bugs. A document source,
by my standards, should clean, crisp and very well
organized to enhance ease in reading.
This notion applies equally to cgi scripts which
print html documents. I have a rather unique, very
much sought after chat script which prints a rather
lengthy html page, equal to two pages of notebook
text at times. Even with cgi generation, I make
sure my scripts generate a clean organized print
for a document source; I refer there frequently
during analysis of problems.
If you would like to view a relatively well organized
document source, click below and the view source. This
fairly much exemplifies my notion of a good document
source for an html page; very easy to read.
http://la.znet.com/~callgirl/index2.html
I am pleased to have been of assistance.
Godzilla!
------------------------------
Date: Fri, 26 Jan 2001 20:35:16 GMT
From: whubley@my-deja.com
Subject: Re: More efficient than split?
Message-Id: <94sn24$cck$1@nnrp1.deja.com>
In article <3a71a9fd.3c46$f5@news.op.net>,
mjd@plover.com (Mark Jason Dominus) wrote:
>
> In article <94s7n8$tbm$1@nnrp1.deja.com>, <whubley@my-deja.com>
wrote:
> >From what I read, split is not very efficient.
>
> Split is extremely efficient, in the sense that it would be very
> difficult to construct an equivalent function that would be faster.
> You have either misunderstood or been deceived. 'unpack' is only
> suitable when the fields have the same width in each record.
In Effective Perl Programming" by Joseph N. Hall and Randal L Schwartz,
page 71, Item 19 titled "Use split for clarity, unpack for efficiency"
the use of split is benchmarked against a pattern match. Pattern match
was found to be significantly faster, but no statistics are provided
(parsing a colon delimited string). The section basically explains
what the section title states.
>
> >Is there a more efficient substitution for split when parsing values
> >from pipe- delimited string of text?
>
> Short of a hand-coded special-purpose routine in C, probably not.
> Even that might not win.
>
> What exactly is the problem here? Is your program running too slowly?
> Is the problem really coming from your use of 'split'? If not, I
> suggest that you are worrying about performance at too low a level.
>
I am writing code that will be processing lots of transactions and I
need performance anywhere I can get it. "Well then just write it in
C." many might say. I won’t go there.
> >I have heard that I can use unpack, but have failed at all attempts
to
> >do so.
>
> Now, let's suppose you have spent an hour attempting to use 'unpack'.
> Let's suppose that you found a way to split the line that was twice as
> fast as using 'split'.
>
> An hour is 3600 seconds. My slow, obsolete P233 system performs
> 25,600 splits per second; in one hour it will split the line 92
> million times.
>
> If your data file contains 100,000 records, your program spends about
> 3.9 seconds splitting. With the hypothetical twice as fast method,
> you will save 1.45 seconds in each run of your program.
>
> You spent 3600 seconds finding the fast method. 3600 / 1.45 is 2482.
> You will have to run your program 2482 times just to break even. Of
> course, you really won't break even, because an hour of the computer's
> time is worth a lot less than an hour of your time.
>
It's all about how fast I can turnaround a transaction.
It sounds like your saying that if I'm looking to be more efficient, I
should look elsewhere within my code? I'm not going to
make it up finding an alternative to split?
> Hope this helps.
This is extremely helpful!! Thank you for the quick response!
>
> --
> @P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona
tsuJ";sub p{
> @p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P
[$f^ord
> ($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^
[P.]/&&
> close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/
\S/;print
>
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Fri, 26 Jan 2001 15:50:04 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: More efficient than split?
Message-Id: <3A71F10C.57709AC9@home.com>
whubley@my-deja.com wrote:
>
> mjd@plover.com (Mark Jason Dominus) wrote:
>>
>> What exactly is the problem here? Is your program running too slowly?
>> Is the problem really coming from your use of 'split'? If not, I
>> suggest that you are worrying about performance at too low a level.
>
> [...]
>
> It's all about how fast I can turnaround a transaction.
>
> It sounds like your saying that if I'm looking to be more efficient, I
> should look elsewhere within my code? I'm not going to
> make it up finding an alternative to split?
What he was saying is that your time as a programmer is worth far more
than the computer's time. For the vast majority of programs, trying to
shave a few fractions of a second off of execution time by building a
better split() is just a waste of (your employer's) money. You could be
writing a lot of new code instead! What you failed to mention is that
you're working on an application for which efficiency is a serious
issue.
If speed really is that important, there are a variety of things you can
do: rewrite the bottlenecks in C, buy better hardware, use mod_perl if
it's a web app., etc. If you're focused on improving your Perl code
itself, then try to find a better algorithm. Optimizing split() doesn't
do that -- it's just a point solution -- which means that should be one
of the last things you try, if at all. A better algorithm means stuff
like not doing anything inside a loop you can do outside of one, getting
rid of nested loops, or caching data instead of recalculating it. Note:
you may have to sacrifice memory save time.
For example: I once inherited some code that had one part which took
about two minutes to run. It was doing a brute force lookup of data from
one array in another one inside a nested loop, and both arrays were
large. By first parsing one of the arrays and building a hash of the
data I was interested in, I was able to subsequently do a simple lookup
as I looped over the other array. Making only one pass through each
array cut the number of times I looped from (M * N) to (M + N). The new
runtime was about six seconds, most of which was spent writing files to
disk. That's a major improvement to the algorithm, and that's the kind
of thing you should be looking for first.
Give it a shot, and good luck.
-mjc
------------------------------
Date: Fri, 26 Jan 2001 21:31:23 GMT
From: jqcordova@my-deja.com
Subject: New way to learn Perl?
Message-Id: <94sqbc$flf$1@nnrp1.deja.com>
I've spent the last couple of years building well-known e-commerce
sites using Open Source code. Turns out that I spent a fair amount of
time teaching Perl (especially object oriented Perl) to jr.
programmers. I found that the most effective way to impart knowledge
was the so-called Socratic method of question/answer. I got so tired of
going through the question/answer ritual with each new engineer, that I
put together a website www.codecity.com to do the job for me. Now,
it's taken on a life of it's own and I thought I would tell this group
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.
Thankyou,
Jeff C.
www.codecity.com
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Fri, 26 Jan 2001 17:15:14 -0500
From: H C <carvdawg@patriot.net>
Subject: Re: OLE Module for AS Perl 5.6 on NT
Message-Id: <3A71F6F2.9FDDFBFC@patriot.net>
Yes. As I seem to remember, it's called Win32::OLE.
wiwo wrote:
> Is there a module compareable to Win32::OLE for AS Perl 5.6 running on NT?
>
> Regards,
> Willi
--
Q: Why is Batman better than Bill Gates?
A: Batman was able to beat the Penguin.
------------------------------
Date: Fri, 26 Jan 2001 22:27:37 GMT
From: "Jeff Garnett" <jeff@shopclue.com>
Subject: Perl and SQL Programmers Needed-URGENT
Message-Id: <tRmc6.4120$pb6.867290@typhoon2.ba-dsg.net>
Financed Software Venture needs Perl & SQL programmers for immediate work.
Contact Jeff Garnett at 914-273-0353 or fax resume to 914-206-4041 or e-mail
jeffgarnett@hotmail.com. Competitive Salary, Bonuses and stock.
------------------------------
Date: Fri, 26 Jan 2001 22:42:13 GMT
From: birgitt@my-deja.com
Subject: Re: Perl Style Guide - uncuddled elses
Message-Id: <94sug4$jhm$1@nnrp1.deja.com>
In article <94shhi$6ok$1@nnrp2.phx.gblx.net>,
Jim Monty <monty@primenet.com> wrote:
> Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> > Bart Lateur <bart.lateur@skynet.be> wrote:
> > > Bleh. I prefer cuddled elses any time.
> >
> > I don't. But that's just another religious war.
>
> [*snip* lengthy discourse on cuddled elses v. uncuddled elses]
>
> > Let's not get into one of these [religious wars] again.
>
> Ok. Good suggestion.
>
> (Oh, by the way: cuddles braces RULE! Now let's have no more
> senseless discussion about this topic, please. ;-)
>
Thanks for the responses and sorry for the question. Was not aware
that this was a question, which had caused religious wars in the
past. As a non native speaker, just couldn't associate something with
"cuddled" (and I thought those things are called brackets, not braces -
sorry again).
--
birgitt
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Fri, 26 Jan 2001 23:01:13 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Perl Style Guide - uncuddled elses
Message-Id: <x78znxvrye.fsf@home.sysarch.com>
>>>>> "b" == birgitt <birgitt@my-deja.com> writes:
b> (and I thought those things are called brackets, not braces -
that is another war topic. :)
() are known universally as parentheses. there are some odd variations
in places. parens is a common abbreviation.
[] are usually called brackets (or redundantly square brackets). i have
seen variations including square braces.
{} are usually called braces (or redundantly curly or squiggly
braces). i have seen them also called curly brackets and other similar
things.
so the most common short names for those in the perl world are parens,
brackets and braces.
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: Fri, 26 Jan 2001 19:18:00 GMT
From: tuoihong@my-deja.com
Subject: Please help with the piece of code
Message-Id: <94sih0$81l$1@nnrp1.deja.com>
I have a piece of code like below:
$command = "/tp/ftp.pl";
$SIG{CHLD} = 'IGNORE';
my $pid = fork;
die "Can't fork: $!" unless defined $pid;
if ($pid == 0) {
# diassociate from process group
if (POSIX::setsid == -1) {
die "Can't setsid: $!";
}
# dissociate from controlling "terminal"
open STDOUT, ">/dev/null";
open STDIN, "/dev/null";
# replace current program with
LOG ("Executing command \"$command\"");
exec "perl $command";
}
print "Content-type: text/plain\n\n";
print "Parent exiting ...\n";
My question is if the line -- exec "perl $command"; -- fails,
say it can't find the file, how to I caught that error message in my
code? Thank you for your help.
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Sat, 27 Jan 2001 00:47:20 +0100
From: Per Kistler <kistler@gmx.net>
Subject: Re: Please help with the piece of code
Message-Id: <3A720C88.CDE8BED3@gmx.net>
tuoihong@my-deja.com wrote:
> exec "perl $command";
> My question is if the line -- exec "perl $command"; -- fails,
> say it can't find the file, how to I caught that error message in my
> code?
Hi
It's in $!
So put the following line below the exec:
die "Exec failed: $!";
Per.
--
Per Kistler, Zurich, Switzerland
------------------------------------------------------------------------
------------------------------
Date: Fri, 26 Jan 2001 19:32:44 GMT
From: "junior" <junior_s@sympatico.ca>
Subject: Re: POST method problem in a request
Message-Id: <whkc6.125548$JT5.4592389@news20.bellglobal.com>
"Jonathan Feinberg" <jdf@pobox.com> wrote in message
news:snm6qj8o.fsf@pobox.com...
> "junior" <junior_s@sympatico.ca> writes:
>
> > I want to make a request via the POST method and I'm lost...
>
> > is there an example that i can view somewhere other than the
> > manpages or the documentaion coming with the packages.
>
> Did you read the lwpcook man page? It has a fairly simple example of
> negotiating a POST.
>
> perldoc lwpcook
thanx!
this is better!
>
> If you've already read that, and you still have questions, please do,
> ahem, *post* here again.
>
> --
> Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
> http://pobox.com/~jdf
------------------------------
Date: Fri, 26 Jan 2001 18:58:16 GMT
From: keith_paschal@my-deja.com
Subject: ps -ef for perl in windows NT
Message-Id: <94shc3$6vv$1@nnrp1.deja.com>
Folks;
Does anyone here know if a there is a way in perl to get a process
listing for processes running on an NT box? (kind of like ps -ef in
Unix)
Thanks for your time.
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Fri, 26 Jan 2001 17:16:15 -0500
From: H C <carvdawg@patriot.net>
Subject: Re: ps -ef for perl in windows NT
Message-Id: <3A71F72F.DC077DC0@patriot.net>
You asked this same question about a week ago...go back and read the
answer...
keith_paschal@my-deja.com wrote:
> Folks;
>
> Does anyone here know if a there is a way in perl to get a process
> listing for processes running on an NT box? (kind of like ps -ef in
> Unix)
>
> Thanks for your time.
>
> Sent via Deja.com
> http://www.deja.com/
--
Q: Why is Batman better than Bill Gates?
A: Batman was able to beat the Penguin.
------------------------------
Date: Fri, 26 Jan 2001 11:09:16 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Regular expression question
Message-Id: <3A71CB5C.974FA470@stomp.stomp.tokyo>
Kauser Ali Karim wrote:
(snippage)
> I need to get rid of the first fifteen charcters
My presumption is you are asking to remove the
first fifteen characters of a string, regardless
of what are those characters.
You will find substring to be quicker and
more efficient for this specific example
over a regex method.
One substring method is below my signature.
Godzilla!
--
TEST SCRIPT:
____________
#!perl
print "Content-type: text/plain\n\n";
$string = "123ABC456DEF789 Save This";
# non-destructive
$new_string = substr ($string, 15, length ($string) - 15);
print "Non-destructive Method:\n\n $new_string";
# destructive
$string = substr ($string, 15, length ($string) - 15);
print "\n\nDestructive Method:\n\n $string";
exit;
PRINTED RESULTS:
________________
Non-destructive Method:
Save This
Destructive Method:
Save This
------------------------------
Date: 26 Jan 2001 19:00:25 +0000
From: nobull@mail.com
Subject: Re: Regular expression question
Message-Id: <u9n1cef88i.fsf@wcl-l.bham.ac.uk>
Kauser Ali Karim <g9karkav@cdf.toronto.edu> writes:
> Subject: Regular expression question
Regular expressions are a wide subject. Conder putting more info in
you subject line. To make space you should omit the word "question".
> Newsgroups: comp.unix.questions,comp.lang.perl.misc
What does this have to do with Unix?
> I need to get rid of the first fifteen charcters
> (which are uppercase letters and numbers) of a line. How
> would I do this using regular expressions.
>
> I know that something like this would work,
> but would only get rid of the first character.
>
> s/[^A-Z0-9]//
No, it would get rid of the first character that was not a
upperalphanumeric.
s/^[A-Z0-9]{15}//;
Of course if you know that the first 15 characters will always be
upperalphanumeric then you can simply use substr().
> Any help would be appreciated
Perl regular expressions are documented in the perlre manpage.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 26 Jan 2001 19:39:09 +0000
From: nobull@mail.com
Subject: Re: Regular expression question
Message-Id: <u9k87if6hu.fsf@wcl-l.bham.ac.uk>
"Godzilla!" <godzilla@stomp.stomp.tokyo> writes:
> Kauser Ali Karim wrote:
>
> (snippage)
>
> > I need to get rid of the first fifteen charcters
>
> My presumption is you are asking to remove the
> first fifteen characters of a string, regardless
> of what are those characters.
>
> You will find substring to be quicker and
> more efficient for this specific example
> over a regex method.
So far so good. You should have quit while you were ahead.
> One substring method is below my signature.
Bzzzt! Anything after the sigsep is _part_ of the signature. There's
no sigsep in your post so this is moot.
> #!perl
Bzzzzt! Missing strictures.
> print "Content-type: text/plain\n\n";
Bzzzzt! Not a CGI question.
> $new_string = substr ($string, 15, length ($string) - 15);
Bzzzt! Third argument of substr should be omitted.
Oh, and you never did answer the OP's question. Sure the OP
_probably_ asked the wrong question but you can't be sure and the
answer to the question he did ask is just as trivial as the answer to
the question you decided to answer.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 26 Jan 2001 15:11:57 -0500
From: "Kurt J. Lanza" <kjl@inforonics.com>
Subject: Re: Regular expression question
Message-Id: <3A71DA0D.AF805ABE@inforonics.com>
Kauser Ali Karim wrote:
>
> Hi,
>
> I need to get rid of the first fifteen charcters
> (which are uppercase letters and numbers) of a line. How
> would I do this using regular expressions.
>
> I know that something like this would work,
> but would only get rid of the first character.
>
> s/[^A-Z0-9]//
>
S/^.{15}//
"man regexp" for a complete description of REs.
------------------------------
Date: 26 Jan 2001 19:38:19 GMT
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: right place for a mod_perl question?
Message-Id: <94sjnb$kar@gap.cco.caltech.edu>
In article <Pine.LNX.4.20.0101251929560.17945-100000@ethyl.addictmud.org>,
Daniel W. Burke <dwb1@home.com> wrote:
>What I ended up doing, and I don't know if this is the best way to go but it
>seems to work on a global scale, I modified every script and added this line
>to the top:
>
>shift if (defined($_[0]));
>
>The "if defined" bit is probably unnecessary, but a co-worker agreed that it
>makes the shift look more useful and avoids being grilled by the B.O.S.S.
>next time he looks at any of our code... ;)
It's not necessary; just shift would work.
>Is there any reason this kind of fix would be bad?
You're making assumptions about what you might find in the @_ array.
(Specifically, that there is at most one unwanted argument.) Also, you're
assuming that this initial value is the only source of bad data -- if
you call &Somefunc from within one of your own functions that takes
arguments, you'll see those arguments appearing in Somefunc.
> Also, if that's the
>apache object, where can I find the documentation on how to use it in that
>form? It just looks like a reference to a scalar....
Now that question *is* better addressed elsewhere -- the mod_perl
documentation or mailing list would be my guess.
-- Gary Ansok
------------------------------
Date: Fri, 26 Jan 2001 21:21:25 +0100
From: usenet@chka.de (Christian Kaufhold)
Subject: Re: Script to "rotate" the chars in a string.
Message-Id: <0t3a71d99di678an64@simia.chka.de>
Uri Guttman <uri@sysarch.com> wrote:
[...]
> just trying a little golf. anyone else?
> so the rules are one liner and the token is in @ARGV
> perl -le'$_=pop;print,substr($_,0,0,chop)while$i++<length' qwert
> qwert
> tqwer
> rtqwe
> ertqw
> wertq
perl -le'$_=pop;print$_=chop().$_ while$i++<length' qwert
perl -le'$_=pop;for$a(1..length){print$_=chop().$_}' qwert
perl -le'map{print$s=chop($s).$s}1..length($s=pop)' qwert
You can even leave away the parentheses with chop(), but then it
gives an warning for ambiguity.
Christian
------------------------------
Date: 26 Jan 2001 16:11:36 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: Script to "rotate" the chars in a string.
Message-Id: <3de6qarb.fsf@pobox.com>
Uri Guttman <uri@sysarch.com> writes:
> so the rules are one liner and the token is in @ARGV
>
> perl -le'$_=pop;print,substr($_,0,0,chop)while$i++<length' qwert
You missed the hole; you must also rotate the reversed input string.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: 26 Jan 2001 21:21:42 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Script to "rotate" the chars in a string.
Message-Id: <slrn973qj6.q5.abigail@tsathoggua.rlyeh.net>
Julien Quint (julien.quint@imag.fr) wrote on MMDCCV September MCMXCIII in
<URL:news:khvhf2mbbih.fsf@imag.fr>:
:: Jerome Abela <Jerome.Abela@free.fr> writes:
::
:: > A one liner is always a contest. Here is shorter variation (no need to chop):
:: > perl -le'$:=reverse$;=pop;map{map{print}/(?=(.{${\length$;}}).)/g}$;x2,$:x2'
:: >
:: > I tried to avoid a map, but it's not shorter:
:: > perl -le'$:=reverse$;=pop;map{print}"$;$;\n$:$:"=~/(?=(.{${\length$;}}).)/g'
::
:: What about:
::
:: perl -le"$:=reverse$;=pop;for($;,$:){print$&.$'.$\`while/./g}"
::
perl -le"$;=pop;map{print$&.$'.$\`while/./g}$;,''.reverse$;"
That can be inproved Perl wise (at the expensive of spending more strokes
escaping the shell, resulting in the same amount of chars):
perl -le'$_=pop;map{print$&.$'\''.$`while/./g}$_,"".reverse'
Abigail
--
$_ = "\x3C\x3C\x45\x4F\x54\n" and s/<<EOT/<<EOT/ee and print;
"Just another Perl Hacker"
EOT
------------------------------
Date: Fri, 26 Jan 2001 21:39:33 GMT
From: eggie@REMOVE_TO_REPLYsunlink.net (James Kufrovich)
Subject: Re: Script to "rotate" the chars in a string.
Message-Id: <slrn973rpt.26h.eggie@melody.mephit.com>
On 26 Jan 2001 16:04:22 +0100, Julien Quint <julien.quint@imag.fr> wrote:
[one-liners snipped]
Thanks for all the suggestions, folks. I knew that I would be
impressed if anybody could do a one-liner, and here it is turning into a
golf tournament. o.O I'm still trying to parse them all. Regardless,
my bag of tricks is already a little heavier (it was pretty light to
begin with, though).
Jamie, worshipping the gurus present.
--
Egg, eggie@REMOVE_TO_REPLYsunlink.net
FMSp3a/MS3a A- C D H+ M+ P+++ R+ T W Z+
Sp++/p# RLCT a+ cl++ d? e++ f h* i+ j p+ sm+
------------------------------
Date: Fri, 26 Jan 2001 19:09:10 GMT
From: Aitor Garcia <a58289@yahoo.com>
Subject: Re: sed and Perl
Message-Id: <94si0f$7ja$1@nnrp1.deja.com>
In article <hf2mqima.fsf@pobox.com>,
Jonathan Feinberg <jdf@pobox.com> wrote:
> Aitor Garcia <a58289@yahoo.com> writes:
>
> > sed '/^[0-9][0-9]*\( 0\.00000000000000000000e+00\)\{2048\}/d'
file_in >> file.out.
>
> > But when I write this command inside a Perl script and try to
> > execute it using backtick operator, does not work.
>
> Why are you using Perl when the sed command works just fine?
Because the sed command is embeded in a bigger Perl script.
> If you want to use Perl, why not just have Perl do what sed was doing?
>
> perl -ne 'print unless /^\d+( 0\.0+e\+00){2048}/' \
> file_in >> file.out
>
> (Warning: I'm guessing at the meaning of that sed program!)
>
Yes, you are right but I have done with sed because I do not
know Perl very well (neither sed).
> What do you mean when you say it doesn't work? One problem I'd
> anticipate is that backticks interpolate their argument, so that some
> of those backwhacks within the sed program disappear.
I have thought about this and it is probably that this is happening.
How can I fix this problem of the backwhacks disspearing ?
>
> --
> Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
> http://pobox.com/~jdf
>
Thanks for your help.
Aitor
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Fri, 26 Jan 2001 19:56:03 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: sed and Perl
Message-Id: <t73lij1lu471aa@corp.supernews.com>
In article <94si0f$7ja$1@nnrp1.deja.com>,
Aitor Garcia <a58289@yahoo.com> wrote:
: In article <hf2mqima.fsf@pobox.com>,
: Jonathan Feinberg <jdf@pobox.com> wrote:
:
: > What do you mean when you say it doesn't work? One problem I'd
: > anticipate is that backticks interpolate their argument, so that some
: > of those backwhacks within the sed program disappear.
:
: I have thought about this and it is probably that this is happening.
: How can I fix this problem of the backwhacks disspearing ?
Add more backwhacks! :-) Beware Leaning Toothpick Syndrome.
Greg
--
Isn't it a bit unnerving that doctors call what they do "practice"?
-- George Carlin
------------------------------
Date: 26 Jan 2001 16:05:02 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: sed and Perl
Message-Id: <8znyqb29.fsf@pobox.com>
Aitor Garcia <a58289@yahoo.com> writes:
> Because the sed command is embeded in a bigger Perl script.
This is a design flaw, one that you have inherited and for which you
must now suffer!
> Yes, you are right but I have done with sed because I do not
> know Perl very well (neither sed).
Well, we can help you to a limited extent, but if you don't actually
know Perl (even some small, beginner's subset of Perl) it will be hard
for you to understand the answers. You might have to hire someone to
fix and maintain the script in question until you've taken the time to
train yourself or to take a course. You should definitely buy the
book "Learning Perl".
> > What do you mean when you say it doesn't work? One problem I'd
> > anticipate is that backticks interpolate their argument, so that some
> > of those backwhacks within the sed program disappear.
>
> I have thought about this and it is probably that this is happening.
> How can I fix this problem of the backwhacks disspearing ?
If you want a back-slash character to survive interpolation, you must
prefix it with another back-slash. So instead of
`blah blah \blah blah`
you must write
`blah blah \\blah blah`
But exec()ing sed from perl is Evil and Weird, TMTOWTDI
notwithstanding.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Fri, 26 Jan 2001 22:24:01 GMT
From: "Jay Flaherty" <fty@mediapulse.com>
Subject: Re: simple question for probably all of you... about @
Message-Id: <5Omc6.32994$Df2.2509889@news3.aus1.giganews.com>
"Mike" <verdien_guldens@hotmail.com> wrote in message
news:3a70af16$0$29588@reader2...
> Dear all
>
> How do I write '@' on my screen between two fields..
>
> as in name1.name2@site?
>
> What is wrong here?
>
$link[$field_id{"name1"}].$link[$field_id{"name2"}]@$link[$field_id{"Server"
> ]
What is wrong is exactly what your error messages states is wrong. ie:
In string, @blahblahblah now must be written as \@blahblahblah at test.pl
line 2
, near blahblahblah@blahblahblah
jay
------------------------------
Date: 26 Jan 2001 23:00:37 GMT
From: edel@best.com (Nate Edel)
Subject: Split losing UTF-8 flag on UTF-8 scalars
Message-Id: <94svil$10hs$1@nntp1.ba.best.com>
First, the situation:
I take the following code:
($fieldText, $altText) = split /\|/, $fieldText, 2;
where $fieldText is a UTF-8 string (converted from Shift_JIS, containing a
pipe to seperate the fieldname from the text). After a bunch of processing,
$altText gets appended to another UTF-8 string, and instead of working
properly, it appears to treat the string $altText as ASCII and "converts" it
to UTF-8, producing an unreadable mess.
(Convert::Scalar::utf8 $fieldText;) run before the split returns 1;
run after the split on either $fieldText or $altText returns 0.
The workaround:
Doing
Convert::Scalar::utf8_on $fieldText;
Convert::Scalar::utf8_on $altText;
fixes the problem.
Finally, my question:
Is split supposed to lose the UTF-8 flag, or is this a bug?
If it's supposed to, is the documentation somewhere of what other operations
will lose the UTF-8 flag?
If it's not supposed to, what am I doing wrong? Or is this just a bug?
Many thanks!
Nate Edel
------------------------------
Date: Fri, 26 Jan 2001 22:34:29 GMT
From: "What A Man !" <whataman@home.com>
Subject: Re: Syntax Trouble
Message-Id: <3A71FBE0.BFD7155B@home.com>
grehom@my-deja.com wrote:
> You might like to look at this for ideas:
> #!perl
> use strict;
> use warnings;
> use File::stat;
>
> my $dir = $ARGV[0] || "*"; # if first parameter on command line
> # null get all files in current dir
> my $epoch_secs_2hrs_ago = time() - 2 * 3600;
> my @files = glob $dir;
> foreach my $f (@files) {
> if ( -d $f # is file a directory?
> && ($f !~ /^\.\.?$/) # is it directory above (..) !
> # or && ($f =~ /^\d{4}$/) # is file name 4 digits?
> ) {
> my $stats = stat($f); # get this file's statistics using
> # recommended object oriented module
> if ($stats->mtime > $epoch_secs_2hrs_ago) {
> # epoch secs when created > 2 hours ago...
I think you meant < 2 hours ago.
> print $f, " created ",
> time() - $stats->mtime,
> " seconds ago\n";
> }
> }
> }
>
> 1;
>
Thanks a mil! This was really helpful. I really didn't
want to use another module, but it looks like File::stat
is in the regular Perl distribution so that'll work out
great.
Kind Regards,
Dennis
------------------------------
Date: Fri, 26 Jan 2001 22:52:11 GMT
From: "What A Man !" <whataman@home.com>
Subject: Re: Syntax Trouble
Message-Id: <3A720006.48C66B13@home.com>
Uri Guttman wrote:
>
> >>>>> "BN" == BUCK NAKED1 <dennis100@webtv.net> writes:
>
> BN> ## Remove this directory after 2 hours
> BN> sub rmtmp{ $age = (-M "$dir")*24;
> BN> if ($age > 2) { `rm -r $dir`
> BN> }
> BN> } ;
> BN> print &&rmtmp;
>
> first, fix your indenting.
OK
>
> second, why use backticks if you are not using the returned results? use
> system.
OK, thanks.
>
> third, why are you using the rm program when you can use rmdir in
> perl. if the dir is not empty, there is a module you can use for that.
I want to remove the dirs whether they are empty or not,
and don't want to add any more modules... so that's the
only way I know to do it.
>
> fourth, what is &&rmtmp?
It's the name of my sub (above) for removing the temp
directories.
>
> [ SNIP ]
>
> BN> I've tried
> BN> $dir = "wkdir";
> BN> $sdir =~ m/^\d{4}$/;
>
> and what is in $sdir? that statement doesn't do anything (except set $&
> and friends).
I'll have to research this. I don't understand why it
won't work. I was trying to put my 4 digit directory names
in scalar $sdir... that's all.
>
> BN> print $dir/$sdir;
>
> BN> just to see if a scalar would access the subdirectories before doing a
> BN> procedure, but the above code only prints "wkdir". It doesn't print
> BN> something like "wkdir/6442", as I had hoped.
>
> use readdir to get the dir names. then filter them on date and name.
Good suggestion, but the File:stat example that another
member posted seems easier...
I appreciate your time, help and opinion as always.Thanks
for your response.
Respectfully,
--Dennis
------------------------------
Date: Fri, 26 Jan 2001 20:57:43 GMT
From: "John Hall" <jhall@ifxonline.com>
Subject: ternary conditional operator
Message-Id: <bxlc6.813$E6.25022@news1.rdc1.sdca.home.com>
Why does this print no? I can't figure it out:
___________________________
#!/usr/bin/perl
$director = "else";
$director =~ /else/ ? $redirto = "yes" : $redirto = "no";
print $redirto;
____________________________
------------------------------
Date: Fri, 26 Jan 2001 21:07:25 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: ternary conditional operator
Message-Id: <x7elxquinl.fsf@home.sysarch.com>
>>>>> "JH" == John Hall <jhall@ifxonline.com> writes:
JH> Why does this print no? I can't figure it out:
JH> ___________________________
JH> #!/usr/bin/perl
JH> $director = "else";
JH> $director =~ /else/ ? $redirto = "yes" : $redirto = "no";
your precedence is wrong. ?: binds tighter than =
regardless, you should do it this way:
$redirto = $director =~ /else/ ? "yes" : "no" ;
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: 26 Jan 2001 21:30:29 GMT
From: The WebDragon <nospam@nospam.com>
Subject: What are some ways to connect to mysql server on a remote host?
Message-Id: <94sq9l$436$0@216.155.32.34>
Connecting to a SQL server on a host remote from the local domain group
(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?
B> what am I overlooking in thinking this is possible?
C> if it is possible, what have some of the preferred/better methods for
connecting a DBI/DBD::mysql script to a 'remote-remote' host been, in
your experience?
thanks for any assistance in this regard.
--
send mail to mactech (at) webdragon (dot) net instead of the above address.
this is to prevent spamming. e-mail reply-to's have been altered
to prevent scan software from extracting my address for the purpose
of spamming me, which I hate with a passion bordering on obsession.
------------------------------
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 153
**************************************