[31100] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2345 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 17 00:09:46 2009

Date: Thu, 16 Apr 2009 21:09:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 16 Apr 2009     Volume: 11 Number: 2345

Today's topics:
    Re: effienct way to select random value from the hash <smallpond@juno.com>
    Re: effienct way to select random value from the hash <someone@example.com>
    Re: effienct way to select random value from the hash <1usa@llenroc.ude.invalid>
    Re: F<utf8.pm> is evil (was: XML::LibXML UTF-8 toString <whynot@pozharski.name>
        Net::FTPSSL Issue, can't put/get <christophergraber@gmail.com>
    Re: no $ENV{'CONTENT_LENGTH'} <someone@somewhere.nb.ca>
    Re: no $ENV{'CONTENT_LENGTH'} <1usa@llenroc.ude.invalid>
    Re: no $ENV{'CONTENT_LENGTH'} <tadmc@seesig.invalid>
        output from shell cmd <jrwats@gmail.com>
    Re: output from shell cmd <jrwats@gmail.com>
    Re: output from shell cmd <1usa@llenroc.ude.invalid>
    Re: output from shell cmd <ben@morrow.me.uk>
    Re: What does `my' do?! <peter@makholm.net>
    Re: What does `my' do?! <nospam-abuse@ilyaz.org>
    Re: What does `my' do?! <nospam-abuse@ilyaz.org>
    Re: What does `my' do?! <nospam-abuse@ilyaz.org>
    Re: What does `my' do?! <nospam-abuse@ilyaz.org>
    Re: What does `my' do?! <devnull4711@web.de>
    Re: What does `my' do?! <whynot@pozharski.name>
    Re: What does `my' do?! <tadmc@seesig.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 16 Apr 2009 13:34:13 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: effienct way to select random value from the hash
Message-Id: <e7099553-400a-431d-9d3f-b4c0b6dc8beb@r28g2000vbp.googlegroups.com>

On Apr 16, 10:35=A0am, viki <viki...@gmail.com> wrote:
> sub RandomElement { # select random element from the hash
> =A0 =A0 my ($hashref) =3D @_;
> =A0 =A0 my @keys =3D keys(%{$hashref});
> =A0 =A0 my $random =3D $hashref->{ $keys[ int(rand( @keys )) ]};
>
> }
>
> When the hash is large, the creation of @keys for every
> invocation is invefficient. It's waste that's O((N)) for every call to
> RandomElement.
>
> What would be the fastest version of RandomElement ?
>
> Thanks
> Viki


sub ran3($) {
    my ($hashref) =3D @_;
    my @vals =3D values(%{$hashref});
    $vals[ int(rand( @vals )) ];
}

10,000 calls to this took 2.341 s

to yours took 3.947 s

I also tried flattening the whole hash into
key/value pairs and choosing an odd element.
That took 6.161 s.




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

Date: Thu, 16 Apr 2009 14:41:58 -0700
From: "John W. Krahn" <someone@example.com>
Subject: Re: effienct way to select random value from the hash
Message-Id: <HCNFl.45635$e_5.41629@newsfe03.iad>

Ben Morrow wrote:
> Quoth "John W. Krahn" <jwkrahn@shaw.ca>:
>> Ben Morrow wrote:
>>> Presumably
>>>
>>>     sub RandomElement {
>>>         my ($hashref) = @_;
>>>         my ($count, $got);
>>>
>>>         scalar keys %$hashref;  # reset iterator
>>>         while (1) {
>>>             my ($k, $v) = each %$hashref;
>>>             $got = $v if 1 > rand ++$count;
>>>         }
>>>         return $got;
>>>     }
>>>
>>> would be more efficient for a large hash, since it doesn't build a list
>>> of the values. Since none of these are using the hash for lookup, it
>>> would be better to keep the values in an array and just use 
>>> $ary[rand @ary] instead.
>> Your while (1) loop doesn't end so it would probably be less efficient.
> 
> :)
> 
> I had initially forgotten that the algorithm needs to iterate over the
> whole hash, and was planning something like
> 
>     last if 1 > rand...;
> 
> to exit early.
> 
>> ITYM:
>>
>> while ( my ( $k, $v ) = each %$hashref ) {
>>      $got = $v if 1 > rand ++$count;
>> }
>>
>> But under my Benchmark tests that is less efficient than the OP's version.
> 
> Interesting. Presumably it's because there are more ops involved, and a
> new BLOCK every time around the while loop.

If you exit early then it is not truly random.  You have to iterate over 
the complete list to get a random element.

Actually, this appears to be a lot more efficient than the others:

sub RandomElement3 {
     my ( $hashref ) = @_;
     my $index = rand values %$hashref;
     my $random = ( values %$hashref )[ $index ];
     }



John
-- 
Those people who think they know everything are a great
annoyance to those of us who do.        -- Isaac Asimov


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

Date: Fri, 17 Apr 2009 01:19:37 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: effienct way to select random value from the hash
Message-Id: <Xns9BEFD8EFE6F35asu1cornelledu@127.0.0.1>

smallpond <smallpond@juno.com> wrote in
news:e7099553-400a-431d-9d3f-b4c0b6dc8beb@r28g2000vbp.googlegroups.com: 

> On Apr 16, 10:35 am, viki <viki...@gmail.com> wrote:
>> sub RandomElement { # select random element from the hash
>>     my ($hashref) = @_;
>>     my @keys = keys(%{$hashref});
>>     my $random = $hashref->{ $keys[ int(rand( @keys )) ]};
>>
>> }
>>
>> When the hash is large, the creation of @keys for every
>> invocation is invefficient. It's waste that's O((N)) for every call
>> to RandomElement.
>>
>> What would be the fastest version of RandomElement ?

 ...

> sub ran3($) {
>     my ($hashref) = @_;
>     my @vals = values(%{$hashref});
>     $vals[ int(rand( @vals )) ];
> }
> 
> 10,000 calls to this took 2.341 s

Interesting because here is what I get:

C:\Temp> cat t.pl

#!/usr/bin/perl

use strict;
use warnings;
use Benchmark qw( cmpthese );

my $h;

for (1 .. 10_000) {
    $h->{"key$_"} = rand;
}

cmpthese -5, {
    smallpond => sub { ran3($h)  },
    sinan     => sub { ran42($h) },
};

sub ran3 {
    my ($h) = @_;
    my @v = values %$h;
    $v[rand @v];
}

sub ran42 {
    my ( $h ) = @_;
    (values %$h)[rand values %$h ];
}

__END__

C:\Temp> t
            Rate smallpond     sinan
smallpond  288/s        --      -82%
sinan     1569/s      446%        --


-- 
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://www.rehabitation.com/clpmisc/


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

Date: Fri, 17 Apr 2009 03:23:39 +0300
From: Eric Pozharski <whynot@pozharski.name>
Subject: Re: F<utf8.pm> is evil (was: XML::LibXML UTF-8 toString() -vs- nodeValue())
Message-Id: <slrngufj2u.36t.whynot@orphan.zombinet>

On 2009-04-15, Peter J. Holzer <hjp-usenet2@hjp.at> wrote:
> On 2009-04-14 23:45, Eric Pozharski <whynot@pozharski.name> wrote:
>> On 2009-04-12, Peter J. Holzer <hjp-usenet2@hjp.at> wrote:
>>
>> I've thought a lot.  I should admit, whenever I see C<use 'utf8';>
>> instead of C<use encoding 'utf8';> I'm going nuts.
>
> I'm going nuts when I see "use encoding". It does way too many magic
> things and most of them only half-baked. Here be dragons! Don't use that
> stuff, if you value your sanity.

I'm puzzled.  However, I should admit, that I've yet found those dark
corners of C<use encoding 'utf8';>.  And I'm not afraid of dragons.

