[31503] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2762 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jan 9 21:09:44 2010

Date: Sat, 9 Jan 2010 18: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           Sat, 9 Jan 2010     Volume: 11 Number: 2762

Today's topics:
    Re: Error when combining threads and system() <willem@stack.nl>
    Re: FAQ 5.4 How can I use Perl's "-i" option from withi <marc.girod@gmail.com>
        Net::SSH::Expect SSHAuthenticationError Login timed out <bsinghrana@gmail.com>
    Re: Net::SSH::Expect SSHAuthenticationError Login timed <derykus@gmail.com>
    Re: Permutations <jurgenex@hotmail.com>
    Re: Permutations <jimsgibson@gmail.com>
    Re: Permutations <xhoster@gmail.com>
    Re: Regex to extract email from .msg <bart@nijlen.com>
    Re: Regex to extract email from .msg <jurgenex@hotmail.com>
    Re: Regex to extract email from .msg sln@netherlands.com
    Re: Regex to extract email from .msg sln@netherlands.com
    Re: Regex to extract email from .msg <ben@morrow.me.uk>
    Re: translating an OS directory recursively into a tree sln@netherlands.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 9 Jan 2010 23:13:29 +0000 (UTC)
From: Willem <willem@stack.nl>
Subject: Re: Error when combining threads and system()
Message-Id: <slrnhki3cp.20fl.willem@turtle.stack.nl>

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.

As I said above, it only fails on Windows NT.

) Do you have cmd.exe in your path?

Obviously, otherwise the main thread would have failed as well.


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: Sat, 9 Jan 2010 04:03:05 -0800 (PST)
From: Marc Girod <marc.girod@gmail.com>
Subject: Re: FAQ 5.4 How can I use Perl's "-i" option from within a program?
Message-Id: <f2754f02-8177-4304-942d-1b0d197a120a@j14g2000yqm.googlegroups.com>

On Jan 9, 11:00=A0am, PerlFAQ Server <br...@theperlreview.com> wrote:

> 5.4: How can I use Perl's "-i" option from within a program?

It is 'perl' there, no?

Marc


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

Date: Fri, 8 Jan 2010 15:18:53 -0800 (PST)
From: bsingh <bsinghrana@gmail.com>
Subject: Net::SSH::Expect SSHAuthenticationError Login timed out.
Message-Id: <490c6b09-1f04-4201-af1c-f0fa7d433331@c3g2000yqd.googlegroups.com>

I get the following error even though it is clearly connecting. Any
amount of timeout is not helping.
How do I avoid this exception? Thank you.

