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.perl doesn't exist", rofl). 13 1914
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.perl 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.perl 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
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
Wildpeaks wrote: > PS: I tried posting on the perl newsgroup first, > but Google Groups didn't seem to be in the mood >("comp.lang.perl 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
> 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).
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 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...
|
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....
|
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...
|
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...
|
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...
|
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....
|
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...
|
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,...
|
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: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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...
| |