[30628] in Perl-Users-Digest
Perl-Users Digest, Issue: 1873 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 24 16:09:56 2008
Date: Wed, 24 Sep 2008 13:09:23 -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 Wed, 24 Sep 2008 Volume: 11 Number: 1873
Today's topics:
Re: expect.pm - stdout buffering issue <glennj@ncf.ca>
Re: expect.pm - stdout buffering issue <yandry77@gmail.com>
Re: expect.pm - stdout buffering issue <glennj@ncf.ca>
Re: expect.pm - stdout buffering issue <yandry77@gmail.com>
Re: IPC:Shareable <tzz@lifelogs.com>
Opening files on the web for reading <graham.stow@gmail.com>
Re: Opening files on the web for reading <peter@makholm.net>
Re: Opening files on the web for reading <jurgenex@hotmail.com>
Re: Opening files on the web for reading xhoster@gmail.com
Re: Opening files on the web for reading <jurgenex@hotmail.com>
Re: Opening files on the web for reading <ben@morrow.me.uk>
Re: question about "package" and variable scope... <news@chaos-net.de>
Re: question about "package" and variable scope... <spamtrap@dot-app.org>
Re: question about "package" and variable scope... <john@castleamber.com>
Re: question about "package" and variable scope... <ben@morrow.me.uk>
Re: question about "package" and variable scope... <news@chaos-net.de>
Re: question about "package" and variable scope... <news@chaos-net.de>
Regular Expressions & replacements <jhgaylor@gmail.com>
Re: Regular Expressions & replacements <someone@example.com>
websites and cookies? <tch@nospam.wpkg.org>
Re: websites and cookies? <spamtrap@dot-app.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 24 Sep 2008 11:50:25 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: expect.pm - stdout buffering issue
Message-Id: <slrngdkac1.kpj.glennj@smeagol.ncf.ca>
The paradigm behind Expect is this: send something and then expect to
see the result. What you are thinking is that the act of sending
somehow immediately produces outout. send and expect commands really
occur in pairs.
If I send you an email, I would expect to wait for your reply.
NOT: I send you an email and magically your reply instantly appears.
You should send the ls command, then expect the prompt. In the output
that contains the prompt you will find the result of ls.
At 2008-09-24 04:25AM, "Andry" wrote:
> > Andry wrote:
> > > Hi all,
> > > I have the following script:
> > > ******************************************************************
> > > #!/usr/bin/perl -w
> > > use Expect;
> > >
> > > $timeout = 5;
> > > $|=1;
> > >
> > > $exp = new Expect();
> > > $exp->raw_pty(1);
> > >
> > > $exp->log_file("output.log", "w");
> > >
> > > $exp->spawn("ssh -l username 10.17.39.29");
> > > $exp->expect($timeout, [ "[Pp]assword" => sub { $_[0]->send("password
> > > \n"); } ]);
> > > $exp->expect($timeout, [ "prompt-string" => sub { $_[0]->send("ls -l
> > > \n"); } ]);
> > > sleep 2;
> > > $exp->expect($timeout, [ "prompt-string" => sub { $_[0]->send("ls
> > > \n"); } ]);
> > > sleep 5;
I would write the above as:
my @match_prompt = ('-re', 'prompt_pattern$');
$exp->spawn("ssh -l username 10.17.39.29");
$exp->expect($timeout, @match_prompt);
$exp->send("password\r");
$exp->expect($timeout, @match_prompt) or
die "couldn't see prompt after 'send password'\n";
$exp->send("ls -l\r");
$exp->expect($timeout, @match_prompt) or
die "couldn't see prompt after 'send ls -l'\n";
# parse $match_patterns for 'ls -l' output
$exp->send("ls\r");
$exp->expect($timeout, @match_prompt) or
die "couldn't see prompt after 'send ls'\n";
# parse $match_patterns for 'ls' output
$exp->send("exit\r");
$exp->expect($timeout, 'eof');
> > > $exp->log_file(undef);
> >
> > > $exp->expect($timeout, [ "prompt-string" => sub { $_[0]->send("exit
> > > \n"); } ]);
--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
------------------------------
Date: Wed, 24 Sep 2008 06:18:59 -0700 (PDT)
From: Andry <yandry77@gmail.com>
Subject: Re: expect.pm - stdout buffering issue
Message-Id: <3589f3d6-c5ab-4b6e-b2ee-cd27c3737636@z72g2000hsb.googlegroups.com>
On Sep 24, 1:50=A0pm, Glenn Jackman <gle...@ncf.ca> wrote:
> The paradigm behind Expect is this: =A0send something and then expect to
> see the result. =A0What you are thinking is that the act of sending
> somehow immediately produces outout. =A0send and expect commands really
> occur in pairs.
>
> If I send you an email, I would expect to wait for your reply.
> NOT: I send you an email and magically your reply instantly appears.
>
> You should send the ls command, then expect the prompt. =A0In the output
> that contains the prompt you will find the result of ls.
>
> At 2008-09-24 04:25AM, "Andry" wrote:
>
>
>
> > > Andry wrote:
> > > > Hi all,
> > > > I have the following script:
> > > > ******************************************************************
> > > > #!/usr/bin/perl -w
> > > > use Expect;
>
> > > > $timeout =3D 5;
> > > > $|=3D1;
>
> > > > $exp =3D new Expect();
> > > > $exp->raw_pty(1);
>
> > > > $exp->log_file("output.log", "w");
>
> > > > $exp->spawn("ssh -l username 10.17.39.29");
> > > > $exp->expect($timeout, [ "[Pp]assword" =3D> sub { $_[0]->send("pass=
word
> > > > \n"); } ]);
> > > > $exp->expect($timeout, [ "prompt-string" =3D> sub { $_[0]->send("ls=
-l
> > > > \n"); } ]);
> > > > sleep 2;
> > > > $exp->expect($timeout, [ "prompt-string" =3D> sub { $_[0]->send("ls
> > > > \n"); } ]);
> > > > sleep 5;
>
> I would write the above as:
>
> =A0 =A0 my @match_prompt =3D ('-re', 'prompt_pattern$');
>
> =A0 =A0 $exp->spawn("ssh -l username 10.17.39.29");
> =A0 =A0 $exp->expect($timeout, @match_prompt);
>
> =A0 =A0 $exp->send("password\r");
> =A0 =A0 $exp->expect($timeout, @match_prompt) or
> =A0 =A0 =A0 =A0 die "couldn't see prompt after 'send password'\n";
>
> =A0 =A0 $exp->send("ls -l\r");
> =A0 =A0 $exp->expect($timeout, @match_prompt) or
> =A0 =A0 =A0 =A0 die "couldn't see prompt after 'send ls -l'\n";
> =A0 =A0 # parse $match_patterns for 'ls -l' output
>
> =A0 =A0 $exp->send("ls\r");
> =A0 =A0 $exp->expect($timeout, @match_prompt) or
> =A0 =A0 =A0 =A0 die "couldn't see prompt after 'send ls'\n";
> =A0 =A0 # parse $match_patterns for 'ls' output
>
> =A0 =A0 $exp->send("exit\r");
> =A0 =A0 $exp->expect($timeout, 'eof');
>
> > > > $exp->log_file(undef);
>
> > > > $exp->expect($timeout, [ "prompt-string" =3D> sub { $_[0]->send("ex=
it
> > > > \n"); } ]);
>
> --
> Glenn Jackman
> =A0 =A0 Write a wise saying and your name will live forever. -- Anonymous
Hi Glenn,
Sorry but you did not catch the point.
Doing this:
> $exp->expect($timeout, [ "[Pp]assword" =3D> sub { $_[0]->send("password\n=
"); } ]);
It's exactly the same of doing this:
> $exp->expect($timeout, '-re', "[Pp]assword");
> $exp->send("password\r");
There is no difference (even '-re' is taken by default in the first
method) execpt that the first method compresses the syntax.
You can try and check it out yourself.
Here the problem is different. STDOUT is not being managed by
Expect.pm as expected.
Now, I found that if I put $exp->log_file(undef) at the very end of
the script (after $exp->soft_close) I can catch the rest of the script
that was being missed out previously. Though the desired result would
be to catch "ls -l" and "ls" but not the rest (exit ssh...). If I put
$exp->log_file(undef) after the last 'send ls' but before $exp-
>soft_close() then the output of the last "ls" is missed out.
So, I still see inconsistent behavior with STDOUT for 'sleep' commands
as well as log_file operations.
Any idea?
Thanks,
Andrea
------------------------------
Date: 24 Sep 2008 13:50:34 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: expect.pm - stdout buffering issue
Message-Id: <slrngdkhdb.kpj.glennj@smeagol.ncf.ca>
At 2008-09-24 09:18AM, "Andry" wrote:
> On Sep 24, 1:50 pm, Glenn Jackman <gle...@ncf.ca> wrote:
>
> Doing this:
> > $exp->expect($timeout, [ "[Pp]assword" => sub { $_[0]->send("password\n"); } ]);
> It's exactly the same of doing this:
> > $exp->expect($timeout, '-re', "[Pp]assword");
> > $exp->send("password\r");
> There is no difference (even '-re' is taken by default in the first
> method) execpt that the first method compresses the syntax.
> You can try and check it out yourself.
I'll take your word, I'm not an Expect.pm user. I was trying to
belabour the point that the result of a send shows up in the subsequent
expect.
> Here the problem is different. STDOUT is not being managed by
> Expect.pm as expected.
>
> Now, I found that if I put $exp->log_file(undef) at the very end of
> the script (after $exp->soft_close) I can catch the rest of the script
> that was being missed out previously. Though the desired result would
> be to catch "ls -l" and "ls" but not the rest (exit ssh...). If I put
> $exp->log_file(undef) after the last 'send ls' but before $exp-
> >soft_close() then the output of the last "ls" is missed out.
Your old code was:
$exp->expect($timeout, ["prompt-string" => sub { $_[0]->send("ls\n"); }]);
sleep 5;
$exp->log_file(undef);
$exp->expect($timeout, ["prompt-string" => sub { $_[0]->send("exit\n"); }]);
In this case, the "ls" output won't appear until you match the prompt
(in the second expect command). By that time, you've already turned off
logging. Another analogy: you phone me, hang up before I answer, and
wonder why you didn't hear me say "hi".
Turn off logging after you send "exit" and before you expect "eof".
> So, I still see inconsistent behavior with STDOUT for 'sleep' commands
> as well as log_file operations.
I still don't understand why you need to sleep. The expect command
should block until it either finds a match or times out. I think your
expectations are wrong concerning when you should see the output from
sent commands.
--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
------------------------------
Date: Wed, 24 Sep 2008 08:51:00 -0700 (PDT)
From: Andry <yandry77@gmail.com>
Subject: Re: expect.pm - stdout buffering issue
Message-Id: <b675b3e9-928c-4434-aeca-3a3601737d80@z66g2000hsc.googlegroups.com>
On Sep 24, 3:50=A0pm, Glenn Jackman <gle...@ncf.ca> wrote:
> At 2008-09-24 09:18AM, "Andry" wrote:
>
> > =A0On Sep 24, 1:50=A0pm, Glenn Jackman <gle...@ncf.ca> wrote:
>
> > =A0Doing this:
> > > $exp->expect($timeout, [ "[Pp]assword" =3D> sub { $_[0]->send("passwo=
rd\n"); } ]);
> > =A0It's exactly the same of doing this:
> > > =A0 =A0 $exp->expect($timeout, '-re', "[Pp]assword");
> > > =A0 =A0 $exp->send("password\r");
> > =A0There is no difference (even '-re' is taken by default in the first
> > =A0method) execpt that the first method compresses the syntax.
> > =A0You can try and check it out yourself.
>
> I'll take your word, I'm not an Expect.pm user. =A0I was trying to
> belabour the point that the result of a send shows up in the subsequent
> expect.
>
> > =A0Here the problem is different. STDOUT is not being managed by
> > =A0Expect.pm as expected.
>
> > =A0Now, I found that if I put $exp->log_file(undef) at the very end of
> > =A0the script (after $exp->soft_close) I can catch the rest of the scri=
pt
> > =A0that was being missed out previously. Though the desired result woul=
d
> > =A0be to catch "ls -l" and "ls" but not the rest (exit ssh...). If I pu=
t
> > =A0$exp->log_file(undef) after the last 'send ls' but before $exp-
> > >soft_close() then the output of the last "ls" is missed out.
>
> Your old code was:
>
> =A0 =A0 $exp->expect($timeout, ["prompt-string" =3D> sub { $_[0]->send("l=
s\n"); }]);
> =A0 =A0 sleep 5;
> =A0 =A0 $exp->log_file(undef);
> =A0 =A0 $exp->expect($timeout, ["prompt-string" =3D> sub { $_[0]->send("e=
xit\n"); }]);
>
> In this case, the "ls" output won't appear until you match the prompt
> (in the second expect command). =A0By that time, you've already turned of=
f
> logging. =A0Another analogy: =A0you phone me, hang up before I answer, an=
d
> wonder why you didn't hear me say "hi".
>
> Turn off logging after you send "exit" and before you expect "eof".
>
> > =A0So, I still see inconsistent behavior with STDOUT for 'sleep' comman=
ds
> > =A0as well as log_file operations.
>
> I still don't understand why you need to sleep. =A0The expect command
> should block until it either finds a match or times out. =A0I think your
> expectations are wrong concerning when you should see the output from
> sent commands.
>
> --
> Glenn Jackman
> =A0 =A0 Write a wise saying and your name will live forever. -- Anonymous
You said:
GJ> Turn off logging after you send "exit" and before you expect
"eof".
I already tried that and log_file still doesn't capture the last
"ls" (it does it only if I put '$exp->log_file(undef)' after '$exp-
>soft_close()').
------------------------------
Date: Wed, 24 Sep 2008 13:51:22 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: IPC:Shareable
Message-Id: <86bpydbcnp.fsf@lifelogs.com>
On Tue, 23 Sep 2008 07:42:26 -0700 (PDT) Snorik <clauskick@hotmail.com> wrote:
S> On Sep 23, 3:27 pm, Ted Zlatanov <t...@lifelogs.com> wrote:
>> This is not showing all your code;
>> your initialization should have an ID for the shared memory segment
>> you're using. If you use the same ID, you will reuse the same space, so
>> you don't have to destroy it if you'll be reusing it regularly.
S> I just noticed that reusing it means that for a second run with other
S> parameters, I also receive part of the result from the first one. So,
S> I better not keep it :)
S> For initialization, I just use the following:
S> my $ipc = tie %shared, 'Tie::ShareLite', -key=>1971, -mode=>0600, -
S> create=>'yes', -destroy =>'no' or die("Could not tie to shared memory:
S> $!")
Do this in the parent (the one which forks all the others) with
-destroy => 'yes'
If you want to keep running children after the parent script is gone,
you'll have to have a cleanup function or script, which is called before
the next run happens. It's exactly like leaving files in /tmp after
you're done processing them.
Ted
------------------------------
Date: Wed, 24 Sep 2008 14:14:07 +0100
From: "Graham Stow" <graham.stow@gmail.com>
Subject: Opening files on the web for reading
Message-Id: <gbdech$2ics$1@energise.enta.net>
Can anyone give me some Perl code to open an html file on the web (i.e. an
html file stored on somebody elses web server and not mine), for reading. Or
is it more complicated than that?
------------------------------
Date: Wed, 24 Sep 2008 15:25:54 +0200
From: Peter Makholm <peter@makholm.net>
Subject: Re: Opening files on the web for reading
Message-Id: <87skrp3cbh.fsf@hacking.dk>
"Graham Stow" <graham.stow@gmail.com> writes:
> Can anyone give me some Perl code to open an html file on the web (i.e. an
> html file stored on somebody elses web server and not mine), for reading. Or
> is it more complicated than that?
You can use the LWP::Simple module. The example in the documentation
should tell you how to do it.
//Makholm
------------------------------
Date: Wed, 24 Sep 2008 06:39:10 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Opening files on the web for reading
Message-Id: <mjgkd4150o6em1hh1rh26acjgmmknu3pkp@4ax.com>
"Graham Stow" <graham.stow@gmail.com> wrote:
>Can anyone give me some Perl code to open an html file on the web (i.e. an
>html file stored on somebody elses web server and not mine), for reading. Or
>is it more complicated than that?
Is there anything wrong with the answer in "perldoc -q HTML":
How do I fetch an HTML file?
jue
------------------------------
Date: 24 Sep 2008 15:47:32 GMT
From: xhoster@gmail.com
Subject: Re: Opening files on the web for reading
Message-Id: <20080924114734.357$S0@newsreader.com>
Jürgen Exner <jurgenex@hotmail.com> wrote:
> "Graham Stow" <graham.stow@gmail.com> wrote:
> >Can anyone give me some Perl code to open an html file on the web (i.e.
> >an html file stored on somebody elses web server and not mine), for
> >reading. Or is it more complicated than that?
>
> Is there anything wrong with the answer in "perldoc -q HTML":
>
> How do I fetch an HTML file?
Other than it not answering the question? At least on my Perl version,
none of the answers there return a file handle opened for reading. Now
maybe he is fine with downloading the entire file (either to disk or to
memory) and then reading from that, but I'd be inclined to give the benefit
of the doubt that he meant what he asked.
LWP::UserAgent using a callback with for example :content_cb would "stream"
the data back, but not via a file handle. One could probably come up with
an adaptor that ties a file handle front end to the callback backend.
There might be a more direct way, but I don't know what it is.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Wed, 24 Sep 2008 08:57:31 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Opening files on the web for reading
Message-Id: <gjokd49likvee9msvogj9pj1pdg8te01s5@4ax.com>
xhoster@gmail.com wrote:
>Jürgen Exner <jurgenex@hotmail.com> wrote:
>> "Graham Stow" <graham.stow@gmail.com> wrote:
>> >Can anyone give me some Perl code to open an html file on the web (i.e.
>> >an html file stored on somebody elses web server and not mine), for
>> >reading. Or is it more complicated than that?
>>
>> Is there anything wrong with the answer in "perldoc -q HTML":
>>
>> How do I fetch an HTML file?
>
>Other than it not answering the question? At least on my Perl version,
>none of the answers there return a file handle opened for reading. Now
>maybe he is fine with downloading the entire file (either to disk or to
>memory) and then reading from that, but I'd be inclined to give the benefit
>of the doubt that he meant what he asked.
Fair enough. I interpreted "to open an html file on the web [...] for
reading" as he just wants to get he content of that file (which as we
all know may not be a file in the first place), not to actually have a
read file handle to a URL.
At the very least his terminology is sloppy and your interpretation may
very well be closer to his intentions.
jue
------------------------------
Date: Wed, 24 Sep 2008 18:25:48 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Opening files on the web for reading
Message-Id: <sp9qq5-vc11.ln1@osiris.mauzo.dyndns.org>
Quoth xhoster@gmail.com:
> Jürgen Exner <jurgenex@hotmail.com> wrote:
> > "Graham Stow" <graham.stow@gmail.com> wrote:
> > >Can anyone give me some Perl code to open an html file on the web (i.e.
> > >an html file stored on somebody elses web server and not mine), for
> > >reading. Or is it more complicated than that?
> >
> > Is there anything wrong with the answer in "perldoc -q HTML":
> >
> > How do I fetch an HTML file?
>
> Other than it not answering the question? At least on my Perl version,
> none of the answers there return a file handle opened for reading. Now
> maybe he is fine with downloading the entire file (either to disk or to
> memory) and then reading from that, but I'd be inclined to give the benefit
> of the doubt that he meant what he asked.
>
> LWP::UserAgent using a callback with for example :content_cb would "stream"
> the data back, but not via a file handle. One could probably come up with
> an adaptor that ties a file handle front end to the callback backend.
>
> There might be a more direct way, but I don't know what it is.
IO::All::LWP
Ben
--
The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching.
Assyrian stone tablet, c.2800 BC ben@morrow.me.uk
------------------------------
Date: Wed, 24 Sep 2008 20:46:01 +0200
From: Martin =?UTF-8?Q?Ki=C3=9Fner?= <news@chaos-net.de>
Subject: Re: question about "package" and variable scope...
Message-Id: <slrngdl2nd.49m.news@maki.homeunix.net>
Sherm Pendley wrote :
> Raymundo <gypark@gmail.com> writes:
>
>> I can't understand this.. Any help would be apprecieated.
>
> That's just "our" doing its job as designed. Your code is basically
> the same as the example given in "perldoc -f our":
>
> An "our" declaration declares a global variable that will be
> visible across its entire lexical scope, even across package
> boundaries. The package in which the variable is entered is
> determined at the point of the declaration, not at the point of
> use. This means the following behavior holds:
>
> package Foo;
> our $bar; # declares $Foo::bar for rest of lexical scope
> $bar = 20;
>
> package Bar;
> print $bar; # prints 20, as it refers to $Foo::bar
>
This does not work("print $bar" will not print anything in this case),
if Bar is in a separate file Bar.pm and included with 'use Bar;
Why?
How can I use variables across Packages wich are in separate files?
Thanks in advance
regards
Martin
--
perl -e '$S=[[73,116,114,115,31,96],[108,109,114,102,99,112],
[29,77,98,111,105,29],[100,93,95,103,97,110]];
for(0..3){for$s(0..5){print(chr($S->[$_]->[$s]+$_+1))}}'
------------------------------
Date: Wed, 24 Sep 2008 15:05:14 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: question about "package" and variable scope...
Message-Id: <m1tzc5icut.fsf@dot-app.org>
Martin Kißner <news@chaos-net.de> writes:
> Sherm Pendley wrote :
>> Raymundo <gypark@gmail.com> writes:
>>
>>> I can't understand this.. Any help would be apprecieated.
>>
>> That's just "our" doing its job as designed. Your code is basically
>> the same as the example given in "perldoc -f our":
>>
>> An "our" declaration declares a global variable that will be
>> visible across its entire lexical scope, even across package
>> boundaries. The package in which the variable is entered is
>> determined at the point of the declaration, not at the point of
>> use. This means the following behavior holds:
>>
>> package Foo;
>> our $bar; # declares $Foo::bar for rest of lexical scope
>> $bar = 20;
>>
>> package Bar;
>> print $bar; # prints 20, as it refers to $Foo::bar
>>
>
> This does not work("print $bar" will not print anything in this case),
> if Bar is in a separate file Bar.pm and included with 'use Bar;
>
> Why?
Our declares variables as being global within a lexical context; a
different file is in a different lexical context.
> How can I use variables across Packages wich are in separate files?
Use the full package name - i.e. "print $Foo::bar;"
Or, have a look at 'perldoc Exporter' if you'd like to make the
"short" form available to code that uses your module.
sherm--
--
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: 24 Sep 2008 19:14:22 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: question about "package" and variable scope...
Message-Id: <Xns9B2390DA4AEB6castleamber@130.133.1.4>
Sherm Pendley <spamtrap@dot-app.org> wrote:
> Or, have a look at 'perldoc Exporter' if you'd like to make the
> "short" form available to code that uses your module.
http://johnbokma.com/mexit/2006/07/05/exporting-scalar-variable-perl.html
--
John http://johnbokma.com/ - Hacking & Hiking in Mexico
Perl help in exchange for a gift:
http://johnbokma.com/perl/help-in-exchange-for-a-gift.html
------------------------------
Date: Wed, 24 Sep 2008 20:11:16 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: question about "package" and variable scope...
Message-Id: <kvfqq5-lk41.ln1@osiris.mauzo.dyndns.org>
Quoth Martin =?UTF-8?Q?Ki=C3=9Fner?= <news@chaos-net.de>:
> Sherm Pendley wrote :
> > Raymundo <gypark@gmail.com> writes:
> >
> >> I can't understand this.. Any help would be apprecieated.
> >
> > That's just "our" doing its job as designed. Your code is basically
> > the same as the example given in "perldoc -f our":
> >
> > An "our" declaration declares a global variable that will be
> > visible across its entire lexical scope, even across package
> > boundaries. The package in which the variable is entered is
> > determined at the point of the declaration, not at the point of
> > use. This means the following behavior holds:
> >
> > package Foo;
> > our $bar; # declares $Foo::bar for rest of lexical scope
> > $bar = 20;
> >
> > package Bar;
> > print $bar; # prints 20, as it refers to $Foo::bar
> >
> This does not work("print $bar" will not print anything in this case),
> if Bar is in a separate file Bar.pm and included with 'use Bar;
No. Seperate files have separate lexical scopes: 'my' variables are
never visible across files, and 'our' variables must be referred to by
their full package name.
> Why?
> How can I use variables across Packages wich are in separate files?
The first question is: are you sure you need to? It's often a bad idea
to do this; it may be better to provide a function or OO interface to
the variable.
That said, you have three options:
1. Refer to the variable by its fully-qualified name, $Foo::bar.
2. Export the variable into the 'Bar' namespace with Exporter,
something like this:
package Foo;
use base qw/Exporter/;
our @EXPORT_OK = qw/$bar/;
1;
package Bar;
use Foo qw/$bar/;
1;
3. Make a new 'our' variable in the second file that refers to
$Foo::bar:
package Bar;
#...
package Foo;
our $bar;
package Bar;
#...
1;
Ben
--
The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching.
Assyrian stone tablet, c.2800 BC ben@morrow.me.uk
------------------------------
Date: Wed, 24 Sep 2008 21:52:17 +0200
From: Martin =?UTF-8?Q?Ki=C3=9Fner?= <news@chaos-net.de>
Subject: Re: question about "package" and variable scope...
Message-Id: <slrngdl6jk.49m.news@maki.homeunix.net>
Sherm Pendley wrote :
> Martin KiÃner <news@chaos-net.de> writes:
>
>> Sherm Pendley wrote :
>> if Bar is in a separate file Bar.pm and included with 'use Bar;
>>
>> Why?
>
> Our declares variables as being global within a lexical context; a
> different file is in a different lexical context.
Thank you. I wasn't aware of this.
>
>> How can I use variables across Packages wich are in separate files?
>
> Use the full package name - i.e. "print $Foo::bar;"
>
> Or, have a look at 'perldoc Exporter' if you'd like to make the
> "short" form available to code that uses your module.
'perldoc Exporter' explains how to use Exporter in modules (I didn't
read it thoroughly yet).
Is it also possible to use it in the main script to make variables
declared in the main script accessible inside the module?
I know I can use '$main::variablename' but I am just interested if I
could could also use Exporter for this.
regards
Martin
--
perl -e '$S=[[73,116,114,115,31,96],[108,109,114,102,99,112],
[29,77,98,111,105,29],[100,93,95,103,97,110]];
for(0..3){for$s(0..5){print(chr($S->[$_]->[$s]+$_+1))}}'
------------------------------
Date: Wed, 24 Sep 2008 21:54:49 +0200
From: Martin =?UTF-8?Q?Ki=C3=9Fner?= <news@chaos-net.de>
Subject: Re: question about "package" and variable scope...
Message-Id: <slrngdl6ob.49m.news@maki.homeunix.net>
Tad J McClellan wrote :
> Raymundo <gypark@gmail.com> wrote:
>
>> Ooops.. I couldn't even imagine that "our" and "use vars" have
>> different scope rule...
>
>
> Simply read their documentation...
>
> perldoc -f our
>
> ... within the lexical scope of the C<our> declaration ...
I wasn't aware that the lexical scope is restricted to the file.
Thanks to sherm I am now.
regards
Martin
--
perl -e '$S=[[73,116,114,115,31,96],[108,109,114,102,99,112],
[29,77,98,111,105,29],[100,93,95,103,97,110]];
for(0..3){for$s(0..5){print(chr($S->[$_]->[$s]+$_+1))}}'
------------------------------
Date: Wed, 24 Sep 2008 09:42:37 -0700 (PDT)
From: jhgaylor <jhgaylor@gmail.com>
Subject: Regular Expressions & replacements
Message-Id: <a00061ec-7bbb-4c6b-824c-23dba1158e49@73g2000hsx.googlegroups.com>
So, I am working on a program to take a list of First and Last names
exported from Novell Groupwise and making the list become Last, First,
firstfourlettersofLastName, password ||
The script I am using is this
#!"\xampplite\perl\bin\perl.exe"
use CGI qw/:standard/;
use overload;
$| = 1;
$q = new CGI;
print $q->header();
local $/=undef;
open FILE, "users.list" or die "Couldn't open file: $!";
binmode FILE;
$string = <FILE>;
close FILE;
$_ = $string;
chomp($_);
#Removes some of the formatting
s/Cof....Members//g;
s/To:\s//g;
s/Bc:.*\s//g;
#Checks if the expression will replace anything
if(m/ {1}\w.+\w\b.\w.+\w {1}/g){print "Hello";}
#Finds all names and replaces them with ___
s/ {1}\w.+\w\b.\w.+\w {1}/___/g;
open (OUT,">>usersFinal.list") || die;
print OUT $_;
close OUT;
The line I am having problems with is
s/ {1}\w.+\w\b.\w.+\w {1}/___/g;
The line is supposed to find all the names and remove them. It does
that, but replaces all the names with one instance of ___ instead of
___ for each name on the list. I can not break the names up by
looking for \n or \r. I am not sure why, but I think that they got
stripped
Eventually I want to add to the end of the name some other
information, but for now I just need to find the expression that finds
the names.
Below is an example of the starting information.
Cof2001Members
To: LastName1, FirstName1
To: LastName2, FirstName2
To: LastName3, FirstName3
To: LastName4, FirstName4
Bc: Zzip
Here is the way I want to eventually make the information look
Cof2001Members
Smith, Bob, smit001,
Jones, John, jone001,
Green, Jane, gree001,
Henry, Chris, henr001,
Either the expression to match the names and/or the code to add to the
end of names the needed information would be wonderful. Thanks
everyone.
------------------------------
Date: Wed, 24 Sep 2008 10:28:19 -0700
From: "John W. Krahn" <someone@example.com>
Subject: Re: Regular Expressions & replacements
Message-Id: <PMuCk.15586$Il.14040@newsfe09.iad>
jhgaylor wrote:
> So, I am working on a program to take a list of First and Last names
> exported from Novell Groupwise and making the list become Last, First,
> firstfourlettersofLastName, password ||
>
> The script I am using is this
>
> #!"\xampplite\perl\bin\perl.exe"
You should also have these two pragmas at the beginning of your program:
use warnings;
use strict;
> use CGI qw/:standard/;
> use overload;
>
> $| = 1;
> $q = new CGI;
> print $q->header();
>
> local $/=undef;
> open FILE, "users.list" or die "Couldn't open file: $!";
> binmode FILE;
> $string = <FILE>;
> close FILE;
>
> $_ = $string;
> chomp($_);
> #Removes some of the formatting
> s/Cof....Members//g;
> s/To:\s//g;
> s/Bc:.*\s//g;
> #Checks if the expression will replace anything
> if(m/ {1}\w.+\w\b.\w.+\w {1}/g){print "Hello";}
Using the /g option in boolean context makes no sense.
> #Finds all names and replaces them with ___
> s/ {1}\w.+\w\b.\w.+\w {1}/___/g;
>
> open (OUT,">>usersFinal.list") || die;
> print OUT $_;
> close OUT;
>
> The line I am having problems with is
> s/ {1}\w.+\w\b.\w.+\w {1}/___/g;
> The line is supposed to find all the names and remove them. It does
> that, but replaces all the names with one instance of ___ instead of
> ___ for each name on the list. I can not break the names up by
> looking for \n or \r. I am not sure why, but I think that they got
> stripped
>
> Eventually I want to add to the end of the name some other
> information, but for now I just need to find the expression that finds
> the names.
>
> Below is an example of the starting information.
>
> Cof2001Members
> To: LastName1, FirstName1
> To: LastName2, FirstName2
> To: LastName3, FirstName3
> To: LastName4, FirstName4
> Bc: Zzip
>
> Here is the way I want to eventually make the information look
>
> Cof2001Members
> Smith, Bob, smit001,
> Jones, John, jone001,
> Green, Jane, gree001,
> Henry, Chris, henr001,
Perhaps something like this (UNTESTED):
#!"\xampplite\perl\bin\perl.exe"
use warnings;
use strict;
open FILE, '<', 'users.list' or die "Couldn't open 'users.list': $!";
open OUT, '>>', 'usersFinal.list' or die "Couldn't open
'usersFinal.list': $!";
while ( <FILE> ) {
if ( /Cof.{4}Members/ ) {
print OUT;
}
elsif ( s/^To:\s+// ) {
my ( $last, $first ) = split /\s*,\s*/;
print OUT join ', ', $last, $first, lc substr( $last, 0, 4 ) .
'001', "\n";
}
}
__END__
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
------------------------------
Date: Wed, 24 Sep 2008 16:48:50 +0200
From: Tomasz Chmielewski <tch@nospam.wpkg.org>
Subject: websites and cookies?
Message-Id: <gbdk0j$jls$1@online.de>
I have a webmail which is protected by a "user/password" form (one which
you can find in any webmail, i.e. squirrelmail, yahoo/google mail etc.).
The webmail is the only way to fetch mail; there is no POP3/IMAP there.
Therefore, I'd like to write a Perl script which will "log in" to that
page automatically, parse certain pages (inbox, new mail, save it as
files etc.).
As far as I understand, I need to "emulate" a webbrowser a bit:
1) log in to a website (fill proper form fields, send it to the web server)
2) get the cookie, browse other pages using that cookie
What do I need to implement it in a Perl script?
I'm not looking for a ready solution, I just need some terms to look up
(CGI::Cookie perhaps for handling cookies; but how do I fill a form to
obtain the cookie? links browser?).
Any links to Perl examples would be great too, of course.
--
Tomasz Chmielewski
http://wpkg.org
------------------------------
Date: Wed, 24 Sep 2008 10:50:58 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: websites and cookies?
Message-Id: <m1skrpvbql.fsf@dot-app.org>
Tomasz Chmielewski <tch@nospam.wpkg.org> writes:
> As far as I understand, I need to "emulate" a webbrowser a bit:
> 1) log in to a website (fill proper form fields, send it to the web server)
> 2) get the cookie, browse other pages using that cookie
>
> What do I need to implement it in a Perl script?
Have a look at WWW::Mechanize
sherm--
--
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
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 1873
***************************************