SSHAuthenticationError Login timed out. The input stream currently has
the contents bellow: Last login: Fri Jan  8 20:20:46 2010 from
gildb118.flowserve.net
 at /cygdrive/c/Data/perl_mods/lib/Expect.pm line 828
 at /cygdrive/c/Data/perl_mods/lib/Net/SSH/Expect.pm line 209
        Net::SSH::Expect::__ANON__[/cygdrive/c/Data/perl_mods/lib/Net/
SSH/Expect.pm:212]('ARRAY(0x10530758)') called at /cygdrive/c/Data/
perl_mods/lib/Expect.pm line 828
        Expect::_multi_expect(1, 'ARRAY(0x105308d8)', 'ARRAY
(0x10530ae8)') called at /cygdrive/c/Data/perl_mods/lib/Expect.pm line
565
        Expect::expect('Expect=GLOB(0x10576940)', 1, 'ARRAY
(0x105776c0)', 'ARRAY(0x10530218)', 'ARRAY(0x10530338)', 'ARRAY
(0x10530458)', 'ARRAY(0x10530590)') called at /cygdrive/c/Data/
perl_mods/lib/Net/SSH/Expect.pm line 580
        Net::SSH::Expect::_sec_expect('Net::SSH::Expect=HASH
(0x10517c08)', 1, 'ARRAY(0x105776c0)', 'ARRAY(0x10530218)', 'ARRAY
(0x10530338)', 'ARRAY(0x10530458)', 'ARRAY(0x10530590)') called at /
cygdrive/c/Data/perl_mods/lib/Net/SSH/Expect.pm line 213
        Net::SSH::Expect::login('Net::SSH::Expect=HASH(0x10517c08)')
called at netsshexpect.pl line 13

Here's the code
------------------------------------------
use Net::SSH::Expect;

my $ssh = Net::SSH::Expect->new (
            host => $host,
            password=> $pwd,
            user => $usr,
            raw_pty => 1,
            timeout => 10
        );

my $login_output = $ssh->login();


# disable terminal translations and echo on the SSH server
# executing on the server the stty command:
$ssh->exec("stty raw -echo");


my $cmd = "ls -l";
my $cmd_out;

$cmd_out = $ssh->exec($cmd);

print "\n";


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

Date: Sat, 9 Jan 2010 15:08:22 -0800 (PST)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: Net::SSH::Expect SSHAuthenticationError Login timed out.
Message-Id: <ccedd713-3023-440e-b992-d15db86fbacf@j24g2000yqa.googlegroups.com>

On Jan 8, 3:18=A0pm, bsingh <bsinghr...@gmail.com> wrote:
> I get the following error even though it is clearly connecting. Any
> amount of timeout is not helping.
> How do I avoid this exception? Thank you.
>
> SSHAuthenticationError Login timed out. The input stream currently has
> the contents bellow: Last login: Fri Jan =A08 20:20:46 2010 from
> gildb118.flowserve.net
> =A0at /cygdrive/c/Data/perl_mods/lib/Expect.pm line 828
> =A0at /cygdrive/c/Data/perl_mods/lib/Net/SSH/Expect.pm line 209
> =A0 =A0 =A0 =A0 Net::SSH::Expect::__ANON__[/cygdrive/c/Data/perl_mods/lib=
/Net/
> SSH/Expect.pm:212]('ARRAY(0x10530758)') called at /cygdrive/c/Data/
> perl_mods/lib/Expect.pm line 828
> =A0 =A0 =A0 =A0 Expect::_multi_expect(1, 'ARRAY(0x105308d8)', 'ARRAY
> (0x10530ae8)') called at /cygdrive/c/Data/perl_mods/lib/Expect.pm line
> 565
> =A0 =A0 =A0 =A0 Expect::expect('Expect=3DGLOB(0x10576940)', 1, 'ARRAY
> (0x105776c0)', 'ARRAY(0x10530218)', 'ARRAY(0x10530338)', 'ARRAY
> (0x10530458)', 'ARRAY(0x10530590)') called at /cygdrive/c/Data/
> perl_mods/lib/Net/SSH/Expect.pm line 580
> =A0 =A0 =A0 =A0 Net::SSH::Expect::_sec_expect('Net::SSH::Expect=3DHASH
> (0x10517c08)', 1, 'ARRAY(0x105776c0)', 'ARRAY(0x10530218)', 'ARRAY
> (0x10530338)', 'ARRAY(0x10530458)', 'ARRAY(0x10530590)') called at /
> cygdrive/c/Data/perl_mods/lib/Net/SSH/Expect.pm line 213
> =A0 =A0 =A0 =A0 Net::SSH::Expect::login('Net::SSH::Expect=3DHASH(0x10517c=
08)')
> called at netsshexpect.pl line 13
>
> Here's the code
> ------------------------------------------
> use Net::SSH::Expect;
>
> my $ssh =3D Net::SSH::Expect->new (
> =A0 =A0 =A0 =A0 =A0 =A0 host =3D> $host,
> =A0 =A0 =A0 =A0 =A0 =A0 password=3D> $pwd,
> =A0 =A0 =A0 =A0 =A0 =A0 user =3D> $usr,
> =A0 =A0 =A0 =A0 =A0 =A0 raw_pty =3D> 1,
> =A0 =A0 =A0 =A0 =A0 =A0 timeout =3D> 10
> =A0 =A0 =A0 =A0 );
>
> my $login_output =3D $ssh->login();


The Net::SSH::Expect doc shows a keyword search on the
login() output:

        if ($login_output !~ /Welcome/) {
            die "Login has failed....";
        }

Did you forget to do that?


> ...

--
Charles DeRykus


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

Date: Fri, 08 Jan 2010 15:26:58 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Permutations
Message-Id: <c7ffk5t6sc87rg4km8v6sj825svkellaod@4ax.com>

Justin C <justin.1001@purestblue.com> wrote:
>I need to calculate all permutations of a list. 

See "perldoc -q permute"

>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.

Maybe: for each generated number compute the matching mirrored number
and keep the generated number only if it is the smaller (or larger) of
the two numbers or if the two numbers are identical. This way you don't
need to repeatedly scan through the already computed numbers.

jue


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

Date: Fri, 08 Jan 2010 17:26:20 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Permutations
Message-Id: <080120101726202018%jimsgibson@gmail.com>

In article <c7ffk5t6sc87rg4km8v6sj825svkellaod@4ax.com>, Jürgen Exner
<jurgenex@hotmail.com> wrote:

> Justin C <justin.1001@purestblue.com> wrote:
> >I need to calculate all permutations of a list. 
> 
> See "perldoc -q permute"
> 
> >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.
> 
> Maybe: for each generated number compute the matching mirrored number
> and keep the generated number only if it is the smaller (or larger) of
> the two numbers or if the two numbers are identical. This way you don't
> need to repeatedly scan through the already computed numbers.

Note that if the elements are distinct, the reverse will never equal
the generated permutation. In addition, you only need compare the first
element of the permutation with the last element and keep only those
where the first is less than the last: e.g. compare the '1' and the '4'
in the example 1234 == 4321.

-- 
Jim Gibson


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

Date: Fri, 08 Jan 2010 18:43:31 -0800
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: Permutations
Message-Id: <4b47f75d$0$31744$ed362ca5@nr5-q3a.newsreader.com>

Justin C wrote:
> 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.

Just as long as rotational permutations are not also considered 
equivalent, per that very long thread a few months ago :)


> 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,

Absolutely, as long as you are only counting rather than enumerating, as 
as long as and each symbol appears only once:

my $reversed = scalar reverse $permutation;
if ($reversed lt $permutation) { $count++};

You don't need to store all or half of the permutations this way.

If symbols can appear more than once, then you would need to generate 
only distinct permutations (I've previously posted code to do that) and 
you would have to address palindromes, for example by counting each one 
as only 1/2 of a count.

> so that I don't have to
> calculate all of the permutations when I'll only need 50% of them.

You could do that too, but much less easily.  The standard permutation 
algorithms have no way to prune entire branches of the permutation 
chains, so you would have to implement your own.  Whether doing that is 
more amusing than solving the math problem is left as an exercise for 
the reader :)

In the case of 1234, if you decide to count only the lesser member of 
each mirror pair, then you would anchor the first and last symbol to be 
from the list:
1..2
1..3
1..4
2..3
2..4
3..4

And then would have to permute only the remaining two symbols 
(represented by the periods).  The six other "bookmark" pairs would not 
be needed to be generated, as they clearly fail the lesser member criterion.

Xho


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

Date: Sat, 9 Jan 2010 00:50:51 -0800 (PST)
From: Bart Van der Donck <bart@nijlen.com>
Subject: Re: Regex to extract email from .msg
Message-Id: <a6ce0d38-98f9-4cab-a9f5-97f169ed1c1c@m25g2000yqc.googlegroups.com>

Peter J. Holzer wrote:

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

For my particular situation, it appears that I need the raw method
anyhow. When I read directly with '<:encoding(UTF-16LE)', it says:

  "UTF-16LE:Unicode character fffe is illegal at script.pl line 32."

(32 is the line with the 'open'-call)

--
 Bart


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

Date: Sat, 09 Jan 2010 01:20:09 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Regex to extract email from .msg
Message-Id: <4bigk55och2n7uvhtq7dt14cqq4vdjtjbh@4ax.com>

Bart Van der Donck <bart@nijlen.com> wrote:
>For my particular situation, it appears that I need the raw method
>anyhow. When I read directly with '<:encoding(UTF-16LE)', it says:
>
>  "UTF-16LE:Unicode character fffe is illegal at script.pl line 32."

The only place where 0xFFFE could possibly show up is the byte order
mark (BOM) and I would be very surprised if Perl couldn't handle the
BOM. 
I would suggest to check the file with a hex editor to make sure it does
not contain an additional rouge BOM somewhere in the middle of the file.

jue


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

Date: Sat, 09 Jan 2010 05:41:49 -0800
From: sln@netherlands.com
Subject: Re: Regex to extract email from .msg
Message-Id: <l21hk5tj5tvcm2qu0focjkptpioogbpbp2@4ax.com>

On Sat, 9 Jan 2010 00:50:51 -0800 (PST), Bart Van der Donck <bart@nijlen.com> wrote:

>Peter J. Holzer wrote:
>
>> On 2010-01-08 09:58, Bart Van der Donck <b...@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;
>
>For my particular situation, it appears that I need the raw method
>anyhow. When I read directly with '<:encoding(UTF-16LE)', it says:
>
>  "UTF-16LE:Unicode character fffe is illegal at script.pl line 32."
>
>(32 is the line with the 'open'-call)

Try:
   open(my $in, '<:encoding(UTF-16)', $mypath) || die "Couldn't open file: $!";
                              ^^
                             UTF-16

fffe BOM is UTF-16LE, and should have opened ok.
However, when you read the first time without seeking past the 
bom offset (2), fffe is read and is illeagal UTF-16 char.

When you open with UTF-16 instead, the layer expects a BOM and
automatically moves the file position past it for the first read.
Its called the BOM bug !!!

Of course if you don't have a BOM, using UTF-16 will die with
"no BOM". Another bug !!!

I posted code before that auto navigates these waters, if you
bothered to look.

-sln


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

Date: Sat, 09 Jan 2010 05:47:56 -0800
From: sln@netherlands.com
Subject: Re: Regex to extract email from .msg
Message-Id: <t02hk5d4og9tllfhmfbgsh7bltinvb7aga@4ax.com>

On Sat, 09 Jan 2010 05:41:49 -0800, sln@netherlands.com wrote:

>On Sat, 9 Jan 2010 00:50:51 -0800 (PST), Bart Van der Donck <bart@nijlen.com> wrote:
>
>>Peter J. Holzer wrote:
>>
>>> On 2010-01-08 09:58, Bart Van der Donck <b...@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;
>>
>>For my particular situation, it appears that I need the raw method
>>anyhow. When I read directly with '<:encoding(UTF-16LE)', it says:
>>
>>  "UTF-16LE:Unicode character fffe is illegal at script.pl line 32."
>>
>>(32 is the line with the 'open'-call)
>
>Try:
>   open(my $in, '<:encoding(UTF-16)', $mypath) || die "Couldn't open file: $!";
>                              ^^
>                             UTF-16
>
>fffe BOM is UTF-16LE, and should have opened ok.
>However, when you read the first time without seeking past the 
>bom offset (2), fffe is read and is illeagal UTF-16 char.
>
>When you open with UTF-16 instead, the layer expects a BOM and
>automatically moves the file position past it for the first read.
>Its called the BOM bug !!!

The bug is that seek's are dead, you have to keep track of bom
offset yourself (if bom) and this should be transparent if :encoding(UTF-16).
>
>Of course if you don't have a BOM, using UTF-16 will die with
>"no BOM". Another bug !!!
>
>I posted code before that auto navigates these waters, if you
>bothered to look.
>
>-sln



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

Date: Sat, 9 Jan 2010 22:04:28 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Regex to extract email from .msg
Message-Id: <c4bn17-kbt2.ln1@osiris.mauzo.dyndns.org>


Quoth Jürgen Exner <jurgenex@hotmail.com>:
> Bart Van der Donck <bart@nijlen.com> wrote:
> >For my particular situation, it appears that I need the raw method
> >anyhow. When I read directly with '<:encoding(UTF-16LE)', it says:
> >
> >  "UTF-16LE:Unicode character fffe is illegal at script.pl line 32."
> 
> The only place where 0xFFFE could possibly show up is the byte order
> mark (BOM) and I would be very surprised if Perl couldn't handle the
> BOM. 

IIRC the the Perl UTF-16 layers are a little too picky. If you ask for
UTF-16LE, it will complain if there is a BOM. If, OTOH, you ask for
UTF-16, it will correctly detect the BOM and set the byte order from it.

> I would suggest to check the file with a hex editor to make sure it does
> not contain an additional rouge BOM somewhere in the middle of the file.

I wasn't aware BOMs came in different colours :).

Ben



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

Date: Fri, 08 Jan 2010 15:20:13 -0800
From: sln@netherlands.com
Subject: Re: translating an OS directory recursively into a tree object
Message-Id: <1affk5tl4tk31bkbg4mkahei20o0p2ckg2@4ax.com>

On Fri, 08 Jan 2010 14:30:45 -0800, sln@netherlands.com wrote:

>On Fri, 8 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 ;-).
>>
>>	hp
>
>s{ [^/]*/ }{| }xg,
>s{ \|\ ([^|]*)$ }{`--$1}x,
>print "$_\n" for @{[qw{
> .
> ./a
> ./a/b
> ./a/b/c
>}]};
>

Forgot that extra space.

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

-sln


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

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 2762
***************************************


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