[22151] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4372 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 9 11:10:46 2003

Date: Thu, 9 Jan 2003 08:10:10 -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           Thu, 9 Jan 2003     Volume: 10 Number: 4372

Today's topics:
        pack( "N", inet_aton("client.example.net")) (M. S. Bob)
        silly question -- please help! (tom)
    Re: silly question -- please help! <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
    Re: silly question -- please help! (Anno Siegel)
    Re: Taint check question (Tad McClellan)
    Re: Taint check question <simon.andrews@bbsrc.ac.uk>
    Re: Taint check question <md0nilhe@mdstud.DIESPAMchalmers.se>
    Re: The Best and The Easiest Perl Module to Draw 2-D Li (Jay Chan)
    Re: tracing the HTTP <skerschhofer@yahoo.de>
        Unix Vars declared in system() call -> %ENV (Christopher Hamel)
    Re: Unix Vars declared in system() call -> %ENV <jurgenex@hotmail.com>
    Re: Unix Vars declared in system() call -> %ENV (Tad McClellan)
    Re: using subroutines defined in other scripts (Tad McClellan)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 9 Jan 2003 07:41:29 -0800
From: msbob@hotmail.com (M. S. Bob)
Subject: pack( "N", inet_aton("client.example.net"))
Message-Id: <d3a9d3a6.0301090741.43c2bb45@posting.google.com>

I am have problems writing a pack statement that uses the output of
inet_aton(). I want to write a module that supports a legacy network
protocol that we use for existing C client/server software.

Below is a simplified example, of what I've tried so far. It generates
an couple of errors:

msbob@nix$ ./sample.pl 

Argument "Àš^D^E" isn't numeric in pack at ./sample.pl line 17.
Argument "\n@^C^D" isn't numeric in pack at ./sample.pl line 17.
54 68 69 73 20 69 73 20 61 20 68 65 61 64 65 72
20 75 73 65 64 20 74 6f 20 69 64 65 6e 74 69 66
79 20 6d 65 73 73 61 67 65 73 2e 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 77 00 00 00 00 00 00 00 00 00 00 00 00

Thanks for any help.



#!/usr/bin/perl -w -T

use strict;
use warnings;
use Socket;
use Sys::Hostname;

my %record;
my $buffer;

$record{'header'} = "This is a header used to identify messages.";
$record{'src_inet'} = "192.168.4.5";
$record{'dst_inet'} = "10.64.3.4";
$record{'length'} = 1024;
$record{'timestamp'} = time();

# Pack entire protocol header into buffer, which will be sent via
# IO::Socket for support for an existing legacy network protocol.

$buffer = pack( 'a64'. ('C'x8) .'NN', 
				$record{'header'},
				inet_aton($record{'src_inet'}),
				inet_aton($record{'dst_inet'}),
				$record{'length'},
				$record{'timestamp'}
				);

# Print hex dump of $buffer, so I can check if correct.

my $i;
print map { ++$i % 16 ? "$_ " : "$_\n" }
unpack( 'H2' x length( $buffer ), $buffer ),
	length( $buffer ) % 16 ? "\n" : '';
print "\n";


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

Date: 9 Jan 2003 03:21:37 -0800
From: theiman@comcast.net (tom)
Subject: silly question -- please help!
Message-Id: <47f04bf1.0301090321.38f31f47@posting.google.com>

Hi,

I have lots of files with the following structure:

Wnt8	Krl	SoxB1	Krox	Otx	Eve
-0.069	0.028	-0.025	-0.011	0.0171	-0.022
-0.066	-0.011	-0.035	0.002	-0.001	0.007
-0.064	0.0171	-0.040	0.030	0.025	0.009
etc...

and I need to convert each one to the following format for use with
somebody else's program:

Wnt8 -0.069
Krl 0.028
SoxB1 -0.025
Krox -0.011
Otx 0.017
Eve -0.022
Wnt8 -0.066
Krl -0.011
SoxB1 -0.035
Krox 0.002
Otx -0.001
Eve 0.007
etc...

Any ideas on how to do this in Perl? I'm drawing a big blank.. I'd
really appreciate it!!! Thank you!!

Sincerely,

Tom


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

Date: Thu, 09 Jan 2003 12:35:29 +0100
From: Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Subject: Re: silly question -- please help!
Message-Id: <newscache$5v2g8h$4t6$1@news.emea.compuware.com>

tom wrote (Thursday 09 January 2003 12:21):

