Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: How do I train myself to write more Perl-ish Perl, rather than C-ish Perl?

by LighthouseJ (Sexton)
on Dec 14, 2007 at 16:43 UTC ( [id://657078]=note: print w/replies, xml ) Need Help??


in reply to How do I train myself to write more Perl-ish Perl, rather than C-ish Perl?

I'm the king of writing C-ish Perl at least on the initial attempts. I know assembly code so I understand how much of a luxury C is so I'm eager to use it.

When I get to use Perl, my initial edits reek of C-style editing. However, as I refine the code, I shed the C-code and get to use pure Perl.

I have noticed that to shed the C-code, you pretty much have to exclusively use only the Perl functions. Take the obfuscations that people write, they are incarnations of pure Perl facilities, usually in obfuscated forms.

Sure, I could write a Perl program:
#!/usr/bin/perl -w use strict; { my $i = 0; for ($i = 0; $i<10; $i++) { print ("count $i\n"); } }
Not only is that not obfuscated but it's also very C-like. The only difference is identifying variables with dollar signs, and using print instead of printf (for it's closest-named C counterpart).

Now if I was going to shake off the C-style, I'd look for Perl-specific ways of streamlining this program. Eventually, after several iterations (because I don't claim to be a super perl programmer, just aware enough to do damage), I might be satisfied on this:
#!/usr/bin/perl -w use strict; print "count $_\n" for (0..9);
Not counting the interpreter line and use strict, see how I reduce everything down to only the things I need? I need to print something, state the format including where to put the variable, then repeat. That's all, no variable declarations, traditional loop structures, etc...

When you use Perl-specific mechanisms, that is only the minimum need to do the job, there won't be any use for traditional C-style coding behavior.
"The three principal virtues of a programmer are Laziness, Impatience, and Hubris. See the Camel Book for why." -- `man perl`

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://657078]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-25 21:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found