in reply to Replacing parts of a string

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!

Replies are listed 'Best First'.
Re: Re: Replacing parts of a string
by spiderbo (Sexton) on Apr 11, 2003 at 14:26 UTC

    Unfortunately the code is not calendarview.pl, so I will try your

    $string =~ s/month=\d+/month=$newmonth/g;
    for my month and year.

    Still to find a solution for the CalendarName then... In response to your comment, it could be numeric or alphnumeric, in any order.