[17401] in Perl-Users-Digest
Perl-Users Digest, Issue: 4821 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 6 11:05:27 2000
Date: Mon, 6 Nov 2000 08:05:11 -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: <973526710-v9-i4821@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 6 Nov 2000 Volume: 9 Number: 4821
Today's topics:
設下Perl論壇,歡迎高手,新手來論Perl <answer@hotmail.com>
Calculating Date Difference balkuwai@celestica.com
Re: Calculating Date Difference (John J. Trammell)
Re: character replacements ASCII > 127 only <Peter.Dintelmann@dresdner-bank.com>
Re: character replacements ASCII > 127 only <flavell@mail.cern.ch>
Converting ?!& etc. characters into unicode entities? <paul.groves@oucs.ox.ac.uk>
Re: Converting ?!& etc. characters into unicode entitie <nospam.newton@gmx.li>
Re: Converting ?!& etc. characters into unicode entitie <answer@hotmail.com>
Emailing formatted <abaltd@ntlworld.com>
Getting the Day of a Date jamesmagnus@my-deja.com
Re: Getting the Day of a Date (Clay Irving)
Re: Getting the Day of a Date <not.my.real.email@bellglobal.com>
Re: Getting the Day of a Date <answer@hotmail.com>
Help - read from CSV <simon@suit-u-sir.com>
Re: how to access object variables <eric@urbanrage.com>
Re: how to access object variables (Anno Siegel)
Re: how to make $ARGV[0] numeric <bart.lateur@skynet.be>
large file size <dshaklee@dtic.mil>
Re: large file size <josef.moellers@fujitsu-siemens.com>
Re: Looking for idiom for getting value from @ARGV, or (Abigail)
Re: Looking for idiom for getting value from @ARGV, or <bart.lateur@skynet.be>
Re: Looking for idiom for getting value from @ARGV, or (Anno Siegel)
OT: Behind the Cargo Cult <lmoran@wtsg.com>
Re: OT: Behind the Cargo Cult <joe+usenet@sunstarsys.com>
Re: Passing Hash to Perl Module Update <gus@black.hole-in-the.net>
Re: Passing Hash to Perl Module Update <eric@urbanrage.com>
Re: Passing Hash to Perl Module Update <eric@urbanrage.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 6 Nov 2000 22:48:29 +0800
From: "問題" <answer@hotmail.com>
Subject: 設下Perl論壇,歡迎高手,新手來論Perl
Message-Id: <8u6h0f$49d10@rain.i-cable.com>
http://easyto.heha.net/
本站提供Perl教學 自學資源,Perl 論壇 ,特別適合有意學Perl 的朋友.
歡迎前來發言本站有問必答.
------------------------------
Date: Mon, 06 Nov 2000 15:24:00 GMT
From: balkuwai@celestica.com
Subject: Calculating Date Difference
Message-Id: <8u6ie8$b68$1@nnrp1.deja.com>
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.
I would appreciate your help.
Regards,
Bashar
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 6 Nov 2000 15:39:09 GMT
From: trammell@nitz.hep.umn.edu (John J. Trammell)
Subject: Re: Calculating Date Difference
Message-Id: <slrn90cpq5.710.trammell@nitz.hep.umn.edu>
On Mon, 06 Nov 2000 15:24:00 GMT, balkuwai@celestica.com
<balkuwai@celestica.com> wrote:
>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.
Quick and dirty:
print scalar(localtime(time - 14*24*3600));
--
John J. Trammell
johntrammell@yahoo.com
------------------------------
Date: Mon, 6 Nov 2000 16:05:06 +0100
From: "Dr. Peter Dintelmann" <Peter.Dintelmann@dresdner-bank.com>
Subject: Re: character replacements ASCII > 127 only
Message-Id: <8u6hc0$o411@intranews.bank.dresdner.net>
Hi,
ozetechnology schrieb in Nachricht <8u6bum$5j4$1@nnrp1.deja.com>...
>I have to read around 9000 html files and replace several known
>character codes with internet character enterties, then strip out any
>remaining character code > 127
have a look at the HTML::Entities modules which has
two methods encode_entites() and decode_entities().
encode_entities( $string, "\200-\377" ) is probably
what you are looking for.
Best regards,
Peter Dintelmann
------------------------------
Date: Mon, 6 Nov 2000 15:58:41 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: character replacements ASCII > 127 only
Message-Id: <Pine.GHP.4.21.0011061551360.8829-100000@hpplus03.cern.ch>
On Mon, 6 Nov 2000, ozetechnology wrote:
> codes other than replacing the known codes is ok, its the greater than
> 127 thats giving me problems. I am assuming that I can use the
> substitution operator like I have for the known replacements.
You'll probably get better mileage with the tr/// operation, using
its 'd' option to delete the offending characters.
------------------------------
Date: Mon, 6 Nov 2000 14:20:57 -0000
From: "Paul Groves" <paul.groves@oucs.ox.ac.uk>
Subject: Converting ?!& etc. characters into unicode entities?
Message-Id: <8u6eni$8b1$1@news.ox.ac.uk>
Does anyone know if there is an easy way (e.g. a function of some sort) to
convert characters like "!", "?" "&" etc. into their respective
(unicode) entity values when these values occur in strings containing
paragraphs of text (they cause processing errors in my code otherwise,
don't ask...). i.e. is there something I can just use to convert the
whole string?
cheers
Paul
------------------------------
Date: Mon, 06 Nov 2000 16:08:33 +0100
From: "Philip 'Yes, that's my address' Newton" <nospam.newton@gmx.li>
Subject: Re: Converting ?!& etc. characters into unicode entities?
Message-Id: <pnhd0tsum5sd8pqv010bekk5dkc76jrp74@4ax.com>
[Newsgroups trimmed to comp.lang.perl.misc]
On Mon, 6 Nov 2000 14:20:57 -0000, "Paul Groves"
<paul.groves@oucs.ox.ac.uk> wrote:
> Does anyone know if there is an easy way (e.g. a function of some sort) to
> convert characters like "!", "?" "&" etc. into their respective
> (unicode) entity values when these values occur in strings containing
> paragraphs of text (they cause processing errors in my code otherwise,
> don't ask...). i.e. is there something I can just use to convert the
> whole string?
Defined "(unicode) entity value". For example, for '!', do you want to
get out 'U+0021' or '!' or '!' or '33' or '\u0021' or '\x21' or
what?
If '!' is what you want, then HTML::Entities may be the module for
you. You can pass it a range of characters that you want escaped, so
you can say "anything but letters" or "only ! ? &" or "characters with
bit 8 set" or whatever you want. However, for HTML 'named characters'
it won't give you e.g. 'ö' but rather 'ö', so this may be a
problem. On the other hand, I'd imagine it's fairly trivial to roll
your own regex that'll replace all $1 with '&#' . ord($1) . ';' for
all values of $1 looking like ([^A-Za-z0-9]), for example. But then,
the same goes for the other formats I posted (though you might need a
sprintf('%04X') or similar for some).
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
If you're not part of the solution, you're part of the precipitate
------------------------------
Date: Mon, 6 Nov 2000 22:51:00 +0800
From: "問題" <answer@hotmail.com>
Subject: Re: Converting ?!& etc. characters into unicode entities?
Message-Id: <8u6h57$49c4@rain.i-cable.com>
http://easyto.heha.net/
本站提供Perl教學 自學資源,Perl 論壇 ,特別適合有意學Perl 的朋友.
Paul Groves <paul.groves@oucs.ox.ac.uk> wrote in message
news:8u6eni$8b1$1@news.ox.ac.uk...
> Does anyone know if there is an easy way (e.g. a function of some sort) to
> convert characters like "!", "?" "&" etc. into their respective
> (unicode) entity values when these values occur in strings containing
> paragraphs of text (they cause processing errors in my code otherwise,
> don't ask...). i.e. is there something I can just use to convert the
> whole string?
>
> cheers
>
> Paul
>
>
------------------------------
Date: Mon, 6 Nov 2000 14:04:14 -0000
From: "abaltd" <abaltd@ntlworld.com>
Subject: Emailing formatted
Message-Id: <mUyN5.80123$hk2.158083@news6-win.server.ntlworld.com>
I'm trying to email an HTML-formatted message to a list of folks - via Perl
script using Unix sendmail (on a hosted service).
I know I can get sendmail to interpret To: and CC: lines ok (using -t
option)
But how can I get it to process Content-type: multipart/alternative; lines,
so that I can send formatted emails?
I found a comprehensive send_mail script on the web (re: extract from
CGI/Perl Cookbook)
Do I need to install this and/or have special SMTP server privileges?
Any suggestions as to the simplest way forward appreciated.
--
Alan Dougall
alan.dougall@virgin.net
http://start.at/the.cross
------------------------------
Date: Mon, 06 Nov 2000 14:16:39 GMT
From: jamesmagnus@my-deja.com
Subject: Getting the Day of a Date
Message-Id: <8u6eg1$7mq$1@nnrp1.deja.com>
Hi,
Can anyone tell me how to take a date (eg, 6 Nov 2000) and get the day
(eg, Monday)?
Any help or pointers appreciated - Thanks, James.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 6 Nov 2000 14:47:52 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: Getting the Day of a Date
Message-Id: <slrn90dh4o.ljt.clay@panix3.panix.com>
On Mon, 06 Nov 2000 14:16:39 GMT, jamesmagnus@my-deja.com
<jamesmagnus@my-deja.com> wrote:
>Can anyone tell me how to take a date (eg, 6 Nov 2000) and get the day
>(eg, Monday)?
>
>Any help or pointers appreciated - Thanks, James.
#!/usr/local/bin/perl -w
use Date::Calc qw/Day_of_Week/;
my %day = (
'0' => 'Sunday',
'1' => 'Monday',
'2' => 'Tuesday',
'3' => 'Wednesday',
'4' => 'Thursday',
'5' => 'Friday',
'6' => 'Saturday'
);
$date = "11/06/2000";
($month, $day, $year) = split /\//, $date;
$dow = Day_of_Week($year,$month,$day);
print "$date is a $day{$dow}.\n";
Result:
11/06/2000 is a Monday.
--
Clay Irving <clay@panix.com>
My mother taught me how to solve PHYSICS PROBLEMS:
"If I yelled because I saw a meteor coming toward you;
would you listen then?"
------------------------------
Date: Mon, 06 Nov 2000 14:51:57 GMT
From: "MNJP" <not.my.real.email@bellglobal.com>
Subject: Re: Getting the Day of a Date
Message-Id: <hAzN5.446721$1h3.12071484@news20.bellglobal.com>
If that date is already in epoch seconds format (let's say $edate) then all
you have to do is
$dayname = (localtime($edate))[6];
You will end up with $dayname being a number from 0 to 6, Sunday being 0;
If the date is already in text form like you've portrayed, then there might
be a module that does what you want already written. If not, then I beleive
the module Time::Local will take your date, convert it into epoch seconds
format. You can then plug it into the above function to get the weekday out
of it.
<jamesmagnus@my-deja.com> wrote in message
news:8u6eg1$7mq$1@nnrp1.deja.com...
> Hi,
>
> Can anyone tell me how to take a date (eg, 6 Nov 2000) and get the day
> (eg, Monday)?
>
> Any help or pointers appreciated - Thanks, James.
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
------------------------------
Date: Mon, 6 Nov 2000 22:52:17 +0800
From: "問題" <answer@hotmail.com>
Subject: Re: Getting the Day of a Date
Message-Id: <8u6h7h$4997@rain.i-cable.com>
http://easyto.heha.net/
本站提供Perl教學 自學資源,Perl 論壇 ,特別適合有意學Perl 的朋友.
<jamesmagnus@my-deja.com> wrote in message
news:8u6eg1$7mq$1@nnrp1.deja.com...
> Hi,
>
> Can anyone tell me how to take a date (eg, 6 Nov 2000) and get the day
> (eg, Monday)?
>
> Any help or pointers appreciated - Thanks, James.
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
------------------------------
Date: Mon, 06 Nov 2000 14:57:30 +0000 (GMT)
From: Simon E. John <simon@suit-u-sir.com>
Subject: Help - read from CSV
Message-Id: <4a193f1725simon@suit-u-sir.com>
I'm trying to write a poll in Perl, I've got most of it done, but would like
to read in the results from a flat file e.g. CSV or pipe-delimited.
The format would only consist of two fields with each record separated by a
newline, e.g.
Bush|1
Gore|2
Homer Simpson|100
I'd like to be able to setup a loop so that the file is read into an array
until EOF and the number of records counted and put into a variable,
processed and then written back to the file.
This way I could change the survey simply by changing the CSV file.
Someone said use the DBD::CSV or Text::CSV modules, but I'd prefer not to -
someone else mentionned grep....
TIA ;o)
--
Simon E. John, BA(Hons), DipM
Email: simon@suit-u-sir.com | Running RISC OS 4.02,
Web: www.suit-u-sir.com | RedHat Linux 7/2.4,
PGP: send-pgp@suit-u-sir.com | & Windows 2000 Pro
3 kinds of people: those who can count & those who can't.
------------------------------
Date: Mon, 06 Nov 2000 09:06:21 -0600
From: eric <eric@urbanrage.com>
Subject: Re: how to access object variables
Message-Id: <3A06C8ED.3F0F1C6@urbanrage.com>
john prokopek wrote:
>
> I am just starting to use objects in perl and have been successful with
> method invocations but I cannot seem to access an object's variable.
>
> the following is a part of my code for the object. I would like to
> access the state variable via $myboj->state. Is this possible and if so,
> how?
>
> thanks, I appreciate the help.
you can access as $TestMod::state, but the problem is that state is
'global' to all instances of the package. If you want state to reflect
each individual instance you need to reference it out of your package's
hash.
sub _initialize {
my $self = shift;
$self->{'state'} = "init";
}
sub start {
my $self = shift;
$self->{'state'} = "start";
return $self->{'state'};
}
sub stop {
my $self = shift;
$self->{'state'} = "stop";
return $self->{'state'};
}
sub status {
my $self = shift;
return $self->{'state'};
}
this allows you to reference the state via $myobj->{'state'} or you can
call the status subroutine that I added $myobj->status; to get the
current state.
Eric
eric@urbanrage.com
Brainbench MVP for Unix Programming
http://www.brainbench.com
------------------------------
Date: 6 Nov 2000 15:45:08 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how to access object variables
Message-Id: <8u6jm4$tet$1@lublin.zrz.tu-berlin.de>
john prokopek <john_prokopek@instinet.com> wrote in comp.lang.perl.misc:
>I am just starting to use objects in perl and have been successful with
>method invocations but I cannot seem to access an object's variable.
That may be because Perl doesn't have the concept of an object's
(or instance-) variable(s). An object in Perl is a data structure
(well, a pointer to a blessed data structure), and nothing else
is associated with it, in particular no specific variables. All
data associated with an object must be stored in the object itself.
It is therefore customary for your garden-variety object to be a
hash (of probably further data structures). That way, each object
carries around its own name space.
>the following is a part of my code for the object. I would like to
>access the state variable via $myboj->state. Is this possible and if so,
>how?
>
>thanks, I appreciate the help.
>
>package TestMod;
>
>use strict;
>use Carp;
>use vars qw($state $VERSION @ISA @EXPORT @EXPORT_OK);
>
>require Exporter;
>
>@ISA = qw(Exporter AutoLoader);
>@EXPORT = qw(
> start stop
>);
The use of objects is, generally speaking, an alternative to exporting.
Since "start" and "stop" are meant to be methods, there's no need to
export them. Once you have an object, Perl knows how to find its
methods.
This doesn't mean that objects and exportation can't be usefully
combined, but exporting object methods isn't often considered
useful.
So don't "use Exporter" at this point and scratch the related code,
it's only confusing. The same goes for the AutoLoader part.
>$VERSION = '0.01';
>
>my %fields = (
> state => undef
> );
>
>sub _initialize
>{
> $state = "init";
>}
>
>sub new
>{
> my $self = { %fields };
> bless $self;
> $self->_initialize();
> return $self;
>}
Okay, you are using a hash for the basic structure, as is common.
From your %fields setup it contains a key "state", whose value
is initially undef, as in %fields. This key/value pair is as close
to an "object variable" as you will get in Perl. But you will
have to access it as such.
In "_initialize" I assume you are attempting to give a value to
this field by accessing the variable $state. But $state is just
a variable in your current package (and Perl would have told you
so under "strict"). Instead, you have to access the hash that is
your object directly. The method call "$self->_initialize()" places
the object on the parameter list, so if you were to re-write
sub _initialize {
my $self = shift;
$self->{ state} = 'init';
}
you would indeed access your object.
The rest of you code suffers from the same mistaken assumption that
the package variable $TestMod::state is somehow magically connected
with your object. It isn't, and in general there is very little
magic involved with Perl objects. Perl code functions the same with
or without the presence of objects, and an assignment to a variable
is just that.
[rest snipped]
Anno
------------------------------
Date: Mon, 06 Nov 2000 15:21:30 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: how to make $ARGV[0] numeric
Message-Id: <b3jd0t48p5d5193n95u2fnousiesjvnikm@4ax.com>
dick dijk wrote:
>Does anyone know how to make a commandline argument (like $ARGV[0]) numeric,
>so that you can use it in
>"$a = pack("n", $ARGV[0])"?
You always can try. Perl will automatically treat ANY string as a
number, if you use it as a number. Your code is an example of that.
--
Bart.
------------------------------
Date: Mon, 06 Nov 2000 10:36:25 -0500
From: Dave's box <dshaklee@dtic.mil>
Subject: large file size
Message-Id: <3A06CFF9.5AD7C940@dtic.mil>
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
------------------------------
Date: Mon, 06 Nov 2000 16:59:26 +0100
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: large file size
Message-Id: <3A06D55E.DCBC2DF1@fujitsu-siemens.com>
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 ...
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
------------------------------
Date: 6 Nov 2000 14:33:55 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Looking for idiom for getting value from @ARGV, or a default
Message-Id: <slrn90dgaj.kg6.abigail@tsathoggua.rlyeh.net>
On Mon, 06 Nov 2000 05:49:33 GMT, Uri Guttman (uri@sysarch.com) wrote in comp.lang.perl.misc <URL: news:<x7g0l5hcpe.fsf@home.sysarch.com>>:
++ >>>>> "MV" == Martien Verbruggen <mgjv@tradingpost.com.au> writes:
++
++
++ MV> If you really need to test for defined-ness, then you need to use two
++ MV> statements:
++
++ MV> $s = shift @ARGV;
++ MV> $s = 'default' unless defined $s;
++
++ $s = defined( $ARGV[0] ) ? shift : 'default' ;
That is not quite the same. For instance, if @ARGV && !defined $ARGV [0].
Abigail
------------------------------
Date: Mon, 06 Nov 2000 15:24:59 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Looking for idiom for getting value from @ARGV, or a default
Message-Id: <m8jd0t0r2kch5dnu5pp30gjjfqvnn24d7l@4ax.com>
Uri Guttman wrote:
>$s = defined( $ARGV[0] ) ? shift : 'default' ;
@ARGV is a special case, an array for which it's garanteed that no
existing item can be undefined. If an element exists, it is defined. So
you can do:
$s = @ARGV ? shift : 'default';
--
Bart.
------------------------------
Date: 6 Nov 2000 15:53:33 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Looking for idiom for getting value from @ARGV, or a default
Message-Id: <8u6k5t$tg5$1@lublin.zrz.tu-berlin.de>
Abigail <abigail@foad.org> wrote in comp.lang.perl.misc:
>On Mon, 06 Nov 2000 05:49:33 GMT, Uri Guttman (uri@sysarch.com) wrote in comp.lang.perl.misc <URL: news:<x7g0l5hcpe.fsf@home.sysarch.com>>:
>++ >>>>> "MV" == Martien Verbruggen <mgjv@tradingpost.com.au> writes:
>++
>++
>++ MV> If you really need to test for defined-ness, then you need to use two
>++ MV> statements:
>++
>++ MV> $s = shift @ARGV;
>++ MV> $s = 'default' unless defined $s;
>++
>++ $s = defined( $ARGV[0] ) ? shift : 'default' ;
>
>
>That is not quite the same. For instance, if @ARGV && !defined $ARGV [0].
True, but that cannot happen if @ARGV is fresh from one of the shells.
So in the standard situation @ARGV != 0 implies that $ARGV[ 0] is defined.
Anno
------------------------------
Date: Mon, 06 Nov 2000 09:20:20 -0500
From: Lou Moran <lmoran@wtsg.com>
Subject: OT: Behind the Cargo Cult
Message-Id: <8bfd0toip3j179ehvs3lpar9af15hl7toi@4ax.com>
--Where can I find the Story behind the Cargo Cult phrase? I read it
in a post ages ago and I can't find it again. It was a good story.
"Ow, ow, stupid trash, rotten, stinky, hate world, revenge soon,
take out on everyone..."
lmoran@wtsg.com
------------------------------
Date: 06 Nov 2000 09:38:17 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: OT: Behind the Cargo Cult
Message-Id: <m3y9yxtbc6.fsf@mumonkan.sunstarsys.com>
Lou Moran <lmoran@wtsg.com> writes:
> --Where can I find the Story behind the Cargo Cult phrase? I read it
> in a post ages ago and I can't find it again. It was a good story.
google ("Richard Feynman 1974 Caltech Commencement")
Bear in mind the audience of his speech; IMHO
his tale was not meant as a castigation of the ignorance in others,
but in the relative ease in which even the best of us are capable
of fooling ourselves.
--
Joe Schaefer
------------------------------
Date: Mon, 06 Nov 2000 14:39:33 GMT
From: Gus <gus@black.hole-in-the.net>
Subject: Re: Passing Hash to Perl Module Update
Message-Id: <973521573.25155.0.nnrp-13.c29f015a@news.demon.co.uk>
spcman@my-deja.com wrote:
> What im trying to do is pass the %INFO hash from test.cgi over to
> template.pm. When I try to receive the hash in template.pm, i receive
> different values.
Firstly, are you sure you're not reinventing the wheel ? There are many
fine template modules on CPAN which you may wish to look at.
/trimmed/
> $RunTemplate = New template;
> $RunTemplate -> SetVariables(\%INFO);
Fine, but make the "New" in to "new", you're not calling a subroutine
called "New" you're creating an object.
> ################# Code for Template.pm ######################
> package template;
> sub New {
> my $class = shift; #Not sure what this code
> my %baseHtml = (); #Does yet, havent reverse
> bless \%baseHtml, $class; #Enginereed it.
> return \%baseHtml
> }
"Reverse engineered" ? Why not just read the documentation ?
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;
}
> sub SetVariables {
> my(%hash) = @_;
> foreach $key (keys %hash) {
> print "$key value: $hash{$key}<BR><BR>"; #Look at output below }
> }
Yuk.
Ok, firstly you're not getting the args off the stack properly, the first
argument to an object method is the object itself. Also, you're not passing
a hash, you're passing a reference to a hash so you're "foreach" needs to
be modifed to take that in to account.
try
sub SetVariables {
my($self,$hashref) = @_;
foreach $key (keys %$hashref) {
print "$key value: ", $hashref->{$key}, "\n";
}
}
And don't use StudlyCaps for subroutine names use the foobar_thing style.
use StudlyCaps for your package name, CAPITALS for constants etc.
To get the full picture, read the "h2xs" documentation, since that starts
off the whole thing by making a skeleton module for you, then read the
"perltoot" pages for more info on objects, and also take in perlmod,
perltoot, and perlmodlib.
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: Mon, 06 Nov 2000 08:49:37 -0600
From: eric <eric@urbanrage.com>
Subject: Re: Passing Hash to Perl Module Update
Message-Id: <3A06C501.747D95E8@urbanrage.com>
>
> print "Content-Type: text/html\n\n";
>
> $RunTemplate = New template;
> $RunTemplate -> SetVariables(\%INFO);
^^^^^^^
Here you passed in a reference to a hash
> sub SetVariables {
> my(%hash) = @_;
^^^^^^^^
Here you are treating it as a hash instead of a reference
try
my $hash_ref = shift;
%hash = %{$hash_ref};
> foreach $key (keys %hash) {
> print "$key value: $hash{$key}<BR><BR>"; #Look at output below }
> }
>
> 1;
Hope this helps,
Eric
eric@urbanrage.com
Brainbench MVP for Unix Programming
http://www.brainbench.com
------------------------------
Date: Mon, 06 Nov 2000 09:13:41 -0600
From: eric <eric@urbanrage.com>
Subject: Re: Passing Hash to Perl Module Update
Message-Id: <3A06CAA5.8FB39A93@urbanrage.com>
eric wrote:
>
> >
> > print "Content-Type: text/html\n\n";
> >
> > $RunTemplate = New template;
> > $RunTemplate -> SetVariables(\%INFO);
> ^^^^^^^
> Here you passed in a reference to a hash
>
> > sub SetVariables {
> > my(%hash) = @_;
> ^^^^^^^^
> Here you are treating it as a hash instead of a reference
> try
> my $hash_ref = shift;
> %hash = %{$hash_ref};
you forgot this is a package reference so you need to shift off that
first
my $self = shift;
my $hash_ref = shift;
>
> > foreach $key (keys %hash) {
> > print "$key value: $hash{$key}<BR><BR>"; #Look at output below }
> > }
> >
> > 1;
>
Eric :)
------------------------------
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 4821
**************************************