[29761] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1004 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 5 16:09:41 2007

Date: Mon, 5 Nov 2007 13:09:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 5 Nov 2007     Volume: 11 Number: 1004

Today's topics:
    Re: error running a perl TK programme <ben@morrow.me.uk>
        File handling and regex <lucavilla@cashette.com>
    Re: File handling and regex <krahnj@telus.net>
    Re: Getting MySQL table info in perl script <tlviewer@VISTAyahoo.com>
        Least Squares <alexxx.magni@gmail.com>
        Math Functions in Perl <naureen.nizam@gmail.com>
    Re: Math Functions in Perl <jurgenex@hotmail.com>
    Re: Math Functions in Perl <glennj@ncf.ca>
    Re: Math Functions in Perl <smallpond@juno.com>
    Re: Math Functions in Perl <naureen.nizam@gmail.com>
    Re: Math Functions in Perl <jimsgibson@gmail.com>
    Re: Math Functions in Perl <naureen.nizam@gmail.com>
    Re: Math Functions in Perl <glex_no-spam@qwest-spam-no.invalid>
    Re: Math Functions in Perl <bik.mido@tiscalinet.it>
    Re: Math Functions in Perl <bik.mido@tiscalinet.it>
    Re: Math Functions in Perl <jimsgibson@gmail.com>
        nat traverse <dontmewithme@got.it>
    Re: PID of exec  hendedav@gmail.com
    Re: Problems with Arithmetic Operators in a Perl hash <zen13097@zen.co.uk>
    Re: Problems with Arithmetic Operators in a Perl hash <naureen.nizam@gmail.com>
        Simple question to experts <lucavilla@cashette.com>
    Re: Simple question to experts <mritty@gmail.com>
    Re: Simple question to experts <krahnj@telus.net>
    Re: Simple question to experts <elvis-85473@notatla.org.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 5 Nov 2007 11:14:53 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: error running a perl TK programme
Message-Id: <dia305-i31.ln1@osiris.mauzo.dyndns.org>


Quoth king <hara.acharya@gmail.com>:
> I have a script as below to be ran in windows.
> 
> But whenever I am running this i am getting an error #No -label at C:/
> Perl/lib/Tk/Widget.pm line 256#.

Something that often helps when you get a message of this sort is to run
your program with
    
    perl -MCarp=verbose

 . This gives you a full stacktrace on (some) errors, so you can see
where in your script the problem is.

> Sometimes I am not getting this error also but I am not getting the
> output window also. Even if its not showing any error but it also is
> not showing the output window.
> What can be the problem?
> ##########################################
> #!\c\perl\bin

I'm not sure what you think this line is doing for you, but a #! line
that doesn't end in 'perl' is a bad idea. perl tries to do clever things
with it for you.

> use strict;
> use warnings;
> use tk;

Perl modules are case-sensitive. While this may work on a
case-insensitive filesystem in some cases, in many (such as use Strict)
it will not.

    use Tk;

> my $main=MainWindow->new();

I would strongly recommend using

    my $main = Tk::MainWindow->new();

instead. Tk really didn't ought to be messing about in other toplevel
namespaces.

