[21759] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3963 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 13 18:12:21 2002

Date: Sun, 13 Oct 2002 15:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 13 Oct 2002     Volume: 10 Number: 3963

Today's topics:
    Re: 96-column punched-card data <bik.mido@tiscalinet.it>
        Array Assigning problem .. <ken_mahi@hotmail.com>
    Re: Array Assigning problem .. <jkeen@concentric.net>
    Re: Array Assigning problem .. <s_grazzini@hotmail.com>
    Re: Array Assigning problem .. <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Array assigning program .. <Tassilo.Parseval@post.rwth-aachen.de>
    Re: complex hash structure -- any ideas? <goldbb2@earthlink.net>
        E-mail reader questions  Oct. 13, 2002 <edgrsprj@ix.netcom.com>
        Emacs modules for Perl programming (Jari Aalto+mail.perl)
    Re: Email link to a word Document <nobody@dev.null>
        Having problems with SMTP  <tim@nonspam_melonhead.net>
    Re: Having problems with SMTP <Juha.Laiho@iki.fi>
    Re: How to create a bundle? <dd@4pro.net>
    Re: How to create a bundle? <dd@4pro.net>
    Re: Multiple Pings/Second <goldbb2@earthlink.net>
    Re: newb here learning Perl <bart.lateur@pandora.be>
    Re: undef == true? <bart.lateur@pandora.be>
    Re: use strict (Tad McClellan)
        Using Perl to solve interesting Banking Probm .. <ken_mahi@hotmail.com>
    Re: Using Perl to solve interesting Banking Probm .. <jkeen@concentric.net>
    Re: Using Perl to solve interesting Banking Probm .. (Jay Tilton)
        Weird Race Condition (Shannon Appelcline)
    Re: Weird Race Condition <Juha.Laiho@iki.fi>
    Re: Weird Race Condition <s_grazzini@hotmail.com>
        What purpose does eval{ ... } server? <me@hotmail.com>
    Re: What purpose does eval{ ... } server? <goldbb2@earthlink.net>
    Re: What purpose does eval{ ... } server? <nospam@nospam.com>
    Re: What purpose does eval{ ... } server? <s_grazzini@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 13 Oct 2002 17:06:12 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: 96-column punched-card data
Message-Id: <dskequ8hio2060ef7cn7jqggm413vb9fo2@4ax.com>

On Fri, 11 Oct 2002 14:50:00 -0400, Benjamin Goldberg
<goldbb2@earthlink.net> wrote:

[now OT wrt the OP]

>The + serves the same purpose as the parens, except that it's one
>character, not two.

thanks, if I were smarter I would have found it by myself in the
perlop manpage:

Unary ``+'' has no effect whatsoever, even on strings. It is useful
syntactically for separating a function name from a parenthesized
expression that would otherwise be interpreted as the complete list of
function arguments. (See examples above under Terms and List Operators
(Leftward).)


Michele
-- 
Liberta' va cercando, ch'e' si' cara,
Come sa chi per lei vita rifiuta.
           [Dante Alighieri, Purg. I, 71-72]

I am my own country - United States Confederate of Me!
           [Pennywise, "My own country"]


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

Date: Sun, 13 Oct 2002 11:41:15 -0700
From: KM <ken_mahi@hotmail.com>
Subject: Array Assigning problem ..
Message-Id: <3DA9BE4B.472768F1@hotmail.com>

Can anyone tell me how to do this array assigning program  ..

e.g -

@sym = qw (Rat, Ox, Tiger, Rabbit, Dragon, Snake, Horse, Goat, Monkey,
Rooster, Dog, Pig);

@per = (1900..1911);    # 1900 to 1911 are 12 yrs assigned to the above
array for the respective year


I want to write a program that will print the 'symbol' from the 1st
array,  for the respective scalar data of the 2nd array ..


~ Thank you





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

Date: 13 Oct 2002 19:26:15 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: Array Assigning problem ..
Message-Id: <aochcn$pqt@dispatch.concentric.net>


"KM" <ken_mahi@hotmail.com> wrote in message
news:3DA9BE4B.472768F1@hotmail.com...
> Can anyone tell me how to do this array assigning program  ..
>
> e.g -
>
> @sym = qw (Rat, Ox, Tiger, Rabbit, Dragon, Snake, Horse, Goat, Monkey,
> Rooster, Dog, Pig);
>

