Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > problem GD and my package Random->Random::new

Reply
Thread Tools

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

 
 
john.swilting
Guest
Posts: n/a
 
      01-21-2007
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


 
Reply With Quote
 
 
 
 
john.swilting
Guest
Posts: n/a
 
      01-21-2007
john.swilting wrote:

> 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
 
Reply With Quote
 
 
 
 
Mark Clements
Guest
Posts: n/a
 
      01-21-2007
john.swilting wrote:
> john.swilting wrote:
>
>> my code not work
>> its obvious for me
>>

<snip lots of code>
>
> 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
 
Reply With Quote
 
Stan R.
Guest
Posts: n/a
 
      01-21-2007
Mark Clements wrote:
> john.swilting wrote:
>> john.swilting wrote:
>>
>>> my code not work
>>> its obvious for me
>>>

> <snip lots of code>
>>
>> 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.


or

my $random_obj = new Random;

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

--
Stan R.


 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      01-21-2007
"Stan R." <(E-Mail Removed)/hmrprint/com.com> wrote in news:ep0hcj0hp1
@news2.newsguy.com:

>> john.swilting wrote:

....

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


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
 
Reply With Quote
 
john.swilting
Guest
Posts: n/a
 
      01-22-2007
Stan R. wrote:

> Mark Clements wrote:
>> john.swilting wrote:
>>> john.swilting wrote:
>>>
>>>> my code not work
>>>> its obvious for me
>>>>

>> <snip lots of code>
>>>
>>> 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.

>
> 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
 
Reply With Quote
 
john.swilting
Guest
Posts: n/a
 
      01-22-2007
A. Sinan Unur wrote:

> "Stan R." <(E-Mail Removed)/hmrprint/com.com> wrote in news:ep0hcj0hp1
> @news2.newsguy.com:
>
>>> john.swilting wrote:

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

>
> 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

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;

 
Reply With Quote
 
john.swilting
Guest
Posts: n/a
 
      01-22-2007
john.swilting wrote:

> A. Sinan Unur wrote:
>
>> "Stan R." <(E-Mail Removed)/hmrprint/com.com> wrote in news:ep0hcj0hp1
>> @news2.newsguy.com:
>>
>>>> john.swilting wrote:

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

>>
>> 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

> 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
 
Reply With Quote
 
john.swilting
Guest
Posts: n/a
 
      01-22-2007
john.swilting wrote:

> john.swilting wrote:
>
>> A. Sinan Unur wrote:
>>
>>> "Stan R." <(E-Mail Removed)/hmrprint/com.com> wrote in news:ep0hcj0hp1
>>> @news2.newsguy.com:
>>>
>>>>> john.swilting wrote:
>>> ...
>>>
>>>>>> I am going to eat then to go to sleep me
>>>>>> I return tomorrow
>>>
>>> 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

>> 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
 
Reply With Quote
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      01-22-2007
Mark Clements <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> john.swilting wrote:


> > its $text = Random->Random::new


> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Package HTML - Missing package documentation file jochenhebbrecht@gmail.com Java 1 11-27-2007 01:59 PM
Package that imports with name of dependent package David Pratt Python 4 05-13-2006 05:12 PM
single package import v/s the entire package Parvinder Java 6 02-27-2005 02:02 PM
package module import name clash with global package George P Python 3 09-11-2004 01:19 PM
Importing a package and looping through modules in the package Dave Python 2 02-10-2004 08:14 PM



Advertisments