[28954] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 198 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 6 14:10:17 2007

Date: Tue, 6 Mar 2007 11:09:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 6 Mar 2007     Volume: 11 Number: 198

Today's topics:
    Re: get the week day of a date? <veatchla@yahoo.com>
        How do I -MCPAN install and pass commandline params? usenet@DavidFilmer.com
    Re: How do I -MCPAN install and pass commandline params <spamtrap@dot-app.org>
        How to use the "system" operator? <zhouyan1986@gmail.com>
    Re: How to use the "system" operator? usenet@DavidFilmer.com
    Re: IPC::Open2 - Bad File Descriptor <ced@blv-sam-01.ca.boeing.com>
    Re: IPC::Open2 - Bad File Descriptor <uri@stemsystems.com>
    Re: IPC::Open2 - Bad File Descriptor <ben@morrow.me.uk>
    Re: IPC::Open2 - Bad File Descriptor <ben@morrow.me.uk>
    Re: Is it ok to change $ENV{'QUERY_STRING'} before "use <gypark@gmail.com>
    Re: Net-SSH-W32Perl strange behaviour. <1usa@llenroc.ude.invalid>
    Re: Net-SSH-W32Perl strange behaviour. fhornain@gmail.com
    Re: Question about wizard Perl programmers <cwilbur@chromatico.net>
    Re: Question about wizard Perl programmers <bik.mido@tiscalinet.it>
    Re: Question about wizard Perl programmers <hjp-usenet2@hjp.at>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 06 Mar 2007 09:19:38 -0600
From: l v <veatchla@yahoo.com>
Subject: Re: get the week day of a date?
Message-Id: <12ur1jechbq2a85@news.supernews.com>

robertchen117@gmail.com wrote:
> my date format is "030207", 03/02/2007, how could I get it is Friday?
> 
> 
> Thanks, too tricky for me and beyond my mind.
> 

I prefer to use Date::Calc for this type of work

perl -MDate::Calc -e "print Date::Calc::Day_of_Week_to_Text( 
Date::Calc::Day_of_Week(2007,3,2) )"

returns:
Friday

-- 

Len


------------------------------

Date: 6 Mar 2007 10:27:08 -0800
From: usenet@DavidFilmer.com
Subject: How do I -MCPAN install and pass commandline params?
Message-Id: <1173205628.569047.194030@8g2000cwh.googlegroups.com>

I have a module which needs to know the path to a library (which is in
a goofy place on my system).  The module's perldocs tell me that I can
stipulate this with a commandline parameter 'libdir=/dir'.

I would prefer to install this module via the CPAN module.  If I type
this in a CPAN shell:
    install My::Module libdir=/dir

the parameter is silently ignored.

How would I stipulate this parameter within a CPAN install?

Thanks!



------------------------------

Date: Tue, 06 Mar 2007 13:57:18 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: How do I -MCPAN install and pass commandline params?
Message-Id: <m27ituw67l.fsf@local.wv-www.com>

usenet@DavidFilmer.com writes:

> I have a module which needs to know the path to a library (which is in
> a goofy place on my system).  The module's perldocs tell me that I can
> stipulate this with a commandline parameter 'libdir=/dir'.
>
> I would prefer to install this module via the CPAN module.  If I type
> this in a CPAN shell:
>     install My::Module libdir=/dir
>
> the parameter is silently ignored.
>
> How would I stipulate this parameter within a CPAN install?

Use the "look" command. I.e.:

    look My::Module

This will download the latest version, unpack it, and open up a subshell in
the unpacked build directory. From there you can run "perl Makefile.PL
libdir=/dir" manually. After it's done, you can either run "make; make test;
sudo make install" manually also, or you can exit out of the subshell and
run "install My::Module" to let it handle those steps.

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


------------------------------

Date: Wed, 07 Mar 2007 02:14:20 +0800
From: Zhou Yan <zhouyan1986@gmail.com>
Subject: How to use the "system" operator?
Message-Id: <m2lkiatf2b.fsf@stu.ust.hk>

How to make the output of the system operator to a variable?
For instance
system "ls";
I want the list to be stored in a variable, e.g. @list.