First, study enough Perl to understand what's wrong with the syntax of the
'qw' operator above.  If you had actually attempted a script and called 'use
strict', you would have immediately gotten an error message.

> @per = (1900..1911);    # 1900 to 1911 are 12 yrs assigned to the above
> array for the respective year
>
> I want to write a program that will print the 'symbol' from the 1st
> array,  for the respective scalar data of the 2nd array ..
>
The word 'for' in your statement above is the key to the problem.

> ~ Thank you
>
>
>




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

Date: 13 Oct 2002 13:35:09 -0600
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: Array Assigning problem ..
Message-Id: <3da9caec@news.mhogaming.com>

KM <ken_mahi@hotmail.com> wrote:
> Can anyone tell me how to do this array assigning program 
 ...

> @sym = qw (Rat, Ox, Tiger, Rabbit, Dragon, Snake, Horse, Goat, 
> Monkey, Rooster, Dog, Pig);

Don't think you want commas there.

> @per = (1900..1911);    # 1900 to 1911 are 12 yrs assigned to the 
> above array for the respective year
> 
> I want to write a program that will print the 'symbol' from the 1st
> array,  for the respective scalar data of the 2nd array ..
> 

You're looking for "hashes".

  $ perldoc perldata

But since you haven't encountered this already, you might
be better off with one of the good introductory Perl books.

-- 
Steve

perldoc -qa.j | perl -lpe '($_)=m("(.*)")'


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

Date: 13 Oct 2002 20:13:11 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Array Assigning problem ..
Message-Id: <aock4n$a61$1@nets3.rz.RWTH-Aachen.DE>

Also sprach KM:

> Can anyone tell me how to do this array assigning program  ..

[...]

Arrrgh! I should have known. If you want to post to several groups, then
please do a proper cross-post. Multi-posts are very annoying and cause
considerable confusion.

Tassilo
-- 
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;


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

Date: 13 Oct 2002 20:07:20 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Array assigning program ..
Message-Id: <aocjpo$9r0$1@nets3.rz.RWTH-Aachen.DE>

[ full-quote because of X-post to clpc]

Also sprach KM:
> Can anyone tell me how to do this array assigning program  ..
> 
> e.g -
> 
> @sym = qw (Rat, Ox, Tiger, Rabbit, Dragon, Snake, Horse, Goat, Monkey,
> Rooster, Dog, Pig);
> 
> @per = (1900..1911);    # 1900 to 1911 are 12 yrs assigned to the above
> array for the respective year
> 
> 
> I want to write a program that will print the 'symbol' from the 1st
> array,  for the respective scalar data of the 2nd array ..

First step would be to properly declare the symbols array. qw() does an
implicit split on whitespaces so you need to get rid of the commata.

After that, you can iterate over the two arrays in parallel:

    my @sym = qw(Rat Ox Tiger Rabbit Dragon Snake Horse Goat Monkey
                 Rooster Dog Pig);
    my @per = (1900 .. 1911);

    for my $y (0 .. $#sym) {
        print "$per[$y]: year of the $sym[$y]\n";
    }
    
Tassilo

PS: follow-up to clpm
-- 
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;


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

Date: Sun, 13 Oct 2002 16:56:32 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: complex hash structure -- any ideas?
Message-Id: <3DA9DE00.D4B91B8@earthlink.net>

Jeremy Miller wrote:
> 
> Hello,
> I've recently taken on a project involving mapping out a network
> device's
> physical slots, ports, logical ports and pvcs.. Anyhow, I'm running
> into a situation where I would like to present the data in a
> hierarchical way so that it's easy to read and understand, but storing
> the data in an elegant fashion is posing quite a challenge.  Here's
> the output I would like to have:
> 
> SLOT    PPORT   LPORT   PVC     STATE
> ------- ------- ------- ------- -------
> 13 .... ....... ....... ....... up
>         1 ..... ....... ....... up
>                 19 .... ....... down
>         2 ..... ....... ....... up
>                 19 .... ....... down
>                 30 .... ....... down
>                         200 ... inactive
> 14 .... ....... ....... ....... down
>         2 ..... ....... ....... down
>                 37 .... ....... down
>                         33 .... inactive
>                         131147  inactive
> 
> As you can see, I need to be able to keep track of all "slots", each
> "pport" on the "slot", each "lport" on each "pport", each "pvc" on
> each "lport" and finally, the "state" of each item.  I currently have
> all the above data in various hashes, and can print it individually,
> but would like to combine them into one, so that I can have one main
> loop to access and print the data in a nice way =)  Anybody have any
> ideas/insight??