>> And with C<use encoding 'utf8';> you'll get the same character string,
>> and lots of other useful stuff.
>
> Correction: Lots of stuff which looks useful at first glance but which
> works in subly different ways than you expect (and some stuff which you
> simply don't expect). "use utf8" OTOH does only one thing, and it does
> it well.

I fail to see how utfizing both literals and symbols makes F<utf8.pm>
doing one thing.  I don't say that it doesn't do it well.

>> (I just can't get why anyone would need
>> implicit upgrade of scalars into characters and yet then maintain wide
>> IO.)  But my point isn't that F<encoding.pm> outperforms F<utf8.pm>.
>> I'm scared.  I consider F<utf8.pm> kind of Pandora box.  Read this, if
>> you can
>>
>> 	ΠΏΡ€ΠΎΡ† Π·Π°ΠΏΡ€ΠΎΡΠΈΡ‚ΡŒ {
>> 	   ΠΌΠΎΠ΅ ($имяфайла) = @_;
> [...]
>> 	}
>>
>> I admit, it's imposible to write this with F<utf8.pm> alone
>
> Right. "sub" still is "sub", not "ΠΏΡ€ΠΎΡ†", and "my" is still "my", not
> "ΠΌΠΎΠ΅". Your example is more like a Russian(?) equivalent to
> Lingua::Romana::Perligata. 
>
> And frankly, "ΠΏΡ€ΠΎΡ† Π·Π°ΠΏΡ€ΠΎΡΠΈΡ‚ΡŒ" is only marginable less readable to me
> than "sub zaprosit". I need a dictionary for both, and "Π·Π°ΠΏΡ€ΠΎΡΠΈΡ‚ΡŒ" at
> least has the advantage that I can actually find it in a Russian
> dictionary :-). If you want your software to be maintainable by authors
> from other countries, stick to English and write "sub request". If you
> want to use Russian names you might as well go all the way and use
> cyrillic letters instead of a transliteration into latin letters which
> neither those who speak Russian nor those who don't speak Russian
> understand easily.

So you suggest that localizing Perl (or actually any other language) is
kind of online dictionary providers conspiracy?  I didn't think it this
way, should consider.

>> I bet you've seen this before,
>
> I've seen German versions of BASIC in the 1980's. They weren't a huge
> success, to put it mildly. About the only successful localization of a
> programming language i can think of is MS-Excel (and I guess it's
> debatable if this is even a programming language (without VBA) - is it
> turing-complete?).

That's in case you have an option.  There're places you have no option.

>> Someone could say "Who the heck would need that stupidity?"  Idiots.  It
>> still surprises me how many idiots are around.  They would scream:
>> "Look!  What a cool stuff!  I have to learn nothing!"
>
> Idiots indeed, if they think learning a few dozen keywords is the
> hardest part in learning a programming language. In fact I think the
> main reason why localized programming languages are so unpopular is that
> people figure out that it doesn't make any difference whether you
> declare a lexical variable with "my", "ΠΌΠΎΠ΅", or "mein": You have to
> learn the keyword anyway and you have to learn what it means and how to
> use it.

Then get any dictionary handy, till they are cheap.


*SKIP*
>>> That doesn't fix the endianness, and it behaves completely differently. 
>>> "perl -Mencoding=ucs2" can't work, as I already explained to sln.
*SKIP*
>> However, since I don't understand why it "can't work",
>
> It can't work because -Mencoding=ucs2 says that the source code is
> encoded in ucs2. So your script would have to begin with the byte
> sequence 
>
>     FE FF 00 70 00 72 00 69 00 6e 00 74 00 20 ...
>
> to be interpreted as "print ...". But it doesn't (and it can't because
> you cannot pass arguments with embedded null bytes in Unix).
> It begins with 
>
>     70 72 69 6e 74 20 
>
> which doesn't seem to be anything useful in UCS2 (U+2074 is SUPERSCRIPT
> FOUR, but the rest is unassigned in both big and little endian).
>
> It becomes worse if you use "use encoding 'ucs2';" inside a script:
> You would have to start the script in US-ASCII so that "use encoding
> 'ucs2';" is recognized and then switch to UCS2: So you need to mix two
> different incompatible encodings in the same script: Good luck finding
> an editor which supports this. And you don't have to, anyway, because if
> you want to encode your scripts in UTF-16, you can just do it and perl
> will notice it automatically (but Unix won't recognize the hashbang any

Ouch.  Shame on me.

> more, so you don't want to do this on Unix - you might on windows,
> though).

