[17464] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4884 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 14 09:05:47 2000

Date: Tue, 14 Nov 2000 06:05:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <974210712-v9-i4884@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 14 Nov 2000     Volume: 9 Number: 4884

Today's topics:
    Re: activeperl: reading registry <mmthoma@attglobal.net>
        re: CR LF to <br> in REGEX <19wlr@globalnet.co.uk>
    Re: CR LF to <br> in REGEX <geoff-at-farmline-dot-com@127.0.0.1>
    Re: creating an error log help (Martien Verbruggen)
    Re: Does  sub foo { 'A'..'Z' }  return a list? <wyzelli@yahoo.com>
    Re: Does  sub foo { 'A'..'Z' }  return a list? <kstep@pepsdesign.com>
    Re: Does  sub foo { 'A'..'Z' }  return a list? (Martien Verbruggen)
    Re: Does  sub foo { 'A'..'Z' }  return a list? (Martien Verbruggen)
    Re: Does  sub foo { 'A'..'Z' }  return a list? <joe+usenet@sunstarsys.com>
        getting the real virtual host <newsgroups@mail.ru>
    Re: Help with HTML::Parser module <eliseo@cocoon.ulpgc.es>
    Re: Help with HTML::Parser module <eliseo@cocoon.ulpgc.es>
    Re: HTML download form - CGI/Perl <kstep@pepsdesign.com>
    Re: HTML download form - CGI/Perl (dionysus)
    Re: HTML download form - CGI/Perl (Gwyn Judd)
    Re: IP geography (Martien Verbruggen)
    Re: Looking for idiom for getting value from @ARGV, or  <bart.lateur@skynet.be>
        Message Queue stuff <vidulats@yahoo.co.uk>
    Re: Message Queue stuff (Anno Siegel)
    Re: Message Queue stuff <geoff-at-farmline-dot-com@127.0.0.1>
        net::telnet question menorevs@my-deja.com
    Re: net::telnet question (Martien Verbruggen)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 14 Nov 2000 05:00:31 -0800
From: Marshall Thomas <mmthoma@attglobal.net>
To: EM <me@privacy.net>
Subject: Re: activeperl: reading registry
Message-Id: <3A11376F.2044C0A4@attglobal.net>

EM wrote:
> 
> i have windows me with activeperl installed
> is there a way to read/write a key from the windows registry?
> 
> thanks in advance

Since you are running in the Winbloze environment, you should
check out the Active State port - www.activestate.com

You want the Win32::TieRegistry module.

something like this should work fine:

my $Registry;
use Win32::TieRegistry 0.20 (
        TiedRef => \$Registry, Delimiter => "/", ArrayValues => 0,
        SplitMultis => 1, AllowLoad => 1, AllowSave => 1,
        qw ( REG_SZ REG_EXPAND_SZ REG_DWORD REG_BINARY REG_MULTI_SZ
           KEY_READ KEY_WRITE KEY_ALL_ACCESS ),
);
my $somevariable;
#a read of a string value is like this:
unless ($somevariable) =
$Registry->{"HKEY_LOCAL_MACHINE/blah/blah//subkey"})
          {do what you want if the key doesn't exit};

#a write of a string value is like this:
$Registry->{"HKEY_LOCAL_MACHINE/blah/blah//subkey"}="$somevariable"
         || some_error_routine();

reading and writing dwords is more tricky. The HTML documentation for
TieRegistry is something like 30 pages. This subject can get really
complicated. You've got a start here.

Good Luck,
/Marshall


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

Date: Tue, 14 Nov 2000 11:49:04 -0000
From: "John Plaxton" <19wlr@globalnet.co.uk>
Subject: re: CR LF to <br> in REGEX
Message-Id: <8ur8tf$a9$1@gxsn.com>

Hi there,

I'm just off to the dentist and wondered If anyone could help stop the pain
before I get back!

$text=~ s/CR LF/<br>/g;

I want to display text from a Mysql Text field in a table, but I am loosing
the CR LFs. Can anyone help with the above REGEX. I'm new to all this. I've
got this far with my book!! I'm tryingto replace CR
LF with <br>. Is this correct?

Thanks in advance, and wish me luck at the dentist.







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

Date: Tue, 14 Nov 2000 12:08:36 -0000
From: "Geoff Winkless" <geoff-at-farmline-dot-com@127.0.0.1>
Subject: Re: CR LF to <br> in REGEX
Message-Id: <8ur9sh$j2r$1@soap.pipex.net>

"John Plaxton" <19wlr@globalnet.co.uk> wrote in message
news:8ur8tf$a9$1@gxsn.com...
> $text=~ s/CR LF/<br>/g;
>
> I want to display text from a Mysql Text field in a table, but I am
loosing
> the CR LFs. Can anyone help with the above REGEX. I'm new to all this.
I've
> got this far with my book!! I'm tryingto replace CR
> LF with <br>. Is this correct?

Try

$text=~s/\n/<br>\n/g;

Same as in C, \n is the newline.

> Thanks in advance, and wish me luck at the dentist.

Heh. Hope it doesn't hurt too much.

Geoff




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

Date: Tue, 14 Nov 2000 22:26:26 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: creating an error log help
Message-Id: <slrn9128b2.gs3.mgjv@martien.heliotrope.home>

On Mon, 13 Nov 2000 17:41:00 GMT,
    menorevs@my-deja.com <menorevs@my-deja.com> wrote:
>  creating a Telnet session to be able to change a password for over
> 200 routers, the only trouble i am having is that i can not create an
> error log. So far i have:

Since you also sent me a private email with this question, I hunted down
the article here. I'm not a private help desk, but I have fewer problems
posting to Usenet. 

> open SUCCESSFILE, ">>C:\\routerSuccess.txt";
> open FAILUREFILE, ">>C:\\routerFailure.txt";
> 
> 
>  if ()

In your email you stated that you didn't know what the condition is you
need to test for. The problem is that we don't know either. Somewhere
earlier in this program, you used Net::Telnet. How you did that, we
don't know. The documentation for Net::Telnet will tell you that there
are several ways to deal with errors in the module.

However, errors in the remote commands are a different thing altogether.
If you were telneting to a Unix host, I'd say that you should print out
$? on the host shell after a command, and see what that does. On the
case of Cisco's IOS I really don't know. I suspect that on successfully
changing a password it'll print something, and on failure it'll print
something else.

Capture the output of the exchange. Compare it to something you expect.
If it doesn't compare correctly, exit with an error. Write a sub that
looks something like:

sub log_error
{
    local (*ERROR);
    open ERROR, ">>C:/routerlog/error" or 
        warn("Cannot append to error log"), return;
    print ERROR @_;
}

And set your loop up something like:

foreach my $router (@routers)
{
    # Do the telnet thang
    
    # Attempt to change password
    if ($expected_response ne $actual_response)
    {
        log_error("Couldn't change pass on $router: ",
            "Got response '$actual_response'\n");
        next;
    }
    else
    {
        log_success("Changed pass on $router");
    }
    # Cleanup, close, quit, whatever
}

If you need igh speed, you might want to open the files once, instead of
for each log line.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | In the fight between you and the
Commercial Dynamics Pty. Ltd.   | world, back the world - Franz Kafka
NSW, Australia                  | 


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

Date: Tue, 14 Nov 2000 18:29:38 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Does  sub foo { 'A'..'Z' }  return a list?
Message-Id: <s57Q5.3$YO.808@vic.nntp.telstra.net>

"John Lin" <johnlin@chttl.com.tw> wrote in message
news:8uqn3m$459@netnews.hinet.net...
>
> Q3: How can we test to see whether it will return a list or not?
>
> Thank you.
>
> John Lin
>
> P.S.  Hey, I just did a test:
>
>     sub foo { 'A'..'Z' }
>     print scalar foo;
>
> Guess what the result is?  26?  'Z'?  or  1?  0?
> Could someone explain why the result is like this?

Maybe this might help to demonstrate that it returns a list:

sub foo {'A'..'Z'}
@array = foo;
print @array,"\n";
print scalar @array;


You can assign a list to an array and then print the array itself or the
array in scalar context, but you cannot print a list in scalar context,
since a list in scalar context makes little sense, whilst an array in
scalar context does.

@array = ('A'..'Z');
print @array,"\n";
print scalar ('A'..'Z'); #nobody home

Naturally you can also print the list directly.

print ('A'..'Z');

Or even with the sub,

sub foo {'A'..'Z'}
print foo;

Hope that helps.

Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass
it around');
for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
$_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";






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

Date: Tue, 14 Nov 2000 07:08:37 -0500
From: "Kurt Stephens" <kstep@pepsdesign.com>
Subject: Re: Does  sub foo { 'A'..'Z' }  return a list?
Message-Id: <8ur9vt$thh$1@slb1.atl.mindspring.net>

"John Lin" <johnlin@chttl.com.tw> wrote in message
news:8uqn3m$459@netnews.hinet.net...

> P.S.  Hey, I just did a test:
>
>     sub foo { 'A'..'Z' }
>     print scalar foo;
>
> Guess what the result is?  26?  'Z'?  or  1?  0?
> Could someone explain why the result is like this?

If you read the section on the range operator in perlop you will get an
explanation for this 'strange' behavior.  In a scalar context, the range
operator returns a boolean value, which prints as a blank string.  This is
to support 'sed' like features, but since I've never used sed, I don't know
what they're talking about.






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

Date: Tue, 14 Nov 2000 23:22:29 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Does  sub foo { 'A'..'Z' }  return a list?
Message-Id: <slrn912bk5.gs3.mgjv@martien.heliotrope.home>

On Tue, 14 Nov 2000 14:42:49 +0800,
	John Lin <johnlin@chttl.com.tw> wrote:
> Dear all,
> 
> Q1: Is it possible to write the following pieces of code in
> one statement (so we can save two variables $begin,$end).
> 
>     my ($begin,$end) = $object->iterate;
>     print $object->get($_) for $begin..$end;

Yes.

> Q2: My original version was like:

[snip]

> Actually, will the range operator sub return a list?  Even if it is
> in a scalar context?

No. When it's in scalar context, it is no longer the range operator.

> Q3: How can we test to see whether it will return a list or not?

And the answer:

> P.S.  Hey, I just did a test:
> 
>     sub foo { 'A'..'Z' }
>     print scalar foo;
> 
> Guess what the result is?  26?  'Z'?  or  1?  0?
> Could someone explain why the result is like this?

The result is an empty string.

# man perlop
[snip]
       Binary ".." is the range operator, which is really two
       different operators depending on the context.  In list
       context, it returns an array of values counting (up by
       ones) from the left value to the right value.
[snip]
       In scalar context, ".." returns a boolean value.  The
       operator is bistable, like a flip-flop, and emulates the
       line-range (comma) operator of sed, awk, and various edi­
       tors.  Each ".." operator maintains its own boolean state.
       It is false as long as its left operand is false.  Once
       the left operand is true, the range operator stays true
       until the right operand is true, AFTER which the range
       operator becomes false again.
[snip]
                                                     The value
       returned is either the empty string for false, or a
       sequence number (beginning with 1) for true.
[snip]
                                                  If either
       operand of scalar ".." is a constant expression, that
       operand is implicitly compared to the `$.' variable, the
       current line number. 


The scalar context propagates into the subroutine, putting the flipflop
in a scalar context. This means it will work as described above. It will
return false, since $. is not equal to 'A'. So, it returns "", the empty
string.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | In the fight between you and the
Commercial Dynamics Pty. Ltd.   | world, back the world - Franz Kafka
NSW, Australia                  | 


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

Date: Tue, 14 Nov 2000 23:30:04 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Does  sub foo { 'A'..'Z' }  return a list?
Message-Id: <slrn912c2c.gs3.mgjv@martien.heliotrope.home>

On Tue, 14 Nov 2000 07:08:37 -0500,
	Kurt Stephens <kstep@pepsdesign.com> wrote:
>                                           In a scalar context, the range
> operator returns a boolean value, which prints as a blank string.  This is
> to support 'sed' like features, but since I've never used sed, I don't know
> what they're talking about.

Look at the examples :) They speak louder than the preceding paragraphs.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Failure is not an option. It comes
Commercial Dynamics Pty. Ltd.   | bundled with your Microsoft product.
NSW, Australia                  | 


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

Date: 14 Nov 2000 08:38:48 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Does  sub foo { 'A'..'Z' }  return a list?
Message-Id: <m3y9ymr7vb.fsf@mumonkan.sunstarsys.com>

mgjv@tradingpost.com.au (Martien Verbruggen) writes:

>                                                   If either
>        operand of scalar ".." is a constant expression, that
>        operand is implicitly compared to the `$.' variable, the
>        current line number. 
> 
> 
> The scalar context propagates into the subroutine, putting the flipflop
> in a scalar context. This means it will work as described above. It will
> return false, since $. is not equal to 'A'. So, it returns "", the empty
> string.
> 

Grrr...

and yet not a single mention of the damned thing in perldoc -f readline.

-- 
Joe Schaefer


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

Date: Tue, 14 Nov 2000 16:51:57 +0300
From: "Steve" <newsgroups@mail.ru>
Subject: getting the real virtual host
Message-Id: <8urfub$uc3$1@storm.comstar.ru>

I have a script which does different things depending on which domain the
user has accessed.
I've done this using virtual_host(), which is the same as $ENV{'HTTP_HOST'}.
The problem is that this relies on the browser putting the correct value in
the Host: header, and a significant number of browsers (/hackers/robots) do
not.
Is there any way of getting the real host that the user requested in order
to end up at my page?





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

Date: 14 Nov 2000 09:42:13 -0100
From: Juan Eliseo Carrasco =?iso-8859-1?Q?D=EDaz?= <eliseo@cocoon.ulpgc.es>
To: Niklas Frykholm <r2d2@shaka.acc.umu.se>
Subject: Re: Help with HTML::Parser module
Message-Id: <3A110962.2DED8144@cocoon.ulpgc.es>

 Your package and script seems to be OK but only two things:

 - I have some html pages with I get the next error:

    Can't locate object method "_declaration" via package "FontDelete" at
/usr/lib/perl5/site_perl/5.005/i386-linux/HTML/Transform.pm line 220.

 - With lines like: <font face="Arial, Times New Roman">0</font> ,it cut all (the
zero too)


Niklas Frykholm wrote:

> In article <3A094BCF.2020E154@cocoon.ulpgc.es>, Juan Eliseo Carrasco Díaz wrote:
> >I trying to delete all the <font face="Arial"> and <font face="Times new
> >roman"> marks and its respective </font> marks of my HTML pages, but I
> >can't find an easy way.
>
> This is one of the things that are easy to do with my HTML::Transform package.
> The following script takes care of the problem, and also correctly handles
> font-tags with more than one attribute, i e
>
>         <font face=arial color=red>
>
> is converted to
>
>         <font color=red>
>
> ---
> use HTML::Transform;
>
> package FontDelete;
> @FontDelete::ISA = qw(Transform);
>
> sub font {
>         my ($self, $text, $attr) = @_;
>         if ($attr->{face} =~ /arial/i ||
>                 $attr->{face} =~ /times\s*new\s*roman/i) {
>                 delete $attr->{face};
>         }
>         if (%$attr)
>                 {$self->make_tag("FONT", $attr).$text."</FONT>"}
>         else
>                 {$text}
> }
>
> print FontDelete->parse("test.html");
> ---
>
> I haven't released HTML::Transform on CPAN yet (want to make some last tweaks,
> if you have any feedback I'll be happy), you can download it at
>
>         http://www.acc.umu.se/~r2d2/files/Perl/html_transform/index.html
>
> // Niklas



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

Date: 14 Nov 2000 10:38:25 -0100
From: Juan Eliseo Carrasco =?iso-8859-1?Q?D=EDaz?= <eliseo@cocoon.ulpgc.es>
Subject: Re: Help with HTML::Parser module
Message-Id: <3A111691.B1530C08@cocoon.ulpgc.es>

After all, I think I got it. The next script work fine (without any module
an package), but it is slow.

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

undef $/;
$_=<STDIN>;

@abrefont=m#<font#gsi;
@cierrafont=m#</font#gsi;
if(scalar(@abrefont)!=scalar(@cierrafont))
{
die("The number of <font... and </font> are differents\n")
}

$x=0;
while (m#<font\s+?face.+?>#gsi)
{
 while (m#(<font.+?>)|(</font\s*>)#gsi)
 {
  if($1)
  {
  $x++
  }
  elsif($x>0)
     {
     $x--
     }
     else
     {
     $_=$`.$';
     s#<font\s+?face.+?>##si;
     last
     }
 }
}
print
----



Juan Eliseo Carrasco Díaz wrote:

> I trying to delete all the <font face="Arial"> and <font face="Times new
>
> roman"> marks and its respective </font> marks of my HTML pages, but I
> can't find an easy way.
>
> Example:
>
> Text .... <font face="Arial"> more text .... <b> xxx </b> ....
> .... <font size=+1> .... </font> ....
> <font face="Times new roman"> <font color=red> .... </font> ...
> .... </font> .... </font>
>
> Desired result:
>
> Text .... more text .... <b> xxx </b> ....
> .... <font size=+1> .... </font> ....
> <font color=red> .... </font> ...
> ....  ....
>
> Somebody say me that HTML::Parse module can help me. I downloaded it. I
> read the documentation, but I don't know how to start. (I'm a beginner).



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

Date: Tue, 14 Nov 2000 03:41:45 -0500
From: "Kurt Stephens" <kstep@pepsdesign.com>
Subject: Re: HTML download form - CGI/Perl
Message-Id: <8uqts3$sod$1@nntp9.atl.mindspring.net>

Whoa - hold your horses!

"dionysus" <dionysus39@hotmail.com> wrote in message
news:3a10a0d6.111690646@nntp.unsw.edu.au...
> Since apparently noone in the world can help me with my win9x
> passthrough query (probably not all that surprising, since when I went
> looking for a package allowing me to use perl to access my win9x
> TCP/IP LAN a while ago I found nothing), I am changing my approach. I
> now need to know if it is possible to use a CGI/Perl script containing
> a HTML form to setup a download to the client. The idea is that the
> client looks up the site and chooses a resource, and the script sets
> up the download (presumably using the socket function somehow?) of the
> file(s), which are stored somewhere on my machine (not necessarily
> under the webserver's directory, and not at a location that can be
> aliased, so using the script to print hyperlinks will not work), and
> then performs some other stuff after the download is complete. I
> assume I would just read the file into an array in the usual fashion,
> but I have no idea how to create a file descriptor that is linked to a
> socket going to the client's machine....
>
> any help much appreciated,

Why bother with sockets when you have one open already?  By its very nature,
a CGI connection already has a socket open on port 80 (or whatever other
port your web server uses).  All you need to do is write to it, and since
CGI directs STDOUT over this connection, that just means 'print'.

The secret to providing a file download via CGI is to tell the browser what
kind of file it is receiving, so that it knows to prompt the user to save it
to disk rather than trying to display it itself.  This is done using the
Content-type field of the HTTP header.  You can find a list of registered
media types at the following location.

http://www.isi.edu/in-notes/iana/assignments/media-types/

Note that Windows has it's own ideas about MIME types; for the example below
I will use a ZIP file with the content type 'application/x-zip-compressed'.
The same technique is used for sending images (image/jpeg) or audio files
(audio/wav), etc.  Consult the FAQs for HTTP and CGI before trying anything
for real.

<< Code follows >>

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

use CGI::Carp qw(fatalsToBrowser);

my $infile = 'C:\TEMP\testfile.zip';

# Open the input file for reading
open IN, "< $infile"
    or die "Can't open $infile: $!";

binmode IN;

# Get the file info
my @info = stat(IN);
my $length = $info[7];
my $blksize = $info[11] || 16384;

# Make sure that the output is written in
# binary mode and buffered
binmode STDOUT;
select STDOUT; $|=1;

# Send the HTTP header
print "200 OK\n";
print "Content-type: application/x-zip-compressed\n";
print "Content-Length: $length\n";
print "\n";

# Read each chunk of the input file
# and pass it to the browser
my $buffer;
while (!eof(IN)) {
    read(IN, $buffer, $blksize);
    print $buffer;
}

close IN;
exit 0;

<< End Code >>

> ------------------------------------------------------------
> "One World, one Web, one Program" - Microsoft promotional ad
> "Ein Volk, ein Reich, ein Fuhrer" - Adolf Hitler .

Maybe that's why the new MSN ad starts out with a field full of sheep....

Kurt Stephens
Pepsdesign





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

Date: Tue, 14 Nov 2000 11:10:39 GMT
From: dionysus39@hotmail.com (dionysus)
Subject: Re: HTML download form - CGI/Perl
Message-Id: <3a1115fc.23769326@nntp.unsw.edu.au>

<snip>>
>Why bother with sockets when you have one open already?  By its very nature,
>a CGI connection already has a socket open on port 80 (or whatever other
>port your web server uses).  All you need to do is write to it, and since
>CGI directs STDOUT over this connection, that just means 'print'.
uhhh...oops....realised this about 30min after making that post...up
until that point the only CGI scripts I had done had used a perl
function to return a text/html header, and that line of code was so
unobtrusive I had not even noticed it (it came from a skeleton script)
and realised that it could be changed......ok, so that would be an
easier way....however, even with a script set up to read in a file
(code below) I run into problems.


use CGI qw/:all/;
print "Content-type: application/x-zip-compressed\n\n";
open (IN, "c:\\setups\\server stuff\\tinyweb web server.zip") or print
"can't open music file\n";
while (sysread IN, $store, 512) {
	print $store;
	}
close IN;


Problem 1 (major). - if I use this, the client is prompted to download
a file. Great. But, when they do go to download the file, they recieve
around 200bytes of data. Opening the destination file in Notepad
reveals that they received the same few bytes that are displayed on
the screen if you attempt type "more tinywe~1.zip" at the dos prompt,
where "tiny web server.zip" was the 72Kb file I was using for the
test. I assume that is because sysread() is reading the file in the
same (text-oriented?) way that more reads files...(as more will read
the entirity of any text file I parse it, but only the first few lines
of any binary file)....

Problem 2 (minor). - when the user is prompted to download the file,
the default filename is not "tiny web server.zip" or "tinywe~1.zip",
but "ftest.zip" - where ftest.pl is the name of the perl/cgi
script....

I am not sure exactly what is happening here...perhaps there is
another function to read from files in another fashion? Anyhow, thanks
for your help, in any case....I tried your code below, but IE gives me
a blank doc when I try it, and netscape claims the document has no
data.....I attempted to work out where it was going wrong by
commenting out stuff like Binmode that would correct the output but
not produce it, and still no dice....I trimmed it down to the
following:

use strict;
use warnings;
use CGI qw/:all/;
open(IN, "< c:\\setups\\server stuff\\tinyweb web server.zip")
	or die "Can't open infile: $!";
my @info = stat(IN);
my $length = $info[7];
my $blksize = $info[11] || 16384;
print "Content-type: application/x-zip-compressed\n\n";
my $buffer;
while (!eof(IN)) {
    read(IN, $buffer, $blksize);
    print $buffer;
}
close IN;
exit 0;

which, to my mind, should at least return something....but no,
nothing....
-d

>
>The secret to providing a file download via CGI is to tell the browser what
>kind of file it is receiving, so that it knows to prompt the user to save it
>to disk rather than trying to display it itself.  This is done using the
>Content-type field of the HTTP header.  You can find a list of registered
>media types at the following location.
>
>http://www.isi.edu/in-notes/iana/assignments/media-types/
>
>Note that Windows has it's own ideas about MIME types; for the example below
>I will use a ZIP file with the content type 'application/x-zip-compressed'.
>The same technique is used for sending images (image/jpeg) or audio files
>(audio/wav), etc.  Consult the FAQs for HTTP and CGI before trying anything
>for real.
>
><< Code follows >>
>
>#!/usr/bin/perl -w
>use strict;
>use warnings;
>
>use CGI::Carp qw(fatalsToBrowser);
>
>my $infile = 'C:\TEMP\testfile.zip';
>
># Open the input file for reading
>open IN, "< $infile"
>    or die "Can't open $infile: $!";
>
>binmode IN;
>
># Get the file info
>my @info = stat(IN);
>my $length = $info[7];
>my $blksize = $info[11] || 16384;
>
># Make sure that the output is written in
># binary mode and buffered
>binmode STDOUT;
>select STDOUT; $|=1;
>
># Send the HTTP header
>print "200 OK\n";
>print "Content-type: application/x-zip-compressed\n";
>print "Content-Length: $length\n";
>print "\n";
>
># Read each chunk of the input file
># and pass it to the browser
>my $buffer;
>while (!eof(IN)) {
>    read(IN, $buffer, $blksize);
>    print $buffer;
>}
>
>close IN;
>exit 0;
>
><< End Code >>
>
>> ------------------------------------------------------------
>> "One World, one Web, one Program" - Microsoft promotional ad
>> "Ein Volk, ein Reich, ein Fuhrer" - Adolf Hitler .
>
>Maybe that's why the new MSN ad starts out with a field full of sheep....
Haven't caught any of them out here in australia....which is probably
fortuante, because the mere mention of that company is enough to put
me in rant mode, which is bad if anyone else is trying to watch TV at
the time...
>
>Kurt Stephens
>Pepsdesign
>
>
>


------------------------------------------------------------
"One World, one Web, one Program" - Microsoft promotional ad
"Ein Volk, ein Reich, ein Fuhrer" - Adolf Hitler .


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

Date: Tue, 14 Nov 2000 13:36:51 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: HTML download form - CGI/Perl
Message-Id: <slrn912fvg.7p0.tjla@thislove.dyndns.org>

I was shocked! How could dionysus <dionysus39@hotmail.com>
say such a terrible thing:

>test. I assume that is because sysread() is reading the file in the
>same (text-oriented?) way that more reads files...(as more will read

Yup. You need to binmode() the file you are reading from (after you open
it) and also STDOUT too. Or get a real operating system :) *duck*

>Problem 2 (minor). - when the user is prompted to download the file,
>the default filename is not "tiny web server.zip" or "tinywe~1.zip",
>but "ftest.zip" - where ftest.pl is the name of the perl/cgi
>script....

Beats me. Sounds like you want to ask this in a CGI group.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Missed the train at the railway station
Oh hell, blast, and damnation!
Asked a lady in there if she had the time,
She said "Yes", and a strong inclination.


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

Date: Tue, 14 Nov 2000 22:58:42 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: IP geography
Message-Id: <slrn912a6i.gs3.mgjv@martien.heliotrope.home>

On Tue, 14 Nov 2000 14:46:39 +1100,
	jason <elephant@squirrelgroup.com> wrote:
> tcblue@my-deja.com wrote ..
>>does any know if there is a perl module or script that can 'try' and
>>detect the physical location of a given IP address or hostname?  I
>>found this site that gives a pretty good description of how to make an
>>educated guess on it.  I know there is no real solid way of doing this,
>>but i'd like to start collecting geographical information of IP
>>address.  please let me know If you have any ideas or if there is
>>already something out there that does this.  Thanks,
> 
> how closely do you want to be able to identify the IP ? .. and what's 
> this web site that you're talking about ?
> 
> IP addresses can quite easily be classified by country of designation

No, they cannot. There are a few IP addresses that have spatial meaning.
The large bulk has none.  Try to guess where IBM's IP addresses hang
out, for example. Then guess again half a year later. Even a top level
domain means not that much. Someone in Sydney, Australia and someone in
Perth, Australia both have .au at the end of their hostname (unless they
have a reverse DNS resolution to a .com, .nu, .to, or any other domain),
but they're 3 time zones away from each other. There are other countries
that span multiple time zones. Hell, someone in Honolulu could have an
IP address that resolves to a .au TLD.

Sure, if your accuracy only needs to be about 21000 km, then you can
determine it quite well. As soon as you want more accuracy, your
reliability goes out of the window really fast.

All you can do is make a guess at it, and get about 60% or so
(reasonably) right (and that would be based on host names, not IP
addresses). The other 40 or so % will simply be wrong, undetectably so.

There are some tracerouting packages out there that keep databases of
gateway addresses, and their location. Those databases could be used,
together with a full traceroute, to determine where the closest major
gatway to that IP address would live. Note that that can still give you
a 4000 km error. Easily.

None of this is on-topic here. To the OP, who had an on-topic question:
I don't know of any module that implements heuristics to do this sort of
thing. I have seen attempts to code this sort of stuff up, all being
abandoned after a while, as soon as the people realise how useless and
unreliable the data is. The people who write that tracerouting software
also have given up trying to keep their database up to date. The net is
too fluid to do anything decent. Until IPV6 and/or a few extensions to the
DNS (see RFC 1876), you should probably just forget about it.

Alternatively, you could implement the heuristics, if you really believe
in them, and put them on CPAN. Then at least, the next time this
question comes up, we can just point people to it.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | In a world without fences, who needs
Commercial Dynamics Pty. Ltd.   | Gates?
NSW, Australia                  | 


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

Date: Tue, 14 Nov 2000 08:05:24 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Looking for idiom for getting value from @ARGV, or a default
Message-Id: <tds11tkoedp4m3mhp6po4nan0lr8ovm54e@4ax.com>

Garry Williams wrote:

>>Compact, but actually causes a bug: my password happened to 
>>be "" so this sets it to undef.
>
>Does this fix the bug?
>
>    $sh->{password} = shift(@args) || exists $ENV{DBI_PASS}
>					   ? $ENV{DBI_PASS}
>					   : undef;

(I think this may have a precedence problem, if ?: has higher precedence
than ||)

Simply drop it.

     $sh->{password} = shift(@args) || $ENV{DBI_PASS};

Without command line arguments, if the environment variable DBI_PASS
doesn't exist, this will return undef; otherwise, it will return
whatever $ENV{DBI_PASS} contains, even if it's "0" or "".

-- 
	Bart.


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

Date: Tue, 14 Nov 2000 11:30:03 -0000
From: <vidulats@yahoo.co.uk>
Subject: Message Queue stuff
Message-Id: <t128hrr27dqhe2@corp.supernews.com>

Hi Perl Experts,

#!/usr/bin/perl

require 'sys/ipc.ph';
require 'sys/msg.ph';

$PERMISSION=0666;
$ipckey = 42;

$Msg_ID = msgget($ipckey, &IPC_CREAT | $PERMISSION);

print "\nEnter the message to be send : ";
chomp($msg = <>);

$msg_type = 1;
$msg = pack("L a*", $msg_type, $msg);

msgsnd($Msg_ID, "$msg", &IPC_NOWAIT);

The above code works file except this:
Prototype mismatch: sub main::__need_size_t vs () at (eval 63) line 1.

My send question is:
Here I'm sending a scalar ($msg) as a message, instead of that I want to 
send a Hash. I tried passing a hash, hash reference, but none of them 
worked.
How to overcome this problem?

I already refered to perlxs, perlstut manpage.

Thanks in advance,

Regards,
Vidula                                                                 

--
Posted via CNET Help.com
http://www.help.com/


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

Date: 14 Nov 2000 11:58:26 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Message Queue stuff
Message-Id: <8ur9d2$cdj$1@lublin.zrz.tu-berlin.de>

 <vidulats@yahoo.co.uk> wrote in comp.lang.perl.misc:
>Hi Perl Experts,
>
>#!/usr/bin/perl

Regulations require me to mention that you fail to employ warnings
and strict.

>require 'sys/ipc.ph';
>require 'sys/msg.ph';

In more modern Perls you can say

use IPC::SysV qw( IPC_CREAT IPC_NOWAIT);

instead.

>$PERMISSION=0666;
>$ipckey = 42;
>
>$Msg_ID = msgget($ipckey, &IPC_CREAT | $PERMISSION);
>
>print "\nEnter the message to be send : ";
>chomp($msg = <>);
>
>$msg_type = 1;
>$msg = pack("L a*", $msg_type, $msg);
>
>msgsnd($Msg_ID, "$msg", &IPC_NOWAIT);
>
>The above code works file except this:
>Prototype mismatch: sub main::__need_size_t vs () at (eval 63) line 1.

I don't see this after using IPC::SysV.

>My send question is:

send = next?

>Here I'm sending a scalar ($msg) as a message, instead of that I want to 
>send a Hash. I tried passing a hash, hash reference, but none of them 
>worked.
>How to overcome this problem?

You will have to linearize the hash so you can transfer it as a string.
Data::Dumper (in the standard distribution) does this.

Anno


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

Date: Tue, 14 Nov 2000 12:13:16 -0000
From: "Geoff Winkless" <geoff-at-farmline-dot-com@127.0.0.1>
Subject: Re: Message Queue stuff
Message-Id: <8ura59$j7k$1@soap.pipex.net>

<vidulats@yahoo.co.uk> wrote in message
news:t128hrr27dqhe2@corp.supernews.com...
> Hi Perl Experts,
>
> #!/usr/bin/perl
>
> require 'sys/ipc.ph';
> require 'sys/msg.ph';
>
> $PERMISSION=0666;
> $ipckey = 42;
>
> $Msg_ID = msgget($ipckey, &IPC_CREAT | $PERMISSION);
>
> print "\nEnter the message to be send : ";
> chomp($msg = <>);
>
> $msg_type = 1;
> $msg = pack("L a*", $msg_type, $msg);

AIUI it should be

$msg = pack("la*", $msg_type, $msg);

> The above code works file except this:
> Prototype mismatch: sub main::__need_size_t vs () at (eval 63) line 1.

Maybe having line numbers on your source would help? :)

> My send question is:
> Here I'm sending a scalar ($msg) as a message, instead of that I want to
> send a Hash. I tried passing a hash, hash reference, but none of them
> worked.
> How to overcome this problem?

What are you sending it to?

G




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

Date: Tue, 14 Nov 2000 12:43:27 GMT
From: menorevs@my-deja.com
Subject: net::telnet question
Message-Id: <8urc1e$r9o$1@nnrp1.deja.com>

how can you get a session to keep running if it runs into errors

for example

i have an array of routers that need to be run one by one, but if it
does not connect to one of the routers, i dont need it to stop the
whole process, i need it to write an error log and run the next router.

Any ideas would be appreciated.

John


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 14 Nov 2000 23:58:02 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: net::telnet question
Message-Id: <slrn912dmq.gs3.mgjv@martien.heliotrope.home>

On Tue, 14 Nov 2000 12:43:27 GMT,
	menorevs@my-deja.com <menorevs@my-deja.com> wrote:
> how can you get a session to keep running if it runs into errors

Look for errmode in the Net::Telnet documentation.

I do suppose that you mean 'keep the program running' instead of the
session, right? if your telnet session returns an error, you should dump
it, and create a new one.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | +++ Out of Cheese Error +++ Reinstall
Commercial Dynamics Pty. Ltd.   | Universe and Reboot +++
NSW, Australia                  | 


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4884
**************************************


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