Recursion?

sub print_one_line {
   my ($depth, $key, $val) = @_;
   print " " x (8*$depth);
   print substr( $key . , 0, 7 );
   print " ......." for 1 .. 3-$depth;
   print " ", $val, "\n";
}

sub print_stuff {
   my ($depth, $key_a, $hashref) = @_;
   print_one_line( $depth, $key_a, $hashref->{STATE} )
      if $depth >= 0;
   while( my ($key, $val) = each %$hashref ) {
      next if $key eq "STATE";
      print_stuff( $depth+1, $key, $val );
   }
}

while( my( $host, $info ) = each %elements ) {
   print $host, "\n";
   print_stuff( -1, undef, $info );
}

[untested]

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Sun, 13 Oct 2002 10:32:57 -0500
From: "E.D.G." <edgrsprj@ix.netcom.com>
Subject: E-mail reader questions  Oct. 13, 2002
Message-Id: <aoc3sa$kac$1@slb6.atl.mindspring.net>

From:  E.D.G.  Professional Analyst  edgrsprj@ix.netcom.com
Web Sites:  http://www.freewebz.com/eq-forecasting/index.html
http://home.netcom.com/~edgrsprj/index.html
Date:  October 13, 2002

The e-mail related questions in this report have to do with some important
earthquake research.  If people wish to post their responses to a single
Newsgroup then I will propose that comp.lang.perl.misc might be the most
appropriate one.

A number of people are presently working informally on what is being
discussed here in addition to myself.  And if these technical problems can
be solved then I believe that more people will probably soon become involved
with the effort.

GOAL:  Earthquake data are listed at the following Web site and other
similar sites:

http://wwwneic.cr.usgs.gov/neis/bulletin/

It is possible to have earthquake data like those sent to you by e-mail.
What we would want to do is have those types of data sent to a domain (Web
site) related e-mail address such as address@ . .org.  And each time a
message arrives a PERL CGI program running at the domain Web site would
extract data such as earthquake time, latitude, longitude, magnitude etc.
from the message and store them in a file at the Web site.  The CGI program
would also automatically add some additional information to each data line.
Data copyright formalities would of course be observed.

QUESTIONS:

***  Does anyone know of any Internet servers which allow automatic e-mail
reading programs like that to run.  We already have a domain on a particular
server.  But it does not allow you to run preset time activated (cron?)
programs.  And I have been unable to discover from anyone if e-mail arrival
activated CGI programs can be run there or if you can even run any type of
CGI program which will read e-mail messages sent to Web site addresses.

***  Does anyone know where to locate PERL modules which are designed to
read e-mail messages sent to a Web site address and then store information
extracted from them in a Web site file?

A few years ago, several of us were running a Web site on a server which did
allow you to do those types of things.  However the servers on which I have
my present personal Internet accounts apparently do not allow this for those
types of Web sites.  And as I said, I have been unable to determine if this
can be done on another server which is presently in use.





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

Date: 13 Oct 2002 15:34:49 GMT
From: <jari.aalto@poboxes.com> (Jari Aalto+mail.perl)
Subject: Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_1034523049@rtfm.mit.edu>

Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
URL: http://tiny-tools.sourceforge.net/
Maintainer: Jari Aalto <jari.aalto@poboxes.com>

Announcement: "What Emacs lisp modules can help with programming Perl"

    Preface

        Emacs is your friend if you have to do anything comcerning software
        development: It offers plug-in modules, written in Emacs lisp
        (elisp) language, that makes all your programmings wishes come
        true. Please introduce yourself to Emacs and your programming era
        will get a new light.

    Where to find Emacs/XEmacs

        o   Unix:
            http://www.gnu.org/software/emacs/emacs.html
            http://www.xemacs.org/

        o   Unix Windows port (for Unix die-hards):
            install http://www.cygwin.com/  which includes native Emacs 21.x.
            XEmacs port is bundled in XEmacs setup.exe available from
            XEmacs site.

        o   Pure Native Windows port
            http://www.gnu.org/software/emacs/windows/ntemacs.html
            ftp://ftp.xemacs.org/pub/xemacs/windows/setup.exe

        o   More Emacs resources at
            http://tiny-tools.sourceforge.net/  => Emacs resource page

