Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > perl script for apache mod_rewrite

Reply
Thread Tools

perl script for apache mod_rewrite

 
 
Aaron Haspel
Guest
Posts: n/a
 
      09-08-2006
Greetings perl hackers:

Not being a perl programmer myself, I'm trying to get a simple perl
script to work for url rewriting and I'm having a bit of trouble. My
script looks like this:

#!/usr/bin/perl
$|=1; # Turn off buffering
while ( <STDIN> )
{
local $postid = $_;
++postid;
print "/?p=$postid\n";
}

Simple enough. Just takes old urls, converts them to numbers, adds 1,
and returns a string. Runs fine from the command line. But when I try
to use it in a RewriteRule in apache, it behaves strangely. The first
time it executes, it returns null. The next time it executes, it
returns what one would have expected from the first run, the third time
from the second, and so forth. So, for example, if I run it three times
I get the following:

arg: /archives/00000590.html return: null
arg: /archives/00000577.html return: /?p=591
arg: /archives/00000490.html return: /?p=578

I thought about posting this to apache, but the script is executing
when it's supposed to, just weirdly, so I thought it was more of a perl
problem. Any help is most appreciated.

Regards,
Aaron Haspel

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      09-08-2006
Aaron Haspel wrote:
> Greetings perl hackers:
>
> Not being a perl programmer myself,


<snip>

> Runs fine from the command line. But when I try
> to use it in a RewriteRule in apache, it behaves strangely.


<snip>

> I thought about posting this to apache, but the script is executing
> when it's supposed to, just weirdly, so I thought it was more of a perl
> problem.


Think again, I'd suggest. You've already proven that when fed correct
data, it works as it's supposed to. Therefore, the Perl is fine. The
input, however, may not be. Talk to the Apache people about how the
data is being fed to the program.

Paul Lalli

 
Reply With Quote
 
 
 
 
rajeev.networld@gmail.com
Guest
Posts: n/a
 
      09-08-2006
I am wonder why dont u try using "my" variable instead of "local".

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      09-08-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I am wonder why dont u try using "my" variable instead of "local".


I wonder why you think that would matter.

Paul Lalli

 
Reply With Quote
 
Brian McCauley
Guest
Posts: n/a
 
      09-08-2006
(E-Mail Removed) wrote:

> I am wonder why dont u try using "my" variable instead of "local".


I wonder why you think this is relevant.

Granted there's no reason for the OP to be using local() where he could
use my() but this will not account for his problem.

 
Reply With Quote
 
Brian McCauley
Guest
Posts: n/a
 
      09-08-2006
Aaron Haspel wrote:

[ invalid code ]

> Runs fine from the command line.


So what does your actual code look like?

 
Reply With Quote
 
Aaron Haspel
Guest
Posts: n/a
 
      09-08-2006
Copied directly, here it is:

#!/usr/bin/perl
$|=1; # Turn off buffering
while (<STDIN>)
{
local $postid = $_;
++$postid;
print "/?p=$postid\n";
}

I apologize if the previous listing was wrong, and also for the bad
style that other commenters pointed out.

AH


Brian McCauley wrote:
> Aaron Haspel wrote:
>
> [ invalid code ]
>
> > Runs fine from the command line.

>
> So what does your actual code look like?


 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      09-08-2006
Brian McCauley wrote:
> Aaron Haspel wrote:
>
> [ invalid code ]
>
> > Runs fine from the command line.

>
> So what does your actual code look like?


I may be missing something, but would you care to explain what was
"invalid" about the code the OP posted?

Paul Lalli

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      09-08-2006
Paul Lalli wrote:
> Brian McCauley wrote:
> > Aaron Haspel wrote:
> >
> > [ invalid code ]
> >
> > > Runs fine from the command line.

> >
> > So what does your actual code look like?

>
> I may be missing something, but would you care to explain what was
> "invalid" about the code the OP posted?


D'oh. And now I see it. Missing sigil. Sorry, Brian, I should have
attempted to run it before asserting it was not invalid....

Paul Lalli

 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      09-08-2006
Aaron Haspel <(E-Mail Removed)> wrote:


> $|=1; # Turn off buffering


That does not turn off buffering you know.

$| = 1; # Enable auto-flush


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache mod_rewrite External Rewriting Program Patrick Joyce Ruby 1 11-01-2007 07:07 PM
MOD_REWRITE - Latin2 characters - 404 ERROR! janecki@gmail.com HTML 1 08-05-2006 06:10 PM
mod_rewrite active? MS Computer Support 1 08-14-2005 04:24 PM
Apache mod_rewrite Peter Morris [Droopy eyes software] ASP .Net 1 02-19-2005 08:53 PM
Servlet front page without redirect - Tomcat 4.1 with mod_rewrite and mod_jk2 Alex Martinoff Java 2 09-07-2003 06:50 PM



Advertisments