Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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`

In reply to Re: How do I train myself to write more Perl-ish Perl, rather than C-ish Perl? by LighthouseJ
in thread How do I train myself to write more Perl-ish Perl, rather than C-ish Perl? by amarquis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-19 19:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found