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

Discussion in 'Perl Misc' started by john.swilting, Jan 21, 2007.

  1. 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
     
    john.swilting, Jan 21, 2007
    #1
    1. Advertising

  2. 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
     
    john.swilting, Jan 21, 2007
    #2
    1. Advertising

  3. 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
     
    Mark Clements, Jan 21, 2007
    #3
  4. john.swilting

    Stan R. Guest

    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.
     
    Stan R., Jan 21, 2007
    #4
  5. "Stan R." </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
     
    A. Sinan Unur, Jan 21, 2007
    #5
  6. 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
     
    john.swilting, Jan 22, 2007
    #6
  7. A. Sinan Unur wrote:

    > "Stan R." </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;
     
    john.swilting, Jan 22, 2007
    #7
  8. john.swilting wrote:

    > A. Sinan Unur wrote:
    >
    >> "Stan R." </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
     
    john.swilting, Jan 22, 2007
    #8
  9. john.swilting wrote:

    > john.swilting wrote:
    >
    >> A. Sinan Unur wrote:
    >>
    >>> "Stan R." </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
     
    john.swilting, Jan 22, 2007
    #9
  10. john.swilting

    -berlin.de Guest

    Mark Clements <> 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
     
    -berlin.de, Jan 22, 2007
    #10
  11. -berlin.de wrote:

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


    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;
     
    john.swilting, Jan 22, 2007
    #11
  12. john.swilting

    J. Gleixner Guest

    john.swilting wrote:

    > 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);
     
    J. Gleixner, Jan 22, 2007
    #12
  13. On 2007-01-22, J. Gleixner <> wrote:
    > john.swilting wrote:
    >
    >> 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

    --
    David H. Adler - <> - http://www.panix.com/~dha/
    Perl should only be studied as a second language. A good first
    language would be English. - Larry Wall
     
    David H. Adler, Feb 4, 2007
    #13
  14. john.swilting

    szr Guest

    A. Sinan Unur wrote:
    > "Stan R." </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.


    I didn't write that line.

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


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

    --
    Stan R.
     
    szr, Aug 9, 2007
    #14
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Parvinder
    Replies:
    6
    Views:
    747
    Thomas G. Marshall
    Feb 27, 2005
  2. Dave
    Replies:
    2
    Views:
    470
  3. globalrev
    Replies:
    4
    Views:
    769
    Gabriel Genellina
    Apr 20, 2008
  4. Replies:
    2
    Views:
    465
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
  5. VK
    Replies:
    15
    Views:
    1,174
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page