[18294] in Perl-Users-Digest
Perl-Users Digest, Issue: 462 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Mar 10 21:05:45 2001
Date: Sat, 10 Mar 2001 18:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <984276310-v10-i462@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 10 Mar 2001 Volume: 10 Number: 462
Today's topics:
Re: "uninitiatlized value" errors? <jazrant@zsc.nrcan.zc.ca>
[Fwd: Hash of Hashes problem - someone explain why this <tommiy@ozemail.com.au>
CGI NNTP Client? <mjj@pp.fi>
Re: create a text file in DOS format. <Bing@home.com>
Re: Detecting User Country in CGI Script <Juha.Laiho@iki.fi>
Re: GDBM <s1sims@home.com>
Help! Function call gives error 500! <shamilton@plateausystems.holdthespam.com>
Re: Help! Function call gives error 500! (Tad McClellan)
Re: Help! Function call gives error 500! <bart.lateur@skynet.be>
How can I create files in directories other than the on <costas@seleucia.tamu.edu>
Re: How do I DROP a table using XBase module (Honza Pazdziora)
Re: How do I DROP a table using XBase module (Honza Pazdziora)
Re: How do I get the name of a variable as a string? <donotreply@interbulletin.bogus>
Re: How do I get the name of a variable as a string? <donotreply@interbulletin.bogus>
Re: How do I get the name of a variable as a string? <Juha.Laiho@iki.fi>
Re: How do I get the name of a variable as a string? (Tad McClellan)
Re: How do I get the name of a variable as a string? <bart.lateur@skynet.be>
Re: if($array1[1] eq $string1) DOESN'T WORK?? (David H. Adler)
Re: if($array1[1] eq $string1) DOESN'T WORK?? <tommiy@ozemail.com.au>
Re: Macbeth and Perl threads <vdhamer@msn.com>
Re: Maintaining the number format and not exponential <godzilla@stomp.stomp.tokyo>
Re: Maintaining the number format and not exponential <uri@sysarch.com>
Re: Maintaining the number format and not exponential <godzilla@stomp.stomp.tokyo>
newbie Q : problems with using 'use lib qw(....' to poi <nospamplease@thankyou.com>
Re: RFC: FAQ3 update -- Using less memory (Kai =?iso-8859-1?q?Gro=DFjohann?=)
Re: scalar(localtime) in reverse? <sorryno@email.at.all>
Re: scalar(localtime) in reverse? <wyzelli@yahoo.com>
Re: XS - typemap void ? (Ilya Zakharevich)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 10 Mar 2001 20:54:40 -0500
From: "John A. Grant" <jazrant@zsc.nrcan.zc.ca>
Subject: Re: "uninitiatlized value" errors?
Message-Id: <98em0o$5tm9@nrn2.NRCan.gc.ca>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrn9ack2f.9vo.tadmc@tadmc26.august.net...
> John A. Grant <jazrant@zsc.nrcan.zc.ca> wrote:
[...]
> When perl says "uninitialized value" you should think "undef".
> You are using the special "undef" value somewhere in your program.
Yes, I am using "undef", here:
DoIt($reason,$title,$config,\%captions,\%param,
$param{$VAR_EMAIL},undef,undef,1,$font3);
In the function, I have:
my ($reason, $title, $config, $refcaptions, $refparam,
$to, $cc, $bcc, $ccquery, $font3)=@_;
...
if($cc) ...
if($bcc) ...
There are other calls to DoIt(), which have valid strings.
In this case, I don't need $cc or $bcc, so I want to pass
a 'null' value. In C, I would just pass NULL (null pointer) to
the function instead of a string. Perhaps 'undef' is not
appropriate for a NULL "pointer to a string"?
I don't see how this use of 'undef' affects code hundreds
of lines away, especially in another function.
> >1547: my $lastslash=rindex($filename,"/");
> >1548: if($lastslash){
> >Use of uninitialized value in rindex at contact.cgi line 1547.
> >Use of uninitialized value in substr at contact.cgi line 1548.
>
> Looks like $filename got the undef value somehow.
Here's the complete function:
#return filename part of pathname
sub FilenameFromPathname()
{
my ($pathname)=@_;
my $filename=$pathname;
my $lastslash=rindex($filename,"/");
if($lastslash){
$filename=substr $filename,$lastslash+1;
}
return $filename;
}
That raises another issue. I never know whether to refer
to function parameters as "@" or "$".
> >On reflection, I see I've used both "==" and "eq" in my program.
> >for strings, i.e.:
> > if($xxx=="hello")
>
> Aren't you getting a warning about "isn't numeric" there?
My mistake. The Perl program contains a block of JavaScript
code that is emitted to an HTML page. I was getting the
Perl & JS mixed up.
I still have this problem:
1703: my $method=$ENV{'REQUEST_METHOD'};
1704: if($method eq "POST"){
Use of uninitialized value in string eq at contact.cgi line 1704.
Use of uninitialized value in string eq at contact.cgi line 1704.
Why do I get 2 errors?
This problem still remains:
my $MAGIC_NOHTML="!";
...
1639: if (substr($message,0,1) eq $MAGIC_NOHTML){ ...
"Use of uninitialized value in string eq at contact.cgi line 1639.
> Use == to compare numbers.
> Use eq to compare strings.
Ok, thanks. That's clear enough.
> >But 2>err doesn't work on my solaris box (also running perl 5.6)
> ^^^^^^^
> The OS is not an issue, the _shell_ used may be the issue though.
> That should work in Bourne-ish shells.
> Were you perhaps using a csh-ish shell instead?
Yes, I use csh. Can't it be done with csh? That's odd.
Thanks for the help.
--
John A. Grant * I speak only for myself * (remove 'z' to reply)
Radiation Geophysics, Geological Survey of Canada, Ottawa
If you followup, please do NOT e-mail me a copy: I will read it here
------------------------------
Date: Sun, 11 Mar 2001 08:31:24 +1000
From: tommiy <tommiy@ozemail.com.au>
Subject: [Fwd: Hash of Hashes problem - someone explain why this works]
Message-Id: <3AAAAB3C.69EBD82F@ozemail.com.au>
This is a multi-part message in MIME format.
--------------ECFB32F78264ECC0F2854EEB
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Resending this because it appears to have been removed from the
list.....weird
--------------ECFB32F78264ECC0F2854EEB
Content-Type: message/rfc822
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
X-Mozilla-Status2: 00000000
Message-ID: <3AAAA297.34B51DB6@ozemail.com.au>
Date: Sun, 11 Mar 2001 07:54:31 +1000
From: tommiy <tommiy@ozemail.com.au>
X-Mailer: Mozilla 4.75 [en] (X11; U; Linux 2.2.17-21mdk i686)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.lang.perl.modules
Subject: Hash of Hashes problem - someone explain why this works
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
I have this script that is basically out of the perldsc man page and
functions as one would expect...
#!/usr/bin/perl
# reading from file # flintstones: lead=fred pal=barney wife=wilma
pet=dino
$line[0]="flintstones: lead=fred pal=barney wife=wilma pet=dino";
$line[1]="jetsons: boy=elroy dog=astro";
foreach $x (@line) {
next unless $x=~s/^(.*?):\s*//;
$who = $1;
for $field ( split /\s/,$x ) {
($key, $value) = split /=/, $field;
$HoH{$who}{$key} = $value;
}
}
print %HoH;
print $HoH{'jetsons'}{'boy'};
print;
As one would expect this sets up a hash of hashes. Dumping the %HoH
variable shows a complex data stucture. A friend of mind changed this to
keep account of the number of times things are traversed and changed it
to do this. In effect giving the $HoH{$who} a value. I told him that
this wouldn't work but in fact it does... Taking the above and doing
this to it proves it does....
#!/usr/bin/perl
# reading from file # flintstones: lead=fred pal=barney wife=wilma
pet=dino
$line[0]="flintstones: lead=fred pal=barney wife=wilma pet=dino";
$line[1]="jetsons: boy=elroy dog=astro";
foreach $x (@line) {
next unless $x=~s/^(.*?):\s*//;
$who = $1;
$HoH{$who}=1;
for $field ( split /\s/,$x ) {
($key, $value) = split /=/, $field;
$HoH{$who}{$key} = $value;
}
}
print %HoH;
print $HoH{'jetsons'}{'boy'};
print;
Now if you print $HoH{'flinstones'} the answer is 1 and the final print
of $HoH{'jetsons'}{'boy'} returns elroy...... looking at the data
structure for %HoH shows a straight hash and nothing else.....so how
does the above work??? I'm confused it appears as though perl still
knows that this is a hash of hashes but a dump doesn't show
it.....please help
--------------ECFB32F78264ECC0F2854EEB--
------------------------------
Date: Sun, 11 Mar 2001 01:39:13 GMT
From: Mikko Jussilainen <mjj@pp.fi>
Subject: CGI NNTP Client?
Message-Id: <5HAq6.2113$a83.109855@news.kpnqwest.fi>
Hi,
I am looking for a good CGI or PHP web based news client. It can be
commercial or free as long as it works. I am not interested in having one
written from scratch or writing one myself. It should have the following
features:
1. Allows easy reading and posting to newsgroups.
2. Does not require javascript or cookies. Should work with any browser.
3. Has next and next in thread capbilities, with full threading of articles.
4. Does not require copying news articles from nntp server and converting
them to html with mhonarc or similar so that the web server can serve them
to clients.
5. Must work with Apache. (no window$ code)
It would be nice if users could log in, so that the system would remember
which articles they had read in some type of server side database. Also
some searching capabilities would be great, but not absolutely necessary.
Please send any recommendations to me.
Thanks,
Mikko
------------------------------
Date: Sat, 10 Mar 2001 22:43:04 GMT
From: Bing Santos <Bing@home.com>
Subject: Re: create a text file in DOS format.
Message-Id: <3AAAAD06.B66533ED@home.com>
Thanks a lot everybody for the help. I'm really impressed how quick the
response was to my problem. Galen, your solution is exactly what I
needed. It worked. Thanks a bunch.
Bing
Galen Menzel wrote:
>
> Try ending each line with "\r\n" instead of just "\n" when you are printing to
> the file.
>
> galen
>
> Renato Santos wrote:
> >
> > How do I create a text file in UNIX perl that is in DOS format rather
> > than UNIX?
> >
> > I tried the system("/bin/UNIX2DOS $file1 $file2"); but it keeps giving
> > me a server error. I'm using the perl script to create a text file from
> > a user input and the file has to be read by an NT machine.
> >
> > I also tried using the binmode function after I open the filehandle but
> > that did not work either.
> >
> > The file looks fine in UNIX but when I open it in WindowsNT it is all
> > just one long line. The carriage return for each line is ignored.
> >
> > Any clue? I'm really a newbie with PERL so please excuse me if this
> > question is too trivial.
> >
> > Bing
------------------------------
Date: 10 Mar 2001 14:59:12 GMT
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: Detecting User Country in CGI Script
Message-Id: <98dfg0$d61$1@ichaos.ichaos-int>
Bart Lateur <bart.lateur@skynet.be> said:
>MartelLM wrote:
>>Does anyone know of a way in Perl or any other langues for that matter that
>>will allow me to detect a user's country in a CGI script.
>
>No you can't. Not easily. For example, there are Belgian websites which
>use a ".com" for a root domain. And what country is ".net" from? Heaven
>knows. It could, for example, be Holland, or the Phillipines.
>
>You could, in principle, do a Whois search on the domain name, and parse
>the record you get back. See for example
><http://www.geektools.com/cgi-bin/proxy.cgi>. (That's a site that works
>with international domains, too).
... and even then it'll be only partially correct for multinationals
using a single domain (f.ex. .nokia.com; might be in the US as well
as in the Europe).
------------------------------
Date: Sat, 10 Mar 2001 22:52:10 GMT
From: Tuxman <s1sims@home.com>
Subject: Re: GDBM
Message-Id: <3AAAB0B9.4D3D558@home.com>
Tuxman wrote:
> Hello,
>
> Anyone know of a good website that
> demonstrates the use of the GDBM module in Perl
> syntax. All documentation I've found is given in C
> syntax. Maybe I'm stupid and should be able to
> translate from $C->{Perl}. Or am I supposed to
> embed C in Perl, someone enlighten me por favor,
>
> Tuxman
Nevermind, I woke up the next morning and figured it
out,
Tuxman
------------------------------
Date: Sat, 10 Mar 2001 23:09:28 GMT
From: "Scott" <shamilton@plateausystems.holdthespam.com>
Subject: Help! Function call gives error 500!
Message-Id: <Iuyq6.169144$B6.37388564@news1.rdc1.md.home.com>
Here's a real mystery. I have a perl script that USES a module that I
wrote. It calls a function in that module (call it module A). That
function, in turn, calls ANOTHER function in ANOTHER module (that I wrote)
that is USEd in module A:
main script --> myFunction()
calls
module A --> mySecondFunction()
calls
module B --> myFinalFunction()
Now, as soon as the call to myFinalFunction() is reached, the server throws
up a 500 server error (and I can't get to the server logs). If I comment
out that line, the code after it is reached without any problems. And,
here's the real weird part: there's another function in module A that also
calls module B's myFinalFunction() and it works fine - every time.
Even if I comment out every line in mySecondFunction() except the call to
myFinalFunction(), I get the server error.
Can anyone even begin to suggest why a call to a function works fine in one
case and blows up in the second?
Here are the things I have ruled out:
1. The myFinalFunction() is NOT being called - if I put debug tracking
information as the very 1st line there it never gets called.
2. The scripts all compile without any errors, so it's not syntactical or
anything.
3. The parameter to the function is a literal string, and even if I do the
exact same one as the version that works, it blows up.
4. It should not be a stack overflow, as the other usage of the function
call that works goes the same level deep in the stack with similar, if not
exact, parameter profiles.
5. It's JUST that particular function that I call. If I call a different
function in module B at that point, the call succeeds.
6. It's not the actual code in that function. If I copy the code verbatim
and paste it into the mySecondFunction() body in place of the function call,
it works fine.
I've already pulled out all my head hair, and I don't wanna get started
pulling any other hairs out, so PLEASE, if someone can suggest anything at
all, that'd be great!
Thanks,
Scott
------------------------------
Date: Sat, 10 Mar 2001 19:16:21 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Help! Function call gives error 500!
Message-Id: <slrn9algul.kms.tadmc@tadmc26.august.net>
Scott <shamilton@plateausystems.holdthespam.com> wrote:
>the server throws
>up a 500 server error (and I can't get to the server logs).
So run your program from the command line, and watch stuff
go by on the terminal.
It is easy to run your Perl CGI program from the command line
if you are using the CGI.pm module.
Or, see the messages in a browser, Perl FAQ, part 9:
"How can I get better error messages from a CGI program?"
Your ISP sucks if they don't give you some form of access to
the server logs. Web hosting is pretty darn cut throat, there
are dozens of other places. Look around until you find one with
some sense.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 11 Mar 2001 01:32:21 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Help! Function call gives error 500!
Message-Id: <a9llatojtojj1ngocej7fuhrbq573de9hm@4ax.com>
Scott wrote:
>Now, as soon as the call to myFinalFunction() is reached, the server throws
>up a 500 server error (and I can't get to the server logs). If I comment
>out that line, the code after it is reached without any problems.
I'll venture a guess, first: you might have a package scope problem. If
you "require" the same library file twice in two different packages, it
will actually be loaded only once, and the second time, no subs will
appear in the caller package.
And now, a tip for debugging:
use CGI::Carp 'fatalsToBrowser';
--
Bart.
------------------------------
Date: Sat, 10 Mar 2001 19:30:58 -0600
From: Costas Tzimeas <costas@seleucia.tamu.edu>
Subject: How can I create files in directories other than the one that the perl script executes from?
Message-Id: <3AAAD552.9B71A87F@seleucia.tamu.edu>
How can I create files in directories other than the one that the perl
script executes from?
I guess I could move the files to any other directory after the script
is done writting
to these files but is there any way the files are "directly" created in
that "other" directory?
Thanks in advance,
Costas
Perl newbie
------------------------------
Date: Thu, 8 Mar 2001 19:45:11 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: How do I DROP a table using XBase module
Message-Id: <slrn9afoa4.384.adelton@nemesis.fi.muni.cz>
On Thu, 01 Mar 2001 13:04:31 -0500, Don <don@lclcan.com> wrote:
>
> I am using the XBase module. I need to create a table each time my
> script is run. If the table exists, it should be overwritten. My code
> for creating is:
>
> my $newtable = XBase->create("name" => "copy.dbf",
> "field_names" => [ "ID", "MSG" ],
> "field_types" => [ "N", "C" ],
> "field_lengths" => [ 6, 40 ],
> "field_decimals" => [ 0, undef ]);
>
> However, the docs state that the above statement will NOT overwrite if
> it already exists. It then states that the table must be DROPPED first
> via the "drop" method. Unfortunately, the docs don't state how to use
> it nor is there an example.
my $oldtable = new XBase "copy";
$oldtable->drop;
my $newtable = = XBase->create("name" => "copy.dbf",
... rest of your code
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
.project: Perl, mod_perl, DBI, Oracle, auth. WWW servers, XML/XSL, ...
Petition for a Software Patent Free Europe http://petition.eurolinux.org
------------------------------------------------------------------------
------------------------------
Date: Thu, 8 Mar 2001 20:20:16 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: How do I DROP a table using XBase module
Message-Id: <slrn9afqbu.384.adelton@nemesis.fi.muni.cz>
On 3 Mar 2001 10:52:01 -0000, Jonathan Stowe <gellyfish@gellyfish.com> wrote:
>
> Of course this all begs the question why the OP isnt using DBD::XBase where
> the SQL syntax 'DROP TABLE foo' would work. DBD::XBase is installed alongside
> XBase nowadays.
While I encourage everyone to use DBD::XBase instead of plain
XBase.pm, I can understand that there are situations when using
XBase.pm is a must -- not having DBI, using index files, something
like that.
But you're right: with DBD::XBase and SQL we'd all be much happier. :-)
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
.project: Perl, mod_perl, DBI, Oracle, auth. WWW servers, XML/XSL, ...
Petition for a Software Patent Free Europe http://petition.eurolinux.org
------------------------------------------------------------------------
------------------------------
Date: Sat, 10 Mar 2001 20:45:53 +0000
From: Prem <donotreply@interbulletin.bogus>
Subject: Re: How do I get the name of a variable as a string?
Message-Id: <3AAA9281.5128CEAD@interbulletin.com>
Tad,
Appreciate your response.
The links you provided have been helpful.
http://perl.plover.com/ is good site for perl, has lot of info.
Thanks.
You wrote : "Your question is a reliable indicator of a poor design".
I admit, I started using perl a just few months ago, am still
learning the language and I apparently do not have your level
of expertise, or would have recognized it is a "reliable indicator
of a poor design"!
Just made me wonder, if you were jumping to "conclusion" here!,
specially without knowing the complete picture!.
Lets assume...
1) Maybe I have no practical purpose for this function
"GetVarNameAsString" and am just exploring the language,
hoping to learn more about it by going off path.
OR
2) Maybe I am trying to write something generic to help in debugging
my programs by printing a variable name along with its data every
time a variable is updated using tie.
something like [ Var : $myvar1, old value=100, new value=200 ].
I do not know if it is possible, and I might be doing it the wrong way,
or if it has been done by someone
and is available as a module that I could use.
OR
3) Maybe I am trying to implement the function for one of my programs,
I have no idea of what I am doing and as you mentioned,its a bad design
Go ahead Tad, take your pick! but I feel, stating my question as a
"reliable indicator of a poor design" was done without being aware
of finer details.
I do really appreciate the time you took to responsed.
and the 3 links you provided were helpful.
Thanks again.
best,
Prem
tadmc@augustmail.com (Tad McClellan) wrote in article
<slrn9ak6l0.ioi.tadmc@tadmc26.august.net> :
>[ Please limit your line lengths to the conventional 70-72 characters ]
>
>
>Prem <donotreply@interbulletin.bogus> wrote:
>>
>>Question: Is it possible to get the variable name as a string, if so how?
>
>
>Why do you think you need to do this?
>
>Your question is a reliable indicator of a poor design.
>
>Explain a bit about why you need to know the variable's name, and
>we can help you redesign it so that you do not need to know the
>variable's name.
>
>
>>$myvar1str=GetVarNameAsString($myvar1);
>># GetVarNameAsString should return "myvar1"
>
>>Any suggestins where I should start looking
>
>
>I get the feeling that you are headed toward the slippery slope
>of "Symbolic references". You do not want to go there. You
>should see if there isn't some other way to get what you need.
>
> http://www.plover.com/~mjd/perl/varvarname.html
> http://www.plover.com/~mjd/perl/varvarname2.html
> http://www.plover.com/~mjd/perl/varvarname3.html
>
>
>
>>for the solution if
>
>
>The solution often involves the use of a hash.
>
>
>>I need to write the function "GetVarNameAsString".
> ^^^^^^^
>>'perl internals' or is there an easy solution?
>
>
>Redesign your approach so that you do not need that.
>
>
>--
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
_______________________________________________
Submitted via WebNewsReader of http://www.interbulletin.com
------------------------------
Date: Sat, 10 Mar 2001 20:49:04 +0000
From: Prem <donotreply@interbulletin.bogus>
Subject: Re: How do I get the name of a variable as a string?
Message-Id: <3AAA9340.4ECD56B0@interbulletin.com>
Chris,
Appreciate the time you put in to respond, Thanks
Prem
Chris Stith <mischief@velma.motion.net> wrote in article
<takch4h0b65o0b@corp.supernews.com> :
>Prem <donotreply@interbulletin.bogus> wrote:
>
>> Hello,
>
>> Question: Is it possible to get the variable name
>> as a string, if so how?
>
>Why would be a better question, I think. Either you're
>misunderstanding something here or I am. I won't rule
>out that I am, especially before 8 AM on Saturday, but
>I don't see why you need to do this.
>
>> $myvar1str=GetVarNameAsString($myvar1);
>> # GetVarNameAsString should return "myvar1"
>
>$myvar1str = 'myvar1'; # does the same thing
>
>> $myvar1str=GetVarNameAsString(@myvar2);
>> # GetVarNameAsString should returns "myvar2"
>
>$myvar2str = 'myvar2'; # ditto
>
>> Any suggestins where I should start looking for
>> the solution if I need to write the function
>> "GetVarNameAsString". 'perl internals' or is
>> there an easy solution?
>
>My questions are:
>
> Any easy solution to what?
>
> Why do you need to return the name of a variable
> you just typed in on the same line?
>
> Are you sure you don't want to use a hash?
> (This sound like a generalized PSI::ESP response,
> but see Note 1 for why it's not.)
>
> What are you trying to accomplish in the program
> that needs this functionality?
>
>
>> Thanks in advance.
>
>You're welcome to whatever minimal help I might have
>offered.
>
>Note 1:
> This is a specific PSI::ESP response. The OP may
> want to use a hash because you can often use a
> scalar variable to store the value of a hash key,
> then access the value of that key by doing something
> like this:
> $foo = 'bar';
> print $foo . '=' . $baz{$foo} . "\n";
>
>Chris
>
>--
>Christopher E. Stith
>The purpose of a language is not to help you learn the
>language, but to help you learn other things by using the
>language. --Larry Wall, The Culture of Perl, August 1997
>
_______________________________________________
Submitted via WebNewsReader of http://www.interbulletin.com
------------------------------
Date: 10 Mar 2001 15:05:09 GMT
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: How do I get the name of a variable as a string?
Message-Id: <98dfr5$d61$2@ichaos.ichaos-int>
Prem <donotreply@interbulletin.bogus> said:
>Question: Is it possible to get the variable name as a string, if so how?
Hmm.. I think it should be doable via the symbol table, but I don't know
the details (never needed this).
Typically when this kinds of questions are asked, the good solution for
the real problem behind the question has been to use hashes.
------------------------------
Date: Sat, 10 Mar 2001 17:26:29 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How do I get the name of a variable as a string?
Message-Id: <slrn9alagl.k9p.tadmc@tadmc26.august.net>
[ Please put your comments *following* the quoted text that you
are commenting on.
Please do not quote an entire article.
Please never quote .sigs.
Please visit: http://www.geocities.com/nnqweb/nquote.html
Thanks.
]
Prem <donotreply@interbulletin.bogus> wrote:
>
>You wrote : "Your question is a reliable indicator of a poor design".
Yes, and I'll stand by it until proven otherwise, which I don't
see happening in the below discussion.
>I admit, I started using perl a just few months ago, am still
>learning the language and I apparently do not have your level
>of expertise, or would have recognized it is a "reliable indicator
>of a poor design"!
Yes, that is why I said it, so that you _would_ know.
>Just made me wonder, if you were jumping to "conclusion" here!,
Of course I was. That was all that was possible with the
info available to me.
The quality of answer is nearly always in direct proportion
to the quality of the question. You did not supply enough
information for me to be of much help.
>specially without knowing the complete picture!.
I think I asked that you describe the complete picture.
>Lets assume...
>
>1) Maybe I have no practical purpose for this function
>"GetVarNameAsString" and am just exploring the language,
>hoping to learn more about it by going off path.
If you just want to "learn" rather than get some particular
problem solved, you should say so. Most questions here are
the second kind, so that is assumed unless you say otherwise.
I am suprised that you haven't noticed that yourself when
you lurked a bit before posting.
>2) Maybe I am trying to write something generic to help in debugging
>my programs by printing a variable name along with its data every
>time a variable is updated using tie.
>something like [ Var : $myvar1, old value=100, new value=200 ].
Now there we have a plausible reason for wanting such a thing,
though it is a rather specialized application area.
>I do not know if it is possible,
It would be possible for dynamic variables. See the "Symbol Tables"
section in perlmod.pod. I don't think it can be done for lexical
variables.
>and I might be doing it the wrong way,
If you do not show us what way you are using, we cannot help
you evaluate the way you are doing it...
>3) Maybe I am trying to implement the function for one of my programs,
>I have no idea of what I am doing and as you mentioned,its a bad design
>
>
>Go ahead Tad, take your pick!
Go ahead Prem, tell me why you think you "need to" get the
variables name.
>but I feel, stating my question as a
>"reliable indicator of a poor design" was done without being aware
>of finer details.
You did not provide any finer details. I'm not that good
at mind reading, I just dabble with it :-)
I will still say, even without knowing what it is you want to do
(you still have not told us that by the way), that your question
is very likely an indicator of poor design.
Do not take offense, just examine your design to see if you
can eliminate the "need" to get the variable name.
[ snip Jeopardy quoted text ]
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 10 Mar 2001 23:39:42 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: How do I get the name of a variable as a string?
Message-Id: <8melatgv1icc5h0elq4roqvkab250b7bop@4ax.com>
Juha Laiho wrote:
>>Question: Is it possible to get the variable name as a string, if so how?
>
>Hmm.. I think it should be doable via the symbol table, but I don't know
>the details (never needed this).
Indeed. a little while back, I posted some code here that could trace a
reference to a sub back to its name. The same principle applies here.
But it can only ever work for global variables, NOT for lexicals, those
variables declared with "my", because these are not in any symbol table.
One could alway stash names and references in a hash, and do a lookup if
you need one of those. It's simpler than looking through the symbol
table.
--
Bart.
------------------------------
Date: 10 Mar 2001 22:08:54 GMT
From: dha@panix6.panix.com (David H. Adler)
Subject: Re: if($array1[1] eq $string1) DOESN'T WORK??
Message-Id: <slrn9al9fm.49s.dha@panix6.panix.com>
On Thu, 08 Mar 2001 03:44:10 GMT, Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote:
>I was shocked! How could Peter Sundstrom <peter.sundstrom-eds@eds.com>
>say such a terrible thing:
>
>>Your problem is more than likely related to your data. As you don't provide
>>any input, it is not possible to say where the exact problem is.
>
>I'd say his problem is more likely related to his syntax. But that's
>just me.
No... no it isn't just you...
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"Perl Porters, Inc. today announced the release of version .006 of
their popular Perl5 compiler suite, codenamed `Rabid Rat'."
- Nathan Torkington on p5p (this was a *joke*)
------------------------------
Date: Sun, 11 Mar 2001 08:29:36 +1000
From: tommiy <tommiy@ozemail.com.au>
Subject: Re: if($array1[1] eq $string1) DOESN'T WORK??
Message-Id: <3AAAAAD0.50F2422@ozemail.com.au>
Also theres no block for the if......
Peter Sundstrom wrote:
>
> "Wannabe Perl Guru" <donotreply@interbulletin.bogus> wrote in message
> news:3AA6B1B9.56610105@interbulletin.com...
> > I have @array1 filled with strings, and have $string1 = "somestring";
> > But when I use this statement:
> >
> > if($array1[1] eq $string1)
> > print "yes";
> >
> > Then Perl throws up!
> > Why can't I do this this Perl?
> > What alternatives are there to the above statement??
>
> It works fine. Try this:
>
> #!/usr/bin/perl -w
> use strict;
>
> my @array1;
> $array1[1]="somestring";
> my $string1="somestring";
>
> if ($array1[1] eq $string1) {
> print "yes\n";
> }
>
> Your problem is more than likely related to your data. As you don't provide
> any input, it is not possible to say where the exact problem is.
------------------------------
Date: Sat, 10 Mar 2001 23:59:27 +0100
From: "Peter van den Hamer" <vdhamer@msn.com>
Subject: Re: Macbeth and Perl threads
Message-Id: <98ebie$le2$1@news.IAEhv.nl>
Dan Sugalski <dan@tuatha.sidhe.org> wrote
> Peter van den Hamer <vdhamer@msn.com> wrote:
> > Question: is it possible for one Perl (5.005-type) thread to kill
> > another thread in that thread's sleep?
>
> Nope. You can't do this safely with threads in general, and perl's
> threads are no exception.
>
> Dan
Wow, the Perl threading guru himself!
Rather than ask the man for his signature, I would appreciate
a pointer to what's in store for threading in future versions of Perl.
I was recently confronted with a confusing array of info on threads in
today's Perl. It took about a week worth of free time to figure out:
* in typical configurations perl -v says "multi-threading" but the multi
and the threading didn't mean what one would expect.
* p-threads require a recompile (I managed on Win32, but not what
I can ask my users to do) and are "experimental", although some
of the documentation (and a tutorial ;-) pretends it's the way to go.
* Interpreter threads probably work, but don't have much of an interface.
* there are a slew of alternative RFC's on threading for Perl 6
Whence will Perl threading evolve?
What time scale till a decision?
And till a release?
Peter van den Hamer
------------------------------
Date: Sat, 10 Mar 2001 14:56:03 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Maintaining the number format and not exponential
Message-Id: <3AAAB103.DB1F9BD4@stomp.stomp.tokyo>
FORM Rookie wrote:
> Just trying to figure out how to maintain the format
> of the number displayed. Basically, I was adding a number
> to a variable and the result was an exponential number.
> I really need the format of the display to remain the
> same as the data number.
> Ex:
> $adder = 5;
> $form_data = $formdata{'data'}; #data=123456789123456
> $result = $adder + $form_data;
> print "$result";
> #the result comes out as an exponential number 1.123456789123e+15
> #actual result that I wanted should read 123456789123461
If you would like to avoid using a module, there is a method
of accomplishing this by 'fooling' perl into treating your
input number and your number to be added, as character strings
rather than as numbers, during a portion of processing.
However, if you add a number greater than fifteen digits in
length, my test code below will revert to use of Scientific
Notation. Additional coding can be added to circumvent this.
My test code will not deal with fractional numbers in a decimal
format. Additional coding would be required for this.
You have not stated full parameters on your expectations so
there is a possibility you will need to make some modifications
to deal with your unique circumstances. Nonetheless, my code does
reflect basic principles of how to do this without use of a module.
This test code will display a form action page in which you can
enter both your base number and number to add, for ease in testing.
Exhaustive testing will yield successful circumstances and, will
yield failure circumstances.
Godzilla!
--
Name this test script: test3.pl or change my
form action to reflect a different file name.
#!perl
&Parse;
sub Parse
{
local (*in) = @_ if @_;
my ($iterate, $key, $value);
read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
my (@in) = split(/&/, $in);
foreach $iterate (0 .. $#in)
{
$in[$iterate] =~ s/\+/ /g;
($key, $value) = split(/=/, $in[$iterate], 2);
($value eq "") && next;
$key =~ s/%(..)/pack("c",hex($1))/ge;
$value =~ s/%(..)/pack("c",hex($1))/ge;
$in{$key} .= "\0" if (defined($in{$key}));
$in{$key} .= $value;
}
return 1;
} # Read Parse #
print "Content-type: text/html\n\n
<HTML><HEAD><TITLE>Godzilla Rocks!</TITLE></HEAD>
<BODY TEXT=\"#000000\" BGCOLOR=\"#ffffff\">
<FONT FACE=\"arial rounded mt bold\" SIZE=\"3\">\n\n
<CENTER>
<BR><BR>
<FORM ACTION=\"test3.pl\" METHOD=\"POST\">
Base Number:
<INPUT TYPE=\"text\" SIZE = \"40\" MAXLENGTH=\"200\" NAME=\"Base_Num\">
<BR>
Add Number:
<INPUT TYPE=\"text\" SIZE = \"40\" MAXLENGTH=\"200\" NAME=\"Add_Num\">
<P>
<FONT FACE=\"arial rounded mt bold\" SIZE=\"3\">
<INPUT TYPE=\"submit\" NAME=\"Button\" VALUE=\"Test\">
</FONT>
</FORM>
<HR WIDTH=\"12%\">
</CENTER>
<P>";
## code
$digits = 15 - (length ($in{Add_Num}) + 2);
if (length ($in{Base_Num}) > 15)
{
$base = substr ($in{Base_Num}, 0, $digits);
$additive = substr ($in{Base_Num}, $digits);
$additive += $in{Add_Num};
$result = "$base$additive";
}
else
{ $result = $in{Base_Num} + $in{Add_Num}; }
## code
print "
Original Number: $in{Base_Num} <BR>
Additive Number: $in{Add_Num} <BR>
Result Is: $result
</BODY></HTML>";
------------------------------
Date: Sat, 10 Mar 2001 23:26:26 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Maintaining the number format and not exponential
Message-Id: <x71ys5ciji.fsf@home.sysarch.com>
>>>>> "G" == Godzilla! <godzilla@stomp.stomp.tokyo> writes:
G> If you would like to avoid using a module, there is a method
G> of accomplishing this by 'fooling' perl into treating your
G> input number and your number to be added, as character strings
G> rather than as numbers, during a portion of processing.
well, this is great. moronzilla has just redefined addition. how about
dealing with carries?
G> However, if you add a number greater than fifteen digits in
G> length, my test code below will revert to use of Scientific
G> Notation. Additional coding can be added to circumvent this.
G> My test code will not deal with fractional numbers in a decimal
G> format. Additional coding would be required for this.
and where is that additional coding? as usual you handle some tiny
fraction of the cases and leave the rest. try and write a program that
handles arbitrary length integers. i would love to see you try and then
post it. but you won't
and you talk about converting back to float which is exactly what the OP
DID NOT WANT! so try to answer the question for a change.
G> You have not stated full parameters on your expectations so
G> there is a possibility you will need to make some modifications
G> to deal with your unique circumstances. Nonetheless, my code does
G> reflect basic principles of how to do this without use of a module.
no it does not. it does not handle carries from any digit place.
try it with a large number of all 9's.
999999999999999999999999 + 1
watch this lovely output:
Original Number: 9999999999999999999
Additive Number: 1
Result Is: 99999999999910000000
sure fine math you done learned on the reservation! wanna teach some
more?
jeez, will you finally get it that you can't do shit like this without
serious coding.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Sat, 10 Mar 2001 17:35:07 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Maintaining the number format and not exponential
Message-Id: <3AAAD64B.9CDCA535@stomp.stomp.tokyo>
Uri Guttman spewed:
> > Godzilla! wrote:
(snipped village idiot blatherings)
It is annoyingly clear you still suffer serious
challenges in reading comprehension skills.
Godzilla!
------------------------------
Date: Sat, 10 Mar 2001 17:42:09 -0500
From: "null" <nospamplease@thankyou.com>
Subject: newbie Q : problems with using 'use lib qw(....' to point to modules
Message-Id: <98eajc$kih$1@bob.news.rcn.net>
I am virtually hosted and my hosting service has an old version of GD.pm
installed (a version that outputs gifs but not pngs, and I need pngs). I
downloaded the GD tar.gz from CPAN, ftp'd to a special "perlmods" subdir on
my host account, unzipped it using ssh, and added a couple of lines to the
top of the top of the script after the "shebangs" line (residing in my
cgi-bin):
#!/usr/bin/perl
use lib qw(/home/mydomain/mydomain-www/perlmods/GD-1.32/);
use Config;
and commented out the line :
use GD;
which had been placed a bit further down.
The previous version of the script would work fine when told to output gifs
and would at least give me a broken image icon when told to kick out png's
(I have been very careful to always upload in ascii and chmod 755 the pl
file), but now all that I can get are 500 internal server errors.
Uncommenting the #use GD line will give me the broken image icon again (so I
am sure that i didn't introduce any other errors accidentally) - it seems
that Perl can't find my GD.pm. The path given to me by my host to use was
"/home/mydomain/mydomain-www/perlmods/GD-1.32/GD.pm", I was still getting
the 500 error and, during testing on my own machine, I got the "point to the
directory containing the file, not the file itself" error (although using
/home/mydomain/mydomain-www/perlmods/GD-1.32/ or
/home/mydomain/mydomain-www/perlmods/GD-1.32 have not fixed the problem at
my site or locally, where I used the equivalent paths beginning with C:\).
The problem definitely seems to be that Perl cannot find GD.pm, but I don't
know what I've done wrong.
Someone else in this ng had suggested using the -I switch to specify a
directory containing mods, but I searched quite a bit and could not locate
an example of its use, so I went with use lib qw(... instead.
help?
(ps I didn't actually use "mydomain" in the paths, I just subbed that in
here because I don't want people to associate my domain name with this level
of cluelessness)
------------------------------
Date: 10 Mar 2001 20:32:36 +0100
From: Kai.Grossjohann@CS.Uni-Dortmund.DE (Kai =?iso-8859-1?q?Gro=DFjohann?=)
Subject: Re: RFC: FAQ3 update -- Using less memory
Message-Id: <vafvgph8lnv.fsf@lucy.cs.uni-dortmund.de>
On Tue, 06 Mar 2001, Michael Carman wrote:
> Don't read an entire file into memory if you can process it line
> by line. Whenever possible, use this:
>
> while (<FILE>) {
> # ...
> }
>
> instead of this:
>
> @data = <FILE>;
> foreach (@data) {
> # ...
> }
>
> and B<never> use this:
>
> for (<FILE>) {
> # ...
> }
>
> When the files you're processing are small, it doesn't much matter
> which way you do it, but it makes a huge difference when they start
> getting larger. The latter method keeps eating up more and more
> memory, while the former method scales to files of any size.
Does it make sense to use the terms `former' and `latter' when there
are three items? What about the middle item, then?
kai
--
Be indiscrete. Do it continuously.
------------------------------
Date: Sat, 10 Mar 2001 22:03:51 -0000
From: "Brian J" <sorryno@email.at.all>
Subject: Re: scalar(localtime) in reverse?
Message-Id: <3aaaa4d7_2@news2.uncensored-news.com>
"Bart Lateur" <bart.lateur@skynet.be> wrote in message
news:jd7katcu0scruoifinjmfbemjmk82ak3vi@4ax.com...
> Oops! Let's get this absolutely right.
>
> Bart Lateur wrote:
>
> >Bart Lateur wrote:
> >
> >> /^\w+ (\w+) (\d+) (\d+):(\d+):(\d+) (\d+)$/
> >
> >My tests have shown that localtime() puts two spaces in front of the
day
>
> MAY put two spaces in front of the day of the month, but only if it
> consists of one digit. The total string length is always the same.
>
> >of month, so make that regex:
> >
> > /^\w+ (\w+) +(\d+) (\d+):(\d+):(\d+) (\d+)$/
> >
>
> That still applies.
Many thanks, it worked a treat :-)
--
Brian
______________________________________________________________________
Posted Via Uncensored-News.Com - Still Only $9.95 - http://www.uncensored-news.com
With Servers In California, Texas And Virginia - The Worlds Uncensored News Source
------------------------------
Date: Sun, 11 Mar 2001 11:33:45 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: scalar(localtime) in reverse?
Message-Id: <02Bq6.3$nM2.3896@vic.nntp.telstra.net>
"Brian J" <sorryno@email.at.all> wrote in message
news:3aa982ab$1_1@news2.uncensored-news.com...
> Is there anyway, for example, that 'Tue Jan 2 16:32:11 2001' can be
> turned back into the number of seconds since the Unix epoch. I'm sure
> it can be done with some complex mathematics, but is there a function
> built in that will let me do this?
>
I dont know of a builtin function, but you can do this...
#!/usr/bin/perl -w
use strict;
use Time::Local;
print time,"\n";
my $num = scalar localtime;
print "$num\n";
my %months = ('Jan'=>0, 'Feb'=>1, 'Mar'=>2, 'Apr'=>3, 'May'=>4, 'Jun'=>5,
'Jul'=>6,
'Aug'=>7, 'Sep'=>8, 'Oct'=>9, 'Nov'=>10, 'Dec'=>11);
my ($dayofweek, $mon, $mday, $time, $year) = split / +?/,$num;
my ($hours, $min, $sec) = split /:/,$time;
my $other = timelocal($sec,$min,$hours,$mday,$months{$mon},$year);
print $other;
Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';
------------------------------
Date: 10 Mar 2001 20:17:57 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: XS - typemap void ?
Message-Id: <98e25l$lvr$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Matthias Papesch
<mpapesch@gmx.de>],
who wrote in article <98di2u$52f$07$1@news.t-online.com>:
> Hi,
>
> I'm trying to create a PERL interface for a c-library and encountering a
> few problems.
>
> The header file contains many typedefs, such as INT32, FLOAT64, ... ,which
> can easily be covered in the typemap.
>
> The problem occurs with VOID for void.
As a quick hack, I would edit the typemap for TBOOL to emit
&sv_undef. But this may create some mis-C xsubpp output... Maybe the
easiest thing is to replace all VOID by void manually.
Hope this helps,
Ilya
------------------------------
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 V10 Issue 462
**************************************