[28645] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 10009 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 26 14:06:07 2006

Date: Sun, 26 Nov 2006 11:05:06 -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           Sun, 26 Nov 2006     Volume: 10 Number: 10009

Today's topics:
    Re: a short non-working Perl script (OT) <wahab@chemie.uni-halle.de>
    Re: a short non-working Perl script <mritty@gmail.com>
    Re: a short non-working Perl script <bik.mido@tiscalinet.it>
    Re: Calling Perl program from Java Script and populatin krakle@visto.com
    Re: die on "use of uninitialized value"? <bik.mido@tiscalinet.it>
    Re: handling hanging database connections: timeout in p daniel.crosby@gmx.de
    Re: I use TK to show some chinese web page, I get nothi <zentara@highstream.net>
    Re: Is a file in use? <hjp-usenet2@hjp.at>
    Re: Is a file in use? <bik.mido@tiscalinet.it>
    Re: Is a file in use? <hjp-usenet2@hjp.at>
    Re: my <benmorrow@tiscali.co.uk>
    Re: my <hjp-usenet2@hjp.at>
    Re: my <tadmc@augustmail.com>
    Re: Net::SSH::Perl -- can I capture the command prompt? <hjp-usenet2@hjp.at>
    Re: Perl and Online Banking usenet@DavidFilmer.com
    Re: prevent further hash auto-vivification <benmorrow@tiscali.co.uk>
    Re: problems while compiling perl on solaris 10 <hjp-usenet2@hjp.at>
        Running and Feeding Input to Interactive Program in Win zemalf@gmail.com
    Re: Running and Feeding Input to Interactive Program in <jurgenex@hotmail.com>
    Re: seek/tell in presence of multibyte characters <hjp-usenet2@hjp.at>
    Re: seek/tell in presence of multibyte characters <robert.dodier@gmail.com>
    Re: seek/tell in presence of multibyte characters <robert.dodier@gmail.com>
    Re: speaking of forking -- parallel database fetches? <hjp-usenet2@hjp.at>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 26 Nov 2006 12:54:08 +0100
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: a short non-working Perl script (OT)
Message-Id: <ekbvi6$ajr$1@mlucom4.urz.uni-halle.de>

Thus spoke Gunnar Hjalmarsson (on 2006-11-26 06:05):

> Paul Lalli wrote:
>> Mark Tarver wrote:
>>>for my own education I would still like to know the answer to my
>>>question as to how $buffer can read the output of series of forms.
>> 
>> Un-f***ing-believable.  Your question was answered at least 4 times,
> 
> Then I have a problem with the maths. Which 4 posts explain that the 
> STDIN contents in $buffer is replaced by the return value from read()?

I think Paul, who is in almost all cases (I know of)
a very helpful guy, gut somehow upset without any
real reason - maybe because he doesn't bother to
envisage the personality of his disputants
"by default" ... ;-)

http://groups.google.com/groups/profile?enc_user=DoSuDxkAAAAuiTJYvEBPtbjX9KoCqqCVYIlA15amWEd-_934DYe-qw&hl=en

Regards

M.


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

Date: 26 Nov 2006 04:56:09 -0800
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: a short non-working Perl script
Message-Id: <1164545769.092801.135710@l12g2000cwl.googlegroups.com>

Gunnar Hjalmarsson wrote:
> Paul Lalli wrote:
> > Mark Tarver wrote:
> >>for my own education I would still like to know the answer to my
> >>question as to how $buffer can read the output of series of forms.
> >
> > Un-f***ing-believable.  Your question was answered at least 4 times,
>
> Then I have a problem with the maths. Which 4 posts explain that the
> STDIN contents in $buffer is replaced by the return value from read()?


Alright, fine, I overestimated.  Two posts:
http://groups.google.com/group/comp.lang.perl.misc/msg/e9017fc8aa1c572d
:: From perldoc -f read:
::
:: Attempts to read LENGTH characters of data into variable SCALAR from
:: the specified FILEHANDLE.  Returns the number of characters actually
:: read...
::
:: You are overwriting the $buffer contents with the number of
characters.

http://groups.google.com/group/comp.lang.perl.misc/msg/7479274c2876d0d4
:: $buffer is passed as the second argument to the function, and
:: the function fills that buffer.  It then returns HOW MANY BYTES
:: WERE READ, not the actual text.  Therefore, you're reading, for
:: example, "Hello World", which Perl is storing into $buffer
:: automatically. But then you immediately replace that string with
:: the number 11, because you assigned the $buffer variable to the
:: return value of read().

