Comments requested: brief summary of Perl

M

Michele Dondi

No, it returns the assigned-to lvalue. This is why

(my $x = $y) =~ s/a/b/;

does what it does.

Yes, it's obvious. Now that you tell me! An yet I've used such
constructs who knows how many times... Thank you for the
clarification.


Michele
 
M

Malcolm Dew-Jones

Michele Dondi ([email protected]) wrote:

: | As a shortcut for lists of strings, you can use qw (the letter q followed by the letter w):
: ^^^^^^^

: Of "words"!

not really words, actually fairly arbitrary strings, just as long as they
don't have white space in them, try the following

e.g.

@a=qw( s/one/two/g; $x=sub{print"hello"}; );
eval $a[1];
&$x;
 
A

Adam Barr

Michele Dondi said:

Some more cmts...

[about REs]
| () can be used to group parts of a regular expression
^^^

But does a lot more than that, with side-effects. For simple grouping
you can use (?: ... ) instead.

| if ($phone =~ /\d{3}\-\d{4}/) {

if ($phone =~ /\d{3}-\d{4}/) {

| The return statement is actually optional; if it is missing, then the subroutine will return the
| value of the last expression calculated, or undef if no expressions were calculated.

But it becomes necessary if one wants to exit early from a sub, as is
often the case e.g. with recursive ones...

| Variables local to a function can be declared with the my operator, so the previous function
| could be written:

Variables local to "anything"! As you should have clearly stated much
above...

| accesses the global variable by name. And, for reasons which are best left to Perl wizards to
| explain, you can't use my on a file handle, you have to use local.

But with recent enough perls it is much better and highly recommended
to use lexical filehandles (unless backwards compatibility is an
issue), as you may explain in the section about open():

my $all = do {
open my $fh, '<', $file or die $!;
local $/;
<$fh> };


Hmmm, seems like eventually I finished it! These are more or less the
cmts and suggestion I felt like giving about your work. Other posters
(Hey, Ben!!) may correct me if, as is unfortunately usual, further
imprecisions have inadvertently slipped in...


Michele

Michele, thanks for all the great comments. I don't have time right
now to follow up on them, I will later, but I wanted to acknowledge
them now.

- adam
 
M

Michele Dondi

: | As a shortcut for lists of strings, you can use qw (the letter q followed by the letter w):

: Of "words"!

not really words, actually fairly arbitrary strings, just as long as they
don't have white space in them, try the following

Wild guess: may this be a good reason why I wrote qq|"words"| instead
of qq|words|?!?


Michele
 

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,009
Latest member
GidgetGamb

Latest Threads

Top