Experts, How can we use value in sub which was accepted at script run?

DB: oracle 11gR2

I tried using $days = $ARGV[1], not sure but it doesn't work.

Usage: ./delete_data.pl -days 30
sub deleteData { $days = <how to have 10 here??>; my $sth = $dbh->prepare("DELETE FROM TEST_TABLE WHERE date = trunc(sysdate) - ?"); $sth->execute( $days ) or die $DBI::errstr; print "Number of rows deleted :" + $sth->rows; $sth->finish(); $dbh->commit or die $DBI::errstr; }
Does above delete all days together or it will use cursor and delete one day at a time? Deleting one day at a time using bind variable will give better performance. Thanks...

Update

Experts, How can we use value in sub which was accepted at script run?

DB: oracle 11gR2

I tried using $days = $ARGV[0], not sure but it doesn't work.

Usage: ./delete_data.pl -days 30
my $days; sub deleteData { my $rc; if (@ARGV) { $days = $ARGV[0]; $logfile-> logmessage ("Days in sub $days ...) } $days = shift (@ARGV); my $SQL = qq{ DELETE from TEST_TABLE WHERE trunc(date) < trunc(sysdate) - $days }; $sth->prepareCursor( $SQL ) or die $DBI::errstr; print "Number of rows deleted :" + $sth->rows; $sth->execute(); $rc++ $sth->finish() }
I'm not able to display value for $days even in logfile. Not sure why above just don't work, I have used suggestion solution from comment. Thanks...

In reply to Use command line argument in script by homer4all

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.