> Hi,
> 
> I have lots of files with the following structure:
> 
> Wnt8  Krl     SoxB1   Krox    Otx     Eve
> -0.069        0.028   -0.025  -0.011  0.0171  -0.022
> -0.066        -0.011  -0.035  0.002   -0.001  0.007
> -0.064        0.0171  -0.040  0.030   0.025   0.009
> etc...
> 
> and I need to convert each one to the following format for use with
> somebody else's program:
> 
> Wnt8 -0.069
> Krl 0.028
> SoxB1 -0.025
> Krox -0.011
> Otx 0.017
> Eve -0.022
> Wnt8 -0.066
> Krl -0.011
> SoxB1 -0.035
> Krox 0.002
> Otx -0.001
> Eve 0.007
> etc...
> 
> Any ideas on how to do this in Perl? I'm drawing a big blank.. I'd
> really appreciate it!!! Thank you!!
> 
> Sincerely,
> 
> Tom


You have a bit of a problem here. clpm is a not a helpdesk but a self help 
group. That is, you hand over your failing Perl script and we will take a 
lot at it in order to help. We will not program it for you.

So, run --don't walk-- to your online Perl documentation and type:
perldoc -f open
perldoc -f split
perldoc -f print

Show us anything you could whip up and we'll be glad to help.
Cheers,

-- 
KP



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

Date: 9 Jan 2003 11:35:21 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: silly question -- please help!
Message-Id: <avjmpp$7kc$2@mamenchi.zrz.TU-Berlin.DE>

tom <theiman@comcast.net> wrote in comp.lang.perl.misc:
> Hi,
> 
> I have lots of files with the following structure:
> 
> Wnt8	Krl	SoxB1	Krox	Otx	Eve
> -0.069	0.028	-0.025	-0.011	0.0171	-0.022
> -0.066	-0.011	-0.035	0.002	-0.001	0.007
> -0.064	0.0171	-0.040	0.030	0.025	0.009
> etc...
> 
> and I need to convert each one to the following format for use with
> somebody else's program:
> 
> Wnt8 -0.069
> Krl 0.028
> SoxB1 -0.025
> Krox -0.011
> Otx 0.017
> Eve -0.022
> Wnt8 -0.066
> Krl -0.011
> SoxB1 -0.035
> Krox 0.002
> Otx -0.001
> Eve 0.007
> etc...
> 
> Any ideas on how to do this in Perl? I'm drawing a big blank.. I'd
> really appreciate it!!! Thank you!!

    my @titles = split /\s+/, <DATA>;
    while ( <DATA> ) {
        my @fields = split;
        print "$_ ", shift @fields, "\n" for @titles;
    }

Anno


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

Date: Thu, 9 Jan 2003 08:05:01 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Taint check question
Message-Id: <slrnb1r0cc.o43.tadmc@magna.augustmail.com>

henrik nilsson <md0nilhe@mdstud.DIESPAMchalmers.se> wrote:
> Again a big thanks for your valuable comments. Yes, I use external 
> programs in my script, and yes, I have probably misunderstood how to use 
> PATH. 


I think you still misunderstand.

My other followup already said what to do, either:

   put the external program dirs (not the dir where your Perl
   program file is) in PATH
or
   make PATH empty, and use absolute paths to the external programs

In either case, every copy of your Perl program would be identical,
you would set PATH to the same thing every time.

Did you try that? Did it work when you did?


> When at the top of my script, I do not yet know the complete path 
> leading to the directory where my external programs will be run 


It *does not matter* where your Perl program is located in the filesystem.

I think you have yet another misunderstanding about how programs
are run.

Do you understand the concept of "current working directory" (cwd) ?


> (it is 
> given a random but unique names later on). At the end of the script, I 
> remove the temp directory and obviously all its files.


Can these unique names be determined from within your Perl program?

If so, then you can have one Perl program and chdir() to whereever
you need the cwd to be.


> I was under the imporession that you shouldn't set PATH under these 
> circumstances. 


Why not (again)?


> Should I take it that whatever I set PATH to, it only 
> matters to the very instance of the script, and not to the system in 
> general? 


Of course.

Do you understand the concept of "processes" ?


> (If I run 5 simultaneous instances of the script, they would 
> all have different PATHs due to the name of the temp dir, 


No they wouldn't. They would all have the same PATH.

They might, however, all have different cwd's.


> but this 
> would, then, be OK?)


