books on perl

K

K4 Monk

can someone be so kind to point out some good perl books? I've
programmed in perl for a few years now but only to write small scripts
etc. and never went deep down to even find out stuff like proper use
of regex or parsing long strings for repeat patterns etc. Any help
would be appreciated.
 
C

ccc31807

can someone be so kind to point out some good perl books? I've
programmed in perl for a few years now but only to write small scripts
etc. and never went deep down to even find out stuff like proper use
of regex or parsing long strings for repeat patterns etc. Any help
would be appreciated.

In my opinion, the best book not on a beginner level is 'Higher Order
Perl' by Mark Jason Dominus. You can get it for free at
http://hop.perl.plover.com/
but I strongly recommend buying it, not least because it encourages
others to write such books.

You can also obtain books for special topics, like the Perl DBI, Perl
CGI, networking, object oriented Perl, data munging, best practices,
Perl and TK, and so on. Speaking for myself, the two most important
books in my Perl development are data munging by Cross, and Perl and
MySQL by Dubois, although both of these books are regarded poorly by
the Perl community as a whole.

Finally, the most essential 'book' is the Perl documentation. I
constantly keep this open on my computer, and have been known to
actually print dead tree copies of particular sections and study them.
You really can't consider this as a text -- the purpose isn't (in most
cases) to instruct -- but the documentation is the one thing that
every Perl developer should know and love.

CC.
 
J

Justin C

can someone be so kind to point out some good perl books? I've
programmed in perl for a few years now but only to write small scripts
etc. and never went deep down to even find out stuff like proper use
of regex or parsing long strings for repeat patterns etc. Any help
would be appreciated.

Ask perl: `perldoc -q book`

Justin.
 
E

Ekki (DF4OR) Plicht

K4 said:
can someone be so kind to point out some good perl books? I've
programmed in perl for a few years now but only to write small scripts
etc. and never went deep down to even find out stuff like proper use
of regex or parsing long strings for repeat patterns etc. Any help
would be appreciated.

a) this is an FAQ, see perlfaq2, Perl Books

b) I just finished "Modern Perl" by 'chromatic', ISBN 978-0-9779201-5-0.
Although available online I bought the paper edition (easier to read in the
tub) to support the author(s).
Highly recommended, even or especially if you already have some Perl
experience. Gives an excellent overview of modern Do's and Don'ts, a solid
refresh of my knowledge and a bagful of useful hints and tricks.

YMMV.


Cheers,
Ekki
 
C

ccc31807

is "O'Reilly rules!" :)

Yes, O'Reilly generally produces books of a high caliber, with the odd
exception here and there -- certainly several orders of magnitude
above the Sam's Teach Yourself in 24 Hours books.

However, I'm beginning to like the Manning books as well. The ones I
have also do well. They tend to be Windows centric, but we don't judge
the quality of a book by the OS or technology preference. Case in
point: 'Object Oriented Perl' by Damian Conway.

I also like the few Pragmatic Bookshelf books I've bought, not as
strong perhaps as O'Reilly but still of high quality.

CC.
 
J

Justin C

vidura@localhost~ $ perldoc -q book
You need to install the perl-doc package to use this program.

God helps those who help themselves. Install perldoc.

Justin.
 
J

Jürgen Exner

K4 Monk said:
[...]
vidura@localhost~ $ perldoc -q book
You need to install the perl-doc package to use this program.

This combination is, well, shall we say, "interesting". How did you
manage to program in Perl without using the Perl documentation?

May I suggest to repair your broken installation asap?

jue
 
K

K4 Monk

K4 Monk said:
I've programmed in perl for a few years now
[...]
vidura@localhost~ $ perldoc -q book
You need to install the perl-doc package to use this program.

This combination is, well, shall we say, "interesting". How did you
manage to program in Perl without using the Perl documentation?

May I suggest to repair your broken installation asap?

jue

I've installed it now. I've programmed (if you can call it that) in
perl for years and never heard about perldoc. I generally wrote
whatever scripts I had to write with a bit of fiddling around and
looking at existing code
 
J

J. Gleixner

K4 said:
I've installed it now. I've programmed (if you can call it that) in
perl for years and never heard about perldoc. I generally wrote
whatever scripts I had to write with a bit of fiddling around and
looking at existing code

Welcome to the 21st century. :)

Be sure to learn about CPAN too: http://www.cpan.org/
 
K

K4 Monk

Welcome to the 21st century. :)

Be sure to learn about CPAN too:  http://www.cpan.org/

Thank you! btw, I posted this in another newsgroup but never got a
response. After reading this thread and one of the booke (HOP) I have
realized that I don't know Perl. I've never used functions extensively
and don't understand how they work. And here's a program I wrote to
prove it.

#!/usr/bin/perl
use strict;

sub func {
my %list;
$list{"map"} = "key";
$list{"l"}="j";

my @arr;
push (@arr, "egg");
push (@arr, "hell");


return (%list, @arr);

}

