[29552] in Perl-Users-Digest
Perl-Users Digest, Issue: 796 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 26 14:09:42 2007
Date: Sun, 26 Aug 2007 11:09:05 -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 Sun, 26 Aug 2007 Volume: 11 Number: 796
Today's topics:
Re: great and better hash eval <bik.mido@tiscalinet.it>
Re: great and better hash eval <john.swilting@wanadoo.fr>
Help: How to change PATH variable by array? <openlinuxsource@gmail.com>
Re: Help: How to change PATH variable by array? <tadmc@seesig.invalid>
new CPAN modules on Sun Aug 26 2007 (Randal Schwartz)
Re: Program Dies after 60 or so Iterations of Loop <sisyphus1@nomail.afraid.org>
Re: Program Dies after 60 or so Iterations of Loop <hjp-usenet2@hjp.at>
Searching within the hash values of an array of hashes usenet@DavidFilmer.com
Re: Searching within the hash values of an array of has xhoster@gmail.com
Re: Symrefs <ben@morrow.me.uk>
Re: Symrefs <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 26 Aug 2007 11:28:43 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: great and better hash eval
Message-Id: <tsh2d3hhdg8pep6chhp5f1jekarl2j2vti@4ax.com>
On Sun, 26 Aug 2007 01:26:42 +0200, john swilting
<john.swilting@wanadoo.fr> wrote:
>I do not understand .i start the deboguor ,is the file test.dat is well
>execute.in the file main.pl the loop while does not seem to function
>correctly. one only value is returned to me before keys. it appears
>infinite
http://en.wikipedia.org/wiki/Darmok
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Sun, 26 Aug 2007 18:38:04 +0200
From: john swilting <john.swilting@wanadoo.fr>
Subject: Re: great and better hash eval
Message-Id: <46d1ac6e$0$25919$ba4acef3@news.orange.fr>
anno4000@radom.zrz.tu-berlin.de wrote:
> john swilting <john.swilting@wanadoo.fr> wrote in comp.lang.perl.misc:
>> I do not understand .i start the deboguor ,is the file test.dat is well
>> execute.in the file main.pl the loop while does not seem to function
>> correctly. one only value is returned to me before keys. it appears
>> infinite
>>
##########################################################################
>> #main.pl
>>
##########################################################################
>> #!/usr/bin/perl
>>
>> require "ouvre_fichier.pl";
>> $f = "test.dat";
>> %fh = ouvre_fichier($f);;
>> while(( $clef,$valeur) = each %fh){
#update code
print "$clef => $valeur";
# keys %fh;
#assuming not infinite loop
> What is the call to "keys %fh" for? It does nothing useful but messes
> up the iteration.
>
>> }
>
> The call to "keys %fh" resets the iterator that controls the behavior
> of "each". Instead of giving you the next key/value pair it gives you
> the first one again. That leads to the endless loop you're observing.
> Remove the line, then the loop will work as expected.
>
>> ########################################################################
>> #ouvre_fichier.pl
>> ########################################################################
>> !/usr/bin/perl
>> sub ouvre_fichier {
>> open ($F, $_[0]) || die "impossible d ouvrir le fichier : $!";
>> while($ligne =<$F>){
>> $str.= $ligne;
>> }
>> eval $str;
>> }
>> $f = 'test.dat';
>> while(1){
>> eval {
>> ouvre_fichier($f);#si ouvre fichier echoue, le programme ne se termine
>> pas };##et à mon avis c la dernier veleur utliser
>> last unless $@; #pas d erreur on sort de la boucle
>> print "$f est absent. entrez un nouveau nom de fichier $f";
>> chomp ($f = <STDIN>);
>> }
>>
>> 1
>> #######################################################################
>> #test.dat
>> #######################################################################
>> $Conf{XferMethod} = 'rsync';
>> $Conf{XferLogLevel} = '1';
>> $Conf{RSyncShareName} = '___1___';
>> $Conf{ClientNameAlias} = '___2___';
>
> From your usage the function ouvre_fichie() is supposed to set up
> a hash. As far as I can see without running it, it returns the
> single value "___2___", in an incredibly convoluted manner.
>
> Anno
I do not understand .ok any more while infinite. now only a key is turned
over, ___ 2___. at the time of eval of test.dat the last value used it is
my hash I think?. ouvre_fichier should return the hach in entirety
Perl main.pl
___ 2 ___ =>
it is the key or is the value ?
------------------------------
Date: Sun, 26 Aug 2007 21:08:51 +0800
From: Amy Lee <openlinuxsource@gmail.com>
Subject: Help: How to change PATH variable by array?
Message-Id: <pan.2007.08.26.13.08.50.74485@gmail.com>
Hi,
I make a Perl script to add a path in PATH variable of the .bash_profile.
Just like
PATH=/usr/java/jdk1.5.0_09/bin:$HOME/perl:$HOME/shell:$PATH:$HOME/bin
to be
PATH=/usr/local/vice:/usr/java/jdk1.5.0_09/bin:$HOME/perl:$HOME/shell:$PATH:$HOME/bin
There's my code:
$ADD="/usr/local/vice"
foreach $FILE (@ARGV)
{
open $IN, '<', $FILE;
while (<$IN>)
{
if (/PATH=/)
{
chomp;
s/PATH=/;
my @PATH=s/:/ /;
unshift @PATH, $ADD;
print $_;
}
}
close $IN;
}
But when I run this script, it still displays
/usr/java/jdk1.5.0_09/bin $HOME/perl $HOME/shell $PATH $HOME/bin
Could you tell me how to solve this problem?
Thank very much~
Regards,
Amy Lee
------------------------------
Date: Sun, 26 Aug 2007 09:10:34 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Help: How to change PATH variable by array?
Message-Id: <slrnfd32eq.jrm.tadmc@tadmc30.sbcglobal.net>
Amy Lee <openlinuxsource@gmail.com> wrote:
> I make a Perl script to add a path in PATH variable of the .bash_profile.
> Just like
>
> PATH=/usr/java/jdk1.5.0_09/bin:$HOME/perl:$HOME/shell:$PATH:$HOME/bin
>
> to be
>
> PATH=/usr/local/vice:/usr/java/jdk1.5.0_09/bin:$HOME/perl:$HOME/shell:$PATH:$HOME/bin
# untested
perl -p -i.bak -e 's#PATH=#PATH=/usr/local/vice:#' .bash_profile
> There's my code:
If you say so.
> $ADD="/usr/local/vice"
Syntax error. No semicolon.
> foreach $FILE (@ARGV)
> {
> open $IN, '<', $FILE;
You should always, yes *always*, check the return value from open():
open $IN, '<', $FILE or die "coulde not opne '$FILE' $!";
> while (<$IN>)
> {
> if (/PATH=/)
> {
> chomp;
> s/PATH=/;
Another syntax error. There are 2 parts to a s/// operator.
This clearly is NOT your code.
> my @PATH=s/:/ /;
@PATH now contains 1 element, whose value is 1.
I doubt that that is what you want. Maybe you wanted to split
on colons instead:
my @PATH = split /:/;
> unshift @PATH, $ADD;
> print $_;
> }
> }
> close $IN;
> }
>
> But when I run this script, it still displays
>
> /usr/java/jdk1.5.0_09/bin $HOME/perl $HOME/shell $PATH $HOME/bin
>
> Could you tell me how to solve this problem?
Start by showing us the code that you really have.
Have you seen the Posting Guidelines that are posted here frequently?
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Sun, 26 Aug 2007 04:42:17 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Sun Aug 26 2007
Message-Id: <JnD6EH.p1D@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
Alzabo-GUI-Mason-0.11
http://search.cpan.org/~drolsky/Alzabo-GUI-Mason-0.11/
A GUI for Alzabo using Mason
----
Business-ISBN-2.02_02
http://search.cpan.org/~bdfoy/Business-ISBN-2.02_02/
work with International Standard Book Numbers
----
Business-KontoCheck-2.3
http://search.cpan.org/~michel/Business-KontoCheck-2.3/
Perl extension for checking German and Austrian Bank Account Numbers
----
CGI-Application-Plugin-Mason-1.00
http://search.cpan.org/~holly/CGI-Application-Plugin-Mason-1.00/
HTML::Mason plugin for CGI::Application
----
Class-Data-Annotated-0.1
http://search.cpan.org/~zaphar/Class-Data-Annotated-0.1/
Data::Annotated wrapped objects
----
DBIx-Admin-CreateTable-1.04
http://search.cpan.org/~rsavage/DBIx-Admin-CreateTable-1.04/
A module for creating and dropping tables and sequences
----
Data-Annotated-0.02
http://search.cpan.org/~zaphar/Data-Annotated-0.02/
Data structure Annotation module
----
File-HomeDir-0.66
http://search.cpan.org/~adamk/File-HomeDir-0.66/
Find your home and other directories, on any platform
----
Games-RolePlay-MapGen-1.0.1
http://search.cpan.org/~jettero/Games-RolePlay-MapGen-1.0.1/
The base object for generating dungeons and maps
----
OCR-Naive-0.03
http://search.cpan.org/~karasik/OCR-Naive-0.03/
convert images into text in a extremely naive fashion
----
POE-Component-Server-IRC-1.18
http://search.cpan.org/~bingos/POE-Component-Server-IRC-1.18/
A fully event-driven networkable IRC server daemon module.
----
Path-Resource-0.06
http://search.cpan.org/~rkrimen/Path-Resource-0.06/
URI/Path::Class combination.
----
Pod-Simple-Wiki-0.08
http://search.cpan.org/~jmcnamara/Pod-Simple-Wiki-0.08/
A class for creating Pod to Wiki filters.
----
Prima-prigraph-win32-1.01
http://search.cpan.org/~karasik/Prima-prigraph-win32-1.01/
binary prigraph.dll distribution for win32
----
Regexp-Exhaustive-0.01
http://search.cpan.org/~lodin/Regexp-Exhaustive-0.01/
Find all possible matches, including backtracked and overlapping, of a pattern against a string
----
Test-Tester-0.105
http://search.cpan.org/~fdaly/Test-Tester-0.105/
Ease testing test modules built with Test::Builder
----
Wx-Demo-0.09
http://search.cpan.org/~mbarbon/Wx-Demo-0.09/
the wxPerl demo
----
v6-0.019
http://search.cpan.org/~fglock/v6-0.019/
An experimental Perl 6 implementation
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Sun, 26 Aug 2007 21:07:02 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: Program Dies after 60 or so Iterations of Loop
Message-Id: <46d15ed0$0$13999$afc38c87@news.optusnet.com.au>
"Hal Vaughan" <hal@thresholddigital.com> wrote in message
news:i-KdnWQuLpP_T03bnZ2dneKdnZydnZ2d@comcast.com...
.
.
> .... then the program stops with
> a "Killed!" statement.
That's not something that would be coming from perl (afaik).
Sounds more like something that the OS is doing.
Does your ISP impose any limits that may be coming into play ?
Cheers,
Rob
------------------------------
Date: Sun, 26 Aug 2007 13:44:10 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Program Dies after 60 or so Iterations of Loop
Message-Id: <slrnfd2psa.9bd.hjp-usenet2@zeno.hjp.at>
On 2007-08-26 01:07, Hal Vaughan <hal@thresholddigital.com> wrote:
> I found the old time radio shows a the Interet Archives, so I wrote a
> program to scan the shows, then the episodes and let me list the ones I
> wanted to download. The program then goes through the list of files and
> downloads each file (most are MP3, some are Ogg). Files are at least a few
> megabytes in length. The problem is that after about 60 or so downloads
> (it varies), my computer (running Linux, Ubuntu Fiesty Fawn) slows down for
> about 30 minutes (not an exaggeration), then the program stops with
> a "Killed!" statement.
That sounds like you are exhausting virtual memory. When the total
memory used by all processes approaches the sum of RAM and swap space,
the system spends more and more time to finding yet another piece of
memory it doesn't need immediately and could reuse. If you are unlucky,
the system becomes completely unresponsive. However, most of the time
the system just gives up at some point and kills a process (hopefully
the one which caused this sorry state).
Run "top" in a second window to confirm this.
> #Download the file with WWW::Mechanize
> #Isn't $data reinitialized each loop? Could old copies not be cleared
> #by garbage collector?
> $data = getpage($url);
$data is reinitialized, but WWW::Mechanize may cache downloaded
documents. I vaguely remember that this has been discussed here before
and that there is a way to turn this off even though perldoc
WWW::Mechanize doesn't seem to mention it. Google should find it.
If all else fails, you can use lower level packages like LWP::UserAgent
to do the heavy lifting.
hp
--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | hjp@hjp.at |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"
------------------------------
Date: Sun, 26 Aug 2007 04:18:20 -0000
From: usenet@DavidFilmer.com
Subject: Searching within the hash values of an array of hashes
Message-Id: <1188101900.026118.176930@x40g2000prg.googlegroups.com>
I have an array of hashes that looks like this:
my @media = (
{
'Name' => 'foo'
'Format' => 'mp3',
},
{
'Name' => 'bar'
'Format' => 'ogg',
},
{
'Name' => 'baz'
'Format' => 'wav',
},
);
I want to know if I have any ogg formatted media. If this was a plain
hash then it would be simple to grep the values. Is there a way I can
do something simple like this on this AoH so I don't have to use a for
loop or something to iterate over the array?
Thanks!
--
David Filmer (http://DavidFilmer.com)
------------------------------
Date: 26 Aug 2007 04:55:21 GMT
From: xhoster@gmail.com
Subject: Re: Searching within the hash values of an array of hashes
Message-Id: <20070826005525.116$fa@newsreader.com>
usenet@DavidFilmer.com wrote:
> I have an array of hashes that looks like this:
> my @media = (
> {
> 'Name' => 'foo'
Missing comma at eol.
> 'Format' => 'mp3',
> },
> {
> 'Name' => 'bar'
> 'Format' => 'ogg',
> },
> {
> 'Name' => 'baz'
> 'Format' => 'wav',
> },
> );
>
> I want to know if I have any ogg formatted media.
print "have ogg" if grep $_->{Format} eq 'ogg', @media;
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Sun, 26 Aug 2007 18:03:13 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Symrefs
Message-Id: <hbo8q4-bbb.ln1@osiris.mauzo.dyndns.org>
Quoth "Petr Vileta" <stoupa@practisoft.cz>:
> Ben Morrow wrote:
> > Quoth "Petr Vileta" <stoupa@practisoft.cz>:
> >>
> > I don't understand why your subs need to be in a symbol table at all.
> > Why can't you just store them directly in the dispatch table? Then you
> > don't need to worry about quoting the names.
> >
> > my %dispatch = (
> >
> > 'www.france.weather.fr' => sub { ... },
> >
>
> Because:
>
> my %dispatch = (
> 'www.france-weather.fr' =>sub {100 - 500 lines of code}
> ...
> :-)
How is this either more or less readable than
sub www_france_weather_fr {
# 100--500 lines of code
}
? Separate your subs out properly into bits (I'm sure a lot of them have
large sections in common), and define those bits as named subs. Then
buid the subs in the dispatch table from the bits.
Ben
--
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ ben@morrow.me.uk ~ Jorge Luis Borges, 'The Babylon Lottery'
------------------------------
Date: Sun, 26 Aug 2007 18:09:40 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Symrefs
Message-Id: <kno8q4-bbb.ln1@osiris.mauzo.dyndns.org>
Quoth Brian McCauley <nobull67@gmail.com>:
> On Aug 23, 2:33 pm, Ben Morrow <b...@morrow.me.uk> wrote:
>
> > I don't understand why your subs need to be in a symbol table at all.
> > Why can't you just store them directly in the dispatch table?
>
> Anonymous functions are a pain in the backtrace.
#!/usr/bin/perl
use strict;
use warnings;
use Carp qw/confess/;
use Sub::Name qw/subname/;
my %dispatch = (
'www.france-weather.fr' => sub { confess "error"; },
);
subname $_, $dispatch{$_} for keys %dispatch;
$dispatch{'www.france-weather.fr'}->();
__END__
~/src/perl% perl subname
error at subname line 10
main::www.france-weather.fr() called at subname line 15
Ben
--
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes, [ Heracles shoots Vulture with arrow. Vulture bursts into ]
'Alcestis') [ flame, and falls out of sight. ] ben@morrow.me.uk
------------------------------
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 796
**************************************