Emacs Perl Modules

    Cperl -- Perl programming mode

        ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl
        http://www.perl.com/CPAN-local/misc/emacs/cperl-mode/
        <ilya@math.ohio-state.edu>    Ilya Zakharevich

        CPerl is major mode for editing perl files. Forget the default
        `perl-mode' that comes with Emacs, this is much better. Comes
        standard in newest Emacs.

    TinyPerl -- Perl related utilities

        http://tiny-tools.sourceforge.net/

        If you ever wonder how to deal with Perl POD pages or how to find
        documentation from all perl manpages, this package is for you.
        Couple of keystrokes and all the documentaion is in your hands.

        o   Instant function help: See documentation of `shift', `pop'...
        o   Show Perl manual pages in *pod* buffer
        o   Grep through all Perl manpages (.pod)
        o   Follow POD references e.g. [perlre] to next pod with RETURN
        o   Coloured pod pages with `font-lock'
        o   Separate `tiperl-pod-view-mode' for jumping topics and pages
            forward and backward in *pod* buffer.

        o   Update `$VERSION' variable with YYYY.MMDD on save.
        o   Load source code into Emacs, like Devel::DProf.pm
        o   Prepare script (version numbering) and Upload it to PAUSE
        o   Generate autoload STUBS (Devel::SelfStubber) for you
            Perl Module (.pm)

    TinyIgrep -- Perl Code browsing and easy grepping

        [TinyIgrep is included in Tiny Tools Kit]

        To grep from all installed Perl modules, define database to
        TinyIgrep. There is example file emacs-rc-tinyigrep.el that shows
        how to set up dattabases for Perl5, Perl4 whatever you have
        installed

        TinyIgrep calls Igrep.el to to do the search, You can adjust
        recursive grep options, set search case sensitivity, add user grep
        options etc.

        You can find latest `igrep.el' module at
        <http://groups.google.com/groups?group=gnu.emacs.sources> The
        maintainer is Jefin Rodgers <kevinr@ihs.com>.

    TinyCompile -- To Browse grep results in Emacs *compile* buffer

        TinyCompile is a minor mode for *compile* buffer from where
        you can collapse unwanted lines or shorten file URLs:

            /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
            /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT

            -->

            cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
            file1:NNN: MATCHED TEXT
            file1:NNN: MATCHED TEXT

End



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

Date: Sun, 13 Oct 2002 16:18:45 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: Email link to a word Document
Message-Id: <3DA99D2E.3040803@dev.null>



GetWebWise wrote:

> Hi there
> 
> I am a real perl/html novice....
> 
> II am using a form to send an email, in which I would like a link to a word
> document or zip file.
> 
> Please can someone help me understand how to make this work. 
> 
> #     open(REPLY, "|/usr/sbin/sendmail -t");
> #     print REPLY "To: $email \n"; # SEND TO ENQUIRER
> #     print REPLY "From: $emailsales \n";
> #     print REPLY "Subject: Internet Enquiry \n";
> #     print REPLY "Dear $fn \n";
> #     print REPLY "I have just received your enquiry which is being processed.
> \n";
> #     print REPLY " \n";
> 
>        This is the part I cannot seem to make work??? -----------
> #     print REPLY "<HREF="http://www.cleanandeasymoney.co.uk/cgi-
> #     bin/infopack/infopack.doc">Click Here to Download Information Pack>
> \n\n";
> 
> Thank you
> Ian
> 
> 

Well, you can start by uncommenting your code :-)

Your biggest problem is that you are trying to nest double quotes within 
     double quotes in your last print statement. Instead, you could do 
something along the lines of

print REPLY qq[<a href="http://www.sleazymoney.con">Avoid me</a>\n\n];

You have other problems, too. The HTML you are printing is totally 
bogus. Your HREF wants an A before it and you also need a closing </A> tag.

I guess it would also help if the document 
http://www.cleanandeasymoney.co.uk/cgi-bin/infopack/infopack.doc 
actually existed :-)







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

Date: Sun, 13 Oct 2002 15:40:19 +0100
From: "melonhead" <tim@nonspam_melonhead.net>
Subject: Having problems with SMTP 
Message-Id: <1034520018.66245.0@dyke.uk.clara.net>

Using Perl 5.8.0 under RH 8.0 and trying to do some code to use SMTP.  My
code does something like:

$smtp->($from);
where $from is "Melon Head" <melonhead@test.com>

What actually gets sent (set debug on to have a peek) is:
MAIL FROM:<"Melon Head <melonhead@test.com>

