[19425] in Perl-Users-Digest
Perl-Users Digest, Issue: 1620 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 26 21:05:26 2001
Date: Sun, 26 Aug 2001 18:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <998874307-v10-i1620@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 26 Aug 2001 Volume: 10 Number: 1620
Today's topics:
Re: $1 as subroutine parameter - problems ctcgag@hotmail.com
Re: expired Linux accounts check program in Perl <gnarinn@hotmail.com>
Re: form post to https server, best method <bwalton@rochester.rr.com>
Re: It's to AM for me to think <Tassilo.Parseval@post.rwth-aachen.de>
Re: It's to AM for me to think <tinamue@zedat.fu-berlin.de>
Re: It's to AM for me to think (Mark Jason Dominus)
Re: It's to AM for me to think <Tassilo.Parseval@post.rwth-aachen.de>
Re: It's to AM for me to think <tinamue@zedat.fu-berlin.de>
Re: Keylogging in perl <bwalton@rochester.rr.com>
Re: Modem::Vgetty (Newbie) thedoctor@space.net
Re: Perl help <jbc@west.net>
Re: Perl help (Eric Bohlman)
Re: Perl help <Tassilo.Parseval@post.rwth-aachen.de>
Re: Perl help (Mark Jason Dominus)
Re: Perl help (Mark Jason Dominus)
Re: Perl help <Tassilo.Parseval@post.rwth-aachen.de>
Re: Perl help (Tad McClellan)
Re: Perl help (Tad McClellan)
Re: random link from web page <bwalton@rochester.rr.com>
Re: Self-Searchable Perl documention - Extremely Useful (John Holdsworth)
Re: Telnet front-end <somewhere@in.paradise.net>
uploadin images into tables? <swancar2000@yahoo.com>
Re: uploadin images into tables? (E.Chang)
Re: uploadin images into tables? (Martien Verbruggen)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 26 Aug 2001 22:32:19 GMT
From: ctcgag@hotmail.com
Subject: Re: $1 as subroutine parameter - problems
Message-Id: <20010826183219.628$gz@newsreader.com>
abigail@foad.org (Abigail) wrote:
> Markus Laire (markus.laire@usa.net) wrote on MMCMXVI September MCMXCIII
> in <URL:news:Xns9109A5A7BF1markuslaire@192.89.123.233>:
> -:
> -: When I use $1 as parameter to subroutine, which does some regexp for
> that -: parameter and then tries to use parameter again, it is changed by
> that -: regexp because $_[0] seems to reference $1 which was given as
> parameter.
>
> That's because Perl passes arguments by reference. You pass $1 as $_ [0],
> which will be passed as a reference, then your regex will set $1 -
> modifying $_ [0] too.
But, if you print $1 again after the subroutine, it will have the same
value it did before the subroutine. So $_[0] wasn't really acting as an
alias for the passed $1.
#!/usr/bin/perl -w
use strict;
my $x="abcdefgh";
$x=~ /(d.+f)/ or die;
print "outer start: $1\n";
&x($1);
print "outer end: $1\n";
sub x {
print "inner start: $1, $_[0] \n";
"deadbeef" =~ /(d.+f)/ or die;
print "inner end: $1, $_[0] \n";
} ;
__END__
outer start: def
inner start: def, def
inner end: deadbeef, deadbeef
outer end: def
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service
------------------------------
Date: Sun, 26 Aug 2001 21:43:26 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: expired Linux accounts check program in Perl
Message-Id: <998862206.16045152861625.gnarinn@hotmail.com>
In article <3B8934A4.4BAB2F80@yahoo.com>,
Valentin 30IR976 <radiotito@yahoo.com> wrote:
>I am writing a Perl program to check my Linux system with shadow
>password installed. I think I must check the /etc/shadow file, with
>something like:
>
>($field1,$field2,...)=split(..) -->extract the different fields from
>shadow file with ':' as separator.
>
>But, I think I should make some calculus to check if an account has
>expired, but...what calculus?
there *might* be linux admin types here on this group that might want to
help you with this, but am am sure you would do better by going to some
appropriate newsgroup and ask there how to do what you want.
if you then have problems with the implementation of that in Perl,
then come back to this group with a clear problem/question.
gnari
------------------------------
Date: Sun, 26 Aug 2001 23:43:31 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: form post to https server, best method
Message-Id: <3B89899A.CF8C41A0@rochester.rr.com>
Nitin G wrote:
>
> am looking at implementing a solution where I need to post some data to a
> https server. Before I went down a path that led to nowhere, I wanted to get
> input from people who might have implemented a similar solution. What's the
> best recommended module to use for handling such a situation?
...
> -Nitin
I would start with the LWP module. The following should be very
helpful:
perldoc lwpcook
You might have to get the Crypt::SSLeay module.
--
Bob Walton
------------------------------
Date: Mon, 27 Aug 2001 00:25:42 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: It's to AM for me to think
Message-Id: <3B897766.20506@post.rwth-aachen.de>
Mark Jason Dominus wrote:
>>So, a pure Perl-loop of O(n) seems to be quicker than a C-optimized Perl-sort of
>>O(n log(n)).
>>
>
> That's because you cheated by picking a very special test case. The
> array elements are in order from largest to smallest. This is the
> *optimal* case for the loop code, because it only performs one
> assignment, and is a common worst-case for sort functions. In such a
> case, the following algorithm is the most efficient:
>
> my $largest = $array[0];
Ah, shit, sorry! Reversed order is indeed bad for the sort-algorithm and
good for the loop....I overlooked it.
But I just did it again, this time with the ordered list for the loop
and reverse order for the sort. This would mean worst case with maximum
number of assignements. For a 1000 element list and with 1000
iterations, the loop is still 52% quicker. Same for smaller lists of 100
and 10 elements. So it does not result in a fundemantal change.
>
> You also neglected to say what version of Perl you are using. In
> recent versions of Perl,
>
> sort { $b <=> $a }
>
> is more efficient than in old versions, because the function call to
> the comparator is optimized away.
Implicitely I said which version I at least use. I have 5.6.1 while I
pointed out that since 5.6.0 Perl uses merge-sort. I wouldn't have said
it had I used an older version. ;-)
> For an alternative (and probably more useful) look at this, see
>
> http://perlmonks.plover.com/index.pl?node_id=67059
Hmmh....this does not at all reflect my results. I though it might be
because in this benchmark cited by you they'd use random numbers.
But now I just initialized an array with 10000 rand-numbers between 0
and 100. Loop performs even twice as well as with sorted rising numbers,
234% quicker that is. The same with smaller arrays of 1000 and 100
elements. Even with just 10 random elements, sort is 12% slower.
So, I do not have an explanation for my benchmark and this one on
perlmonks. One of either did something wrong. ;-)
Tassilo
PS: I did not deliberatly cheat on the first benchmark. In fact I'd been
quite silly if I had done so since it was to the disadvantage of my own
method suggested.
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: 26 Aug 2001 22:27:07 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: It's to AM for me to think
Message-Id: <9mbt3r$193ud$1@fu-berlin.de>
Tassilo v. Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote:
> On 26 Aug 2001 15:26:21 -0500, Logan Shaw <logan@cs.utexas.edu> wrote:
>>>$largest = (sort { $b <=> $a } @a) [0];
>>>
>>>Admittedly, this may be slower on very large arrays - O(n log(n)) -
>>>while yours is O(n)....though I am not sure whether Perl's optimizations
>>>would make up for that.
>>
>> The answer is, there is a certain threshold of array size where the
>> sort method will start to become slower than the other method. It may
> Obviously with any size bigger than (at least) 9. :-) But see below.
> Ok, I was curious:
> #! /usr/bin/perl -w
[benchmark snipped]
just another version:
my $biggest = largest(@array);
use Inline C => <<'END_OF_C_CODE';
int largest(int a1, ...) {
Inline_Stack_Vars;
int i;
int biggest = 0;
for (i = 0; i < Inline_Stack_Items; i++) {
int temp = SvIV(Inline_Stack_Item(i));
if (temp >= biggest)
biggest = temp;
}
return biggest;
}
END_OF_C_CODE
okay, it's C, and I'm taking 0 as the start value so it's
working correctly only for numbers >= 0, but if you have
really large arrays and slow CPU, that's the best way =)
(starts to be quicker at arrays with about 200000 entries)
regards,
tina
--
http://www.tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
--- Warning: content of homepage hopelessly out-dated ---
------------------------------
Date: Sun, 26 Aug 2001 22:40:12 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: It's to AM for me to think
Message-Id: <3b897acb.1550$b7@news.op.net>
In article <3B897766.20506@post.rwth-aachen.de>,
Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote:
>Hmmh....this does not at all reflect my results. I though it might be
>because in this benchmark cited by you they'd use random numbers.
It might also be that the hash walking overhead in the other benchmark
is affecting the results.
>So, I do not have an explanation for my benchmark and this one on
>perlmonks. One of either did something wrong. ;-)
Or not. Performance varies.
>PS: I did not deliberatly cheat on the first benchmark.
I was being facetious. I didn't really think you were trying to cheat.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Mon, 27 Aug 2001 00:40:49 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: It's to AM for me to think
Message-Id: <3B897AF1.1000003@post.rwth-aachen.de>
Tina Mueller wrote:
> just another version:
> my $biggest = largest(@array);
> use Inline C => <<'END_OF_C_CODE';
> int largest(int a1, ...) {
> Inline_Stack_Vars;
> int i;
> int biggest = 0;
> for (i = 0; i < Inline_Stack_Items; i++) {
> int temp = SvIV(Inline_Stack_Item(i));
> if (temp >= biggest)
> biggest = temp;
> }
> return biggest;
> }
> END_OF_C_CODE
>
> okay, it's C, and I'm taking 0 as the start value so it's
> working correctly only for numbers >= 0, but if you have
> really large arrays and slow CPU, that's the best way =)
> (starts to be quicker at arrays with about 200000 entries)
Your version's been respectfully rejected for the sake of convenience.
It'd force me into writing evil C. ;-)
As for performance, however, I agree. There is not much that matches
well-written C. I guess once I encounter a task that can no longer be
sensibly done in Perl, I will work myself into Inline::C. Just praying
it wont happen.
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: 27 Aug 2001 00:06:36 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: It's to AM for me to think
Message-Id: <9mc2uc$193ud$2@fu-berlin.de>
Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote:
> Tina Mueller wrote:
>> just another version:
[Inline::C example]
>> okay, it's C, and I'm taking 0 as the start value so it's
>> working correctly only for numbers >= 0, but if you have
>> really large arrays and slow CPU, that's the best way =)
>> (starts to be quicker at arrays with about 200000 entries)
> Your version's been respectfully rejected for the sake of convenience.
> It'd force me into writing evil C. ;-)
=)
> As for performance, however, I agree. There is not much that matches
> well-written C. I guess once I encounter a task that can no longer be
> sensibly done in Perl, I will work myself into Inline::C. Just praying
> it wont happen.
yeah, for me it's just a nice tool playing around with at the
moment, but also a point to start with learning C a little
bit and looking into the perl internals...
got it a little bit quicker by not having @array as a parameter
to the sub, instead it uses the @main::array for sorting.
but it's still slower for array sizes under about 120000 elements... :-/
only if you use the function more than once in a script,
let's say, you call it 1000 times on arrays with > 400 elements,
then it's quicker.
but i guess if somebody really wants to save CPU time, they
would use pure C instead... =)
regards,
tina
--
http://www.tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
--- Warning: content of homepage hopelessly out-dated ---
------------------------------
Date: Sun, 26 Aug 2001 23:19:19 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Keylogging in perl
Message-Id: <3B8983EF.97CE4733@rochester.rr.com>
Massacre Zero wrote:
>
> I've been trying to write a basic keylogger as a project in Perl for
> Windows.
> Someone told me that I would have to look into 'windows hooks' for the
> solution.
> I have no experience on the subject and would appreciate any help.
>
> -Ryan
> massacre0@yahoo.com
Check out Win32::Console, particularly the Input method. I think you
could make it record and pass through all keystrokes to that console. I
don't think that would get keystrokes in other windoze in Windoze,
though. You might want to look over the other Win32:: modules and see
if perhaps one of them would help -- maybe Win32::API?
--
Bob Walton
------------------------------
Date: Sun, 26 Aug 2001 22:21:40 GMT
From: thedoctor@space.net
Subject: Re: Modem::Vgetty (Newbie)
Message-Id: <3b894ad6$1$oeczf$mr2ice@news.earthlink.net>
In <cd3e8552.0108110705.1c96c0ef@posting.google.com>, on 08/11/01
at 08:05 AM, mikekh123@yahoo.com (Mike) said:
>hi,
>I'm trying to use Modem::Vgetty and I can't even get the exampel code
>that comes with the module to work!
>I have this code
>----------
>#!/usr/bin/perl -w
>use Modem::Vgetty;
>$v = new Modem::Vgetty();
>$v->add_handler('BUSY_TONE', 'endh', sub { $v->stop; exit(0); }); local
>$SIG{ALRM} = sub { $v->stop; };
>$v->enable_events;
>$v->record('/tmp/hello.rmd');
>alarm(20);
>$v->waitfor('READY');
>$v->shutdown;
>-------------
>And get this error
>"can't call method "add_handler" on an undefined value at .test.pl line
>4"
>Can anyone help ??
>Thx
>Mike
What modem are you using? What version of vgetty are you using? All of
the event calls failed for me until I installed 1.1.26. I think it is
working better now, but I'm still in the process of testing.
Paul Schwartz
--
-----------------------------------------------------------
Reply to brpms at earthlink dot net
-----------------------------------------------------------
------------------------------
Date: Sun, 26 Aug 2001 15:24:40 -0700
From: John Callender <jbc@west.net>
Subject: Re: Perl help
Message-Id: <3B897728.214DA122@west.net>
teleconnect wrote:
>
> What exactly does localizing variables do? In other words, what is its
> purpose? Also are there any differences between "my" and "local"? I'v
> read "local" is replaced with "my" in Perl 5, yet I see some programmers
> using it, even in Matt's Script Archive.
The basic idea is that you are making it so a variable that
you're using in one part of your script doesn't trample on a
variable with the same name somewhere else. Even if you happen to
know already that that won't be a problem, it's still a good
idea, since it makes it easier for future maintainers of your
code to figure that out for themselves. The differences between
'my' and 'local' as a way to do this are going to seem fairly
subtle at this stage in your education, but in general you should
use 'my' as much as possible (which is going to be almost
always).
For more detail, see the perlsub manpage, in particular the
places where it talks about "Private Variables via my()" and
"Temporary Values via local()".
P.S. Couple of minor issues you'll doubtless hear about from
others: "Perl help" is a poor choice for a subject line, since it
makes it hard for people people scanning the newsgroup's subject
lines to know what, specifically, your message is about.
Something like "Why localize variables?" or "my versus local?"
would be better.
Also, Matt's Script Archive is something of a hot-button issue
for many of the regulars around here. His scripts are generally
looked down upon, at least as examples to learn from, since he
was himself only just learning when he wrote a lot of them, and
it shows.
------------------------------
Date: 26 Aug 2001 22:33:34 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Perl help
Message-Id: <9mbtfu$l7$1@bob.news.rcn.net>
teleconnect <teleconnect@webtv.net> wrote:
> Im a newbie to Perl so I have a newbie question. Here it goes.
In this case, one that's covered in the FAQs that came with your perl
installation, namely "What's the difference between dynamic and lexical
(static) scoping? Between local() and my()?" It's in perlfaq7. I'm
going to ask you to read it there, rather than telling you the difference,
for two reasons:
1) I might make a mistake in describing the difference, but the FAQ answer
has been reviewed by thousands of people. It's as guaranteed to be
correct as you can get in this business.
2) This is already a very high-traffic group, and the congestion gets
worse when people ask FAQs here; there's one message to ask the FAQ, at
least one message to answer it, and if someone realizes that somebody else
gave an incorrect answer, there's at least one more message to correct it.
The upshot of all this is that asking FAQs here is rather rude behavior;
it may not have been initially apparent to you, but you need to keep it in
mind for the future; if a poster develops a reputation for asking FAQs,
what eventually happens is that the most experienced people here tell
their newsreaders to give his/her posts a very low priority to read
(remember that the traffic here is so high that few if any people have the
time to read all the posts; they have to be choosy). And this means that
when you *do* have a question that's not easily answerable by the FAQ
documents, the very people who could help you the most won't see it, and
most of your answers will come from people whose expertise you may not be
able to trust.
> What exactly does localizing variables do? In other words, what is its
> purpose? Also are there any differences between "my" and "local"? I'v
> read "local" is replaced with "my" in Perl 5, yet I see some programmers
> using it, even in Matt's Script Archive.
Matt's Script Archive is not regarded as quality code in these parts; most
of the scripts were written quite long ago (long enough ago that Perl
didn't even have lexical (my) scoping) and haven't been updated since.
That's a pity because many of them are buggy and some of them have serious
security holes. Matt's code is *not* a good place to learn Perl from.
> Thanks alot to anyone that helps me!
The best way to show your gratitude is to familiarize yourself with the
extensive documentation that comes with perl. Learn to use the perldoc
program ("perldoc perldoc" will show you how to get started).
> P.S. Hope no one cares im @webtv.net
In this group, you're judged by your behavior, not where you come from.
Just remember that this is a discussion group, not a help desk, and that
that's sort of analogous to the difference between a potluck dinner and a
restaurant meal. Don't bogart the potato salad!
------------------------------
Date: Mon, 27 Aug 2001 00:34:44 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Perl help
Message-Id: <3B897984.2040900@post.rwth-aachen.de>
teleconnect wrote:
> Hey group,
>
> Im a newbie to Perl so I have a newbie question. Here it goes.
>
> What exactly does localizing variables do? In other words, what is its
> purpose? Also are there any differences between "my" and "local"? I'v
> read "local" is replaced with "my" in Perl 5, yet I see some programmers
> using it, even in Matt's Script Archive.
Since Perl 5 there is a difference between those two, though, in general
you are safe using my.
What local() does is creating a temporary copy of the original variable
while my creates a totally new variable that does not have any
connection with the world outside its block.
You need local() if you want to 'localize' (temporarily change) the
value of one of Perl globals.
Consider you want to check if a string is inside strings of
array-elements. For convenience you want to do that with index:
{
local $[ = 1;
for my $s (@array) {
if (! index $s, "pattern") {
do_something;
}
}
}
$[ is the index of the first element of an array or the first letter of
a string. As default, it is 0 which would lead index to return -1 if
"pattern" is not to be found in $s. But since we want to avoid writing
if (index $s, "pattern" == -1)
we'd have to locally set $[ = 1 so that a non-matching index returns 0.
In this example you could not have used my since it wont work on Perl's
special variables. In most other cases where you want to declare
lexically scoped variables, you use my. It is more efficient, since
local has to save the original value of a variable away in order to
restore it later when you leave the block.
As for Matt's script archive....I am not so acquainted with that. But I
assume that a lot of scripts date back to the time of Perl 4 where there
was not proper scoping of variables.
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: Sun, 26 Aug 2001 22:42:07 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Perl help
Message-Id: <3b897b3e.155c$10@news.op.net>
In article <3B897984.2040900@post.rwth-aachen.de>,
Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote:
>Since Perl 5 there is a difference between those two, though, in general
>you are safe using my.
There was a difference before Perl 5 also. Before Perl 5, 'my' was a
syntax error.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Sun, 26 Aug 2001 22:44:21 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Perl help
Message-Id: <3b897bc5.1569$fb@news.op.net>
In article <23506-3B896BB4-199@storefull-223.iap.bryant.webtv.net>,
teleconnect <teleconnect@webtv.net> wrote:
>What exactly does localizing variables do? In other words, what is its
>purpose? Also are there any differences between "my" and "local"?
See some parts of http://perl.plover.com/FAQs/Namespaces.html
Especially the part starting at
http://perl.plover.com/FAQs/Namespaces.html#Lexical_Variables
It explains why you want lexical variables, and the difference between
'my' and 'local'.
> I see some programmers
>using it, even in Matt's Script Archive.
Most programs are badly written. Most of Matt's programs are also
badly written.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Mon, 27 Aug 2001 00:50:11 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Perl help
Message-Id: <3B897D23.2090706@post.rwth-aachen.de>
Mark Jason Dominus wrote:
> In article <3B897984.2040900@post.rwth-aachen.de>,
> Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote:
>
>>Since Perl 5 there is a difference between those two, though, in general
>>you are safe using my.
>>
>
> There was a difference before Perl 5 also. Before Perl 5, 'my' was a
> syntax error.
Really? And till Perl 20.1.0 "perl -e 'make_coffee'" will also be a
syntax error....or rather a bareword or whatever. ;-)
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: Sun, 26 Aug 2001 18:52:45 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl help
Message-Id: <slrn9oivds.mih.tadmc@tadmc26.august.net>
Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote:
>teleconnect wrote:
[snip re-asking of a Frequently Asked Question, that is not good ]
>What local() does is creating a temporary copy of the original variable
local() does not make a temporary copy of the variable, it makes
a temporary copy of a variable's value.
my() is about variables.
local() is about _values_ (of variables).
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 26 Aug 2001 19:02:38 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl help
Message-Id: <slrn9oj00e.mih.tadmc@tadmc26.august.net>
teleconnect <teleconnect@webtv.net> wrote:
>Subject: Perl help
Please put the subject of your article in the Subject of your article.
Nearly every original article posted here is asking for Perl help.
Your choice of Subject does not convey any useful information.
>Im a newbie to Perl
And to Usenet in general, it would appear.
Usenet is it's own little society, with its own rules of what
is socially acceptable.
I tried to write down what folks here expect, maybe it will help you:
http://mail.augustmail.com/~tadmc/clpmisc.shtml
>so I have a newbie question. Here it goes.
"newbie questions" are also often Frequently Asked Questions.
You should check the Perl FAQs *before* posting to the Perl newsgroup.
This is netiquette common to nearly all newsgroups.
>What exactly does localizing variables do?
Controls the "scope" (visibility) of variables.
See also "Coping with Scoping":
http://perl.plover.com/FAQs/Namespaces.html
>In other words, what is its
>purpose?
To avoid hard-to-troubleshoot bugs.
>Also are there any differences between "my" and "local"?
Yes, and the FAQ explains them. Please read that first.
"What's the difference between dynamic and lexical (static) scoping?
Between local() and my()?"
>I'v
>read "local" is replaced with "my" in Perl 5, yet I see some programmers
>using it, even in Matt's Script Archive.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You say that as if Matt's programs are good or something.
They are examples of *very poor* Perl code. Don't learn your
Perl from those programs.
>Thanks alot to anyone that helps me!
Please do not take advantage of us again. We are not here to
read the FAQs to you.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 26 Aug 2001 23:08:25 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: random link from web page
Message-Id: <3B898162.46FD3CA0@rochester.rr.com>
confused wrote:
>
> ok, i am using the code at the bottom of this message to get links
> from a web page. How do i get it to return only 1 random link from the
> page so every time you goto the cgi page, it will show a different
> link ?
>
> #!/usr/bin/perl -w
>
> use strict;
> use HTML::LinkExtor;
> use LWP::Simple;
>
> my %seen;
> my $url =
> "http://www.yahoo.com";
> my $parser = HTML::LinkExtor->new(undef, $url);
> $parser->parse(get($url))->eof;
> my @links = $parser->links;
> foreach my $linkarray (@links) {
> my @element = @$linkarray;
> my $elt_type = shift @element;
> while (@element) {
> my ($attr_name, $attr_value) = splice(@element, 0, 2);
> $seen{$attr_value}++;
> }
> }
>
> print "Content-type: text/html\n\n";
> for (sort keys %seen) { print $_, "\n" };
Well, since you have them all stored as keys to a hash, you could just
pick one at random. This could be done by first putting them in an
array. Something like:
my @links=keys %seen;
print $links[rand @links],"\n";
to replace your last line of code above, perhaps.
--
Bob Walton
------------------------------
Date: 26 Aug 2001 16:15:43 -0700
From: coldwave@bigfoot.com (John Holdsworth)
Subject: Re: Self-Searchable Perl documention - Extremely Useful!
Message-Id: <2a46b11e.0108261515.374f8a06@posting.google.com>
demerphq@hotmail.com (Yves Orton) wrote in message news:<74f348f7.0108250743.2631f2e1@posting.google.com>...
> dkcombs@panix.com (David Combs) wrote in message news:<9ll790$fvi$2@news.panix.com>...
> > In article <74f348f7.0108120702.662a6771@posting.google.com>,
> > Yves Orton <demerphq@hotmail.com> wrote:
> > >...
> > >Incidentally, I stayed up all night enhancing your activestate search
> > >engine (found a couple of minor gliitches, but who cares). Check your
> > >mails for a copy of my mods.
Thanks very much Yves. You fixed a dumb bug due to a
last minute "optimisation". I like the weighting too.
Your new version is posted at:
http://www.openpsp.org/source/util/pertoc2.pl
and is now the version pointed to by the openpsp site
john
http://www.openpsp.org
------------------------------
Date: Mon, 27 Aug 2001 08:08:47 +1000
From: "Tintin" <somewhere@in.paradise.net>
Subject: Re: Telnet front-end
Message-Id: <9tei7.1$Hh5.59451@news.interact.net.au>
"Antonio" <agm@physics.berkeley.edu> wrote in message
news:3B892A9A.77B05CF9@physics.berkeley.edu...
> Logan Shaw wrote:
>
> > In article <3B88A198.1916B4BC@physics.berkeley.edu>,
> > Antonio <agm@physics.berkeley.edu> wrote:
> > >I need to make a front-end to a program that, among other things,
> > >invokes standard telnet after soliciting a login and password. The
> > >program would prompt the user for various information, and then after
> > >having a login session, would let telnet function from that point on.
> >
> > Wouldn't it be much easier just to not use telnet and instead use
> > something that allows you to do a remote login without having to enter
> > a username and password interactively? The most likely candidate is
> > Secure Shell. See http://www.ssh.com/ and http://www.openssh.com/ .
> >
>
> Yes it would be easier, but to my understanding of SSH, one needs to
> configure the hosts file on the remote server, in order to have a
> passwordless login. Otherwise, SSH prompts you interactively for a
> password, just like telnet. In my situation, the remote server is likely
> one I do not administer, hence I can do nothing about it. If that is
> indeed the case (which I think it is), how does one handle interactive
> processes with Perl?
There are many authentication methods for ssh ranging from simple .shosts to
certificates. I'm sure you'll find something to suit, otherwise use the
Net::Telnet module.
------------------------------
Date: Mon, 27 Aug 2001 00:57:43 +0100
From: "Julie" <swancar2000@yahoo.com>
Subject: uploadin images into tables?
Message-Id: <U_fi7.28270$_71.1695285@news6-win.server.ntlworld.com>
I am very new to all this and so my question maybe very simple to all you
lot.
I am using a perl script for a database and I am allowing people to upload
pictures as well as their data, the problem is that I would like to have all
the pictures appear in a table cell to be all the same size. I have tried to
use CSS but this only works in Explorer, is there another way I can do this
either by setting the size of the table cell so that any large images that
are uploaded can be squashed into the cell or is there a way to make it
mandatory that a set picture size has to be uploaded. I already have it set
so that the file size is mandatory but not image dimensions.
I am very very new to this so if anyone is kind enough to reply will you
please choose an easy option that I might understand
Thanks
Julie
------------------------------
Date: Mon, 27 Aug 2001 00:33:01 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: uploadin images into tables?
Message-Id: <Xns9109D1CEC55CBechangnetstormnet@207.106.92.86>
"Julie" <swancar2000@yahoo.com> wrote in
<U_fi7.28270$_71.1695285@news6-win.server.ntlworld.com>:
> I am very new to all this and so my question maybe very simple to
> all you lot.
> I am using a perl script for a database and I am allowing people to
> upload pictures as well as their data, the problem is that I would
> like to have all the pictures appear in a table cell to be all the
> same size. I have tried to use CSS but this only works in Explorer,
> is there another way I can do this either by setting the size of
> the table cell so that any large images that are uploaded can be
> squashed into the cell or is there a way to make it mandatory that
> a set picture size has to be uploaded. I already have it set so
> that the file size is mandatory but not image dimensions.
As I understand it, you are printing out an image tag for each image
displayed and want to control the size. Instead of trying to set the
dimensions of the table cell, just set the dimensions of the image
using standard height and width attributes:
print qq(<img src="$whatever_it_is" height="$calculated_height
width="$calculated_width" alt="Of_course_you_use_image_alts.">);
The use of the qq operator saves escaping the double quotes in the
string. (And justifies this as a Perl question rather than just an
HTML question, which would belong in another newsgroup.)
--
EBC
------------------------------
Date: Mon, 27 Aug 2001 10:31:49 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: uploadin images into tables?
Message-Id: <slrn9oj57l.3ga.mgjv@martien.heliotrope.home>
On Mon, 27 Aug 2001 00:57:43 +0100,
Julie <swancar2000@yahoo.com> wrote:
> I am very new to all this and so my question maybe very simple to all you
> lot.
> I am using a perl script for a database and I am allowing people to upload
> pictures as well as their data, the problem is that I would like to have all
> the pictures appear in a table cell to be all the same size. I have tried to
> use CSS but this only works in Explorer, is there another way I can do this
> either by setting the size of the table cell so that any large images that
> are uploaded can be squashed into the cell or is there a way to make it
> mandatory that a set picture size has to be uploaded. I already have it set
> so that the file size is mandatory but not image dimensions.
The Image::Size module may be of help to you. It is available from CPAN.
If you use ActiveState Perl, use the ppm tool to install it.
If you are looking at resizing images after they have been uploaded,
check out the Image::Magick module (http://www.imagemagick.org/).
It is generally not a good idea to serve up images that have a different
size from the intended display size. It's wasteful, and looks ugly.
There was a discussion on this not that long ago on this very newsgroup
earlier this year. Go to http://groups.google.com/ and do a search for
"re-sizing gif images on the fly".
Martien
--
Martien Verbruggen |
Interactive Media Division | You can't have everything, where
Commercial Dynamics Pty. Ltd. | would you put it?
NSW, Australia |
------------------------------
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.
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 1620
***************************************