[31502] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2761 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 8 18:09:42 2010

Date: Fri, 8 Jan 2010 15:09:07 -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           Fri, 8 Jan 2010     Volume: 11 Number: 2761

Today's topics:
        Error when combining threads and system() <willem@stack.nl>
    Re: Error when combining threads and system() sln@netherlands.com
    Re: Error when combining threads and system() sln@netherlands.com
    Re: FAQ 7.16 How do I create a static variable? <pshendley@gmail.com>
    Re: FAQ 9.16 How do I decode a CGI form? <pshendley@gmail.com>
    Re: FAQ 9.16 How do I decode a CGI form? <hhr-m@web.de>
    Re: LWP::UserAgent HTTP POST authentication problem <tadmc@seesig.invalid>
    Re: LWP::UserAgent HTTP POST authentication problem <pshendley@gmail.com>
    Re: LWP::UserAgent HTTP POST authentication problem <pshendley@gmail.com>
    Re: LWP::UserAgent HTTP POST authentication problem <hjp-usenet2@hjp.at>
        Permutations <justin.1001@purestblue.com>
    Re: Regex to extract email from .msg <pshendley@gmail.com>
    Re: Regex to extract email from .msg <hjp-usenet2@hjp.at>
    Re: Solar cells for less than 1 USD per Watt <jurgenex@hotmail.com>
    Re: translating an OS directory recursively into a tree <hjp-usenet2@hjp.at>
    Re: translating an OS directory recursively into a tree <OJZGSRPBZVCX@spammotel.com>
    Re: translating an OS directory recursively into a tree <smallpond@juno.com>
    Re: translating an OS directory recursively into a tree <m@rtij.nl.invlalid>
    Re: translating an OS directory recursively into a tree sln@netherlands.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 8 Jan 2010 18:51:51 +0000 (UTC)
From: Willem <willem@stack.nl>
Subject: Error when combining threads and system()
Message-Id: <slrnhkevm7.12m3.willem@turtle.stack.nl>

Hi,

I'm having a weird problem involving threads and calls to system()

Note: it only fails on some systems, notably a Windows NT 2003 server.

The issue is that when I call system() in the main thread, everything works
like it should, but when I call it in a subthread, it fails with the
following message:

  Can't spawn "cmd.exe": No such file or directory at test-bug.pl line 10.
  foo

This is the test program as minimal as I could get it:

  use warnings;
  use strict;
  use threads;
  threads->create(\&tests)->join();
  tests();
  sub tests { system('echo foo') }

It fails on both perl 5.8.8 built for MSWin32-x86-multi-thread
and perl 5.10.x, using Activestate.

The value of $? seems to be 255<<8, so that's a return code
of -1 from the shell.

Piped open fails as well, as do backticks.  Probably for the same reason.
Can anyone shed any light on this ?  I've tried googling, but I haven't
found anything specific to threading.


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT


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

Date: Fri, 08 Jan 2010 11:12:13 -0800
From: sln@netherlands.com
Subject: Re: Error when combining threads and system()
Message-Id: <kq0fk5191esh0cuqnlr10j3bcuee4bva44@4ax.com>

On Fri, 8 Jan 2010 18:51:51 +0000 (UTC), Willem <willem@stack.nl> wrote:

>Hi,
>
>I'm having a weird problem involving threads and calls to system()
>
>Note: it only fails on some systems, notably a Windows NT 2003 server.
>
>The issue is that when I call system() in the main thread, everything works
>like it should, but when I call it in a subthread, it fails with the
>following message:
>
>  Can't spawn "cmd.exe": No such file or directory at test-bug.pl line 10.
>  foo
>

Works on XP.
Do you have cmd.exe in your path?
-sln

 use warnings;
  use strict;
  use threads;

  threads->create(\&tests)->join();
  tests();
  sub tests { system('echo foo') }

__END__

c:\temp>perl -v

