Perl Newbie question about upgrade from Perl 5.8.8 to 5.10

2009-01-15 Thread dolphin_sonar
Hi,

I bought the O'Reilly 5th edition Learning Perl the other day and it's
great. I am new to programming and Perl as well. I do know my way
around Linux but I am having problems upgrading from the version that
was on my OS (Cent OS 5.2) to 5.10. I downloaded Perl 5.10 from
http://www.cpan.org/authors/id/R/RG/RGARCIA/perl-5.10.0.tar.gz, then
tar -xvzf perl-5.10.0.tar.gz the package in /usr/local/bin   I then
followed the README guide that said to:

./Configure -des -Dprefix=$HOME/localperl
  make test
  make install

Now, the first command was probably my mistake because I really have
no idea what that would do. I figured that I could simply use the
shebang after make test and make install was done "doing it's thing"
and type out #!/usr/local/bin/perl-5.10.0 or  #!/usr/local/bin/
perl-5.10 and everything was work just fine and I would be using Perl
5.10 This obviously is not the case as now it tells me I still have
5.8.8 installed. I know this is probably a very common problem and
I'll try and do all the research I can when I find the time but if any
of you that are a lot more experienced could help me out and "put me
in the right direction" that would be great.

Here is the code from the book (page 68) I am trying to run:
---
#!/usr/local/bin/perl-5.10.0 # I've also used perl5.10 and every
other thing I could think of...
use 5.010;
use strict;

sub marine {
state $n = 0;   # private, persistent variable $n
$n += 1;
print "Hello, sailor number $n!\n";
}

&marine;
&marine;
&marine;

And here is the output I am getting when I try running it:
Perl v.5.10.0 required --this is only v.5.8.8


I've also noticed that now there's a perl5.10.0 located in the /root/
localperl/bin so I am sure it has something to do with the
above .Configure command. Can anyone give me some advice on how to get
5.10 working? I feel like I am close, but nothing so far.

thanks in advance,
jim


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Perl Newbie question about upgrade from Perl 5.8.8 to 5.10

2009-01-16 Thread dolphin_sonar
On Jan 15, 7:39 am, telemac...@arpinum.org (Telemachus) wrote:
> On Wed Jan 14 2009 @  8:17, dolphin_sonar wrote:
>
>
>
> > Hi,
>
> > I bought the O'Reilly 5th edition Learning Perl the other day and it's
> > great. I am new to programming and Perl as well. I do know my way
> > around Linux but I am having problems upgrading from the version that
> > was on my OS (Cent OS 5.2) to 5.10. I downloaded Perl 5.10 from
> >http://www.cpan.org/authors/id/R/RG/RGARCIA/perl-5.10.0.tar.gz, then
> > tar -xvzf perl-5.10.0.tar.gz the package in /usr/local/bin   I then
> > followed the README guide that said to:
>
> > ./Configure -des -Dprefix=$HOME/localperl
> >   make test
> >   make install
>
> > Now, the first command was probably my mistake because I really have
> > no idea what that would do.
>
> In -Dprefix=$HOME/localperl, the variable $HOME is what you're not getting,
> I think. That configuration line means "build a new installation of Perl in
> my home directory and put it all into a folder called localperl."
> (Normally, the build would get put into the directory you choose, but then
> into bin/, lib, share/ and man/ directories there.)
>
> > I've also noticed that now there's a perl5.10.0 located in the /root/
> > localperl/bin so I am sure it has something to do with the
> > above .Configure command. Can anyone give me some advice on how to get
> > 5.10 working? I feel like I am close, but nothing so far.
>
> Apparently, you were logged in as root when you built and installed this
> version of Perl. That was a mistake. You should be root as little as
> possible. (I can tell you were root since $HOME for root = /root. You
> configured it to be built in $HOME/localperl and it was.)
>
> In any case, I would recommend that you remove entirely the localperl/
> directory in your root home directory, and then start again. Download the
> latest sources as a regular user, in your regular user's $HOME. Then build
> it and install it there. After that you should be able to invoke it with
> this shebang line:
>     #!/home/username/localperl/bin/perl
>
> Hope this helps, T

