[19368] in Perl-Users-Digest
Perl-Users Digest, Issue: 1563 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 19 06:05:40 2001
Date: Sun, 19 Aug 2001 03:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <998215509-v10-i1563@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 19 Aug 2001 Volume: 10 Number: 1563
Today's topics:
Re: Alternative to use URI::Escape; (Martin Vorlaender)
Re: CGI Filter (Martin Vorlaender)
CODE reference to member function of package Confusing. <romerun@greezi.com>
Re: Coercing list context onto pair of regexps in a com (Martien Verbruggen)
Re: Coercing list context onto pair of regexps in a com <uri@sysarch.com>
Re: Color Coding Lexer for Editor (Martin Vorlaender)
Re: Copy file in Perl <bwalton@rochester.rr.com>
Re: Copy file in Perl <ernst.wernli@gibthun.ch>
dec2hex conversion ,uninitialized value <stephen@oxnee.com>
Re: dec2hex conversion ,uninitialized value <krahnj@acm.org>
Re: dec2hex conversion ,uninitialized value <samneric@tigerriverOMIT-THIS.com>
dynamic variable question <zkent@adelphia.net>
Re: dynamic variable question <uri@sysarch.com>
Re: dynamic variable question <ahorvath@cyberjus.com>
Re: dynamic variable question <uri@sysarch.com>
FAQ: I'm having trouble matching over more than one lin <faq@denver.pm.org>
Re: From UNIX to Windows (Martin Vorlaender)
Hash of Complex Records <mark.riehl@agilecommunications.com>
Re: Hash of Complex Records <samneric@tigerriverOMIT-THIS.com>
Re: How to call ISAPI dll from perl? (Martin Vorlaender)
Re: IO::Socket::INET - Setting Reset bit when closing T (Jay McGavren)
Is element in array <guymal@__NOSPAM__hotmail.com>
Re: Is element in array (Tassilo v. Parseval)
Re: Local Perl via browser (Eric Bohlman)
Re: Local Perl via browser (Logan Shaw)
Re: Local Perl via browser <newspost@coppit.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 19 Aug 2001 05:07:01 +0200
From: martin@radiogaga.harz.de (Martin Vorlaender)
Subject: Re: Alternative to use URI::Escape;
Message-Id: <3b7f2d55.524144494f47414741@radiogaga.harz.de>
jtjohnston (jtjohnston@courrier.usherb.ca) wrote:
> >>use URI::Escape;
> >>$in{'P1OC2Q1'} = uri_escape($in{'P1OC2Q1'}, "^A-Za-z");
>
> A luck would have it, when I tried my script on the University server,
> URI.pm was not installed in the last installation of libnet. Rather than
> wait 6 months, can anyone come up with an alternative to URI.pm. I have
> found this line of code, but does it escape everything?
>
> $in{'blah'} =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
No. This *de*codes. To (simplistically) encode:
$in{'blah'} =~ s/([^A-Za-z])/sprintf '%%%02X', ord $1/eg;
This, however, escapes way too many characters. OTOH, you could even use
(.) instead of ([^A-Za-z]).
And it assumes you do this in an ISO8859-1 environment.
cu,
Martin
--
So long, and thanks | Martin Vorlaender | VMS & WNT programmer
for all the books... | work: mv@pdv-systeme.de
In Memoriam Douglas Adams | http://www.pdv-systeme.de/users/martinv/
1952-2001 | home: martin@radiogaga.harz.de
------------------------------
Date: Sun, 19 Aug 2001 05:19:07 +0200
From: martin@radiogaga.harz.de (Martin Vorlaender)
Subject: Re: CGI Filter
Message-Id: <3b7f302b.524144494f47414741@radiogaga.harz.de>
bones10 (bones10@email.msn.com) wrote:
> I"m just learning perl. I'd like to create a CGI filter in perl, where
> the perl script is given a URL to a web page and the perl script then
> reads through the html file, possibly modifying it, and sends the results
> back out to the browser.
LWP should aid you to get the HTML file through the URL. Use HTML::Parser
to "read through it" (and interpret tags correctly - a necessity when
modifying it). print() should be enough to send it ;-)
> The URL to the web page could be restricted to refer a web
> page on the server.
LWP allows you to dissect an URL and replace the host part.
> The problem I'm running into is in finding where the html file actually
> exists on the server. I'd rather not hard code server side paths in the
> url that invokes the perl script.
Server side paths are not (necessarily) part of an URL.
Ask the web server to serve the page to your script.
cu,
Martin
--
One OS to rule them all | Martin Vorlaender | VMS & WNT programmer
One OS to find them | work: mv@pdv-systeme.de
One OS to bring them all | http://www.pdv-systeme.de/users/martinv/
And in the Darkness bind them.| home: martin@radiogaga.harz.de
------------------------------
Date: Sun, 19 Aug 2001 14:10:44 +0700
From: Komtanoo Pinpimai <romerun@greezi.com>
Subject: CODE reference to member function of package Confusing..
Message-Id: <9lnoob$agojt$1@ID-98172.news.dfncis.de>
Hi,
I've found many modules using some callback functions such as
$obj->set_handler('on_clicked',\&clicked);
this work with most programs. Users can set callback handlers to their
functions. But when I try to bind the callback to my method in a package
I can't do something like this:
$obj->set_handler('on_clicked', \&{$self->clicked} );
this is not work,
what should I do?
suggestion please...
Regards,
u40kpp.
------------------------------
Date: Sun, 19 Aug 2001 10:55:57 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Coercing list context onto pair of regexps in a comparison
Message-Id: <slrn9nu3kt.3ga.mgjv@martien.heliotrope.home>
On Sat, 18 Aug 2001 19:06:41 GMT,
Uri Guttman <uri@sysarch.com> wrote:
>>>>>> "EB" == Eric Bohlman <ebohlman@omsdev.com> writes:
>
> EB> Someone forging the name of Uri Guttman <uri@sysarch.com> wrote:
> >> When Charlie's violent fax machine moans, ...
>
> EB> I think there's potential for a song title here.
>
> and that was forged. i never wrote that. note among other things it
> doesn't have my signature.
Check the X-Complaints and X-Trace lines. With a willing news admin
there, you should be able to get a good idea where these came from.
Martien
--
Martien Verbruggen |
Interactive Media Division | I'm just very selective about what I
Commercial Dynamics Pty. Ltd. | accept as reality - Calvin
NSW, Australia |
------------------------------
Date: Sun, 19 Aug 2001 03:45:24 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Coercing list context onto pair of regexps in a comparison
Message-Id: <x7k800iug9.fsf@home.sysarch.com>
>>>>> "MV" == Martien Verbruggen <mgjv@tradingpost.com.au> writes:
MV> On Sat, 18 Aug 2001 19:06:41 GMT,
MV> Uri Guttman <uri@sysarch.com> wrote:
>>>>>>> "EB" == Eric Bohlman <ebohlman@omsdev.com> writes:
>>
EB> Someone forging the name of Uri Guttman <uri@sysarch.com> wrote:
>> >> When Charlie's violent fax machine moans, ...
>>
EB> I think there's potential for a song title here.
>>
>> and that was forged. i never wrote that. note among other things it
>> doesn't have my signature.
MV> Check the X-Complaints and X-Trace lines. With a willing news admin
MV> there, you should be able to get a good idea where these came from.
heh, this is att/mediaone cable. support or service? they never heard of
it. getting them to fix their b0rken news server is impossible.
anyhow, nobody believes i wrote that post. and it wasn't anything to
really worry about. now, if the forger keeps up with it, i can easily
change to another id from multiple domains.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org
------------------------------
Date: Sun, 19 Aug 2001 05:25:08 +0200
From: martin@radiogaga.harz.de (Martin Vorlaender)
Subject: Re: Color Coding Lexer for Editor
Message-Id: <3b7f3194.524144494f47414741@radiogaga.harz.de>
Buck Turgidson (noway@nohow.com) wrote:
> I want to use a CodeWright editor for Perl. I can do color-coding,
> formatting, etc if I build a lexer. Has someone done this before, and
> would be willing to share it with me.
>
> Or, does someone know of a keyword list for Perl, so I can build my
> own?
You obviously don't know that "Only perl can parse Perl".
You could, of course, duplicate the perl interpreter's lexer
with all its context thingies and special cases :-)
That said, there is a pretty good Cperl mode for Emacs; see the post
"Emacs modules for Perl programming".
cu,
Martin
--
OpenVMS: | Martin Vorlaender | VMS & WNT programmer
The operating system | work: mv@pdv-systeme.de
God runs the | http://www.pdv-systeme.de/users/martinv/
earth simulation on. | home: martin@radiogaga.harz.de
------------------------------
Date: Sun, 19 Aug 2001 01:58:34 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Copy file in Perl
Message-Id: <3B7F1D6D.C4460554@rochester.rr.com>
Philip Taylor wrote:
>
...
> (the `copy ...` method tries to access my floppy drive every time it
> runs the command, so I cannot include it in the test)
...
> --
> Philip Taylor
...
Hmmmm...you aren't by chance running McAfee VirusScan on Windoze 9x, are
you? If so, try a different virus checker, and maybe the annoying
"floppy read" will go away. It did for me.
--
Bob Walton
@b=reverse qw(5.343661747946449e10 -6.870680690767926e8
-1.975771987860562e11 2.131669362055020e9 3.109571746855627e11
-2.596991050289181e9 -2.730223404245535e11 1.509524556094990e9
1.473205544423461e11 -3.461473703699918e8 -5.076036670755333e10
-5.454741451803003e7 1.124701215943620e10 5.059108441610335e7
-1.575711669364010e9 -1.182973200557814e7 1.338518987279448e8
1.290612694169348e6 -6.387952390526651e6 -7.131700994976459e4
1.490495390583466e5 2.244925340775351e3 -1.247664152253088e3
-2.608118501828809e1);for(1..24){($_-=12.5)/=12.5;@c=@b;$a=0;
while(@c){($a*=$_)+=pop @c}print chr $a+95.7}
------------------------------
Date: Sun, 19 Aug 2001 11:16:59 +0200
From: Ernst Wernli <ernst.wernli@gibthun.ch>
Subject: Re: Copy file in Perl
Message-Id: <3B7F840B.FE26E42A@gibthun.ch>
--------------DDF67767195B4AE3C029E1C5
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Thank you all, very much!
Ernst Wernli, Switzerland
Ernst Wernli schrieb:
> Hi,
>
> I've to copy files with PERL. How can I do it?
>
> Exemple:
>
> N:\temp\test.htm
> N:\temp\last\test.htm
>
> Thank you
> Ernst
--------------DDF67767195B4AE3C029E1C5
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Thank you all, very much!
<p>Ernst Wernli, Switzerland
<br>
<br>
<p>Ernst Wernli schrieb:
<blockquote TYPE=CITE>Hi,
<p>I've to copy files with PERL. How can I do it?
<p>Exemple:
<blockquote>N:\temp\test.htm
<br>N:\temp\last\test.htm</blockquote>
Thank you
<br>Ernst</blockquote>
</html>
--------------DDF67767195B4AE3C029E1C5--
------------------------------
Date: Sun, 19 Aug 2001 15:49:07 +1000
From: Stephen Lohning <stephen@oxnee.com>
Subject: dec2hex conversion ,uninitialized value
Message-Id: <3B7F5353.669942F2@oxnee.com>
This function works but comes back with a warning uninitialized value
at hexStr, any idea why ?
And does anyone know how to get pack unpack to do decimal to hex string
conversions ?
Thanks
sub dec2hex{
my $dec = pop @_;
my $width = pop @_;
my @hex =
("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");
my @hexStr = ();
my $stringIndex = ();
$stringIndex =0;
#if( $dec >= 0 && $dec <= 0xFFFFFFFF){
my $k = ();
# @hexStr =();
for($k = 0; $k < $width; $k++){
$stringIndex = $dec % 16;
$hexStr[($width-$k)] = $hex[$stringIndex];
if( ( $dec - $stringIndex) >0){
$dec = ($dec - $stringIndex)/16;
}else{
$dec = 0;
}
}
#}
my $retStr = (join '',@hexStr); <--
return $retStr;
}
------------------------------
Date: Sun, 19 Aug 2001 08:10:24 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: dec2hex conversion ,uninitialized value
Message-Id: <3B7F74C8.4A890802@acm.org>
Stephen Lohning wrote:
>
> This function works but comes back with a warning uninitialized value
> at hexStr, any idea why ?
> And does anyone know how to get pack unpack to do decimal to hex string
> conversions ?
>
> Thanks
>
> sub dec2hex{
> my $dec = pop @_;
> my $width = pop @_;
> my @hex =
> ("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");
> my @hexStr = ();
> my $stringIndex = ();
> $stringIndex =0;
> #if( $dec >= 0 && $dec <= 0xFFFFFFFF){
> my $k = ();
> # @hexStr =();
> for($k = 0; $k < $width; $k++){
> $stringIndex = $dec % 16;
> $hexStr[($width-$k)] = $hex[$stringIndex];
> if( ( $dec - $stringIndex) >0){
> $dec = ($dec - $stringIndex)/16;
> }else{
> $dec = 0;
> }
> }
>
> #}
> my $retStr = (join '',@hexStr); <--
> return $retStr;
> }
sub dec2hex {
my $dec = pop @_;
my $width = pop @_;
return substr( sprintf( "%0${width}X", $dec ), -$width );
}
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sun, 19 Aug 2001 04:23:24 -0400
From: Samneric <samneric@tigerriverOMIT-THIS.com>
Subject: Re: dec2hex conversion ,uninitialized value
Message-Id: <MPG.15e94166a40b0bf7989689@news.usit.net>
Stephen Lohning wrote:
> This function works but comes back with a warning uninitialized value
> at hexStr, any idea why ?
[snip]
> for($k = 0; $k < $width; $k++){
$k is never equal to $width, right?
> $stringIndex = $dec % 16;
> $hexStr[($width-$k)] = $hex[$stringIndex];
So, ($width-$k) is never equal to zero,
The first element of @hexStr is always undef.
------------------------------
Date: Sun, 19 Aug 2001 04:40:20 GMT
From: "Zachary Kent" <zkent@adelphia.net>
Subject: dynamic variable question
Message-Id: <UqHf7.688$Rl5.1156143@news1.news.adelphia.net>
I have this code in my script quoting data stored in variables for an SQL
database. Instead of quoting the value of the variable itself, I would like
to make a new variable for the quoted value (i.e. $regEmail would be
unquoted and $regEmail_q would be quoted). How do I add the '_q' to the
end of the variable dynamically.
foreach $item ( qw( regEmail regEmailSecondary regUsername regPassword ) )
{
if (defined($$item)) {
$$item = $dbh->quote($$item);
} else {
$$item = 'NULL';
}
}
TIA,
Zach
------------------------------
Date: Sun, 19 Aug 2001 04:49:08 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: dynamic variable question
Message-Id: <x7elq8iri3.fsf@home.sysarch.com>
>>>>> "ZK" == Zachary Kent <zkent@adelphia.net> writes:
ZK> I have this code in my script quoting data stored in variables for
ZK> an SQL database. Instead of quoting the value of the variable
ZK> itself, I would like to make a new variable for the quoted value
ZK> (i.e. $regEmail would be unquoted and $regEmail_q would be
ZK> quoted). How do I add the '_q' to the end of the variable
ZK> dynamically.
ZK> foreach $item ( qw( regEmail regEmailSecondary regUsername regPassword ) )
ZK> {
ZK> if (defined($$item)) {
ZK> $$item = $dbh->quote($$item);
ZK> } else {
ZK> $$item = 'NULL';
ZK> }
ZK> }
don't use symbolic references. use a hash (or 2).
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org
------------------------------
Date: Sun, 19 Aug 2001 06:59:40 +0200
From: "Andreas Horvath" <ahorvath@cyberjus.com>
Subject: Re: dynamic variable question
Message-Id: <998196761.557153@fuchs.cyberlink.ch>
Zachary Kent <zkent@adelphia.net> schrieb:
> I have this code in my script quoting data stored in variables for an SQL
> database. Instead of quoting the value of the variable itself, I would
like
> to make a new variable for the quoted value (i.e. $regEmail would be
> unquoted and $regEmail_q would be quoted). How do I add the '_q' to the
> end of the variable dynamically.
>
> foreach $item ( qw( regEmail regEmailSecondary regUsername
regPassword ) )
> {
> if (defined($$item)) {
> $$item = $dbh->quote($$item);
${"${item}_q"} = $dbh->quote($$item);
> } else {
> $$item = 'NULL';
> }
> }
HTH, andy
------------------------------
Date: Sun, 19 Aug 2001 04:56:44 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: dynamic variable question
Message-Id: <x7ae0wir5d.fsf@home.sysarch.com>
>>>>> "AH" == Andreas Horvath <ahorvath@cyberjus.com> writes:
AH> Zachary Kent <zkent@adelphia.net> schrieb:
>> I have this code in my script quoting data stored in variables for an SQL
>> database. Instead of quoting the value of the variable itself, I would
AH> like
>> to make a new variable for the quoted value (i.e. $regEmail would be
>> unquoted and $regEmail_q would be quoted). How do I add the '_q' to the
>> end of the variable dynamically.
>>
>> foreach $item ( qw( regEmail regEmailSecondary regUsername
AH> regPassword ) )
>> {
>> if (defined($$item)) {
>> $$item = $dbh->quote($$item);
AH> ${"${item}_q"} = $dbh->quote($$item);
don't encourage symrefs. it is a bad solution and you should ban it from
your head.
hashes are the correct solution.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org
------------------------------
Date: Sun, 19 Aug 2001 06:17:01 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: I'm having trouble matching over more than one line. What's wrong?
Message-Id: <xRIf7.244$V3.175066624@news.frii.net>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.
+
I'm having trouble matching over more than one line. What's wrong?
Either you don't have more than one line in the string you're looking at
(probably), or else you aren't using the correct modifier(s) on your
pattern (possibly).
There are many ways to get multiline data into a string. If you want it
to happen automatically while reading input, you'll want to set $/
(probably to '' for paragraphs or "undef" for the whole file) to allow
you to read more than one line at a time.
Read the perlre manpage to help you decide which of "/s" and "/m" (or
both) you might want to use: "/s" allows dot to include newline, and
"/m" allows caret and dollar to match next to a newline, not just at the
end of the string. You do need to make sure that you've actually got a
multiline string in there.
For example, this program detects duplicate words, even when they span
line breaks (but not paragraph ones). For this example, we don't need
"/s" because we aren't using dot in a regular expression that we want to
cross line boundaries. Neither do we need "/m" because we aren't wanting
caret or dollar to match at any point inside the record next to
newlines. But it's imperative that $/ be set to something other than the
default, or else we won't actually ever have a multiline record read in.
$/ = ''; # read in more whole paragraph, not just one line
while ( <> ) {
while ( /\b([\w'-]+)(\s+\1)+\b/gi ) { # word starts alpha
print "Duplicate $1 at paragraph $.\n";
}
}
Here's code that finds sentences that begin with "From " (which would be
mangled by many mailers):
$/ = ''; # read in more whole paragraph, not just one line
while ( <> ) {
while ( /^From /gm ) { # /m makes ^ match next to \n
print "leading from in paragraph $.\n";
}
}
Here's code that finds everything between START and END in a paragraph:
undef $/; # read in whole file, not just one line or paragraph
while ( <> ) {
while ( /START(.*?)END/sm ) { # /s makes . cross line boundaries
print "$1\n";
}
}
-
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to
news:news.answers
or to the many thousands of other useful Usenet news groups.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-1999 Tom Christiansen and Nathan
Torkington. All rights reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
06.02
--
This space intentionally left blank
------------------------------
Date: Sun, 19 Aug 2001 05:32:07 +0200
From: martin@radiogaga.harz.de (Martin Vorlaender)
Subject: Re: From UNIX to Windows
Message-Id: <3b7f3337.524144494f47414741@radiogaga.harz.de>
Kev The Condenser (mkc@aon.at) wrote:
> Benjamin Goldberg wrote:
> > try this code:
> > #!/usr/local/bin/perl -wT
> > use strict;
> > use CGI;
> >
> > print header, begin_html;
> > print "<H1>Hellow World</H1>";
> > print end_html;
> > __END__
>
> did not thought that the CGI module would be _that_ powerful:)
> used it only for getting GETted parameters...
You could even replace the "<H1>...</H1>" stuff by h1(...). CGI,pm has
functions for (almost?) all HTML tags.
cu,
Martin
--
OpenVMS: | Martin Vorlaender | VMS & WNT programmer
The operating system | work: mv@pdv-systeme.de
God runs the | http://www.pdv-systeme.de/users/martinv/
earth simulation on. | home: martin@radiogaga.harz.de
------------------------------
Date: Sun, 19 Aug 2001 02:49:07 GMT
From: "Mark Riehl" <mark.riehl@agilecommunications.com>
Subject: Hash of Complex Records
Message-Id: <DOFf7.442$uC2.197009@typhoon1.gnilink.net>
All - I followed the complex records example in the Camel book, and had a
few questions. Here's my data structure:
# %LocationData = (
# 1001 => {
# records => [
# { time=>"8456823", latitude=>"35.311",
longitude=>"-116.4101", },
# { time=>"8456824", latitude=>"35.312",
longitude=>"-116.4201", },
# { time=>"8456825", latitude=>"35.313",
longitude=>"-116.4301", },
# ],
# },
# );
Basically, 1001 is a vehicle id, and I have movement data for each vehicle.
I've got a few hundred vehicles, so this is repeated.
Question - how do I use exists() to see if a vehicle is in the LocationData
hash? I tried the following:
if (exists ($LocationData{1001}) ) {
...
}
But this isn't working. If I use the following, it works:
my $test = 1001;
my ($key, $who);
for $key (keys %LocationData) {
if ($key == $test) {
print "Yes, test exists\n";
}
Any suggestions? I'd rather not loop through all the hashes if I can just
use exists().
Thanks,
Mark
------------------------------
Date: Sun, 19 Aug 2001 02:21:25 -0400
From: Samneric <samneric@tigerriverOMIT-THIS.com>
Subject: Re: Hash of Complex Records
Message-Id: <MPG.15e924f2de99d511989688@news.usit.net>
Mark Riehl wrote:
> Question - how do I use exists() to see if a vehicle is in the LocationData
> hash? I tried the following:
>
> if (exists ($LocationData{1001}) ) {
> ...
> }
>
> But this isn't working.
If your example code wasn't copied from your actual code, then your example
doesn't reflect the problem that you encountered (and is actually better-
written). If the code within the "if" block didn't give you what you expected,
then maybe that's why you assumed that the condition wasn't being met.
This works, and it reflects your own example:
************
#!/usr/bin/perl -w
use strict;
my %LocationData = (
1001 => {
records => [
{ time => "8456823", lat => "35.311", long => "-116.4101", },
{ time => "8456824", lat => "35.312", long => "-116.4201", },
{ time => "8456825", lat => "35.313", long => "-116.4301", },
],
},
);
if (exists ($LocationData{1001})) {
print "Time 0: $LocationData{1001}{records}[0]{time}\n";
}
else {
print "1001 does not exist\n";
}
********
Time 0: 8456823
********
BTW, unless you want to add another key to %{$LocationData{1001}}, then that
hash containing the single "records" key is an un-needed level of complexity.
my %LocationData = (
1001 => [
{ time => "8456823", lat => "35.311", long => "-116.4101", },
{ time => "8456824", lat => "35.312", long => "-116.4201", },
{ time => "8456825", lat => "35.313", long => "-116.4301", },
],
};
------------------------------
Date: Sun, 19 Aug 2001 05:40:04 +0200
From: martin@radiogaga.harz.de (Martin Vorlaender)
Subject: Re: How to call ISAPI dll from perl?
Message-Id: <3b7f3514.524144494f47414741@radiogaga.harz.de>
chch (chch@kyokofukada.net) wrote:
> How I call my isapi dll from perl script?
> that isapi link like as http://127.0.0.1/scripts/testisapi.dll?a=xx&b=yy
use LWP::Simple;
$content = get('http://127.0.0.1/scripts/testisapi.dll?a=xx&b=yy');
If the libwww-perl (LWP) isn't installed on your server, please let the
system admin find it on CPAN and install it.
cu,
Martin
--
| Martin Vorlaender | VMS & WNT programmer
OpenVMS: When you | work: mv@pdv-systeme.de
KNOW where you want | http://www.pdv-systeme.de/users/martinv/
to go today. | home: martin@radiogaga.harz.de
------------------------------
Date: 18 Aug 2001 20:51:38 -0700
From: sgarfunkle@hotmail.com (Jay McGavren)
Subject: Re: IO::Socket::INET - Setting Reset bit when closing TCP connection?
Message-Id: <6bb557e1.0108181951.d45a2da@posting.google.com>
mfuhr@dimensional.com (Michael Fuhr) wrote:
> Calling shutdown(SHUT_WR) or shutdown(SHUT_RDWR) should send a FIN,
> which is the proper way to close a TCP connection but isn't the desired
> behavior in this case.
Yup; tried that and got the same result as close($socket), I'm afraid.
> You might be able to use the SO_LINGER socket option to send RST instead
> of FIN when you close the socket. The following example works for me:
Bingo! Both my example and my full script work properly now.
> Hope this helps.
Sure did! The reference material is a little over my head, but that
may be helpful at some point, too. Many thanks!
------------------------------
Date: Sun, 19 Aug 2001 11:17:16 +0200
From: "Guy" <guymal@__NOSPAM__hotmail.com>
Subject: Is element in array
Message-Id: <3b7f7695$1@news.barak.net.il>
How can test a scalar to see if it is an element in a given array?
Example:
@bla=("one","two","three");
if ("two" IS IN @bla) #returns true
{
#this code would be executed
....
}
if ("four" IS IN @bla)#returns false
{
#this code would not be executed
}
TIA,
Guy
------------------------------
Date: 19 Aug 2001 09:02:41 GMT
From: Tassilo.Parseval@post.rwth-aachen.de (Tassilo v. Parseval)
Subject: Re: Is element in array
Message-Id: <9lnvbh$16u$1@nets3.rz.RWTH-Aachen.DE>
On Sun, 19 Aug 2001 11:17:16 +0200, Guy <guymal@__NOSPAM__hotmail.com> wrote:
> How can test a scalar to see if it is an element in a given array?
> Example:
> @bla=("one","two","three");
You could always iterate over the array:
my $in_array;
for my $item (@bla) {
if ($item eq 'two') {
$in_array++;
last;
}
}
if ($in_array) { ... }
Or you could create a hash where you fill in the array-elements as a
key. Yet, this always loops over the whole array which only makes sense
if you often test for a value being in the array. Thus, you would only
create the %seen-hash once and each time you test for a value you simply
check whether $seen{key} exists.
my %seen;
$seen{$_}++ for (@bla);
if (exists $seen{two}) { ... }
In case you are lazy you could also use grep:
if (grep {$_ eq 'two} @bla) { print "Yes, it is there" }
But again, this always iterates over the whole array which makes it sort
of slow.
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: 19 Aug 2001 01:43:27 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Local Perl via browser
Message-Id: <9ln5jv$5qi$1@bob.news.rcn.net>
Tad McClellan <tadmc@augustmail.com> wrote:
> I knew that of course, but I figure:
> PerlScript is not Perl.
> If it was, it would be called Perl, not PerlScript.
Actually, PerlScript is simply a wrapper around perl that gives it an
ActiveX interface of the sort that many MS applications expect. The
language involved *is* Perl; it's not at all analogous to the relationship
between JavaScript and Java.
------------------------------
Date: 19 Aug 2001 00:34:30 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Local Perl via browser
Message-Id: <9lnj56$s95$1@charity.cs.utexas.edu>
In article <9ln5jv$5qi$1@bob.news.rcn.net>,
Eric Bohlman <ebohlman@omsdev.com> wrote:
>Actually, PerlScript is simply a wrapper around perl that gives it an
>ActiveX interface of the sort that many MS applications expect. The
>language involved *is* Perl; it's not at all analogous to the relationship
>between JavaScript and Java.
There's a relationshiop between JavaScript and Java?
- Logan
--
"Our grandkids love that we get Roadrunner and digital cable."
(Advertisement for Time Warner cable TV and internet access, July 2001)
------------------------------
Date: Sun, 19 Aug 2001 02:15:08 -0400
From: David Coppit <newspost@coppit.org>
Subject: Re: Local Perl via browser
Message-Id: <3B7F596C.9050509@coppit.org>
Logan Shaw wrote:
> In article <9ln5jv$5qi$1@bob.news.rcn.net>,
> Eric Bohlman <ebohlman@omsdev.com> wrote:
>
>>Actually, PerlScript is simply a wrapper around perl that gives it an
>>ActiveX interface of the sort that many MS applications expect. The
>>language involved *is* Perl; it's not at all analogous to the relationship
>>between JavaScript and Java.
>
> There's a relationshiop between JavaScript and Java?
They're totally different languages. The former is named like the latter
in a misguided marketing ploy to gain mindshare. PerlScript is basically
Perl under the covers. JavaScript has no such relationship to Java.
David
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 1563
***************************************