This is perl, v5.10.0 built for MSWin32-x86-multi-thread
(with 5 registered patches, see perl -V for more detail)

Copyright 1987-2007, Larry Wall

Binary build 1004 [287188] provided by ActiveState http://www.ActiveState.com
Built Sep  3 2008 13:16:37

c:\temp>perl cc.pl
foo
foo

c:\temp>



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

Date: Fri, 08 Jan 2010 11:15:56 -0800
From: sln@netherlands.com
Subject: Re: Error when combining threads and system()
Message-Id: <f01fk5tchrg8r1o4jlqrpbqa74kimm2l3t@4ax.com>

On Fri, 08 Jan 2010 11:12:13 -0800, sln@netherlands.com wrote:

>On Fri, 8 Jan 2010 18:51:51 +0000 (UTC), Willem <willem@stack.nl> wrote:
>
>>Hi,
>>
>>I'm having a weird problem involving threads and calls to system()
>>
>>Note: it only fails on some systems, notably a Windows NT 2003 server.
>>
>>The issue is that when I call system() in the main thread, everything works
>>like it should, but when I call it in a subthread, it fails with the
>>following message:
>>
>>  Can't spawn "cmd.exe": No such file or directory at test-bug.pl line 10.
>>  foo
>>
>
>Works on XP.
>Do you have cmd.exe in your path?
>-sln
>

Click Start->Run, paste %SystemRoot%\system32\cmd.exe
in edit box, hit return.
Try it there.

-sln


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

Date: Fri, 8 Jan 2010 06:07:27 -0800 (PST)
From: Permostat <pshendley@gmail.com>
Subject: Re: FAQ 7.16 How do I create a static variable?
Message-Id: <ab9ac218-8198-487d-aea4-b3d3f03e22d3@m16g2000yqc.googlegroups.com>

On Jan 8, 5:00=A0am, PerlFAQ Server <br...@theperlreview.com> wrote:
> This is an excerpt from the latest version perlfaq7.pod, which
> comes with the standard Perl distribution. These postings aim to
> reduce the number of repeated questions as well as allow the community
> to review and update the answers. The latest version of the complete
> perlfaq is athttp://faq.perl.org.
>
> --------------------------------------------------------------------
>
> 7.16: How do I create a static variable?
>
> =A0 =A0 (contributed by brian d foy)
>
> =A0 =A0 In Perl 5.10, declare the variable with "state". The "state" decl=
aration
> =A0 =A0 creates the lexical variable that persists between calls to the
> =A0 =A0 subroutine:
>
> =A0 =A0 =A0 =A0 =A0 =A0 sub counter { state $count =3D 1; $counter++ }
>
> =A0 =A0 You can fake a static variable by using a lexical variable which =
goes
> =A0 =A0 out of scope. In this example, you define the subroutine "counter=
", and
> =A0 =A0 it uses the lexical variable $count. Since you wrap this in a BEG=
IN
> =A0 =A0 block, $count is defined at compile-time, but also goes out of sc=
ope at
> =A0 =A0 the end of the BEGIN block. The BEGIN block also ensures that the
> =A0 =A0 subroutine and the value it uses is defined at compile-time so th=
e
> =A0 =A0 subroutine is ready to use just like any other subroutine, and yo=
u can
> =A0 =A0 put this code in the same place as other subroutines in the progr=
am text
> =A0 =A0 (i.e. at the end of the code, typically). The subroutine "counter=
" still
> =A0 =A0 has a reference to the data, and is the only way you can access t=
he
> =A0 =A0 value (and each time you do, you increment the value). The data i=
n chunk
> =A0 =A0 of memory defined by $count is private to "counter".
>
> =A0 =A0 =A0 =A0 =A0 =A0 BEGIN {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 my $count =3D 1;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 sub counter { $count++ }
> =A0 =A0 =A0 =A0 =A0 =A0 }
>
> =A0 =A0 =A0 =A0 =A0 =A0 my $start =3D counter();
>
> =A0 =A0 =A0 =A0 =A0 =A0 .... # code that calls counter();
>
> =A0 =A0 =A0 =A0 =A0 =A0 my $end =3D counter();
>
> =A0 =A0 In the previous example, you created a function-private variable =
because
> =A0 =A0 only one function remembered its reference. You could define mult=
iple
> =A0 =A0 functions while the variable is in scope, and each function can s=
hare
> =A0 =A0 the "private" variable. It's not really "static" because you can =
access
> =A0 =A0 it outside the function while the lexical variable is in scope, a=
nd even
> =A0 =A0 create references to it. In this example, "increment_count" and
> =A0 =A0 "return_count" share the variable. One function adds to the value=
 and
