I tried to add a parameter to the following code and it does not work.

Thats because that code is unorganized and full of "Red flags".

Organize your code, box up everything into subroutines (Every loop, every heredoc template, every giant if/else block).

This is a "Red flag" localtime ... $year + 1900, . Time::Piece and DateTime is what you want to use for date stamps/math, none of this +1900 stuff.

You would benefit heavily from reading "Red flag" as it was written exactly for you. Almost every example is one you have posted here.

Subroutines should take arguments not work on globals. You shouldn't mix who prints from where....

This is something like what your program should end up looking like

Main( @ARGV ); exit( 0 ); sub Main { my $pms = empire->new; my $query = CGI->new; my( $header, $body ) = Dispatch( $pms, $query ); print $header, $body; } sub Dispatch { my( $pms, $q ) = @_; if( $pms->authenticate( $q ) ){ my $page = $q->page || 'default'; return ThisPage( $pms, $q ) if $page eq 'thisone'; return ThatPage( $pms, $q ) if $page eq 'thatone'; return DefaultPage( $pms, $q ); } else { return UnauthorizedPage( $pqms, $q ); } } sub UnauthorizedPage { my( $pms, $q ) = @_; return RedirectTo($q, 'notloggedin.cgi'); } sub RedirectTo { my( $q , $page ) = @_; my $header = $q->redirect( UrlFor( $page ) ); my $body = ''; return $header, $body; } sub UrlFor { my( $name ) = @_; return $name; } sub DefaultPage { my( $pms, $q ) = @_; my $members = $pms->list_members; my $schedule = $pms->campaign_schedule; return $q->header, CampaignMembersHtml( $pms, $q, $members, $sched +ule ); } sub CampaignMembersHtml { my( $pms, $q, $members, $schedule ) = @_; my $html = MembersHtml( $q, $members ); $html .= ScheduleHtml( $q, $schedule ); return $html; } sub MembersHtml { ...; } sub ScheduleHtml { my( $q, $schedule ) =@_; my ( $status, $schedule_date, $max_emails, $clast60, $aolflag, $openflag, $yaho­o_flag, $shour, $smin, $old_mid, $old_dname, $cname, ) = @$schedule; ...; return $html; } sub Empire::authenticate { my( $pms, $query ) = @_; my $user = $query->param('user'); my $pass = $query->param('pass'); return !! $pms->check_security( $user, $pass ) } sub Empire::list_members { my( $pms, $q ) = @_; ... my $members = $dbh->selectall_arrayref($sql); ... return $members; } sub Empire::campaign_schedule { my( $pms, $q ) = @_; ... my $schedule = $dbh->selectall_arrayref($sql); ... return $schedule; }

In reply to Re: Object Identifier? (red flags, more subs) by Anonymous Monk
in thread Object Identifier? by damfer21

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.