[10298] in Perl-Users-Digest
Perl-Users Digest, Issue: 3890 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 5 13:57:33 1998
Date: Mon, 5 Oct 98 04:00:20 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 5 Oct 1998 Volume: 8 Number: 3890
Today's topics:
Re: $/ in 5.005 <ets@egnetz.uebemc.siemens.de>
anyone using gtk/perl??? <damonbrent@earthlink.net>
Re: Custom HTML functions - I could use some direction, (Alex McLintock)
Re: HELP !!! <garethr@cre.canon.co.uk>
Re: help with finding a regular expression (Ronald J Kimball)
How to trim a line ...? (Tianxiong)
Re: How to trim a line ...? (Craig Berry)
Re: How to write a MS Excel file <gadget@bc.sympatico.ca>
Re: Keeping a running list of the top n values retrieve (Ronald J Kimball)
Re: LWP on NT fails to fetch more than 4000 URLs. (Fergus McMenemie)
Re: Need IP Address Sort Subroutine <erhmiru@erh.ericsson.se>
Re: Omaha Perl Mongers - First Meeting ! <jimbo@soundimages.co.uk>
Re: passing javascript vars to CGI <phinneas@eskimo.com>
Re: Passing Variables: $_ vs. @_ <r.goeggel@atos-group.de>
perl as shell. <cb921@satch.ml.org>
Re: POLL: Perl features springing into your face (Kai Henningsen)
Re: Problems Using a Compare Subroutine with Sort <erhmiru@erh.ericsson.se>
Problems with syswrite (I guess!!!) jonas4524@my-dejanews.com
Re: read subdirectories <jerryp.usenet@connected.demon.co.uk>
Re: Run cgi scripts ar regular intervals <daniel.vesma@thewebtree.com>
Re: sendmail.pl francesx@my-dejanews.com
Re: Size or format problem <erhmiru@erh.ericsson.se>
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 05 Oct 1998 10:23:48 +0200
From: "Hr. Jochen Stenzel" <ets@egnetz.uebemc.siemens.de>
Subject: Re: $/ in 5.005
Message-Id: <36188213.3B34B654@egnetz.uebemc.siemens.de>
> I can't duplicate your result:
>
> orpheus:~/perl$ perl5.00404
> BEGIN {print "A\n" if defined $/;}
> print "B\n" if defined $/;
> A
> B
> orpheus:~/perl$ perl5.00502
> BEGIN {print "A\n" if defined $/;}
> print "B\n" if defined $/;
> A
> B
I still used 5.00501. May be 5.00502 is the better choice - so I will try
it.
Thanks
Jochen
------------------------------
Date: Mon, 05 Oct 1998 01:11:53 -0500
From: brent verner <damonbrent@earthlink.net>
Subject: anyone using gtk/perl???
Message-Id: <36186329.39B0306F@earthlink.net>
if anyone could point me toward any resources about using the gtk/perl
bindings i'd really appreciate it!
thanks,
--brent
------------------------------
Date: Mon, 05 Oct 1998 10:04:19 GMT
From: alex.mclintock@removethisbit.earthling.net (Alex McLintock)
Subject: Re: Custom HTML functions - I could use some direction, hints, help! :-)
Message-Id: <907581790.27352.0.nnrp-04.9e982230@news.demon.co.uk>
cnlsilva@3dgaming.com wrote:
>I am attempting to modify a script to allow a HTML page to be updated
>dynamically. I want to use a custom tag <poll> and </poll> to allow
>new information to be updated to the page in a easy to use manner.
I would recommend looking at the MetaText perl module by Andy Wardley.
It is available on CPAN.
Damn fine software which saved me days of work and let me finish a project on
time. It copes with all the basic template parsing and you only have to figure
out how to code the stuff inside your custom tag.
Alex
------------------------------
Date: Mon, 5 Oct 1998 10:43:33 GMT
From: Gareth Rees <garethr@cre.canon.co.uk>
Subject: Re: HELP !!!
Message-Id: <siu31j5lwq.fsf@cre.canon.co.uk>
"Charles Li" <qli3@jetson.uh.edu> wrote:
> I'm doing PERL CGI programming. I am not able to use CGI.pm (for some
> reason), how do I pass on the HTML form inputs to the variables in my PERL
> CGI script?
Use CGI::Request or CGI_Lite instead of CGI.
--
Gareth Rees
------------------------------
Date: Mon, 5 Oct 1998 00:04:20 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: help with finding a regular expression
Message-Id: <1dgef23.1lykxa3h943i8N@bay1-358.quincy.ziplink.net>
David Alan Black <dblack@pilot.njin.net> wrote:
> > "Hello<delim>Here's my problem</delim>everyone."
>
> >The regexp would replace all "e"s by "*"s, but only if the "e"s lie within
> ><delim></delim>:
>
> > Hello<delim>h*r*'s my probl*m</delim>everyone.
> This version is similar in principle to Garry's but easier to
> maintain,
Which is good, because I'm afraid it needs some maintaining right off...
:-)
> as it abstracts the delimiter into a variable which
> you can redefine if it changes (assuming the basic tag syntax
> remains the same).
A good idea. That's how I would do it too.
> #!/usr/local/bin/perl -w
>
> use strict;
>
> my $s = "Hello<delim>Here's my problem</delim>everyone.\n";
> my $d = "delim";
>
> $s=~s!(?:<$d>)(.*?)(?:</$d>)!(my$x=$1)=~tr/e/*/;$x!ge;
>
> print $s;
HelloH*r*'s my probl*meveryone.
Don't forget to put the delimiters back in! Also, just in case the
delimiters contain metacharacters...
$s=~s!(<\Q$d\E>)(.*?)(</\Q$d\E>)!(my$x=$2)=~tr/e/*/;"$1$x$3"!ge;
Hello<delim>H*r*'s my probl*m</delim>everyone.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 5 Oct 1998 05:46:40 GMT
From: tianxiong@aol.com (Tianxiong)
Subject: How to trim a line ...?
Message-Id: <19981005014640.05879.00006580@ng-fd1.aol.com>
Hi, folks, here is my another question ...
I'd like to parse all the strings one by one from a line like
"10/02/98 11:10:22 Sold YHOO 100 123 15/16 $12,340.56 $-4,567.87 2 3
AAA-001-kkkk", it would be more flexible if the line could be trimmed after a
string is parsed, for example, after "10/02/98' is parsed the line will be
trimmed as "11:10:22 Sold YHOO ....". How would you implement it?
Thanks in advance.
PS. Is 'abs' available? The following was what I did and what I got ...
print " abs = ", abs(-20), "\n";
"abs" may clash with future reserved word at xxx.pl line 25.
Syntax error in file xxx.pl at line 25, next 2 tokens "abs("
------------------------------
Date: 5 Oct 1998 06:45:23 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: How to trim a line ...?
Message-Id: <6v9pu3$r5g$2@marina.cinenet.net>
Tianxiong (tianxiong@aol.com) wrote:
: I'd like to parse all the strings one by one from a line like
: "10/02/98 11:10:22 Sold YHOO 100 123 15/16 $12,340.56 $-4,567.87 2 3
: AAA-001-kkkk", it would be more flexible if the line could be trimmed after a
: string is parsed, for example, after "10/02/98' is parsed the line will be
: trimmed as "11:10:22 Sold YHOO ....". How would you implement it?
You *can* trim, but why? I'd just grab the tokens by splitting the line,
then iterate over the resulting array. But if you really want to trim,
here's one way (untested):
while (defined ($line = <STRINGS>)) {
while ($line) {
($token, $line) = split ' ', $line, 2;
# Do stuff with $token (the next word) and $line (the
# remainder of the line) here.
}
}
: PS. Is 'abs' available? The following was what I did and what I got ...
:
: print " abs = ", abs(-20), "\n";
:
: "abs" may clash with future reserved word at xxx.pl line 25.
: Syntax error in file xxx.pl at line 25, next 2 tokens "abs("
/usr2/people/cberry > perl -v
This is perl, version 5.004_04 built for sun4-solaris
[snip]
/usr2/people/cberry > perl -we 'print " abs = ", abs(
abs = 20
Looks like you either have a seriously backlevel Perl, or (more likely, I
think) there's something wrong just before the line you quote that's the
real cause of your problem.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| "Ripple in still water, when there is no pebble tossed,
nor wind to blow..."
------------------------------
Date: Sun, 04 Oct 1998 22:36:18 -0700
From: Fred Richards <gadget@bc.sympatico.ca>
To: Hans Xie <hans.xie@its.csiro.au>
Subject: Re: How to write a MS Excel file
Message-Id: <36185AD2.BA6F2C03@bc.sympatico.ca>
<HTML>
<P>Hans Xie wrote:
<BLOCKQUOTE TYPE=CITE>Hi there,
<P>Are there tools/packages can help me to output a file into MS Excel
format?
<P>Thanks a lot.
<BR>HB XIE</BLOCKQUOTE>
There is an excellent article in the Summer 1998 Issue of:<B><FONT COLOR="#3333FF"></FONT></B>
<P><B><FONT COLOR="#3333FF">The Perl Journal</FONT></B>
<BR><B><FONT COLOR="#000000">Issue #10 (Vol 3, No. 2)</FONT></B><FONT COLOR="#000000"></FONT>
<P><FONT COLOR="#000000">Hope this helps</FONT><FONT COLOR="#000000"></FONT>
<P><FONT COLOR="#000000">Fred Richards</FONT>
<BR><FONT COLOR="#000000">The Gadget Guy</FONT>
<BR><FONT COLOR="#000000"></FONT> </HTML>
------------------------------
Date: Mon, 5 Oct 1998 00:04:22 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Keeping a running list of the top n values retrieved
Message-Id: <1dgef8x.nm3n0zv9tqbaN@bay1-358.quincy.ziplink.net>
Nick Tonkin <nick@valueclick.com> wrote:
> I am guessing that what I should do is push and pop variables off a
> list, but how would I avoid sorting the list for each variable so I
> can compare the value with the 20th highest value?
If you want to only compare the value against the 20th highest value,
you must keep the list sorted. Otherwise, you don't know which value is
the lowest in the top 20 list.
However, keep in mind that each time you need to add a new value, the
current top 20 list will already be sorted. So, instead of doing a full
sort, you can just insert the new value into the list in the appropriate
place.
A quick hack:
$top = 20;
# shuffle initial array as in FAQ
@all = ();
@vals = 1 .. 100;
foreach (@vals) {
my $r = rand @all+1;
push(@all,$all[$r]);
$all[$r] = $_;
}
@top = ();
for $new (@all) {
# find position for new element
for ($i=$#top; $i>=0; --$i) {
last if ($new < $top[$i]);
}
# add new element to array
splice(@top, $i+1, 0, $new);
# remove last element if @top is overfull
pop @top if (@top > $top);
}
print join("\n", @top), "\n";
Of course, you could easily modify this code to do hash lookups or
whatever for the comparison, just like the built-in sort function.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Mon, 5 Oct 1998 08:07:17 +0000
From: fergus@twig.demon.co.uk (Fergus McMenemie)
Subject: Re: LWP on NT fails to fetch more than 4000 URLs.
Message-Id: <1dg7nph.gfpofnwlprrqN@twig.demon.co.uk>
Gisle,
Yes I would say it does. Thanks very much. I will try again
checking the results of a netstat and I will look for that
update.
> fergus@twig.demon.co.uk (Fergus McMenemie) writes:
>
> > Further to this article. I have copied the script to UNIX and had
> > better luck there. The unix version ran fine fethcing over 68000
> > page, but there appears to be some kind of limit on NT.
>
> I recently got a copy of this message from Sarathy. Does this apply
> to your situation?
>
> -------------------------------
> On Thu, 24 Sep 1998 09:40:58 CDT, Craig Brockmeier wrote:
> >I'm using the perl5.00402-bindist04-bc.tar.gz build of perl on Windows/NT
> >
> >I wrote a program to check http links, but it starts failing with 500 server
> >errors after checking about 4000 links. Using netstat -an to look at open
> >sockets, it seems that the sockets are not being closed correctly.
>
> There is a known socket leak in the win32 support in 5.00402. Later
> versions don't have the problem.
>
> - Sarathy.
> gsar@engin.umich.edu
>
> -------------------------------
--
======================================================================
Fergus McMenemie Email: fergus@twig.demon.co.uk
Technical Basis
======================================================================
------------------------------
Date: 05 Oct 1998 11:17:21 +0200
From: Michal Rutka <erhmiru@erh.ericsson.se>
Subject: Re: Need IP Address Sort Subroutine
Message-Id: <lad8875pwe.fsf@erh.ericsson.se>
"Joe Williams" <willliams@clark.net> writes:
> This is in answer to my original post. First, many thanks for all the
> comments. I will be traveling over the next couple of days, but look forward
> to checking them out. Meantime, I'm posting a solution that is certainly not
> the most elegant or efficient, but it does work, and is fairly transparent.
> I used John Porter's solution to the IP string conversion with some changes
> as noted. It is probably over-commented, but what the hell!
You are welcome. Your code is quite impressive. However, you can consider
some improvements. The most importent of these is that the code is much
shorter and clear (at lest to me), therefore easier to maintain.
Improvement 1:
@sorted_lines = sort {get_ipa($a) cmp get_ipa($b)} @list;
# Where get_ipa() can be:
sub get_ipa{
return udef unless $_[0] =~ /.*: ([\d.]+)#/;
return pack("C4",split(/\./,$1));
}
# Or more correct:
use Socket;
sub get_ipa{
return udef unless $_[0] =~ /.*: ([\d.]+)#/;
return inet_aton($1);
}
This solution might suffer when you have a lot lines to compare, because of
the routine passed to sort. As John Porter banchmarked, this gives an extra
overhead. However, in your original solution you also use routine, therefore
you should notice speed improvements. (Note that ST solution will also
suffer from this fact, as it uses sub call too to dereference indexes).
Improvement 2:
@sorted_lines = map {substr($_,4)} sort map {get_ipa($_).$_} @list;
This solution is quite similar to ST but faster. It does not use
dereference during sort and finall map should be faster too.
Nevertheless, when I try to benchmark all solutions it seems that the first
improvement is only slightly faster than original solution and the
second one is not improvement at all (i.e. in speed)! Some more realistic
benchmarking should be done for which I do not have enough time. In my
opinion, as map creates a new array it will always suffer from speed
penalty, as on most systems memory allocation is the most time consuming
operation. Above counts for ST too.
Regards,
Michal
------------------------------
Date: 05 Oct 1998 11:58:10 +0100
From: Jim Brewer <jimbo@soundimages.co.uk>
Subject: Re: Omaha Perl Mongers - First Meeting !
Message-Id: <uzpbbs2bh.fsf@jimbosntserver.soundimages.co.uk>
Jonathan Stowe <gellyfish@btinternet.com> writes:
>
> I reesed that up like a right gugus - that'll be flamingos of course.
> I'm getting my Lewis Caroll confused with King Lear's daughters
>
> But I think I got away with it ;-P`
>
Only a REAL pervert would think a flamingo looks anything like a
daughter of King Lear. Or any other hominoid.
Does your community policing initiative require you to register your
presence whenever in the local shopping mall?
Do you inspire fear in your local bird watchers?
A flamingo looks like a female hominoid. Really. The youth of today.
Must be lunch time. I'm off. Maybe it's past my sell by date.
--
Jim Brewer
e-mailed courtesy copies are unappreciated, please refrain.
------------------------------
Date: Sun, 04 Oct 1998 23:28:26 -0700
From: "Phinneas G. Stone" <phinneas@eskimo.com>
To: jeff@vpservices.com
Subject: Re: passing javascript vars to CGI
Message-Id: <36186709.D1D8905@eskimo.com>
My apologies for coloring outside the lines and asking a question that
encompasses JavaScript and HTML as well as Perl. It's a shame we can't just
have one tool in our belt to do the whole job; but sometimes in order to
use a chisel you must also use a hammer. Let me try to explain my question
more specifically:
What I am trying to do is enter a list of items into a textarea to be
subsequently passed to perl through cgi, joined into a :: delimited string
and stored in a single field of a database. Later on, the script will split
the string to create an array that will be used to display the list as a
bulleted list. Still with me? Now, each time the form is used there may be
a different amount of items (bullets), so I can't just initially create the
form with a hard-coded group of text inputs. Previously, I had opened a
JavaScript prompt box to get the number of bullets for that item, then
generated the form with a little help from JavaScript to create text input
for each of the specified number of bullets, passed them off to the cgi
script which then joined them together into a string and filed it away in
the database. But now I don't want to have the prompt box popping up all
the time. So if I can enter the list of bullets into a textarea, separated
by line breaks, I could translate the line breaks into :: and avoid the
prompt box and individual text inputs altogether.
When I tried this approach, however, all my line breaks were converted into
spaces and couldn't be split(/\n/$bullets)-ed. So I thought maybe I could
have the client convert the whole string into an encoded form before
sending it off. But how to send it off? I can't put it into a hidden field
because all the form html code has already been written to the browser
window!
Am I going about this all wrong? It doesn't seem like it should be this
difficult and confusing (not to mention controversial).
Phinneas
Jeff Zucker wrote:
> [pre-note to clpm-ers: right, this has nothing to do with perl, but
> three previous clpm-ers gave bogus answers to this question about using
> wrap or saying this is a javascript question (which it isn't, it's an
> html question, so to clear the air...]
>
> In comp.lang.perl.misc Phinneas G. Stone <phinneas@eskimo.com> wrote:
> >Is it possible to process a variable with javascript, then pass that
> >value along to a CGI script? What I'm trying to do is preserve the
> >line breaks in a <textarea> by encoding with the javascript escape()
> >function and decoding them with perl once the form has been submitted.
>
> Is this a trick question? Why would you need to use javascript to
> escape the contents of the textarea? *Anything* in a form is
> automatically escaped when you submit the form so escaping it again
> would be pointless. And line breaks *are already automatically*
> preserved in a textarea regardless of wrap being set to physical or
> virtual or not. Wrap only impacts lines where the user does not press
> carriage return (i.e. where there are no line breaks).
>
> Perhaps what you mean is that the line breaks do not show up when you
> display the form on the web. That's because any amount of whitespace
> (including line breaks) is turned into a single space by a conforming
> browser.
>
> If you want the line breaks to show up on your web page, you don't need
> to do anything on the form itself, just, when you decode the form, do
> this for each param: $param =~ s/\n/<br>/g;
>
> - Jeff
Jeff Zucker wrote:
> [pre-note to clpm-ers: right, this has nothing to do with perl, but
> three previous clpm-ers gave bogus answers to this question about using
> wrap or saying this is a javascript question (which it isn't, it's an
> html question, so to clear the air...]
>
> In comp.lang.perl.misc Phinneas G. Stone <phinneas@eskimo.com> wrote:
> >Is it possible to process a variable with javascript, then pass that
> >value along to a CGI script? What I'm trying to do is preserve the
> >line breaks in a <textarea> by encoding with the javascript escape()
> >function and decoding them with perl once the form has been submitted.
>
> Is this a trick question? Why would you need to use javascript to
> escape the contents of the textarea? *Anything* in a form is
> automatically escaped when you submit the form so escaping it again
> would be pointless. And line breaks *are already automatically*
> preserved in a textarea regardless of wrap being set to physical or
> virtual or not. Wrap only impacts lines where the user does not press
> carriage return (i.e. where there are no line breaks).
>
> Perhaps what you mean is that the line breaks do not show up when you
> display the form on the web. That's because any amount of whitespace
> (including line breaks) is turned into a single space by a conforming
> browser.
>
> If you want the line breaks to show up on your web page, you don't need
> to do anything on the form itself, just, when you decode the form, do
> this for each param: $param =~ s/\n/<br>/g;
>
> - Jeff
------------------------------
Date: Mon, 05 Oct 1998 12:08:33 +0100
From: "Ronald Gvggel" <r.goeggel@atos-group.de>
Subject: Re: Passing Variables: $_ vs. @_
Message-Id: <3618A8B1.4E4D09F8@atos-group.de>
Michael Griffith wrote:
> sub AddRecord{
> $database=$_[0];
> $returnto=$_[1];
> $record =$_[2];
>
> ... Snip ...
>
> }
>
> Is there any difference in that implementation and this one:
>
> sub AddRecord{
> ($database,$returnto,$record) = @_;
>
> ... Snip ...
>
> }
>
> Just wondering...
>
There is just one difference:
The three line code depends on $[
$[ = 1;
@arr = (1,2,3,4,5,6,7);
&sub(@arr);
sub sub {
print $_[0];
print $_[1];
print $_[2];
}
this results in:
112
(I don't know why)
This is perl, version 5.004_04 built for PA-RISC1.1
HTH
Ronald
------------------------------
Date: Mon, 5 Oct 1998 12:20:43 +0200
From: Campbell <cb921@satch.ml.org>
Subject: perl as shell.
Message-Id: <Pine.LNX.4.00.9810051219310.2943-100000@cb921.voice.co.za>
I have heard scary little whisperings about people using perl instead of
bash as their shell.
The mind boggles.
Does anyone here know how this could be accomplished under Linux?
Campbell
An email Cc: would be appreciated...
------------------------------
Date: 02 Oct 1998 10:29:00 +0200
From: kaih=727lswbmw-B@khms.westfalen.de (Kai Henningsen)
Subject: Re: POLL: Perl features springing into your face
Message-Id: <727lswbmw-B@khms.westfalen.de>
Tom.Horsley@worldnet.att.net (Thomas A. Horsley) wrote on 27.09.98 in <uaf3l9ycb.fsf@worldnet.att.net>:
> >Do not follow you. Do you want to prohibit lexicals at toplevel
> >scope, or what? If yes, why? And how is this a restate of
> >life-time-of-emporaries issues?
>
> Actually I probably shouldn't have used the word "restate", I really went
> off on a tangent.
>
> I guess I do want to prohibit top-level lexicals, mainly because of the
> non-intuitive interactions (or lack of interactions :-) they have with
> packages. Mostly they just seem to confuse people.
Could you elaborate on this? Currently, you confuse me.
> >Hmm, yea. Do not know: nested subs, are they good for anything? I
> >did not see any meaningful usage, but maybe there is?
>
> They can be useful in languages that define them "correctly" (although even
> in Pascal and Ada programming, I've rarely had any reason to use them, but
> I've also rarely had any reason to do Pascal or Ada programming :-). With
> the sort of accidental definition they have in perl though, I can't see
> any use.
"Real" nested subs are very useful once you do large programs. To put it
in Perl terms, you have access to the my variables of the parent sub,
which means that many less parameters; also, the sub is itself a sort of
my variable in the parent sub, and thus its name cannot collide with any
odd sub elsewhere.
Kai
--
http://www.westfalen.de/private/khms/
"... by God I *KNOW* what this network is for, and you can't have it."
- Russ Allbery (rra@stanford.edu)
------------------------------
Date: 05 Oct 1998 12:27:01 +0200
From: Michal Rutka <erhmiru@erh.ericsson.se>
Subject: Re: Problems Using a Compare Subroutine with Sort
Message-Id: <la7lyf5moa.fsf@erh.ericsson.se>
John Porter <jdporter@min.net> writes:
[...]
> > Do you dont understand that it overflows? Thats mean it
> > gives different result on your Spark than on mine. Does this not worry
> > you? At least it worries me.
>
> Are you sure it overflows?
Yes.
> I have a hard time believing that your
> machine, which is alsa a sparc, behaves so differently.
It is up to you.
> How did you "discover" that 255.255.255.255 gets converted to -1?
Here is the code:
#!/usr/local/bin/perl
sub dotted_to_int {
return undef if $_[0] =~ /[^0-9.]/;
my @a = split /\./, $_[0];
my $n = pop @a;
return undef unless $n < (256 ** ( 4 - @a ));
for ( 0..$#a ) {
return undef unless $a[$_] < 256;
$n += ( $a[$_] << (8*(3-$_)) );
}
$n;
}
$a = dotted_to_int('255.255.255.255');
print "$a\n";
print $a > 0 ? "is positive" : "is negative" ,"\n";
And here is the result:
-1
is negative
> I notice that it prints -1 if I use printf("%d"); but print()
> and the debugger give me 4294967295.
Here is my debuger:
DB<1> X a
$a = '-1'
>
> --
> John "Many Jars" Porter
> baby mother hospital scissors creature judgment butcher engineer
Regards,
Michal
------------------------------
Date: Mon, 05 Oct 1998 10:41:56 GMT
From: jonas4524@my-dejanews.com
Subject: Problems with syswrite (I guess!!!)
Message-Id: <6va7pk$5je$1@nnrp1.dejanews.com>
I have a little problem when sending data with a modem - modem connection. I
use the syswrite function but can't get it to work. Don't know if that which
I'm sending is transmitted or if it is transmitted correctly. What I'm sure
of is that I don't get the desired result. ;-) If anyone knows anything about
this, please mail me. I know the information is a bit short, if at all
existent, but I don't know the problem so....
Thanks in advance.
/Jonas
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Sun, 4 Oct 1998 18:54:49 +0100
From: Jerry Pank <jerryp.usenet@connected.demon.co.uk>
Subject: Re: read subdirectories
Message-Id: <Z9XdbJApZ7F2EwYk@connected.demon.co.uk>
In <comp.lang.perl.misc>
Douglas SEAY <doug@kittycat.france.seay>, writes:
>[posted and CC'd]
>
>On Sun, 04 Oct 1998 15:00:30 GMT, Richard Ahier
> <richarda@profil-cdi.qc.ca> wrote:
>>
>>I try since a week to make a recursive script who read a directory and all
>>his subdirectories.
>>I just need directories not files.
>
>If you are using Unix (you don't say) then the easiest way is
His mail header does-------/
X-Newsreader: Microsoft Internet News 4.70.1161
> `find $dir -type d -print`
>
>For a bit more control, try running
> "perldoc File::Find"
>
>from the command line.
>
>- doug
-- Jerry Pank mailto:jerryp.usenet@netconnected.com
Part of language design is purturbing the proposed feature in various
directions to see how it might generalize in the future.
-- Larry Wall in <199709032332.QAA21669@wall.org>
------------------------------
Date: Mon, 5 Oct 1998 11:55:53 +0100
From: "Daniel Vesma" <daniel.vesma@thewebtree.com>
Subject: Re: Run cgi scripts ar regular intervals
Message-Id: <3618a606.0@news.thefree.net>
It's just a guess, but couldn't you use a webpage with a refresh tag to keep
calling the script. I may be wrong.
Daniel Vesma
www.thewebtree.com/daniel-vesma
------------------------------
Date: Mon, 05 Oct 1998 04:31:03 GMT
From: francesx@my-dejanews.com
Subject: Re: sendmail.pl
Message-Id: <6v9i27$eu2$1@nnrp1.dejanews.com>
Thanks for your replies. This NET::SMTP method sounds good. Where do I get
the libnet module. I downloaded smtp.pm from CPAN which then gave error
'couldn't find flock.pm', which I found and downloaded. It now is looking
for posix.pm. Can I get all needed files at once? Where?
Thanks again
Frances
In article <3614BE09.8FC9F263@home.net>,
vwstranathan <vwstranathan@home.net> wrote:
> Forgive me for sending this if you've already seen it. This is straight out
of
> the ActivePerl documentation...
>
> How do I send email from Perl for Win32?
>
> You may come across scripts that send email with an external mail
> program, as in:
>
> #!/usr/bin/perl
>
> open(MAIL, '| /usr/lib/sendmail user@there.com') or die "$!";
> print MAIL <<EOF;
> To: user@there.com
> From: user@here.com
>
> Hello, World!
>
> EOF
>
> These sort of scripts generally cause people to ask, ``is there a
> sendmail equivalent on Windows?'' If you need to
> send email from a Perl script, there is no need to use an external
> program like sendmail. The libnet bundle includes
> Net::SMTP, a module that can be used to send mail. Here is an
example:
>
> use Net::SMTP;
>
> $smtp = Net::SMTP->new('here.com'); # connect to an SMTP
server
>
> $smtp->mail( 'user@here.com' ); # use the sender's
address
> here
>
> $smtp->to('user@there.com'); # recipient's address
>
> $smtp->data(); # Start the mail
>
> # Send the header.
> #
> $smtp->datasend("To: user@there.com\n");
> $smtp->datasend("From: user@here.com\n");
> $smtp->datasend("\n");
>
> # Send the body.
> #
> $smtp->datasend("Hello, World!\n");
>
> $smtp->dataend(); # Finish sending the mail
> $smtp->quit; # Close the SMTP
connection
>
> A Perl script for sending mail without using an external program is
also
> available on Robin Chatterjee's Perl for
> Win32 page (see Are there information sources available on Perl for
Win32
> on the World Wide Web?).
>
> If you really need a sendmail equivalent for Windows, several such
> equivalents exist:
>
> Blat
>
> Blat is a public domain program for sending email from the
Windows NT
> command-line. Although it is reputed
> to work under Windows 95, the Blat authors have not tested it
under
> Windows 95. The Blat home page is
> located at http://gepasi.dbs.aber.ac.uk/softw/Blat.html
> sendmail
>
> Microsoft has a port of sendmail available on their FTP site at
>
ftp://ftp.microsoft.com/developr/drg/unix-to-windows/ports/sendmail/
>
> A commercial sendmail product is available from MetaInfo, Inc. An
> evaluation version is available at
> http://www.metainfo.com/
> wrmail
>
> Another commercial mail product is wrmail, part of the slmail
product
> from Seattle Labs. A free version is
> available at http://www.seattlelab.com/
>
> Will Stranathan
> vwstranathan@home.net
>
> francesx@my-dejanews.com wrote:
>
> > I want to call up the sendmail.pl program from a perl script on NT. To send
> > input of a form via email.
> >
> > I have called it up on Unix by using the line:
> >
> > open(MAIL,"|/usr/sbin/sendmail -t");
> >
> > Can I call this up from my cgi-bin on NT or do I need an NT version of the
> > sendmail program?
> >
> > I can call up my perl scripts by the following:
> >
> > http://www.myserver.com.au/cgi-bin/perlscript.pl
> >
> > So I was wondering if I can call up sendmail by using a similar line, such
as:
> >
> > open(MAIL,"http://www.myserver.com.au/sbin/sendmail -t");
> >
> > Thankyou
> >
> > Frances
> >
> > -----------== Posted via Deja News, The Discussion Network ==----------
> > http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
>
>
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 05 Oct 1998 11:47:39 +0200
From: Michal Rutka <erhmiru@erh.ericsson.se>
To: gcushing@exchange.nih.gov
Subject: Re: Size or format problem
Message-Id: <laaf3b5ohw.fsf@erh.ericsson.se>
Hello George,
it seems to me that you have a typical integer overflow problem. In 32 bit
systems, an integer 0xFFFFFFFF can be represented as 4294967295 or -1. You
are going negative as soon as MSB is 1, i.e. from 2147483648 which is
MAXINT + 1. Every number equal or greater than this will be negative.
This answers why you are geting negative numbers.
How you should correct this problem? The good news is that you can still
use your format, however such a big numbers should be represented as
strings. In order to allow arthmetic operation on these strings you can
use Math::BigInt (see perldoc bigint).
Hope this helps,
Michal
George Cushing <gcushing@exchange.nih.gov> writes:
> I am getting some minus numbers in my statistical reports. We keep
> track of
> users looking at out homepage and downloading files. Looking at the
> total
> size of files downloading there are some minus numbers example
> -2017337938 for
> the bytes downloaded. I should be getting 2,277,629,358 as the number
> of bytes
> sent. I get this when the bytes size is over 2 gig. My question is:
> Is there a
> size limit in printing with format cammand? I increased my format size
> to
> @>>>>>>>>>>>. It seems I am truncating the number being printed and
> there is
> no sign to the number. I do not know why I am truncating the output if
> it is over
> 2 gig. I displayed the variable right before printing the report line
> and it is okay. This must mean that the problem is when I print the
> report.
[...]
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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 3890
**************************************