> =A0 =A0 the other simply returns the value. They can both access $count, =
and
> =A0 =A0 since it has gone out of scope, there is no other way to access i=
t.
>
> =A0 =A0 =A0 =A0 =A0 =A0 BEGIN {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 my $count =3D 1;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 sub increment_count { $count++ }
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 sub return_count =A0 =A0{ $count =
}
> =A0 =A0 =A0 =A0 =A0 =A0 }
>
> =A0 =A0 To declare a file-private variable, you still use a lexical varia=
ble. A
> =A0 =A0 file is also a scope, so a lexical variable defined in the file c=
annot
> =A0 =A0 be seen from any other file.
>
> =A0 =A0 See "Persistent Private Variables" in perlsub for more informatio=
n. The
> =A0 =A0 discussion of closures in perlref may help you even though we did=
 not
> =A0 =A0 use anonymous subroutines in this answer. See "Persistent Private
> =A0 =A0 Variables" in perlsub for details.
>
> --------------------------------------------------------------------
>
> The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
> are not necessarily experts in every domain where Perl might show up,
> so please include as much information as possible and relevant in any
> corrections. The perlfaq-workers also don't have access to every
> operating system or platform, so please include relevant details for
> corrections to examples that do not work on particular platforms.
> Working code is greatly appreciated.
>
> If you'd like to help maintain the perlfaq, see the details in
> perlfaq.pod.

You need some erotic talk in your FAQ. And start charging for it.

PERMO


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

Date: Fri, 8 Jan 2010 09:31:05 -0800 (PST)
From: Permostat <pshendley@gmail.com>
Subject: Re: FAQ 9.16 How do I decode a CGI form?
Message-Id: <7692104b-129c-4fd0-99b8-bf8935d02216@21g2000yqj.googlegroups.com>

