G'day Ben328,
Welcome to Perl and the monastery.
I don't know where you're looking online for Perl documentation. Except in very rare cases, the following two sites have provided all the Perl documentation I've needed for many years:
-
perldoc.perl.org - Perl Programming Documentation. You'll find Perl syntax, functions, built-in modules, etc. here.
-
search.cpan.org - CPAN (Comprehensive Perl Archive Network). You'll find user contributed modules here.
All documentation links I provide below are to pages on the first of those sites.
What is "join q[], @{+shift}" doing? Normally join is like join("expression", "list")
If online documentation has said that join("expression", "list") is normal syntax, it is wrong and I wouldn't use that site again. Did it say that or have you paraphrased what it said or, perhaps, taken it out of context? That piece of code evaluates to just "list" making join("expression", and the closing parenthesis completely pointless:
$ perl -Mstrict -Mwarnings -E '
my $x = join("expression", "list");
say $x;
my $y = "list";
say $y;
'
list
list
Take a look at join which shows the syntax as: join EXPR, LIST. (It only has one example which shows join(EXPR, LIST) - read on for a further explanation).
When you write a subroutine, e.g. sub some_function { ... }, you'd call it like this: some_function(arg1, ..., argN). Perl's built-in functions can, but don't need to, use the parentheses. It's normally perfectly fine to omit the parentheses; here's an example where you might include them:
print 'Tabbed items: ', join("\t", @items), "\n";
[Advanced exception: There is a way to make your functions act like Perl functions. It's generally a bad idea to do this. I strongly recommend that you do not do this - certainly not until you are way past the "newbie" stage. As you may see it in other's code, here's what I'm recommending you don't use: perlsub - Prototypes.]
It is all too easy to read '' as ". Can you see the difference in your browser? Perl has a number of Quote-Like Operators which you can use to avoid this potential confusion. That documentation shows q/.../, q!...! and q(...); tobyink has used q[...]; my personal preference is for q{...}; you can pick some other delimiter if you want. q[] is a zero-length string: it is unambiguous and doesn't require you to decide if you're looking at one double-quote or two single-quotes.
The start of the process_record function could have been written more verbosely as:
sub process_record
{
my $array_ref = shift;
my $record = join q[], @{$array_ref};
...
See shift if you're not sure how that works. The code @{shift} is ambiguous and could be interpreted as @shift or @{shift(@_)}. Adding the + tells Perl you mean the second interpretation. See perlop - Symbolic Unary Operators for a discussion of this.
And what is this line doing? local $Data::Dumper::Terse = 1;
I'm don't know what part of that you're having trouble with. Have a read of local and Data::Dumper ($Data::Dumper::Terse is mentioned in a few places). If you're still in the dark with one or more parts of that line of code, please specify where you're having problems.
|