------------------------------

Date: 6 Mar 2007 10:29:11 -0800
From: usenet@DavidFilmer.com
Subject: Re: How to use the "system" operator?
Message-Id: <1173205751.653213.89880@j27g2000cwj.googlegroups.com>

On Mar 6, 10:14 am, Zhou Yan <zhouyan1...@gmail.com> wrote:
> How to make the output of the system operator to a variable?


perldoc -q system

   Why can't I get the output of a command with system()?


--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)



------------------------------

Date: 6 Mar 2007 04:23:16 -0800
From: "comp.llang.perl.moderated" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: IPC::Open2 - Bad File Descriptor
Message-Id: <1173183796.290344.270160@t69g2000cwt.googlegroups.com>

On Mar 6, 12:22 am, Bernard Chan <cbkih...@hotmail.com> wrote:
> Dear All,
>
> I am pretty new to the area of pipes and IPC in general. I'm currently
> experimenting with it in different ways trying to understand how it works.
>
> I tried the following simple command:
>
> $ LANG=C perl -MIPC::Open2 -e 'open2(">&1", "<&0", "ls", "-l",
> "/dev/shm")'
> total 4
> -rw-rw-r-- 1 bernardchan bernardchan 3204 Mar  6 16:00 test.txt
> open2: close(0) failed: Bad file descriptor at -e line 1
> ...

You were close...

 open2('>&=0', '<&=0', ... )

>From 'perldoc -f open' :

 If you specify '<&=X', where "X" is a file
 descriptor number or a filehandle, then Perl
 will do an equivalent of C's "fdopen" of that
 file

--
Charles DeRykus



------------------------------

Date: Tue, 06 Mar 2007 10:10:59 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: IPC::Open2 - Bad File Descriptor
Message-Id: <x73b4ih0fw.fsf@mail.sysarch.com>

>>>>> "BM" == Ben Morrow <ben@morrow.me.uk> writes:

  BM> You may find IPC::Run easier to work with, not least because open2 seems
  BM> to require you to use bareword filehandles, which are not considered
  BM> good practice nowadays. (Is it even possible to create a bareword
  BM> filehandle to a socket, except by using the raw socket function?)

you could always store in a lexical a Symbol::gensym for any handle
thing for ages, even open2. and recent versions of perl will autovivify
the handles in open2 (and open3) if you use lexicals. for some reason in
open3, the stderr handle still needs to be passed in but again, you can
use gensym in a lexical and never go near bareword handles.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


------------------------------

Date: Tue, 6 Mar 2007 18:10:15 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: IPC::Open2 - Bad File Descriptor
Message-Id: <7dn0c4-mlf.ln1@osiris.mauzo.dyndns.org>


Quoth "comp.llang.perl.moderated" <ced@blv-sam-01.ca.boeing.com>:
> On Mar 6, 12:22 am, Bernard Chan <cbkih...@hotmail.com> wrote:
> > Dear All,
> >
> > I am pretty new to the area of pipes and IPC in general. I'm currently
> > experimenting with it in different ways trying to understand how it works.
> >
> > I tried the following simple command:
> >
> > $ LANG=C perl -MIPC::Open2 -e 'open2(">&1", "<&0", "ls", "-l",
> > "/dev/shm")'
> > total 4
> > -rw-rw-r-- 1 bernardchan bernardchan 3204 Mar  6 16:00 test.txt
> > open2: close(0) failed: Bad file descriptor at -e line 1
> > ...
> 
> You were close...
> 
>  open2('>&=0', '<&=0', ... )

Did you try it?

~% perl -MIPC::Open2 -e 'open2(">&=1", "<&=0", "ls", "-l", "/dev/shm")' 
total 0
open2: close(=0) failed: Bad file descriptor at -e line 1

Still get the warning, for the same reason: open2 is explicitly trying
to close \*{"=0"}, which isn't open.

> >From 'perldoc -f open' :
> 
>  If you specify '<&=X', where "X" is a file
>  descriptor number or a filehandle, then Perl
>  will do an equivalent of C's "fdopen" of that
>  file

open2 ne open.

Ben

-- 
2 + 2 = 5 for sufficiently large values of 2
                                                         [ben@morrow.me.uk]


------------------------------

Date: Tue, 6 Mar 2007 18:14:37 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: IPC::Open2 - Bad File Descriptor
Message-Id: <dln0c4-mlf.ln1@osiris.mauzo.dyndns.org>


Quoth Uri Guttman <uri@stemsystems.com>:
> >>>>> "BM" == Ben Morrow <ben@morrow.me.uk> writes:
> 
>   BM> You may find IPC::Run easier to work with, not least because open2 seems
>   BM> to require you to use bareword filehandles, which are not considered
>   BM> good practice nowadays. (Is it even possible to create a bareword
>   BM> filehandle to a socket, except by using the raw socket function?)
> 
> you could always store in a lexical a Symbol::gensym for any handle
> thing for ages,

Of course.

> even open2.

Perhaps I wasn't clear: I was specifically talking about the '>&FOO'
syntax for open2 which performs a dup instead of a pipe. In this case I
can't see any way to use a lexical FH, as open2 (well,
IPC::Open3::_open3) explicitly refers to \*{$dad_rdr}, where $dad_rdr is
">&FOO" =~ s/^[<>]&// .

Ben

-- 
   Although few may originate a policy, we are all able to judge it.
                                               Pericles of Athens, c.430 B.C.
  ben@morrow.me.uk


------------------------------

Date: 6 Mar 2007 06:30:56 -0800
From: "Raymundo" <gypark@gmail.com>
Subject: Re: Is it ok to change $ENV{'QUERY_STRING'} before "use CGI;" is called..?
Message-Id: <1173191456.578177.13310@n33g2000cwc.googlegroups.com>

oops.. I wrote a reply. It took about 3 hours. (It's too difficult to
me to write in English) I posted it an hour ago but I can't see it
even now. I'm afraid it's lost :'(

I'll rewrite my last reply...


At first, thank you Ben for your kind advice.


In fact, the Perl script that I'm modifying is not my own code. It is
UseModWiki (http://www.usemod.com/cgi-bin/wiki.pl) and I've been
modifying it to use it for my personal homepage. (But I'm just a
novice in Perl so it's not easy :-)

In wiki site, the URL of each page consists of script URL and "the
title of that page", like ".../wiki.pl?Perl". I'm a Korean and my wiki
has many pages whose names are in Korean.




> Well... a not-url-encoded URL is invalid. At least Firefox appears to
> automatically translate (say) a URL typed into the address bar into its
> correct URL-escaped form before submitting it to the server; I don't
> know what IE or Konq/Safari or Opera do.

As you said, multi-byte characters in URL is invalid. I know it :'( So
url-encoded URL is the answer. However, see the following URLs:
1: .../wiki.pl?Linux <- Everyone can know it is the page about "Linux"
2: .../wiki.pl?%EB%A6%AC%EB%88%85%EC%8A%A4 <- Can anyone guess what
the title of this page is?? :-/ It's "Linux" in Korean
3: .../wiki.pl?=B8=AE=B4=AA=BD=BA <- (If you can't see the Korean chars, pl=
z see
http://gypark.pe.kr/upload/linux_in_korean.gif ) Everyone who are able
to read Korean can know it is the page about Linux. (I'll type
"LINUX(ko)" for this word from now on)

URL 2 is valid, but its appearance is so.... :-/ And I must give up
the big advantage of wiki, "URL represent the content"

URL 3 is said to be invalid. But I still want to support it. That is,
when someone types that URL in the address bar of a browser, or
someone clicks the link to URL 3 in other site, I want my wiki.pl
script show the proper page, "LINUX(ko)".

Fortunately, web browsers like FF, IE, and Safari convert the URL into
%-encoded form before they submit it, as you said. Therefore, I think,
it's not main issue that URL contains multi-bytes chars, because the
server will receive %-encoded request. The problem is that, as I'd
said in my first article, the %-encoded form of "LINUX(ko)" is not
unique. It can be "%EB%A6%AC%EB%88%85%EC%8A%A4" (UTF-8 sequence) or
"%B8%AE%B4%AA%BD%BA" (EUC-KR, in Korea) The browsers choose which
encoding to use according to the option in them. (for FF,
"network.standard-url.encode-utf8" in "about:config") Server can't
choose it and even can't know what is chosen explictily, which is the
reason that wiki.pl should "guess".




> > Returing to my first post in this thread... Is it so bad idea to
> > change the environment variable QUERY_STRING? It solves every problem
> > about this. It requires only one additional line in code. I think that
> > change may affect only the script and its child processes, and the
> > script doesn't fork any child process.
>
> If you're using CGI.pm to process QUERY_STRING, then you should stick to
> that. Messing about is just asking for trouble. What is the problem with
> decoding the submitted values afterwards? (It can still be one line or
> so of code, if you do it right. See Anno's example.)


"The problem with decoding the submitted values afterward" is...
(following are come from my testing results. it may be fixed but I'm
not so expert in Perl)

1) There are hundreds of lines that call "->param()". I don't think
it's good idea to insert so many "guess_and_convert()" after those
lines.

1-1) In fact, those lines actually call "GetParam()" subroutine and
GetParam() calles ->param in it. So it can be a solution to insert
guess_and_convert() in GetParam(). However, GetParam() fetches the
value of a parameter not only from GET request but also from POST
request and even from saved files. For now, I'm not sure it's ok to
modify GetParam(). In addition, it seems to be inefficient to call
convert routine every time a single parameter is fetched.

2) Concering Anno's example, it looks good because it calls convert
routine only once. However, it shows some problem while processing
POST request, like file uploading, receiving trackback, etc. I tried
to debug but failed to find why. I think it is the second best way to
apply that code with additional if-clause: if ($q->request_method() eq
"GET")

3) In the original code, there are some lines that access
$ENV{QUERY_STRING} directly, without calling CGI functions. I need to
apply "guess_and_convert" to those lines.