> > at least one of those times by me.
>
> Where?

The second one I just quoted.

> > Screw you.  We did answer it.  Repeatedly.  Your inability to read is
> > now your own problem.
>
> What about ability to count? ;-)

Damnit, Gunnar, I'm a programmer, not a mathematician! ;-)

Paul Lalli



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

Date: Sun, 26 Nov 2006 15:04:20 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: a short non-working Perl script
Message-Id: <lk7jm2pj1jig00k8qqns0i9thrj2blm26o@4ax.com>

On 26 Nov 2006 04:56:09 -0800, "Paul Lalli" <mritty@gmail.com> wrote:

>> What about ability to count? ;-)
>
>Damnit, Gunnar, I'm a programmer, not a mathematician! ;-)

Damnit Paul, do not confuse Mathematics with something having to do
with the ability to count! ;-)


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: 26 Nov 2006 10:06:35 -0800
From: krakle@visto.com
Subject: Re: Calling Perl program from Java Script and populating the list boxes
Message-Id: <1164564395.401941.279740@14g2000cws.googlegroups.com>



On Nov 3, 12:41 pm, Christian Winter <thepoet_nos...@arcor.de> wrote:
> There's absolutely no need to mess with file extensions on the
> server side. Every halfway decent browser will take any extension
> the server uses for its CGIs or applications, as long as the
> returned Content-Type: header and the HTML attribution for the
> script tag are correct.

The server will NEVER execute the .js file as a CGI script unless you
change the type with the server to a cgi executable. If you leave it
alone (as you suggest) it will simply serve the .js as text including
the Perl code.



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

Date: Sun, 26 Nov 2006 15:16:13 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: die on "use of uninitialized value"?
Message-Id: <cn7jm21mtlamtr5mcd1m9n2dr1r5deb5v0@4ax.com>

On 25 Nov 2006 07:30:50 -0800, "Brian McCauley" <nobull67@gmail.com>
wrote:

>> Yes, but that would be rather strange since that particular warning is
>> probably the most common and reasonable one for which people
>> consciously wants to temporarily disable warnings.
>
>That does not follow.
>
>The fact that one often wants to treat undef as "" or 0 without warning
>is in now way mutually exclusive with the idea that there are other
>times when you'd want that same warning promoted to an error.

You're right, of course. But since the OP seemed to want to do so on a
regular basis, I wouldn't count that strictly as "other times". Well,
before you tell me, I'll say it in the first place: indeed "under any
circumstance" logically is a particular instance of a "in a particular
circumstance". I agree. Yet, in common sense they describe somewhat
different situations. So all in all I would say that the two concepts
are not perfectly orthogonal, but let's say that they have a very
small internal product wrt their norms, and I still find *slightly*
surprising to want to have *that* warning promoted to an error.


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: 26 Nov 2006 09:34:17 -0800
From: daniel.crosby@gmx.de
Subject: Re: handling hanging database connections: timeout in perl
Message-Id: <1164562457.634243.16570@l39g2000cwd.googlegroups.com>

The script contains also the following information, i cannot see why
the timeout would not be used when specified, some database connections
just hang and do not timeout as they should per script.

