[17409] in Perl-Users-Digest
Perl-Users Digest, Issue: 4829 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 7 09:05:37 2000
Date: Tue, 7 Nov 2000 06:05:18 -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: <973605917-v9-i4829@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 7 Nov 2000 Volume: 9 Number: 4829
Today's topics:
Re: Calculating Date Difference <matt@sergeant.org>
exporting environmental variables <Monica.Martin@sdrc.com>
Re: exporting environmental variables (Anno Siegel)
Re: Getting the Day of a Date (Anno Siegel)
Help - read from CSV <simon@suit-u-sir.com>
Re: Help - read from CSV (Tad McClellan)
How can I sent a GIF to the browser <fschlicht@tourisline.de>
How can I sent a GIF to the browser <fschlicht@tourisline.de>
Re: How do I put field names with spaces in SQL stateme (Bryce Pursley)
Re: large file size (Martien Verbruggen)
Re: Looking for idiom for getting value from @ARGV, or (Abigail)
Re: Looking for idiom for getting value from @ARGV, or (Martien Verbruggen)
Re: Monitoring PIDs (Anno Siegel)
Re: Newbie Question: Hiding password? nobull@mail.com
Re: OOP and information hiding (Abigail)
Pass by reference from Perl to C <jaya_j_k@hotmail.com>
pass by reference to C <vidulats@yahoo.co.uk>
Re: Passing Hash to Perl Module Update <james@NOSPAM.demon.co.uk>
Re: Passing Hash to Perl Module Update (Garry Williams)
Re: Passing Hash to Perl Module Update (Greg McCarroll)
Re: Passing Hash to Perl Module Update (Anno Siegel)
Problem converting data u1606@my-deja.com
Re: Problem converting data <frnack.caron@infineon.com>
Re: Problem converting data <stephenk@cc.gatech.edu>
Re: Problem converting data (Martien Verbruggen)
Re: Problem reading a binary file <james@NOSPAM.demon.co.uk>
Re: problems creating a file <mdorrel@fsnet.co.uk>
Re: problems creating a file (Tad McClellan)
Q: Getting program line number? nospam@our.site
Re: Q: Getting program line number? (Greg McCarroll)
returning a true value is FUN! (was Re: Log.pm did not <jeffp@crusoe.net>
Re: Splitting variable length fixed records <bart.lateur@skynet.be>
Re: Splitting variable length fixed records (Martien Verbruggen)
system call return <oeschey@media-saturn.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 07 Nov 2000 11:26:24 +0000
From: Matt Sergeant <matt@sergeant.org>
Subject: Re: Calculating Date Difference
Message-Id: <3A07E6E0.8060205@sergeant.org>
balkuwai@celestica.com wrote:
> Hi,
>
> I'm trying to find out the date exactly 2 weeks before the day my
> script is running. Is there an easy way of doing this? I need the
> year, month, day of month to be returned.
use Time::Object;
use Time::Seconds;
my $now = localtime;
my $two_weeks_ago = $now - (ONE_WEEK * 2);
print $two_weeks_ago->date;
Hope that helps.
Matt.
------------------------------
Date: Tue, 07 Nov 2000 07:11:40 -0500
From: Monica Martin <Monica.Martin@sdrc.com>
Subject: exporting environmental variables
Message-Id: <3A07F17C.DC98D85A@sdrc.com>
Is there a clean way to export environmental variables through a perl
script, such that the environmental variable persists after the script
ends?
------------------------------
Date: 7 Nov 2000 12:56:52 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: exporting environmental variables
Message-Id: <8u8u6k$vfs$1@lublin.zrz.tu-berlin.de>
Monica Martin <Monica.Martin@sdrc.com> wrote in comp.lang.perl.misc:
>Is there a clean way to export environmental variables through a perl
>script, such that the environmental variable persists after the script
>ends?
Uh... those are just "environment variables". Nothing green about
them.
No, you cannot set environment variables in a parent process from a
child process; the child simply has no access to its parents address
space.
What you can do is have the script print the value (and probably even
the name) of the desired variable to stdout. The calling shell can then
capture the output and set *its* environment variable accordingly.
You can even print the complete command (which is shell-dependent) to
set one or more environment variables and let the shell do
eval `your script`
Some Unix utilities are set up this way.
Anno
------------------------------
Date: 7 Nov 2000 11:43:21 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Getting the Day of a Date
Message-Id: <8u8psp$v8l$1@lublin.zrz.tu-berlin.de>
Steffen Beyer <sb@engelschall.com> wrote in comp.lang.perl.misc:
>In article <8u8ke3$v2b$1@lublin.zrz.tu-berlin.de>, Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>
>>>> my %day = (
>>>> '0' => 'Sunday',
>>>> '1' => 'Monday',
>>>> '2' => 'Tuesday',
>>>> '3' => 'Wednesday',
>>>> '4' => 'Thursday',
>>>> '5' => 'Friday',
>>>> '6' => 'Saturday'
>>>> );
>>>this is uneccessary and wrong. Sunday's index is 7
>
>> Huh? From perldoc -f localtime:
>> $wday is the day of the week, with 0 indicating Sunday...
>> Please check before making public claims.
>
>Please do so yourself, i.e., please read the thread before posting to it! ;-)
>
>We were talking about Date::Calc, not localtime, where Sunday is indeed
>7 and not 0 (as opposed to localtime).
Ack, indeed. Please note that I took care to snip the embarrassing
reference to Date::Calc :) And apologies to Malte Ubl.
Anno
------------------------------
Date: Tue, 07 Nov 2000 11:17:14 +0000 (GMT)
From: Simon E. John <simon@suit-u-sir.com>
Subject: Help - read from CSV
Message-Id: <4a19aec2a6simon@suit-u-sir.com>
OK, so now I've done the poll, it reads the counts from the logfile and the
vote from the form, then prints out the results in a table as percentages and
bar graphs and prints the results back to the logfile (not append).
What I'd like to do next is try to make the polls dynamic, i.e. have the
program read from the log file, so that instead of having to hard code the
table with Bush et al, the program would read what's on the left of the pipe
and put that in the table.
The variables would have to be automatically generated too, so instead of $a,
$b, $c, it would make $var0, $var1, $var2 up to $numrecords so that I could
change the poll by just changing the logfile (and generate the HTML page from
Perl/SSI, I guess).
Then I'd have to stop people voting multiple times - using cookies I guess,
(anyone know any good cookie tutorials/libraries?) this is getting ridiculous
now, by the time it's finished it'll be worthy of Freshmeat'ing! ;o)
Here's what I've got so far (non-dynamic)......
#!/usr/bin/perl -w
# sets vote file location
$poll_file = "../poll/votes.txt";
# open vote file for reading
open(POLL, $poll_file);
# count records and split columns
my %votes;
my $numrecords = 0;
while(<POLL>) {
chomp();
my ($name, $value) = split(/\|/);
$votes{$name} = $value;
$numrecords++;
}
close(POLL);
# reads votes into variables
$a = $votes{'a'};
$b = $votes{'b'};
$c = $votes{'c'};
# split the name-value pair from the form
@pairs = split(/&/, $ENV{'QUERY_STRING'});
# for each name-value pair, split into variables
foreach $pair (@pairs) {
local($name, $value) = split(/=/, $pair);
# form decoding
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
# go through the form looking for the votes
$poll = ($FORM{'vote'});
if ($FORM{'vote'} eq 'a') { $a++; }
if ($FORM{'vote'} eq 'b') { $b++; }
if ($FORM{'vote'} eq 'c') { $c++; }
# write votes back to file
open(POLL, ">$poll_file");
print(POLL "a\|",$a,"\n");
print(POLL "b\|",$b,"\n");
print(POLL "c\|",$c,"\n");
close(POLL);
# total up the votes
$total = $a+$b+$c;
# convert into percentages, preventing division by zero
if ($a > 0) { $apc = $a / $total * 100 } else { $apc = 0 };
if ($b > 0) { $bpc = $b / $total * 100 } else { $bpc = 0 };
if ($c > 0) { $cpc = $c / $total * 100 } else { $cpc = 0 };
# print out the Content-type header
print "Content-type: text/html\n\n";
# print question
print "<P>Who's going to be the next US President?";
# start table
print "<P><TABLE BORDER=1 CELLPADDING=5>";
# round and print as percentages and bar graphs - sorry about wrapping
print "<TR><TD>a) Bush</TD><TD ALIGN=right>";
printf ("%.1f",$apc);
print "%</TD><TD WIDTH=100><TABLE BORDER=0><TR><TD COLOR=#FF0000
WIDTH=",$apc,"> </TD></TR></TABLE></TD>";
print "<TR><TD>b) Gore</TD><TD ALIGN=right>";
printf ("%.1f",$bpc);
print "%</TD><TD><TABLE BORDER=0><TR><TD COLOR=#FF0000
WIDTH=",$bpc,"> </TD></TR></TABLE></TD>";
print "<TR><TD>c) Homer Simpson</TD><TD ALIGN=right>";
printf ("%.1f",$cpc);
print "%</TD><TD><TABLE BORDER=0><TR><TD COLOR=#FF0000
WIDTH=",$cpc,"> </TD></TR></TABLE></TD>";
# end table
print "</TD></TR></TABLE>";
print "<P>Total votes: ",$total;
====END====
Try it out at http://www.suit-u-sir.com/poll/
TIA ;o)
--
Simon John, BA(Hons), DipM
Email: simon@suit-u-sir.com | Running RISC OS 4.02,
Web: www.suit-u-sir.com | RedHat Linux 7.0/2.4
PGP: send-pgp@suit-u-sir.com | & Windows 2000 Pro
This tagline was brought to you with the letters T, A and G
------------------------------
Date: Tue, 7 Nov 2000 07:19:56 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Help - read from CSV
Message-Id: <slrn90fsrc.563.tadmc@magna.metronet.com>
On Tue, 07 Nov 2000 11:17:14 +0000 (GMT), Simon E. John
<simon@suit-u-sir.com> wrote:
>The variables would have to be automatically generated too, so instead of $a,
>$b, $c, it would make $var0, $var1, $var2 up to $numrecords
That sounds like Symbolic References.
Symrefs are disallowed by "use strict".
Since everybody with a lick of sense has invoked "use strict",
hardly anybody uses symrefs.
That is a Very Good Thing.
What's wrong with putting your sequentially ordered values into an array?
$var[0], $var[1]...
That is what an array is _for_.
>Then I'd have to stop people voting multiple times - using cookies I guess,
^^^^
You mean "discourage". You cannot really "stop" it...
>(anyone know any good cookie tutorials/libraries?)
Perl does not have "cookies". That is a WWW/CGI thing, best asked
in a WWW/CGI newsgroup.
>this is getting ridiculous
>now, by the time it's finished it'll be worthy of Freshmeat'ing! ;o)
>
>Here's what I've got so far (non-dynamic)......
>
>open(POLL, $poll_file);
Check the return value:
open(POLL, $poll_file) || die "could not open '$poll_file' $!";
Just because you ask for something does not mean that you actually got it.
># count records and split columns
>my %votes;
>my $numrecords = 0;
>while(<POLL>) {
> chomp();
> my ($name, $value) = split(/\|/);
> $votes{$name} = $value;
> $numrecords++;
^^^^^^^^^^^^^
You could use $. instead of maintaining a counter yourself...
>open(POLL, ">$poll_file");
Check the return value.
>print(POLL "a\|",$a,"\n");
^
^
Backslashing slows down the human reader of your program.
You should not slow down reading when you do not need to.
That backslash does not do anything, and therefore should
not be there.
You could just interpolate there:
print(POLL "a|$a\n");
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 7 Nov 2000 13:02:15 +0100
From: "Frank Schlicht" <fschlicht@tourisline.de>
Subject: How can I sent a GIF to the browser
Message-Id: <973598599.53679@news.mediaWays.net>
Hello,
I have the following problem. My code:
print "Content-type: image/gif\n\n";
binmode(STDOUT);
open(DATEI, "bild.gif");
binmode(DATEI);
while ($_ = read(DATEI, $buffer, 1024))
{
print $buffer;
}
close(DATEI);
If I start the script from the console it works fine. But in the browser the
script finds no end. I write a log-file, so I can say that all code after
"close(DATEI)" will proceed. After this code the pl-file ends. What is the
browser/script waiting for?
Thanks and Regards
Frank
------------------------------
Date: Tue, 7 Nov 2000 13:03:38 +0100
From: "Frank Schlicht" <fschlicht@tourisline.de>
Subject: How can I sent a GIF to the browser
Message-Id: <973598601.280777@news.mediaWays.net>
Hello,
I have the following problem. My code:
print "Content-type: image/gif\n\n";
binmode(STDOUT);
open(DATEI, "bild.gif");
binmode(DATEI);
while ($_ = read(DATEI, $buffer, 1024))
{
print $buffer;
}
close(DATEI);
If I start the script from the console it works fine. But in the browser the
script finds no end. I write a log-file, so I can say that all code after
"close(DATEI)" will proceed. After this code the pl-file ends. What is the
browser/script waiting for?
Thanks and Regards
Frank
------------------------------
Date: Tue, 07 Nov 2000 13:05:51 GMT
From: hbpursle@duke-energy.com (Bryce Pursley)
Subject: Re: How do I put field names with spaces in SQL statement?
Message-Id: <3a08fe0a.599069886@news.infoave.net>
Thanks Kurt. That did the trick.
On Mon, 6 Nov 2000 17:26:57 -0500, "Kurt Stephens"
<kstep@pepsdesign.com> wrote:
>Hi Bryce,
>
>To specify a field name that contains spaces, enclose the name in [square
>braces].
>
>$SqlStatement = "SELECT HOST1, HOST2, [P1 LINK NAME], HOST3 FROM INFO"
>
>This syntax is specific to the MS Access/Jet driver. Other drivers may use
>a different syntax, if they allow spaces at all.
>
>I hope this helps,
>
>Kurt Stephens
>kstep@pepsdesign.com
>
>
------------------------------
Date: Tue, 7 Nov 2000 21:58:26 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: large file size
Message-Id: <slrn90fo2i.boe.mgjv@martien.heliotrope.home>
On 6 Nov 2000 16:41:29 GMT,
Clay Irving <clay@panix.com> wrote:
> On Mon, 06 Nov 2000 16:59:26 +0100, Josef Moellers
> o<josef.moellers@fujitsu-siemens.com> wrote:
>
>>Dave's box wrote:
>>>
>>> I have a 4 gb file that I can't open with "open(LOG, "$log") || die
>>> "Unable to open $log\n";
>>> Does perl have a file size limitation? When I split the file in 2 it
>>> will work . Thanks
>>
>>Perl may not, but the underlying OS may ...
>
> Makes you wonder how the file got on the machine serviced by the OS?
SunOS 5.5 or 5.6 binary of perl on a SunOS 5.7 machine, maybe?
Martien
--
Martien Verbruggen |
Interactive Media Division | In a world without fences, who needs
Commercial Dynamics Pty. Ltd. | Gates?
NSW, Australia |
------------------------------
Date: 7 Nov 2000 13:06:32 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Looking for idiom for getting value from @ARGV, or a default
Message-Id: <slrn90fvio.ctp.abigail@tsathoggua.rlyeh.net>
On Tue, 7 Nov 2000 21:36:06 +1100, Martien Verbruggen (mgjv@tradingpost.com.au) wrote in comp.lang.perl.misc <URL: news:<slrn90fmom.boe.mgjv@martien.heliotrope.home>>:
++ On 7 Nov 2000 08:39:46 GMT,
++ Abigail <abigail@foad.org> wrote:
++ > On Tue, 07 Nov 2000 01:24:03 GMT, Martien Verbruggen
++ > (mgjv@tradingpost.com.au) wrote:
++ > ++ On Mon, 06 Nov 2000 23:59:03 GMT,
++ > ++ Uri Guttman <uri@sysarch.com> wrote:
++ > ++ >
++ > ++ > i note that in another post. normally you can't have an undefined value
++ > ++ > in @ARGV from the shell, but someone could be messing around with @ARGV
++ > ++ > in a BEGIN block.
++ > ++
++ > ++ Yes, I read that after sending this post as well. But then, anyone
++ > ++ doingthat gets what they deserve :). Or at least, anyone doing that
++ > ++ probably knows what they are doing.
++ >
++ > But only a handful of people never download something from CPAN and use it.
++
++ I'm sorry.. I don't get what you mean...
++
++ or do you mean that many people download stuff from CPAN, without
++ knowing how it works, internally? Maybe. But anyone deliberately
I do that all the time. Do you think more than 1% of the people using CGI.pm
know how it works, internally? Or the various IO::* and Net::* modules?
++ assigning something to @ARGV is something different from using a CPAN
++ module. And, anyone copying code without knowing what it does, still
++ gets what they deserve. Or do you mean that you know of CPAN modules
++ that modify @ARGV? I'm a bit confused.
GetOpt::* even comes with perl. Granted, it won't add to @ARGV, but it
does modify @ARGV. And then there's -s.
Abigail
------------------------------
Date: Wed, 8 Nov 2000 00:45:55 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Looking for idiom for getting value from @ARGV, or a default
Message-Id: <slrn90g1sj.boe.mgjv@martien.heliotrope.home>
On 7 Nov 2000 13:06:32 GMT,
Abigail <abigail@foad.org> wrote:
> On Tue, 7 Nov 2000 21:36:06 +1100, Martien Verbruggen (mgjv@tradingpost.com.au) wrote:
>> On 7 Nov 2000 08:39:46 GMT,
>> Abigail <abigail@foad.org> wrote:
>>>
>>> But only a handful of people never download something from CPAN and
>>> use it.
>>
>> I'm sorry.. I don't get what you mean...
>>
>> or do you mean that many people download stuff from CPAN, without
>> knowing how it works, internally? Maybe. But anyone deliberately
>
> I do that all the time. Do you think more than 1% of the people using
> CGI.pm know how it works, internally? Or the various IO::* and Net::*
> modules?
I do that all the time as well. I just wasn't sure whether that was what
you meant.
>> assigning something to @ARGV is something different from using a CPAN
>> module. And, anyone copying code without knowing what it does, still
>> gets what they deserve. Or do you mean that you know of CPAN modules
>> that modify @ARGV? I'm a bit confused.
>
> GetOpt::* even comes with perl. Granted, it won't add to @ARGV, but it
> does modify @ARGV. And then there's -s.
I know they modify @ARGV. I was just asking whether this was what you
meant.
I had trouble parsing your statement and was asking for clarification
about what exactly you intended to say.
Maybe I should have originally said something like "It's very unlikely
that you ever end up with undef in @ARGV". I've personally never
encountered it, and can't imagine anything usefully mdoifying @ARGV by
stuffing undef in it somewhere. shifting things off, ok.
Anyway, it's a non-argument really. The person writing the code to do
those checks that this whole thread started out with is most likely also
the one who would mutilate @ARGV unnecessarily. And, again, they would
get what they ask for.
Martien
--
Martien Verbruggen |
Interactive Media Division | In a world without fences, who needs
Commercial Dynamics Pty. Ltd. | Gates?
NSW, Australia |
------------------------------
Date: 7 Nov 2000 11:21:58 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Monitoring PIDs
Message-Id: <8u8okm$v7c$1@lublin.zrz.tu-berlin.de>
David McMullen <davidmac@austin.rr.com> wrote in comp.lang.perl.misc:
>I am trying to monitor a process and have it notify me when it is
>finished. I'm either missing something or close and don't know it. Any
>help is appreciated.
>
>
>
>$i = (system "ps -ef | grep find | grep -v grep")
>print $i
>
>returns 0 while process is running and 256 when it is not running.
>What is the best way to monitor the process.
There is rarely a single best way to do something. It's like asking
for the best way to build a house. On what ground? In what climate?
How much do you want to spend? Does it need to have...
In your case, the equivalent questions are: What OS are you using?
(Probably Unix, because you mention ps, but who knows?) Do you start
the process to be monitored yourself? If not, do you control what it
does? Do you know its PID? If you don't, can you make the process
deposit its PID in a known place?
The "best way" to monitor a process depends on the answers to these
questions, and probably more once these are answered.
In the meantime, check out signals. In particular SIGCHLD, or the
special properties of signal 0 may lead to a comparatively simple
solution.
Anno
------------------------------
Date: 07 Nov 2000 13:46:02 +0000
From: nobull@mail.com
Subject: Re: Newbie Question: Hiding password?
Message-Id: <u9aebbj3ol.fsf@wcl-l.bham.ac.uk>
na0ise@my-deja.com writes:
> Subject: Newbie Question: Hiding password?
Please check out this helpful information on choosing good subject
lines. It will be a big help to you in making it more likely that your
requests will be answered.
http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post
> I am writing a perl script that reads data from a webform.
But your question has fundamental to the task and nothing to do with
the choice of Perl as the implementation language or the choice of web
as the user-interface.
Before posting a question to usenet it is a good idea to get your
thought processes as clear as possible. Work out what is part of your
underlying question and what is just background information and/or you
attempt to answer the question. Often doing this will be sufficient
to make the answer obvious.
> I want to zip
> the data I read with a password. I do not want to put the password in
> plain text inside the Perl script. Is there a more secure way to achieve
> my purpose? Any helps will be greatly appreciated.
Your real question is: "How can I have a program store data in an
encypted data file such that access to the program source is not
sufficient to decrypt the data?"
This can be re-arraged into "How can something reversably encyrpt data
in such a way that the knowlege available to the encyptor is not
sufficient to decrypt?"
Once you've go this far it should be self-evident that the solution is
to use some form public key encryption. (PGP, GPG or whatever.)
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 7 Nov 2000 13:08:37 GMT
From: abigail@foad.org (Abigail)
Subject: Re: OOP and information hiding
Message-Id: <slrn90fvml.ctp.abigail@tsathoggua.rlyeh.net>
On Wed, 01 Nov 2000 21:43:34 +0500, David Allen (s2mdalle@titan.vcu.edu) wrote
+in comp.lang.perl.misc <URL: news:<8tqkhf$1bf$1@bob.news.rcn.net>>:
++ Recently I've been looking into different aspects o
++ information hiding in OO languages just out of interest.
++
++ I'm quite interested in the way that Perl doesn't
++ do information hiding in OOP. I've never had a
++ problem with perl's way of doing things; i.e. I've
++ never really tried to muck around in the insides of
++ an object, because I've learned through hard experience
++ in other languages that it's a good way to break
++ programs down the line when the implementation of
++ the object changes. You should stick to the "public"
++ interface.
But, on the other hand, Perl doesn't protect you from mucking around
in the object by accident either. And I don't mean $obj -> {foo} = "bar";
that's easily avoidable.
What I mean is: you are using OO, hence, you are reusing code. You need
to extend a class you downloaded from CPAN, or one that has been developed
by a team of 50 programmers the past 4 years in another department.
You study its interface, and decide to strictly follow the interface.
In the great Perl tradition of "do it all yourself, the language won't
make it easy for you", the object is implemented as a hashref. You add
your little 2 methods to the object, using one attribute to store data,
and your module goes in production.
Two year later, after the meltdown of the nuclear power generator,
inspection of the code revealed that your attribute coincided with
an attribute used by the code that controls the temparature of the
cooling system 50 levels up in the inheritance hierarchy.
Despite by using strict, -w, and never going around the public
interface, Perl didn't do a thing to prevent disaster to happen.
Anyone who uses Perl OO for production code should be fired as
being irresponsible.
Oh, and please spare me the list of hacks (many mentioned in Damians
books) on how to avoid it. They all have their drawbacks, two of them
being that they are hardly used (go to CPAN and or the Perl standard
distribution and see which often used modules actually use them) and
that they tend to be incompatible.
Perls way of implementing OO is actually anti-OO, as it gives the
user of the class (that is, the inheriting class) all the baggage
of the implementation. Precisely what OO is *NOT* supposed to do.
"Stick to the interface" should all that's needed to succesfully
use objects. But in Perl, it's "stick to the implementation".
Abigail
------------------------------
Date: Tue, 07 Nov 2000 13:30:03 -0000
From: jaya <jaya_j_k@hotmail.com>
Subject: Pass by reference from Perl to C
Message-Id: <t0g0ur5jome708@corp.supernews.com>
Hi,
In the following code if I pass @y through the subroutine cfunc,i.e.,
cfunc(@y)
it gives the error
Usage: Datatypes::cfunc(x) at datatypes.pl
But the code below works. Why?
#!/usr/bin/perl5
use Datatypes;
@y= ('12','34','56','90','345');
foreach $x(@y)
{
cfunc ($x);
}
void
cfunc(x)
char * x
CODE:
{
int i;
for(i=0;(*x) != '\0';i++,x++)
{
printf("%c\n",*x);
}
}
--
Posted via CNET Help.com
http://www.help.com/
------------------------------
Date: Tue, 07 Nov 2000 13:30:03 -0000
From: <vidulats@yahoo.co.uk>
Subject: pass by reference to C
Message-Id: <t0g0urffjsp809@corp.supernews.com>
Hello,
I'm facing a problem while passing a address to C function.
Will anyone please guide me.
In Perl Script: I have following code:
#!/usr/bin/perl5
use Datatypes;
@y= ('12','34','56','90','345');
foreach $x(@y)
{
cfunc ($x);
}
This is the code of XS file:
void
cfunc(x)
char * x
CODE:
{
int i;
for(i=0;(*x) != '\0';i++,x++)
{
printf("%c\n",*x);
}
}
This works perfectly OK.
But, if I change the foreach loop. i.e. instead of
foreach $x(@y)
{
cfunc ($x);
}
If I write
cfunc(@y);
then, it gives the error as
Usage: Datatypes::cfunc(x) at datatypes.pl
Will any one help me.
Thanks in advance,
Regards,
Vidula
--
Posted via CNET Help.com
http://www.help.com/
------------------------------
Date: Tue, 7 Nov 2000 12:15:19 +0000
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: Passing Hash to Perl Module Update
Message-Id: <ant0712191cbfNdQ@oakseed.demon.co.uk>
In article <973521573.25155.0.nnrp-13.c29f015a@news.demon.co.uk>, Gus
<URL:mailto:gus@black.hole-in-the.net> wrote:
>
> A slightly better new() would perhaps be
>
> sub new {
> my($class,$args) = @_;
> my $self = {};
> bless $self,ref $class || $class;
> #$self->setup_defaults($args) if $args; # If needed
> return $self;
> }
Is it necessary to say bless $self, ref $class || $class;
or is it enough just to say bless $self, $class; ?
--
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02
------------------------------
Date: Tue, 07 Nov 2000 13:18:01 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Passing Hash to Perl Module Update
Message-Id: <diTN5.878$FG.49161@eagle.america.net>
On Tue, 7 Nov 2000 12:15:19 +0000, James Taylor
<james@NOSPAM.demon.co.uk> wrote:
>In article <973521573.25155.0.nnrp-13.c29f015a@news.demon.co.uk>, Gus
><URL:mailto:gus@black.hole-in-the.net> wrote:
>
>Is it necessary to say bless $self, ref $class || $class;
>or is it enough just to say bless $self, $class; ?
You can answer that question by reading the manual page for bless().
$ perl -MIO::Handle -wle '$fh=IO::Handle->new;print $fh;print ref $fh'
IO::Handle=GLOB(0x111160)
IO::Handle
The original poster apparently expects the method to be called both as
a class method *and* an instance method.
--
Garry Williams
------------------------------
Date: 7 Nov 2000 13:18:19 GMT
From: gem@mccarroll.demon.co.uk (Greg McCarroll)
Subject: Re: Passing Hash to Perl Module Update
Message-Id: <slrn90g3q7.7i2.gem@mccarroll.demon.co.uk>
James Taylor wrote :
>
>Is it necessary to say bless $self, ref $class || $class;
>or is it enough just to say bless $self, $class; ?
>
the first allows you to call new on an existing instance of an object
returning a new instance, the second allows you to call new only on a
class name
imho, the use of the ref $class || $class is over engineering and you
really shouldn't need to call new on instances, however YMMV
hth
Greg
--
Greg McCarroll http://www.mccarroll.uklinux.net
perl hacker | book collector | the very model of a modern mailing list kook
London.pm - meetings held on the day after the first wednesday of the month
------------------------------
Date: 7 Nov 2000 13:25:12 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Passing Hash to Perl Module Update
Message-Id: <8u8vro$vid$1@lublin.zrz.tu-berlin.de>
James Taylor <james@NOSPAM.demon.co.uk> wrote in comp.lang.perl.misc:
>In article <973521573.25155.0.nnrp-13.c29f015a@news.demon.co.uk>, Gus
><URL:mailto:gus@black.hole-in-the.net> wrote:
>>
>> A slightly better new() would perhaps be
>>
>> sub new {
>> my($class,$args) = @_;
>> my $self = {};
>> bless $self,ref $class || $class;
>> #$self->setup_defaults($args) if $args; # If needed
>> return $self;
>> }
>
>Is it necessary to say bless $self, ref $class || $class;
>or is it enough just to say bless $self, $class; ?
This is by no means necessary.
You will need this bit of gymnastics only if you want new() to work as
an object method as well as a class method, so that you can say
my $other = $some_obj->new. In this case the first parameter to new()
isn't a class, but an object in that class ($some_obj), and ref
retrieves the class for new().
Camps are divided whether this kind of polymorphism is even desirable.
Myself, I usually prefer to have separate object methods for cloning
existing objects and not saddle new() with that task.
Anno
------------------------------
Date: Tue, 07 Nov 2000 11:29:22 GMT
From: u1606@my-deja.com
Subject: Problem converting data
Message-Id: <8u8p2e$6t4$1@nnrp1.deja.com>
I have a variable containing a binairy/hex value 07cf
This is representing the year 1999
How kan I print this variable so that it says "1999"
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 07 Nov 2000 13:17:41 +0100
From: Caron Franck <frnack.caron@infineon.com>
Subject: Re: Problem converting data
Message-Id: <3A07F2E5.52180BB0@infineon.com>
to convert a string that contain hexadecimal value to a number use the
hex($) function
EX:
$hexstr = "07cf";
$num = hex($hexstr);
print $num."\n";
this will print 1999.
you can also do more compact: print hex($hexstr)."\n";
to do the oposite use sprintf to format a number onto a string:
$hexstr = sprintf("%X\n",$num);
convert a number in its hexadecimal value.
--franck
u1606@my-deja.com wrote:
> I have a variable containing a binairy/hex value 07cf
> This is representing the year 1999
> How kan I print this variable so that it says "1999"
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
------------------------------
Date: Mon, 06 Nov 2000 07:24:18 -0500
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: Problem converting data
Message-Id: <3A06A2F2.801B7600@cc.gatech.edu>
u1606@my-deja.com wrote:
> I have a variable containing a binairy/hex value 07cf
> This is representing the year 1999
> How kan I print this variable so that it says "1999"
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
perldoc -f hex
--
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: Wed, 8 Nov 2000 00:25:13 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Problem converting data
Message-Id: <slrn90g0lp.boe.mgjv@martien.heliotrope.home>
On Tue, 07 Nov 2000 11:29:22 GMT,
u1606@my-deja.com <u1606@my-deja.com> wrote:
> I have a variable containing a binairy/hex value 07cf
> This is representing the year 1999
> How kan I print this variable so that it says "1999"
You are faced with this problem. In September ---it's always
September--- you want to figure out which year you are in. But you have
this odd calendar. Some geek must have designed it, because at the
bottom of each page it simply says:
$year = '07cf';
You decide to bite the bullet, and finally get into this programming
thing that people seem to be making so much money with. First, you pull
out your mathematical schoolbooks, and figure out how to transform one
number base into another. You realise that you'll probably need a hash
like this:
my %hex;
@hex{qw(0 1 2 3 4 5 6 7 8 9 a b c d e f)} = (0..15);
@hex{qw(A B C D E F)} = (10..15);
You start reading perlre, and like everyone foolish enough to do that,
you start to think that everything can be solved with a regexp,
including the thical problems involving transgenetic corn crops. You
play with them:
sub hex_to_dec
{
my $hex = reverse shift;
my $dec = my $i = 0;
while ($hex =~ /(.)/g) {$dec += 16 ** $i++ * $hex{$1}};
$dec
}
But you don't like that loop too much. You pull out perlop to see what
else you can come up with, and you see the /e flag on s///
sub hex_to_dec
{
my $hex = reverse shift;
my $dec = my $i = 0;
$hex =~ s/(.)/$dec += 16 ** $i++ * $hex{$1}/eg;
$dec
}
Look mummy, no loop!
Then, like everyone eventually does, you come to your senses, and you
realise that regular expressions, and their related operators, are,
unfortunately, not the answer to everything in the universe. You start
going through perlsyn, and notice the while modifier. A quick little
browse through perlfunc gives you substr:
sub hex_to_dec
{
my $hex = shift;
my $dec = my $i = 0;
$dec += 16 ** $i++ * $hex{$_} while $_ = substr $hex, -1, 1, '';
$dec
}
You have a loop again, but you decide to live with that for now. After
a bit of thinking, andmore browsing of perlfunc, you rewrite that to the
shorter
sub hex_to_dec
{
my $dec = my $i = 0;
$dec += 16 ** $i++ * $hex{$_} for split //, reverse shift;
$dec
}
Now we're getting somewhere!
Then you're browsing through perldata, and notice that Perl can handle
scalar value constructors in a hexadecimal form, as long as they start
with 0x. So you come up with this clever idea:
$val = eval "0x$var";
You're pretty pleased with this. But a doubt gnaws at your conscience.
This can't be the Right Thing(TM) to do.
You start looking in perlfunc again, to see whether there's any
disadvantage to using eval. While doing that, you notice pack, and
unpack, with the H and h template. After four hours of fiddling with
them, you give up, and look at perlfunc again. You notice oct(). You
think to yourself: "Gosh, I wish there was a function like oct() for
hexadecimal numbers. It would really make my life easy. Oh well. I give
up. Let's just ask the good people on comp.lang.perl.misc how to do
this.".
And because you have been so good, and you have actually looked at the
documentaiton, and you have shown us the herculian effort you have put
into solving this problem yourself, some nice person on there tells you
the solution.
[spoiler follows]
$val = hex $var;
Martien
--
Martien Verbruggen |
Interactive Media Division | Freudian slip: when you say one thing
Commercial Dynamics Pty. Ltd. | but mean your mother.
NSW, Australia |
------------------------------
Date: Tue, 7 Nov 2000 12:27:32 +0000
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: Problem reading a binary file
Message-Id: <ant071232b49fNdQ@oakseed.demon.co.uk>
In article <8u8lvn$v3q$1@lublin.zrz.tu-berlin.de>, Anno Siegel
<URL:mailto:anno4000@lublin.zrz.tu-berlin.de> wrote:
>
> While I managed to remain in blissful ignorance of all things Windowish,
> there's been enough mumble about binmode() in the group for me to mumble
> along: You want binmode().
When you say binmode(); in a program does it affect both
STDIN and STDOUT simultaneously?
Is the effect of binmode simply to turn off newline translation?
If that is the case then for portability all file access that is
not being processed as text should have binmode set, is that right?
What happens when a text file which has foreign newline characters
is read without binmode set? Does Perl know how to convert all kinds
of newline character combinations in the file to the "\n" kind in
memory?
--
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02
------------------------------
Date: Tue, 7 Nov 2000 10:10:37 -0000
From: "Mike Dorrel" <mdorrel@fsnet.co.uk>
Subject: Re: problems creating a file
Message-Id: <3a07dcb8.0@energise.enta.net>
Now I'm getting the following error
Software error:
Couldn't open ``file'': Permission denied at MyDomain/cgi-bin/create.cgi
line 10.
For help, please send mail to the webmaster...
I've tried to chmod the direcory and script file so that all users have all
permissions but the above error still occurs.
Is it possibly the permissions with which Appache is running?
----- Original Message -----
From: "Gus" <gus@black.hole-in-the.net>
Newsgroups: comp.lang.perl.misc
Sent: Monday, November 06, 2000 3:19 PM
Subject: Re: problems creating a file
> Mike Dorrel <mdorrel@fsnet.co.uk> wrote:
> > Hello,
>
> > The following simple script is supposed to create a one line text file,
> > but it is not working correctly and I get no error from the browser
> > when I run the script.
>
> /trimmed/
>
> > if (open(LOGFILE, "> /newfile.txt")) {
> > print LOGFILE ("sample text.\n");
> > close(LOGFILE);
> > }
>
> So, when the open() fails, what then ?
>
> if (open(LOGFILE,"> /newfile.txt")) {
> print LOGFILE "sample text.\n";
> close(LOGFILE) || die("Content-type: text/plain\n\nCan't close: $!");
> }else{
> # Deal gracefully with error
> print STDERR "Couldn't open /newfile.txt, error was $!\n";
> }
>
> Regards,
> _Gus
>
>
>
>
> --
> gus@black.hole-in-the.net
> 0x58E18C6D
> 82 AA 4D 7F D8 45 58 05 6D 1B 1A 72 1E DB 31 B5
> http://black.hole-in-the.net/gus/
------------------------------
Date: Tue, 7 Nov 2000 07:23:17 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: problems creating a file
Message-Id: <slrn90ft1l.563.tadmc@magna.metronet.com>
On Tue, 7 Nov 2000 10:10:37 -0000, Mike Dorrel <mdorrel@fsnet.co.uk> wrote:
>Now I'm getting the following error
>
>Software error:
>Couldn't open ``file'': Permission denied at MyDomain/cgi-bin/create.cgi
>line 10.
>For help, please send mail to the webmaster...
Didn't the webmaster answer your email?
>I've tried to chmod the direcory and script file so that all users have all
>permissions but the above error still occurs.
>Is it possibly the permissions with which Appache is running?
I dunno. Apache is not Perl. This is the Perl newsgroup. If
you have a WWW server question, you will have much better luck
getting an answer in a WWW server newsgroup.
[ snip Jeopardy quoted text ]
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 07 Nov 2000 13:36:52 +0000
From: nospam@our.site
Subject: Q: Getting program line number?
Message-Id: <8u90hl$j95$1@icrf.news>
This message has been posted by: Aengus Stewart <aengus.stewart@REMOVE-THIS-TO-SENDicrf.icnet.uk>
In my program I want to do
"Error at line number XXX"
However I cant find a PERL global variable for this.
I want this as my program parses a text results file and if the format
of the results change I want a way that I can immediately spot where the
parsing has broken and jump in and fix it.
The PERL interpreter knows this info as it uses it in its diagnostic
output.
Apologies if this is something basic that I have missed, but I cant find
a reference to it in the Programming Perl book or the man pages or the
FAQs.
Please dont tell me its a ".....download module Blobby from
CPAN.........." :)
Cheers
Aengus
--
----------------------------------------------------------------------
Aengus Stewart aengus.stewart@icrf.icnet.uk
Computational Genome Analysis Laboratory Tel: +44 (0)171 269 3679
Imperial Cancer Research Fund
Lincoln's Inn Fields, Holborn, London, WC2A 3PX, UK
----------------------------------------------------------------------
------------------------------
Date: 7 Nov 2000 13:49:51 GMT
From: gem@mccarroll.demon.co.uk (Greg McCarroll)
Subject: Re: Q: Getting program line number?
Message-Id: <slrn90g5lb.7k3.gem@mccarroll.demon.co.uk>
On Tue, 07 Nov 2000, Aengus Stewart wrote:
>
>However I cant find a PERL global variable for this.
>
there may be a better way to do this (although there is definetly a
better syntax/golf way to do this) ...
sub mylineno {
my (undef,undef,$lineno)=caller();
return $lineno;
}
print "this is line number ",mylineno(),"\n";
print "this is line number ",mylineno(),"\n";
print "this is line number ",mylineno(),"\n";
hth
--
Greg McCarroll http://www.mccarroll.uklinux.net
perl hacker | book collector | the very model of a modern mailing list kook
London.pm - meetings held on the day after the first wednesday of the month
------------------------------
Date: Tue, 7 Nov 2000 08:27:32 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: returning a true value is FUN! (was Re: Log.pm did not return a true value)
Message-Id: <Pine.GSO.4.21.0011070826300.25313-100000@crusoe.crusoe.net>
On Nov 7, Anno Siegel said:
>Jeff Zucker <jeff@vpservices.com> wrote in comp.lang.perl.misc:
>>dick dijk wrote:
>
>>> How can I make it work?
>>
>>By following the instructions as listed in perldiag: put "1;" at the end
>>of the file to be included (without the quotes).
>
>As it happens, it even works with the quotes.
As does:
()=0;
at the end of a file... sigh, what wicked webs we weave.
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
------------------------------
Date: Tue, 07 Nov 2000 11:56:03 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Splitting variable length fixed records
Message-Id: <doqf0t4a1vd7grulkrgaoiah6pst1tifc3@4ax.com>
Peter Sundstrom wrote:
>I have a file of fixed records of variable length (newline terminated), eg:
>
>F1F2..F120
>
>Where
>
>F1 is 120 bytes
>F2 up to F120 is 60 bytes.
>
>The minimum number of fields is 2 and max is 120.
chomp;
@field = unpack 'A120'.('A60' x 119), $_;
Apparently, this will fill in zero length strings for all fields with
missing data, so yes, you will get 120 fields in total.
If you don't like that, Martien's more elaborate way of calculating the
unpack template, may help. But I don't get why he didn't use the 'x'
operator.
chomp;
@field = unpack 'A120'.('A60' x int((length($_)-120)/60)), $_;
--
Bart.
------------------------------
Date: Wed, 8 Nov 2000 00:47:57 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Splitting variable length fixed records
Message-Id: <slrn90g20d.boe.mgjv@martien.heliotrope.home>
On Tue, 07 Nov 2000 11:56:03 GMT,
Bart Lateur <bart.lateur@skynet.be> wrote:
>
> If you don't like that, Martien's more elaborate way of calculating the
> unpack template, may help. But I don't get why he didn't use the 'x'
> operator.
neither do I. What a moron.
:)
Martien
--
Martien Verbruggen |
Interactive Media Division | Failure is not an option. It comes
Commercial Dynamics Pty. Ltd. | bundled with your Microsoft product.
NSW, Australia |
------------------------------
Date: Tue, 07 Nov 2000 13:51:47 +0100
From: Lars Oeschey <oeschey@media-saturn.com>
Subject: system call return
Message-Id: <3A07FAE3.E1645C1E@media-saturn.com>
Hi,
from a perl script, I execute the following system call:
unless (system ("wep $_ status |grep alive >/dev/null")) {
#wenn erreichbar upgrade fahren, output prüfen
unless (system ("wadminep $_ upgrade |grep SUCCESS
>/dev/null")) {
#fehlercode für erfolg
$EP{$_}=0;
}
else {
#fehlercode für fail
$EP{$_}=1;
}
}
else {
#fehlercode für nicht erreichbar
$EP{$_}=2;
}
}
the second system call first returns some error message (which I could
ignore) and
afterwards the "SUCCESS" message. But i do get $EP{$_}=1, so I guess,
the
grep returns after getting the first message. When I do the systemcall
at
the prompt, I just get the "SUCCESS" line back, as it should be.
Any ideas?
Lars
------------------------------
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 4829
**************************************