So I cling to Q_S like this. :-) As far as I know: (please correct me
if I am wrong)
1) Q_S is related to only GET request. (All the forms in wiki.pl calls
"wiki.pl" without any appending URL query when it submits)

2) Q_S may be in the form of "keywords" or
"param1=3Dvalue1&param2=3Dvalue2...". guess_and_convert() will not change
the important characters like "&", "=3D", "+". It will not change any
other ASCII characters. It will just change the multi-byte chars.
Because those characters have been already encoded by browser, this
change is just the change of the number and the sequence of the "%HH"
runs. There is, I think, no problem when CGI object is created and
initialized using Q_S.

3) Changing Q_S affects only the running script and it's child
process.

4) After I began to test my approach, no problem shown until now. (Of
course, this can't be the proof that it will never make a problem. So
I asked your advices in usenet :-)

5) Most of all, I expect that I don't need to care about it when the
rest of code is updated. (at least until the browser's behavior change
dramatically or CGI module)

If anyone give me concrete examples of the problem that may appear
when I convert the encoding of Q_S, I'll give up my way immediately...



Raymundo




------------------------------

Date: Tue, 06 Mar 2007 11:47:38 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Net-SSH-W32Perl strange behaviour.
Message-Id: <Xns98EB451C3C1D2asu1cornelledu@127.0.0.1>

fhornain@gmail.com wrote in
news:1173171296.209051.155770@p10g2000cwp.googlegroups.com: 

> Well, I am currently stuck with a stange Perl behaviour. 

 ...
>            my $ssh = Net::SSH::W32Perl->new($host,protocole =>2, debug
> => 0); 
 
s/protocole/protocol/


Please do read and follow the posting guidelines for this group. 

Sinan 
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



------------------------------

Date: 6 Mar 2007 06:46:15 -0800
From: fhornain@gmail.com
Subject: Re: Net-SSH-W32Perl strange behaviour.
Message-Id: <1173192373.684735.311600@q40g2000cwq.googlegroups.com>

> s/protocole/protocol/
Done ! But the problem is still there.

>Please do read and follow the posting guidelines for this group.
I already done that.
What is wrong with my post ?

Thanks a lot for your help.
BR
Fred