T,

You are 'so right on'!. Thanks, as you just confirmed what someone
else told me on my local Perl Mongers mailing list, though he didn't
catch that I was logged in as root so thank you for the tip on that.
Now I am starting to really understand why people say that 'You should
be root as little as possible' I will remove the localperl dir
immediately in root. Thanks! I really do appreciate it!

J.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Newbie question about variables, arrays and where they all go

2009-01-18 Thread dolphin_sonar
   1 # When calling 'running_sum(5, 6);' the variable 'state @numbers'
receives those two
   2 # parameters, (5 and 6), right? Then, the @numbers array also
copies/stores (5 and 6)
   3 # into the special '( @_ )' variable as well, right? Also, line
13 pushes '$number' into
   4 # the '@numbers' array each time through the foreach loop,
right?
   5 # For instance, it pushes 5 to the end of the array the first
time around,
   6 # then pushes 6 to the end of the array the next time around.
   7
   8 sub running_sum {
   9state $sum = 0;
  10state @numbers;
  11
  12foreach my $number ( @_ ) {
  13push (@numbers, $number);
  14$sum += $number;
  15}
  16say "The sum of (@numbers) is $sum";
  17 }
  18
  19 running_sum( 5, 6 );


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Newbie question about variables, arrays and where they all go

2009-01-19 Thread dolphin_sonar
On Jan 18, 7:54 pm, telemac...@arpinum.org (Telemachus) wrote:
> On Sun Jan 18 2009 @ 10:59, dolphin_sonar wrote:
>
> >    1 # When calling 'running_sum(5, 6);' the variable 'state @numbers'
> > receives those two
> >    2 # parameters, (5 and 6), right? Then, the @numbers array also
> > copies/stores (5 and 6)
> >    3 # into the special '( @_ )' variable as well, right? Also, line
> > 13 pushes '$number' into
> >    4 # the '@numbers' array each time through the foreach loop,
> > right?
>
> Maybe I'm not understanding what you mean, but I think you're confused. The
> arguments to a subroutine go into the @_ array. The @numbers array is
> empty until you load it up in the foreach loop. Having 5 and 6 as arguments
> does not automatically put those items into @numbers, nor does @numbers
> copy anything into @_.
>
> Also, I understand that you may just be testing out persistent variables in
> 5.10, but this program is confusing.
>
> Consider what happens if you call running sum a second time (say as
> running_sum( 2, 7 );) If I add that call, here's my output:
>
>     telemachus ~ $ perl sum
>     The sum of (5 6) is 11
>     The sum of (5 6 2 7) is 31
>
> That appears to say that perl has added 5, 6, 2, and 7 up to 31. What
> actually happened was that you added 5, 6, 2 and 7 (20) to 11 (the sum from
> the previous call to running_sum - which was saved). To put this another way
> around: maybe you want to keep a running sum, but the print statement in the
> subroutine is very confusing.
>
> Hope this helps, T

T!

Again, you answered my question. You should be teaching Perl as your
responses are very clear and that's not easy for people to do...give
clear, concise responses.

Regardless, I now understand exactly what your saying about the state
@numbers declaration. I was confused about that and that helps me
understand a lot of what is going on, that was important for me to
understand. The example code actually had two more calls to running
sum: running_sum( 1..3 ); and running_sum( 4 ); (see the link to the
code and the out below).

Here is a link to the example code in a much better format, you can
see the code better than using Gmail IMO. http://sial.org/pbot/34575

# The output I get each time is this:
The sum of (5 6) is 11
The sum of (5 6 1 2 3 ) is 17
The sum of (5 6 1 2 3 4 ) is 21

This example comes from page 68 O'Reilly Learning Perl 5th edition.
They also used 'say' for the first time in the book instead of print
as well, which was kind of confusing to me.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/