I don't windows.

-- 
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom


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

Date: Thu, 16 Apr 2009 17:00:43 -0700 (PDT)
From: chrisg <christophergraber@gmail.com>
Subject: Net::FTPSSL Issue, can't put/get
Message-Id: <36d7968f-0fe6-43b4-a638-633055ef7299@c9g2000yqm.googlegroups.com>

Didn=92t see any contact info for the current maintainer, sorry. Tried
to email the orig author but it came back undeliverable.

Trying to connect to a FTP (TLS) server and get/put files. I can
connect to the ftp site via FileZilla app in windows and transfer
files using FTP over TLS explicit encryption, port 21, Passive mode. I
first had to accept cert.

I recently downloaded http://search.cpan.org/CPAN/authors/id/C/CL/CLEACH/Ne=
t-FTPSSL-0.08.tar.gz
Then also http://search.cpan.org/dist/IO-Socket-SSL/SSL.pm I set them
up on my suse linux server manually. I get a =93534 Fallback to [C]=94
error when trying to get/put files on the external FTP server.
IO::Socket::SSL said "You have version 1.30 of Net::SSLeay. Support
for subjectAltNames in certificates is only available in Version
>=3D1.33" but I don't think that should matter.

I have the following test script on my linux suse box:

#! /usr/bin/perl
use strict;
use warnings;
use Net::FTPSSL;
my $ftpsite =3D "ftp.foo.com";
my $ftpuser =3D "1111";
my $ftppwd =3D "123456";
my $ftps =3D Net::FTPSSL->new($ftpsite, Port =3D> 21, Encryption =3D> "E",
Debug =3D> 1) or die "Cannot connect to $ftpsite";
$ftps->login($ftpuser, $ftppwd) or die "Cannot login: ", $ftps-
>last_message;
$ftps->command("PASV");
$ftps->cwd("/report_broadcasts") or die "Cannot change working
directory ", $ftps->last_message;
if(!$ftps->get("test.txt")) {
    print "Cannot get file: ", $ftps->last_message;
}
$ftps->quit;

Here=92s what I get. Apparently the "cwd" works, but "get" doesn't:

SKT <<< 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
SKT <<< 220-You are user number 4 of 50 allowed.
SKT <<< 220-Local time is now 20:20. Server port: 21.
SKT <<< 220-This is a private system - No anonymous login
SKT <<< 220-IPv6 connections are also welcome on this server.
SKT <<< 220 You will be disconnected after 5 minutes of inactivity.
SKT >>> AUTH TLS
SKT <<< 234 AUTH TLS OK.
>>> USER 1111
<<< 331 User 1111 OK. Password required
>>> PASS *******
<<< 230-Your bandwidth usage is restricted
<<< 230-User 1111 has group access to:  nobody
<<< 230 OK. Current restricted directory is /
>>> PASV
>>> CWD /report_broadcasts
<<< 227 Entering Passive Mode (4,78,144,125,235,152)
>>> PBSZ 0
<<< 250 OK. Current directory is /report_broadcasts
>>> PROT P
<<< 200 PBSZ=3D0
>>> PASV
<<< 534 Fallback to [C]
>>> QUIT
<<< 227 Entering Passive Mode (4,78,144,125,235,235)
Cannot get file: 534 Fallback to [C]


In Filezilla when I do the same thing I get:

Status:	Connecting to ftp.foo.com ...
Status:	Connected with ftp.foo.com, negotiating SSL connection...
Response:	220---------- Welcome to Pure-FTPd [privsep] [TLS]
----------
Response:	220-You are user number 3 of 50 allowed.
Response:	220-Local time is now 19:52. Server port: 21.
Response:	220-This is a private system - No anonymous login
Response:	220-IPv6 connections are also welcome on this server.
Response:	220 You will be disconnected after 5 minutes of inactivity.
Command:	AUTH TLS
Response:	234 AUTH TLS OK.
Status:	SSL connection established. Waiting for welcome message...
Command:	USER 1111
Response:	331 User 1111 OK. Password required
Command:	PASS **********
Response:	230-Your bandwidth usage is restricted
Response:	230-User 1111 has group access to:  nobody
Response:	230 OK. Current restricted directory is /
Command:	FEAT
Response:	211-Extensions supported:
Response:	 EPRT
Response:	 IDLE
Response:	 MDTM
Response:	 SIZE
Response:	 REST STREAM
Response:	 MLST
type*;size*;sizd*;modify*;UNIX.mode*;UNIX.uid*;UNIX.gid*;unique*;
Response:	 MLSD
Response:	 ESTP
Response:	 PASV
Response:	 EPSV
Response:	 SPSV
Response:	 ESTA
Response:	 AUTH TLS
Response:	 PBSZ
Response:	 PROT
Response:	211 End.
Command:	SYST
Response:	215 UNIX Type: L8
Command:	PBSZ 0
Response:	200 PBSZ=3D0
Command:	PROT P
Response:	534 Fallback to [C]
Status:	Connected
Status:	Retrieving directory listing...
Command:	PWD
Response:	257 "/" is your current location
Command:	TYPE A
Response:	200 TYPE is now ASCII
Command:	PASV
Response:	227 Entering Passive Mode (4,78,144,125,235,216)
Command:	LIST
Response:	150 Accepted data connection
Response:	226-Options: -l
Trace:	drwxr-xr-x    2 0        0            4096 Apr 15 11:20 lists
Trace:	drwxr-xr-x    2 0        0            4096 Apr 16 15:31
report_broadcasts
Trace:	drwxr-xr-x    2 0        0            4096 Apr 16 00:06
report_endofday
Trace:	drwxr-xr-x    5 0        0            4096 Apr 13 13:45
schedule
Response:	226 4 matches total
Status:	Directory listing successful
Status:	Retrieving directory listing...
Command:	CWD report_broadcasts
Response:	250 OK. Current directory is /report_broadcasts
Command:	PWD
Response:	257 "/report_broadcasts" is your current location
Command:	TYPE A
Response:	200 TYPE is now ASCII
Command:	PASV
Response:	227 Entering Passive Mode (4,78,144,125,235,168)
Command:	LIST
Response:	150 Accepted data connection
Response:	226-Options: -l
Trace:	-rw-r--r--    1 0        0              35 Apr 15 19:19
test.txt
Response:	226 15 matches total
Status:	Directory listing successful
Status:	Starting download of /report_broadcasts/test.txt
Command:	TYPE A
Response:	200 TYPE is now ASCII
Command:	PASV
Response:	227 Entering Passive Mode (4,78,144,125,235,146)
Command:	RETR test.txt
Response:	150 Accepted data connection
Response:	226-File successfully transferred
Response:	226 0.001 seconds (measured here), 51.70 Kbytes per second
Status:	Download successful



Any ideas?



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

Date: Thu, 16 Apr 2009 21:16:19 -0300
From: "Guy" <someone@somewhere.nb.ca>
Subject: Re: no $ENV{'CONTENT_LENGTH'}
Message-Id: <49e7ca35$0$5463$9a566e8b@news.aliant.net>


"Tad J McClellan" <tadmc@seesig.invalid> a ιcrit dans le message de news: 
slrngueq3p.t5t.tadmc@tadmc30.sbcglobal.net...
> A. Sinan Unur <1usa@llenroc.ude.invalid> wrote:
>> "Guy" <someone@somewhere.nb.ca> wrote in
>> news:49e69739$0$5478$9a566e8b@news.aliant.net:
>
>>> I had forgotten about GET/POST.
>>
>> Use CGI.pm or CGI::Simple rather than cargo cult code to decode and
>> process requests.
>
>
> That was suggested to him 8 years ago.
>
> Time to exercise some intolerance with regard to this OP...

Ok, I guess it's time to pick up a recent book on Perl and start reading. 
But how in God's name can you remember that I asked that 8 years ago?  Even 
I don't remember that!!
Guy 




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