So it's putting the extra < in after FROM: and the SMTP keeps throwing it
out.  I've tested this on Activeperl under w2k and it seems to work there,
the docs & RFC fon't seem to help much, does anyone have any ideas?

regards,




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

Date: Sun, 13 Oct 2002 18:47:01 GMT
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: Having problems with SMTP
Message-Id: <aocf17$tea$1@ichaos.ichaos-int>

"melonhead" <tim@nonspam_melonhead.net> said:
>Using Perl 5.8.0 under RH 8.0 and trying to do some code to use SMTP.  My
>code does something like:
>
>$smtp->($from);
>where $from is "Melon Head" <melonhead@test.com>
>
>What actually gets sent (set debug on to have a peek) is:
>MAIL FROM:<"Melon Head <melonhead@test.com>
>
>So it's putting the extra < in after FROM: and the SMTP keeps throwing it
>out.  I've tested this on Activeperl under w2k and it seems to work there,
>the docs & RFC fon't seem to help much, does anyone have any ideas?

Mail has two sets of address information, the ones on the envelope
and the ones in the message headers. The address information on the
envelope is limited to the "technical" address only, i.e.
recipient@domain.example . This is what you're setting with
$smtp->mail($from) (assuming it's Net::SMTP you're talking about).
The more "free-form" sender address should be placed into the message
headers (i.e. to whatever you're sending with $smtp->data() ).
-- 
Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
         PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)


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

Date: Sun, 13 Oct 2002 09:17:41 -0400
From: "Domizio Demichelis" <dd@4pro.net>
Subject: Re: How to create a bundle?
Message-Id: <aobrr5$l46rn$1@ID-159100.news.dfncis.de>

> > I found just a little section in the CPAN pod, nothing at all in the
faq,
>
> Are you sure?
> See
>     http://www.cpan.org/misc/cpan-faq.html#How_make_bundle

hmmm... I didn't search in that faq :-) (I didn't even know that there was
different faq than the installed one)

C:\>perldoc -f bundle
No documentation for perl function `bundle' found

Thank you

Grazie ;-)

--
-.. --- -- .. --.. .. ---
-.. . -- .. -.-. .... . .-.. .. ...


"Enrico Sorcinelli" <enrico@sorcinelli.it> wrote in message
news:3DA96C7D.A48219DA@sorcinelli.it...
> Domizio Demichelis wrote:
>
>
>     - Enrico
>




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

Date: Sun, 13 Oct 2002 09:29:04 -0400
From: "Domizio Demichelis" <dd@4pro.net>
Subject: Re: How to create a bundle?
Message-Id: <aobsp4$l867l$1@ID-159100.news.dfncis.de>

ooops... I mean

C:\>perldoc -q bundle
No documentation for perl FAQ keyword `bundle' found

--
-.. --- -- .. --.. .. ---
-.. . -- .. -.-. .... . .-.. .. ...




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

Date: Sun, 13 Oct 2002 16:31:47 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Multiple Pings/Second
Message-Id: <3DA9D833.FD84E5F@earthlink.net>

smackdab wrote:
> 
> Wow what great timing...I was looking @ trying to do this, gave up and
> then saw these posts.  I have used an example of yours for nonblocking
> port scanning, which works great (took me a while to understand it
> though...)
> It used IO::Select, which seems easier for us beginners...
> 
> I can't get this to run, I currently get
>     Error in recv: Unknown error at test.pl line 53.
> Here are the lines:
> my $resp =  "";
> my $responder = recv( $socket, $resp, 8, 0 )
>      or die "Error in recv: $!"; # shouldn't happen.

Whenever I see $! produce an "Unknown error" string, I try changing it
to $^E... then, if that doesn't print anything useful, I try printing
out the numeric value of $! or $^E, and then doing a google search to
find out which Windows Socket Error that is.

If you're not on windows, this advice might not help (there are other
systems than windows where $^E prints something more useful than $!, but
obviously on non-windows platforms you can't lookup WSA-errors)

> (I changed the my ($resp), as I saw the above in another book, but
> it didn't help...).  $socket is valid at this point...
> 
> This line was confusing, so I dropped the $t as my book only
> said 1 thing came back from this call...
> I noticed that IO::Select->select() returns 3 things though...
> #(my ($n), $t) = select($rvec, $wvec, '', 0.5);
> my $n = select($rvec, $wvec, '', 0.5);

Hmm... I suppose that if you don't use $t (which an earlier version of
my code did), then they are equivilant.

