[7686] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1312 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 13 12:15:53 1997

Date: Thu, 13 Nov 97 09:00:26 -0800
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, 13 Nov 1997     Volume: 8 Number: 1312

Today's topics:
     !Best HW/SW config for Perl <74331.3261@CompuServe.COM>
     [Q]: Arbitrary sort on field names <mystery@itis.com>
     Re: [Q]: Arbitrary sort on field names (Toutatis)
     Re: [Q]: Arbitrary sort on field names (Tad McClellan)
     Re: [Q]: Arbitrary sort on field names (Andrew M. Langmead)
     Re: Cannot Opendir in NT? <$_=qq!fearless\@NOSPAMio.com!;y/A-Z//d;print>
     Re: carriage returns (Greg Bacon)
     Re: creating file <rootbeer@teleport.com>
     Re: Finding "best fit" subset of a set? gnat@frii.com
     GD.pm installation problem on WinNT 4.0 <dixxonn@dixxonn.on.ca>
     how do you execute external programs with perl <eeparrad@swansea.ac.uk>
     Re: how do you execute external programs with perl (Mike Stok)
     Re: How do you pass a codeRef to the sort sub (Mike Stok)
     Re: How do you pass a codeRef to the sort sub <tw36027@glaxowellcome.com>
     Re: How do you pass a codeRef to the sort sub (Mike Stok)
     Re: How to create a timeout for connect() ? <gbarr@ti.com>
     How to determine absolute file path on UNIX (Alfred von Campe)
     multiple files with perl compiler <bhh@iti-oh.com>
     Re: Newbie Q: Perl @HASH and C Structures <youngej@magpage.com>
     Perl.exe <douglas@kemo.com>
     Please help explain this math error: (James L. McGill)
     Re: Please help explain this math error: (Mike Stok)
     Re: s/PATTERN/REPLACE/eeg with list context? <merlyn@stonehenge.com>
     Re: Seeking help with File::Find <merlyn@stonehenge.com>
     Re: Tainting Question (Vince Wilding)
     Tk support in perldb question <gwebb@reedtech.com>
     URGENT: Perl calling Perl (was: Re: Calling a Perl scri <frits.scholten@nl.origin-it.com>
     Re: URGENT: Perl calling Perl (was: Re: Calling a Perl  (Tad McClellan)
     Re: Will pay $$ for FORM-to-DBASE perl script rets@meta3.com
     Re: WIN32:ODBC Problems <petri.backstrom@icl.fi>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Thu, 13 Nov 1997 08:55:02 -0500
From: Terry Michaels <74331.3261@CompuServe.COM>
Subject: !Best HW/SW config for Perl
Message-Id: <eOD59uD88GA.305@nih2naab.prod2.compuserve.com>

Greetings!

I am interested in hearing people's thoughts on what is the
best hardware/software configuration for using perl and
internet.  Tell me what works for you.

Thanks

Terry Michaels
TMichaels@compuserve.com


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

Date: Thu, 13 Nov 1997 09:47:17 -0500
From: Prince Mystery <mystery@itis.com>
Subject: [Q]: Arbitrary sort on field names
Message-Id: <346B12F5.A2470F6B@itis.com>

@fieldnames = ("name", "address1", "address2", "city", "state");

If I give the user the option to list a variable amount of field names,
and end up with an array similar (but smaller) to the one above, how do
I sort so that they will always appear in some semblance to the order
implied by the @fieldnames array?  (i.e. an array of ("city","name")
would be sorted to ("name", "city")).

Myst
-- 

Version: 2.6.2

owEBiAB3/4kAdQMFADPY9d1hGXgCUdEssQEBvREDAJodjyXMMZnOxrzl6Z5Anldh
p/mCNLshfYr/aLB+vmR2CrdySGCqBZFg+GanInyn/Vg6oRNoLgM/sU5+sbYntGt1
nI2B8/PZIDxOTA3S6BktLawONN/RGcqjPhDPm8l636wOYgh0ZXh0ZmlsZQAAAAA=
=beaq
-----END PGP MESSAGE-----


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

Date: 13 Nov 1997 15:28:11 GMT
From: toutatis@_SPAMTRAP_toutatis.net (Toutatis)
Subject: Re: [Q]: Arbitrary sort on field names
Message-Id: <toutatis-ya023180001311971628120001@news.euro.net>

Prince Mystery <mystery@itis.com> wrote:

Hmmm, handsome too?

> @fieldnames = ("name", "address1", "address2", "city", "state");
> 
> If I give the user the option to list a variable amount of field names,
> and end up with an array similar (but smaller) to the one above, how do
> I sort so that they will always appear in some semblance to the order
> implied by the @fieldnames array?  (i.e. an array of ("city","name")
> would be sorted to ("name", "city")).

I suggest you build a lookuptable with the sort order once in your script:
$i = 0;
%LUT = map {$_,$i++} @fieldnames;

Then use this table to sort:
@sorted = sort {$LUT{$a} <=> $LUT{$b}} @user_supplied_fields;

-- 
Toutatis


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

Date: Thu, 13 Nov 1997 09:46:18 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: [Q]: Arbitrary sort on field names
Message-Id: <ac7f46.om.ln@localhost>

Prince Mystery (mystery@itis.com) wrote:

: If I give the user the option to list a variable amount of field names,
: and end up with an array similar (but smaller) to the one above, how do
: I sort so that they will always appear in some semblance to the order
: implied by the @fieldnames array?  (i.e. an array of ("city","name")
: would be sorted to ("name", "city")).


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

@fieldnames = ("name", "address1", "address2", "city", "state");

for ($i=0; $i<@fieldnames; $i++)  # store in a hash instead
   {$order{$fieldnames[$i]} = $i}  #   key=fieldname value=ordinal number

@actuals = ("city", "name");
@actuals = sort {$order{$a} <=> $order{$b}} @actuals;

foreach (@actuals)
   {print "$_\n"}
------------


--
    Tad McClellan                          SGML Consulting
    tadmc@flash.net                        Perl programming
    Fort Worth, Texas


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

Date: Thu, 13 Nov 1997 16:37:09 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: [Q]: Arbitrary sort on field names
Message-Id: <EJLFHx.FA6@world.std.com>

Prince Mystery <mystery@itis.com> writes:

>@fieldnames = ("name", "address1", "address2", "city", "state");

>If I give the user the option to list a variable amount of field names,
>and end up with an array similar (but smaller) to the one above, how do
>I sort so that they will always appear in some semblance to the order
>implied by the @fieldnames array?  (i.e. an array of ("city","name")
>would be sorted to ("name", "city")).

How about if you set up a hash that maps the contents of @fieldnames
to their sort order, and have a sort subroutine that access that hash
to determine the current items placement in that ordering?

#!/usr/bin/perl -w

@fieldnames = ("name", "address1", "address2", "city", "state");

{
 my $pos = 0;
 %order = map { $_, $pos++ } @fieldnames;
}

@input = ('city','name');

@sorted = sort { $order{$a} <=> $order{$b} } @input;

print "@sorted\n";
-- 
Andrew Langmead


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

Date: Thu, 13 Nov 1997 06:29:09 -0800
From: "Creede Lambard" <$_=qq!fearless\@NOSPAMio.com!;y/A-Z//d;print>
Subject: Re: Cannot Opendir in NT?
Message-Id: <64f2qt$16g@mtinsc02.worldnet.att.net>

I'm not sure entirely what's happening here, but you might want to find out.
Try changing the opendir line and the one before it to

return 0 unless (-e $target_dir);
opendir(DIR,$target_dir) or die "Can't open $targetdir: $!";

$! holds the last error message and may tell you something useful.

--- Creede Lambard
Minister of Irregular Expressions
Programming Republic of Perl

lai wrote in message <346AABCD.A3B5E573@src.ncu.edu.tw>...
>hi all,
>
>My follow program always die at "opendir" in NT but never die in Unix.
>What's wrong with me or with the program ? I has tried many many times
>and cannot find why? Would anybody help me?
>
>
>my $mydir="C:\\Inetpub\\wwwroot\\";
>### I had tried C:\\Inetpub\\wwwroot";
>### and even C:\Inetpub\wwwroot\;
>
>
>read_dir($mydir);
>
>sub read_dir
>{
>    local($target_dir) = @_ ;
>    local($files);
>     return 0 if( !$target_dir );
>     opendir(DIR, $target_dir) ||   die "$target_dir: return 0 file";
>     @files=readdir(DIR);
>     closedir(DIR);
>     return @files;
>}
>
>Thanks
>




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

Date: 13 Nov 1997 16:33:28 GMT
From: gbacon@adtran.com (Greg Bacon)
Subject: Re: carriage returns
Message-Id: <64fa4o$1ni$1@info.uah.edu>

In article <comdog-ya02408000R1211971754410001@news.panix.com>,
	comdog@computerdog.com (brian d foy) writes:
: In article <64cqt0$3de$5@info.uah.edu>, gbacon@adtran.com (Greg Bacon) wrote:
: 
: >In article <3469E823.67CA@cpdmfg.cig.mot.com>,
: >: $var = "This is^Ma text string^Mwith unwanted^Mcarriage returns."
: >
: >    $var =~ s/\s+/ /g;
: 
: but that leaves the carriage returns since they don't 
: necessarily match that pattern.

If your locale/libc is so broken that they doesn't consider a carriage
return to be whitespace, there's not much perl (or Perl) can do to
help you. :-)

I've always found C<s/\s+/ /g> to be far more useful than other more
specific substitutions.

Greg
-- 
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF


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

Date: Thu, 13 Nov 1997 06:28:19 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: mmj@philonline.com
Subject: Re: creating file
Message-Id: <Pine.GSO.3.96.971113062747.18021B-100000@usertest.teleport.com>

On 11 Nov 1997, Michael J. Maravillo wrote:

> open(F, '>/foo/bar');

Even when your script is "just an example" (and perhaps especially in that
case!) you should _always_ check the return value after opening a file.

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: 13 Nov 1997 09:37:12 -0700
From: gnat@frii.com
Subject: Re: Finding "best fit" subset of a set?
Message-Id: <5qk9ecg37r.fsf@prometheus.frii.com>

mcravit@best.com (Matthew Cravit) writes:
> I'd like to find a function/module which will, given an array of
> integers, return the subset of them whose sum is closest to a
> specified "target" value.

This is the knapsack problem.  As far as we know, there's no algorithm
that will give you the best subset without trying all combinations.
The simplest algorithm to solve the problem is a greedy one.

#!/usr/bin/perl -w

#
# greedy algorithm to solve knapsack problem
#

$max = shift @ARGV || die "first argument is maximum size of knapsack\n";
@all = sort {$b <=> $a} @ARGV;

print "Finding $max from @all\n";

@knapsack = ();
$sum = 0;

while ($sum <= $max && @all) {
    $elt = shift @all;
    if ($sum + $elt <= $max) {
	push(@knapsack, $elt);
	$sum += $elt;
    }
}

print "Sum: $sum\n";
print "Set: @knapsack\n";

__END__

This goes through the list of objects, from biggest to smallest, and
adds the current object to the knapsack if it fits.  It's not hard to
find situations where the greedy solution doesn't do what you wanted:

gnat@prometheus (~/cs) /tmp/knapsack 12 4 3 3 3 3
Finding 12 from 4 3 3 3 3
Sum: 10
Set: 4 3 3

It could have filled the knapsack exactly by taking the four threes,
but it was greedy and took a four, which meant it could then only make
a total of ten using the remaining threes.

There is also an approximate algorithm, in which you quantize your
file sizes, provide a lower bound for file size, and then solve this
approximation of your problem.  You can find it in the lecture notes
for CS651 ("Advanced Algorithms") online at
	http://www.cs.umd.edu/~samir/cs651.ps
You'll want pages 70 on.

Cheers;

Nat


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

Date: Thu, 13 Nov 1997 10:46:12 -0500
From: "S. Sebastein Dixxonn" <dixxonn@dixxonn.on.ca>
Subject: GD.pm installation problem on WinNT 4.0
Message-Id: <346B20C3.2C771013@dixxonn.on.ca>

Hi,

I'm getting most of the installation, but the file GD.so isn't being
created and thus isn't being
installed into the perl-lib directory. Can someone suggest where I can
get a hold of the file?

Preferrably on short notice, as my companies website is due to launch
tomorrow, and this is the
only section of the site that is "playing up".

Thank you in advance


--
S. Sebastein Dixxonn,
President/Owner
Dixxonn Corporation
www.dixxonn.on.ca
dixxonn@dixxonn.on.ca




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

Date: Thu, 13 Nov 1997 15:10:47 +0000
From: Dean Parratt <eeparrad@swansea.ac.uk>
Subject: how do you execute external programs with perl
Message-Id: <346B1876.7B07@swansea.ac.uk>

I am trying to execute a program or command which has arguments from a
loop within a perl program so that the command will execute over and
over again. I have tried exec and system but I can't make them execute
my command. Can anybody tell me how to do this?

Please email me at 

eeparrad@swansea.ac.uk

Thanks.


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

Date: 13 Nov 1997 15:34:33 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: how do you execute external programs with perl
Message-Id: <64f6m9$179@news-central.tiac.net>

In article <346B1876.7B07@swansea.ac.uk>,
Dean Parratt  <eeparrad@swansea.ac.uk> wrote:
>I am trying to execute a program or command which has arguments from a
>loop within a perl program so that the command will execute over and
>over again. I have tried exec and system but I can't make them execute
>my command. Can anybody tell me how to do this?

Well system is probably what you want, could you post the code that fails
and any error diagnostics?

Mike
-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: 13 Nov 1997 13:56:39 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: How do you pass a codeRef to the sort sub
Message-Id: <64f0un$opr@news-central.tiac.net>

In article <346AF510.EBC40B2D@glaxowellcome.com>,
Thad Welch  <tw36027@glaxowellcome.com> wrote:
>Striped to its basics, here's what I'm trying to do:
>
>print objSort( sub { $a cmp $b } );
>
>sub objSort{
>    my $codeRef = shift;
>     my @objs = qw( c b a );
>
>     return sort $codeRef @objs
>}

One way to do it might be:

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

use strict;

sub objSort (&);		# see perlsub discussion on prototypes

sub ascending {$a cmp $b};

print objSort {$b cmp $a}, "\n";
print objSort {ascending}, "\n";

sub objSort (&) {
  local *codeRef = shift;
  my @objs = qw( c b a );

  return sort codeRef @objs
}

__END__

Hope this helps,

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: Thu, 13 Nov 1997 09:43:17 -0500
From: Thad Welch <tw36027@glaxowellcome.com>
To: Mike Stok <mike@stok.co.uk>
Subject: Re: How do you pass a codeRef to the sort sub
Message-Id: <346B1204.51251E5D@glaxowellcome.com>

    Mike,

    Thanks for your reply.   However, I stripped  my example too much. Here's what
I should of
posted the first time:
#!/pub/bioinfo/perl/bin/perl
require 5.001;

my $objs = Objs->new;
$objs->sort( sub { $a cmp $b } );

print @{$objs->{objs}}, "\n";

package Objs;

sub new {
    bless { objs=>[ 'b', 'c', 'a' ] }, 'Objs';
}

sub sort {
    my $self = shift;
    my $codeRef = shift;

    my @t = sort codeRef @{$objs->{objs}};
    $objs->{objs} = \@t;
}

Since my sort is in a package,  the sub prototype doesn't work.

Thanks,
Thad


Mike Stok wrote:

> In article <346AF510.EBC40B2D@glaxowellcome.com>,
> Thad Welch  <tw36027@glaxowellcome.com> wrote:
> >Striped to its basics, here's what I'm trying to do:
> >
> >print objSort( sub { $a cmp $b } );
> >
> >sub objSort{
> >    my $codeRef = shift;
> >     my @objs = qw( c b a );
> >
> >     return sort $codeRef @objs
> >}
>
> One way to do it might be:
>
> #!/usr/local/bin/perl -w
>
> use strict;
>
> sub objSort (&);                # see perlsub discussion on prototypes
>
> sub ascending {$a cmp $b};
>
> print objSort {$b cmp $a}, "\n";
> print objSort {ascending}, "\n";
>
> sub objSort (&) {
>   local *codeRef = shift;
>   my @objs = qw( c b a );
>
>   return sort codeRef @objs
> }
>
> __END__
>
> Hope this helps,
>
> Mike
>
> --
> mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
> http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
> http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
> stok@colltech.com                  |            Collective Technologies (work)





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

Date: 13 Nov 1997 15:20:49 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: How do you pass a codeRef to the sort sub
Message-Id: <64f5sh$g3@news-central.tiac.net>

Does this help?  (I think) You need to use a glob and because the sort
anon sub is compiled outside of the Objs package you need to make sure
that $a and $b are appropriately qualified...  Using Sort or sort as the
method name doesn;t seem to matter, but if you're going to use a builtin's
name then it might be worth calling the "real" sort as CORE::sort

(I'm using 5.004_04, so there may be version dependent bug fixes...)

Mike

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

require 5.001;

my $objs = Objs->new;
$objs->Sort (sub {package Objs; $a cmp $b});

print @{$objs->{objs}}, "\n";

package Objs;

sub new {
  my $pack = shift;
  bless { objs => [ 'b', 'c', 'a' ] }, $pack;
}

sub Sort {
    my $self = shift;
    local *codeRef = shift;

    $self->{objs} = [sort codeRef @{$self->{objs}}];
}

Mike

In article <346B1204.51251E5D@glaxowellcome.com>,
Thad Welch  <tw36027@glaxowellcome.com> wrote:
>    Mike,
>
>    Thanks for your reply.   However, I stripped  my example too much. Here's what
>I should of
>posted the first time:
>#!/pub/bioinfo/perl/bin/perl
>require 5.001;
>
>my $objs = Objs->new;
>$objs->sort( sub { $a cmp $b } );
>
>print @{$objs->{objs}}, "\n";
>
>package Objs;
>
>sub new {
>    bless { objs=>[ 'b', 'c', 'a' ] }, 'Objs';
>}
>
>sub sort {
>    my $self = shift;
>    my $codeRef = shift;
>
>    my @t = sort codeRef @{$objs->{objs}};
>    $objs->{objs} = \@t;
>}
>
>Since my sort is in a package,  the sub prototype doesn't work.
>
>Thanks,
>Thad
>
>
>Mike Stok wrote:
>
>> In article <346AF510.EBC40B2D@glaxowellcome.com>,
>> Thad Welch  <tw36027@glaxowellcome.com> wrote:
>> >Striped to its basics, here's what I'm trying to do:
>> >
>> >print objSort( sub { $a cmp $b } );
>> >
>> >sub objSort{
>> >    my $codeRef = shift;
>> >     my @objs = qw( c b a );
>> >
>> >     return sort $codeRef @objs
>> >}
>>
>> One way to do it might be:
>>
>> #!/usr/local/bin/perl -w
>>
>> use strict;
>>
>> sub objSort (&);                # see perlsub discussion on prototypes
>>
>> sub ascending {$a cmp $b};
>>
>> print objSort {$b cmp $a}, "\n";
>> print objSort {ascending}, "\n";
>>
>> sub objSort (&) {
>>   local *codeRef = shift;
>>   my @objs = qw( c b a );
>>
>>   return sort codeRef @objs
>> }
>>
>> __END__
>>
>> Hope this helps,
>>
>> Mike
>>
>> --
>> mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
>> http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
>> http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
>> stok@colltech.com                  |            Collective Technologies (work)
>
>
>


-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: Thu, 13 Nov 1997 07:57:46 -0600
From: Graham Barr <gbarr@ti.com>
Subject: Re: How to create a timeout for connect() ?
Message-Id: <346B075A.35827509@ti.com>

Frederic GILLES wrote:
> 
> When the connection to a server with the function connect() doesn't
> work, it doesn't give me an answer.
> I want to define a timeout alarm to stop the connect() and to continue
> the program?
> How can I do that?
> 
> I'm using Perl 5.004 with Solaris 2.5.

If you have perl5.004 then you have IO::Socket, perldoc IO::Socket
will give you the man page. IO::Socket does exactly what you want
but it does not use $SIG{ALRM} which can cause unwanted side effects.

use IO::Socket;

$sock = new IO::Socket(
    PeerAddr => "123.456.789.012",
    PeerPort => "ftp",
    Timeout  => 10, # seconds
    Domain => AF_INET,
    Proto => 'tcp'
) or die "$@";

you now have a handle $sock which is connect ro your remote host,
IO::Socket can also create listen sockets and accept incoming
connections.

Graham.

    
-- 
Originality is the ability to conceal your source.


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

Date: 13 Nov 1997 15:53:33 GMT
From: alfred@hw.stratus.com (Alfred von Campe)
Subject: How to determine absolute file path on UNIX
Message-Id: <64f7pt$b0s@transfer.stratus.com>

Before I reinvent the wheel, is there a way in Perl to determine
the absolute path to a given filename?  The File::Basename module
doesn't do what I need, and I haven't found anything else that
comes close.

Here are some examples of what I need assuming that my current
working directory is ~/bin (at our site, all user directories
are accessible as /h/user):

  foo                    -> /h/alfred/bin/foo
  sub/foo                -> /h/alfred/bin/sub/foo
  ./sub/foo              -> /h/alfred/bin/sub/foo
  ../tools/../bin/foo    -> /h/alfred/bin/foo
  ../tools/foo           -> /h/alfred/tools/foo
  ~user/foo              -> /h/user/foo
  /usr/local/scripts/foo -> /usr/local/scripts/foo

Also, if there are any symbolic links along a path, I need to get
the final (real) path.  Basically, what I need is what $ENV{'PWD'}
is set to if I were to "cd" to the directory that contains the file
in question.  There must be an easy way to do this in Perl, but I
have not found it (yet! :-).

Alfred
-- 
+------------------------------------------------------------+
| Phone: H: 978.448.6214, W: 508.490.6306, fax: 508.460.2888  \
|  Mail: Alfred von Campe, 402 Lowell Road, Groton, MA 01450   \
| Email: alfred@hw.stratus.com                                  \
+----------------------------------+-----------------------------+
| Why is common sense so uncommon? | I'd rather be flying N4381Q |
+----------------------------------+-----------------------------+


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

Date: Thu, 13 Nov 1997 10:20:34 -0500
From: Brad Hochstetler <bhh@iti-oh.com>
Subject: multiple files with perl compiler
Message-Id: <346B1AC2.3B4A@iti-oh.com>

I was wondering if anyone has compiled a perl file and a package
into one executable with the perl compiler?
Am I overlooking something in the documentation?  Any help would
be appreciated.

I am using perl5.003 with the alpha3 version of the perl compiler.

Thanks in advance,

Brad Hochstetler
bhh@iti-oh.com


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

Date: 13 Nov 1997 14:50:44 GMT
From: Ed Young <youngej@magpage.com>
Subject: Re: Newbie Q: Perl @HASH and C Structures
Message-Id: <64f444$37f$1@204.179.92.233>

Look into 'unpack' in perlfunc, or 'pack' if you want to write.

coyote ghost wrote:
> 
> Hello o' venerable Perl Programmers,
> 
> I'm a seasoned C programmer, but I am just now getting into Perl.  I
> have some C binary database files that I.ve created and I'd like to
> create a library for perl to access them.
> 
> It appears that the closest thing to a C structure in perl is an
> associative array, so is it possible to create an associative array to
> duplicate my C structure, then use that array to read and write to a
> file, as I would with a structure in C?  (The key to this being that the
> C structure and the Perl Array will be set up to be the exact same size
> in terms of bytes used.)
> 
> I'd really appreciate hearing from anyone that has any ideas on how this
> task might be accomplished.
> 
> Thanks,
> Bryan Ingram
> zeropage@computek.net


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

Date: Thu, 13 Nov 1997 15:04:33 +0000
From: Douglas Willock <douglas@kemo.com>
Subject: Perl.exe
Message-Id: <DqgVSDABcxa0EwrP@kemo1.demon.co.uk>


I have Microsoft Internet Server running on NT server. And I would like
to be able to execute perl files on the machine, can I just load a
perl.exe program on to the NT server and associate files with a PL
extension with the perl.exe program.

Will this work??
Where can I get this file? (Perl Version 5 would be handy.)

Thanks,


  Douglas Willock

  Email: douglas@kemo.com       Web: www.kemo.com


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

Date: 13 Nov 1997 10:17:58 -0600
From: fishbowl@fotd.netcomi.com (James L. McGill)
Subject: Please help explain this math error:
Message-Id: <64f97m$k3a$1@fotd.netcomi.com>

This is one of those kinds of math errors I expect to 
find, but I want to explain the exact nature of the error.

In C, I write:

main(int argc, char **argv){
    float fl;
	fl= 129.23;
		printf( "float = %f, int = %d\n", fl,  (int) (fl * 100) );
}

which says:
float = 129.229996, int = 12923


Which is what I expect.

In Perl, This is perl, version 5.004_03
I write:

	$fl= 129.23;
	printf( "float = %f, int = %d\n", $fl, int($fl * 100) );

which says:
float = 129.230000, int = 12922


So what I believe is that there is a difference in the way a
float is formatted, but the internal representation of a 
float (a perl double sv of course) is the same, thus
the rounding error of int().  I really expected 12923.

--
g-r-a-t-e-f-u-l-l-y---[   email:<fishbowl@conservatory.com>   ]---l-i-v-i-n-g
d-e-a-d-i-c-a-t-e-d---[     http://www.conservatory.com/      ]-----l-i-g-h-t


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

Date: 13 Nov 1997 16:40:33 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Please help explain this math error:
Message-Id: <64fai1$4se@news-central.tiac.net>

Because perl's aritmetic is done using double precision numbers by
default.  Changing the float to a double in your C should produce similar
results to the perl.

Hope this helps,

Mike

In article <64f97m$k3a$1@fotd.netcomi.com>,
James L. McGill <fishbowl@fotd.netcomi.com> wrote:
>This is one of those kinds of math errors I expect to 
>find, but I want to explain the exact nature of the error.
>
>In C, I write:
>
>main(int argc, char **argv){
>    float fl;
>	fl= 129.23;
>		printf( "float = %f, int = %d\n", fl,  (int) (fl * 100) );
>}
>
>which says:
>float = 129.229996, int = 12923
>
>
>Which is what I expect.
>
>In Perl, This is perl, version 5.004_03
>I write:
>
>	$fl= 129.23;
>	printf( "float = %f, int = %d\n", $fl, int($fl * 100) );
>
>which says:
>float = 129.230000, int = 12922
>
>
>So what I believe is that there is a difference in the way a
>float is formatted, but the internal representation of a 
>float (a perl double sv of course) is the same, thus
>the rounding error of int().  I really expected 12923.
>
>--
>g-r-a-t-e-f-u-l-l-y---[   email:<fishbowl@conservatory.com>   ]---l-i-v-i-n-g
>d-e-a-d-i-c-a-t-e-d---[     http://www.conservatory.com/      ]-----l-i-g-h-t


-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: 13 Nov 1997 08:31:35 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: jwang@harbinger.sims.berkeley.edu (James Wang)
Subject: Re: s/PATTERN/REPLACE/eeg with list context?
Message-Id: <8cbtzoolns.fsf@gadget.cscaper.com>

>>>>> "James" == James Wang <jwang@harbinger.sims.berkeley.edu> writes:

James> 	i'm using the "s/(\$\w+)/$1/eeg" idiom to expand
James> 	simple embedded variables, per the example given
James> 	in the manpages.

Although the latest FAQ says you should do it this way (for
package vars, anyway):

	s/\$(\w+)/$$1/g;

No "e" required.

James> 	now i would like to expand list variables, arrays
James> 	to be specific.  the obvious thing i tried was:
James> 	"s/(\@\w+)/$1/eeg", which returned the lengths of
James> 	the arrays i'm after, rather than their content.

James> 	it appears that the $1 expression is evaluated
James> 	in scalar context, and i haven't been able to 
James> 	convince it otherwise.

James> 	what am i missing?  please cc: any followup.

Try this:

	s/\@(\w+)/@$1/g;

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 292 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: 13 Nov 1997 08:35:16 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: Dave Barnett <barnett@houston.Geco-Prakla.slb.com>
Subject: Re: Seeking help with File::Find
Message-Id: <8c90usolhn.fsf@gadget.cscaper.com>

>>>>> "Dave" == Dave Barnett <barnett@houston.Geco-Prakla.slb.com> writes:

Dave> I'm attempting to use the File::Find module to find files > 7 days old,
Dave> and (eventually) remove them.

You're working too hard.  Let Perl write the code for you:

find2perl /top /level /dirs -mtime +7 \
    -eval 'print "$File::Find::name? "; <STDIN> =~ /^y/i and unlink' >yourprog

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 292 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: Thu, 13 Nov 1997 09:51:57 -0600
From: vwilding@mib.nbs.gov (Vince Wilding)
Subject: Re: Tainting Question
Message-Id: <879435998.19201@dejanews.com>

In article <879366984.32217@dejanews.com>,
  vwilding@mib.nbs.gov (Vince Wilding) wrote:
>
> I have a CGI-script that needs to allow users to generate a file in a
> world-writable directory and write to it.  When I run with -T, it
> complains, I would suppose, about the world-writable directory.  Is there
> a way around this, i.e. WRITING to a world writable directory and still
> pass the taint check?

There must be a sniglet for someone who posts a reply to his own post.
Anyway,  I found my problem.  The tainting problem was not that I was
writing to a world writable directory, but a little deeper.  I was
picking up a count from a world writable file and using it to generate
the file name.  The following snippet demonstrates:

##########################################################################
#!/usr/local/bin/perl -Tw
$ENV{'PATH'} = "/bin:/usr/bin:/usr/ucb";
$ENV{'IFS'} = "";
$date_command = "/usr/bin/date";
$DTG = `$date_command +"%D %T %Z"`; chomp($DTG);

$count_file = "/yada/count.fil";  #World Writable File

open(COUNT,"$count_file") || die "VCFW: Failed Open(r) $count_file: $!\n";

$count = <COUNT>;          #<< $count is now nasty

close(COUNT); chomp ($count); $count++; open(COUNT,">$count_file") || die
"VCFW: Failed Open(w) $count_file: $!\n"; print COUNT "$count";
close(COUNT); $TraceFile_fl  = "/yada/worldwritable/file".$count.".html";
print "$TraceFile_fl\n"; open (TraceFile, ">$TraceFile_fl") ; print
TraceFile "Greetings, Earther, We Have Landed \@ $DTG\n"; close
(TraceFile); exit;
########################################################################

After reading $count, I added (straight from the perlsec man page):

if ($count =~ /^([-\@\w.]+)$/) {
  $count = $1;                     # $count now denastificated
} else {
  die "VCFW  $count_file Corrupted!!!";
}

The counter bump routine was buried elsewhere, but I put it inline in
the above snippet.

REMEMBER!!! You were a newbie once, yourself.
=================================
Vince Wilding
Web Wrangler
USGS/BRD
vince_wilding@usgs.gov
http://biology.usgs.gov/pubs/vcfw

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: Thu, 13 Nov 1997 09:52:21 -0600
From: Garth Webb <gwebb@reedtech.com>
Subject: Tk support in perldb question
Message-Id: <879435147.18395@dejanews.com>

I am trying to write a very simple perl debugger using the Tk module in
perl.  My problem is that the perl debugger wants to call a DB function
listed in the debugger code for every breakable line.  This clashes with
Tk's event driven interface.  I want to have at Tk event (such as a mouse
click on a button labeled 'step') tell the debugger to move to the next
line and call the DB function, instead of the debugger doing it
automatically when DB exits.	     I know there is a debugger option
called 'tkrunning' which I suspect may hold an answer but I have found no
documentation on it anywhere (perldebug says 'Runs Tk while prompting'
which doesnt tell me much, and the camel book doesnt even mention it). 
Does anyone have a solution to my problem?  Your help is appreciated.

Garth Webb
gwebb@reedtech.com

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: 13 Nov 1997 14:39:32 GMT
From: "Frits Scholten" <frits.scholten@nl.origin-it.com>
Subject: URGENT: Perl calling Perl (was: Re: Calling a Perl script from a Perl script CAN YOU HELP??)
Message-Id: <01bcf042$9c466c60$f52110ac@di33frsc.groswi.nl.origin-it.com>

Hi everyone,

brian d foy <comdog@computerdog.com> wrote in article
<comdog-ya02408000R1211971716580001@news.panix.com>...

> >Anyway, I was wondering if there was a way to call a Perl CGI script
> >from another Perl CGI script. Currently I'm having the first script
> >write an HTML page with javascript which is instructed to call the next
> >Perl Script. 
> 
> it sounds like you simply need a reference to the next CGI script in
> the HTML.  was there some other way that you needed to call the 
> second CGI script?
> 

We're trying to start a Perl script on a NT / Netscape Enterprise 3.0
server. The script is supposed to call another script that produces the
output but it doesn't seem to work. On the command prompt it works ok but
from the browser it doesn't. We've tried to do the same with .bat files
where the first .bat calls the second .bat which produces the http header
and famous hello world! line. This doesn't work either so it looks like it
isn't a Perl problem. The plan is to use scripts to set environment
variables and then call other scipts or exe's (using system("name.pl")).

What are we doing wrong....?

Mike Pruis (mike.pruis@nl.origin-it.com)
Frits Scholten (frits.scholten@nl.origin-it.com)
Origin/Groningen


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

Date: Thu, 13 Nov 1997 09:33:25 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: URGENT: Perl calling Perl (was: Re: Calling a Perl script from a Perl script CAN YOU HELP??)
Message-Id: <5k6f46.bj.ln@localhost>

Frits Scholten (frits.scholten@nl.origin-it.com) wrote:

: We're trying to start a Perl script on a NT / Netscape Enterprise 3.0
: server. The script is supposed to call another script that produces the
: output but it doesn't seem to work. 

: On the command prompt it works ok but
: from the browser it doesn't. 


Perl FAQ, part 9:

   "My CGI script runs from the command line but not the browser.  
    Can you help me fix it?"


: We've tried to do the same with .bat files
: where the first .bat calls the second .bat which produces the http header
: and famous hello world! line. 

: This doesn't work either so it looks like it
: isn't a Perl problem. 


So why are you posting to the perl newgroup then?


: What are we doing wrong....?


Asking server questions in a newsgroup that is not related to servers  ;-)

   comp.infosystems.www.servers.ms-windows


--
    Tad McClellan                          SGML Consulting
    tadmc@flash.net                        Perl programming
    Fort Worth, Texas


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

Date: Thu, 13 Nov 1997 08:32:10 -0600
From: rets@meta3.com
To: rets@meta3.com
Subject: Re: Will pay $$ for FORM-to-DBASE perl script
Message-Id: <879431131.14911@dejanews.com>

#!/usr/bin/perl5

# URL Encoded to DB recovery
# Copyright(C) 1997 Kenneth A. Holm III
# All rights reserved
#
# See Licensing Info at http://www.metamall.com/rets/license.html
# If you find this script useful please send lots of money to
# Ken Holm
# POB 97536
# Jackson, MS 39288-7536
# rets@meta3.com

my $OFile = "test.dat";	# ASCII file where Data is kept
my $NFile = "data.new"; # ASCII, comma delimited file
my @List;
my @Data;

open (A, $OFile);	# Open our Data file
open (B, ">>$NFile");	# Open a file to catch the output
while (<A>) {
    chomp;		# Get rid of the newline
    $_ =~ s/\cM//g;	# Get rid of any ^M's
    next unless ($_);	# Skip this line if it is blank
    (@Data) = split(/\&/, $_);
			# Split the current line into manageable chunks
    for (@Data) {
	$_ =~ s/^.*\=//g;
			# Get rid of the key
	$_ =~ s/\+/ /g;	# Change URL encoded spaces into ASCII spaces
	$_ =~ s/%(..)/pack("c",hex($1))/ge;
			# Change URL encoded stuff into ASCII stuff
	$_ = qq!"$_"!;	# Put "'s around each piece of data
	push @List, $_;	# Building our list
    }
    print B join ",", @List;
			# Build new line for output file
    print B "\n";	# Print new line to output file
    @List = ();		# Clear our list
}
close B;		# Close our output file
close A;		# Close out input file

exit;

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: Thu, 13 Nov 1997 14:40:33 +0200
From: Petri Backstrom <petri.backstrom@icl.fi>
Subject: Re: WIN32:ODBC Problems
Message-Id: <346AF541.16CE@icl.fi>

Guy R. Loucks wrote:
> 
> Ok, this is driving me off the deep end.
> 
> This is our configuration:
> Windows NT 4.0 (Workstation and Server) Service PAK 2
> Oracle 7.3.2.3.1 Workgroup Server (NT)
> Oracle ODBC Driver
> 
> ODBC has checked out fine, with Excel, Access, ...
> 
> Perl version 5.003_07 Build 310 by Activeware
> 
> Initial problem was we were unable to locate the libraries. Have now
> defined the PERL5LIB to point to c:\perl\lib
> 
> The perl program works fine, until we try to include the ODBC module.
> We
> are using the latest version. Our program and the ODBC test program
> provide the samer error:
> 
> error: parse exception,
> 
> This is generated whenever the line:
> 
> use Win32::ODBC;
> 
> is uncommented.  We have tried with and without use strict, and are
> using -w, no warnings or errors. This has to be something simple in
> the
> setup or configuration.
> 
> No other environment variables are set. And the Perl\bin directory is
> in
> the path.
> 
> the odbc.pll file is in the c:\perl\lib\auto\win32odbc directory
> and odbc.pm is in the c:\perl\lib\win32 directory.
> 
> Any ideas would be greatly appreciated.

It is a version mismatch; Perl version vs. the Win32::ODBC
module version.

The fix is to get a newer Win32::ODBC module. The workaround
is to get an older Perl release.

regards,
 ...petri.backstrom@icl.fi
    ICL Data Oy
    Finland


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 1312
**************************************

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