problem GD and my package Random->Random::new

J

john.swilting

my code not work
its obvious for me

#!/usr/bin/perl -w

use strict;
use diagnostics;
use GD;
use GD::Text;
use GD::Text::Wrap;
use CGI;
use CGI::Carp;




my $q = new CGI;


# create a new

my $im = new GD::Image(100,100);

# allocate some colors
my $white = $im->colorAllocate(255,255,255);
my $black = $im->colorAllocate(0,0,0);
my $red = $im->colorAllocate(255,0,0);
my $blue = $im->colorAllocate(0,0,255);

# make the background tra $im_pngnsparent and interlaced
$im->transparent($white);
$im->interlaced('true');

# put a black frame around the picture
$im->rectangle(0,0,99,99,$black);

# draw a blue oval
$im->arc(50,50,95,75,0,360,$blue);

# and fill it with red
$im->fill(50,50,$red);


my $text = Random->Random::new();

my $wp = GD::Text::Wrap->new ( $im,
width => 100,
line_space => 4,
color => $black,
text => $text,
);
$im->rectangle ( $wp->get_bounds(50,50), $blue);
$wp->draw(50,50);

print $q->header( -type => "image/png", -expires => "-1d");
binmode STDOUT;
print STDOUT $im->png


package Random;

sub new{
my $class=shift;
my $self={};
bless $self,$class;


my@liste=('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15',
'16','17','18','19','20','21','22','23','24','25','26','27','28',
'29','30','31','32','33','34','35','36','37','38','39','40','41',
'42','43','44','45','46','47','48','49','50','51','52','53','54',
'55','56','57','58','59','60','61','62','63','64','65','66','67',
'68','69','70','71','72','73','74','75','76','77','78','79','78',
'79','80','81','82','83','84','85','86','87','88','89','90','91',
'92','93','94','95','96','97','98','99','100','101','102','103',
'104','105','106','107','108','109','110');
$self="";
my$self1="";
my$self2="";
my$self3="";
my$self4="";
$self1.=$liste[int rand@liste];
$self .= $self1;
$self2.=$liste[int rand@liste];
$self .=$self2;
$self3.=$liste[int rand@liste];
$self .=$self3;
$self4.=$liste[int rand@liste];
return $self;
}
1
 
J

john.swilting

john.swilting said:
my code not work
its obvious for me

#!/usr/bin/perl -w

use strict;
use diagnostics;
use GD;
use GD::Text;
use GD::Text::Wrap;
use CGI;
use CGI::Carp;




my $q = new CGI;


# create a new

my $im = new GD::Image(100,100);

# allocate some colors
my $white = $im->colorAllocate(255,255,255);
my $black = $im->colorAllocate(0,0,0);
my $red = $im->colorAllocate(255,0,0);
my $blue = $im->colorAllocate(0,0,255);

# make the background tra $im_pngnsparent and interlaced
$im->transparent($white);
$im->interlaced('true');

# put a black frame around the picture
$im->rectangle(0,0,99,99,$black);

# draw a blue oval
$im->arc(50,50,95,75,0,360,$blue);

# and fill it with red
$im->fill(50,50,$red);


my $text = Random->Random::new();

my $wp = GD::Text::Wrap->new ( $im,
width => 100,
line_space => 4,
color => $black,
text => $text,
);
$im->rectangle ( $wp->get_bounds(50,50), $blue);
$wp->draw(50,50);

print $q->header( -type => "image/png", -expires => "-1d");
binmode STDOUT;
print STDOUT $im->png


package Random;

sub new{
my $class=shift;
my $self={};
bless $self,$class;


my@liste=('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15',
'16','17','18','19','20','21','22','23','24','25','26','27','28',
'29','30','31','32','33','34','35','36','37','38','39','40','41',
'42','43','44','45','46','47','48','49','50','51','52','53','54',
'55','56','57','58','59','60','61','62','63','64','65','66','67',
'68','69','70','71','72','73','74','75','76','77','78','79','78',
'79','80','81','82','83','84','85','86','87','88','89','90','91',
'92','93','94','95','96','97','98','99','100','101','102','103',
'104','105','106','107','108','109','110');
$self="";
my$self1="";
my$self2="";
my$self3="";
my$self4="";
$self1.=$liste[int rand@liste];
$self .= $self1;
$self2.=$liste[int rand@liste];
$self .=$self2;
$self3.=$liste[int rand@liste];
$self .=$self3;
$self4.=$liste[int rand@liste];
return $self;
}
1

I am going to eat then to go to sleep me
I return tomorrow