------------------------------

Date: 06 Mar 2007 10:37:32 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Question about wizard Perl programmers
Message-Id: <87bqj6e62r.fsf@mithril.chromatico.net>

>>>>> "MD" == Michele Dondi <bik.mido@tiscalinet.it> writes:

    MD> They are, and moreover contrary to what one may naively
    MD> expect, golf and obfu players are generally perfectly able to
    MD> write sane and readable code too, when it matters, e.g. in
    MD> "production", whatever that means.

Players who are conscious of what they're doing, perhaps.  I've seen a
lot of poor Perl code.

People who are fluent in natural languages and clear of thought can
use them to clearly and unambiguously express things; or they can
indulge in wordplay and puns.  People who are not fluent, or careless,
can rarely do either well, and their attempts at the former are often
indistinguishable from their attempts at the latter.

It's the same way with Perl: the very best authors of obfuscated and
golf Perl can also write straightforward clear and unambiguous Perl.
Indeed, their reasonable Perl is likely to be terser and clearer than
it might otherwise be, because they understand the language deeply.
And those who aren't fluent, or don't think clearly, don't produce
very good Perl.

But blaming Perl for the inability of programmers to write clearly is
like blaming English for the circumlocutions of bureaucrats: it's
blaming the tool, not the user.  The reason Perl gets this blame --
and it's just as possible to not think clearly in Java, or C++, or
Python -- is that it's one of the few languages that's so flexible in
syntax and semantics that style can become idiosyncratic, and it's
widely used by both experts and novice programmers.  

(It's also, in entrenched corporate environments, a Threat to the Way
Things Are Done, which explains a lot of the FUD.  But Ruby and Python
get much of that same FUD too.)

Charlton



-- 
Charlton Wilbur
cwilbur@chromatico.net


------------------------------

Date: Tue, 06 Mar 2007 19:05:37 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Question about wizard Perl programmers
Message-Id: <o7bru29blqbsf03rb4fmdq7l91p6pe4ces@4ax.com>

On 06 Mar 2007 10:37:32 -0500, Charlton Wilbur
<cwilbur@chromatico.net> wrote:

>    MD> They are, and moreover contrary to what one may naively
>    MD> expect, golf and obfu players are generally perfectly able to
>    MD> write sane and readable code too, when it matters, e.g. in
>    MD> "production", whatever that means.
>
>Players who are conscious of what they're doing, perhaps.  I've seen a
>lot of poor Perl code.

You're right: I meant *good* golf and obfu players. Those are likely
to be consciuous of what they're doing. Indeed I've seen tons of poor
Perl code too, but I don't expect one who writes such code to be an
excellent golfer, either.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


------------------------------

Date: Tue, 6 Mar 2007 19:04:02 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Question about wizard Perl programmers
Message-Id: <slrneurb8i.2p2.hjp-usenet2@yoyo.hjp.at>

On 2007-03-06 10:55, Michele Dondi <bik.mido@tiscalinet.it> wrote:
> On Mon, 05 Mar 2007 11:00:28 +0200, Alex <check.sig@for.email.invalid>
> wrote:
>>It compiles and runs. Does this make Java a very difficult language? (It
>>simply prints "Hi!", in case you're interested.)
>
> Not to mention widely known C stuff, from a friend of mine's .sig:
>
>   char code[] =
>   "\xeb\x19\x31\xc0\x31\xdb\x31\xc9\x31\xd2\xb0"
>   "\x04\xb3\x01\x59\xb2\x03\xcd\x80\x31\xc0\x31"
>   "\xdb\xb0\x01\xcd\x80\xe8\xe2\xff\xff\xffG.\n"
>   ;

Shouldn't that be "char main[] = ..."?

	hp

-- 
   _  | Peter J. Holzer    | Blaming Perl for the inability of programmers
|_|_) | Sysadmin WSR       | to write clearly is like blaming English for
| |   | hjp@hjp.at         | the circumlocutions of bureaucrats.
__/   | http://www.hjp.at/ |	-- Charlton Wilbur in clpm


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V11 Issue 198
**************************************


home help back first fref pref prev next nref lref last post