Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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 making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2025-03-25 23:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When you first encountered Perl, which feature amazed you the most?










    Results (67 votes). Check out past polls.

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.