View the Most Wanted LQ Wiki articles.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-16-2006, 05:49 AM   #1
Registered: May 2002
Location: Philly/So. Jersey
Distribution: ESXi CentOS Red-Hat Ubuntuu Solaris Debian
Posts: 80

Rep: Reputation: 15
Testing parameter input to perl script

Hi All,

I'm working on trying to get a redirector script to add to a squid install and I am trying to debug the sample script but I am having a perl brain deficiency...

The script is called and is as follows:


while (<>) {
 @X = split;
 $url = $X[0];
 if ($url =~ /^http:\/\/.*/) {
  $url =~ s/^http/https/;
  print "302:$url\n";
 } else {
  print "403:$url\n";
So right off I see that $| is taking stdin and using it as the value to operate on right? So when @X=split; runs it is using whatever came in on stdin...

So to test this supposition (suppository? LOL) in the shell; it would be like:

echo | ./
I try this but I get:

./ line 1: No such file or directory
How should I format the shell command to process properly? I need to maintain the pipe input as this is how squid will pass the data into the script... Also am I correct in assuming that the prints will just go out on stdout?

Your comments appreciated!

: EDIT :

I just added the "-w" to the "#!/usr/bin/perl" line and now I am getting the output to the screen when I run:

echo | ./
I now get:

Now I just have to figure out if that will break the way it works in squid...

Last edited by merana; 03-16-2006 at 06:22 AM.
Old 03-17-2006, 10:54 AM   #2
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
The problem is that $| doesn't change the default filehandle. It's the autoflush option; setting it to non-zero forces a buffer flush after every write operation (see `man perlvar`). It's best to be explicit with the diamond operator:
#!/usr/bin/env perl

use warnings;
use strict;

while (<STDIN>) {
    my @X = split;
    my $url = $X[0];
    if ($url =~ m{^http://.*}) {
        $url =~ s{^http}{https};
        print "302:$url\n";
    } else {
        print "403:$url\n";
This works fine for me.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing hash of hashes as a parameter (Perl) rose_bud4201 Programming 8 04-21-2005 08:18 PM
Converting a Windows Perl script to a Linux Perl script. rubbercash Programming 2 07-19-2004 11:22 AM
how to add -h parameter in script yulitao Programming 4 03-23-2004 08:30 PM
Perl parameter dvong3 Programming 3 02-21-2004 11:03 AM
Including methods from a perl script into another perl script gene_gEnie Programming 3 01-31-2002 06:03 AM

All times are GMT -5. The time now is 04:29 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration