Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Any opinions expressed herein are from someone with about a month's exposure to Perl working with it during what little free time I have. Saying that, here goes from my still "new to Perl" point of view... :)

while (<>) { ... } or while (my $line = <>) { ... }?

I generally use the former right now for ease of typing although I'm beginning to have some notions seeping into my head about lexical scoping of $_ which I think I need to learn more about!

-w or use warnings;?

I started with -w for my first few programs just because I'd read it on here, then I changed to use warnings; after some interesting discussions on here and due to the fact the Perl code I'm writing is always designed to be run on a version of Perl that supports it.

sub CONSTANT () { ... } or use constant CONSTANT => ...;?

This would have to be the latter as I didn't really know about the former until now :) Time to research the differences if any! (Hopefully there will be lots of wise words in this thread)

my ($foo, $bar) = @_; or my $foo = shift; my $bar = shift;?

Originally I'd have chosen the first option but since I've been trying to play around with packages and OO programming in Perl I've come to understand that shift isn't as scarey as it first looked so now I'd choose the latter.

for (@array) { ... } or foreach (@array) { ... }?

Easy one! The first because it has fewer keystrokes, I'm lazy, and right now I'm the only one who will ever see my Perl so there is nothing to be gained (AFAIK) in using the extra four letters. (Enlightenment is welcomed if there *is* a difference at all)

print 'foo'; or print('foo');?

Generally without the parentheses unless I have some scoping issue. Speaking of scoping issues that *really* hurt me the first time it happened but now I'm more wary!

'simple string' or "simple string"?

Always single quotes unless I know there is some variable in the string that I want interpolated, just seems safer that way to me right now.

glob '*' or &lt;*&gt;?

At the moment I'd pick glob '*' because my limited experience of glob is currently just from reading the Llama book so I like to be reminded that it's there and I still don't "get" what it does 100%

readline *FOO or &lt;FOO&gt;?

I'd choose the latter here simply because the former is a notation I hadn't seen much of before.

for (keys %foo) { $_ and $foo{$_} } or while (my ($key, $value) = each %foo) { $key and $value }?

Again I'd choose the former but there is still some tingling feeling running up my spine that I'm not entirely conversant with the scoping of $_ and what I can and can't do with it! :)

Nice thread,

In reply to Re: Style, style, style by Nemp
in thread Style, style, style by Juerd

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 or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2021-07-25 10:54 GMT
Find Nodes?
    Voting Booth?

    No recent polls found