But if they did need different PATHs (they don't, AFAICT) then,
yes, it would be OK.


> Thanks for your patience,


I am reasonably certain that we are working on an "XY problem" here.[1]

It also seems that your difficulties don't really have to do with
Perl, but rather with how processes are run, and how Unix works.

If we can discover what the "X" is, we can likely suggest a way
to accomplish it without going round-and-round in an attempt to
accomplish "Y" (which we likely do not _need_ to accomplish).

I cannot envision a situation where you need multiple copies of
your Perl program in various places in the file system.

You should be able to have only one physical Perl program file.
You may need to change the cwd (using chdir()) to the "temp dirs"
though.

-----

So, let's "back up" and start over. Maybe we can avoid the
problems with your "Y" altogether. You said earlier:


> 1. My script relies on a couple of old programs which only read infiles 
> in progdir and with a fixed name, INFILE. 


I really really doubt that that is the case.

It *does not matter* where the Perl program file is located. What
matters is the cwd.[2] So:

   ... which only read infiles in the cwd and with a fixed name, INFILE.

That will be no problem, just chdir() to the correct dir that 
contains INFILE.


> Hence, for the script to 
> potentially run in parallell, I have to make a tempdir for every script 
> instance and copy and run the programs there.
           ^^^^^^^^

You do not have to copy the program file, you can have one program
file and chdir() to wherever the appropriate INFILE is.



[1] You have a case of the XY disease.  This is
    when you are trying to accomplish some task X, and you decide that
    doing Y will help you accomplish X, so you come and ask about Y.  But
    actually, Y is totally wrong, and nobody can help you because you
    never mentioned X, which is what yuo really want.
    (quote from Mark-Jason Dominus)

[2] Some web servers are configured to set your cwd to be the same
    as the dir where the CGI program file is, but if you don't like
    that cwd, just change it to the one that you _do_ want.

-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 09 Jan 2003 15:06:52 +0000
From: Simon Andrews <simon.andrews@bbsrc.ac.uk>
Subject: Re: Taint check question
Message-Id: <3E1D900C.54BE44EA@bbsrc.ac.uk>

henrik nilsson wrote:
> 
> Again a big thanks for your valuable comments. Yes, I use external
> programs in my script, and yes, I have probably misunderstood how to use
> PATH. When at the top of my script, I do not yet know the complete path
> leading to the directory where my external programs will be run (it is
> given a random but unique names later on). At the end of the script, I
> remove the temp directory and obviously all its files.

OK, let me see if I've got this straight..

You have an old executable (which you can't change) which you need to
run from within a Perl script.  This old program requires its input to
be in an file called INPUT which is in the same dir as the program
itself.  Yes?

Assuming the above is correct I think that you might as well forget
about the whole PATH issue and do it another way.  Clear $ENV{'PATH'} at
the top of your script, then later on:

Pick a random directory name.

Create that directory under somewhere you can write to
  mkdir ('/data/web_stuff/$random') || die "Can't create $random: $!";

Move into that directory
  chdir ('/data/web_stuff/$random') || die "Can't move to $random: $!";

Copy your executable from wherever your reference copy is to your
current directory
  use File::Copy;
  copy ('/usr/bin/oldprog','./oldprog') || die "Can't copy file $!";

Make your INFILE file
  open (OUT,'>INFILE') || die "Can't write to INFILE";
  print OUT "whatever";
  close (OUT) || die $!;

Finally run your program.
  system('./oldprog') && die "Oldprog exited badly";

In this scenario you're never relying on the path to find your external
program, and you can run as many copies of it as you like without
changing them.  Taint should also be happy as your paths are hard coded,
or generated internally.

Hope this helps

Simon.


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

Date: Thu, 09 Jan 2003 15:52:36 +0100
From: henrik nilsson <md0nilhe@mdstud.DIESPAMchalmers.se>
Subject: Re: Taint check question
Message-Id: <3E1D8CB4.5010403@mdstud.DIESPAMchalmers.se>

Yes, yes, yes!

The way you describe it is *exactly* how I have done it, although it 
appears that I have described it to you in a very unsatisfactory way.

Huh. Leaving out PATH totally - I'll be glad to do that. I have been 
getting these taint check complaints all the time, and after searching 
for info on the web I thought I HAD to do something about PATH, unknown 
what. I've played around with my script to get rid of the taint errors, 
but it appears I only manage to shift the error from one thing to another.

Now I at least know I won't have bother too much about PATH.
My taint check error messages must be related to someting else.

Thanks a lot!

Yours gratefully,

Henrik



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

Date: 9 Jan 2003 07:51:53 -0800
From: jaykchan@hotmail.com (Jay Chan)
Subject: Re: The Best and The Easiest Perl Module to Draw 2-D Line Chart?
Message-Id: <c7e5acb2.0301090751.6789527a@posting.google.com>

> PS: I think this posting would have been better placed to
> comp.perl.lang.modules

Thanks for the suggestion.  I will post my message over there.

Jay Chan


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

Date: Thu, 9 Jan 2003 13:34:57 +0100
From: "Sascha Kerschhofer" <skerschhofer@yahoo.de>
Subject: Re: tracing the HTTP
Message-Id: <avjq9i$mtb$1@news.mch.sbs.de>


"Jay Tilton" <tiltonj@erols.com> wrote in message
news:3e1cab15.281753665@news.erols.com...
> "Sascha Kerschhofer" <skerschhofer@yahoo.de> wrote:
>
> : How can I log the communication between my web-browser and any
webserver?
>
> I reckon you could have a simple proxy sit between the browser and the
> outside world, unobtrusively taking notes.
>
> : Or is there any software that does that for me (Windows Software)?
>
> There probably is.
>
> Did you have a Perl question?

Yes. I thought, Perl could help.

Sascha




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

Date: 9 Jan 2003 06:45:58 -0800
From: hamelcd@hotmail.com (Christopher Hamel)
Subject: Unix Vars declared in system() call -> %ENV
Message-Id: <4f60d5b3.0301090645.628a835a@posting.google.com>

Perhaps this is easy; perhaps it's impossible.

Within a Perl program, I have a desire to launch a Unix Korn shell
script that exports a number of variables.  A snippet of the program
looks as follows:

  if [[ $HOST = "0xae026c0" ]] ; then
    export SERVER=test21
  else [[ $HOST = "0xae02647" ]] ; then
    export SERVER=prod21
  fi

  export FP_DIR=/i2/$ENVIRONMENT/fp

(pretty basic stuff)

Is there any way to launch this program within Perl and have the
variable declarations within the program update %ENV?

  system "my_unix_script";
  print "$ENV{FP_DIR}\n";

Doesn't appear to work, nor does:

  system ". my_unix_script";
  print "$ENV{FP_DIR}\n";

The ksh program in particular is a centralized variable respository,
so altought I could put it into Perl, it's used by a multitude of
other programs (Perl and ksh), and it's best to only have one place to
look.

Right now, I'm doing a crude ksh2Perl parse within each Perl program
(while (<ksh>) { blah blah; eval }), that is neither perfect nor
fool-proof.  It would be nice to have something a little more
scalable.

Thanks in advance for any assistance or direction.
Chris


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

Date: Thu, 09 Jan 2003 15:19:00 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Unix Vars declared in system() call -> %ENV
Message-Id: <EpgT9.33875$xb.28129@nwrddc02.gnilink.net>

Christopher Hamel wrote:
> Within a Perl program, I have a desire to launch a Unix Korn shell
> script that exports a number of variables.  [...]
> Is there any way to launch this program within Perl and have the
> variable declarations within the program update %ENV?
[...]
> Thanks in advance for any assistance or direction.

Which part of the FAQ "perldoc -q environment" is unclear and need
improvement?

jue




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

Date: Thu, 9 Jan 2003 09:51:52 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Unix Vars declared in system() call -> %ENV
Message-Id: <slrnb1r6ko.oh7.tadmc@magna.augustmail.com>

Christopher Hamel <hamelcd@hotmail.com> wrote:

> Perhaps this is easy; perhaps it's impossible.


It is the latter.


> Is there any way to launch this program within Perl and have the
> variable declarations within the program update %ENV?


No.


> Thanks in advance for any assistance or direction.

   perldoc -q environment


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 9 Jan 2003 09:28:20 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: using subroutines defined in other scripts
Message-Id: <slrnb1r58k.oh7.tadmc@magna.augustmail.com>

Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com> wrote:
> Tad McClellan wrote (Wednesday 08 January 2003 17:50):

>> Read all about it:
>> 
>>     http://www.geocities.com/nnqweb/nquote.html
> 
> 
> That pages doesn't run anymore. It has been moved to
> http://members.fortunecity.com/nnqweb/nquote.html


Doh!

Looks like I'll be revising the Posting Guidelines soon then.

I'll start another thread to see if there's anything else folks
think I should change while I'm in there.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

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.  

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 V10 Issue 4372
***************************************


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