my @arrref = &func();
my %l = %{$arrref[0]};
my @r = @{$arrref[1]};

print "keys\n";
foreach my $k(keys %l) { print "$k\n"; }
print "array\n";
foreach my $rr(@r) { print "$rr\n"; }
 
J

Jürgen Exner

K4 Monk said:
Thank you! btw, I posted this in another newsgroup but never got a
response. After reading this thread and one of the booke (HOP) I have
realized that I don't know Perl. I've never used functions extensively
and don't understand how they work.

See "perldoc perlsub"
And here's a program I wrote to
prove it.

#!/usr/bin/perl
use strict;

Good. But you should also enable warnings.

use warnings;
sub func {
my %list;
$list{"map"} = "key";
$list{"l"}="j";

You can write such an initialization more easily as
my %list = (
"map" => "key",
"l" => "j");
my @arr;
push (@arr, "egg");
push (@arr, "hell");

Most people would probably do a simple
my @arr = ('egg", "hell");
return (%list, @arr);

You are aware that you are returning a list with 6 elements, mixing your
hash and array elements indiscrimently togehter, aren't you?
Just like arguments the return value of a sub is just a list of scalars,
too, and any sub-structure or composite data will be flattened.
}

my @arrref = &func();

Just print the lenght of the array here
print scalar(@arrref);
and it will tell you that @arrref contains 6 elements.
my %l = %{$arrref[0]};
my @r = @{$arrref[1]};

Whatever you are trying to do here doesn't work because @arrref already
contains the wrong data. If you want to preserve your return hash and
return array from sub func then first of all you have to return a
reference to them instead of their values (see "Make Rule 1" in "Making
References" in "perldoc perlreftut")

return (\%list, \@arr);

Then the rest will more or less fall into place on its own.

jue
 
K

K4 Monk

See "perldoc perlsub"



Good. But you should also enable warnings.

        use warnings;


You can write such an initialization more easily as
        my %list = (
            "map" => "key",
            "l" => "j");


Most people would probably do a simple
        my @arr = ('egg", "hell");


You are aware that you are returning a list with 6 elements, mixing your
hash and array elements indiscrimently togehter, aren't you?

Thank you jue, no I wasn't aware of this, and on my end I spent an
hour looking for the but gave up.
Just like arguments the return value of a sub is just a list of scalars,
too,  and any sub-structure or composite data will be flattened.

so, even if I do a func(%hash), on func's end it gets an array of a
scalar pointing to %hash?

Just print the lenght of the array here
        print scalar(@arrref);

nice. I noted this down.
and it will tell you that @arrref contains 6 elements.
my %l = %{$arrref[0]};
my @r = @{$arrref[1]};

Whatever you are trying to do here doesn't work because @arrref already
contains the wrong data. If you want to preserve your return hash and
return array from sub func then first of all you have to return a
reference to them instead of their values (see "Make Rule 1" in "Making
References" in "perldoc perlreftut")

        return (\%list, \@arr);

Then the rest will more or less fall into place on its own.

jue

Thanks jue for your help!
 
J

Jürgen Exner

K4 Monk said:
so, even if I do a func(%hash), on func's end it gets an array of a
scalar pointing to %hash?

No. It gets a flat(!) list(!) which is composed of the alternating keys
and values of %hash, i.e. if %hash has 5 entries then the argument list
@_ of func(%hash) will contain 10 values.

jue
 
J

Justin C

so, even if I do a func(%hash), on func's end it gets an array of a
scalar pointing to %hash?

AIUI (and ICBW, in which case this'll be a learning exercise for me
too), if you do func(%hash) what func receives *is* an array, there's
no 'pointing to'. For example:

my %hash = (
john => "lennon",
paul => "macca",
george => "harrison",
ringo => "star",
);
func(%hash);

func() would receive an array containing qw/john, lennon, paul, macca,
george, harrison, ringo, star/ ... which can be shown by:
sub func {
print $_, "\n" for @_;
}

You could massage the array back into a hash in func() with (for
example)
sub func {
my %hash = @_;
# do stuff ...
}

Justin.
 
K

K4 Monk

Have you done that yet?

yep, finally!

"The Perl model for function call and return values is simple:
all functions are passed as
parameters one single flat list of scalars, and all functions
likewise return to their caller one
single flat list of scalars. Any arrays or hashes in these
call and return lists will collapse,
losing their identities--but you may always use pass-by-
reference instead to avoid this. "
 
M

Martijn Lievaart

kick($self)

Better written as:

$self->kick();

although if kick() does not exist, the former fails at compile time while
the latter fails at run time.

:)

M4
 
R

Randal L. Schwartz

Martijn> Better written as:

Martijn> $self->kick();

Martijn> although if kick() does not exist, the former fails at compile time while
Martijn> the latter fails at run time.

And if kick doesn't know what to do with an object of the type that
$self is, it'll have to check that itself unless it's a method call. :)
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top