You could do the regexp thing: $string =~ s/month=\d+/month=$newmonth/g;, or if the code you are working on is calendarview.pl, and you already have a CGI.pm object you are working with, I find this is a really easy way to get slightly modified URLs:
my $cgi = new CGI;
# .... bunch of calendarview.pl code here ....
# need to get a url that takes us back to new years
my $newyears = new CGI($cgi);
$newyears->param('month',1);
$newyears->param('day',1);
my $newyears_url = $newyears->self_url;
Generally I just abstract this into a little subroutine:
sub new_self_url {
my %params = @_;
my $new = new CGI($cgi);
foreach(keys %params) {
$new->param($_,$params{$_});
}
return $new->self_url;
}
# now you can get urls back to your script with different
# dates like this:
my $newyears = new_self_url(month => 1, day => 1);
my $christmas = new_self_url(month => 12, day => 25);
We're not surrounded, we're in a target-rich environment! |
---|
-
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.
|