[21804] in Perl-Users-Digest
Perl-Users Digest, Issue: 4008 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 22 00:06:20 2002
Date: Mon, 21 Oct 2002 21:05:11 -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 Mon, 21 Oct 2002 Volume: 10 Number: 4008
Today's topics:
Re: [REPOST] Need advice on a project (wrt to tie'ing t (Tad McClellan)
Re: Calling Subroutines (aka ? the Platypus)
Re: Calling Subroutines <goldbb2@earthlink.net>
Re: dynamically named arrays <jkeen@concentric.net>
Re: eval, I think <goldbb2@earthlink.net>
Re: format to output <wksmith@optonline.net>
Re: how to call java in perl? <goldbb2@earthlink.net>
How to capture all stderr and stdout for logging? <chris@home.com>
Re: How to use flock properly? <krahnj@acm.org>
Re: How to use flock properly? <garry@ifr.zvolve.net>
Installing Digest::MD5 on Linux Box, libgdbm.3.so, erro <cmustard@nyc.rr.com>
Looking for perl book <Crackhead@mensa.org>
Re: Looking for perl book <krahnj@acm.org>
Re: lost - map { "$_:\t$h->{$_}[0]\n"} keys %$h (Tad McClellan)
Re: lost - map { "$_:\t$h->{$_}[0]\n"} keys %$h <goldbb2@earthlink.net>
Newbie: how to include a file from my webpage (Francesco Moi)
Re: Newbie: how to include a file from my webpage <Oakseer@attbi.com>
Re: opendir/readdir can't handle french characters: Wha (Jean Gagnon)
Re: opendir/readdir can't handle french characters: Wha <goldbb2@earthlink.net>
Re: Question about hash entries with two keys <goldbb2@earthlink.net>
Re: Sleep(1) is not returning ? <storys@NOSPAM.charter.net>
Where can I get threaded perl 5.8 binaries for cygwin? (Peter Steele)
Re: while loop to stop take #2 <mgjv@tradingpost.com.au>
XML-Parser and Expat <jaralston3@att.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 21 Oct 2002 16:09:19 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: [REPOST] Need advice on a project (wrt to tie'ing to a file and general strategy)
Message-Id: <slrnar8r7v.2c3.tadmc@magna.augustmail.com>
Michele Dondi <bik.mido@tiscalinet.it> wrote:
> Last week I posted the article pasted hereafter. Since I haven't
> received much feedback,
If the feedback answers the question, then a single followup is "enough".
Did the previous feedback not answer your question?
> I'm posting it again.
Why?
If what was suggested there won't work for you, then share why
it won't work for you.
> Sorry for any
> disturbance this might cause...
What do you hope to gain this time that didn't happen the first time?
>
>>If you don't mind the chance of two distinct files with the same filename
>>and checksum, and like to speed up your checksum computation significantly,
>>you might consider using CRC32. Correct me if I'm wrong, the collision
>>probability of CRC32 is 2^(-32) which is approximately one out of 4 billion
>>trials. Might be good enough for you application.
>
> Indeed it would be good enough for my application.
Looks like your problem has already been solved.
Is there something else that you meant to mention this time around?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 21 Oct 2002 22:28:36 GMT
From: "David Formosa (aka ? the Platypus)" <dformosa@dformosa.zeta.org.au>
Subject: Re: Calling Subroutines
Message-Id: <slrnar9037.s4g.dformosa@dformosa.zeta.org.au>
On 21 Oct 2002 21:26:00 GMT, Tassilo v. Parseval
<tassilo.parseval@post.rwth-aachen.de> wrote:
[...]
> There is nothing to fear about subroutines within subroutines, as long
> as you make them refer to a closure. Real subs wont nest properly, so
> don't try this:
>
> sub outer {
> ...
> sub inner {
> ...
> }
> inner(@args);
> }
I've had no problem with that type of construct. Have I been just
lucky? I have had trouble with the following, perl warns me about it.
sub outer {
...
my $middel = sub {
...
sub inner {
....
}
}
}
--
Please excuse my spelling as I suffer from agraphia. See
http://dformosa.zeta.org.au/~dformosa/Spelling.html to find out more.
Free the Memes.
------------------------------
Date: Mon, 21 Oct 2002 22:57:03 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Calling Subroutines
Message-Id: <3DB4BE7F.73C5347B@earthlink.net>
David Formosa (aka ? the Platypus) wrote:
>
> On 21 Oct 2002 21:26:00 GMT, Tassilo v. Parseval
> <tassilo.parseval@post.rwth-aachen.de> wrote:
> [...]
>
> > There is nothing to fear about subroutines within subroutines, as
> > long as you make them refer to a closure. Real subs wont nest
> > properly, so don't try this:
> >
> > sub outer {
> > ...
> > sub inner {
> > ...
> > }
> > inner(@args);
> > }
>
> I've had no problem with that type of construct. Have I been just
> lucky?
The problem with this type of construct come about only when if you have
some lexical variable declared inside of sub outer, and before sub
inner. If you don't do that, then there're no problems.
Eg, try this code:
sub outer {
my @x;
sub inner { push @x, 1; scalar @x }
return inner();
}
print outer, outer, outer;
It prints "123", which is probably not what you would expect.
Changing inner to an anonymous sub avoids the problem, and results in it
printing "111", as expected.
> I have had trouble with the following, perl warns me about it.
>
> sub outer {
> ...
> my $middel = sub {
> ...
> sub inner {
> ....
> }
> }
> }
>
> --
> Please excuse my spelling as I suffer from agraphia. See
> http://dformosa.zeta.org.au/~dformosa/Spelling.html to find out more.
> Free the Memes.
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: 22 Oct 2002 02:11:30 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: dynamically named arrays
Message-Id: <ap2c4i$bvd@dispatch.concentric.net>
"mostuff" <stuff@nowhere.com> wrote in message
news:n0Js9.235$P5.21954@nasal.pacific.net.au...
> i have a list of files that i'd like to put into an array. there are a
> number of different files each indentified by a 2 letter prefix. so the
> files might be call vs010101.000, ud010101.000, eq010101.000. at any other
> time there might a another type added. what i'd like to do is push
> modification times of each of those files into arrays for each type.
>
> so i might have
>
> for (@filetypes) {
> push(@$_modtime,$modtime);
> }
>
> or something like that. what i'd like to know if how i create an array
like
> that where the first 2 characters of the array are the type of file it is.
>
If I understand your problem correctly, I think you would do better with a
multi-dimensional hash rather than an array:
my %data = (
'vs' => {
'010101.000' => 'its_modtime',
'010101.001' => 'its_modtime',
...
},
'ud' => {
'010101.000' => 'its_modtime',
'010101.001' => 'its_modtime',
...
},
'eq' => {
'010101.000' => 'its_modtime',
'010101.001' => 'its_modtime',
...
},
);
A new file type would be represented by a new key in the top-level hash. To
enter data you could get the first and second level keys with a regex
something like:
my ($type, $file_no) =~ /^(\w\w)(.*)$/; # untested
then the assignment would be something like:
$data{$type}{$file_no} = 'its_modtime';
HTH
Jim Keenan
Brooklyn, NY
------------------------------
Date: Mon, 21 Oct 2002 23:14:08 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: eval, I think
Message-Id: <3DB4C280.AD965246@earthlink.net>
Brandon Metcalf wrote:
>
> I'm trying to do something like
>
> my $testop = $windows ? '-f' : '-l';
>
> $ret = 1 if $testop $link;
>
> But this obviously won't compile. I was thinking eval might help out
> here, but I can't seem to put anything together that works.
eval is overkill for this problem. Either do:
$ret = 1 if $windows ? -f $link : -l $link;
Or something like:
my $testop = $windows ? sub { -f shift() } : sub { -l shift() };
$ret = 1 if $testop->($link);
> I would rather have a pointer to the documentation where I can find a
> solution instead of just the solution. That is, just a hint will do.
perldoc -f sub
perldoc perlsub
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Tue, 22 Oct 2002 01:40:56 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: format to output
Message-Id: <I02t9.4065$A41.301@news4.srv.hcvlny.cv.net>
"Christian Caron" <nospam@nospam.org> wrote in message
news:ap1k0f$3g85@nrn2.NRCan.gc.ca...
> Hi everyone,
>
> If I execute that:
>
> #############
> #!/usr/bin/perl -w
>
> use strict;
>
> my $variable1 = "scalar_one";
> my @array1 = ("array1_one","array1_two","array1_three");
> my @array2 = ("array2_one","array2_two");
>
> format STDOUT =
> @<<<<<<<<<<<<<<<
> $variable1,
> @*
> @array1,
> @*
> @array2
> .
>
> write;
> #############
>
> I get:
>
> colargol# ./test.pl
> scalar_one
> array1_one
> array2_one
>
> I would like to get:
>
> scalar_one array1_one array2_one
> array1_two array2_two
> array1_three
>
> Is this possible? I tried all combination (multiline ~~ ^<<<<<<, etc.) but
I
> can't figure out a way to do that...
>
> Thanks!
>
>
You can get the desired output using the following code.
#!/usr/bin/perl -w
use strict;
my $variable1 = "scalar_one";
my @array1 = ("array1_one","array1_two","array1_three");
my @array2 = ("array2_one","array2_two");
format STDOUT =
@<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<
$variable1, $array1[0], $array2[0]
@<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<
$array1[1],$array2[1]
@<<<<<<<<<<<<<<<
@array1[2]
.
write;
I advise against using write/format unless you have a very strong reason for
it. (e.g. You need column headers on every page)
Bill
------------------------------
Date: Mon, 21 Oct 2002 22:32:24 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: how to call java in perl?
Message-Id: <3DB4B8B8.DF0CB936@earthlink.net>
Hong Liang wrote:
>
> Hi,
>
> can anyone present a somewhat full list of
> ways for calling other programs from Perl,
> such as Java class?
http://search.cpan.org/search?query=java&mode=all
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Tue, 22 Oct 2002 03:03:51 GMT
From: chris <chris@home.com>
Subject: How to capture all stderr and stdout for logging?
Message-Id: <h6f9ruospniu0sfh1as601dkcbuq1ft3sh@4ax.com>
I need to create a batch process to run a perl script. The script in
turn runs deeply nested child scripts. The main script is open with a
pipe | and I have to redirect stderr in each child script. This is
working.
Now the bacth process has reached a child script that I should not
modify. This child script will make use of a module that I wrote and I
am able to make changes at this level.
How do I capture all stderr and stdout from the parent for logging?
My batch execution goes like this
open ($fh ($cmd) | )
main script (need to log all stderr and std out from here)
---child script1 (redirect stderr)
------child script 2 (redirect stderr)
----------- child script 3 (cannot modify)
---------------my module (do I redirect stderr in each sub?)
------------------------------
Date: Mon, 21 Oct 2002 22:19:10 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: How to use flock properly?
Message-Id: <3DB47D74.DDC13558@acm.org>
"D. Alvarado" wrote:
>
> Hi, I'm running on Solaris 5.8 and I was having a problem getting
> flock to work the way I wanted. I have a single script, which looks
> like this:
>
> # Acquire the lock, or wait to acquire if another process holds it.
> open LOCK_FILE, "$LOCK_FILE";
> flock(LOCK_FILE, LOCK_EX);
>
> ... run program ...
>
> # Release the lock, let other scripts continue.
> flock(LOCK_FILE, LOCK_UN);
>
> The "run program" part takes about 20 seconds to run and I log the
> beginning and end times of the program execution. However, if I run 3
> separate instances of this script, they all start about 1 or 2 seconds
> after the other. I thought once one instance acquired the lock
> through flock, the other instances were forced to wait when they tried
> to acquire the lock through flock, but apparently I'm wrong.
>
> What should I do to get the desired behavior?
flock does not lock a read-only file, open the file for read/write to
lock it.
open LOCK_FILE, "+< $LOCK_FILE" or die "Cannot open $LOCK_FILE: $!";
flock LOCK_FILE, LOCK_EX;
John
--
use Perl;
program
fulfillment
------------------------------
Date: Mon, 21 Oct 2002 22:43:30 GMT
From: Garry Williams <garry@ifr.zvolve.net>
Subject: Re: How to use flock properly?
Message-Id: <slrnar90h4.lsr.garry@zfw.zvolve.net>
On 21 Oct 2002 14:20:49 -0700, D. Alvarado <laredotornado@zipmail.com> wrote:
> Hi, I'm running on Solaris 5.8 and I was having a problem getting
> flock to work the way I wanted. I have a single script, which looks
> like this:
>
> # Acquire the lock, or wait to acquire if another process holds it.
> open LOCK_FILE, "$LOCK_FILE";
^ ^
Those quotes are useless.
How do you know if this succeeded? Always check the result of open():
open LOCK_FILE, $LOCK_FILE
or die "can't open open $LOCK_FILE: $!\n";
> flock(LOCK_FILE, LOCK_EX);
How do you know if this succeeded? Always check the result of flock():
flock(LOCK_FILE, LOCK_EX)
or die "can't flock: $!\n";
I bet your problem would be revealed, if you made these changes.
[snip]
> I thought once one instance acquired the lock
> through flock,
How do you know that happened?
> What should I do to get the desired behavior?
I would check to see if the system calls I made were successful.
Another poster pointed out that this OS _requires_ a file to be opened
for update, if you want an exclusive lock.
--
Garry Williams
------------------------------
Date: Tue, 22 Oct 2002 02:30:56 GMT
From: coL mUstard <cmustard@nyc.rr.com>
Subject: Installing Digest::MD5 on Linux Box, libgdbm.3.so, error,...
Message-Id: <slrnar9e7j.14l.cmustard@nyc.rr.com>
I am trying to install some perl modules on a linux box, debian woody
3.0 2.4.218 bf-2.4 the 'minimal' iso install package.
The perl modules i am really trying to install are the LWP modules by
Gisle Aas.These libwww modules have several dependancies which must be
installed first. All the the pre-req mods installed fine, except for:
Digest::MD5, i have tried via the `auto CPAN' and manually, each produces
the same undesireable results. I have tried the current version (2.20
and the older version 2.16) both produce the same error message,...
Testing alignment requirements for U32... ./u32align: error while loading
shared libraries: libgdbm.so.3: cannot open shared object file: No such
file or directory
Test program exit status was 127
Writing Makefile for Digest::MD5
Originally, i recieved: `/usr/bin/ld: can't find -lgdbm' so i installed
the gdbm lib, then i tried again to make MD5 and got '/usr/bin/ld: can't
find -ldb, so i installed the db lib's,... and now the current error
message.
I have read the README and Bugs, and it doesn't appear anything is wrong
with this module, I do have libgdbm.2.so and below, why is it asking for
libgdbm.3.so?.
Is this a possible bug with the test file for digest::md5?
Should i go ahead and try to install MD5 with this error? - doesn't seem
to make sense if it won't compile.
any idea's greatly appreciated.
I appologize if this question is 'pushing' the bounds of this news list,
i'm not having much luck elsewhere. I don't know if it could be a 'debian'
issue, or 'perl' issue.
Please 'cc' me with any replies you may have.
Thanks.
--
I submit it is Colonol Mustard,... in the comp room,... with the pc,...
-mUstard
------------------------------
Date: Tue, 22 Oct 2002 02:25:03 GMT
From: Crackpot <Crackhead@mensa.org>
Subject: Looking for perl book
Message-Id: <Xns92AEC587CD0A8Crackheadmensaorg@204.127.68.17>
Hello all,
I'm looking for a book the will show how to use perl to help manage a
network. Is there one?
Thanks
------------------------------
Date: Tue, 22 Oct 2002 03:21:48 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Looking for perl book
Message-Id: <3DB4C461.4B4F64A6@acm.org>
Crackpot wrote:
>
> I'm looking for a book the will show how to use perl to help manage a
> network. Is there one?
http://www.awprofessional.com/catalog/product.asp?product_id={CF32E8D7-BEC2-4445-8B3E-964C1D8A7895}
http://www.oreilly.com/catalog/perlsysadm/
John
--
use Perl;
program
fulfillment
------------------------------
Date: Mon, 21 Oct 2002 17:55:05 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: lost - map { "$_:\t$h->{$_}[0]\n"} keys %$h
Message-Id: <slrnar91e9.2i9.tadmc@magna.augustmail.com>
Jerry Preston <g-preston1@ti.com> wrote:
>
> Can anyone explain to me how map works in this code?
> print map { "$_:\t$h->{$_}[0]\n"} keys %$h ;
> How can I access this and break it done to look at each line?
$h is a reference to a hash that contains arrays, ie. A HoL
multilevel data structure.
You can use the Data::Dumper module to see the contents of the HoL:
use Data::Dumper;
# $h gets populated here somehow
print Dumper $h;
"keys %$h" dereferences the reference and calls keys() on it,
which returns a list of the keys. So $_ in the map is a hash key.
So the print() above outputs:
a key ($_)
a colon
a tab
the first value in the array corresponding to the key
If you do not grok Perl's references and multilevel data
structures, then you have some reading to do if you must
understand what that code is doing:
perldoc perlreftut
perldoc perlref
perldoc perllol
perldoc perldsc
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 21 Oct 2002 21:26:50 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: lost - map { "$_:\t$h->{$_}[0]\n"} keys %$h
Message-Id: <3DB4A95A.559CA536@earthlink.net>
Jerry Preston wrote:
>
> Hi!
>
> Can anyone explain to me how map works in this code?
[snip stuff which summarizes to:
for my $h (stuff) {
]
> print map { "$_:\t$h->{$_}[0]\n"} keys %$h ;
> }
>
> How can I access this and break it done to look at each line?
First, figure out how it would be written with an ordinary for loop
instead of a map expression:
foreach $_ (keys %$h) {
print "$_:\t$h->{$_}[0]\n";
}
Second, for added clarity, replace $_ with a more meaningful variable
name. Since $_ and $h->{$_} are both used, you might also replace the
foreach loop with a while/each loop. In addition, changing the string
interpolation to explicit concatenation may also improve readability:
If I understand the comments in the original code correctly, each key,
value pair in %$h is the name of a header, and the values in the header.
while( my ($headername, $headervalues) = each %$h ) {
print $headername . ":\t" . $headervalues->[0] . "\n";
}
If you replaced $h with a more meaningful name, (perhaps $msgheaders),
both where you have 'for my $h (' and here, that too would help make it
clear.
Personally, I wouldn't print just the first ( ->[0] ) element of the
values for each header, but all of them:
while( my ($headername, $headervalues) = each %$h ) {
print $headername . ":\t" . $_ . "\n" for @$headervalues;
}
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: 21 Oct 2002 15:12:11 -0700
From: francescomoi@europe.com (Francesco Moi)
Subject: Newbie: how to include a file from my webpage
Message-Id: <5b829932.0210211412.269ab263@posting.google.com>
Hello.
I'm a PHP user, and I use 'include' command in order to build my webpages:
include 'header.php';
include 'body.php'; ....
Does any similiar Perl command exist?
Thank you very much.
------------------------------
Date: Tue, 22 Oct 2002 00:37:32 GMT
From: "Oakseer@attbi.com" <Oakseer@attbi.com>
Subject: Re: Newbie: how to include a file from my webpage
Message-Id: <3DB49E70.EF4B537B@attbi.com>
I believe the equivalent would be "require":
require "somefile";
Francesco Moi wrote:
> Hello.
>
> I'm a PHP user, and I use 'include' command in order to build my webpages:
>
> include 'header.php';
> include 'body.php'; ....
>
> Does any similiar Perl command exist?
>
> Thank you very much.
------------------------------
Date: 21 Oct 2002 16:58:11 -0700
From: jeannot@gmavt.net (Jean Gagnon)
Subject: Re: opendir/readdir can't handle french characters: What am I missing?
Message-Id: <981d6b93.0210211558.20c4c502@posting.google.com>
> Jean Gagnon wrote:
> >
> > Please forgive me if that's an obvious one, but as the title says, if
> > I do an opendir and then a readdir, a directory named "déménagement"
> > will show as "d8m8nagement". Can Perl handle these, am I missing a use
> > statement, or a runtime switch?
> Yes, perl can handle these. Did you get an error message when you tried
> it?
>
> John
Not at all John, no error message whatsoever.
========= Here is my code: ================
use strict;
my $directory = "c:\\tmp";
opendir( ZEDIR, $directory );
my @files = readdir ZEDIR;
closedir( ZEDIR );
foreach( @files )
{
print "Processing $_\n";
}
======= input (output from a dir command: the actual file name)
=========
01/18/2002 02:44p 9,694,520 La Compagnie Créole - Ma première
biguine
partie.mp3
======= output generated by the Perl code above: =============
Processing La Compagnie CrΘole - Ma premiΦre biguine
partie.mp3
================================================
The nuisances appear between the "Cr" and the "ole", and again between
the "premi" and the "re", and are not a copy&paste artifact, except
that
the first funny character is output as an "8" in the console, but
appears
as a capital "O" with a pair of eyes in it as I pasted it here, in the
"compose your message" Google screen.
Jean
------------------------------
Date: Mon, 21 Oct 2002 23:08:40 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: opendir/readdir can't handle french characters: What am I missing?
Message-Id: <3DB4C138.4CEB63E1@earthlink.net>
Jean Gagnon wrote:
>
> > Jean Gagnon wrote:
> > >
> > > Please forgive me if that's an obvious one, but as the title says,
> > > if I do an opendir and then a readdir, a directory named
> > > "déménagement" will show as "d8m8nagement". Can Perl handle these,
> > > am I missing a use statement, or a runtime switch?
>
> > Yes, perl can handle these. Did you get an error message when you
> > tried it?
> >
> > John
>
> Not at all John, no error message whatsoever.
>
> ========= Here is my code: ================
>
> use strict;
>
> my $directory = "c:\\tmp";
> opendir( ZEDIR, $directory );
> my @files = readdir ZEDIR;
> closedir( ZEDIR );
>
> foreach( @files )
> {
> print "Processing $_\n";
> }
>
> ====== input (output from a dir command: the actual file name) ======
>
> 01/18/2002 02:44p 9,694,520 La Compagnie Créole - Ma première
> biguine partie.mp3
>
> ======= output generated by the Perl code above: =============
>
> Processing La Compagnie CrΘole - Ma premiΦre biguine
> partie.mp3
>
> ================================================
>
> The nuisances appear between the "Cr" and the "ole", and again between
> the "premi" and the "re", and are not a copy&paste artifact, except
> that the first funny character is output as an "8" in the console, but
> appears as a capital "O" with a pair of eyes in it as I pasted it
> here, in the "compose your message" Google screen.
Try doing this, and telling us the output:
foreach( @files ) {
s/([^\0-\127])/
sprint '\\x{%X}', ord $1
/ge;
print "Processing $_\n";
}
Anyway... the problem probably arises from one of two sources: One
possibility is readdir() might be truncating wide characters to eight
bit characters, and losing information. The other is that when
outputting the data, perl prints in the wrong encoding. There may be
other reasons, but those are what I can think of.
If perl is using the wrong encoding for output, then you can probably
fix the problem with the Encode.pm module, available from CPAN.
If perl is mangling the strings from readdir, then there probably isn't
any way of fixing it, except perhaps to upgrade to 5.8.0, which might or
might not work.
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Mon, 21 Oct 2002 23:28:20 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Question about hash entries with two keys
Message-Id: <3DB4C5D4.9CDD4CE9@earthlink.net>
Tassilo v. Parseval wrote:
> Also sprach J. Romano:
[snip]
> > Fortunately, Perl can handle this. If I want to give my student
> > Bob a 95% in Math class and a 90% in Social Studies, I can write:
> >
> > $grades{"bob","math"} = 95;
> > $grades{"bob","social studies"} = 90;
> >
> > If I wish to extract and view an entry from the %grades hash
> > table, I can type:
> >
> > ($key,$value) = each(%grades);
> > print "\$key = $key \$value = $value\n";
> >
> > which gives output like the following:
> >
> > $key = bobmath $value = 95
> > $firstKey = bob $secondKey = math
> >
> > I remember reading in a Perl book that Perl manages two-key hash
> > entries by concatenating the keys together with a special character.
>
> Yes, true. I heard that \0 is used for that.
They are concatentated together with $;, which by default, has a value
of "\034".
> > This is apparent in the above output, when we see that the key is
> > set to "bobmath".
> >
> > My question is: how do I extract both keys from that entry, so
> > that I can have "bob" in one variable, and "math" in another?
Like this:
my ($firstkey, $secondkey) = split /\Q$;\E/, $key;
> > It's not like I can split those values out very easily, because I
> > don't normally type the "" character. Even if I did, I couldn't be
> > sure that all versions of Perl use that character to concatenate the
> > two keys, so my program might not be portable.
Firstly, all versions of perl *do* use the "\034" character for $;, or
at least, the $; variable *starts out* as "\034" ... someone might go
and change it later on, producing action-at-a-distance, a common problem
that can arise from things controlled by global variables.
The real problem isn't portability, but that you might have a binary
string which happens to contain "\034" in it. Or similarly, if your
data comes from another language, which uses "\034" as an ordinary
character...
Or, just as bad, $; has one value at one time, and then someone else's
code goes and changes it.
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Mon, 21 Oct 2002 22:51:15 -0400
From: "Lenny Story" <storys@NOSPAM.charter.net>
Subject: Re: Sleep(1) is not returning ?
Message-Id: <ur9f98etvsvg02@corp.supernews.com>
Greetings,
I figured it would be something more complicated. Like a bug in perl or
something of that order. Perhaps even a module bug, but not my own.
Unfortunately i assumed an error on someone elses part first, rather than my
own.
So when i read the response, it was one of those "lightbulb"
moments...fortunately
the humbling kind.
8^)
-Lenny
"Gregory Toomey" <nobody@nowhere.com> wrote in message
news:9Z5s9.56583$g9.162471@newsfeeds.bigpond.com...
> Lenny Story wrote in message ...
> >Greetings,
> >
> >Hmm...well, your right...It works now..Surprising....that wasn't the
> >answer i expected.
> >
> >Bodo, thank you for the response.
> >-Lenny
> >
> It's the right answer. What did you expect?
>
> gtoomey
>
>
------------------------------
Date: 21 Oct 2002 17:56:40 -0700
From: pwsteele@bigfoot.com (Peter Steele)
Subject: Where can I get threaded perl 5.8 binaries for cygwin?
Message-Id: <7deee002.0210211656.25e4402e@posting.google.com>
The subject says it all. I downloaded one build already but it didn't
have thread support. Where can I get a version with support for the
new 5.8 threads features.
Peter Steele
------------------------------
Date: Tue, 22 Oct 2002 00:01:28 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: while loop to stop take #2
Message-Id: <slrnar95di.kud.mgjv@verbruggen.comdyn.com.au>
On Mon, 21 Oct 2002 12:02:27 -0400,
Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote:
> On Mon, 21 Oct 2002, Michael Budash wrote:
>
>>In article
>><Pine.A41.3.96.1021021111125.54190E-100000@vcmr-104.server.rpi.edu>,
>> Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote:
>>
>>> while (<FH>) { ... } # populates $_
>>> while (<FH> && $this) { ... } # does not populate $_
>>
>>thanks jeff... i missed that! (and i'll bet a few more of us did, too)
>
> In a related note, this does populate $_:
>
> while (<FH> && 1) { ... }
>
> but that's because of Perl's hunky-dory constant folding.
Hmm...
$ perl5.6.1 -MO=Deparse -e 'while (<FH>) { print }'
while (defined($_ = <FH>)) {
print $_;
}
-e syntax OK
$ perl5.6.1 -MO=Deparse -e 'while (<FH> && 1) { print }'
while (<FH> and 1) {
print $_;
}
-e syntax OK
I get the same result on 5.00503 and 5.8.0. Checking the output of the
little programs above also shows me that the behaviour is different.
The output of the same programs with 5.00405 is also different from
each other (no Deparse installed for 5.004).
Martien
--
|
Martien Verbruggen |
Trading Post Australia | 42.6% of statistics is made up on the spot.
|
------------------------------
Date: Mon, 21 Oct 2002 23:43:50 GMT
From: "John Ralston" <jaralston3@att.net>
Subject: XML-Parser and Expat
Message-Id: <Wi0t9.21975$Pk1.5159@nwrddc02.gnilink.net>
I'm a perl newbie and don't understand modules and dependencies very well,
yet. I'm trying to install XML-Parser-2.31 on a Win98 system with ActivePerl
5.6.0 installed. I've done a number of builds and installs, so I'm not
totally sure where all the various files I'll describe came from.
I installed expat ver. 1.95.5 and copied expat.h, libexpat.dll and
libexpat.lib to \perl\site\lib and referenced them in making parser.pm.
Somewhere along the line, something created a folder
\perl\site\lib\auto\XML\parser\expat and put expat.dll in it.
I've made and installed parser.pm and expat.pm from the XML-Parser-2.31
package (bundle?). parser.pm is in \perl\site\lib\XML and expat.pm is in
\perl\site\lib\XML\parser. At an early point, I was getting an error that
the version of parser.pm and expat.pm didn't match and I found that the copy
of expat.pm in \perl\site\lib\XML\parser was 2.27. I hadn't paid attention
to how that file got there. So I replaced it with expat.pm from the
XML-Parser build, which carries version number 2.31, same as parser.pm.
Now when I run "perl xmlcomments" to test XML-Parser, I get an error:
"XML::Parser::Expat object version 2.27 does not match bootstrap parameter
2.31 at e:\perl\lib\dynaloader.pm line 225".
Looking into expat docs, I saw something about expat.dll having to be
renamed libexpat.dll in Win systems. From dynaloader.pm and autoloader.pm, I
saw that \perl\site\lib\auto\XML\parser\expat]expat.dll was being loaded
automatically, so I prevented it by renaming the directory. Now when I run
"perl xmlcomments", I get the error:
"Can't find 'boot_XML_Parser_Expat' symbol in
e:\perl\site\lib\libexpat.dll". From this, I assume that expat.dll a
necessary dependency.
For one thing, there are too many expat's floating around, some C libraries,
some perl modules. I can't figure out what's real and what isn't.
But back to that "object version" error. The error is being thrown in
dynaloader.pm where it is calling dl_install_xsub("XML::Parser::Expat
2.31"). dynaloader docs say this is a C routine, but I don't know where to
look for it. Where is it picking up the version 2.27 reference? Where else
would it be looking for Expat objects other than in expat.pm?
Clearly something is left over from that original v2.27 of expat.pm that I
found and replaced in \perl\site\lib\XML\parser. But what could it be?
I'd appreciate any additional information on just what files need to be
installed for XML::Parser to work. And any advice on resolving this version
issue.
tia
John
------------------------------
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 4008
***************************************