[21806] in Perl-Users-Digest
Perl-Users Digest, Issue: 4010 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 22 14:07:31 2002
Date: Tue, 22 Oct 2002 11:05:12 -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 Tue, 22 Oct 2002 Volume: 10 Number: 4010
Today's topics:
Re: Array List Output (BUCK NAKED1)
Re: deleting a file... kill ??? Thanks... <gldouce@nbnet.nb.ca>
deleting a file... kill ??? <gldouce@nbnet.nb.ca>
Re: deleting a file... kill ??? <Graham.T.Wood@oracle.com>
Re: deleting a file... kill ??? (Helgi Briem)
Re: deleting a file... kill ??? <mjcarman@mchsi.com>
Re: deleting a file... kill ??? <johngnub@worldnet.att.net>
Re: format to output <nospam@nospam.org>
Hiding password variables in PERL (Marc Pelletier)
Re: Hiding password variables in PERL <nobull@mail.com>
How does @EXPORT function in a package? <richard@zync.co.uk>
Re: How does @EXPORT function in a package? <comdog@panix.com>
Re: how to call java in perl? (Chris)
Re: how to call java in perl? <mmanso@prodigio.com>
open(STDOUT, ">/dev/null") successful but still get STD (S E H M B)
Re: opendir/readdir can't handle french characters: Wha (Jean Gagnon)
Re: opendir/readdir can't handle french characters: Wha <nospam@nospam.org>
Perl Program (Aryan)
Re: Perl Program <nobull@mail.com>
PHP to Perl translation <anthony.heuveline@wanadoo.fr>
Re: PHP to Perl translation <bryan@akanta.com>
Re: Question about hash entries with two keys (J. Romano)
Re: Question about hash entries with two keys <uri@stemsystems.com>
Re: regular expression to extract the path name (Helgi Briem)
Re: regular expression to extract the path name <depesz@depesz.pl>
Re: regular expression to extract the path name <jurgenex@hotmail.com>
Re: regular expression to extract the path name <johngnub@worldnet.att.net>
warnings::register and inheritance <heather710101@yahoo.com>
Re: warnings::register and inheritance <nobull@mail.com>
Writing Microsoft Outlook Notes With Perl (Chris)
ypur//warning perl 58 <serge.john.swilting@wanadoo.fr>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 22 Oct 2002 07:56:56 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: Array List Output
Message-Id: <16333-3DB54B18-203@storefull-2276.public.lawson.webtv.net>
I guarantee you this wasn't a homework assignment. <smile> I'm an old
man here.
I really appreciate the help. I have been popping, joining, foreaching,
whiling, splitting, grepping, and mapping for a week trying to figure
this out... in addition to reading perldocs and searching for help.
Thank You So Much,
--Dennis
------------------------------
Date: Tue, 22 Oct 2002 15:30:48 GMT
From: "G.Doucet" <gldouce@nbnet.nb.ca>
Subject: Re: deleting a file... kill ??? Thanks...
Message-Id: <3DB56F34.18A37D3C@nbnet.nb.ca>
Sure enough, I flipped throught the pages of my book and found UNLINK which
states:
This function deletes the files in the list and returns the number of
files deleted.
I have absolutely no idea where or how I came up with the kill statement.
PS.
Wouldn't you think that my book's index would have had an entry on deleting
files?
Anyway, I penciled that in the index myself for future reference.
Thanks for everything people!
Guy Doucet
"G.Doucet" wrote:
> I was updating a perl script that I wrote last year. The Perl script
> reads and writes to a few database files which are just simple text
> files. At one point, the perl script deletes an old file which goes
> something like this:
>
> if(-e "$obidfil"){kill $obidfil;}
>
> I wanted to know if I could tell whether the command was able to delete
> the file, or whether there would be an error. So I decided to read up on
> the kill function in my old Perl book "Using Perl 5 for web
> programming". As I read this (which I printed below), I was thinking
> that either there is a mistake in my book, or the kill statement does
> something other than deleting a file.
>
> | KILL
> | Syntax: list operator (process)
> | Arguments: signal, list
> | Return Value: 1 (true) '' (false)
> | This function kills the processes with the pids in the supplied list
> by sending the signal level specified.
> | If the signal level is negative, the process groups are killed.
>
> I just want to make sure that I am using the correct function to delete
> a file.
> Does anyone understand that jargon?
>
> Guy Doucet
------------------------------
Date: Tue, 22 Oct 2002 13:56:36 GMT
From: "G.Doucet" <gldouce@nbnet.nb.ca>
Subject: deleting a file... kill ???
Message-Id: <3DB55928.B980AE2E@nbnet.nb.ca>
I was updating a perl script that I wrote last year. The Perl script
reads and writes to a few database files which are just simple text
files. At one point, the perl script deletes an old file which goes
something like this:
if(-e "$obidfil"){kill $obidfil;}
I wanted to know if I could tell whether the command was able to delete
the file, or whether there would be an error. So I decided to read up on
the kill function in my old Perl book "Using Perl 5 for web
programming". As I read this (which I printed below), I was thinking
that either there is a mistake in my book, or the kill statement does
something other than deleting a file.
| KILL
| Syntax: list operator (process)
| Arguments: signal, list
| Return Value: 1 (true) '' (false)
| This function kills the processes with the pids in the supplied list
by sending the signal level specified.
| If the signal level is negative, the process groups are killed.
I just want to make sure that I am using the correct function to delete
a file.
Does anyone understand that jargon?
Guy Doucet
------------------------------
Date: Tue, 22 Oct 2002 15:14:05 +0100
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: deleting a file... kill ???
Message-Id: <3DB55D2D.15094732@oracle.com>
"G.Doucet" wrote:
> I was updating a perl script that I wrote last year. The Perl script
> reads and writes to a few database files which are just simple text
> files. At one point, the perl script deletes an old file which goes
> something like this:
>
> if(-e "$obidfil"){kill $obidfil;}
>
> I wanted to know if I could tell whether the command was able to delete
> the file, or whether there would be an error. So I decided to read up on
> the kill function in my old Perl book "Using Perl 5 for web
> programming". As I read this (which I printed below), I was thinking
> that either there is a mistake in my book, or the kill statement does
> something other than deleting a file.
>
> | KILL
> | Syntax: list operator (process)
> | Arguments: signal, list
> | Return Value: 1 (true) '' (false)
> | This function kills the processes with the pids in the supplied list
> by sending the signal level specified.
> | If the signal level is negative, the process groups are killed.
>
> I just want to make sure that I am using the correct function to delete
> a file.
> Does anyone understand that jargon?
>
> Guy Doucet
Kill is for killing processes not for deleting files. unlink will delete a
file. Maybe the filename is the same as the id of a process that locks the
file while it is running so that killing the process will mean the file can
be deleted by some other process. Just wildly guessing though. Maybe some
more of the script would make things clearer. So would the exact statement
rather than "something like this".
Graham Wood
------------------------------
Date: Tue, 22 Oct 2002 14:14:58 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: deleting a file... kill ???
Message-Id: <3db55c74.557950179@news.cis.dfn.de>
On Tue, 22 Oct 2002 13:56:36 GMT, "G.Doucet"
<gldouce@nbnet.nb.ca> wrote:
>I was updating a perl script that I wrote last year. The Perl script
>reads and writes to a few database files which are just simple text
>files. At one point, the perl script deletes an old file which goes
>something like this:
>
> if(-e "$obidfil"){kill $obidfil;}
>
<SNIP>
kill is for stopping processes, not deleting files.
Your statement above will never do anything.
To delete a file you use the unlink function
(see perldoc -f unlink).
if (-e $obidfil)
{ unlink $obidfil or warn: Cannot delete $obidfil:$!\n"; }
--
Regards, Helgi Briem
helgi AT decode DOT is
A: Top posting
Q: What is the most irritating thing on Usenet?
- "Gordon" on apihna
------------------------------
Date: Tue, 22 Oct 2002 09:45:45 -0500
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: deleting a file... kill ???
Message-Id: <ap3oa9$6q42@onews.collins.rockwell.com>
On 10/22/02 8:56 AM, G.Doucet wrote:
>
> At one point, the perl script deletes an old file which goes
> something like this:
>
> if(-e "$obidfil"){kill $obidfil;}
>
> I wanted to know if I could tell whether the command was able to delete
> the file, or whether there would be an error. So I decided to read up on
> the kill function in my old Perl book "Using Perl 5 for web
> programming".
If you want to know what a Perl function does, you should consult the
*Perl* documentation, not a third-party book.
perldoc -f kill
kill SIGNAL, LIST
Sends a signal to a list of processes. [...]
> I just want to make sure that I am using the correct function to delete
> a file.
You are not. You want to use unlink() instead.
-mjc
------------------------------
Date: Tue, 22 Oct 2002 16:51:07 GMT
From: "john bennett" <johngnub@worldnet.att.net>
Subject: Re: deleting a file... kill ???
Message-Id: <%lft9.22060$1P1.1387304@bgtnsc05-news.ops.worldnet.att.net>
JB is not to familar with the "Kill" function, but to
remove a file I have used the unlink function.
Besure and look in the perldoc pages for the unlink function.
2 Cents JB.
G.Doucet <gldouce@nbnet.nb.ca> wrote in message
news:3DB55928.B980AE2E@nbnet.nb.ca...
> I was updating a perl script that I wrote last year. The Perl script
> reads and writes to a few database files which are just simple text
> files. At one point, the perl script deletes an old file which goes
> something like this:
>
> if(-e "$obidfil"){kill $obidfil;}
>
> I wanted to know if I could tell whether the command was able to delete
> the file, or whether there would be an error. So I decided to read up on
> the kill function in my old Perl book "Using Perl 5 for web
> programming". As I read this (which I printed below), I was thinking
> that either there is a mistake in my book, or the kill statement does
> something other than deleting a file.
>
> | KILL
> | Syntax: list operator (process)
> | Arguments: signal, list
> | Return Value: 1 (true) '' (false)
> | This function kills the processes with the pids in the supplied list
> by sending the signal level specified.
> | If the signal level is negative, the process groups are killed.
>
> I just want to make sure that I am using the correct function to delete
> a file.
> Does anyone understand that jargon?
>
> Guy Doucet
>
>
------------------------------
Date: Tue, 22 Oct 2002 11:23:58 -0400
From: "Christian Caron" <nospam@nospam.org>
Subject: Re: format to output
Message-Id: <ap3qie$3nj4@nrn2.NRCan.gc.ca>
"Bill Smith" <wksmith@optonline.net> wrote in message
news: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,
> > I would like to get:
> >
> > scalar_one array1_one array2_one
> > array1_two array2_two
> > array1_three
> >
>
> 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
>
>
Ok, your solution involves manual tinkering, but what if there are four
lines instead of 3 because arrays are created dynamically? It needs to be
automatic.
I found this solution (make variable an array, and loop for each line):
#############
#!/usr/bin/perl -w
use strict;
my @array1 = ("array1_one");
my @array2 = ("array2_one","array2_two","array2_three");
my @array3 = ("array3_one","array3_two");
# Find the longest array and assign its length to $v
# which I'm sure there's a solution that I'll find later...
# For the moment, I know it's @array2
my $array2_length = @array2;
my $v = $array2_length;
my $t;
for $t (0 .. $v) {
if (! $array1[$t]) {
$array1[$t] = " ";
}
if (! $array2[$t]) {
$array2[$t] = " ";
}
if (! $array3[$t]) {
$array3[$t] = " ";
}
write;
}
format STDOUT =
@<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<
$array1[$t], $array2[$t], $array3[$t]
.
#############
Prints out:
colargol# perl test.pl
array1_one array2_one array3_one
array2_two array3_two
array2_three
Why do you recommend not to use format/write?
------------------------------
Date: 22 Oct 2002 07:58:41 -0700
From: marcjgpelletier@hotmail.com (Marc Pelletier)
Subject: Hiding password variables in PERL
Message-Id: <96f58607.0210220658.1a037ce5@posting.google.com>
Alright, so here's the scoop .. wondering if anyone has ever come
across something like this. Looking for any advice or workarounds as
well.
I have a main PERL script (call it main.pl) which reads a
username/password file (call it nodes.txt), grabs these login details,
Telnet's to a switch, executes a few commands and logs out. Pretty
simple so far.
I've added two more scripts to encrypt/decrypt the passwords
(encrypt.c and decrypt.c) from the nodes.txt .. so that if anyone
tries to read the file, they don't get the password. Decrypt.c only
accepts requests from main.pl through some hand-shaking. You can't run
this script on it's own against nodes.txt. So far so good, to recap:
1. Populate nodes.txt file
2. Run the encrypt.c script to encrypt passwords in node.txt
3. main.pl calls decrypt.c and stores username/password (which is
non-encrypted now)
4. MY QUESTIONS: Is there a way to ensure that someone can't modify
the main.pl script to output the password before it gets sent off to a
switch? Does PERL allow me have hidden variables or some sort?
I give this program out to users to install on their Unix machines
with root. Anyone with root access can modify the main.pl script .. I
have no control over that. I just want to see if there's anything I
can do to hide the password variable in main.pl so they can't simply
put a print statement on the variable before I call Telnet.
This isn't a banking system model, but so far I can say I have some
decent work around the encrypt/decrypt portions. There are ways to
break into this that would require some work/tools, that's a given.
Now I just need something to make the main.pl a little more hack
proof.
Thanks in advance!!
------------------------------
Date: 22 Oct 2002 17:37:02 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Hiding password variables in PERL
Message-Id: <u9wuoaa0r5.fsf@wcl-l.bham.ac.uk>
marcjgpelletier@hotmail.com (Marc Pelletier) writes:
> Alright, so here's the scoop .. wondering if anyone has ever come
> across something like this.
Many a time. What keywords did you use in your Usenet search before
you concluded you needed to ask this question?
I just tried "group:comp.lang.perl* hide password" and it seemed quite
good and finding several previous threads on this subject.
> I give this program out to users to install on their Unix machines
> with root. Anyone with root access can modify the main.pl script .. I
> have no control over that. I just want to see if there's anything I
> can do to hide the password variable in main.pl so they can't simply
> put a print statement on the variable before I call Telnet.
>
> This isn't a banking system model, but so far I can say I have some
> decent work around the encrypt/decrypt portions. There are ways to
> break into this that would require some work/tools, that's a given.
> Now I just need something to make the main.pl a little more hack
> proof.
Acme::Bleach
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 22 Oct 2002 15:23:02 +0100
From: "Richard Gration" <richard@zync.co.uk>
Subject: How does @EXPORT function in a package?
Message-Id: <20021022.152302.1626276121.8623@richg.richg.zync>
Hi All,
I was under the impression that any subs in the @EXPORT array in a
package would automagically appear of the namespace of the script
"use"ing the package. But I gather from experiments that these subs need
to be mentioned in @EXPORT_OK too. Is this always the case?
I also find that if I
use Module::Lib qw(:tag);
then if the sub mentioned in @EXPORT is not mentioned in the list for the
tag, then it's still not imported, even if it _is_ in @EXPORT_OK.
I find all this counter-intuitive. I expected that anything in @EXPORT
would appear in the namespace of the "use"r, so to speak. Is this ever
the case?
Rich
------------------------------
Date: Tue, 22 Oct 2002 09:59:29 -0500
From: brian d foy <comdog@panix.com>
Subject: Re: How does @EXPORT function in a package?
Message-Id: <221020020959291871%comdog@panix.com>
In article <20021022.152302.1626276121.8623@richg.richg.zync>, Richard Gration <richard@zync.co.uk> wrote:
> Hi All,
>
> I was under the impression that any subs in the @EXPORT array in a
> package would automagically appear of the namespace of the script
> "use"ing the package. But I gather from experiments that these subs need
> to be mentioned in @EXPORT_OK too. Is this always the case?
see the Exporter documentation:
http://www.perldoc.com/perl5.6.1/lib/Exporter.html
--
brian d foy <comdog@panix.com> - Perl services for hire
The Perl Review - a new magazine devoted to Perl
<http://www.theperlreview.com>
------------------------------
Date: 22 Oct 2002 07:57:37 -0700
From: mullman@charter.net (Chris)
Subject: Re: how to call java in perl?
Message-Id: <c71b7a2c.0210220657.79eae167@posting.google.com>
Hong Liang <liang@expert.ics.purdue.edu> wrote in message news:<Pine.GSO.4.44.0210210504410.17995-100000@expert.ics.purdue.edu>...
> Hi,
>
> can anyone present a somewhat full list of
> ways for calling other programs from Perl,
> such as Java class?
>
> thanks,
Here's how I do it:
system ("/usr/bin/java Convert");
------------------------------
Date: Tue, 22 Oct 2002 17:22:13 +0100
From: "Miguel Manso" <mmanso@prodigio.com>
Subject: Re: how to call java in perl?
Message-Id: <UVet9.45$4T6.230532@newsserver.ip.pt>
Hi there,
See the Inline module,
http://search.cpan.org/author/PATL/Inline-Java-0.33/
On Mon, 21 Oct 2002 05:06:53 +0000, Hong Liang wrote:
> Hi,
>
> can anyone present a somewhat full list of
> ways for calling other programs from Perl,
> such as Java class?
>
> thanks,
------------------------------
Date: 22 Oct 2002 09:15:48 -0700
From: googlegroups@sebastienboving.com (S E H M B)
Subject: open(STDOUT, ">/dev/null") successful but still get STDOUT output
Message-Id: <2b853579.0210220815.f372efa@posting.google.com>
Hi,
Somewhere in a module, i have the following lines:
...
open(STDOUT, '>/dev/null')
or die("STDOUT open");
open(STDERR, ">&STDOUT")
or die("STDERR open");
print(STDERR "Still gets on the console\n");
print(STDOUT "Also still gets on the console\n");
...
The last two statements still print out on the terminal.
Now if i put this code in a small test.pl, it works fine. Somehow,
with all the other code that got loaded / executed before getting
there, it fails to work.
In particular, on top of that module, i have "use Inline::Files". If i
put the above code higher than this statement, or uncomment this
'use', it works. Yet adding "use Inline::Files" in my test.pl does not
make it fail (and i need Inline::Files in my module).
I could go on looking for what is causing this by elimination, but
this could take a while... Can someone give me insight as to what
could happen that makes the above code behave in they way i describe
(open()'s successful, yet print()'s still go to the old? fh).
No relevant warnings are displayed, and couldn't find anything related
to this in Inline::Files docs. Perl 5.6.1 on i686-linux.
thank,
-seb.
------------------------------
Date: 22 Oct 2002 10:28:24 -0700
From: jeannot@gmavt.net (Jean Gagnon)
Subject: Re: opendir/readdir can't handle french characters: What am I missing?
Message-Id: <981d6b93.0210220928.6828c62e@posting.google.com>
Benjamin Goldberg <goldbb2@earthlink.net> wrote in message news:<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.
I ran the above code (except for changing sprint to sprintf) and for
the file in question I got the following output:
Processing L\x{61} C\x{6F}\x{6D}\x{70}\x{61}\x{67}\x{6E}\x{69}\x{65}
C\x{72}\x{E
9}\x{6F}\x{6C}\x{65} - M\x{61}
\x{70}\x{72}\x{65}\x{6D}\x{69}\x{E8}\x{72}\x{65}
\x{62}\x{69}\x{67}\x{75}\x{69}\x{6E}\x{65}
\x{70}\x{61}\x{72}\x{74}\x{69}\x{65}.
\x{6D}\x{70}3
The first problematic accented character (e accent-aigu) appears here
as an above-128 character, "E9", and the second one (e accent-grave)
appears as "E8". These are consistent with the same characters entered
in a Notepad file that I closed and reopened in binary mode.
So that eliminates opendir and readdir as culprits. I also performed a
split on the file name, and the resulting fields still had the correct
characters. So I think we can conclude the "print" where something
should be fixed.
I did a search for encode.pm on CPAN, and the search results are
rubbing my nose in my "newbieness". I appreciate your help.
------------------------------
Date: Tue, 22 Oct 2002 13:59:57 -0400
From: "Christian Caron" <nospam@nospam.org>
Subject: Re: opendir/readdir can't handle french characters: What am I missing?
Message-Id: <ap43mu$3g88@nrn2.NRCan.gc.ca>
I think there is a "use locale" thing to permit accented characters (but I'm
not sure if it's only for regular expressions...).
Christian
"Jean Gagnon" <jeannot@gmavt.net> wrote in message
news:981d6b93.0210220928.6828c62e@posting.google.com...
> Benjamin Goldberg <goldbb2@earthlink.net> wrote in message
news:<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.
>
> I ran the above code (except for changing sprint to sprintf) and for
> the file in question I got the following output:
>
> Processing L\x{61} C\x{6F}\x{6D}\x{70}\x{61}\x{67}\x{6E}\x{69}\x{65}
> C\x{72}\x{E
> 9}\x{6F}\x{6C}\x{65} - M\x{61}
> \x{70}\x{72}\x{65}\x{6D}\x{69}\x{E8}\x{72}\x{65}
> \x{62}\x{69}\x{67}\x{75}\x{69}\x{6E}\x{65}
> \x{70}\x{61}\x{72}\x{74}\x{69}\x{65}.
> \x{6D}\x{70}3
>
> The first problematic accented character (e accent-aigu) appears here
> as an above-128 character, "E9", and the second one (e accent-grave)
> appears as "E8". These are consistent with the same characters entered
> in a Notepad file that I closed and reopened in binary mode.
>
> So that eliminates opendir and readdir as culprits. I also performed a
> split on the file name, and the resulting fields still had the correct
> characters. So I think we can conclude the "print" where something
> should be fixed.
>
> I did a search for encode.pm on CPAN, and the search results are
> rubbing my nose in my "newbieness". I appreciate your help.
------------------------------
Date: 22 Oct 2002 09:22:49 -0700
From: aryan_us1975@yahoo.com (Aryan)
Subject: Perl Program
Message-Id: <6e1902a1.0210220822.665c42df@posting.google.com>
I am populating the two these kind of hashes, it is based upon the what user
does on the web page. I have to manipulate with these two hashes plzz help
me..
%original_list = (
"name1" => "name1:",
"name2" => "name2:update",
"name3" => "name3:update",
"name4" => "name4:update",
);
%changed_list = (
"name1" => "name1:update",
"name2" => "name2:",
);
Sub unsubscribe {
}
Sub subscribe{
}
Assumptions:
The changed list would have same number of keys as original or lesser.
For All the keys which are in originalList but not in chnaged call a
function called unsubscribe and populate a array called
unsubscribeArray.
Now compare the values for each keys which are there in both of these
lists::::
if in List1 value contains update for perticular key and in list 2 for the
same key it is null for that key call unsubscribe function and add the
element into unsubscribed Array.
if in List1 value does not contains update for perticular key and in list
2 it is update call subscribe function and add the element into subscribed
Array.
------------------------------
Date: 22 Oct 2002 17:41:33 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Perl Program
Message-Id: <u9u1jea0jm.fsf@wcl-l.bham.ac.uk>
aryan_us1975@yahoo.com (Aryan) writes:
> Subject: Perl Program
Please put the subject of your post in the Subject of your post. If
in doubt try this simple test. Imagine you could have been bothered
to have done a search before you posted. Next imagine you found a
thread with your subject line. Would you have been able to recognise
it as the same subject?
> %original_list = (
>
> "name1" => "name1:",
> "name2" => "name2:update",
> "name3" => "name3:update",
> "name4" => "name4:update",
>
> );
>
>
> %changed_list = (
>
> "name1" => "name1:update",
> "name2" => "name2:",
>
> );
> Assumptions:
>
> The changed list would have same number of keys as original or
> lesser.
You description of your task is now not self-consistant. I'm going to
give up now.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 22 Oct 2002 14:45:18 +0200
From: "Anthony" <anthony.heuveline@wanadoo.fr>
Subject: PHP to Perl translation
Message-Id: <ap3h3q$b85$1@news-reader10.wanadoo.fr>
Is anybody able to translate the source code below into Perl? The aim is to
force the download of a file instead of displaying it in the web browser.
<?php
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=filename.xxx");
readfile("http://www.server.com/dir/filename.xxx");
?>
Thnaks a lot.
Anthony.
------------------------------
Date: Tue, 22 Oct 2002 16:49:44 GMT
From: Bryan <bryan@akanta.com>
Subject: Re: PHP to Perl translation
Message-Id: <3DB581A8.3080304@akanta.com>
Anthony wrote:
> Is anybody able to translate the source code below into Perl? The aim is to
> force the download of a file instead of displaying it in the web browser.
>
> <?php
> header("Content-type: application/force-download");
> header("Content-Disposition: attachment; filename=filename.xxx");
> readfile("http://www.server.com/dir/filename.xxx");
> ?>
>
> Thnaks a lot.
>
> Anthony.
>
>
Check out the CGI documentation ( perldoc CGI ) and read up on the
header subroutine. Everything you need is there, including sample code.
HTH,
B
------------------------------
Date: 22 Oct 2002 10:07:06 -0700
From: jl_post@hotmail.com (J. Romano)
Subject: Re: Question about hash entries with two keys
Message-Id: <b893f5d4.0210220907.266ee58@posting.google.com>
Uri Guttman <uri@stemsystems.com> wrote in message news:<x7elajjwe2.fsf@mail.sysarch.com>...
>
> >>>>> "JR" == J Romano <jl_post@hotmail.com> writes:
>
> JR> I remember reading in a Perl
> JR> book that Perl manages two-key hash
> JR> entries by concatenating the keys
> JR> together with a special character.
>
> whatever book you have that promotes fake multi-dim arrays
> should be burned. which one is it anyhow? i want to downrate it.
For the record, I never said that my book promotes fake multi-dim
arrays -- I simply said that I read in a Perl book that perl manages
two-key hash entries by concatenating the keys together.
In case you're still interested, I just found the book and passage
that discusses multi-dimensional emulation. It happens to be the book
I used the most to learn Perl. Here is the book's identifying
information:
Programming Perl, Third Edition
by Larry Wall, Tom Christiansen, and Jon Orwant
Copyright 2000, O'Reilly & Associates, Inc.
The passage on emulating multidimensional hashes is located on page
78 near the end of the section titled "Hashes" in "Chapter 2: Bits and
Pieces". It even goes so far as to mention that multidimensional hash
emulation is still useful "...for hashes tied to DBM files, which
don't support multidimensional keys" (also on page 78).
-- Jean-Luc Romano
------------------------------
Date: Tue, 22 Oct 2002 17:17:50 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Question about hash entries with two keys
Message-Id: <x7of9mie9u.fsf@mail.sysarch.com>
>>>>> "JR" == J Romano <jl_post@hotmail.com> writes:
JR> Uri Guttman <uri@stemsystems.com> wrote in message news:<x7elajjwe2.fsf@mail.sysarch.com>...
>>
>> >>>>> "JR" == J Romano <jl_post@hotmail.com> writes:
>>
JR> I remember reading in a Perl
JR> book that Perl manages two-key hash
JR> entries by concatenating the keys
JR> together with a special character.
>>
>> whatever book you have that promotes fake multi-dim arrays
>> should be burned. which one is it anyhow? i want to downrate it.
JR> Programming Perl, Third Edition
JR> by Larry Wall, Tom Christiansen, and Jon Orwant
JR> Copyright 2000, O'Reilly & Associates, Inc.
JR> The passage on emulating multidimensional hashes is located on page
JR> 78 near the end of the section titled "Hashes" in "Chapter 2: Bits and
JR> Pieces". It even goes so far as to mention that multidimensional hash
JR> emulation is still useful "...for hashes tied to DBM files, which
JR> don't support multidimensional keys" (also on page 78).
i am surprised by that plug of that feature. there is a MLDBM module
that does this too so it is not needed there. as others have pointed
out, if your keys accidentally have $; in them, you get nasty bugs. i
still say it should not be used in any case. your case does not need it
so you should use regular perl data structures.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 22 Oct 2002 10:38:12 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: regular expression to extract the path name
Message-Id: <3db52994.544925090@news.cis.dfn.de>
On Tue, 22 Oct 2002 09:25:31 +0200, Michael Kirchner
<michael.kirchner@unibw-muenchen.de> wrote:
>I have a path name including the file name and I want to define a
>regular expression which gives only the path name.
Well, I'd rather not give you a regex, because that's the
wrong way to do it IMO
> I tried many constructs but none works.
>f.e.:
>I have "/dir1/dir2/dir3/file.ext"
>I want "/dir1/dir2/dir3/"
>I use s/\/.*?$// ... but gives "" :-(
use File::Basename;
use warnings;
use strict;
my $file = "/dir1/dir2/dir3/file.ext";
my ($name,$path) = fileparse($file);
print "$name is in $path\n";
--
Regards, Helgi Briem
helgi AT decode DOT is
A: Top posting
Q: What is the most irritating thing on Usenet?
- "Gordon" on apihna
------------------------------
Date: Tue, 22 Oct 2002 10:16:45 +0200
From: hubert depesz lubaczewski <depesz@depesz.pl>
Subject: Re: regular expression to extract the path name
Message-Id: <slrn.pl.ara2bd.57p.depesz@depeszws.depesz.pl>
Michael Kirchner wyrze¼bi³(a):
> I have "/dir1/dir2/dir3/file.ext"
> I want "/dir1/dir2/dir3/"
> I use s/\/.*?$// ... but gives "" :-(
my $sFile = "/dir1/dir2/dir3/file.ext";
$sFile=~/^(.*\/)/;
my $sPath = $1;
print $sPath."\n";
depesz
--
hubert depesz lubaczewski http://www.depesz.pl/
------------------------------------------------------------------------
Mój Bo¿e, spraw abym milcza³, dopóki siê nie upewniê, ¿e naprawdê mam
co¶ do powiedzenia. (c) 1998 depesz
------------------------------
Date: Tue, 22 Oct 2002 12:18:55 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: regular expression to extract the path name
Message-Id: <Pmbt9.23790$Pk1.21322@nwrddc02.gnilink.net>
Michael Kirchner wrote:
> Hello all.
>
> I have a path name including the file name and I want to define a
> regular expression which gives only the path name. I tried many
> constructs but none works.
[...]
> Any better idea?
Have you tried File::Basename?
jue
------------------------------
Date: Tue, 22 Oct 2002 17:01:01 GMT
From: "john bennett" <johngnub@worldnet.att.net>
Subject: Re: regular expression to extract the path name
Message-Id: <hvft9.22067$1P1.1388430@bgtnsc05-news.ops.worldnet.att.net>
Call me the lazy one, While Job hunting at home, (PHX AZ) I typed this one
up.
# The dir list, the path.
$foo = "/dir1/dir2/dir3/foobar.txt";
# Print for fun, low profit margin; :)
print "$foo";
# The split will return each part in to the array known as list,
# Sorry for the slash-lish form, the first "/" starts the matching, "\/"
next escape the "/" that defines the dir's
# Last "/" close up the match....
(@list) = split (/\//,$foo);
# More code for fun, print to scr each "one" at a time, still in the low
margin of profits...
foreach $one (@list){
print "$one\n";
}
Just 2 cents, JB
Michael Kirchner <michael.kirchner@unibw-muenchen.de> wrote in message
news:3DB4FD6B.3000903@unibw-muenchen.de...
> Hello all.
>
> I have a path name including the file name and I want to define a
> regular expression which gives only the path name. I tried many
> constructs but none works.
> f.e.:
> I have "/dir1/dir2/dir3/file.ext"
> I want "/dir1/dir2/dir3/"
> I use s/\/.*?$// ... but gives "" :-(
>
> Any better idea?
> Thaks a lot.
> Micha
>
------------------------------
Date: Tue, 22 Oct 2002 16:35:09 +0000 (UTC)
From: Da Witch <heather710101@yahoo.com>
Subject: warnings::register and inheritance
Message-Id: <ap3unt$qlh$1@reader1.panix.com>
I'm having screwy results using warnings::register and inheritance.
The best example I've been able to come up with using simplified code
is this:
# Foo.pm
package Foo;
use warnings::register;
sub new { bless {}, $_[0] }
sub foo { "foo called: " . warnings::enabled() }
1;
# Bar.pm
package Bar;
use warnings::register;
use Foo; our @ISA = ('Foo');
sub foo { (shift)->SUPER::foo() }
1;
# test.pl
use warnings;
use Foo;
print "Foo: ", Foo->new->foo, "\n";
use Bar;
print "Bar: ", Bar->new->foo, "\n";
When I run test.pl, I get
Foo: foo called: 1
Bar: foo called: 0
If I comment out the definition of foo in Bar.pm, I get
Foo: foo called: 1
Bar: foo called: 1
Why does overriding foo in Bar disable the warnings?
(Actually, in the code I'm working in I'm getting the opposite
problem, namely warnings are enabled in a subclass even when they have
been disabled in the superclass.)
Any light shed on this would be much appreciated...
Thanks,
h
------------------------------
Date: 22 Oct 2002 18:05:45 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: warnings::register and inheritance
Message-Id: <u9r8ei9zfa.fsf@wcl-l.bham.ac.uk>
Da Witch <heather710101@yahoo.com> writes:
> I'm having screwy results using warnings::register and inheritance.
No you are not.
> The best example I've been able to come up with using simplified code
> is this:
>
> # Foo.pm
> package Foo;
> use warnings::register;
> sub new { bless {}, $_[0] }
> sub foo { "foo called: " . warnings::enabled() }
> 1;
>
> # Bar.pm
> package Bar;
> use warnings::register;
> use Foo; our @ISA = ('Foo');
> sub foo { (shift)->SUPER::foo() }
> 1;
>
> # test.pl
> use warnings;
> use Foo;
> print "Foo: ", Foo->new->foo, "\n";
> use Bar;
> print "Bar: ", Bar->new->foo, "\n";
>
>
> When I run test.pl, I get
>
> Foo: foo called: 1
> Bar: foo called: 0
>
> If I comment out the definition of foo in Bar.pm, I get
>
> Foo: foo called: 1
> Bar: foo called: 1
warnings::enabled([$category])
Returns TRUE if the warnings category `$category' is
enabled in the calling module. Otherwise returns
FALSE.
When Foo::foo() is called from main.pl it correctly reports that
warnings are enabled at line 4 in main.pl.
When Foo::foo() is called by Bar::foo() in Bar.pm it correctly reports
that warnings are disabled at line 5 in Bar.pm.
Arguably there is a case for a varient of warnings::enabled() and
warnings::warn() that work like carp() and step over entries in the
call stack that are in packages that are ancesctor/decendant of the
current package. However it is not currently so.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 22 Oct 2002 07:38:36 -0700
From: mullman@charter.net (Chris)
Subject: Writing Microsoft Outlook Notes With Perl
Message-Id: <c71b7a2c.0210220638.71e61d3d@posting.google.com>
I've got this half-baked idea for writing a program that will
dynamically generate Microsoft Outlook Notes from information gathered
from a database. I know how to do everything except create the
Outlook Note. Can anyone point me in the direction of information for
accomplishing this? I've seen others do this (not with Perl) where
the program will seek data from the weather service and write that
data into an Outlook Note. That's similar to what I am trying to do.
Any help will be greatly appreciated.
Chris
------------------------------
Date: Tue, 22 Oct 2002 17:56:33 +0200
From: "serge.john.swilting" <serge.john.swilting@wanadoo.fr>
Subject: ypur//warning perl 58
Message-Id: <ap3sfk$10r$1@news-reader11.wanadoo.fr>
est ce que programme marche chez vous avec un perl58
attention
warning ypur software
#!/usr/local/bin/perl -w
use Net::NNTP;
{#slurp
$programme=&programme;
{#slurp
eval `$programme`;
sub programme{
{#slurp
$serveur='news.wanadoo.fr';
{#slurp
$nntp=Net::NNTP->new($serveur) or die "impossible de se connecter ˆ
$serveur:$@\n";
{#slurp
$liste=$nntp->list();
{#slurp
$programme1=&nouvelle_fonction1;
{#slurp
eval `$programme1`;
{#slurp
sub nouvelle_fonction1{
{#slurp
while(<$groupe,$liste,$nbr,$premier,$dernier,$group,$i>){
print;
{#slurp
$programme2=&foreach;
eval `$programme2`;
sub foreach{
{#slurp
sub group{
($nbr,$premier,$dernier,$group)=$nntp->(&foreach);
}
{#slurp
sub foreach{
{#slurp
foreach $groupe(keys %$liste)
{
{#slurp
print $liste->{$groupe}->[$i];
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
------------------------------
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 4010
***************************************