my package compil nice
its $text = Random->Random::new
not works
 
M

Mark Clements

I am going to eat then to go to sleep me
I return tomorrow

my package compil nice
its $text = Random->Random::new
not works

"doesn't work" isn't a very helpful error description. Do you receive an
error message? If so, what is it?

By the way, the constructor would normally be something like:

my $random_obj = Random->new();

Although your syntax appears to work, I've never seen it done like that
before.

You need to work on explaining your problems better: dumping a load of
code on the newsgroup and saying "it doesn't work" isn't likely to get
you very far. Take a look at the posting guidelines and then repost:
they are there to help you.

Mark
 
S

Stan R.

Mark said:
"doesn't work" isn't a very helpful error description. Do you receive
an error message? If so, what is it?

By the way, the constructor would normally be something like:

my $random_obj = Random->new();

Although your syntax appears to work, I've never seen it done like
that before.

or

my $random_obj = new Random;

which can be more confortable for people who are used to C/C++/Java
grammar.
 
A

A. Sinan Unur


Good thing I plonked you today then.
my $random_obj = new Random;

which can be more confortable for people who are used to C/C++/Java
grammar.

Please read the section "Indirect Object Syntax" in perldoc perlobj before
making such recommendations.

Sinan
 
J

john.swilting

Stan said:
or

my $random_obj = new Random;

which can be more confortable for people who are used to C/C++/Java
grammar.
Why not to make one module Random.pm
whit Makefile.pl
and more
 
J

john.swilting

A. Sinan Unur said:
Good thing I plonked you today then.


Please read the section "Indirect Object Syntax" in perldoc perlobj before
making such recommendations.

Sinan
I made one package
uses now $random = new Random

code ok
compil nice
cgi its ok
thank you
I am going to change my customs
I am going to make package for the variables which owe exchanges to the run
my code
#!/use/bin/perl -w

package Random;

use strict;
require Exporter;

use vars qw( @ISA);

##$VERSION = O.O1;

@ISA = qw(Exporter);

sub new {
my $class=shift;
my $self={};
bless $self,$class;

my@liste=('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15',
'16','17','18','19','20','21','22','23','24','25','26','27','28',
'29','30','31','32','33','34','35','36','37','38','39','40','41',
'42','43','44','45','46','47','48','49','50','51','52','53','54',
'55','56','57','58','59','60','61','62','63','64','65','66','67',
'68','69','70','71','72','73','74','75','76','77','78','79','78',
'79','80','81','82','83','84','85','86','87','88','89','90','91',
'92','93','94','95','96','97','98','99','100','101','102','103',
'104','105','106','107','108','109','110');
$self="";
my$self1="";
my$self2="";
my$self3="";
my$self4="";
$self1.=$liste[int rand@liste];
$self .= $self1;
$self2.=$liste[int rand@liste];
$self .=$self2;
$self3.=$liste[int rand@liste];
$self .=$self3;
$self4.=$liste[int rand@liste];
return $self;
}


END {}
1;
 
J

john.swilting

john.swilting said:
A. Sinan Unur said:
Good thing I plonked you today then.


Please read the section "Indirect Object Syntax" in perldoc perlobj
before making such recommendations.

Sinan
I made one package
uses now $random = new Random

code ok
compil nice
cgi its ok
thank you
I am going to change my customs
I am going to make package for the variables which owe exchanges to the
run my code
#!/use/bin/perl -w

package Random;

use strict;
require Exporter;

use vars qw( @ISA);

##$VERSION = O.O1;

@ISA = qw(Exporter);

sub new {
my $class=shift;
my $self={};
bless $self,$class;

my@liste=('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15',
'16','17','18','19','20','21','22','23','24','25','26','27','28',
'29','30','31','32','33','34','35','36','37','38','39','40','41',
'42','43','44','45','46','47','48','49','50','51','52','53','54',
'55','56','57','58','59','60','61','62','63','64','65','66','67',
'68','69','70','71','72','73','74','75','76','77','78','79','78',
'79','80','81','82','83','84','85','86','87','88','89','90','91',
'92','93','94','95','96','97','98','99','100','101','102','103',
'104','105','106','107','108','109','110');
$self="";
my$self1="";
my$self2="";
my$self3="";
my$self4="";
$self1.=$liste[int rand@liste];
$self .= $self1;
$self2.=$liste[int rand@liste];
$self .=$self2;
$self3.=$liste[int rand@liste];
$self .=$self3;
$self4.=$liste[int rand@liste];
return $self;
}


END {}
1;
The positions of the text
Have to change and colours also
I go it package is I believe better
 
J

