Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] Moose what am I doing wrong here?

Expand Messages
  • merlyn@stonehenge.com
    ... wlh1074 1.) If I create a new object with a call to a method that wlh1074 does a say or print statement how do I get this to print to wlh1074
    Message 1 of 9 , Oct 14, 2010
    View Source
    • 0 Attachment
      >>>>> "wlh1074" == wlh1074 <wlh1074@...> writes:

      wlh1074> 1.) If I create a new object with a call to a method that
      wlh1074> does a say or print statement how do I get this to print to
      wlh1074> the screen?

      With say or print.

      wlh1074> 2.) I have written a little code in java and am a beginner
      wlh1074> intermediate in perl. How do I call the new object package from
      wlh1074> another file in the same directory path? Do I need to hard code
      wlh1074> the path or can this just be call by the use: statement?

      See "perldoc lib" to add directories to your @INC path.

      wlh1074> What am I doing wrong here? I am simply trying to get the
      wlh1074> referenced value to show a print out on the screen.

      wlh1074> #!/usr/bin/perl
      wlh1074> use strict;
      wlh1074> use warnings;
      wlh1074> use Moose;

      wlh1074> package FooClass;

      You don't have any "has" here...


      wlh1074> my $foo = FooClass->new( name => 'Wendell');

      ... so "name" is ignored here, and thus...

      wlh1074> print $foo->{name};

      ... there'll be nothing here.

      Without "has", there are no "member" variables (using Java's
      terminology) or "instance" variables (using Smalltalk/Moose
      terminology). And unfortunately for beginners, the ->new method just
      ignores anything it doesn't grok.

      Try something like this instead:

      BEGIN {
      package Foo;
      use Moose;
      has name => (is => 'rw');
      }

      my $object = Foo->new(name => 'Randal');

      print $object->name, "\n";

      And be aware:

      **************************************************
      *
      * THIS IS NOT THE OFFICIAL perl BEGINNERS GROUP.
      *
      * The official one is at beginners@..., with instructions on how to
      * join at http://lists.perl.org/list/beginners.html.
      *
      * You'll get far better response there, not to say you won't get *any* here.
      *
      **************************************************


      --
      Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
      <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
      Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
      See http://methodsandmessages.posterous.com/ for Smalltalk discussion
    • Wendell Hatcher
      I actually tried that before with a similar syntax and it didn t print out to the screen. #!/usr/bin/perl use strict; use warnings; BEGIN{ package FooClass;
      Message 2 of 9 , Oct 14, 2010
      View Source
      • 0 Attachment
        I actually tried that before with a similar syntax and it didn't print out to the screen.

        #!/usr/bin/perl
        use strict;
        use warnings;


        BEGIN{

        package FooClass;
        use Moose;
           has name => (is =>'rw'); 
          
        }

        my $foo = FooClass->new(name => 'Dell');

        print $foo->{name};




        --- On Thu, 10/14/10, merlyn@... <merlyn@...> wrote:

        From: merlyn@... <merlyn@...>
        Subject: Re: [PBML] Moose what am I doing wrong here?
        To: "wlh1074" <wlh1074@...>
        Cc: perl-beginner@yahoogroups.com
        Date: Thursday, October 14, 2010, 11:52 AM







         









        >>>>> "wlh1074" == wlh1074 <wlh1074@...> writes:



        wlh1074> 1.) If I create a new object with a call to a method that

        wlh1074> does a say or print statement how do I get this to print to

        wlh1074> the screen?



        With say or print.



        wlh1074> 2.) I have written a little code in java and am a beginner

        wlh1074> intermediate in perl. How do I call the new object package from

        wlh1074> another file in the same directory path? Do I need to hard code

        wlh1074> the path or can this just be call by the use: statement?



        See "perldoc lib" to add directories to your @INC path.



        wlh1074> What am I doing wrong here? I am simply trying to get the

        wlh1074> referenced value to show a print out on the screen.



        wlh1074> #!/usr/bin/perl

        wlh1074> use strict;

        wlh1074> use warnings;

        wlh1074> use Moose;



        wlh1074> package FooClass;



        You don't have any "has" here...



        wlh1074> my $foo = FooClass->new( name => 'Wendell');



        ... so "name" is ignored here, and thus...



        wlh1074> print $foo->{name};



        ... there'll be nothing here.



        Without "has", there are no "member" variables (using Java's

        terminology) or "instance" variables (using Smalltalk/Moose

        terminology). And unfortunately for beginners, the ->new method just

        ignores anything it doesn't grok.



        Try something like this instead:



        BEGIN {

        package Foo;

        use Moose;

        has name => (is => 'rw');

        }



        my $object = Foo->new(name => 'Randal');



        print $object->name, "\n";



        And be aware:



        **************************************************

        *

        * THIS IS NOT THE OFFICIAL perl BEGINNERS GROUP.

        *

        * The official one is at beginners@..., with instructions on how to

        * join at http://lists.perl.org/list/beginners.html.

        *

        * You'll get far better response there, not to say you won't get *any* here.

        *

        **************************************************



        --

        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095

        <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>

        Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.

        See http://methodsandmessages.posterous.com/ for Smalltalk discussion























        [Non-text portions of this message have been removed]
      • merlyn@stonehenge.com
        ... Wendell print $foo- {name}; Please stop that. You want print $foo- name. Use method calls. Don t peer inside the box. -- Randal L. Schwartz - Stonehenge
        Message 3 of 9 , Oct 14, 2010
        View Source
        • 0 Attachment
          >>>>> "Wendell" == Wendell Hatcher <wlh1074@...> writes:

          Wendell> print $foo->{name};

          Please stop that.

          You want print $foo->name.

          Use method calls. Don't peer inside the box.

          --
          Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
          <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
          Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
          See http://methodsandmessages.posterous.com/ for Smalltalk discussion
        • Wendell Hatcher
          Here is what I have and it doesn t work Have you tested this with positive results? #!/usr/bin/perl use strict; use warnings; BEGIN{ package FooClass; use
          Message 4 of 9 , Oct 14, 2010
          View Source
          • 0 Attachment
            Here is what I have and it doesn't work Have you tested this with positive results?


            #!/usr/bin/perl
            use strict;
            use warnings;


            BEGIN{

            package FooClass;
            use Moose;
               has name => (is =>'rw'); 
              
            }

            my $foo = FooClass->new( name => 'Dell');

            print $foo->name;


            --- On Thu, 10/14/10, merlyn@... <merlyn@...> wrote:

            From: merlyn@... <merlyn@...>
            Subject: Re: [PBML] Moose what am I doing wrong here?
            To: "Wendell Hatcher" <wlh1074@...>
            Cc: perl-beginner@yahoogroups.com
            Date: Thursday, October 14, 2010, 12:04 PM







             









            >>>>> "Wendell" == Wendell Hatcher <wlh1074@...> writes:



            Wendell> print $foo->{name};



            Please stop that.



            You want print $foo->name.



            Use method calls. Don't peer inside the box.



            --

            Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095

            <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>

            Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.

            See http://methodsandmessages.posterous.com/ for Smalltalk discussion























            [Non-text portions of this message have been removed]
          • merlyn@stonehenge.com
            ... Wendell Here is what I have and it doesn t work Have you tested this with positive results? Wendell #!/usr/bin/perl Wendell use strict; Wendell use
            Message 5 of 9 , Oct 14, 2010
            View Source
            • 0 Attachment
              >>>>> "Wendell" == Wendell Hatcher <wlh1074@...> writes:

              Wendell> Here is what I have and it doesn't work Have you tested this with positive results?
              Wendell> #!/usr/bin/perl
              Wendell> use strict;
              Wendell> use warnings;


              Wendell> BEGIN{

              Wendell> package FooClass;
              Wendell> use Moose;
              Wendell>    has name => (is =>'rw'); 
              Wendell>   
              Wendell> }

              Wendell> my $foo = FooClass->new( name => 'Dell');

              Wendell> print $foo->name;

              Did you add a newline there, like I had in my example?

              If not, your output might be being overwritten by your prompt when the
              program ends.

              --
              Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
              <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
              Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
              See http://methodsandmessages.posterous.com/ for Smalltalk discussion
            • Wendell Hatcher
              yes, in-fact I took your code below and just added my name with no success. #!/usr/bin/perl use strict; use warnings; BEGIN { package Foo; use Moose; has name
              Message 6 of 9 , Oct 14, 2010
              View Source
              • 0 Attachment
                yes, in-fact I took your code below and just added my name with no success.

                #!/usr/bin/perl
                use strict;
                use warnings;

                BEGIN {
                package Foo;
                use Moose;
                has name => (is => 'rw');
                }

                my $object = Foo->new(name => 'Dell');

                print $object->name, "\n";


                --- On Thu, 10/14/10, merlyn@... <merlyn@...> wrote:

                From: merlyn@... <merlyn@...>
                Subject: Re: [PBML] Moose what am I doing wrong here?
                To: "Wendell Hatcher" <wlh1074@...>
                Cc: perl-beginner@yahoogroups.com
                Date: Thursday, October 14, 2010, 12:15 PM







                 









                >>>>> "Wendell" == Wendell Hatcher <wlh1074@...> writes:



                Wendell> Here is what I have and it doesn't work Have you tested this with positive results?

                Wendell> #!/usr/bin/perl

                Wendell> use strict;

                Wendell> use warnings;



                Wendell> BEGIN{



                Wendell> package FooClass;

                Wendell> use Moose;

                Wendell>    has name => (is =>'rw'); 

                Wendell>   

                Wendell> }



                Wendell> my $foo = FooClass->new( name => 'Dell');



                Wendell> print $foo->name;



                Did you add a newline there, like I had in my example?



                If not, your output might be being overwritten by your prompt when the

                program ends.



                --

                Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095

                <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>

                Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.

                See http://methodsandmessages.posterous.com/ for Smalltalk discussion























                [Non-text portions of this message have been removed]
              • merlyn@stonehenge.com
                ... Wendell yes, in-fact I took your code below and just added my name with no success. Wendell #!/usr/bin/perl Wendell use strict; Wendell use warnings;
                Message 7 of 9 , Oct 14, 2010
                View Source
                • 0 Attachment
                  >>>>> "Wendell" == Wendell Hatcher <wlh1074@...> writes:

                  Wendell> yes, in-fact I took your code below and just added my name with no success.
                  Wendell> #!/usr/bin/perl
                  Wendell> use strict;
                  Wendell> use warnings;

                  Wendell> BEGIN {
                  Wendell> package Foo;
                  Wendell> use Moose;
                  Wendell> has name => (is => 'rw');
                  Wendell> }

                  Wendell> my $object = Foo->new(name => 'Dell');

                  Wendell> print $object->name, "\n";

                  This runs just fine for me, prints "Dell" followed by newline. *Just*
                  tested it.

                  --
                  Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
                  <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
                  Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
                  See http://methodsandmessages.posterous.com/ for Smalltalk discussion
                • Wendell Hatcher
                  hmm, not sure why it isnt printing out for me. I am using the code below and calling it from my windows laptop from the command line. #!/usr/bin/perl use
                  Message 8 of 9 , Oct 14, 2010
                  View Source
                  • 0 Attachment
                    hmm, not sure why it isnt printing out for me. I am using the code below and calling it from my windows laptop from the command line.


                    #!/usr/bin/perl
                    use strict;
                    use 5.12.1;
                    use warnings;

                    BEGIN {
                    package Foo;
                    use Moose;
                    has name => (is => 'rw');
                    }

                    my $object = Foo->new(name => 'Dell');

                    print $object->name, "\n";


                    --- On Thu, 10/14/10, merlyn@... <merlyn@...> wrote:

                    From: merlyn@... <merlyn@...>
                    Subject: Re: [PBML] Moose what am I doing wrong here?
                    To: "Wendell Hatcher" <wlh1074@...>
                    Cc: perl-beginner@yahoogroups.com
                    Date: Thursday, October 14, 2010, 12:25 PM







                     









                    >>>>> "Wendell" == Wendell Hatcher <wlh1074@...> writes:



                    Wendell> yes, in-fact I took your code below and just added my name with no success.

                    Wendell> #!/usr/bin/perl

                    Wendell> use strict;

                    Wendell> use warnings;



                    Wendell> BEGIN {

                    Wendell> package Foo;

                    Wendell> use Moose;

                    Wendell> has name => (is => 'rw');

                    Wendell> }



                    Wendell> my $object = Foo->new(name => 'Dell');



                    Wendell> print $object->name, "\n";



                    This runs just fine for me, prints "Dell" followed by newline. *Just*

                    tested it.



                    --

                    Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095

                    <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>

                    Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.

                    See http://methodsandmessages.posterous.com/ for Smalltalk discussion























                    [Non-text portions of this message have been removed]
                  Your message has been successfully submitted and would be delivered to recipients shortly.