On Jan 8, 11:00=A0am, PerlFAQ Server <br...@theperlreview.com> wrote:
> This is an excerpt from the latest version perlfaq9.pod, which
> comes with the standard Perl distribution. These postings aim to
> reduce the number of repeated questions as well as allow the community
> to review and update the answers. The latest version of the complete
> perlfaq is athttp://faq.perl.org.
>
> --------------------------------------------------------------------
>
> 9.16: How do I decode a CGI form?
>
> =A0 =A0 (contributed by brian d foy)
>
> =A0 =A0 Use the CGI.pm module that comes with Perl. It's quick, it's easy=
, and
> =A0 =A0 it actually does quite a bit of work to ensure things happen corr=
ectly.
> =A0 =A0 It handles GET, POST, and HEAD requests, multipart forms, multiva=
lued
> =A0 =A0 fields, query string and message body combinations, and many othe=
r
> =A0 =A0 things you probably don't want to think about.
>
> =A0 =A0 It doesn't get much easier: the CGI module automatically parses t=
he
> =A0 =A0 input and makes each value available through the "param()" functi=
on.
>
> =A0 =A0 =A0 =A0 =A0 =A0 use CGI qw(:standard);
>
> =A0 =A0 =A0 =A0 =A0 =A0 my $total =3D param( 'price' ) + param( 'shipping=
' );
>
> =A0 =A0 =A0 =A0 =A0 =A0 my @items =3D param( 'item' ); # multiple values,=
 same field name
>
> =A0 =A0 If you want an object-oriented approach, CGI.pm can do that too.
>
> =A0 =A0 =A0 =A0 =A0 =A0 use CGI;
>
> =A0 =A0 =A0 =A0 =A0 =A0 my $cgi =3D CGI->new();
>
> =A0 =A0 =A0 =A0 =A0 =A0 my $total =3D $cgi->param( 'price' ) + $cgi->para=
m( 'shipping' );
>
> =A0 =A0 =A0 =A0 =A0 =A0 my @items =3D $cgi->param( 'item' );
>
> =A0 =A0 You might also try CGI::Minimal which is a lightweight version of=
 the
> =A0 =A0 same thing. Other CGI::* modules on CPAN might work better for yo=
u, too.
>
> =A0 =A0 Many people try to write their own decoder (or copy one from anot=
her
> =A0 =A0 program) and then run into one of the many "gotchas" of the task.=
 It's
> =A0 =A0 much easier and less hassle to use CGI.pm.
>
> --------------------------------------------------------------------
>
> The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
> are not necessarily experts in every domain where Perl might show up,
> so please include as much information as possible and relevant in any
> corrections. The perlfaq-workers also don't have access to every
> operating system or platform, so please include relevant details for
> corrections to examples that do not work on particular platforms.
> Working code is greatly appreciated.
>
> If you'd like to help maintain the perlfaq, see the details in
> perlfaq.pod.

Why don't you just post the hyperlink?? Seems a waste of time to be
doing this best of chapter posting.

PERMO


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

Date: Fri, 8 Jan 2010 18:48:52 +0100
From: Helmut Richter <hhr-m@web.de>
Subject: Re: FAQ 9.16 How do I decode a CGI form?
Message-Id: <Pine.LNX.4.64.1001081826540.4414@lxhri01.lrz.lrz-muenchen.de>

[ Followup-To: comp.lang.perl.modules ]

On Fri, 8 Jan 2010, PerlFAQ Server wrote in comp.lang.perl.misc:

> 9.16: How do I decode a CGI form?
> 
>     (contributed by brian d foy)
> 
>     Use the CGI.pm module that comes with Perl. It's quick, it's easy, and
>     it actually does quite a bit of work to ensure things happen correctly.
>     It handles GET, POST, and HEAD requests, multipart forms, multivalued
>     fields, query string and message body combinations, and many other
>     things you probably don't want to think about.

It even works with forms that are using UTF-8 code on input which is 
needed for non-English language. However, the documentation warns against 
usage of this feature and recommends fiddling around with encode and 
decode instead, thus deprecating one of the really useful functionalities 
of the CGI.pm module.

More detail in my recent contribution in newsgroup comp.lang.perl.modules.

-- 
Helmut Richter


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

Date: Fri, 08 Jan 2010 07:18:11 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: LWP::UserAgent HTTP POST authentication problem
Message-Id: <slrnhkebun.no2.tadmc@tadbox.sbcglobal.net>

Wanna-Be Sys Admin <sysadmin@example.com> wrote:
> Permostat wrote:


          +-------------------+             .:\:\:/:/:.
          |   PLEASE DO NOT   |            :.:\:\:/:/:.:
          |  FEED THE TROLLS  |           :=.' -   - '.=:
          |                   |           '=(\ 9   9 /)='
          |   Thank you,      |              (  (_)  )
          |       Management  |              /`-vvv-'\
          +-------------------+             /         \
                  |  |        @@@          / /|,,,,,|\ \
                  |  |        @@@         /_//  /^\  \\_\
    @x@@x@        |  |         |/         WW(  (   )  )WW
    \||||/        |  |        \|           __\,,\ /,,/__
     \||/         |  |         |          (______Y______)
/\/\/\/\/\/\/\/\//\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
==================================================================



-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"


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

Date: Fri, 8 Jan 2010 06:02:04 -0800 (PST)
From: Permostat <pshendley@gmail.com>
Subject: Re: LWP::UserAgent HTTP POST authentication problem
Message-Id: <1b970390-23ac-4ba2-b00d-cf05285022f7@s31g2000yqs.googlegroups.com>

On Jan 8, 2:41=A0am, Wanna-Be Sys Admin <sysad...@example.com> wrote:
> Permostat wrote:
> > On Jan 7, 11:33=A0pm, Wanna-Be Sys Admin <sysad...@example.com> wrote:
> >> Permostat wrote:
> >> > On Jan 7, 6:37=A0pm, Wanna-Be Sys Admin <sysad...@example.com> wrote=
:
> >> >> Permostat wrote:
> >> >> > We don't like socialists in our newsgroup. We'll be seeing not
> >> >> > again commie.
>
> >> >> > PERMO
>
> >> >> If you're going to post nonsense, you could at least snip the
> >> >> text. We all know you're know Shendley, so your efforts are in
> >> >> vain (it'll just win more support for the person you're attempting
> >> >> to harass). --
> >> >> Not really a wanna-be, but I don't know everything.
>
> >> It's improper to quote signatures.
>
> >> > What efforts??
>
> >> This, that, what you've done. =A0It takes some effort to bother
> >> pretending to be someone else.
>
> > When you know the internet well enough to do anything in under two
> > minutes, it is no effort.
>
> > Which is where you cross dressers are wrong
> > about trolls spending way too much on here.
>
> >> > I've already proven my point & and he knows what it is.
>
> >> You've made no point, you've only posted as someone else and shown
> >> you don't know how to quote messages on usenet. =A0How does that make
> >> him look bad?
>
> > I'm not trying to make anyone look bad and I'll quote on Usenet
> > however I want to quote.
>
> > Nobody has told me anything about my quoting
> > in 15 years.
>
>
> > So I'm going to assume you are assuming I'm some hack who
> > has never walked into an alt. group before.
>
> > You've lost the plot and
> > let yourself believe you are as smart as you think you are.
>
> >> > Now it's just entertainment for me.
>
> >> That's kind of sad.
>
> > It is sad to be so letdown by people in general that you let them
> > become little wind up things.
>
> >> > I am above nearly every single
> >> > person I come in contact with in every conceivable way.
>
> >> I suppose you are welcome to believe that so long as you make a
> >> claim, that it makes it true in your own mind, but that sort of logic
> >> doesn't work too well in real life, when it's more than just self
> >> esteem.
>
> > It is only confidence and self esteem.
>
> > I have found a loving and
> > sweetly devoted girlfriend.
>
> > I have super loyal friends who defend me.
>
> > And I have parents who fund my education
>
> > and make sure to the final
> > degree that I am well taken care of.
>
> > I don't fuck with bullshitters,
>
> > drama queens, or junkie/alcoholics.
>
> > Why all of this??
>
> > Because I =A0
> > understand how important a person like myself is and I accept NO less
> > than best in my life. It works.
>
> >> > Nearly
> >> > everybody on this planet is the nexus of my next laugh.
>
> >> Are you the guy that wrote the time travel watch spam?
>
> > I use the correct words for the proper intent. I didn't mean to
> > confuse you.
>
> >> > Give me break.
>
> >> I'll be happy to break whatever.
>
> > Stick a cattle prod set to max up your cunt.
>
> >> Not really a wanna-be, but I don't know everything.
>
> > PROTO
>
> Look, I'm sorry, I didn't mean to jump all over your back. I just get ang=
ry sometimes, I'm not sure why.
>
> --
> Not really a wanna-be, but I don't know everything.

It's okay man. Sometimes people have bad days.

SHERMINATOR


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

Date: Fri, 8 Jan 2010 06:06:12 -0800 (PST)
From: Permostat <pshendley@gmail.com>
Subject: Re: LWP::UserAgent HTTP POST authentication problem
Message-Id: <2f4329e9-681e-4c1e-a847-afc81ccbbb90@26g2000yqo.googlegroups.com>

On Jan 8, 12:51=A0am, J=FCrgen Exner <jurge...@hotmail.com> wrote:
> Permostat <pshend...@gmail.com> wrote:
>
> [nothing of any significance]
>
> *PLONK*
>
> jue

What's with this guy?? Do you think he walks around Switzerland saying
plonk at people all day??

SHERMAN


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

Date: Fri, 8 Jan 2010 15:07:16 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: LWP::UserAgent HTTP POST authentication problem
Message-Id: <slrnhkef0k.1mp.hjp-usenet2@hrunkner.hjp.at>


                            ___________________________
                   /|  /|  |                          |
                   ||__||  |       Please don't       |
                  /   O O\__           feed           |
                 /          \       the trolls        |
                /      \     \                        |
               /   _    \     \ ---------------------- 
              /    |\____\     \     ||                
             /     | | | |\____/     ||                
            /       \|_|_|/   |    __||                
           /  /  \            |____| ||                
          /   |   | /|        |      --|               
          |   |   |//         |____  --|               
   * _    |  |_|_|_|          |     \-/                
*-- _--\ _ \     //           |                        
  /  _     \\ _ //   |        /                        
*  /   \_ /- | -     |       |                         
  *      ___ c_c_c_C/ \C_c_c_c____________             


	hp



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

Date: Fri, 8 Jan 2010 22:39:39 +0000
From: Justin C <justin.1001@purestblue.com>
Subject: Permutations
Message-Id: <bqok17-1ev.ln1@purestblue.com>

I have a puzzle to solve, for pleasure rather than gain, and I'd like to
find a perl solution to it because I'm not a mathematician, and
therefore will crack the answer with brute force rather than brains.

I need to calculate all permutations of a list. For the purpose of the
puzzle the mirror images are equivalent ((1234 == 4321) either can be in
my results, but not both.

I'm looking at the documentation for Algorithm::Permute, and I've looked
at List::Permutor. I'm happy to let either one run and generate my
permutations, but I could do with an effective way of weeding out
mirrors of permutations I've already got. I could put each one into a
hash, the key being the permutation, and then:

  my $reversed = scalar reverse $permutation;
  next if ($results{$reversed});

I just wondered if there's a better way, so that I don't have to
calculate all of the permutations when I'll only need 50% of them.

Thank you for any suggestions.

   Justin.

-- 
Justin C, by the sea.


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

Date: Fri, 8 Jan 2010 06:08:40 -0800 (PST)
From: Permostat <pshendley@gmail.com>
Subject: Re: Regex to extract email from .msg
Message-Id: <47bc4bc4-a363-4152-9626-13714afe8d38@c3g2000yqd.googlegroups.com>

On Jan 7, 11:19=A0am, Bart Van der Donck <b...@nijlen.com> wrote:
> Hello,
>
> I have been assigned a task to filter out an email address from the
> body of a (.msg) source file.
>
> The source file looks odd and displays differently in various
> plaintext readers. It looks like some sort of half binary / half ascii
> format (including the headers). The body of the file is more-or-less
> consistent. The address to be extracted is in the following format:
>
> =A0 =A0"- =A0 n a m e @ h o s t . c o m =A0 "
>
> All text in the source file is with such spaces between.
>
> Spaces can be displayed like EOL, space or nothing. Binary characters
> seem to be inserted randomly; sometimes I can recognize a pattern of a
> repeated string. Maybe someone is familiar with this format ? The
> messages were saved from MS Outlook.
>
> I tried many variants, my best shot goes to:
>
> =A0 =A0if (/(-)(\s\s\s)(.+)(@)(.+)(\.)(.+)(\s\s\s)/gs) =A0{ ...
>
> But still no success. I was thinking of an encoding issue (Unicode/
> UTF?), but the source file seems too different for that.
>
> Thanks
>
> --
> =A0Bart

Do little tiny minor jobs usually make you break out in a sweat like
this??

PRONTOR


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

Date: Fri, 8 Jan 2010 15:11:35 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Regex to extract email from .msg
Message-Id: <slrnhkef8o.1mp.hjp-usenet2@hrunkner.hjp.at>

On 2010-01-08 09:58, Bart Van der Donck <bart@nijlen.com> wrote:
>   use Encode;
>   open(my $in, '<:raw', $mypath) || die "Couldn't open file: $!";
>   my $txt = do { local $/; <$in> };
>   close $in;
>   my @lines = split /\n/, decode('UTF-16LE', $txt);

Shorter:

    open(my $in, '<:encoding(UTF-16LE)', $mypath) || die "Couldn't open file: $!";
    my @lines = <$in>;
    chomp @lines;

(untested)

	hp


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

Date: Fri, 08 Jan 2010 12:56:01 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Solar cells for less than 1 USD per Watt
Message-Id: <cu6fk5ljue4414lv8ptstecrl37kpjfons@4ax.com>

".." <sustainable.future115@gmail.com> wrote:
>Do you know that you can find solar cells for less than 1 USD per Watt

Do they come with a Perl interpreter?

jue


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

Date: Fri, 8 Jan 2010 21:13:08 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: translating an OS directory recursively into a tree object
Message-Id: <slrnhkf4el.kgo.hjp-usenet2@hrunkner.hjp.at>

On 2010-01-06 22:56, David Combs <dkcombs@panix.com> wrote:
> In article <slrnhhq479.17h.tadmc@tadbox.sbcglobal.net>,
> Tad McClellan  <tadmc@seesig.invalid> wrote:
>>This probably won't help you solve your problem, but whenever the
>>subject of parsing directory trees comes up, I just must share it.
>>
>>Got this off the 'net over a decade ago...
>>
>>    find . -print | sed -e 's,[^/]*/\([^/]*\)$,`--\1,' -e 's,[^/]*/,|  ,g'
>>
>>Simply amazing.
>
>
> If you have the spare time -- uh -- you could save a whole bunch
> of us the (considerable?) effort of trying to figure out exactly how it
> works.
>
>    Nor am I so sure that I *could* do it.  :-(

It isn't actually that hard to understand (especially if you try it),
but it's pretty cool. I like it.

>>    find . -print |

Prints file (and directory) names like this:

 ./a/b/c

>>    sed 
>>      -e 's,[^/]*/\([^/]*\)$,`--\1,'

This replaces the penultimate path component (including the trailing
slash) with "`--" but preserves everything before and after. So
    ./a/b/c
becomes
    ./a/`--c

>>      -e 's,[^/]*/,|  ,g'

This replaces every path component (with a trailing slash)
with "|  ". So now we get

    |  |  `--c

Doesn't look very impressive for only one filename, does it? But if you
do it for a whole tree, the vertical lines and backticks line up nicely
and you get a tree (with a few extra lines, but avoiding them would make
it a lot more complicated).

Your mission, should you choose to accept it, is to turn this into a
Perl one-liner ;-).

	hp



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

Date: Fri, 08 Jan 2010 22:27:55 +0100
From: "Jochen Lehmeier" <OJZGSRPBZVCX@spammotel.com>
Subject: Re: translating an OS directory recursively into a tree object
Message-Id: <op.u58gktnvmk9oye@frodo>

On Fri, 08 Jan 2010 21:13:08 +0100, Peter J. Holzer <hjp-usenet2@hjp.at>
wrote:

> Your mission, should you choose to accept it, is to turn this into a
> Perl one-liner ;-).