Date: Fri, 17 Apr 2009 01:54:34 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: no $ENV{'CONTENT_LENGTH'}
Message-Id: <Xns9BEFDEDCE6E33asu1cornelledu@127.0.0.1>

"Guy" <someone@somewhere.nb.ca> wrote in
news:49e7ca35$0$5463$9a566e8b@news.aliant.net: 

> 
> "Tad J McClellan" <tadmc@seesig.invalid> a ιcrit dans le message de
> news: slrngueq3p.t5t.tadmc@tadmc30.sbcglobal.net...
>> A. Sinan Unur <1usa@llenroc.ude.invalid> wrote:
>>> "Guy" <someone@somewhere.nb.ca> wrote in
>>> news:49e69739$0$5478$9a566e8b@news.aliant.net:
>>
>>>> I had forgotten about GET/POST.
>>>
>>> Use CGI.pm or CGI::Simple rather than cargo cult code to decode and
>>> process requests.
>>
>>
>> That was suggested to him 8 years ago.
>>
>> Time to exercise some intolerance with regard to this OP...
> 
> Ok, I guess it's time to pick up a recent book on Perl and start
> reading. But how in God's name can you remember that I asked that 8
> years ago?  Even I don't remember that!!

That's a job for score files. Tad has a good one.

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://www.rehabitation.com/clpmisc/


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

Date: Thu, 16 Apr 2009 21:22:42 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: no $ENV{'CONTENT_LENGTH'}
Message-Id: <slrngufpvi.670.tadmc@tadmc30.sbcglobal.net>


