[25426] in Perl-Users-Digest
Perl-Users Digest, Issue: 7671 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 19 06:05:35 2005
Date: Wed, 19 Jan 2005 03:05:10 -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 Wed, 19 Jan 2005 Volume: 10 Number: 7671
Today's topics:
-nodefaultlib <kalinaubears@iinet.net.au>
[perl-python] 20050119 writing modules <xah@xahlee.org>
Re: FAQ 4.64 How can I get the unique keys from two has <a.newmane.remove@eastcoastcz.com>
Re: Help Perlling a program <matthew.garrish@sympatico.ca>
Re: How do I force a specific compiler in Configure/mak <spamtrap@dot-app.org>
Re: HTTP Get with Proxy authentication <aprz43@yahoo.com.au>
Re: HTTP Get with Proxy authentication <matthew.garrish@sympatico.ca>
Re: Low level data manipulation in Perl <do-not-use@invalid.net>
Re: MAP Question <do-not-use@invalid.net>
Re: Parsing in regular expression <do-not-use@invalid.net>
Perl::expect script error <geen@mail.invalid>
Re: Perl::expect script error <1usa@llenroc.ude.invalid>
Re: Perl::expect script error <geen@mail.invalid>
Re: telnet timed out <mikael.petterson@ericsson.se>
Re: telnet timed out chris-usenet@roaima.co.uk
Re: The world's shortest 'Hello World!' program: a prop chris-usenet@roaima.co.uk
Re: Usage of File::Find <toreau@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 19 Jan 2005 04:07:30 +0000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: -nodefaultlib
Message-Id: <41edec86$0$31082$5a62ac22@per-qv1-newsreader-01.iinet.net.au>
Hi,
The subject line is included in $Config{lddlflags} with ActiveState
builds of perl. I'm just wondering what '-nodefaultlibs' actually does -
and where I should look to find the answer.
(Actually - I want to know what will be the effects of removing it from
$Config{lddlflags} on my AS-built perl.)
Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.
------------------------------
Date: 18 Jan 2005 21:12:26 -0800
From: "Xah Lee" <xah@xahlee.org>
Subject: [perl-python] 20050119 writing modules
Message-Id: <1106111546.794861.148010@c13g2000cwb.googlegroups.com>
=A9 # -*- coding: utf-8 -*-
=A9 # Python
=A9
=A9 # one can write functions,
=A9 # save it in a file
=A9 # and later on load the file
=A9 # and use these functions.
=A9
=A9 # For example, save the following line in
=A9 # a file and name it module1.py
=A9 # def f1(n): returns range(n)
=A9
=A9 # to load the file, use import
=A9 import mymodule
=A9
=A9 # to use the function, use
=A9 # fileName.functionName.
=A9 print mymodule.f1(5)
=A9
=A9 # the file name without the .py suffix
=A9 # is the module's name, and is available
=A9 # as the variable fileName.__name__
=A9 print mymodule.__name__
=A9
=A9 # for more on modules, see
=A9 # http://python.org/doc/2.3.4/tut/node8.html
=A9
=A9 --------------------
=A9 # the perl analogue is like this:
=A9 # save the following 3 lines in a file
=A9 # and name it mymodule.pm
=A9
=A9 # package mymodule;
=A9 # sub f1($){(1..$_[0])}
=A9 # 1
=A9
=A9 # then, call it like the following way
=A9 use mymodule;
=A9 use Data::Dumper;
=A9 print Dumper [&mymodule::f1(7)];
=A9
=A9 # this is about the simplest way
=A9 # to write a modlue in perl and
=A9 # calling its function.
=A9 # for an inscrutable treatment,
=A9 # see "perldoc perlmod"
=A9
=A9 Xah
=A9 xah@xahlee.org
=A9 http://xahlee.org/PageTwo_dir/more.html
------------------------------
Date: Tue, 18 Jan 2005 21:53:38 -0800
From: "Alfred Z. Newmane" <a.newmane.remove@eastcoastcz.com>
Subject: Re: FAQ 4.64 How can I get the unique keys from two hashes?
Message-Id: <356av7F4gq4s6U1@individual.net>
PerlFAQ Server wrote:
> This message is one of several periodic postings to
> comp.lang.perl.misc intended to make it easier for perl programmers
> to find answers to common questions. The core of this message
> represents an excerpt
> from the documentation provided with Perl.
>
> --------------------------------------------------------------------
>
> 4.64: How can I get the unique keys from two hashes?
>
> First you extract the keys from the hashes into lists, then solve
> the "removing duplicates" problem described above. For example:
>
> %seen = ();
> for $element (keys(%foo), keys(%bar)) {
> $seen{$element}++;
> }
> @uniq = keys %seen;
>
> Or more succinctly:
>
> @uniq = keys %{{%foo,%bar}};
>
> Or if you really want to save space:
>
> %seen = ();
> while (defined ($key = each %foo)) {
> $seen{$key}++;
> }
> while (defined ($key = each %bar)) {
> $seen{$key}++;
> }
> @uniq = keys %seen;
Or:
use vars qw/%foo %bar %seen $hash $key @uniq/;
%foo = (one => 1, two => 2, three => 3);
%bar = (one => 1, three => 3, five => 5);
foreach $hash (\%foo, \%bar) {
while (defined ($key = each %$hash)) {
$seen{$key}++;
}
}
@uniq = keys %seen;
print join("\n", @uniq);
Or simplying the inner loop:
foreach $hash (\%foo, \%bar) {
$seen{$key}++ while (defined ($key = each %$hash));
}
------------------------------
Date: Tue, 18 Jan 2005 23:59:03 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Help Perlling a program
Message-Id: <qOlHd.26385$K03.663870@news20.bellglobal.com>
"YYusenet" <yyusenet@yahoo.com> wrote in message
news:cskjbo$js0$1@news.xmission.com...
> Hello,
>
> I am new to Perl, so I am probably making my programs (or scripts?) in a
> non-Perl way. I was wondering if the following script could be made with
> less repition or lines of code, or in a more Perl like way.
>
> The script is used so if I download a lot of pictures with not very useful
> names (like from digital camera software that exports pictures called
> IMG000001234 or something), it would name them in order, starting with
> zero. It also should work assuming that there may already be files named
> 0.jpg, etc.
>
You should bundle repitious code into subroutines whenever possible. A
couple of other points I'd make are to use more whitespace in your code and
to always name your variables. Readability of your code is far more
important than how "perlish" it might be. The code below my name should be
pretty self-explanatory.
Matt
use strict;
use warnings;
use File::Copy;
my $path = 'c:/temp/';
my $files = get_files($path);
print_line("RENAMING .jpg STARTING");
my $cnt = '0';
foreach my $file (@{$files->{'jpg'}}) {
rename_file($file, $path, '.jpg', $cnt);
$cnt += 1;
}
print_line("RENAMING COMPLETE");
print_line("RENAMING .gif STARTING");
$cnt = '0';
foreach my $file (@{$files->{'gif'}}) {
rename_file($file, $path, '.gif', $cnt);
$cnt += 1;
}
print_line("RENAMING COMPLETE");
print_line("PROGRAM FINISHED");
sub get_files {
my %files;
opendir(FILEDIR, $_[0]) or die "Could not read $_[0]: $!";
while (my $file = readdir(FILEDIR)) {
if ($file =~ /\.(gif|jpg)(\.bak)?$/i) {
rename("$_[0]$file", "$_[0]$file.bak") or die "Could not rename
$file: $!";
push @{$files{$1}}, "$file.bak";
}
}
closedir(FILEDIR);
return \%files;
}
sub rename_file {
my ($file, $path, $ext, $cnt) = @_;
$file = $path . $file;
my $new = $path . $cnt . '.jpg';
print "renaming $file...\t\tto\t$new\n";
rename($file, $new) or die "unable to rename $file to $new: $!";
}
sub print_line {
print "\n", "-"x8, $_[0], "-"x8, "\n";
}
------------------------------
Date: Wed, 19 Jan 2005 03:11:45 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: How do I force a specific compiler in Configure/make
Message-Id: <VKCdnUHzovbfi3PcRVn-qg@adelphia.com>
Jacob wrote:
> did, but xlc_r was not in the list. However, among the
> aliases was this tidbit:
> cc=/usr/bin/cc
>
> Anything in that? Nah, the make is not invoking cc, it's
> invoking cc_r.
It might be relevant, or it might not. Is /usr/bin/cc a link (either kind)
to cc_r? If so, it might be worth trying a different alias.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: 18 Jan 2005 21:08:52 -0800
From: "Adrian" <aprz43@yahoo.com.au>
Subject: Re: HTTP Get with Proxy authentication
Message-Id: <1106111331.980077.310160@f14g2000cwb.googlegroups.com>
Matt,
Thank you so much for your help. Its obvious that you are a perl
expert.
Not only that, but you were the only one kind enough to offer your
advice. If only other Perl developers were as helpful as you have
been, I may've even solved this problem sooner.
Also, would it be possible to post your easier and more flexible
solution here so that myself and others may also benefit from it.
Cheers,
Adrian
------------------------------
Date: Wed, 19 Jan 2005 00:45:05 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: HTTP Get with Proxy authentication
Message-Id: <AtmHd.27668$K03.675133@news20.bellglobal.com>
"Adrian" <aprz43@yahoo.com.au> wrote in message
news:1106111331.980077.310160@f14g2000cwb.googlegroups.com...
>
> Also, would it be possible to post your easier and more flexible
> solution here so that myself and others may also benefit from it.
>
There's no real point in my posting anything, as the documentation does a
much better job:
http://www.perldoc.com/perl5.8.0/lib/lwpcook.html
In your case, take a look at the section on proxies and authentication.
Matt
------------------------------
Date: 19 Jan 2005 10:08:05 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: Low level data manipulation in Perl
Message-Id: <yzdekghiy6i.fsf@invalid.net>
"Leonard Challis" <perl@lennychallis.co.uk> writes:
> I am referring to most people in this group who aren't newbies. If you do
> plenty of searching first and then ask a question you will still get flamed.
> People seem to enjoy flaming each other in this group. It's quite sad
> really. I fully agree with people just posting "I cant do it how do i do
> it!" questions, but when people show what they have searched already and why
> they are still struggling do they deserve being flamed still?
The text you quote (*) mostly mentions attributions, and their absence
in your article. You wrote "You don't seem to get me straight", with
no indication on who or what you mean.
I don't know what "most people in this group who aren't newbies" like
to do. Many of them probably read this group hoping to learn something
now and then, and don't bother to post anything. Some jump in and post
something now and then when they think it might be useful and not
mentioned already. Some point out style and other errors, including
failure to follow the posting guidelines, as a matter of routine.
(*) In the wrong place. It's better and common practice to write your
comments after the text you're referring to. The opposite is called
"top-posting".
------------------------------
Date: 19 Jan 2005 10:27:45 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: MAP Question
Message-Id: <yzdacr5ix9q.fsf@invalid.net>
Michele Dondi <bik.mido@tiscalinet.it> writes:
> On 17 Jan 2005 17:31:19 -0800, "Peroli" <peroli@gmail.com> wrote:
>
> >hi george,
> >If Map bugs you, why dont you try grep. It works.
>
> map() and grep() do different things, even if they're indeed cousins
> each other. There's nothing in the OP's post that suggests he may be
> interested in the latter, but of course it would be important to
> understand what he does really want or what he expected out of map().
>
> As a side note I tried to draw the attention of the OP to the
> inutility spelling "map" incorrectly only to, presumably, emphasize
> it. I don't see no need to capitalize it either, nay, to be fair it
> seems even worse than uppercasing it altogether.
To add to this subject (as relative Perl newbie), some common ways of
pointing out that a word (or longer construct) in running text is not
meant as an ordinary English word, but rather as Perl code, are:
'map'
"map"
map()
C<map>
"map()" is only used when that is in fact valid syntax, or a contraction
of valid syntax, e.g., when it's a function.
The C<map> convention seems to come from the Perl documentation "pod"
format. If the quoted text contains a '<', use C<< >> instead:
C<< $x >= $y >>
Personally, I mostly use single quotes for function names, and double
quotes for longer stuff, as well as file names, book titles, etc.
When discussing other languages, exactly what needs to be quoted
varies. For example. I would use 'number' for a C variable called
"number", but in Perl, just $number usually works fine, because of the
'$' sigil. There may still be a need to distinguish between just
talking about the variable $number, and pointing out that the variable
occurrence "$numbr" should be spelt "$number", for example.
Case of letters should never be changed when case is significant.
I even start sentences with a (quoted) lower-case letter. Doc writers
sometimes react to that.
------------------------------
Date: 19 Jan 2005 11:26:58 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: Parsing in regular expression
Message-Id: <yzd651tiuj1.fsf@invalid.net>
sam <sam.wun@authtec.com> writes:
>
> The following pattern does not return all the values, the pattern only
> able to parse the first two fields:
>
> my $test = "01-, Revlon, n/a, Revlon";
> $test =~
> /^([0-9]*-), #prefix 1
> (.*), #vendor 2
> (.*), #Category 3
> (.*) #basename 4
> /x;
>
> if ($1 eq "" or $2 eq "" or $3 eq "") {
> print "Failed to parse $test\n";
> } else {
> # get the value
> }
It works for me - I get the respective fields in all $1-$4.
" n/a" in $3, in particular. What do you get in $3?
It's better to test the match itself for success:
if ($test =~ ...)
but that doesn't explain why the match doesn't work for you.
------------------------------
Date: Wed, 19 Jan 2005 07:40:51 +0100
From: ruud <geen@mail.invalid>
Subject: Perl::expect script error
Message-Id: <cskve2$c0j$1@box.nl-netwerken.com>
I'm writing a script that can post to my newsserver.
#!/usr/bin/perl
use Expect;
use warnings;
use strict;
my $post = "post";
my $hallo = "200";
my $quit = "quit";
my $conn;
$conn -> spawn ("news.nntpserver.com:119");
$conn -> expect ("$hallo");
print "$post\n";
But i get this error:
Can't call method "spawn" on an undefined value at ./p line 11.
What is wrong with this expect script ?
--
Gr. Ruud
------------------------------
Date: 19 Jan 2005 07:28:02 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Perl::expect script error
Message-Id: <Xns95E31919DFA1Easu1cornelledu@132.236.56.8>
ruud <geen@mail.invalid> wrote in
news:cskve2$c0j$1@box.nl-netwerken.com:
> I'm writing a script that can post to my newsserver.
>
> #!/usr/bin/perl
> use Expect;
> use warnings;
> use strict;
>
>
>
> my $post = "post";
> my $hallo = "200";
> my $quit = "quit";
> my $conn;
>
>
>
> $conn -> spawn ("news.nntpserver.com:119");
> $conn -> expect ("$hallo");
> print "$post\n";
>
> But i get this error:
> Can't call method "spawn" on an undefined value at ./p line 11.
>
> What is wrong with this expect script ?
Exactly what perl tells you.
It seems like you haven't even read the documentation for Expect.pm.
Expect->spawn($command, @parameters) or
$object->spawn($command, @parameters) or
new Expect ($command, @parameters)
Forks and execs $command. Returns an Expect object upon success
or undef if the fork was unsuccessful or the command could not
be found. spawn() passes its parameters unchanged to Perls
exec(), so look there for detailed semantics.
$conn is not defined at the moment when you call the spawn method on it.
The interface specifies:
my $conn = Expect->new($command, @parameters);
Which brings us to the second issue: The domain name of your news server
is not a command that can be executed on your machine. I guess you could
spawn a telnet session with the news server but why you would bother
with such a cumbersome method is beyond me and I can't really figure out
why you think Expect is a good tool to interact with a news server.
CPAN contains an assortment of NNTP related modules. While I haven't
used either of them, Net::NNTP and Net::NNTP::Client would be the first
modules I would have looked at had I wanted NNTP functionality.
Sinan.
------------------------------
Date: Wed, 19 Jan 2005 11:08:54 +0100
From: ruud <geen@mail.invalid>
Subject: Re: Perl::expect script error
Message-Id: <cslbk3$ctk$3@box.nl-netwerken.com>
A. Sinan Unur wrote:
> Expect->spawn($command, @parameters) or
> $object->spawn($command, @parameters) or
> new Expect ($command, @parameters)
>
> Forks and execs $command. Returns an Expect object upon success
> or undef if the fork was unsuccessful or the command could not
> be found. spawn() passes its parameters unchanged to Perls
> exec(), so look there for detailed semantics.
>
> $conn is not defined at the moment when you call the spawn method on it.
> The interface specifies:
>
> my $conn = Expect->new($command, @parameters);
Thank you for pointing me in the good direction.
It's working like a charm now.
--
Gr. Ruud
news://news.nl-netwerken.com
------------------------------
Date: Wed, 19 Jan 2005 09:22:56 +0100
From: Petterson Mikael <mikael.petterson@ericsson.se>
Subject: Re: telnet timed out
Message-Id: <csl553$8aq$1@newstree.wise.edt.ericsson.se>
l v wrote:
> Petterson Mikael wrote:
>
>> Hi,
>>
>> I am using Net::Telnet module in perl to connect to a remote client.
>> I get a timeout for '$telnet->login($username, $password);'.
>>
>> timed-out waiting for command prompt at ./telnet.pl line 15
>>
>> Any ideas why?
>>
>> I have tried with regular telnet and it works!
>>
>> //Mikael
>>
>>
>> Script
>> -------------------------------------------
>> #!/vobs/cello/cade_struct/bin/perl -w
>>
>> use Net::Telnet;
>>
>> my $hostname = 'ws3196.rnd.ki.sw.ericsson.se';
>> my $username = 'eraonel';
>> my $password = 'test';
>>
>>
>> my $telnet = new Net::Telnet ( Timeout=>30,
>> Errmode=>'die');
>>
>>
>> $telnet->open($hostname);
>> $telnet->login($username, $password);
>> $telnet->waitfor('/login:.*$/');
>> print $telnet->cmd('whoami');
>>
>> This is how my telnet login looks like:
>> ***************************************
>>
>> Trying 147.214.201.190...
>> Connected to ws3196.
>> Escape character is '^]'.
>>
>>
>> SunOS 5.8
>>
>> login:
>>
>> ****************************************
>
>
> According to the Net::Telnet doc:
>
> *The methods login() and cmd() use the prompt setting in the object to
> determine when a login or remote command is complete. The method will
> fail with a time-out if you don't set the prompt correctly. *
>
> Len
>
>
> ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet
> News==----
> http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000
> Newsgroups
> ---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Hi,
I was not clear that it was the prompt after logging in:
The prompt looks like this:
ast login: Wed Jan 19 09:15:41 from ws3196
Sun Microsystems Inc. SunOS 5.8 Generic Patch December 2002
ws3196{NONE}[espresso/rbssw/1.1]
I am using the following (code below) but I still get a timeout.
$telnet->open("$hostname");
$telnet->login("$username", "$password");
$telnet->waitfor('.[\]] $');
$telnet->cmd('who');
$telnet->close;
Hmmmm have I missed something fundamental about Telnet in this module.
it is not obvious to me but maybe to a more experienced perl coder?
//Mikael
------------------------------
Date: Wed, 19 Jan 2005 09:21:29 +0000
From: chris-usenet@roaima.co.uk
Subject: Re: telnet timed out
Message-Id: <pdl1c2-ib1.ln1@moldev.cmagroup.co.uk>
Petterson Mikael <mikael.petterson@ericsson.se> wrote:
>>> I am using Net::Telnet module in perl to connect to a remote client.
>>> I get a timeout for '$telnet->login($username, $password);'.
>>> timed-out waiting for command prompt at ./telnet.pl line 15
>>> my $telnet = new Net::Telnet ( Timeout=>30,
>>> Errmode=>'die');
The first documentation illustration shows a Prompt parameter in here
rather than needing to use waitfor().
>>> $telnet->open($hostname);
>>> $telnet->login($username, $password);
>>> $telnet->waitfor('/login:.*$/');
>>> print $telnet->cmd('whoami');
This chunk will wait for a prompt of "login:" AFTER having logged in,
before issuing the whoami command. I suspect this isn't what you want.
> The prompt looks like this:
> ast login: Wed Jan 19 09:15:41 from ws3196
> Sun Microsystems Inc. SunOS 5.8 Generic Patch December 2002
> ws3196{NONE}[espresso/rbssw/1.1]
Is there a space after the ']' character?
> I am using the following (code below) but I still get a timeout.
> $telnet->open("$hostname");
> $telnet->login("$username", "$password");
> $telnet->waitfor('.[\]] $');
> $telnet->cmd('who');
> $telnet->close;
Your waitfor parameter is incorrect - you've missed the apparently
mandatory // characters around the RE. Try this instead, which matches
"[espresso/rbssw/1.1]", where espresso and rbssw can be replaced by
any word, the 1.1 can be replaced by any decimal number, and there is
possibly a trailing space:
$telnet->waitfor('/\[w+\/w+\/\d+\.\d+\] ?$/');
Chris
------------------------------
Date: Wed, 19 Jan 2005 09:28:07 +0000
From: chris-usenet@roaima.co.uk
Subject: Re: The world's shortest 'Hello World!' program: a proposal
Message-Id: <7ql1c2-ib1.ln1@moldev.cmagroup.co.uk>
Larry <larry_wallet@yahoo.com> wrote:
> The controversy in this proposal may be the way in which to state:
> Hello World
> Here are a few alternatives that have been used traditionally:
> Hello, World
> Hello, World!
> Hello world.
> hello world...
> Hello Worlds!
You've missed out the canonical grandfather of them all (Kernigan and
Ritchie, "The C Programming language"):
ObPerl
print "hello, world\n"
Chris
------------------------------
Date: Wed, 19 Jan 2005 06:52:03 +0100
From: Tore Aursand <toreau@gmail.com>
Subject: Re: Usage of File::Find
Message-Id: <6AmHd.5043$Sl3.119936@news4.e.nsc.no>
tensai wrote:
> Is there any way to use File::Find and control the depth of directory
> recursion
Not with the module itself, I think, but why not use the superior
File::Find::Rule instead?
--
Tore Aursand <tore@aursand.no>
"First get your facts; then you can distort them at your leisure."
(Mark Twain)
------------------------------
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 7671
***************************************