[25252] in Perl-Users-Digest
Perl-Users Digest, Issue: 7497 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 8 18:05:43 2004
Date: Wed, 8 Dec 2004 15:05: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 Wed, 8 Dec 2004 Volume: 10 Number: 7497
Today's topics:
Re: Catch Timeout for system calls in Windows? peterkayatwork@yahoo.com
data structure mxa@yahoo.com
Re: data structure <goedicke@goedsole.com>
Re: data structure <mritty@gmail.com>
Re: data structure mxa@yahoo.com
die'ing with the caller's line number carloschoenberg@yahoo.com
Re: die'ing with the caller's line number peterkayatwork@yahoo.com
Re: die'ing with the caller's line number peterkayatwork@yahoo.com
Re: I'm interesting to install some free database on Wi <abigail@abigail.nl>
Matching words and letters <mr@sandman.net>
Re: Matching words and letters <jkeen_via_google@yahoo.com>
Re: Maximum length of hash key <rob@nova.hbx.us>
Re: Maximum length of hash key <abigail@abigail.nl>
Re: Maximum length of hash key <rob@nova.hbx.us>
MS Perl question -- how to use hacked script to work co <djcameron60616@yahoo.com>
Re: New comp.lang.perl.misc mirror site at lampforums.o <jkeen_via_google@yahoo.com>
Re: Question on loops and return values <djcameron60616@yahoo.com>
Re: Question on loops and return values <djcameron60616@yahoo.com>
Seeking Internet Protection Service <electrician@nospam.com>
Web Form search and open pdf dbmeyers23@yahoo.com
Re: Web Form search and open pdf <mritty@gmail.com>
Re: Web Form search and open pdf <emschwar@fc.hp.com>
Re: why the following HereDoc print don't work? <jl_post@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 8 Dec 2004 13:23:57 -0800
From: peterkayatwork@yahoo.com
Subject: Re: Catch Timeout for system calls in Windows?
Message-Id: <1102541037.365118.216910@f14g2000cwb.googlegroups.com>
I got "Alarm clock" on the cygwin prompt and the script died.
I played around with it and came up with:
eval {
# from http://www.rocketaware.com/perl/perlfunc/alarm.htm
local $SIG{ALRM} = sub { die "alarm\n" }; # NB \n required
alarm(5); # set time limit to 5 sec
system($script);
alarm(0); # if $script finishes in <5sec reset alarm
};
die if $@ && $@ ne "alarm\n"; # propagate errors
if ( $@ ) {
print "Timeout! [$@]\n";
# do stuff if eval fails (eg timeout)
}
Thanks for the suggestion :)
--Peter
------------------------------
Date: 8 Dec 2004 11:09:03 -0800
From: mxa@yahoo.com
Subject: data structure
Message-Id: <1102532943.821950.195630@f14g2000cwb.googlegroups.com>
Hi,
I need to set up a data structure that is very similar to two level
unix directory.
my ( @files, %dir )
@files=('file1','file2','file3');
$dir{'mydir'} = ( @files)
$dir{'root'} = ( $dir{'mydir'})
so root has many directories ( no files ) and each directory has many
files.
I am having problem accessing the above structure , any suggestion
is greatly appreciated ( please note that the actual problem has
nothing to do with dir and files ).
thanks
Michael
------------------------------
Date: Wed, 08 Dec 2004 19:44:03 GMT
From: William Goedicke <goedicke@goedsole.com>
Subject: Re: data structure
Message-Id: <m3oeh4r2wq.fsf@smtp.comcast.net>
Dear mxa -
>>>>> "mxa" == mxa <mxa@yahoo.com> writes:
mxa> Hi, I need to set up a data structure that is very similar to
mxa> two level unix directory. my ( @files, %dir )
mxa> @files=('file1','file2','file3'); $dir{'mydir'} = ( @files)
mxa> $dir{'root'} = ( $dir{'mydir'})
mxa> so root has many directories ( no files ) and each directory
mxa> has many files.
I would use something (untested) like:
my %root;
$root = ( 'd1' => [ 'd1f1', 'd1f2', 'd1f3' ],
'd2' => [ 'd2f1', 'd2f2' ],
'dn' => [ 'dnf1', 'dnf2' ,'dnfn' ],
);
then the following should work
foreach my $aref $root{'d1'} {
foreach @{$sref} {
print;
}
}
Yours - Billy
============================================================
William Goedicke goedicke@goedsole.com
Cell 617-510-7244 http://www.goedsole.com:8080
============================================================
Lest we forget:
Good management involves five activities:
o Facilitate your staff's efforts by removing organizational
impediments.
o Identify each staff member's strengths and goals
and veer their responsibilities towards them.
o Assign responsibility with commensurate authority.
o Set realistic expectations in your customers.
o Evangelize your services.
- William Goedicke
------------------------------
Date: Wed, 08 Dec 2004 20:20:19 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: data structure
Message-Id: <7mJtd.1176$pZ5.478@trndny06>
<mxa@yahoo.com> wrote in message
news:1102532943.821950.195630@f14g2000cwb.googlegroups.com...
> I need to set up a data structure that is very similar to two level
> unix directory.
> my ( @files, %dir )
> @files=('file1','file2','file3');
> $dir{'mydir'} = ( @files)
> $dir{'root'} = ( $dir{'mydir'})
>
> so root has many directories ( no files ) and each directory has many
> files.
>
> I am having problem accessing the above structure , any suggestion
> is greatly appreciated ( please note that the actual problem has
> nothing to do with dir and files ).
You can't assign an array to a scalar variable. You can only assign
array references to a scalar variable.
I strongly suggest you read up on references and multi-dimension data
structures:
perldoc perlreftut
perldoc perllol
perldoc perldsc
perldoc perlref
Any and all of those will be helpful to you.
Paul Lalli
------------------------------
Date: 8 Dec 2004 12:45:16 -0800
From: mxa@yahoo.com
Subject: Re: data structure
Message-Id: <1102538716.022783.319870@c13g2000cwb.googlegroups.com>
Hi,
beautiful , it worked :
my %root;
%root = ( 'd1' => [ 'd1f1', 'd1f2', 'd1f3' ],
'd2' => [ 'd2f1', 'd2f2' ],
'dn' => [ 'dnf1', 'dnf2' ,'dnfn' ],
);
p Dumper(\%root)
$VAR1 = {
'dn' => [
'dnf1',
'dnf2',
'dnfn'
],
'd1' => [
'd1f1',
'd1f2',
'd1f3'
],
'd2' => [
'd2f1',
'd2f2'
]
};
thanks
Michael
------------------------------
Date: 8 Dec 2004 13:29:44 -0800
From: carloschoenberg@yahoo.com
Subject: die'ing with the caller's line number
Message-Id: <1102541384.608648.248460@f14g2000cwb.googlegroups.com>
With DBI, it seems that if I want to use the "?" placeholders that I
must
use prepare and execute. So I made a simple helper function to do both
for
me, saving some typing and making the code slightly cleaner:
sub sql_do($@) {
my $q = shift;
my $sth = $dbh->prepare($q);
$sth->execute(@_);
}
But I run with AutoRaise on, and when I hit a fatal error, I get a line
number
inside of sql_do(), which is rarely useful.
What should I do to get the line number of the call to sql_do() when
sql_do()'s
call to execute fails?
------------------------------
Date: 8 Dec 2004 13:37:27 -0800
From: peterkayatwork@yahoo.com
Subject: Re: die'ing with the caller's line number
Message-Id: <1102541847.272965.162060@z14g2000cwz.googlegroups.com>
I think "confess" is what you're looking for (it has backtrace).
--Peter
------------------------------
Date: 8 Dec 2004 13:39:35 -0800
From: peterkayatwork@yahoo.com
Subject: Re: die'ing with the caller's line number
Message-Id: <1102541975.527432.171750@z14g2000cwz.googlegroups.com>
Oh, stupid on my part, forgot to mention:
use Carp;
confess "I am dying";
--Peter
------------------------------
Date: 08 Dec 2004 21:38:53 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: I'm interesting to install some free database on Windows 98 and XP.
Message-Id: <slrncret3d.k4s.abigail@alexandra.abigail.nl>
Tanja (tanja@verso.co.izbaciovo) wrote on MMMMCXVI September MCMXCIII in
<URL:news:41b5cedd@news.s5.net>:
$$ I'm interesting to install some free database on Windows 98 and XP.
$$ Is it Perl + MySql best solution?
$$ What about PHP + MySql, or Borland Interbase, or some IBM data base (don't
$$ now database name)?
$$ Please help me.
What makes you think comp.lang.perl.misc is the appropriate group to ask
for an OS-specific question regarding databases?
And if it were appropriate, what makes you think people here would be
unbiased?
Abigail
--
map{${+chr}=chr}map{$_=>$_^ord$"}$=+$]..3*$=/2;
print "$J$u$s$t $a$n$o$t$h$e$r $P$e$r$l $H$a$c$k$e$r\n";
------------------------------
Date: Wed, 08 Dec 2004 22:33:58 +0100
From: Sandman <mr@sandman.net>
Subject: Matching words and letters
Message-Id: <mr-EF7164.22335808122004@individual.net>
I just can't seem to wrap my mind around how to attack this problem in the best
way, so I thought I'd just post here and see if anyone here has done something
similar and/or has a logical solution to it.
I have a series of letters, say "kljetilamnop", then I have a big textfile with
legit words, but let's use a short one here:
mall
bill
kill
lot
pile
antilope
hello
Now, I want to cycle through this word list and match it to the letters, and
return true if the word can be formed by the letters. So, the above would
return:
mall
kill
lot
antilope
The result is to be used in a Scrabble-like fashion, which leads me to the
other part of my problem. When matching these words, I need to be able to
specify that some of the characters are "locked" in their position. So, lets
say that the letter "k" in the letter string is a fixed letter, then the only
result would be "kill" of course. I imagine that this would be easiest if I fed
the function the string and also the locked position in an array (1,6,8 for
example).
Anyway, this could easily become really complex, and if I just get the basic
scrambled-letters to match to words, I think I can manage my way from there.
So, any help appreciated.
--
Sandman[.net]
------------------------------
Date: Wed, 08 Dec 2004 22:34:24 GMT
From: Jim Keenan <jkeen_via_google@yahoo.com>
Subject: Re: Matching words and letters
Message-Id: <QjLtd.50$ag6.49@trndny07>
Sandman wrote:
>
> Anyway, this could easily become really complex, and if I just get the basic
> scrambled-letters to match to words, I think I can manage my way from there.
> So, any help appreciated.
>
See if the is_LsubsetR() method of my CPAN module List::Compare
(http://search.cpan.org/~jkeenan/List-Compare-0.31/Compare.pm) is useful
to you.
jimk
------------------------------
Date: Wed, 8 Dec 2004 21:45:33 +0100
From: Robert Manea <rob@nova.hbx.us>
Subject: Re: Maximum length of hash key
Message-Id: <d5p7pc.h3j.ln@rob.unisolblade.de>
Segfault in module "Uri Guttman" - dump details are as follows:
[...]
> for your education benchmark them (on a large hash) and post the
> results.
Well, here it goes...
The test code:
#v+
#!/usr/bin/perl
#
use strict;
use warnings;
use Benchmark qw(:all);
our %category;
for( 1 .. 5000 ) {
my $rand_key = 'x' x (int(rand(30)) + 1);
$category{$rand_key} = 1;
}
timethese(100000, {
'Array_Indices' => sub {
my @arr;
for ( keys %category ) {$arr[length $_] = 1;}
my $longest_key_length = $#arr+1;
},
'Sorting' => sub {
my $longest_key_length =
1 + length +(sort { length $b <=> length $a } keys %category)[0];
},
'ORing' => sub {
my $longest_key_len;
$longest_key_len |=$_ foreach keys %category;
$longest_key_len = 1 + length $longest_key_len;
},
'XORing' => sub {
my $longest_key_len;
$longest_key_len ^= $_ for keys %category;
$longest_key_len = length($longest_key_len)+1;
},
'Length_compare' => sub {
my $len=0;
$len = length>$len?length:$len for keys %category;
$len++;
}
});
#v-
And the results on my machine:
Benchmark: timing 100000 iterations of Array_Indices, Length_compare, ORing, Sorting, XORing...
Array_Indices: 3 wallclock secs ( 4.38 usr + 0.01 sys = 4.39 CPU) @ 22779.04/s (n=100000)
Length_compare: 4 wallclock secs ( 3.57 usr + 0.02 sys = 3.59 CPU) @ 27855.15/s (n=100000)
ORing: 4 wallclock secs ( 3.70 usr + 0.01 sys = 3.71 CPU) @ 26954.18/s (n=100000)
Sorting: 6 wallclock secs ( 7.01 usr + 0.03 sys = 7.04 CPU) @ 14204.55/s (n=100000)
XORing: 4 wallclock secs ( 3.68 usr + 0.03 sys = 3.71 CPU) @ 26954.18/s (n=100000)
Same snippets as above and 'cmpthese':
Rate Sorting Array_Indices ORing XORing Length_compare
Sorting 14306/s -- -37% -47% -47% -49%
Array_Indices 22883/s 60% -- -15% -16% -18%
ORing 26954/s 88% 18% -- -1% -4%
XORing 27174/s 90% 19% 1% -- -3%
Length_compare 27933/s 95% 22% 4% 3% --
Quite suprisingly for me the 'Array_Indeces' method runs slower than the
'Length_compare' one which obviously the fastets.
No that surprising is the 'Sorting' case.
And again OR/XOR quite fast although the need to scan each string char by char.
(But, isn't this needed to compute the strings' length with 'length()' anyway?)
Well, all in all not quite the results I expected.
> uri
Greets, Rob
--
The Enterprise meets God, and it's a child, a computer, or a C program.
------------------------------
Date: 08 Dec 2004 21:42:01 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Maximum length of hash key
Message-Id: <slrncret99.k4s.abigail@alexandra.abigail.nl>
Uri Guttman (uri@stemsystems.com) wrote on MMMMCXVII September MCMXCIII
in <URL:news:x73bygoihz.fsf@mail.sysarch.com>:
`` >>>>> "CD" == Craig Dunn <craig@codenation.net> writes:
``
`` >> Find the longest key (most characters) and return
`` >> '$longest_key_length + 1;'.
``
`` CD> [snip]
``
`` >>
`` >> in favor over the more golfish one liner:
`` >>
`` >> my $longest_key_length =
`` >> 1 + length +(sort { length $b <=> length $a } keys %category)[0];
`` >>
``
`` CD> Or another way:
``
`` CD> my $l = (sort{$b<=>$a} map{length($_)} keys(%category))[0]+1;
``
`` ewww! O(N log N) for an O(N) problem? use List::Util::max
ewww! And create another large list? Use 'each' to iterate over the hash.
Abigail
--
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"
------------------------------
Date: Wed, 8 Dec 2004 23:06:49 +0100
From: Robert Manea <rob@nova.hbx.us>
Subject: Re: Maximum length of hash key
Message-Id: <ptt7pc.0bj.ln@rob.unisolblade.de>
Segfault in module "Robert Manea" - dump details are as follows:
> Segfault in module "Uri Guttman" - dump details are as follows:
> [...]
>> for your education benchmark them (on a large hash) and post the
>> results.
> Well, here it goes...
> The test code:
> #!/usr/bin/perl
> #
> use strict;
> use warnings;
> use Benchmark qw(:all);
> our %category;
> for( 1 .. 5000 ) {
> my $rand_key = 'x' x (int(rand(30)) + 1);
> $category{$rand_key} = 1;
> }
General brains overload. Please use this instead of the (sensless) above
code:
our %category;
my $cnt;
for( 0 .. 1000 ) {
my $rand_key = $cnt++ . 'x' x (int(rand(30)) + 1);
$category{$rand_key} = 1;
}
[...]
> And the results on my machine:
[ Now only 5000 iterations have been made ]
Benchmark: timing 5000 iterations of Array_Indices, Length_compare, ORing, Sorting, XORing...
Array_Indices: 7 wallclock secs ( 6.25 usr + 0.05 sys = 6.30 CPU) @ 793.65/s (n=5000)
Length_compare: 6 wallclock secs ( 5.33 usr + 0.03 sys = 5.36 CPU) @ 932.84/s (n=5000)
ORing: 7 wallclock secs ( 5.80 usr + 0.04 sys = 5.84 CPU) @ 856.16/s (n=5000)
Sorting: 24 wallclock secs (22.79 usr + 0.14 sys = 22.93 CPU) @ 218.05/s (n=5000)
XORing: 6 wallclock secs ( 5.73 usr + 0.03 sys = 5.76 CPU) @ 868.06/s (n=5000)
> Same snippets as above and 'cmpthese':
Rate Sorting XORing Array_Indices ORing Length_compare
Sorting 219/s -- -75% -75% -75% -76%
XORing 864/s 294% -- -1% -2% -7%
Array_Indices 873/s 298% 1% -- -1% -6%
ORing 877/s 301% 2% 1% -- -6%
Length_compare 931/s 325% 8% 7% 6% --
> Greets, Rob
Greets, Rob
--
The Enterprise meets God, and it's a child, a computer, or a C program.
------------------------------
Date: 8 Dec 2004 11:59:05 -0800
From: "James" <djcameron60616@yahoo.com>
Subject: MS Perl question -- how to use hacked script to work correctly(was Question on loops and return values or sumpin)
Message-Id: <1102535945.679552.290720@z14g2000cwz.googlegroups.com>
First off, thanks to all who replied to my original post, I will go
back and reply to each of you .. thank you for your time.
And to everyone else now here, thank you for your time.
I have altered a couple scripts to work in IndigoPerl and
Win32::Resources to accomplish a simple task - read in a list of
servers from a text file, query them for their drives and space on the
drives, and put all the information on space out to a second text file,
space delimited.
My questions are before the code:
The important question is this: How to get an array of drive letters in
use in a foreach loop, and associating that with a hash variable
returning strings.
Example: GetDrives expects a string or empty list, and with the
empty list a foreach loop spits out all drive letters.
Example: In using GetDriveSpace, it returns only the values for C:\
(or whatever ("x:\\") letter you feed it.
So the question is how to get this function (GetDriveSpace) to be
passed an array, essentially - is this impossible potentially because
of the module design? Resources.pm is the module used with this
script. ShowKeys is what returns total, used and free space -- so this
is a third factor in manipulating this array.
I'm really trying to get the values for used, total and free space -
and I'm not quite sure how to get at it, and this is already taking too
long for me to figure out.
Here is the code:
use lib "$ENV(HOME)/site/lib";
no lib ".";
use Win32::Resources;
use Win32API::Resources;
# use strict;
# use warnings;
my @Drives = Win32API::Resources::GetDrives();
my %DRVSpace = Win32API::Resources::GetDriveSpace("C:\\");
my $pathtofiles = "\\C:\\scripts\\";
my $pathtoserverslist = "\\\\xxxxxnnnnnn\\";
my $Threshold = "80";
my $last_updated = localtime (time);
my $GB = 1073741824;
open(HANDLE1,"machines.txt") || die "open: $!";
open(HANDLE2,">>growth.txt") || die "open: $!";
print "\n\nLast run: $last_updated\n";
print "The following are valid disk drives: @Drives\n";
while ($Driveinfo=<HANDLE1>)
{
chomp($Driveinfo);
# @Drivearray=split (/[\\+]/, $Driveinfo);
# ($Total, $Free) = Win32API::Resources::GetDriveSpace
("\\\\$Driveinfo\\");
my $Total = 15073741824;
my $Free = 12073741824;
if ($Total gt 0) # if ($Total)
{
$Growth = ($Total-$Free) / $GB;
$Utilpercentage = ($Total-$Free) * 100 / $Total;
$Total1 = $Total / $GB;
$Free1 = $Free / $GB;
$Used1 = ($Total-$Free) / $GB;
$Total1 = sprintf("%5.2f\n", "$Total1");
$Free1 = sprintf("%5.2f\n", "$Free1");
$Used1 = sprintf("%5.2f\n", "$Used1");
$Utilpercentage = sprintf("%5.2f\n", "$Utilpercentage");
iscritical();
# Writing out the result set for this server\\share combo.
# print HANDLE2 "@Drivearray[0], @Drivearray[2], $Utilpercentage,
$Free1, $Used1,
$Total1 ";
# If the $Total was empty then "N/A" is put in the fields
}
else
{
$Total1 ="N/A";
$Free1 = "N/A";
$Used1 = "N/A";
$Utilpercentage = "N/A";
print HANDLE2 "$Total $Free1 $Used1 $Utilpercentage $Growth\n";
}
printstats();
skey();
}
close(HANDLE1) || die "close0: $!";
close(HANDLE2) || die "close0: $!";
sub iscritical()
{
if ($Utilpercentage >=$Threshold)
{
print "!!Utilized percentage greater than threshold level!!\n";
}
else # non-critical level
{
print "Utilized percentage less than threshold level!\n";
}
}
sub printstats()
{
$T1 = sprintf("%5.2f","$Total1");
$T2 = sprintf("%5.2f","$Free1");
$T3 = sprintf("%5.2f","$Used1");
$T4 = sprintf("%5.2f","$Utilpercentage");
$T5 = sprintf("%5.2f","$Growth");
print "\n\t\t\tUtilized\tGrowth\n";
print "Total:\tFree:\tUsed:\tPercentage:\tRate:\n";
print "$T1\t$T2\t$T3\t $T4\t $T5\n";
print HANDLE2 "$T1 $T2 $T3 $T4 $T5\n";
}
sub skey()
{
my $num_keys = keys %DRVSpace;
print "\n\nNumber of keys in DRVSpace: $num_keys\n";
foreach $let (@Drives)
{
Win32API::Resources::ShowKeys("Drive Space:", 1, \%DRVSpace);
}
}
Thanks to all for their responses and time .. even if it takes me a
while to respond.
------------------------------
Date: Wed, 08 Dec 2004 21:17:26 GMT
From: Jim Keenan <jkeen_via_google@yahoo.com>
Subject: Re: New comp.lang.perl.misc mirror site at lampforums.org
Message-Id: <GbKtd.45$ag6.21@trndny07>
Abigail wrote:
> It has to be said that the "retronym" 'Practical Extraction and Report
> Language' existed before Larry released version 1.0, as the manual page
> for perl1 uses 'Practical Extraction and Report Language' to explain
> the name perl:
>
> $ nroff -man perl-1.0.0/perl.man.1 | head -6 | tail -2
> NAME
> perl - Practical Extraction and Report Language
>
Thanks, Abigail. And thanks to the OP for already correcting it on
lampforums -- and for setting up this mirror in the first place. I'll
probably give it a look-see, especially since I find the new Google
Groups interface to our lists to be rather annoying.
jimk
------------------------------
Date: 8 Dec 2004 12:04:24 -0800
From: "James" <djcameron60616@yahoo.com>
Subject: Re: Question on loops and return values
Message-Id: <1102536264.382858.119980@c13g2000cwb.googlegroups.com>
Hi Jim,
Sorry to you and all other posters for my general usenet "Blurting". I
guess what I was dumping the code here for was in light of lacking the
ability to express the problem in theory. What is in general the
problem is maniipulating input and output through module functions,
namely Win32::Resources(GetDrives(), GetDriveSpace(), and ShowKeys()).
This was in fact a 'hacked' script, I was trying to use code originally
useful but directed toward tailor-made for my purposes. I will respond
more in-depth tonight.
Thanks again.
James
------------------------------
Date: 8 Dec 2004 12:22:16 -0800
From: "James" <djcameron60616@yahoo.com>
Subject: Re: Question on loops and return values
Message-Id: <1102537336.432972.205820@c13g2000cwb.googlegroups.com>
It was .. for some reason I had the misguided idea that each math
expression had to be in an eval. I don't know why.
------------------------------
Date: Wed, 8 Dec 2004 12:34:00 -0900
From: "Gerald Newton3" <electrician@nospam.com>
Subject: Seeking Internet Protection Service
Message-Id: <41b77349$1@news.acsalaska.net>
I am willing to pay $3,000 per year for an Internet Protection Service.
What is IPS?
It is a service to protect me from slanderous posts at newsgroups and
spamming at my BB.
Yes, I am willing to pay this price.
I simply do not have the time to trace down these culprits and stop them
Does anyone have this service? Or do you know of this service?
I am sure there are many that would pay for this Protection if it is not
already available!
------------------------------
Date: 8 Dec 2004 11:43:37 -0800
From: dbmeyers23@yahoo.com
Subject: Web Form search and open pdf
Message-Id: <1102535017.156092.22810@c13g2000cwb.googlegroups.com>
All,
I'm trying to create a "simple" web-based application that will allow
users to search for pdf files, and when the files exist, the browser
opens the .pdf in the browser. I can get the form to find the .pdf
and open it on a PC, but the filename is still the name of the ".cgi"
script.
I also cannot get my basic version to work on the Macintosh platform.
I've scoured the web for answers, and have pieced together some code
from different sources, but I'm missing two crucial pieces....having
the file show up with the real name (not script.cgi) and getting this
to work on Macintosh OS9 browsers(file is corrupted).
Here's my code:
#!/usr/bin/perl -wT
###########################Find pdf ads based on user submission
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);
use strict;
my $files_location;
my $ID;
my @fileholder;
$files_location = "/usr/local/apache2/pdfads";
$ID = param('pdfname');
if ($ID eq '') {
print "Content-type: text/html\n\n";
print "You must specify a file to download.<br>";
print "<br>";
print "<form name=pdf method=post action=../cgi-bin/download.cgi>";
print "New pdf search<br>";
print "<br>";
print "<table>";
print "<tr><td><b>Ad Number:</b><input type=text maxlength=30
name=pdfname size=20></td></tr>";
print "</table>";
print "<input type=submit name=Submit value=View PDF size=15>";
print "</form>";
exit;
}
if (-e "$files_location/$ID")
{
open(DLFILE, "<$files_location/$ID") || die ("Cannot open PDF ad $ID,
try again.<br>");
@fileholder = <DLFILE>;
close (DLFILE) || Error ('close', 'file');
###print "Content-Type:application/x-download\n";
print "Content-Type:application/pdf\n";
print "Content-Disposition:inline; filename=$ID\n\n";
print @fileholder
}
print "Content-type: text/html\n\n";
print "Cannot find PDF Ad $ID, please try again<br>";
print "<form name=pdf method=post action=../cgi-bin/download.cgi>";
print "<br>";
print "<table>";
print "<tr><td><b>Ad Number:</b><input type=text maxlength=30
name=pdfname size=20></td></tr>";
print "</table>";
print "<input type=submit name=Submit value=View PDF size=15>";
print "</form>";
exit;
------------------------------
Date: Wed, 08 Dec 2004 20:15:46 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Web Form search and open pdf
Message-Id: <ShJtd.45$sU4.40@trndny01>
<dbmeyers23@yahoo.com> wrote in message
news:1102535017.156092.22810@c13g2000cwb.googlegroups.com...
> All,
>
> I'm trying to create a "simple" web-based application that will allow
> users to search for pdf files, and when the files exist, the browser
> opens the .pdf in the browser. I can get the form to find the .pdf
> and open it on a PC, but the filename is still the name of the ".cgi"
> script.
>
> I also cannot get my basic version to work on the Macintosh platform.
>
> I've scoured the web for answers, and have pieced together some code
> from different sources, but I'm missing two crucial pieces....having
> the file show up with the real name (not script.cgi) and getting this
> to work on Macintosh OS9 browsers(file is corrupted).
If you just want the PDF displayed in the User's browser's location bar,
then you should have your CGI program redirect to the PDF, rather than
print the contents of the PDF.
http://search.cpan.org/~lds/CGI.pm-3.05/CGI.pm#GENERATING_A_REDIRECTION_HEADER
Paul Lalli
------------------------------
Date: Wed, 08 Dec 2004 14:52:51 -0700
From: Eric Schwartz <emschwar@fc.hp.com>
Subject: Re: Web Form search and open pdf
Message-Id: <eto3bygihjg.fsf@wilson.emschwar>
"Paul Lalli" <mritty@gmail.com> writes:
> If you just want the PDF displayed in the User's browser's location bar,
> then you should have your CGI program redirect to the PDF, rather than
> print the contents of the PDF.
That only works if the PDFs are under the webserver's document root,
and there are many good reasons you may not want to do that. If
that's not the case, then you do need to use your CGI program to print
it to the browser. In which case to set the name, I have always found
setting the filename in the MIME Content-Disposition header to do the
trick. This might look like (untested);
#!/usr/bin/perl
use warnings;
use strict;
use CGI;
use File::Basename;
my $pdfpath = '/path/to/filename.pdf'
open my $pdf, '<', $pdfpath or die "Can't open $pdfpath: $!";
print header(-type => 'application/pdf',
-content_disposition => 'inline; filename='.basename($pdfpath));
print while (<$pdf>);
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: 8 Dec 2004 12:48:42 -0800
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: why the following HereDoc print don't work?
Message-Id: <1102538922.266321.214570@z14g2000cwz.googlegroups.com>
Andrew Hamm wrote:
>
> showing real code might be difficult - many
> news readers seem to rip out leading tabs and
> spaces when you make a posting. From your
> lack of indentation, either you are a messy
> programmer, or the newsreader you use has
> modified your message.
I know for a fact that Google Groups strips out all indentations as
of this last weekend. Of course, this is bad for me because I can no
longer post properly-indented code. Honestly, I don't see a single
good reason to strip out leading white-space that the poster explicitly
put in. (I've submitted this feedback, but it's unclear whether Google
will do anything about it.)
In the meantime, if anyone knows how to preserve indentations using
Google Groups, please let me know. Otherwise, the code that I post
will look like this:
sub printHelloWorldNTimes
{
my $num = shift;
for (1 .. $num)
{
print "Hello, World!\n";
}
}
Thanks.
------------------------------
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 V10 Issue 7497
***************************************