Style Bonanza
I started this for a couple reasons. The first is to say that, as Larry and company have stated, there's "Perl" the language and "perl" the interpreter -- they prefer not to see "PERL" written. The language is less an acronym now than a word.
The other is to introduce you to the relaxed style of coding that you might see me using. For instance, I usually don't use parenthesized calls to built-in functions:
open FILE, $name or die "can't open $name: $!";
push @people, "Joe", "Larry";
chomp @lines;
for (keys %hash) { ... }
$sentence = join " " => @word_list;
You'll also notice gratuitous use of default variables, like $_ and @_:
for (keys %ENV) {
print "$_ => $ENV{$_}\n";
}
sub getName {
my $uid = shift;
return $uid->{NAME};
}
for (@files) {
print "$_ => ", -s, "\n";
}
You'll probably also notice me doing idiomatic things... things that aren't easily reproducible in another language like C or Python or Java. That's because I believe there should be a reason you use Perl, and that reason should be taken advantage of sometimes.
That's my opinion, at the very least.
Vorm posted this at 03:26 — 2nd November 2000.
They have: 62 posts
Joined: May 2000
So what's with naming variables shift and split? What does that do?
And wow, that works?
japhy posted this at 13:18 — 2nd November 2000.
They have: 161 posts
Joined: Dec 1999
It's a matter of using the default arguments to a function. @words = split is the same as @words = split ' ', $_. And of course, you could use parentheses here... @words = split(), and @words = split(' ', $_). But I have a tendency not to, unless precedence issues take over.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.