<snip>
> my $file_mb=$menu_bar->Menubutton(-text=>'File', -
> background=>'purple', -activebackground=>'cyan', -
> foreground=>'white',)->pack(-side=>'left');
> $file_mb->command(label=>'Exit', -activebackground =>'magenta',-
                   ^^^
Here is your problem. You want -label.

<snip>
> $help_mb->command(-Label=>'About', -activebackground=>'magenta',-
                    ^^^
Here, again, you want -label. Hash keys (and thus Tk configuration
options) are case-sensitive as well.

Ben



------------------------------

Date: Mon, 05 Nov 2007 08:15:40 -0800
From:  Luca Villa <lucavilla@cashette.com>
Subject: File handling and regex
Message-Id: <1194279340.228083.276990@50g2000hsm.googlegroups.com>

Hi all!

I need help with Perl under Windows command-line to solve the
following task:

I have many disordered txt files and subdirectories under the root
directory "c:\dir", like this:
c:\dir\foobar.txt
c:\dir\popo.txt
c:\dir\sub1\agsds.txt
c:\dir\sub1\popo.txt
c:\dir\sub2\hghghg.txt
c:\dir\sub2\subbb\abc.txt

These txt files are of three types:
type1: those that contain a string definable by the regular expression
"abc[0-9]+def"
type2: those that contain a string definable by the regular expression
"lmn[0-9]+opq"
type3: those that contain a string definable by the regular expression
"rst[0-9]+uvw"

I would to copy with a Perl Windows command-line script all these txt
files into a single directory "c:\output" with the filename composed
by the number found in the regex match (the "[0-9]+" part of the
regex) and a "-type1.txt" or "-type2.txt" or "-type3.txt" suffix
depending of what of the three above regexes are found in the file,
obtaining a result looking like this:
c:\output\15-type2.txt
c:\output\102-type1.txt
c:\output\33-type1.txt
c:\output\49-type3.txt
c:\output\4-type1.txt
c:\output\335-type2.txt
c:\output\32-type3.txt

How can I do it?



------------------------------

Date: Mon, 05 Nov 2007 17:52:28 GMT
From: "John W. Krahn" <krahnj@telus.net>
Subject: Re: File handling and regex
Message-Id: <472F5829.C1AEDEC5@telus.net>

Luca Villa wrote:
> 
> I need help with Perl under Windows command-line to solve the
> following task:
> 
> I have many disordered txt files and subdirectories under the root
> directory "c:\dir", like this:
> c:\dir\foobar.txt
> c:\dir\popo.txt
> c:\dir\sub1\agsds.txt
> c:\dir\sub1\popo.txt
> c:\dir\sub2\hghghg.txt
> c:\dir\sub2\subbb\abc.txt
> 
> These txt files are of three types:
> type1: those that contain a string definable by the regular expression
> "abc[0-9]+def"
> type2: those that contain a string definable by the regular expression
> "lmn[0-9]+opq"
> type3: those that contain a string definable by the regular expression
> "rst[0-9]+uvw"
> 
> I would to copy with a Perl Windows command-line script all these txt
> files into a single directory "c:\output" with the filename composed
> by the number found in the regex match (the "[0-9]+" part of the
> regex) and a "-type1.txt" or "-type2.txt" or "-type3.txt" suffix
> depending of what of the three above regexes are found in the file,
> obtaining a result looking like this:
> c:\output\15-type2.txt
> c:\output\102-type1.txt
> c:\output\33-type1.txt
> c:\output\49-type3.txt
> c:\output\4-type1.txt
> c:\output\335-type2.txt
> c:\output\32-type3.txt
> 
> How can I do it?

*UNTESTED*  YMMV   :-)

#!/usr/bin/perl
use warnings;
use strict;
use File::Find;
use File::Copy;

my $from = 'c:/dir';
my $to   = 'c:/output';

my %trans = qw(
    abc(\d+)def  type1
    lmn(\d+)opq  type2
    rst(\d+)uvw  type3
    );

find sub {
    return unless open my $fh, '<', $_;
    return unless -f $fh;
    read $fh, my $data, -s _;
    close $fh;
    for my $pat ( keys %trans ) {
        next unless $data =~ $pat;
        copy $File::Find::name, "$to/$1-$trans{$pat}.txt";
        last;
        }
    }, $from;

__END__



John
-- 
use Perl;
program
fulfillment


------------------------------

Date: 05 Nov 2007 20:16:42 GMT
From: Mark Pryor <tlviewer@VISTAyahoo.com>
Subject: Re: Getting MySQL table info in perl script
Message-Id: <472f7a2a$0$20566$4c368faf@roadrunner.com>

On Sat, 03 Nov 2007 09:26:17 -0700, Occidental wrote:

> ..ie the column name,  definitions (varchar(100) etc). The most obvious
> way is to parse the output from describe table_name. Is there an easier
> way? My goal is to create a generic INSERT sub, which takes as args
> table_name and a hash reference, eg:
> 
> $table_name = "TheTable";
> $hash(Int1) = 99;
> $hash(Float2) = 1.54;
> $hash(String7) = "Goodbye cruel world";
> 
> ..where Float2, Int1, String7 are some but not all cols in mysql table
> TheTable. The sub is invoked as follows:
> 
> DoInsert($table_name, \%hash);
> 
> DoInsert will generate and execute the INSERT statement, NULLing out
> fields not in %hash, single quoting string fields, etc., maybe even
> doing data tyep compatibility tests. I would be happy to learn that some
> one has beaten me to it, and a procedure like DoInsert already exists.

A module like that should already be available.

Checkout these namespaces at CPAN:
	MySQL::
	DBIx::
	DBD::
http://search.cpan.org/search?query=MySQL%3A%3A&mode=module

Rather than use DESCRIBE, you might want
Show columns from TableName;

----------------- example -------------
mysql> use rt3
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+-------------------------+
| Tables_in_rt3           |
+-------------------------+
| ACL                     |
| Attachments             |
| Attributes              |
| CachedGroupMembers      |
| CustomFieldValues       |
| CustomFields            |
| GroupMembers            |
| Groups                  |
| Links                   |
| ObjectCustomFieldValues |
| ObjectCustomFields      |
| Principals              |
| Queues                  |
| ScripActions            |
| ScripConditions         |
| Scrips                  |
| Templates               |
| Tickets                 |
| Transactions            |
| Users                   |
| sessions                |
+-------------------------+
21 rows in set (0.00 sec)

mysql> show columns from Queues;
+-------------------+--------------+------+-----+---------
| Field          | Type         | Null | Key | Default | Extra 
|-------------------+--------------+------+-----+---------
| id                | int(11)      | NO   | PRI | NULL | auto_increment |
| Name              | varchar(200) | NO   | UNI | NULL    
|                |
| Description       | varchar(255) | YES  |     | NULL    
|                |
| CorrespondAddress | varchar(120) | YES  |     | NULL    
|                |
| CommentAddress    | varchar(120) | YES  |     | NULL    
|                |
| InitialPriority   | int(11)      | NO   |     | 0       
|                |
| FinalPriority     | int(11)      | NO   |     | 0       
|                |
| DefaultDueIn      | int(11)      | NO   |     | 0       
|                |
| Creator           | int(11)      | NO   |     | 0       
|                |
| Created           | datetime     | YES  |     | NULL    
|                |
| LastUpdatedBy     | int(11)      | NO   |     | 0       
|                |
| LastUpdated       | datetime     | YES  |     | NULL    
|                |
| Disabled          | smallint(6)  | NO   | MUL | 0       
|                |
+-------------------+--------------+------+-----+---------
13 rows in set (0.00 sec)

-- 
Mark


------------------------------

Date: Mon, 05 Nov 2007 19:26:33 -0000
From:  "alexxx.magni@gmail.com" <alexxx.magni@gmail.com>
Subject: Least Squares
Message-Id: <1194290793.569055.310260@o38g2000hse.googlegroups.com>

Hi everybody,
I need to perform a huge number of Least Squares Fits to my data,
using probably something like a+b*Atan(c-d*x) as the fitting function.
Can you suggest me the fastest package on CPAN, according to you?

Thanks for any help!


Alessandro Magni



------------------------------

Date: Mon, 05 Nov 2007 05:00:35 -0800
From:  coolchick <naureen.nizam@gmail.com>
Subject: Math Functions in Perl
Message-Id: <1194267635.362329.149650@19g2000hsx.googlegroups.com>

Hi All,

I am trying to compute few equations using perl.

This is the equation that I am trying to solve:

MI=171-5.2*ln(aveV)-0.23*aveV(g)-16.2*ln(aveLOC)
+50sin(sqrt(2.46*perCM))

I have all the variables: aveV, aveV(g), aveLOC and perCM.
So the equation is:

$MI=171 - (5.2*(2.303*log($aveV)))-(0.23*$ecc)-
(16.2*(2.303*log($aveLOC)))+(50*(sin(sqrt(2.46*$perCM))));

where:
$aveV= 239.530014548124
$ecc=9
$aveLOC=47
$perCM=0.297872340425532

I am not getting the correct answer. I get MI=-2.56217048794884, which
is not correct.
I tried to break it down and the problem is that I don't think I have
the right libraries for math.
It is not computing sqrt, log, and sin correctly.

I am using:
use Math::Complex;
use Math::Trig;

Any help would be great!
Thanks,
naureen



------------------------------

Date: Mon, 05 Nov 2007 13:33:38 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Math Functions in Perl
Message-Id: <SYEXi.2446$bm.2176@trndny08>

coolchick wrote:
> MI=171-5.2*ln(aveV)-0.23*aveV(g)-16.2*ln(aveLOC)
> +50sin(sqrt(2.46*perCM))
>
> I have all the variables: aveV, aveV(g), aveLOC and perCM.
> So the equation is:
>
> $MI=171 - (5.2*(2.303*log($aveV)))-(0.23*$ecc)-
> (16.2*(2.303*log($aveLOC)))+(50*(sin(sqrt(2.46*$perCM))));
>
> where:
> $aveV= 239.530014548124
> $ecc=9
> $aveLOC=47
> $perCM=0.297872340425532
>
> I am not getting the correct answer. I get MI=-2.56217048794884, which
> is not correct.

This is a long shot, but is any of the iterim values exceedingly large or 
small? If so then you fell victim to a variation of 'perldoc -q 999'.
The easiest remedy would be to rewrite the equation to avoid very 
large/small iterim values. This is not trivial, but there is a reason why 
Computer Numerics is a class of its own at university.

jue 




------------------------------

Date: 5 Nov 2007 14:54:13 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: Math Functions in Perl
Message-Id: <slrnfiubkl.qkn.glennj@smeagol.ncf.ca>

At 2007-11-05 08:00AM, "coolchick" wrote:
>  Hi All,
>  
>  I am trying to compute few equations using perl.
>  
>  This is the equation that I am trying to solve:
>  
>  MI=171-5.2*ln(aveV)-0.23*aveV(g)-16.2*ln(aveLOC)
>  +50sin(sqrt(2.46*perCM))
>  
>  I have all the variables: aveV, aveV(g), aveLOC and perCM.
>  So the equation is:
>  
>  $MI=171 - (5.2*(2.303*log($aveV)))-(0.23*$ecc)-
>  (16.2*(2.303*log($aveLOC)))+(50*(sin(sqrt(2.46*$perCM))));

Is that log() function base e or base 2 or ...?

-- 
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry


------------------------------

Date: Mon, 05 Nov 2007 07:07:53 -0800
From:  smallpond <smallpond@juno.com>
Subject: Re: Math Functions in Perl
Message-Id: <1194275273.441794.211400@k79g2000hse.googlegroups.com>

On Nov 5, 8:00 am, coolchick <naureen.ni...@gmail.com> wrote:
> Hi All,
>
> I am trying to compute few equations using perl.
>
> This is the equation that I am trying to solve:
>
> MI=171-5.2*ln(aveV)-0.23*aveV(g)-16.2*ln(aveLOC)
> +50sin(sqrt(2.46*perCM))
>
> I have all the variables: aveV, aveV(g), aveLOC and perCM.
> So the equation is:
>
> $MI=171 - (5.2*(2.303*log($aveV)))-(0.23*$ecc)-
> (16.2*(2.303*log($aveLOC)))+(50*(sin(sqrt(2.46*$perCM))));
>
> where:
> $aveV= 239.530014548124
> $ecc=9
> $aveLOC=47
> $perCM=0.297872340425532
>
> I am not getting the correct answer. I get MI=-2.56217048794884, which
> is not correct.
> I tried to break it down and the problem is that I don't think I have
> the right libraries for math.
> It is not computing sqrt, log, and sin correctly.
>
> I am using:
> use Math::Complex;
> use Math::Trig;
>
> Any help would be great!
> Thanks,
> naureen

Rearranging your equation to show intermediate terms:

$aveV = 239.530014548124;
$ecc = 9.0;
$aveLOC = 47.0;
$perCM = 0.297872340425532;

$i1=    (5.2 * (2.303*log($aveV)));
$i2=    (0.23 * $ecc);
$i3=    (16.2 * (2.303*log($aveLOC)));
$i4=    (50 * (sin(sqrt(2.46*$perCM))));

$MI = 171.0 - $i1 - $i2 - $i3 + $i4;

print "171.0 - ",$i1," - ",$i2," - ",$i3," + ",$i4," = ",$MI,"\n";

171.0 - 65.610465007406 - 2.07 - 143.64361681316 + 37.761911332617 =
-2.56217048794883

I don't think you have math errors.  All of the terms are the
same order of magnitude.  If the result is wrong, then it is
something in your formula.  You do want log base e and angle
in radians, right?
--S



------------------------------

Date: Mon, 05 Nov 2007 08:49:56 -0800
From:  coolchick <naureen.nizam@gmail.com>
Subject: Re: Math Functions in Perl
Message-Id: <1194281396.204469.234530@t8g2000prg.googlegroups.com>

Hi, thanks for the help but the problem is that I am trying to solve
the Coleman-Oman's model for computing a code Maintainability Index.
The equation has 'ln' which I equated to 2.303*log(). So how do I
compute that? If I do the same thing using a scientific calculator, I
get a different answer.
For the angle, shouldn't that be in degrees.

Here is the equation:
http://www.stsc.hill.af.mil/consulting/show_ct_article.asp?uri=2001/08/liso.html&uri2=sw_measurement



------------------------------

Date: Mon, 05 Nov 2007 10:03:18 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Math Functions in Perl
Message-Id: <051120071003189705%jimsgibson@gmail.com>

In article <1194281396.204469.234530@t8g2000prg.googlegroups.com>,
coolchick <naureen.nizam@gmail.com> wrote:

> Hi, thanks for the help but the problem is that I am trying to solve
> the Coleman-Oman's model for computing a code Maintainability Index.
> The equation has 'ln' which I equated to 2.303*log(). So how do I
> compute that? If I do the same thing using a scientific calculator, I
> get a different answer.
> For the angle, shouldn't that be in degrees.

perldoc -f log:

       log EXPR
       log     Returns the natural logarithm (base e) of EXPR.

perldoc -f sin:

       sin EXPR
       sin     Returns the sine of EXPR (expressed in radians).

> 
> Here is the equation:
>
> http://www.stsc.hill.af.mil/consulting/show_ct_article.asp?uri=2001/08/liso.ht
> ml&uri2=sw_measurement
> 


% perl -e '
$aveV=239.53001;$ecc=9;$aveLOC=47;$perCM=0.297872;$mi=
171-(5.2*(log($aveV)))-(0.23*$ecc)-(16.2*log($aveLOC))+(50*(sin(sqrt(2.4
6*$perCM))));print "mi=$mi\n";'

mi=115.830374853214

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


------------------------------

Date: Mon, 05 Nov 2007 10:48:58 -0800
From:  coolchick <naureen.nizam@gmail.com>
Subject: Re: Math Functions in Perl
Message-Id: <1194288538.022091.25250@z24g2000prh.googlegroups.com>

How did you get 'mi=115.830374853214 ' as your your answer?

How can I do this inside my perl code ?



------------------------------

Date: Mon, 05 Nov 2007 14:09:45 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Math Functions in Perl
Message-Id: <472f7889$0$3578$815e3792@news.qwest.net>

coolchick wrote:
> How did you get 'mi=115.830374853214 ' as your your answer?
> 
> How can I do this inside my perl code ?

At this point, most people would simply copy and paste the
relevant parts of the code into a file and experiment with
it on their own.


------------------------------

Date: Mon, 05 Nov 2007 21:25:05 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Math Functions in Perl
Message-Id: <gfjui3h92o4qb015g11p29abtt5fh2am8f@4ax.com>

On Mon, 05 Nov 2007 05:00:35 -0800, coolchick
<naureen.nizam@gmail.com> wrote:

>Hi All,
>
>I am trying to compute few equations using perl.

Perl is not oriented at solving equations. You can solve them
symbolically and throw in values to compute the value of some function
given the arguments to it.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


------------------------------

Date: Mon, 05 Nov 2007 21:49:38 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Math Functions in Perl
Message-Id: <kb0vi39glak0m9km4ja8vn15hjd2oo0m07@4ax.com>

On Mon, 05 Nov 2007 10:03:18 -0800, Jim Gibson <jimsgibson@gmail.com>
wrote:

>> For the angle, shouldn't that be in degrees.
>
>perldoc -f log:
>
>       log EXPR
>       log     Returns the natural logarithm (base e) of EXPR.

For some reason, pocket calcultators have this habit of calling log_10
log and log_e ln. In my mathematical writings I just stick with log to
mean "their" ln. logarithms in any other base (unless explicitly
shown) are of little mathematical relevance, IMHO.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


------------------------------

Date: Mon, 05 Nov 2007 12:51:07 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Math Functions in Perl
Message-Id: <051120071251079432%jimsgibson@gmail.com>

In article <1194288538.022091.25250@z24g2000prh.googlegroups.com>,
coolchick <naureen.nizam@gmail.com> wrote:

> How did you get 'mi=115.830374853214 ' as your your answer?

By executing the code shown, which was cut-and-pasted from a shell
session on my computer.

> 
> How can I do this inside my perl code ?

By copying the code shown into a file and turning it into a complete
Perl script (I left out 'use strict;', for example, which you should
add).

-- 
Jim Gibson

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


------------------------------

Date: Mon, 05 Nov 2007 15:49:12 +0100
From: Larry <dontmewithme@got.it>
Subject: nat traverse
Message-Id: <dontmewithme-CB4316.15491205112007@news.tin.it>

Hi,

   I've found this script script that I've found very usefull 
(http://linide.sourceforge.net/nat-traverse/), yet I'd love to use nat 
traverse to set up a udp tunnel to make a browser on host A to connect 
to apache listening on HOST B. Both HOST A and HOST B are behind NAT.

** on host A I have this:

perl nat-traverse --cmd="nc -vlp 65000" 40000:host B:40001

Now, "nc" is bound to nat-traverse...

I use my browser to connect to 127.0.0.1:65000 ("nc" gets tha request 
and sends it to the UDP tunnel...than waits for the response from he 
tunnel)

** on HOST B I have the following:

perl nat-traverse --cmd="perl mediator.pl" 40001:host A:40000

mediator gets data from the UDP tunnel and make a req to apache 
(listening locally on port 80) than sends the apache response back to 
the tunnel...(whereas NC gets the response and send it to the browser)

here's mediator.pl code:

#!/usr/bin/perl

use strict;
use warnings;
use IO::Socket::INET;
use IO::Handle;
STDOUT->autoflush();

my $key;
my %header;
my $req;
my $line;

while(1)
{
   chomp($line = <STDIN>);

   while( defined($_ = <STDIN>) )
   {  
      s/[\r\n]+$//;
      last unless length $_;
      /^ ([\w\-]+) :[\ \t]+ (.+) $/x;
      $key = uc($1);
      $key =~ tr/-/_/;
      $header{$key} = $2
   }
   
   $req = "$line\n";
   
   foreach (sort keys %header)
   {
      $req .= $_ . ':' . " $header{$_}\n";
   }
   
   $req .= "\n";
   
   {
   my ($buff, $sock);
   $sock = IO::Socket::INET->new(PeerAddr => '127.0.0.1', PeerPort => 
'80', Proto => 'tcp') || die "$!";
   $sock->autoflush(1);
   
   syswrite $sock, $req;
   
   while ( sysread($sock, $buff, 1024) )
   {
      print STDOUT $buff;
   }
         
   close($sock);
   }

}

__END__;

tha thing with the whole above scenario is that "nc" exits when the 
browser closes the connection...

Does anyone how to sort this out??

How can I bound STDIN e STDOUT to fifo files??

thanks ever so much


------------------------------

Date: Mon, 05 Nov 2007 09:43:44 -0800
From:  hendedav@gmail.com
Subject: Re: PID of exec
Message-Id: <1194284624.959949.255970@z9g2000hsf.googlegroups.com>

On Oct 26, 3:26 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth hende...@gmail.com:
>
> > [snip] Also, this
> > script seems to be generating zombies.  Anyone have ideas on how to
> > clear that up?  I was hoping that the "local $SIG{CHLD} = "IGNORE";"
> > line would do the trick (as it stated in the perldoc's), but I guess
> > not.
>
> Setting SIGCHLD to IGNORE to clean up zombies is non-portable. Possibly
> your system doesn't have this behaviour: you will need to wait for your
> children yourself.
>
> Ben

Thanks for the reply Ben.  How will I get around the client timing out
if I have to wait for the children to complete.  Also, doesn't Linux
provide for the SIGCHLD to be set to ignore?

Dave



------------------------------

Date: 05 Nov 2007 12:14:18 GMT
From: Dave Weaver <zen13097@zen.co.uk>
Subject: Re: Problems with Arithmetic Operators in a Perl hash
Message-Id: <472f091a$0$13939$fa0fcedb@news.zen.co.uk>

On Thu, 01 Nov 2007 08:40:32 -0700, coolchick <naureen.nizam@gmail.com> wrote:
>  Hi All,
> 
>  I am trying to go through a file and grab all the arithmetic operators
>  using a perl hash.
>  It is not working for me. What am I doing wrong? I think my issue is
>  with the key value that I can't escape. HELP!
> 
>  #!/usr/bin/perl

You should use the warnings & strict pragmas to allow perl to help you out.

   use warnings;
   use strict;

>  %operators = ('+',0,'-',0,'=',0,'*',0,'/',0);

Now you have enabled strictures, you need to declare your variables using 'my'.

   my %operators;

> 
>  $FILE="operator.txt";
>  open(FILE) or die("Could not open $FILE.");

Use the 3-argument form of open, and include "$!" in the error message so
you know *why* the open failed.
   
    open my $f, '<', $FILE or die "Couldn't open '$FILE' : $!";

>  foreach $line (<FILE>) {

When iterating over the lines of a file, use "while" instead of "for" - "for"
will read all lines into memory at once; "while" will read them in one at a
time.

    while ( my $line = <$f> )

>          while (($key,$value) = each(%operators)){
>                     if ($line =~ /\$key/) {
>                        $operators{$key}=$value+1;
>                 }

Looping over the keys of %operators for each line of the file isn't 
terribly efficient. It might be better to construct a pattern that
matches any of the operators you're looking for:

	if ( $line =~ m{([-+=*/])} ) {
	    ++ $operators{ $1 };
	}

Note that this will only find the first operator on the line.
To find all operators:

	while ( $line =~ m{([-+=*/])}g ) {
	    ++ $operators{ $1 };
	}

So, putting it all together:

    #!/usr/bin/perl
    use strict;
    use warnings;

    my %operators;

    my $FILE = 'operator.txt';

    open my $f, '<', $FILE or die "Can't open '$FILE' : $!";

    while ( my $line = <$f> ) {

	while ( $line =~ m{([-+=*/])}g ) {
	    ++ $operators{ $1 };
	}
    }
    close $f;

    use Data::Dumper;
    print Dumper \%operators;



------------------------------

Date: Mon, 05 Nov 2007 05:01:09 -0800
From:  coolchick <naureen.nizam@gmail.com>
Subject: Re: Problems with Arithmetic Operators in a Perl hash
Message-Id: <1194267669.786976.214200@z9g2000hsf.googlegroups.com>


Thanks a bunch for all your help.



------------------------------

Date: Mon, 05 Nov 2007 04:51:17 -0800
From:  Luca Villa <lucavilla@cashette.com>
Subject: Simple question to experts
Message-Id: <1194267077.106483.70030@y42g2000hsy.googlegroups.com>

Hi all!

The simple problem is this: I have a file named example.html on my
harddisk and I want to extract from that file a block of text that
goes from the regex "foobar[0-9]" to the first occurrence of the regex
"abcdef[0-9]".
What's the Perl/command-line/single-line solution for this?

Thanks in advance for any help



------------------------------

Date: Mon, 05 Nov 2007 08:03:07 -0800
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: Simple question to experts
Message-Id: <1194278587.083687.281340@22g2000hsm.googlegroups.com>

On Nov 5, 7:51 am, Luca Villa <lucavi...@cashette.com> wrote:
> Subject: Simple question to experts Options

Please put the subject of your post in the Subject of your post.

> The simple problem is this: I have a file named example.html on my
> harddisk and I want to extract from that file a block of text that
> goes from the regex "foobar[0-9]" to the first occurrence of the
> regex "abcdef[0-9]".
> What's the Perl/command-line/single-line solution for this?

It's my birthday, and I'm feeling generous.  Here, have a fish:

perl -ln0777 -e'print $1 if /foobar[0-9](.*?)abcdef[0-9]/'
example.html

Then read:
perldoc perlrun
perldoc perlre
to understand what's happening.

Paul Lalli



------------------------------

Date: Mon, 05 Nov 2007 16:30:33 GMT
From: "John W. Krahn" <krahnj@telus.net>
Subject: Re: Simple question to experts
Message-Id: <472F44F6.84B92F4A@telus.net>

Paul Lalli wrote:
> 
> It's my birthday,

Ooh, a Scorpio!  Happy birthday Paul.  Many happy returns.


John
-- 
use Perl;
program
fulfillment


------------------------------

Date: 05 Nov 2007 20:02:16 GMT
From: all mail refused <elvis-85473@notatla.org.uk>
Subject: Re: Simple question to experts
Message-Id: <slrnfiutj8.75c.elvis-85473@notatla.org.uk>

On 2007-11-05, John W. Krahn <krahnj@telus.net> wrote:

>> It's my birthday,
>
> Ooh, a Scorpio!  Happy birthday Paul.  Many happy returns.

But not too many - leave something on his stack.

-- 
Elvis Notargiacomo  master AT barefaced DOT cheek
http://www.notatla.org.uk/goen/


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 1004
***************************************


home help back first fref pref prev next nref lref last post