john.swilting

john.swilting said:
john.swilting said:
I made one package
uses now $random = new Random

code ok
compil nice
cgi its ok
thank you
I am going to change my customs
I am going to make package for the variables which owe exchanges to the
run my code
#!/use/bin/perl -w

package Random;

use strict;
require Exporter;

use vars qw( @ISA);

##$VERSION = O.O1;

@ISA = qw(Exporter);

sub new {
my $class=shift;
my $self={};
bless $self,$class;
my@liste=('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15',
'16','17','18','19','20','21','22','23','24','25','26','27','28',
'29','30','31','32','33','34','35','36','37','38','39','40','41',
'42','43','44','45','46','47','48','49','50','51','52','53','54',
'55','56','57','58','59','60','61','62','63','64','65','66','67',
'68','69','70','71','72','73','74','75','76','77','78','79','78',
'79','80','81','82','83','84','85','86','87','88','89','90','91',
'92','93','94','95','96','97','98','99','100','101','102','103',
'104','105','106','107','108','109','110');
$self="";
my$self1="";
my$self2="";
my$self3="";
my$self4="";
$self1.=$liste[int rand@liste];
$self .= $self1;
$self2.=$liste[int rand@liste];
$self .=$self2;
$self3.=$liste[int rand@liste];
$self .=$self3;
$self4.=$liste[int rand@liste];
return $self;
}


END {}
1;
The positions of the text
Have to change and colours also
I go it package is I believe better

the package Random.pm its ok
use require "Random.pm";
use syntax $text = new Random

cgi compil nice
 
A

anno4000

Mark Clements said:
john.swilting wrote:
By the way, the constructor would normally be something like:

my $random_obj = Random->new();

Although your syntax appears to work, I've never seen it done like that
before.

You can always qualify a method with a class name. That makes sure
inheritance starts at that point. You can even specify an entirely
unrelated class:

One->Other::new( ...);

would call the method Other::new (or a method named ->new in one of
Other's base classes) with the invocant One. A normal ->new method
would then initialize an object of its own kind with the parameters
given, but bless it into class One.

The technique does occasionally make sense, though not in the OPs case.

Anno
 
J

john.swilting

You can always qualify a method with a class name. That makes sure
inheritance starts at that point. You can even specify an entirely
unrelated class:

One->Other::new( ...);

would call the method Other::new (or a method named ->new in one of
Other's base classes) with the invocant One. A normal ->new method
would then initialize an object of its own kind with the parameters
given, but bless it into class One.

The technique does occasionally make sense, though not in the OPs case.

Anno

use my code
$test = Random->new();
I have to make what to return him(it) better
my code package
#!/use/bin/perl -w

package Random;

use strict;
require Exporter;

use vars qw( @ISA);

##$VERSION = O.O1;

@ISA = qw(Exporter);

sub new {
my $class=shift;
my $self={};
bless $self,$class;

my@liste=('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15',
'16','17','18','19','20','21','22','23','24','25','26','27','28',
'29','30','31','32','33','34','35','36','37','38','39','40','41',
'42','43','44','45','46','47','48','49','50','a','b','c','d','e',
'f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u',
'v','w', 'x','y','z','A','B','C','D','E','F','G','H','I','J','K',
'L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
$self="";
my$self1="";
my$self2="";
my$self3="";
my$self4="";
$self1.=$liste[int rand@liste];
$self .= $self1;
$self2.=$liste[int rand@liste];
$self .=$self2;
$self3.=$liste[int rand@liste];
$self .=$self3;
$self4.=$liste[int rand@liste];
return $self;
}


END {}
1;
 
J

J. Gleixner

john.swilting said:
my@liste=('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15', [...]
'104','105','106','107','108','109','110');

You can make that much shorter..
push( @liste, 1 .. 110);
 
D

David H. Adler

john.swilting said:
my@liste=('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15', [...]
'104','105','106','107','108','109','110');

You can make that much shorter..
push( @liste, 1 .. 110);

Out of curiosity, why the push rather than just an assignment?

Also, the original example used strings, rather than numbers, fwtw.

dha
 
S

szr

A. Sinan Unur said:
Good thing I plonked you today then.

I didn't write that line.
Please read the section "Indirect Object Syntax" in perldoc perlobj
before making such recommendations.

Thank you, Sinan, I've made a note of that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

help problemes cgi and GD::Text 4
problems GD and GD::Text::Wrap 5
Bug in GD? 3
What's wrong with transparency by GD? 3
GD TrueType empty output 5
semi-opacity with GD 8
help with GD and gd 1
random orc game 6

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top