You did not specify line length. This fits in one of mine:

perl -we 'sub p{$d=$_[0];$_=$d;s,[^/]*/([^/]*)$,`--$1,;s,[^/]*/,|   
,g;print"$_\n";for(<$d/*>,<$d/.??*>){p($_)}};p(".")'

Anyone who finds the obvious bug can keep it.


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

Date: Fri, 08 Jan 2010 16:32:37 -0500
From: Steve C <smallpond@juno.com>
Subject: Re: translating an OS directory recursively into a tree object
Message-Id: <hi88a5$i8j$1@news.eternal-september.org>

Peter J. Holzer wrote:
> 
> Your mission, should you choose to accept it, is to turn this into a
> Perl one-liner ;-).
> 

The sed part is easy enough:

find . -print |perl -lpe 's,[^/]*/([^/]*)$,`--$1,;s,[^/]*/,|  ,g'


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

Date: Fri, 8 Jan 2010 22:35:14 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: translating an OS directory recursively into a tree object
Message-Id: <i1lk17-f0a.ln1@news.rtij.nl>

On Fri, 08 Jan 2010 21:13:08 +0100, Peter J. Holzer wrote:

> Your mission, should you choose to accept it, is to turn this into a
> Perl one-liner ;-).

Well only if we can improve on it, this one sorts the files, which the original doesn't.

perl -MFile::Find -e 'find({preprocess=>sub{sort@_},wanted=>sub{$_=$File::Find::name;s,[^/]*/([^/]*)$,`--$1,;s,[^/]*/,|  ,g;print"$_\n"}},".")'