[ Please excuse my piggybacking, but Guy's post is not on my server ]


A. Sinan Unur <1usa@llenroc.ude.invalid> wrote:

[ nothing that I'm going to quote ]

> "Guy" <someone@somewhere.nb.ca> wrote in

>> But how in God's name can you remember that I asked that 8
>> years ago?  Even I don't remember that!!


I have archived all of my Usenet posts for more than a decade now.

Your name seemed familiar, so I grep'd it in my archive.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Thu, 16 Apr 2009 16:40:06 -0700 (PDT)
From: jrwats <jrwats@gmail.com>
Subject: output from shell cmd
Message-Id: <7fb7ab84-5759-4c0d-9ed5-7570c7eaf8cf@u9g2000pre.googlegroups.com>

When executing some command via backticks like the following:

$strCmd = <<'HEREDOC';
someExecutable.exe -a -bunch -of -options
HEREDOC
`$strCmd`;

the only way to get output from the result is to do:

$result = `$strCmd`;
print $result;

Is there any way to get output from the command real-time?  I don't
even need to save the results, I just want the output to go to stdout
as it would if I had run the command from a bash script.

Thanks,
JW


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

Date: Thu, 16 Apr 2009 17:28:50 -0700 (PDT)
From: jrwats <jrwats@gmail.com>
Subject: Re: output from shell cmd
Message-Id: <88b1dbf5-d322-44c9-a775-13d81f077f5e@s1g2000prd.googlegroups.com>


> Is there any way to get output from the command real-time? =A0I don't
> even need to save the results, I just want the output to go to stdout
> as it would if I had run the command from a bash script.
>

Looks like the system(@args) command is the answer to that question.


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

Date: Fri, 17 Apr 2009 00:30:42 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: output from shell cmd
Message-Id: <Xns9BEFD0A5161CEasu1cornelledu@127.0.0.1>

jrwats <jrwats@gmail.com> wrote in news:7fb7ab84-5759-4c0d-9ed5-
7570c7eaf8cf@u9g2000pre.googlegroups.com:

> Is there any way to get output from the command real-time?  I don't
> even need to save the results, I just want the output to go to stdout
> as it would if I had run the command from a bash script.

Hmmmm ...

perldoc -f system

-- 
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://www.rehabitation.com/clpmisc/


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

Date: Fri, 17 Apr 2009 01:20:12 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: output from shell cmd
Message-Id: <siukb6-hqm1.ln1@osiris.mauzo.dyndns.org>


Quoth jrwats <jrwats@gmail.com>:
> When executing some command via backticks like the following:
> 
> $strCmd = <<'HEREDOC';
> someExecutable.exe -a -bunch -of -options
> HEREDOC
> `$strCmd`;
> 
> the only way to get output from the result is to do:
> 
> $result = `$strCmd`;
> print $result;
> 
> Is there any way to get output from the command real-time?  I don't
> even need to save the results, I just want the output to go to stdout
> as it would if I had run the command from a bash script.

perldoc -q backtick

Ben



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

Date: Thu, 16 Apr 2009 17:29:20 +0200
From: Peter Makholm <peter@makholm.net>
Subject: Re: What does `my' do?!
Message-Id: <87d4bcty5r.fsf@vps1.hacking.dk>

Ilya Zakharevich <nospam-abuse@ilyaz.org> writes:

> Apparently, [*]-action is not executed in this context.  The question
> is: why?  Is it documented?

perlsub(1) got the following under the heading 'Private Variables via
my()':

    A "my" has both a compile-time and a run-time effect.  At
    compile time, the compiler takes notice of it.  The principal
    usefulness of this is to quiet "use strict 'vars'", but it is
    also essential for generation of closures as detailed in
    perlref.  Actual initialization is delayed until run time,
    though, so it gets executed at the appropriate time, such as
    each time through a loop, for example.

Not that perlsub(1) is the most intuitive place to look for the
documentation for 'my', but at least 'perldoc -f my' referes to it, so
it should be findable.

//Makholm


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

Date: Thu, 16 Apr 2009 22:43:20 GMT
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: What does `my' do?!
Message-Id: <slrngufd48.j7o.nospam-abuse@chorin.math.berkeley.edu>

On 2009-04-16, sln@netherlands.com <sln@netherlands.com> wrote:
> On Thu, 16 Apr 2009 14:15:40 GMT, Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
> perl -wle " BEGIN{ $x=12; print $x; } print 'here'; my $x=99; print $x"
> 12
> here
> 99
> ------------
> perl -wle " BEGIN{ $x=12; print $x; } print 'here'; my $x; print $x"
> 12
> here
> Use of uninitialized value in print at -e line 1.

Keep in mind that in these examples you have DIFFERENT variables, all
named $x.

Yours,
Ilya


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

Date: Thu, 16 Apr 2009 22:55:28 GMT
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: What does `my' do?!
Message-Id: <slrngufdr0.j7o.nospam-abuse@chorin.math.berkeley.edu>

On 2009-04-16, Ben Morrow <ben@morrow.me.uk> wrote:
> what you expect is exactly what happens. OK, let's see what's in
> pp_hot.c... it appears that 'my' actually clears the variable on scope
> *exit*, not when the 'my' is encountered at runtime, and this has been
> there since at least 5.000. I suppose it makes sense: since we must
> clear the variable on scope exit (to get timely destruction), there's no
> point clearing it on scope entry as well.

Thanks a lot.  This is an explanation which is "almost correct" (see
below), and may be reasonably expected to be understood even by people
who do not read Perl source...  In other words, it makes sense to
document this...

====

Why it is not completely correct:

  perl -wle "eval shift; delayed()" "my $x; $x=12; sub delayed {print $x}"
  12

*After* `eval' is executed, the scope of $ARGV[0] is exited.  But as
you see (and this is *very expected*), $x is not cleared on scope
exit.

I think it might have been even myself who implemented (one of the
facets of) this behaviour.  The more complete explanation should be
more similar to:

 if refcount of lexical variable is 1, it is cleared on exit;

 otherwise it is marked in some way, and it is cleared on entry...

I'm kinda fuzzy on details...

Thanks again,
Ilya


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

Date: Thu, 16 Apr 2009 22:58:04 GMT
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: What does `my' do?!
Message-Id: <slrngufdvs.j7o.nospam-abuse@chorin.math.berkeley.edu>

On 2009-04-16, Tad J McClellan <tadmc@seesig.invalid> wrote:
>>   perl -wle "my $x; BEGIN{ $x=12 } print $x"
>>   12

> You develop on Windows?

I still manage to run OS/2 on all boxes in the house...

Hope this helps,
Ilya


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

Date: Thu, 16 Apr 2009 23:00:46 GMT
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: What does `my' do?!
Message-Id: <slrngufe4u.j7o.nospam-abuse@chorin.math.berkeley.edu>

On 2009-04-16, Peter Makholm <peter@makholm.net> wrote:
> perlsub(1) got the following under the heading 'Private Variables via
> my()':
>
>     A "my" has both a compile-time and a run-time effect.  At
>     compile time, the compiler takes notice of it.  The principal
>     usefulness of this is to quiet "use strict 'vars'", but it is
>     also essential for generation of closures as detailed in
>     perlref.  Actual initialization is delayed until run time,
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>     though, so it gets executed at the appropriate time, such as
>     each time through a loop, for example.
>
> Not that perlsub(1) is the most intuitive place to look for the
> documentation for 'my', but at least 'perldoc -f my' referes to it, so
> it should be findable.

Now, if you look AGAIN at what I wrote, you see that this explanation
is not correct.

(Likewise for many other replies from people who forget how `my $foo'
behaves in a loop.)

Yours,
Ilya


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

Date: Fri, 17 Apr 2009 01:11:21 +0200
From: Frank Seitz <devnull4711@web.de>
Subject: Re: What does `my' do?!
Message-Id: <74ps8pFt8okjU9@mid.individual.net>

Ilya Zakharevich wrote:
> On 2009-04-16, Peter Makholm <peter@makholm.net> wrote:
>> perlsub(1) got the following under the heading 'Private Variables via
>> my()':
>>
>>     A "my" has both a compile-time and a run-time effect.  At
>>     compile time, the compiler takes notice of it.  The principal
>>     usefulness of this is to quiet "use strict 'vars'", but it is
>>     also essential for generation of closures as detailed in
>>     perlref.  Actual initialization is delayed until run time,
>                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>     though, so it gets executed at the appropriate time, such as
>>     each time through a loop, for example.
>>
>> Not that perlsub(1) is the most intuitive place to look for the
>> documentation for 'my', but at least 'perldoc -f my' referes to it, so
>> it should be findable.
> 
> Now, if you look AGAIN at what I wrote, you see that this explanation
> is not correct.

I think it is correct. Initialization means assignment.
You didn't assign a value in your code.

Frank
-- 
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen fόr Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel


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

Date: Fri, 17 Apr 2009 03:31:50 +0300
From: Eric Pozharski <whynot@pozharski.name>
Subject: Re: What does `my' do?!
Message-Id: <slrngufji9.36t.whynot@orphan.zombinet>

On 2009-04-16, Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
> I managed to confuse myself in a teaspoon...  Consider
>
>   perl -wle "my $x; BEGIN{ $x=12 } print $x"
>   12

Fairly strange shell you have.  Or this is a violation of
copy-paste-but-retype rule.

I've come to conclusion that either everyone just translated seemlesly
double-quotes in single-quotes (while retyping) or everyone are that
afraid of you that just prefered to skip that.  How you've managed them
into that fear?

*CUT*

-- 
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom


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

Date: Thu, 16 Apr 2009 21:28:43 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: What does `my' do?!
Message-Id: <slrngufqar.670.tadmc@tadmc30.sbcglobal.net>

Eric Pozharski <whynot@pozharski.name> wrote:
> On 2009-04-16, Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
>> I managed to confuse myself in a teaspoon...  Consider
>>
>>   perl -wle "my $x; BEGIN{ $x=12 } print $x"
>>   12
>
> Fairly strange shell you have.


That's what I thought too.

Not actually that the shell was strange, but that it was strange
for a programmer of Ilya's cluefulness to be using Windows (which
was my erroneous guess as to why it was double quoted).

I asked him, and he explained else-thread.


> everyone are that
> afraid of you that just prefered to skip that.  How you've managed them
> into that fear?


I am fearless!

I am unmanageable!  (and so is my hair)


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

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


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