Hi perleager. I didn't mean to sound too harsh, and it's not like indenting is the most important thing and tastes vary. But in a chunk of code like you have, I find it most useful to indent mostly based on blocks -- start the indent with the opening "{" of the block and end the indent with the closing "}". This lets you see at a glance which block each line is part of and also to easily check to make sure you didn't omit a curly brace. I sometimes also indent arguments to functions using the opening and closing parentheses to see where to indent. Here's how I would indent your code (again, tastes vary, this is just my way):
use DBI; my $dbh = DBI->connect( $main::location, $main::user, $main::ba_pass, {RaiseError=>1,AutoCommit=>1} ) or die "Couldn't connect to database: " . $DBI::errstr; # # indent one level for the eval block # eval { my $sth= $dbh->prepare("SELECT id FROM sessions"); my $id; $sth->execute(); $sth->bind_columns(undef, \$id); require CGI::Session; import CGI::Session; # # indent a second level for the while block # while ($sth->fetch()) { my $session = CGI::Session->load( "driver:MySQL", $id, {Handle=>$dbh} ); next if $session->is_empty; # # indent a third level for the if block # if (($session->ctime + $session->etime) <= time()) { $session->delete(); } } }; if ($@) { print $@; $dbh->disconnect(); }

update:renamed it so I could find it :-)


In reply to Indentation Style by jZed
in thread CGI::Session disconnect invalidates 1 active statement handle by perleager

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.