Any shorter?

M4


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

Date: Fri, 08 Jan 2010 14:30:45 -0800
From: sln@netherlands.com
Subject: Re: translating an OS directory recursively into a tree object
Message-Id: <adcfk5dcpq33usnemuicepdq26e9mh3gk4@4ax.com>

On Fri, 8 Jan 2010 21:13:08 +0100, "Peter J. Holzer" <hjp-usenet2@hjp.at> wrote:

>On 2010-01-06 22:56, David Combs <dkcombs@panix.com> wrote:
>> In article <slrnhhq479.17h.tadmc@tadbox.sbcglobal.net>,
>> Tad McClellan  <tadmc@seesig.invalid> wrote:
>>>This probably won't help you solve your problem, but whenever the
>>>subject of parsing directory trees comes up, I just must share it.
>>>
>>>Got this off the 'net over a decade ago...
>>>
>>>    find . -print | sed -e 's,[^/]*/\([^/]*\)$,`--\1,' -e 's,[^/]*/,|  ,g'
>>>
>>>Simply amazing.
>>
>>
>> If you have the spare time -- uh -- you could save a whole bunch
>> of us the (considerable?) effort of trying to figure out exactly how it
>> works.
>>
>>    Nor am I so sure that I *could* do it.  :-(
>
>It isn't actually that hard to understand (especially if you try it),
>but it's pretty cool. I like it.
>
>>>    find . -print |
>
>Prints file (and directory) names like this:
>
>./a/b/c
>
>>>    sed 
>>>      -e 's,[^/]*/\([^/]*\)$,`--\1,'
>
>This replaces the penultimate path component (including the trailing
>slash) with "`--" but preserves everything before and after. So
>    ./a/b/c
>becomes
>    ./a/`--c
>
>>>      -e 's,[^/]*/,|  ,g'
>
>This replaces every path component (with a trailing slash)
>with "|  ". So now we get
>
>    |  |  `--c
>
>Doesn't look very impressive for only one filename, does it? But if you
>do it for a whole tree, the vertical lines and backticks line up nicely
>and you get a tree (with a few extra lines, but avoiding them would make
>it a lot more complicated).
>
>Your mission, should you choose to accept it, is to turn this into a
>Perl one-liner ;-).
>
>	hp

s{ [^/]*/ }{| }xg,
s{ \|\ ([^|]*)$ }{`--$1}x,
print "$_\n" for @{[qw{
 .
 ./a
 ./a/b
 ./a/b/c
}]};

__END__
 .
`--a
| `--b
| | `--c



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

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:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 2761
***************************************


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