sub ConnectTimeOut {
# ================================================================
        my ($p_host, $p_db, $p_ars, $p_sev, $p_erg)=@_;
        my @l_errstr = grep $DBI::errstr =~ m/$_/, keys
%G_IGNORE_ORACLE_ERRORS;
        $l_msg   = "$p_db Timeout  $G_CONF{TIMEOUT_DB_CONNECT} sec
occurred conn
ecting $p_db";
        &Logging (0, $A, "timeout", $l_msg);



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

Date: Sun, 26 Nov 2006 18:54:04 GMT
From: zentara <zentara@highstream.net>
Subject: Re: I use TK to show some chinese web page, I get nothing,why?
Message-Id: <n2ojm21p4qm96l0irbmbaeogutupo4ve8e@4ax.com>

On 25 Nov 2006 18:00:20 -0800, quakewang@mail.whut.edu.cn wrote:

>      In the following problem, I use TK to get a page and show it, but
>
>I get nothing when I use it on a chinese web page, and it can get some
>thing for a english based web page, why?

There is something funny in the way you decide there are no results,
and when a error occurs. so it shows nothing.
I tried chopping down your script, so that it just displayed the page
without any word search or html parsing, so to work out 1 problem
at a time.
Your script did not display Chinese characters properly, on my
machine.

This is what I did. 
In order to avoid the complexity of your html parsing, (which I think is
broken), I just display the url, so you can see it works.
>      I think it may the the "FONT" problem, but I do not not how to
>special a chinese font.

I commented out all font lines and let Tk do it.
I hope it helps you out. I just used a simple parser
to extract text.

#!/usr/bin/perl
use warnings;
use strict;
use Tk;
require LWP::UserAgent;
use utf8;
use Encode;
use HTML::Encoding 'encoding_from_http_message';
use HTML::TokeParser;
use HTML::TokeParser::Simple;

my $url = "http://dict.cn/search/";

my $mw = MainWindow->new;

$mw->fontCreate('medium',
   -family=>'courier',
   -weight=>'bold',
   -size=>int(-14*14/10));         

my $scroll = $mw->Scrollbar;
my $text = $mw->Text(-yscrollcommand => ['set', $scroll],
			-wrap => 'word',
			-font => 'medium',
			-bg => 'white',
			-state => 'disabled');

$scroll->configure(-command => ['yview', $text]);
$scroll->pack(-side => 'right', -expand => 'no', -fill => 'y');
$text->pack(-side => 'left', -anchor => 'w',
	-expand => 'yes', -fill => 'both');

&do_search;

MainLoop;

sub do_search {

     $text->configure(-cursor=> 'watch');
     $mw->idletasks;

     my $content = LWP::UserAgent->new->
                            get($url, 'Accept-Charset'=>'UTF-8');
     my $enco = encoding_from_http_message($content);
     my $utf8 = decode($enco => $content->content());

my $output;
my $parser = HTML::TokeParser::Simple->new( \$utf8 );

while ( my $token = $parser->get_token ) {
        # This prints all text in an HTML doc (i.e., it strips the HTML)
    next if ! $token->is_text;
    $output .= $token->as_is;
}
    #remove obvious junk
    $output =~ s/\x{d}//g;

             ## Clear out text item
            $text->configure(-state => "normal");
             $text->delete('1.0', 'end');
             $text->insert('end', $output);                 
            # $text->insert('end', $utf8);       #for the raw page
            $text->configure(-cursor => 'top_left_arrow');
}
__END__





-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html


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

Date: Sun, 26 Nov 2006 11:46:18 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Is a file in use?
Message-Id: <slrnemis3q.koq.hjp-usenet2@yoyo.hjp.at>

On 2006-11-23 09:49, Stevie <steviehaston@hotmail.com> wrote:
> OK, Understood your points about portability but thats not an issue
> here. I'm running linux and my main concern is to ensure the code
> executes as fast as possible.

lsof is slow.

> The reason I'm checking for it being locked is to make sure that it is
> not being written to by another process.

You can't do that. Locking and writing are completely orthogonal in
Unix. You can write to a file without locking it. And lsof doesn't test
for locks anyway.

> Current code is:
>
> system("lsof $file");
> if ( $? == 0 ) {
>    print " success - not locked, exit status = $?\n";
> } else {
>    print " failure - locked, exit status = $?\n";
> }
>
> This always returns failure with a exit status of 256. Any ideas why?

You reversed the test. lsof returns 0 if it finds at least one open
file, and 1 if it finds none. (Also your messages are misleading: lsof
doesn't test if a file is *locked*, just if it is *open*)

	hp


-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


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

Date: Sun, 26 Nov 2006 15:23:24 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Is a file in use?
Message-Id: <fd8jm2t84uu5rq9s4f574ibja9hismpf1k@4ax.com>

On Sun, 26 Nov 2006 11:46:18 +0100, "Peter J. Holzer"
<hjp-usenet2@hjp.at> wrote:

>> OK, Understood your points about portability but thats not an issue
>> here. I'm running linux and my main concern is to ensure the code
>> executes as fast as possible.
>
>lsof is slow.

Indeed. Also because it basically has to check for all processess, if
some hold a file descriptor opened on the wanted file. It amounts to
say that the system keeps track of which process has opened which
file, and that kind of info is fast to recover, but not vice versa, in
which case it's possible to recover the corresponding one, but one has
to lookup for it, and that's slow. Speaking of which I wondered
whether there exist a filesystem that *does* keep track of the reverse
info and provides means to recover it fast by means of a suitable
call.


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: Sun, 26 Nov 2006 17:11:34 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Is a file in use?
Message-Id: <slrnemjf5m.r7v.hjp-usenet2@yoyo.hjp.at>

On 2006-11-26 14:23, Michele Dondi <bik.mido@tiscalinet.it> wrote:
> On Sun, 26 Nov 2006 11:46:18 +0100, "Peter J. Holzer"
><hjp-usenet2@hjp.at> wrote:
>
>>> OK, Understood your points about portability but thats not an issue
>>> here. I'm running linux and my main concern is to ensure the code
>>> executes as fast as possible.
>>
>>lsof is slow.
>
> Indeed. Also because it basically has to check for all processess, if
> some hold a file descriptor opened on the wanted file. It amounts to
> say that the system keeps track of which process has opened which
> file, and that kind of info is fast to recover, but not vice versa, in
> which case it's possible to recover the corresponding one, but one has
> to lookup for it, and that's slow. Speaking of which I wondered
> whether there exist a filesystem that *does* keep track of the reverse
> info and provides means to recover it fast by means of a suitable
> call.

I would expect the Linux (or any Unix) kernel to keep at least a process
(or file descriptor) count on each opened inode, because it needs to
know whether an inode is in use when it is unlinked.  I don't know of
any Unix which makes the information readily available to user programs,
though.

Thinking about it, FAM and friends might be able to do that.

	hp


-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


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

Date: Sun, 26 Nov 2006 12:07:24 +0000
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: my
Message-Id: <skco34-0e7.ln1@osiris.mauzo.dyndns.org>


Quoth "John W. Krahn" <krahnj@telus.net>:
> Awkish wrote:
> > Hello,
> > I'm a bit puzzled by the following behavior:
> > 
> > VARIANT 1:
> > ===========
> > perl -e '
> > my $var=0; 
> > sub fonc{
> >    $var++; 
> >    printf "sub: $var\n";
> > } 
> > $var=5;
> > my @arr=( 10,20,30 ); 
> > for $var (@arr){
> >    printf "main: $var\n";
> >    fonc();} 
> > '
<snip, produces 10 6 20 7 30 8>
> perldoc perlsyn
> 
> [ snip ]
> 
>        Foreach Loops
> 
>        The "foreach" loop iterates over a normal list value and sets the
>        variable VAR to be each element of the list in turn.  If the variable
>        is preceded with the keyword "my", then it is lexically scoped, and is
>        therefore visible only within the loop.  Otherwise, the variable is
>        implicitly local to the loop and regains its former value upon exiting
>        the loop.  If the variable was previously declared with "my", it uses
>        that variable instead of the global one, but it's still localized to
>        the loop.  This implicit localisation occurs only in a "foreach" loop.

This explanation doesn't seem quite right to me. AFAICS, there is only
one $var in the above, with a scope over both the sub and the for loop;
so if for simply local()ised that variable (I know you can't local()
lexicals; but the concept isn't stupid, and perhaps for can) I would
expect to get '10 11 12 13 14 15'. Instead, it seems as though if the
variable was previously declared a lexical, for creates a *new* lexical
over its own scope, exactly as though you had said C<for my $var () {}>.

Am I being stupid, or could the docs use a little revision?

Ben

-- 
                Outside of a dog, a book is a man's best friend.
                Inside of a dog, it's too dark to read.
benmorrow@tiscali.co.uk                                           Groucho Marx


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

Date: Sun, 26 Nov 2006 14:39:45 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: my
Message-Id: <slrnemj691.ng0.hjp-usenet2@yoyo.hjp.at>

On 2006-11-26 12:07, Ben Morrow <benmorrow@tiscali.co.uk> wrote:
>
> Quoth "John W. Krahn" <krahnj@telus.net>:
>> Awkish wrote:
>> > I'm a bit puzzled by the following behavior:
>> > 
>> > VARIANT 1:
>> > ===========
>> > perl -e '
>> > my $var=0; 
>> > sub fonc{
>> >    $var++; 
>> >    printf "sub: $var\n";
>> > } 
>> > $var=5;
>> > my @arr=( 10,20,30 ); 
>> > for $var (@arr){
>> >    printf "main: $var\n";
>> >    fonc();} 
>> > '
><snip, produces 10 6 20 7 30 8>
>> perldoc perlsyn
>> 
>> [ snip ]
>> 
>>        Foreach Loops
>> 
>>        The "foreach" loop iterates over a normal list value and sets the
>>        variable VAR to be each element of the list in turn.  If the variable
>>        is preceded with the keyword "my", then it is lexically scoped, and is
>>        therefore visible only within the loop.  Otherwise, the variable is
>>        implicitly local to the loop and regains its former value upon exiting
>>        the loop.  If the variable was previously declared with "my", it uses
>>        that variable instead of the global one, but it's still localized to
>>        the loop.  This implicit localisation occurs only in a "foreach" loop.
>
> This explanation doesn't seem quite right to me. AFAICS, there is only
> one $var in the above, with a scope over both the sub and the for loop;
> so if for simply local()ised that variable (I know you can't local()
> lexicals; but the concept isn't stupid, and perhaps for can) I would
> expect to get '10 11 12 13 14 15'.

Why? If anything I'd expect '10 11 20 21 30 31'. I.e., $var is set to
each value in @arr in turn and then incremented in fonc. But that would
imply that the loop can change which version of $var fonc() sees and I
don't think that's possible with lexical variables
(I guess I should have a look at how that stuff is implemented one day).

> Instead, it seems as though if the variable was previously declared a
> lexical, for creates a *new* lexical over its own scope, exactly as
> though you had said C<for my $var () {}>.

I think this is what is meant. I.e. "localized" is only used informally
here and means that the variable is visible only within the loop, not
that local() is called on it.


> Am I being stupid, or could the docs use a little revision?

The latter I think. It's ambiguous in the best case.

Even if it is internally implemented differently, I think the effect
would be better described as:

        therefore visible only within the loop.  Otherwise, the variable is
        implicitly local to the loop and regains its former value upon exiting
        the loop.  If the variable was previously declared with "my",
	the loop variable is also lexically scoped to the loop, as if
	it was preceded with the keyword "my".

	hp

-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


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

Date: Sun, 26 Nov 2006 10:56:16 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: my
Message-Id: <slrnemjhpg.ni4.tadmc@tadmc30.august.net>

Ben Morrow <benmorrow@tiscali.co.uk> wrote:
>
> Quoth "John W. Krahn" <krahnj@telus.net>:
>> Awkish wrote:
>> > Hello,
>> > I'm a bit puzzled by the following behavior:
>> > 
>> > VARIANT 1:
>> > ===========
>> > perl -e '
>> > my $var=0; 
>> > sub fonc{
>> >    $var++; 
>> >    printf "sub: $var\n";
>> > } 
>> > $var=5;
>> > my @arr=( 10,20,30 ); 
>> > for $var (@arr){
>> >    printf "main: $var\n";
>> >    fonc();} 
>> > '
><snip, produces 10 6 20 7 30 8>
>> perldoc perlsyn
>> 
>> [ snip ]
>> 
>>        Foreach Loops
>> 
>>        The "foreach" loop iterates over a normal list value and sets the
>>        variable VAR to be each element of the list in turn.  If the variable
>>        is preceded with the keyword "my", then it is lexically scoped, and is
>>        therefore visible only within the loop.  Otherwise, the variable is
>>        implicitly local to the loop and regains its former value upon exiting
>>        the loop.  If the variable was previously declared with "my", it uses
>>        that variable instead of the global one, but it's still localized to
>>        the loop.  This implicit localisation occurs only in a "foreach" loop.
>
> This explanation doesn't seem quite right to me. AFAICS, there is only
> one $var in the above, with a scope over both the sub and the for loop;
> so if for simply local()ised that variable (I know you can't local()
> lexicals; but the concept isn't stupid, and perhaps for can) I would
> expect to get '10 11 12 13 14 15'. Instead, it seems as though if the
> variable was previously declared a lexical, for creates a *new* lexical
> over its own scope, 


Adding some instrumentation seems to confirm a new lexical:

--------------------------------
#!/usr/bin/perl
use warnings;
use strict;

my $var=0; 
my $identity = \$var;
print "file id=$identity\n";

sub fonc{
   my $identity = \$var;
   print "fonc id=$identity\n";
   $var++; 
   printf "sub: $var\n";
} 
$var=5;
my @arr=( 10,20,30 ); 
for $var (@arr){
   my $identity = \$var;
   print "for  id=$identity\n";
   printf "main: $var\n";
   fonc();
} 
--------------------------------

output:

file id=SCALAR(0x8167900)
for  id=SCALAR(0x8166c28)
main: 10
fonc id=SCALAR(0x8167900)
sub: 6
for  id=SCALAR(0x8166d48)
main: 20
fonc id=SCALAR(0x8167900)
sub: 7
for  id=SCALAR(0x816787c)
main: 30
fonc id=SCALAR(0x8167900)
sub: 8


> exactly as though you had said C<for my $var () {}>.


Adding "my" to the for gives the same output. It even has the same addresses.


> Am I being stupid, or could the docs use a little revision?


No and yes, respectively.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sun, 26 Nov 2006 17:34:11 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Net::SSH::Perl -- can I capture the command prompt?
Message-Id: <slrnemjgg3.r7v.hjp-usenet2@yoyo.hjp.at>

On 2006-11-15 08:11, anno4000@radom.zrz.tu-berlin.de <anno4000@radom.zrz.tu-berlin.de> wrote:
> Keith <keithw99@gmail.com> wrote in comp.lang.perl.misc:
>> I've been using Net::SSH::Perl to log in to Cisco routers and perform
>> tasks, but there's one thing I can't seem to do.  Without opening an
>> actual interactive shell, I just want to capture (in a string) the
>> actual command prompt upon logging in.
[...]
>> The reason I need to do this is to tell the level of access; i.e. the
>> prompt "Router>" tells you that you're in EXEC mode, the prompt
>> "Router#" tells you that you're in privileged mode, and
>> "Router(config)#" tells you that you're in configuration mode.  This
>> isn't specific to Cisco either -- logging into another UNIX machine
>> obviously gives you a specific prompt that reveals the host, user, and
>> shell.

SSH on Unix can be used to invoke "interactive" and "non-interactive"
shells. Only interactive shells send a command prompt. Maybe IOS makes
the same distinction. So you need to figure out how to invoke an
interactive shell from Net::SSH::Perl.


> The connection between the prompt and properties of the process is
> tenuous at best.  It is shell-dependent and user configurable, so it's
> nothing to rely on.
>
> Find how the prompt is set to its various forms (study the startup
> script(s) for the shell) and use the methods that are used there.

On a CISCO router?

	hp


-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


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

Date: 26 Nov 2006 03:17:07 -0800
From: usenet@DavidFilmer.com
Subject: Re: Perl and Online Banking
Message-Id: <1164539827.744673.95030@f16g2000cwb.googlegroups.com>

banker123 wrote:
> How did you find this frame?  I took a look at the source and it was
> not immediatley recognizable.

Well, I use Firefox (of course) and I simply right-clicked in the
appropriate region and noticed the "This Frame>" option. Clicking on it
showed me the "Show Only This Frame" option, which I selected to view
the appropriate frame.  If you use IE, you probabliy are not adept
enought to do this task.

> Can you expand on hidden fields or direct me to some documentation?

If you don't understand basic HTML, you probably cannot accomplish your
task.  When viewing the frame, you "View Page Source" and look at the
underlying HTML.  A search for "name=" should show you the various
fields the page expects to set/receive.  You may need to trick your
website (ie, to believe you have Javascript or Flash enabled).

There is no Perl Magick here. You must understand and be able to grok
the language your website communicates in (HTML).  If you grok that, it
is fairly trivial to express it in terms that Mechanize can
communicate.

-- 
David Filmer (http://DavidFilmer.com)



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

Date: Sun, 26 Nov 2006 12:52:34 +0000
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: prevent further hash auto-vivification
Message-Id: <i9fo34-tii.ln1@osiris.mauzo.dyndns.org>


Quoth Uri Guttman <uri@stemsystems.com>:
> >>>>> "BM" == Ben Morrow <benmorrow@tiscali.co.uk> writes:
> 
> 
>   BM> As of 5.9 fields.pm is implemented in terms of locked hashes instead of
>   BM> phashes. This is what they were added to perl for: to keep the
>   BM> 'attribute checking' nature of phashes, which was deemed to be a benefit
>   BM> of using fields.pm.
> 
>   BM> IOO don't use locked hashes; but as of 5.10 they will (or can, anyway)
>   BM> use Anno's new 'fieldhashes', which cope correctly with
>   BM> threads/overloading/re-blessing.
> 
> i tend to not use much inheritance as i prefer delegation in
> general. objects owning objects makes more sense to me than objects
> being a variant of another object. with delegation you don't worry about
> sharing attributes and you should have no issues with those last issues
> you mentioned.

Threads and GC will still be an issue. When a variable is cloned to
create a new thread, its refaddr changes, so you need a CLONE method to
deal with that; and when a variable is destroyed its fields will not be,
so you need a DESTROY method to handle that. Fieldhashes handle both
those cases for you, cleanly.

Ben

-- 
I have two words that are going to make all your troubles go away.
"Miniature". "Golf".
                                                  [benmorrow@tiscali.co.uk]


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

Date: Sun, 26 Nov 2006 15:23:16 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: problems while compiling perl on solaris 10
Message-Id: <slrnemj8qk.ng0.hjp-usenet2@yoyo.hjp.at>

On 2006-11-16 10:24, Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr> wrote:
> ashish wrote:
>> I want to be able to compile perl as later I will need to be able to
>> compile additional modules. In particular, I want to be able to compile
>> the sybperl module which is for connecting to a sybase database.
> OK - you probably don't need to go down this route, though. I had 
> assumed that sybperl, oraperl etc were obsolete, although I stand open 
> to correction.
>
> New code should probably use DBI and its associated driver modules: 
> DBD::Sybase in your case. You don't need to recompile the whole of perl 
> in order to use this: you just compile the module (downloadable from 
> search.cpan.org) against your sybase client libraries.

Yes, but you need to compile the module with the same compiler as the
perl interpreter was compiled with. If you don't have that C compiler,
you have to recompile perl yourself. Some modules also need perl to be
compiled with weird settings to work (for example, some versions of
DBD::Oracle on HP-UX needed a perl interpreter without ithreads but
explicitely linked against libpthread).

	hp


-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


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

Date: 26 Nov 2006 09:30:52 -0800
From: zemalf@gmail.com
Subject: Running and Feeding Input to Interactive Program in Windows from Perl Script
Message-Id: <1164562252.344789.83360@j44g2000cwa.googlegroups.com>

I know how to start a program, and get it's output, this is not the
case. I need to start the program and feed input to it (optionally
reading the programs output at the same time).

So, I'm using a program that runs in windows cmd (so I must run the
script in windows), and all of it's functions can't be executed via
command line parameters.

So if I run it "manually" it goes something like this
c:\>tester -report
what do you want to check: TEST
what version you want to check: 2
what report: A

 ..and then the 'tester' outputs TEST, version 2, report A into screen
and into file..

I haven't been able to do this in windows. I've read that it would be
possible if this was unix, but in windows I can't pipe the program both
ways, so I can't read the programs output and input it at the same
time.
Actually it would be enough, if I could just input these to the
'tester' (I can get the file it outputs automatically with the -report
switch):
1: tester -report (start it)
2: TEST
3: 2
4: A

the program (1) is always the same, with the -report switch. 2,3 & 4
might vary

Can this be done in windows (and with Perl)? If it can be done, how it
can be done?
Expect maybe? But I couldn't get verification from documentation that
it works in Windows as well.



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

Date: Sun, 26 Nov 2006 17:37:18 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Running and Feeding Input to Interactive Program in Windows from Perl Script
Message-Id: <ihkah.18023$mM1.5137@trndny08>

zemalf@gmail.com wrote:
> I know how to start a program, and get it's output, this is not the
> case. I need to start the program and feed input to it (optionally
> reading the programs output at the same time).

You are probably looking for the Expect module.

jue 




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

Date: Sun, 26 Nov 2006 11:53:44 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: seek/tell in presence of multibyte characters
Message-Id: <slrnemisho.koq.hjp-usenet2@yoyo.hjp.at>

On 2006-11-24 21:34, Mumia W. (reading news) <paduille.4060.mumia.w@earthlink.net> wrote:
> On 11/24/2006 01:18 PM, Robert Dodier wrote:
>> I would like to call seek and tell on files which contain multibyte
>> characters (utf8).
>> perldoc -f seek says that seek only considers byte offsets, not
>> character offsets.
>> How can I implement a seek-like function which takes a character
>> offset?
>> (Or does such a thing already exist in some library?)
>> Likewise, I need a tell function which reports character offset instead
>> of byte offset.
[...]
>
> If I had control over the file format, I would use a 16-bit unicode 
> version. That would provide predictable character sizes.

The Unicode character set these days contains characters beyond U+FFFF.
You may not need them now but somebody will want to use them in the
future (Murphy isn't sleeping) - so "a 16-bit unicode version" means
UTF-16, not UCS-2, and you don't have a predictable character size
anymore: One character can be 2 or 4 bytes.

	hp


-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


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

Date: 26 Nov 2006 08:03:31 -0800
From: "Robert Dodier" <robert.dodier@gmail.com>
Subject: Re: seek/tell in presence of multibyte characters
Message-Id: <1164557011.794460.247740@14g2000cws.googlegroups.com>

Brian McCauley wrote:

> Robert Dodier wrote:
>
> > I would like to call seek and tell on files which contain multibyte
> > characters (utf8).
> > perldoc -f seek says that seek only considers byte offsets, not
> > character offsets.
> > How can I implement a seek-like function which takes a character
> > offset?
>
> Why? No, seriously, why?

To find a location in the file specified as the number of characters
from the beginning.

> What meaning does a character offset have?

The number of characters from the beginning of the file.
It is like counting variable-length records.

> If you just want to get back to a position you've visited before

You may wish to consider that I want what I asked for.

FWIW
Robert Dodier



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

Date: 26 Nov 2006 08:13:16 -0800
From: "Robert Dodier" <robert.dodier@gmail.com>
Subject: Re: seek/tell in presence of multibyte characters
Message-Id: <1164557596.059836.263170@45g2000cws.googlegroups.com>

Robert Dodier wrote:

> I would like to call seek and tell on files which contain multibyte
> characters (utf8).
> perldoc -f seek says that seek only considers byte offsets, not
> character offsets.
> How can I implement a seek-like function which takes a character
> offset?

I ended up emulating seek by calling read FH, $stuff, $N; where $N is
the number of characters to seek, after open FH, "<:utf8", $filename;
(and then ignoring $stuff). For tell, I call length on a string to get
the
character count.

It turns out that Perl's open & read functions are plenty fast
enough to make this work. I could wish for a more elegant solution
but for the moment I'm just happy it works.

Thanks to everyone who responded.

Robert Dodier



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

Date: Sun, 26 Nov 2006 11:40:22 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: speaking of forking -- parallel database fetches?
Message-Id: <slrnemirom.koq.hjp-usenet2@yoyo.hjp.at>

On 2006-11-24 19:23, DJ Stunks <DJStunks@gmail.com> wrote:
> I have two straightforward SELECT statements, but both take about two
> minutes to complete.  I'd like to run them in parallel, but I obviously
> need access to all the rows - what's the best way to do so?
>
> I was thinking something along these lines (pseudocode below) but I was
> hoping there would be some way to give the parent access to the
> statement handle itself so it could pull the rows once the queries were
> complete

Theoretically, that's possible. In practice, database client libaries
don't support that.

[...]
>   if ( $pid == 0) {   # I'm one of the children
>
>   	# connect to the db
>   	# prepare query
>   	# execute query
>   	# wait for results
>   	# foreach @row = $sth->fetchrow_array
>   	#    print join( $;, @row ), "\n"
>
>   	# exit; (exit or waitpid?  do I know the parent read everything?)
>   }
>   else {				# I'm the parent
>
>   	# while ( my $line = < $kids[0]{handle} >) {
>   	#    @row = split $;, $line;
>   	# do whatever with @row
>   	#
>   	# while ( my $line = < $kids[1]{handle} >) {
>   	# etc.
>   }

You are reading all the lines from kid 0 before the first line from kid 1
here. This means that kid 1 will block as soon as it has written enough
records to fill the pipe (typically a few kB). Not a problem if your
queried only return a few rows, but if they are long-running because
they return lots of rows, they won't really run in parallel.

You may want to look at select (or IO::Select), but be warned that select
and <> don't mix well - you need to use sysread instead.

	hp

-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


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

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 V10 Issue 10009
****************************************


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