[16686] in Perl-Users-Digest
Perl-Users Digest, Issue: 4098 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 22 18:10:45 2000
Date: Tue, 22 Aug 2000 15:10:31 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <966982230-v9-i4098@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 22 Aug 2000 Volume: 9 Number: 4098
Today's topics:
how convert to binary, hex etc <samuel.irlapati@unisys.com>
Re: how convert to binary, hex etc (Greg Bacon)
Re: how convert to binary, hex etc (Anno Siegel)
Re: how convert to binary, hex etc (Anno Siegel)
Re: how convert to binary, hex etc <lr@hpl.hp.com>
Re: how convert to binary, hex etc <lr@hpl.hp.com>
Re: how convert to binary, hex etc <lr@hpl.hp.com>
How to split mailheaders <kjetilskotheim@iname.com>
Re: How to split mailheaders <stephenk@cc.gatech.edu>
Re: How to split mailheaders (Anno Siegel)
Re: How to split mailheaders <lr@hpl.hp.com>
Is Perl a good choice for manipulating XML data? john_s_brown@my-deja.com
long-to-short dir/filenames <newsgroup@pmail.net>
Re: Lotsa difiiculties - need help with my Perl !! <abe@ztreet.demon.nl>
Re: Lotsa difiiculties - need help with my Perl !! <ren.maddox@tivoli.com>
Re: MS IIS and perl syntax errors causing download prom <fchanny@lbl.gov>
Re: newbie question about "uninitialized variables" <lr@hpl.hp.com>
Re: Parse::Recdescent questions (<commit> and other pro <ocschwar@mit.edu>
PLEASE HELP !!! What is wrong with Windows... <comet999@my-deja.com>
PLEASE HELP !!! What is wrong with Windows... <comet999@my-deja.com>
Problem with PPM working rita_nc@my-deja.com
Rationale Behind 'Use of Uninitialized Value' Warning <grichard@uci.edu>
Re: regexing html-like tags <blair@geo-NOSPAM-soft.org>
Re: regexing html-like tags <blair@geo-NOSPAM-soft.org>
Re: Sorting by a subfield (WAS: Re: This is my last que pape_98@my-deja.com
Re: Sorting by a subfield (WAS: Re: This is my last que (Eric Bohlman)
Re: system() output screwing up redirection. swan_daniel@my-deja.com
Re: Unexpected behavior of shift in a loop <abe@ztreet.demon.nl>
Re: Unexpected behavior of shift in a loop <ren.maddox@tivoli.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 22 Aug 2000 15:18:06 -0400
From: "Samuel Irlapati" <samuel.irlapati@unisys.com>
Subject: how convert to binary, hex etc
Message-Id: <8nujjc$ipe$1@trsvr.tr.unisys.com>
How do you convert a decimal number say to hexadecimal and then shift it by
one digit to the right and then convert it back to decimal?
------------------------------
Date: Tue, 22 Aug 2000 19:44:13 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: how convert to binary, hex etc
Message-Id: <sq5m0drqt91155@corp.supernews.com>
In article <8nujjc$ipe$1@trsvr.tr.unisys.com>,
Samuel Irlapati <samuel.irlapati@unisys.com> wrote:
: How do you convert a decimal number say to hexadecimal and then shift
: it by one digit to the right and then convert it back to decimal?
It's not necessary to perform the change of base. Just shift it:
$num >>= 1;
Greg
--
People are divided into two groups--the righteous and the unrighteous--and
the righteous do the dividing.
-- Lord Cohen
------------------------------
Date: 22 Aug 2000 19:47:22 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how convert to binary, hex etc
Message-Id: <8nulca$20q$1@lublin.zrz.tu-berlin.de>
Samuel Irlapati <samuel.irlapati@unisys.com> wrote in comp.lang.perl.misc:
>How do you convert a decimal number say to hexadecimal and then shift it by
>one digit to the right and then convert it back to decimal?
By some combination of sprintf, substr, and oct, all to be found in
perldoc -f. Perhaps string concatenation comes in handy somewhere,
though it isn't strictly necessary.
While in Perl it appears that numbers are "decimal per default", this
isn't true. A number doesn't have an intrinsic base it carries around,
it is just that, a number. String representations of numbers use
various bases (and other systems) to denote numbers. That doesn't
make the numbers a bit different. It is useful to keep this
distinction in mind.
Anno, who preaches this little sermon from time to time
------------------------------
Date: 22 Aug 2000 19:49:10 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how convert to binary, hex etc
Message-Id: <8nulfm$222$1@lublin.zrz.tu-berlin.de>
Greg Bacon <gbacon@hiwaay.net> wrote in comp.lang.perl.misc:
>In article <8nujjc$ipe$1@trsvr.tr.unisys.com>,
> Samuel Irlapati <samuel.irlapati@unisys.com> wrote:
>
>: How do you convert a decimal number say to hexadecimal and then shift
>: it by one digit to the right and then convert it back to decimal?
>
>It's not necessary to perform the change of base. Just shift it:
>
> $num >>= 1;
$num >>= 4; # my interpretation of the OP
Anno
------------------------------
Date: Tue, 22 Aug 2000 12:57:06 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: how convert to binary, hex etc
Message-Id: <MPG.140c7aeba530508798acbf@nntp.hpl.hp.com>
In article <8nujjc$ipe$1@trsvr.tr.unisys.com> on Tue, 22 Aug 2000
15:18:06 -0400, Samuel Irlapati <samuel.irlapati@unisys.com> says...
> How do you convert a decimal number say to hexadecimal and then shift it by
> one digit to the right and then convert it back to decimal?
That is an amusing question, because Perl knows nothing of 'decimal
numbers'. Numbers may be represented as strings using decimal notation,
but internally the representations are binary.
So your question reduces to:
How do you find the integer quotient of the division of a number by 16?
You should be able to write that in Perl without my help.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 22 Aug 2000 12:59:27 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: how convert to binary, hex etc
Message-Id: <MPG.140c7b77e9e3012598acc0@nntp.hpl.hp.com>
In article <sq5m0drqt91155@corp.supernews.com> on Tue, 22 Aug 2000
19:44:13 GMT, Greg Bacon <gbacon@HiWAAY.net> says...
> In article <8nujjc$ipe$1@trsvr.tr.unisys.com>,
> Samuel Irlapati <samuel.irlapati@unisys.com> wrote:
>
> : How do you convert a decimal number say to hexadecimal and then shift
> : it by one digit to the right and then convert it back to decimal?
>
> It's not necessary to perform the change of base. Just shift it:
>
> $num >>= 1;
Shifting a number in hexadecimal representation one digit to the right
is actually a right-shift of four bits, not one bit, n'ect-ce pas?
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 22 Aug 2000 13:10:28 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: how convert to binary, hex etc
Message-Id: <MPG.140c7e107be7946c98acc1@nntp.hpl.hp.com>
In article <8nulca$20q$1@lublin.zrz.tu-berlin.de> on 22 Aug 2000
19:47:22 -0000, Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> says...
> Samuel Irlapati <samuel.irlapati@unisys.com> wrote in comp.lang.perl.misc:
> >How do you convert a decimal number say to hexadecimal and then shift it by
> >one digit to the right and then convert it back to decimal?
>
> By some combination of sprintf, substr, and oct, all to be found in
> perldoc -f. Perhaps string concatenation comes in handy somewhere,
> though it isn't strictly necessary.
Hmmm... Posted two minutes before your correction to Greg Bacon's
approach, which uses none of the above.
> While in Perl it appears that numbers are "decimal per default", this
> isn't true. A number doesn't have an intrinsic base it carries around,
> it is just that, a number. String representations of numbers use
> various bases (and other systems) to denote numbers. That doesn't
> make the numbers a bit different. It is useful to keep this
> distinction in mind.
>
> Anno, who preaches this little sermon from time to time
It's a good sermon. But you didn't apply it to your answer. :-)
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 22 Aug 2000 20:30:12 +0200
From: Kjetil Skotheim <kjetilskotheim@iname.com>
Subject: How to split mailheaders
Message-Id: <MPG.140ce51c57c8cddd989680@nntp.uio.no>
[This followup was posted to comp.lang.perl.misc and a copy was sent to the cited author.]
Hi all,
I'm convinced it should be easy to split a mail header in its different
parts by using m//g or split(). But how? Each part of the resulting list
should be a line from the header PLUS ALL FOLLOWING LINES as long as
they start with space. Tested and failed:
@header = split(/\n/,$header); #wrong, obviously
@header = split(/.+(?!\n\S|$)/s,$header); #failed, dont know why
Example of mail header:
(First part should be the first line, second part should be line two,
three and four, since they three and four starts with space).
$header=<<END;
Delivery-date: Tue, 22 Aug 2000 11:50:33 +0200
Received: from mons.uio.no ([129.240.257.14])
by lister.uio.no with esmtp (Exim 2.12 #7)
id 13RCZW-0007ip-00; Tue, 22 Aug 2000 11:50:26 +0200
Received: from ulrik.uio.no ([129.240.258.259])
by mons.uio.no with esmtp (Exim 2.12 #7)
id 13RCZW-0004TV-00; Tue, 22 Aug 2000 11:50:26 +0200
Message-Id: <3.0.3.32.20000822135024.033c7320@ulrik.uio.no>
X-Sender: kjetilsk@ulrik.uio.no
X-Mailer: QUALCOMM Windows Eudora Pro Version 3.0.3 (32)
Date: Tue, 22 Aug 2000 13:50:24 +0200
To: brb@yes.no, asdf@no.yes
From: Kjetil Skotheim
Subject:
=?iso-8859-1?Q?Re:_Installasjon_software_p=E5?= brb.
END
--
Kjetil Skotheim,
kjetilskotheim@iname.com
------------------------------
Date: Tue, 22 Aug 2000 15:03:42 -0400
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: How to split mailheaders
Message-Id: <39A2CE8D.C1BBB1F0@cc.gatech.edu>
Kjetil Skotheim wrote:
> [This followup was posted to comp.lang.perl.misc and a copy was sent to the cited author.]
>
> Hi all,
> I'm convinced it should be easy to split a mail header in its different
> parts by using m//g or split(). But how? Each part of the resulting list
> should be a line from the header PLUS ALL FOLLOWING LINES as long as
> they start with space. Tested and failed:
>
> @header = split(/\n/,$header); #wrong, obviously
> @header = split(/.+(?!\n\S|$)/s,$header); #failed, dont know why
>
> Example of mail header:
<snipped>
$header =~ s/\n\s+//gs; will convert all header data to single lines separated by "\n", which
can be easily split.
This method removes internal carriage returns, but if you want them for some reason, you can
use
$header =~ s/\n(\S)/\n***$1/gs;
@header = split '\*{3}',$header;
I recommend reading perlop for information on parameters for s///, namely /s and /m
--
Stephen Kloder | "I say what it occurs to me to say.
stephenk@cc.gatech.edu | More I cannot say."
Phone 404-874-6584 | -- The Man in the Shack
ICQ #65153895 | be :- think.
------------------------------
Date: 22 Aug 2000 19:29:57 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How to split mailheaders
Message-Id: <8nukbl$1vi$1@lublin.zrz.tu-berlin.de>
Stephen Kloder <stephenk@cc.gatech.edu> wrote in comp.lang.perl.misc:
>$header =~ s/\n\s+//gs; will convert all header data to single lines separated by "\n", which
>can be easily split.
But it also loses any separators between continuation lines. s/\n\s+/ /gs
does a better job.
>This method removes internal carriage returns, but if you want them for some reason, you can
>use
>$header =~ s/\n(\S)/\n***$1/gs;
>@header = split '\*{3}',$header;
Is there anything that stops "***" from appearing somewhere in a mail
header? This doesn't look like a reliable procedure.
Oh, and please keep your line length below 72 or so.
Anno
------------------------------
Date: Tue, 22 Aug 2000 12:52:15 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: How to split mailheaders
Message-Id: <MPG.140c79cb88388b5198acbe@nntp.hpl.hp.com>
In article <39A2CE8D.C1BBB1F0@cc.gatech.edu> on Tue, 22 Aug 2000
15:03:42 -0400, Stephen Kloder <stephenk@cc.gatech.edu> says...
...
> $header =~ s/\n\s+//gs; will convert all header data
> to single lines separated by "\n", which can be easily split.
> This method removes internal carriage returns, but if you
> want them for some reason, you can use
> $header =~ s/\n(\S)/\n***$1/gs;
> @header = split '\*{3}',$header;
You know that the first argument for split() is a regex, so why write it
as if it were a string?
> I recommend reading perlop for information on parameters
> for s///, namely /s and /m
If you do that, you will discover that that /s modifiers in each of the
above regexes is superfluous.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 22 Aug 2000 18:35:58 GMT
From: john_s_brown@my-deja.com
Subject: Is Perl a good choice for manipulating XML data?
Message-Id: <8nuh6d$2lk$1@nnrp1.deja.com>
Yeah. The simple but also at the same time very controversial
question is this: Is Perl a good choice for manipulating XML data? So,
should I start learning Perl or would Java be a better language, for
example.
Can I handel DOM and SAX with Perl? I know that SAX stands for Simple
API for XML, but can I use SAX with Perl. And what about DOM?
Please, help me with this problem!
John S. Brown.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 22 Aug 2000 18:54:13 +0200
From: "Giovanni Loc" <newsgroup@pmail.net>
Subject: long-to-short dir/filenames
Message-Id: <8nubgb$2dj$1@nslave2.tin.it>
I'm using an old dos program that accept a @filelist.txt of short 8.3-format
filenames for input
the problem is that I have this filelist.txt with LONG dir/filenames,
like:
c:\mydirectorya\subdirectorya\longfilename.txt
c:\mydirectoryb\subdirectoryb\longfilenameb.txt
c:\foobar\onetwothree.txt
so I need to translate all the paths in @filelist.txt for example in:
c:\MYDIRE~1\SUBDIR~1\LONGFI~1.TXT
c:\MYDIRE~2\SUBDIR~2\LONGFI~1.TXT
c:\FOOBAR\ONETWO~1.TXT
I think the only correct way to do this is to execute and analyze a system
DIR for each row..
using AWK, SED, or PERL and eventually a BAT file for speed (i.e. instead
of calling many times the "system" command in AWK)
anyone knows how to do it?
I'm on Windows 2000,
w2k has DIR /X for displaying SFN
w98 display SFN with a normal DIR
but both seems to not display the dir shortnames (perhaps you can see them
by executing a DIR for each dir/subdir in the row.. but I think it's a bad
method)
------------------------------
Date: Tue, 22 Aug 2000 22:03:34 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: Lotsa difiiculties - need help with my Perl !!
Message-Id: <6dm5qs8fgrjii1du8fu3chedf1g9db1isp@4ax.com>
On Tue, 22 Aug 2000 16:46:30 GMT, reg_exp@my-deja.com wrote:
> hi,
>
> i have a problem that i would like to solve using perl. i have a few
> questions, relating to how i can go about solving my problem, and also
> as to how i can actually implement a soltuib (i'm having some
> difficulties, which i'll explain).
[snip data structure]
> The tag [START] is the one that actually breaks up the structure into
> records, with each record having multiple
> [IN_START]..[IN_DATA]..[IN_END] tags.
>
> What I need to do is:
> 1) First break up the file into many records with the lines between two
> [START] tags making a record.
You can set the input record separator:
$/ = "\n[START]\n";
> 2) Within this record, extract only the lines between the [IN_DATA] and
> [IN_END] and store these in arrays.
You can use a regular expression to get these bits from the record and
push them onto an array. I don't see why you need multiple arrays.
> 3) Process each array - within each array, I need to further break the
> array down into records seperated by a [NUGGET] tag.
I don't understand this bit as your sample data didn't provide an
example.
Show us a small but exemplary bit of the data and what you have done and
what it didn't do that you had expected.
--
Good luck,
Abe
------------------------------
Date: 22 Aug 2000 14:48:21 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Lotsa difiiculties - need help with my Perl !!
Message-Id: <m3lmxp84ca.fsf@dhcp11-177.support.tivoli.com>
reg_exp@my-deja.com writes:
> @nuggs = split $file[1], /\[NUGGET\]/;
> when i run this, i get the error :
> "regexp too big at splitter line 39."
I believe that the above line is the source of the error and the
problem is that you've got your split arguments backwards.
perldoc -f split
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Tue, 22 Aug 2000 12:15:15 -0700
From: Frank Hanny <fchanny@lbl.gov>
To: mgjv@tradingpost.com.au, Abigail <abigail@foad.org>
Subject: Re: MS IIS and perl syntax errors causing download prompt
Message-Id: <39A2D143.163D1997@lbl.gov>
My apologies for not providing the context of the original posting (see
below). This appeared at the time to be a possible perl or cgi.pm
problem and the purpose of the follow up was to make clear that it was
not, hence the perl relevance.
Original post:
>Subject: syntax error in cgi script under IIS causes download prompt
>Date: Tue, 11 Jul 2000 11:30:38 -0700
>From: Frank Hanny <fchanny@lbl.gov>
>Organization: Lawrence Berkeley National Laboratory
>Newsgroups: comp.lang.perl.misc
>
>We are running perl ( Active State ver. 5.00503) CGI scripts from an NT
>server using Microsoft IIS.
>
>Ordinarily, syntax errors in the perl program display in the browser
>window. The commented out version of the "foreach" (with semicolon) in
>the
>sample program below produces:
>
>CGI Error
>The specified CGI application misbehaved by not returning a complete set
>of HTTP headers. The headers it did return are: syntax error at
>mypath\ftpbug.pl line 11, near "$msg;" Execution of mypath\ftpbug.pl
>aborted due to compilation errors.
>
>However, certain syntax errors (the foreach without the semicolon )
>cause the browser (both Netscape 4.73 and IE 5) to prompt the user to
>download the offending perl script, and no useful error messages are
>produced. This makes debugging difficult and presents a security
>problem.
>
>The sample program below will cause this condition.
>
>Is this an IIS configuration issue, a perl configuration issue, a perl
>bug, or something else? It has been suggested that IIS is reporting the
>wrong MIME type for the error message.
>
>Thanks for any assistance,
>
>Frank Hanny
>FCHanny@lbl.gov
>
>
>#!/bin/perl -w
>use strict;
>use CGI;
>
>my $q;
>my $msg;
>
>$q = new CGI;
>
>foreach $msg #<<<<<< syntax error causes download prompt
>#foreach $msg; #<<<<<< syntax error causes useful error msg
>
>print
> $q->header(),
> $q->start_html(),
> $msg,
> $q->end_html(),
> ;
>
>
Frank Hanny
Martien Verbruggen wrote:
>
> On Mon, 21 Aug 2000 12:55:48 -0700,
> Frank Hanny <fchanny@lbl.gov> wrote:
> > Regarding the issue I raised previously of certain perl cgi syntax
> > errors resulting in prompt from the browser to download the file:
>
> I don't see any mention of perl, Perl or even the---incorrect but often
> used in CGI context---PERL. I don't think this has anything to do with
> Perl at all. Could you please, in the future, post announcements like
> this to appropriate newsgroups.
>
> CGI new Perl
>
> And Perl most certainly ne IIS.
>
> Thank you.
> Martien
> --
> Martien Verbruggen |
> Interactive Media Division | Begin at the beginning and go on till
> Commercial Dynamics Pty. Ltd. | you come to the end; then stop.
> NSW, Australia |
------------------------------
Date: Tue, 22 Aug 2000 11:22:51 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: newbie question about "uninitialized variables"
Message-Id: <MPG.140c64d148d9341598acbb@nntp.hpl.hp.com>
In article <39a297e2.6817880@news.earthlink.net> on Tue, 22 Aug 2000
15:26:39 GMT, Jon S. <jonceramic@nospammiesno.earthlink.net> says...
> On Mon, 21 Aug 2000 16:11:46 -0700, Larry Rosler <lr@hpl.hp.com>
> wrote:
...
> Is there a way to make these warnings show up "pretty" in my returned
> html? I've got CGI::Carp going with fatalstoBrowser and a few warn
> and die statements, but I'd like to have my warnings go to the browser
> also. Right now, they get placed oddly in the output. (Like, in
> between words no where near the error in the script.) The only way to
> find them is to scan the output on either my telnet prompt or returned
> source, and I miss them half the time. Plus, with my forms heavy
> pages, entering 20 variables on the command line is a pain.
You might write your own $SIG{__WARN__} handler, which could gather up
all the messages so you can print them all later when you choose.
...
> Thanks Larry. I really appreciate all of the advice you give on these
> groups.
Notes like yours make it worth doing.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 22 Aug 2000 17:35:19 -0400
From: Omri Schwarz <ocschwar@mit.edu>
Subject: Re: Parse::Recdescent questions (<commit> and other problems.)
Message-Id: <39A2F217.5F1D1BFA@mit.edu>
Damian Conway wrote:
>
> Omri Schwarz <ocschwar@mit.edu> writes:
>
> > Right now for some reason the rule for return statements,
>
> > /return/ <commit> {print 'return';}
> > (expression[context => 'return'])(?) ';'
>
> > breaks because of whitespace preceding the return statement.
>
> That's *very* odd.
>
> > Parse::RecDescent::skip is '\s*'
>
> > Is that not what it ought to be?
>
> That's what it should be.
>
> Are you changing $skip anywhere (with a <skip:...> directive perhaps)???
Yes, but only in the rules that deal with CPP directives, and these
don't
get invoked in this sample.
------------------------------
Date: Tue, 22 Aug 2000 20:27:59 GMT
From: comet999 <comet999@my-deja.com>
Subject: PLEASE HELP !!! What is wrong with Windows...
Message-Id: <8nunnj$b2t$1@nnrp1.deja.com>
Hi,
I'm using the following code to dump the contents of a db ("cats.db")
and running into problems. The code works just fine on Unix. But, when
I try the same code on Windows NT the output is blank as if there were
no records in the database. On unix this code prints 4 records.
I'm using ActivePerl on Windows NT.
Can someone shed some light please. Thanks.
***********************************************************************
use AnyDBM_File;
%cats = &readdatabase("h:\data\cats");
while (($key,$value) = each %cats) {
print $key, ' = ', unpack('L', $value), "\n";
}
sub readdatabase
{
my %tmpHash;
tie( %tmpHash, "AnyDBM_File", $_[0], O_RDONLY | O_CREAT, 0664 );
my %tableHash = %tmpHash;
untie %tmpHash;
return %tableHash;
}
***********************************************************************
Also, I need to add a new column to the Hash once it is read from the
database and write it back. Could some one please provide a code sample.
Thanks,
-C.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 22 Aug 2000 20:27:36 GMT
From: comet999 <comet999@my-deja.com>
Subject: PLEASE HELP !!! What is wrong with Windows...
Message-Id: <8nunms$b2k$1@nnrp1.deja.com>
Hi,
I'm using the following code to dump the contents of a db ("cats.db")
and running into problems. The code works just fine on Unix. But, when
I try the same code on Windows NT the output is blank as if there were
no records in the database. On unix this code prints 4 records.
I'm using ActivePerl on Windows NT.
Can someone shed some light please. Thanks.
***********************************************************************
use AnyDBM_File;
%cats = &readdatabase("h:\data\cats");
while (($key,$value) = each %cats) {
print $key, ' = ', unpack('L', $value), "\n";
}
sub readdatabase
{
my %tmpHash;
tie( %tmpHash, "AnyDBM_File", $_[0], O_RDONLY | O_CREAT, 0664 );
my %tableHash = %tmpHash;
untie %tmpHash;
return %tableHash;
}
***********************************************************************
Also, I need to add a new column to the Hash once it is read from the
database and write it back. Could some one please provide a code sample.
Thanks,
-C.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 22 Aug 2000 20:33:55 GMT
From: rita_nc@my-deja.com
Subject: Problem with PPM working
Message-Id: <8nuo3i$bmf$1@nnrp1.deja.com>
I'm trying to follow the suggestion of using a
database proxy to communicate between an MS
database and a Linux box. I've repeatedly tried
to simply install the DBI.ppd from ActiveState
(and a number of other places). If I type in
ppm
ppm>install DBI
or
ppm>install DBI.ppd
I get one out of two error messages. "HTTP POST
failed. (read timeout)
or it "hangs"
I've also tried downloading and the DBI zip file,
unzipping it and then issuing
ppm install DBI.ppd (in the same directory the
unzipped file is).
I then get "could not locate a PPM binary of
'DBI.ppd for this platform"
What's wrong?
How can I fix it?
Thanks!!!!
Rita
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 22 Aug 2000 14:24:06 -0700
From: "Gabe" <grichard@uci.edu>
Subject: Rationale Behind 'Use of Uninitialized Value' Warning
Message-Id: <8nurbe$80e$1@news.service.uci.edu>
I have not been using -w because I don't like getting all the "Use of
Uninitialized Value" warnings. What's the value of the warning? Why is it
better to say "my $foo = '';" as opposed to "my $foo;"? The latter is
quicker to type, and doesn't seem to increase my probability of making
programming errors. So what gives?
The people who wrote Slash seem to agree too.
Gabe
------------------------------
Date: Tue, 22 Aug 2000 21:58:43 GMT
From: "Blair Heuer" <blair@geo-NOSPAM-soft.org>
Subject: Re: regexing html-like tags
Message-Id: <nICo5.675$yH2.35361@newsread2.prod.itd.earthlink.net>
> Well, there is more than one way to do this, obviously. I've
> written a perl script that does some similar parsing. I use
> two character end values that I can guarantee won't be inside
> the tags, except for one deep variable substutitions. My code
> does not go through the attributes and find them all, though.
> Rather the functions that deal with each command ("out" is the
> command here) check for each attribute they need.
>
> Below is some code from it you can use or just study.
> My tags look like:
<snipped for space>
Thanks. Those regexes will probably come in handy.
Also, thanks for being 100 times more polite than Godzilla. :)
-Blair
------------------------------
Date: Tue, 22 Aug 2000 22:03:37 GMT
From: "Blair Heuer" <blair@geo-NOSPAM-soft.org>
Subject: Re: regexing html-like tags
Message-Id: <ZMCo5.686$yH2.35165@newsread2.prod.itd.earthlink.net>
> Originating author indicated "tags" in a template
> or a string, something, input of sorts, whatever.
> He did not indicate a single tag, with serious syntax
> errors at that, as shown in his example. Tags is plural
> Rosler, indicating any possible combination of "tags"
> is likely, whatever the Hades this author means by tags.
Wait, I thought my term "tags" was vague and made absolutely no sense. How
is it that you correct Larry Rosler, when he actually had more comprehension
than you ever did. As I said, Larry Rosler's script was a great base for me
to use for my script. I was able to use it in a context where each tag is
fed to it, since each is processed individually to get it to work perfectly.
Your rants about how poor I am at communicationg, though, failed to compiled
when I tried to use them in my code. Hmm, who was more helpful?
> Really should work on your reading comprehension, Rosler,
> just as this originating author should work on his
> writing skills and communicative skills.
Communicative? Which class was it that you took on this? Ridicule 101? Isn't
this newsgroup for helping people? If you don't want to help people than you
don't have to read and post to this newsgroup. It's your choice to be here,
don't be so bitter.
-Blair
------------------------------
Date: Tue, 22 Aug 2000 21:24:32 GMT
From: pape_98@my-deja.com
Subject: Re: Sorting by a subfield (WAS: Re: This is my last question, I swear!!!!!!!!!!)
Message-Id: <8nur1v$euv$1@nnrp1.deja.com>
I find it difficult to understand what the programmer is saying in
these lines:
> @sorted = map "${\ (unpack 'na*', $_)[-1] }" => sort map pack
> ('na*', /B1D-(\d+),/?$1:0, $_ ) => @unsorted;
The only thing I can decipher from this is that I each time I sort, the
expression B1D- is being removed. The reason why I can't do much with
the rest is that I don't quite know what it means.
Would someone like to explain it to me.
And this doesn't allow to perform a "correct" numerical sort does it??
In article <MPG.140b3086cf77ae4d98acaf@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
> [This is a followup to an existing thread. You shouldn't start a
new
> thread for it. Also, your Subject tells more about you than about
your
> problem. I have changed it.]
>
> In article <8nruvu$36o$1@nnrp1.deja.com> on Mon, 21 Aug 2000 19:13:22
> GMT, pape_98@my-deja.com <pape_98@my-deja.com> says...
> > here is my database,
> >
> > NIH,10B-410,01 36,13 5 26,15 43,1 5 2 5 2 4
> > NIH,6B-4,01 36,13 5 26,15 43,1 5 2 5 2 4
> > Suburban,6C-258,52 51,5256,15 13,152
> > Suburban,ACardiology,52 51,5256,15 13,152
> > NIH,9B-4,01 36,13 5 26,15 43,1 5 2 5 2 4
> > NIH,15-410,01 36,13 5 26,15 43,1 5 2 5 2 4
> > NIH,60B-410,01 36,13 5 26,15 43,1 5 2 5 2 4
> > NIH,B1D-416,52,135 6,1513,52 hi,
> > NIH,B1D-43,01 36,13 5 26,15 43,1 5 2 5 2 4
> > Suburban,10C-58,52 51,5256,15 13,152
> > Suburban,1B-29,52 51,5256,15 13,152
> > NIH,B1D-403,01 36,13 5 26,15 43,1 5 2 5 2 4
> > NIH,B1D-410,52 51 36,135 256,15413,1512
> > Suburban,6B-281,52 51,5256,15 13,152
> > Suburban,Office,52 51,5256,15 13,152
> >
> > here is my script,
> >
> > #!/usr/bin/perl
>
> You forgot the '-w' flag on that line.
>
> > use strict;
> >
> > use vars qw(@unsorted @sorted @new $a $b $c);
>
> You have declared @unsorted as a global variable.
>
> > open (SORTER,"/applications/apache/cgi-bin/pape/box") or die "Can't
> > open file: $!\n";
> >
> > chomp(my @unsorted = <SORTER>);
>
> Here you declare @unsorted as a lexical variable, which is better.
> Drop the 'use vars' statement and use 'my' wherever needed. $a and
$b
> needn't be declared (perldoc -f sort), and $c is just wrong -- see
> below.
>
> > @sorted = map "${\ (unpack 'na*', $_)[-1] }" => sort map pack
> > ('na*', /B1D-(\d+),/?$1:0, $_ ) => @unsorted;
>
> You have added data which makes the above sortkey extraction
inadequate.
> You should be able to fix it yourself by changing the regex.
>
> > @sorted = sort { $a cmp $b } @unsorted;
>
> This line overwrites the careful numerical sort from the previous
> statement with a lexicographic sort.
>
> > @new = sort { $b <=> $c } @sorted;
>
> Surely you meant '$a', not '$c'. But why do this? The'-w' flag
would
> have shown you the folly of this statement.
>
> ...
>
> > now my question is, what do I have to change in my script to get the
> > output in that format but have the numbers sorted out in order (i.e
> > 1,2,10,12,14,22, etc...)
>
> See above.
>
> > Please help me. I'm new to perl and have no idea what to do here.
I've
> > even tried combining the different sorting techniques.
>
> Yes, without complete understanding.
>
> You are doing a lot of copying and pasting, without stopping to grasp
> fully what is being given by members of this newsgroup. Take a few
deep
> breaths, stop typing, and start reading the code for understanding.
>
> The sorting technique you are using is described in detail in the
> following:
>
> http://www.hpl.hp.com/personal/Larry_Rosler/sort/
>
> --
> (Just Another Larry) Rosler
> Hewlett-Packard Laboratories
> http://www.hpl.hp.com/personal/Larry_Rosler/
> lr@hpl.hp.com
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 22 Aug 2000 21:54:57 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Sorting by a subfield (WAS: Re: This is my last question, I swear!!!!!!!!!!)
Message-Id: <8nusrh$dc0$5@slb3.atl.mindspring.net>
pape_98@my-deja.com wrote:
: I find it difficult to understand what the programmer is saying in
: these lines:
:
: > @sorted = map "${\ (unpack 'na*', $_)[-1] }" => sort map pack
: > ('na*', /B1D-(\d+),/?$1:0, $_ ) => @unsorted;
:
: The only thing I can decipher from this is that I each time I sort, the
: expression B1D- is being removed. The reason why I can't do much with
: the rest is that I don't quite know what it means.
When you're trying to understand an expression that uses operators like
grep, map, or sort, you often have to read it from end to front.
The last map iterates over each element of @unsorted and creates a new
list of scalars each consisting of a number (in binary format) followed by
the original element. If the original element contained "B1D-" followed
by a string of digits, the number will be the one represented by that
string of digits, otherwise it will be zero.
The sort sorts that list. Sorting numbers in packed binary form, even
with Perl's default lexicographic comparison routine, will put them in
proper numeric order.
The first map (which is the final one to execute) simply strips the packed
binary number off of each element of the sorted list, giving a list of the
original scalars in sorted order. It's written in what's IMHO an
excessively tricky manner (using a reference trick to interpolate a
function call into a quoted string rather than using a block), but this
may have been done to speed things up.
------------------------------
Date: Tue, 22 Aug 2000 19:21:30 GMT
From: swan_daniel@my-deja.com
Subject: Re: system() output screwing up redirection.
Message-Id: <8nujr1$6b3$1@nnrp1.deja.com>
In article <fano5.56196$rd1.10401651@typhoon-news1.southeast.rr.com>,
"Philip Garrett" <philipg@atl.mediaone.net> wrote:
> <swan_daniel@my-deja.com> wrote in message
> news:8nsqss$41g$1@nnrp1.deja.com...
> > This did help, Philip, but now the script executes fine, but the
system
> > function is not executed... I can tell, because the web pages it is
> > suppost to create do not exist.
> <snip>
> > system("/usr/local/bin/ipacsum --timeframe \"$forminput\" --gif
> > $TRAFDIR --gif-index /home/httpd/html/traffic/index${time}.html
> > --png-caption-in-index --png-asis --fixed-quantity M --png-height
480
> > --png-width 640 > /dev/null 2>&1");
> >
> > Thoughts?
>
> Does the user that your web server is running as (usually nobody)
have write
> permissions to the file you're writing? If you can write to the
file, but
> the web server can't, that would be the first place I would look.
You were right on the money, Philip! I su'd to nobody, and ran the
script from the command line. Saw lots of errors that weren't being
reported elsewhere. Interesting. Changed some ownership, and problem
solved!
Thanks a lot,
Dan.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 22 Aug 2000 21:16:52 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: Unexpected behavior of shift in a loop
Message-Id: <qej5qss4fk05haet3bh2tqtr9i2otbq76g@4ax.com>
On Tue, 22 Aug 2000 14:22:07 GMT, jeffahill@lucent.com (Jeff HIll)
wrote:
> I have a program where I'm taking some information generated by SAP
> and pushing it on to a web page. I came across a curious behavior of
> the shift command and wondered if someone could explain this to me.
>
> Here is the code:
>
> open (FILE, "/prd1/bmp/mfg/parts/total/SIPP") || die "Can't open file
> $!";
> while (<FILE>) {
> $line = $_;
> $line =~ s/^\s*(.*?)\s*$/$1/g;
> $line =~ s/\s+/ /g;
> @items = split(/ /, $line);
If you use the default split() there is no need to take out all those
spaces:
my @items = split;
or using a named variable:
my @items = split ' ', $line;
> $list = join ';', $items[0],$items[1],$items[2],$items[3];
> shift @items;
> shift @items;
> shift @items;
> shift @items;
This is what splice() does:
my $list = join ';', splice @items, 0, 4;
You could write the body of that while like:
my @items = split;
my $list = join';', splice(@items, 0, 4), join ' ', @items;
print "$list\n";
--
Good luck,
Abe
------------------------------
Date: 22 Aug 2000 14:09:17 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Unexpected behavior of shift in a loop
Message-Id: <m3snrx865e.fsf@dhcp11-177.support.tivoli.com>
marcel@codewerk.com (Marcel Grunauer) writes:
> while (<FILE>) {
> s/^\s*//;
> s/\s*$//;
> s/\s+/ /g;
> my $list = join ';' => split /\s+/, $_, 5;
> print $list . "\n";
> }
You can use the magic whitespace handling of split to dispense with the
need for the substitutions. I'll leave it to you to decide if it is
worth it or not (a quick benchmark versus the above code shows a
slight improvement in performance).
while (<FILE>) {
my @fields = split;
print join(";", @fields[0..3]), " ", join(" ", @fields[4..$#fields]), "\n";
}
Off-thread-topic-side-note: I tried to use [4..-1] initially. I don't
know if it was because of the previous thread related to that, or
because it just felt like it should work. Of course, it didn't, but
it still feels like it should....
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 4098
**************************************