> It *seems* to create the socket and call the select, but I never
> see it call send().
>
> This line:
> if( $wvec =~ tr/^\0// ) {
> Is it looking for a NULL in a buffer...

No, it is looking for a NON-nul in the w-vector.

> don't understand this whole part, as $wvec is a "@" or a "." ... well
> beyond me ;-)

The $wvec variable is a bitvector, created with vec().  The only
properties of it that we care about are whether or not:
   vec( $wvec, fileno($socket), 1 )
is a true expression.

It will have a value of "", or of "\000", or (assuming that
fileno($socket) is 3), "\008", which is an unprintable character.

The string "\000" prints out as "^@" on many systems.  I don't see how
you got the string "." ... that seems to be an impossible value.

If it makes more sense to you, consider changing the if statement from:
   if( $wvec =~ tr/^\0// ) {
to:
   if( vec $wvec, fileno($socket), 1 ) {
Or perhaps to:
   if( $wvec eq $svec ) {

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Sun, 13 Oct 2002 15:38:46 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: newb here learning Perl
Message-Id: <0r4jquk8ndcgimp2bub0bccj3lber2pco9@4ax.com>

Alex wrote:

>> I hope to learn and become proficient at Perl
>
>www.perlmonks.com has a lot of useful info including FAQs as well.

And there are a few mailing lists for newbies as well. See
<http://learn.perl.org> for some pointers.

-- 
	Bart.


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

Date: Sun, 13 Oct 2002 15:31:12 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: undef == true?
Message-Id: <644jquk17q5903c6e2k66frrod2g07jr4u@4ax.com>

Tad McClellan wrote:

>If the code is similar to what's in your Subject,
>then it is _supposed_ to evaluate to true, since zero
>_is_ numerically equal to zero.

Good catch. For the OP, for I think this went straight over his head:

	print 'yes' if undef == true;
-->
	yes

Under -w, you'd also get the following warnings:

	Unquoted string "true" may clash with future reserved word at
	test.pl line 2.
	Argument "true" isn't numeric in numeric eq (==) at test.pl line
	2.
	Use of uninitialized value in numeric eq (==) at test.pl line 2.

Unlike, say, Javascript, in Perl "==" is only used for numerical
comparisons. This means that "1.0" eq "1" is false (no string equality),
but numerically, "1.0" == "1" is true, they are both 1 and thus the
same. That's why Perl has two different equality test operators.

In perl, true is not a reserved word, it is here treated as a string
"true", and numerically, it's value is 0. undef, as a number, is also 0.

-- 
	Bart.


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

Date: Sun, 13 Oct 2002 08:21:22 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: use strict
Message-Id: <slrnaqisqi.b9d.tadmc@magna.augustmail.com>

kit <manutd_kit@yahoo.com> wrote:

> can anyone tell me please?

> my $qw_er =3; # compile time error 


Can you tell us what the exact text of the error message was?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sun, 13 Oct 2002 11:06:04 -0700
From: KM <ken_mahi@hotmail.com>
Subject: Using Perl to solve interesting Banking Probm ..
Message-Id: <3DA9B60C.B8341726@hotmail.com>

PROB...
------------

  Write a program to solve the following problem.  Use an array to model
the
  safety deposit box vault and a while loop to iterate.  Initialize the
boxes
  as described below.

The Saftey-Dep boxes ..
-----------------------------
 There has been a run at the local savings and loan.  500 depositors
have lined up in a very long vault with 500 _CLSD_ safety deposit boxes.
One by one the depositors run through the vault.  The 1st depositor
opens every box.  The 2nd depositor goes to every 2nd box and closes
it.   The 3rd depositor goes to every 3rd box and changes it (if open,
closes it; if closed, open it).  In a similiar manner, every 4th, 5th,
6th
  ... depositor changes every 4th, 5th, 6h, ... box.  After all 500
depositors have passed through the vault, WHICH boxes are left OPEN?



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

Date: 13 Oct 2002 19:18:51 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: Using Perl to solve interesting Banking Probm ..
Message-Id: <aocgur$pr2@dispatch.concentric.net>


"KM" <ken_mahi@hotmail.com> wrote in message
news:3DA9B60C.B8341726@hotmail.com...
> PROB...
> ------------
>
>   Write a program to solve the following problem.  Use an array to model
> the
>   safety deposit box vault and a while loop to iterate.  Initialize the
> boxes
>   as described below.
>
> The Saftey-Dep boxes ..
> -----------------------------
>  There has been a run at the local savings and loan.  500 depositors
> have lined up in a very long vault with 500 _CLSD_ safety deposit boxes.
> One by one the depositors run through the vault.  The 1st depositor
> opens every box.  The 2nd depositor goes to every 2nd box and closes
> it.   The 3rd depositor goes to every 3rd box and changes it (if open,
> closes it; if closed, open it).  In a similiar manner, every 4th, 5th,
> 6th
>   ... depositor changes every 4th, 5th, 6h, ... box.  After all 500
> depositors have passed through the vault, WHICH boxes are left OPEN?
>

Please show us the Perl code with which you have attempted to solve this
problem.  We're here to help you develop a (better) solution to your
problem -- not for solving the problem for you.




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

Date: Sun, 13 Oct 2002 20:16:50 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Using Perl to solve interesting Banking Probm ..
Message-Id: <3da9ced5.507819235@news.erols.com>

KM <ken_mahi@hotmail.com> wrote:

|   Write a program to solve the following problem.  Use an array to model
| the
|   safety deposit box vault and a while loop to iterate.  Initialize the
| boxes
|   as described below.

That's some weird line wrapping.  Was it cut and paste from a homework
assignment or something?

|  There has been a run at the local savings and loan.  500 depositors
| have lined up in a very long vault with 500 _CLSD_ safety deposit boxes.
| One by one the depositors run through the vault.  The 1st depositor
| opens every box.  The 2nd depositor goes to every 2nd box and closes
| it.   The 3rd depositor goes to every 3rd box and changes it (if open,
| closes it; if closed, open it).  In a similiar manner, every 4th, 5th,
| 6th ... depositor changes every 4th, 5th, 6h, ... box.  After all 500
| depositors have passed through the vault, WHICH boxes are left OPEN?

Arrays and while loops are boring.
Strings and for loops are where it's at, daddy-o.

    $x=0 x($n=500);
    $x=~s;(.{$_})(.);$1.($2^v1);egfor 0..$n-1;
    ++$i,print"$i "x$_ for$x=~/./g;



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

Date: 13 Oct 2002 12:07:32 -0700
From: appel@erzo.org (Shannon Appelcline)
Subject: Weird Race Condition
Message-Id: <8b25b250.0210131107.37c8c5fa@posting.google.com>

I just managed to track down a weird error in a web game I have. It
turns out to be a race condition involving setting lock files.

Here's the code:

--
$giveUpOnLock = time + 30;
while ( ( -e $lockFile ) && ( time < $giveUpOnLock ) ) {
        &LogIt("WAITING ON LOCK");
        sleep(1);
}

# If lock file still exists, error out; otherwise set a new lock
if ( -e $lockFile ) {
        &ErrorReport("Sorry...game is too busy.  Please reload.");
} else {
        open LOCKFILE, ">$lockFile" or &ErrorReport("Could not set
lock file. Pl
ease try again or mail <a
href=\"mailto:ce\@skotos.net\">ce\@skotos.net</a> if t
he problem persists.");
        &LogIt("set lock");
        # remove lock when program terminates
        END { 
                close LOCKFILE;
                unlink $lockFile;
                &LogIt("cleared lock");
        }
}
--

What seems to happen is that if two hits to this game occur within a
few milliseconds of each other, each process glances at the lockfile,
sees it doesn't exist, then sets the lockfile, like this: Process
A(check, no file); Process B (check, no file); Process A (set file);
Process B(set file).

[Later, when each process writes out a file, things go *splat*,
because the two processes tend to interweave their writing.]

I can see one way to fix this, which is to save the processID to the
lockfile, then recheck that before proceeding, so that only one of the
two can get through.

Is there any more elegant way that people can think of to perform the
check and the setting as a single, atomic, uninterruptible action?

Shannon


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

Date: Sun, 13 Oct 2002 19:32:01 GMT
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: Weird Race Condition
Message-Id: <aochjk$tnd$1@ichaos.ichaos-int>

appel@erzo.org (Shannon Appelcline) said:
>I just managed to track down a weird error in a web game I have. It
>turns out to be a race condition involving setting lock files.
 ...
>What seems to happen is that if two hits to this game occur within a
>few milliseconds of each other, each process glances at the lockfile,
>sees it doesn't exist, then sets the lockfile, like this: Process
>A(check, no file); Process B (check, no file); Process A (set file);
>Process B(set file).
 ...
>I can see one way to fix this, which is to save the processID to the
>lockfile, then recheck that before proceeding, so that only one of the
>two can get through.
>
>Is there any more elegant way that people can think of to perform the
>check and the setting as a single, atomic, uninterruptible action?

"perldoc -f sysopen", at least on Unix platforms. After that, fill in
the missing pieces of information from "man 2 open" - esp. the meanings
of O_CREAT and O_EXCL.
-- 
Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
         PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)


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

Date: 13 Oct 2002 13:53:30 -0600
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: Weird Race Condition
Message-Id: <3da9cf3a@news.mhogaming.com>

Shannon Appelcline <appel@erzo.org> wrote:
> I just managed to track down a weird error in a web game I have. It
> turns out to be a race condition involving setting lock files.
> 
> Here's the code:
> 
> --
> $giveUpOnLock = time + 30;
> while ( ( -e $lockFile ) && ( time < $giveUpOnLock ) ) {
>         &LogIt("WAITING ON LOCK");
>         sleep(1);
> }
> 
> # If lock file still exists, error out; otherwise set a new lock
> if ( -e $lockFile ) {
>         &ErrorReport("Sorry...game is too busy.  Please reload.");
> } else {
>         open LOCKFILE, ">$lockFile" 
 ...

> Is there any more elegant way that people can think of to perform the
> check and the setting as a single, atomic, uninterruptible action?

There some examples using sysopen() in the faq.

  $ perldoc -q "Why can't I just open"
  $ perldoc -q "I still don't get locking"

-- 
Steve

perldoc -qa.j | perl -lpe '($_)=m("(.*)")'


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

Date: Sun, 13 Oct 2002 21:15:55 +0100
From: "Paul Tomlinson" <me@hotmail.com>
Subject: What purpose does eval{ ... } server?
Message-Id: <aockab$l5osg$1@ID-116287.news.dfncis.de>

What purpose does eval{ ... } server?

Nice and simple.  And when should eval be used?
--
Thanks lots




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

Date: Sun, 13 Oct 2002 16:34:03 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: What purpose does eval{ ... } server?
Message-Id: <3DA9D8BB.A7163933@earthlink.net>

Paul Tomlinson wrote:
> 
> What purpose does eval{ ... } server?

It catches errors created with die().

> Nice and simple.  And when should eval be used?

Assuming you mean, "when should eval STRING be used?" the answer is,
only when there's no other way of doing what you want.  Almost never.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Sun, 13 Oct 2002 14:00:40 -0700
From: "Tan Nguyen" <nospam@nospam.com>
Subject: Re: What purpose does eval{ ... } server?
Message-Id: <3da9de71$1_7@nopics.sjc>


"Paul Tomlinson" <me@hotmail.com> wrote in message
news:aockab$l5osg$1@ID-116287.news.dfncis.de...
> What purpose does eval{ ... } server?
It's mainly used to catch exceptions from "die". To a much lesser extent, it
also provides a convenient way of loading modules at runtime.

> Nice and simple.  And when should eval be used?
It's a religious thing. Some might argue that eval is unsafe as people can
maliciously fool "eval" into doing nasty things. As long as you understand
what you're doing with "eval", you should be fine. Barring "eval" from your
code altogether might keep you from having interesting, nice and elegant
code constructs.




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

Date: 13 Oct 2002 15:40:02 -0600
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: What purpose does eval{ ... } server?
Message-Id: <3da9e831@news.mhogaming.com>

Tan Nguyen <nospam@nospam.com> wrote:
> "Paul Tomlinson" <me@hotmail.com> wrote:
>> What purpose does eval{ ... } server?

> It's mainly used to catch exceptions from "die". To a much lesser
> extent, it also provides a convenient way of loading modules at 
> runtime.

Sounds like you started thinking of string eval in the
middle of your answer.

>> Nice and simple.  And when should eval be used?
> It's a religious thing. Some might argue that eval is unsafe as
> people can maliciously fool "eval" into doing nasty things. As 
> long as you understand what you're doing with "eval", you should 
> be fine. Barring "eval" from your code altogether might keep you 
> from having interesting, nice and elegant code constructs.

'eval BLOCK' *only* traps errors.  It doesn't delay
compilation and it doesn't pose any of the security
risks of string eval.

Both forms are described in:

  $ perldoc -f eval

-- 
Steve

perldoc -qa.j | perl -lpe '($_)=m("(.*)")'


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

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 3963
***************************************


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