Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re^3: read an integer from a file

by Boldra (Deacon)
on Jun 16, 2010 at 08:00 UTC ( #844982=note: print w/replies, xml ) Need Help??

in reply to Re^2: read an integer from a file
in thread read an integer from a file

Well I'm not sure about squid, but you should break this into two parts:
  1. check you are getting the behaviour you expect WITHOUT squid,
  2. integrate with squid.
You might not get as much help with part 2 from Perlmonks as you would like, but you will get more help with part 1 if you're clear about what's going wrong.

Since you asked again in the chatterbox about "problem reading a file", I advise you again to look at IO::All. If you're lucky, you can install it just by typing "cpan IO::All". If it turns out to be a bit more complicated, it's definitely worth at least one whole week of effort to get cpan working properly. If you can't install modules from cpan, you are missing out on most of the power of Perl, and you may even find people here getting frustrated with you. The particulars of installing cpan modules vary from site to site, so if you have problems, it's a good idea to talk to other people using Perl at your location.

- Boldra

Replies are listed 'Best First'.
Re^4: read an integer from a file
by long (Initiate) on Jun 16, 2010 at 08:16 UTC
    Hi Bodra, i have split my task into 2 situation as you suggest. for case 1: without squid: i have test the script and it works. i make it print the result to the terminal after reading process. case 2: i integrate it with squid, it works when i disable the code for reading the file. but when i enable the code to read the file, it doesn't work. this script almost hit the target to do the URL redirection but there is something wrong at reading the file process. i'm new to perl. Hope u can help me in this. thanks
      "it doesn't work" is a singularly useless phrase in IT.

      Nevertheless, I googled "squid perl redirect" and found the script I think you are using as a pattern and adapted it for what I think you are trying to do.

      #!/usr/bin/perl use strict; use warnings; use IO::All; use 5.010; $| = 1; while (<>) { my $status = io('status.txt')->all; my $url = ( split )[0]; if( not $status # almost same as if( $status == 0 ) and $url =~ /\Q123.1.34.107:8080\E/ ) { say "301:" } else { say $url } }
      Try this outside of squid first. If it works on the command line, but with squid, it's probably permissions or the file path. Check the squid logs for more information.

      - Boldra
        #!/usr/bin/perl -- use strict; use warnings; use autodie; use 5.010; $| = 1; while (<>) { open my $fh, "<", "status.txt"; my $status = join "",<$fh>; close $fh; my $url = ( split )[0]; if( not $status # almost same as if( $status == 0 ) and $url =~ /\Q123.1.34.107:8080\E/ ) { say "301:" } else { say $url } }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://844982]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2018-01-19 10:13 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (217 votes). Check out past polls.