[7287] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 912 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 23 20:10:18 1997

Date: Sat, 23 Aug 97 17:00:21 -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           Sat, 23 Aug 1997     Volume: 8 Number: 912

Today's topics:
     Re: A flock() of seagulls <rootbeer@teleport.com>
     Re: Building a (very?) complex data structure.... (Ranson)
     Re: Building a (very?) complex data structure.... (Toutatis)
     Re: Die without diagnostics message <rootbeer@teleport.com>
     Re: Error creating files <rootbeer@teleport.com>
     Re: Error running Perl Script <rootbeer@teleport.com>
     Re: foreach and arrays (Dean Inada)
     Re: help displaying a large number with commas (Tad McClellan)
     Re: help displaying a large number with commas (Simon Hyde)
     Re: Help with sub-routine <rootbeer@teleport.com>
     Re: is there a perl compiler ported to NT? <garyng@ibm.net>
     Re: jumping to a URL <deema@tcac.com>
     Re: MAIL question <rootbeer@teleport.com>
     Re: mail <rootbeer@teleport.com>
     Modem Control forster@na-cp.rnp.br
     Re: NDBM problems - HELP! (Seth Perlman)
     Re: Need WIN32's alternative for rename() (plz) (Scott McMahan)
     Re: Need WIN32's alternative for rename() (plz) <rootbeer@teleport.com>
     NEWBIE: Voting Script? <lagos@earthling.net>
     Re: NEWBIE: Voting Script? <rootbeer@teleport.com>
     Re: Newbie: where can I find exercises? <rootbeer@teleport.com>
     OS2 Perl socket.pm problem <abaker@InterVoice.com>
     Re: rand() does not work, HELP <rootbeer@teleport.com>
     What do I pass to setsockopt() to get my program to joi (Craig Petty)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Sat, 23 Aug 1997 14:13:07 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Charles Blaquihre <blaq@interlog.com>
Subject: Re: A flock() of seagulls
Message-Id: <Pine.GSO.3.96.970823140614.19088x-100000@julie.teleport.com>

On Fri, 22 Aug 1997, Charles Blaqui=E8re wrote:

> open ($FH, $filename);

Always check the return value from open.

> if (eval $lock) {

That's not what you want. (Are you passing code in text form to your sub?)
I think you want to simply test $lock, not to eval it.

> # 'eval' used instead of 'defined' to ensure $@ doesn't hold an
> # old "flock timed out"

An eval always sets $@ , so old values can't be left in there. (If I
understand that comment correctly.)

>               local $SIG{ALRM} =3D { die "flock timed out" };

I think you wanted to put 'sub' in there.=20

>               alarm 5;        # Wait 5 seconds max. for file lock
>               flock($FH, $lock);

Why not use non-blocking flock, and check the return value? Since signals
are potentially problematic, that's a safer way to go. (It does have the
disadvantage of a busy wait loop, though.)

Also, I'd capture the return value from flock; it could be failing in this
case.

> if ($@ and $@ !~ /flock timed out/) {
> =09print "flock timed out at ", scalar localtime time,
>               "<BR>\n"; ###
> =09return undef;
> } else {
> =09print "successful flock at ", scalar localtime time,
>               "<BR>\n"; ###

What happens if $@ has a different message than 'flock timed out'? I don't
think that you can call that successful! :-)  (And, in fact, I think the
message in $@ would be quite enlightening here.)

Hope this helps!

--=20
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: 23 Aug 1997 21:22:17 GMT
From: ranson@infoave.net (Ranson)
Subject: Re: Building a (very?) complex data structure....
Message-Id: <5tnka9$5rt@news1.infoave.net>

In article <toutatis-ya023180002308970256020001@news.euro.net>
toutatis@remove.this.toutatis.net (Toutatis) wrote:

> Hi,
> I am trying to build a sorted data structure, just like directories, in a single
> reference, but without any luck so far.
> 
> my $data = {"food-fruit-apple" => $object1,
>             "food-meat-pork"   => $object2,
>             "food-meat"        => $object3,
>             "clothing"         => $object4};
> 
> The key-field comes from a database, and contains up to 6 fields. The objects
> contain various information.
> 
> How do I put these values, sorted per catagory in a datastructure, and, as
> important, how do I access them again.
> 


Maby something like this will work for you.


open (ITEM_DATA, 'lookup.txt');
@lines = <ITEM_DATA>;
close (ITEM_DATA);
foreach $line (@lines)

{

    #chop $line;    # uncomment if you need it

    ($item, $desc, $unit) = split(/:/,$line);
    
    $description{$item}=$desc;
    $eachunit{$item}=$unit
}





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

Date: 23 Aug 1997 21:49:45 GMT
From: toutatis@toutatis.remove_this_to_reply.net (Toutatis)
Subject: Re: Building a (very?) complex data structure....
Message-Id: <toutatis-ya023180002308972349440001@news.euro.net>

In article <5tlntb$3vh@newsops.execpc.com>, zen@onyourmark.com (Rob Bedell)
wrote:

> The illustrious toutatis@remove.this.toutatis.net (Toutatis)
> illuminated our situation by stating:
> 
> The following is a simple subroutine I use to access these "hash
> heirarchies", as I call them:
> 
> ######################################################################
> # traverse_heir
> #   traverse all the nodes of a heirarchy, calling
> #   $before beforing recursing, $after after returning from the
> #recurse,
> #   and $leaf for each leaf node.
> # Notes: traverses them in a sorted order.
> #        processes parent nodes before child nodes.
> ######################################################################
> sub traverse_heir {
>   local($ref,$before,$after,$leaf,@args) = @_;
>   local($i);
> 
>   foreach $i (sort keys %{$ref}) {
>     if(ref  ${$ref}{$i} eq "HASH") {     #node w/children, so recurse
>       &{$before}($i,${$ref}{$i},@args); #process this node.
>       traverse_heir(${$ref}{$i},$before,$after,$leaf,@args);
>       &{$after}($i,${$ref}{$i},@args);  #process this node.
>     } else {    #leaf node.
>       &{$leaf}($i,${$ref}{$i},@args);
>     }
>   }
> }
> 
> __END__
> 
> This should help with accessing these structures.
> Note that it is trivial to add conditional recursion.  Just wrap the 
> &{$before}... in an if stmt that only recurses when $before
> returns true.
> Below is a sample declaration of a hash heirarchy:
> 
> %heirarchy = (
>   "name1" => {
>      "this node has no children" => "",
>      "this node does" => {
>          "la" => "fa so mi la do",
>      },
>   },
>   "name2" => {
>      "here we go again" => "",
>      "__name2__" => "possible way to store data you might normally"
>                         . " just associate with \$heirarchy{name2}",
>   }
> );
> 
> __END__
> 
> If you need to store data in a particular node that has children, come
> up with some example which is highly unlikely to be referenced
> (prefix it with a '/' in unix, for instance, or character \0xFF).
> 
> The following would print the contents of the %heirarchy hash
> heirarchy, for instance (note the use of the global, the sub could
> be rewritten slightly to call each function with an array reference
> so that the subs can manipulate what the children will be called with)
> 
> $leader = 0;
> &traverse_heir(
>   \%heirarchy,   #note that this is a hash table reference
>   sub {  #called before traversing the children
>      local($key,$val_ref,@args) = @_;
>      print "  " x $leader, "$key: \n";
>      $leader++;
>   },
>   sub { #called after the children have been recursed through
>      $leader--;
>   },
>   sub { #called for each leaf node
>      local($key,$value,@args) = @_;
>      print "  " x $leader, "$key => $value\n";
>   },
>   #no extra args to be passed to the various anon subs.
> );
> 
> This is for illustration purposes, of course.  A better implementation
> might tighten it up a little and make the output cleaner. If you're
> wondering, I have checked all the code in this post with perl -c -w,
> so it should work nicely for you.
> 
> Here is the output of the above snippet (if you combine all the code
> sections in this post into one, you should get the same results):
> 
> name1:
>   this node does:
>     la => fa so mi la do
>   this node has no children =>
> name2:
>   __name2__ => possible way to store data you might normally just
> associate with $heirarchy{name2}
>   here we go again =>
> 
> The __name2__ value may wrap on your display.
> 
> ============
> If you want I'll clean up the code I have to create
> hash heirarchies out of directory heirarchies and email
> it to you.
> 
> In order to access a single entry, just deref the entire chain of
> hash's:
> 
> print $heirarchy{"name1"}{"this node does"}{"la"};
> yields:
> fa so mi la do
> 
> NOTE: The recursion technique used here
> would be faster using iteration instead.  perl
> is a bit slow when it comes to function calls, with
> a lot of stack manipulation going on.  Recursion
> just adds to the calls already being made.  It also
> has the potential to waste a lot of memory if you get
> stuck in an infinite loop.  An iteration technique
> that didn't involve a heirarchy without parental
> references would probably have a stack to
> maintain it's position, so maybe it wouldn't help that
> much anyway ;)
> 
> >The key-field comes from a database, and contains up to 6 fields. The objects
> >contain various information.
> 
> You might use pipe-delimiters, or some uncommon character like 0xFF
> or null, to separate the data.
> 
> >How do I put these values, sorted per catagory in a datastructure, and, as
> >important, how do I access them again.
> 
> The implementation I gave you will sort the data by key.
> 
> Say thank you if you find this useful ;)

Thanks, but the problem with this code that it
is a name structure, and not really a directory structure, where a 
directory can have files and subdirectories at the same time. As far
as I understand your code correctly.
However, inspired by your solution, I came up whith
the following, which is quite simple, and elegantly fulfilling all my
wishes. I'd like to share that with you, and anyone else that might find
this useful. Note that there are some calls to private subroutines that
I did not bother to clarify. Fill in your own.

sub _make_tree {
    my @list = @_;
    my ($item,$type,$list,$code,$bit,$object,@bits);
    my @root = ();
    foreach $object(@list){
        $list = \@root;
        $code = _code($object);
        @bits = _split($code);
        foreach $bit(@bits){
            unless (defined $list->[0]->{$bit}){
                $list->[0]->{$bit} = [];
            }
            $list = $list->[0]->{$bit};
        }
        $list->[1] = $object;
        #change this into some push when you expect more than one object
    }
    return \@root;
}

sub _print_tree {
    my $root = _make_tree(@_);
    _traverse($root,0);
}

sub _traverse {
    my($list,$count) = @_;
    my ($object,$key,$value,$dir,$tab);
    $dir = shift @{$list};
    foreach $object(@{$list}){
        $tab = "\t" x $count;
        print $tab,$object->name,"\n";
    }
    if ($dir){
        while(($key,$value) = each %{$dir}){
            _traverse($value,$count + 1);
        }
    }
}

-- 
Toutatis


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

Date: Sat, 23 Aug 1997 14:26:46 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Vegard Bakke <vba@knoll.hibu.no>
Subject: Re: Die without diagnostics message
Message-Id: <Pine.GSO.3.96.970823142213.19088z-100000@julie.teleport.com>

On Sat, 23 Aug 1997, Vegard Bakke wrote:

> I really would like to use the diagnostics module in my scripts.

Mostly, you should do that only during development. By the time you give
your script to end-users, it shouldn't produce any diagnostics from
perldiag. 

> Still, I'd like to 'die' without any additional diagnostics messages.

Maybe you want exit? Good luck!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Sat, 23 Aug 1997 15:04:05 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Arthur Merar <amerar@unsu.com>
Subject: Re: Error creating files
Message-Id: <Pine.GSO.3.96.970823150228.19088L-100000@julie.teleport.com>

On Sat, 23 Aug 1997, Arthur Merar wrote:

> When I run the script from the shell, everything works fine.  but when I
> invoke it from the browser, it dies trying to create the file?? 

Maybe you want to have it tell you why things aren't working.

    unless (open FILE, ">my_new_file") {
	print "Content-type: text/plain\n\n";	# If you need this
	print "Oops: Can't create my_new_file: $!\n";
	exit;
    }

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Sat, 23 Aug 1997 15:08:37 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Arthur Merar <amerar@unsu.com>
Subject: Re: Error running Perl Script
Message-Id: <Pine.GSO.3.96.970823150817.19088N-100000@julie.teleport.com>

On Sat, 23 Aug 1997, Arthur Merar wrote:

> When I try to run my perl script from my web page, I get this error
> message:

When you're having trouble with a CGI program in Perl, you should first
look at the please-don't-be-offended-by-the-name Idiot's Guide to
solving such problems. It's available on the perl.com web pages. Hope
this helps!

   http://www.perl.com/perl/
   http://www.perl.com/perl/faq/
   http://www.perl.com/perl/faq/idiots-guide.html

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: 23 Aug 1997 22:07:03 GMT
From: dmi@delta1.deltanet.com (Dean Inada)
Subject: Re: foreach and arrays
Message-Id: <5tnmu7$62t$1@news01.deltanet.com>

In article <33FD93F8.6956@adc.metrica.co.uk>,
Simon Fairey  <sfairey@adc.metrica.co.uk> wrote:
>denis@mathi.uni-heidelberg.de wrote:
>> foreach $i (@array)
>> {
>> 
>>         if ($i=~ /xxx/) {
>>         #insert cell????
>>         }
>> }
>> 
@array = map {/xxx/?'insert cell????':(),$_} @array;



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

Date: Sat, 23 Aug 1997 15:36:50 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: help displaying a large number with commas
Message-Id: <2lhnt5.qa8.ln@localhost>

randy.paries@avex.com wrote:

: I need help...

There is much help available in the documentation that is included with
the perl distribution.

To get that help, you have to read them though.  ;-)


: I have a number 12300000.00
: I would like to display it like 12,300,000.00
: I am looking for a clean way instead of a for loop counting char positions
: Any suggestions
  ^^^^^^^^^^^^^^^

Sure.

I would suggest getting the perl FAQs, setting them up for easy
word searching, and then using them ;-)

If you get them in *.pod format, then you can extract only the 'headings'
parts into a single file for easy searching.

Then you would be able to answer many questions like this in less
than 30 seconds.

   cd /dir/with/faqs

   grep '^=' *.pod >headings   # get the heading lines in their own file

   grep comma headings

   [found 49 lines, let's try and do better]

   grep comma headings | grep -v command    # ignore 'comma' embedded 

   [finds 9 lines, much better. One of which says:

    "How can I output my numbers with commas added?"
   ]



The Perl FAQs are available at http://www.perl.com/FAQ

You are expected to check for your question in there *before* posting
to the newsgroup. You get your answer faster that way anyway.


: thanks

You're welcome.


--
    Tad McClellan                          SGML Consulting
    tadmc@flash.net                        Perl programming
    Fort Worth, Texas


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

Date: Sat, 23 Aug 1997 23:11:11 GMT
From: shyde@poboxes.com (Simon Hyde)
Subject: Re: help displaying a large number with commas
Message-Id: <33ff6caa.16916185@news.uni-stuttgart.de>

On Sat, 23 Aug 1997 13:01:18 -0600, randy.paries@avex.com wrote:

>Hello,
>
>I need help...
>I have a number 12300000.00
>I would like to display it like 12,300,000.00
>I am looking for a clean way instead of a for loop counting char positions
>Any suggestions
>
>thanks
>
how about the following little regex I cooked up with a few tweaks from other ppl on
#perl:

$number = 2890000600.0011;
$number =~ s/^\$//;
1 while $number =~ s/^([^.]*)(\d)(\d{3})(,|\.|$)/$1$2,$3$4/g;
print $number, "\n";

It won't do all the fancy different formating in different countries that some of the
modules do...but it does me fine.


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

Date: Sat, 23 Aug 1997 16:34:49 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Ranson <ranson@infoave.net>
Subject: Re: Help with sub-routine
Message-Id: <Pine.GSO.3.96.970823163057.19088Z-100000@julie.teleport.com>

On 22 Aug 1997, Ranson wrote:

> What I want is a routine that will work for an infinate number of items
> in the database,

The trouble with having an infinitely-large disk drive is that the average
seek time is outrageously large. :-)

> and print the menu list, assigning 10 items per page. 

I think you could use the methods in Randal's second Web Techniques
column, which explains how to return a large volume of data in bite-sized
pieces. Hope this helps! 

   http://www.stonehenge.com/merlyn/WebTechniques/

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: 23 Aug 1997 03:43:27 GMT
From: "Gary Ng" <garyng@ibm.net>
Subject: Re: is there a perl compiler ported to NT?
Message-Id: <01bcaf76$c3eb22e0$c41952ca@dkkong>

Y Chen <yinso@u.washington.edu> wrote in article
<Pine.OSF.3.96.970822115644.31017A-100000@saul9.u.washington.edu>...
> Hello,
> 
> got a question for all you perl gurus out there... do you know whether or
> not Mr. Malcolm Beattie's compiler has been ported to NT?  I have run the
> compiler under unix, however, I can't find one for NT yet.  If someone
can
> let me know where to find information about it, I will be grateful :)
> 
> thanks a bunch :)
> 
> yin-so	
> 
> 

Yes. with 5.004_01 and up you can use Malcolm's compiler on NT.
But bytecode do not work. Only the cc backend.

Gary


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

Date: Sat, 23 Aug 1997 16:14:13 +0000
From: Mary Nipper <deema@tcac.com>
Subject: Re: jumping to a URL
Message-Id: <33FF0C55.8C138F60@tcac.com>

I need to do about the same thing but without having the user enter the
path into the form. How can I add a path in front of and ".htm" behind
the form data to come up with full $URL??

Any Help - Thanks !!!!

Kyzer wrote:

> Hurrah, for 'tis said that Patrick Wiseman did write:
> : Sam Mingolelli wrote:
> : > When the program gets into a specific subroutine I would like to
> : > instruct the browser to jump to a designated URL.
> : print "Location:$URL\n\n";
> : where $URL is the FULL URL to which you wish to jump.
>
> I would suggest a space in there - print "Location: $URL\n\n";
> Even better, I would suggest making use of one of the CGI modules
> available
> at http://www.perl.com/CPAN/
>
> Then you can do, as part of the powerful command set available, this:
> print $my_form->redirect($URL);
>
> --
> Stuart 'Kyzer' Caie, Aberdeen University, Scotland.  Email to:
> kyzer@4u.net
> My opinions are not those of Aberdeen University, and I do not speak
> for or
> on behalf of AUCC.
>                    ..100% Amiga, forever!..
> http://www.abdn.ac.uk/~u13sac/
>
> --
> Random sig of the day:
> "Slightly less safe than joining the mile high club bareback with a
> junkie
> whore in a plane flying over a war zone with three engines on fire, a
> pissed
> up pilot and Carlos the Jackal sitting RIGHT BEHIND YOU" - MK3 advert.



--
Deema

Doodles by Deema
3440 Bell Street, Suite 320-255
Amarillo, TX 79109
www:            http://www.deema.com
e-mail:           pics@deema.com
phone:           (806) 467-1023
fax:                (806) 355-4796

And, for the Kids . . .
Kid Train
www:            http://www.deema.com/kidtrain




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

Date: Sat, 23 Aug 1997 14:20:48 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Burt Lewis <burt@ici.net>
Subject: Re: MAIL question
Message-Id: <Pine.GSO.3.96.970823141956.19088y-100000@julie.teleport.com>

On 23 Aug 1997, Burt Lewis wrote:

> I'm using this bit of code which works nice:
> 
> $youmail = 'burt@ici.net';
> open (MAIL, "|$mailprog $youmail");
> 
> Question is, I can't seem to add additional receipients to this, it only 
> seems to work with one.

Maybe you want to ask about it in a newsgroup about your mail program.
Look in comp.mail.* . Hope this helps! 

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Sat, 23 Aug 1997 14:28:39 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: megabytte7@erols.com
Subject: Re: mail
Message-Id: <Pine.GSO.3.96.970823142702.19088A-100000@julie.teleport.com>

On Fri, 22 Aug 1997 megabytte7@erols.com wrote:

> Could someone please offer a little advice as to why i get an invalid
> cookie error when i attempt to register with Deja news? my conformation
> e-mail says browser type mozilla/ 3.0c-aol i had to reinstall aol again
> i was using aol 3.0b. could this be the problem? 

No, the problem is that you're posting a non-Perl question to a Perl
newsgroup. When you have Perl questions which aren't answered in the docs
or FAQs, please post those questions here. Thanks!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Sat, 23 Aug 1997 18:21:36 -0600
From: forster@na-cp.rnp.br
To: forster@na-cp.rnp.br
Subject: Modem Control
Message-Id: <872378205.30937@dejanews.com>

Hello Folks!

I was wondering... Is there any module or something to control modems?

I've made a script to make dial-up connections using dip, but I have some
problems with dip. e.g.: when in a PABX.

And of course, I'd like to use only perl on the script.

Thanks for any suggestions!

Regards,

Antonio Forster

PS: please reply via mail.

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: 23 Aug 1997 19:13:32 -0400
From: seth@fellspt.charm.net (Seth Perlman)
Subject: Re: NDBM problems - HELP!
Message-Id: <5tnqqs$k76@fellspt.charm.net>

In article <33fce17b.73476@news.lrz-muenchen.de>,
Joachim Wunder <Joachim.Wunder@LRZ-Muenchen.DE> wrote:
>Hi!
>
>I am simply trying to create a ndbm database in Perl to write it and to read it
>with dbm_open under C.
>
>The problem: Perl 5.004 creates it like `test.db4 and dbm_open (FreeBSD 2.2.1)
>             expects it to be `test.pag4 and `test.dir4. So dbm_open returns a
>             NULL pointer if I try to open the test-database which was created
>             under Perl.
There  is no incompatibility between creating and working with an ndbm file
using C's ndbm functions and then having a perl script work with the very
same ndbm file. It appears that your perl script may be trying to read the
file as if it were a berkley DB_File. Try using an explicit "Use NDBM_File"
in your script in order to make it use the ndbm underlying functions when
accessing your C dbm file.
 ...seth
>Any help asap would be appreiated!!
>
>TIA,
>Joachim
>--
>Email: Joachim.Wunder@LRZ-Muenchen.DE
>


-- 
Seth Perlman  Unix/Sybase Consultaant  
6000 Rusk Avenue 
Baltimore, Md. 21209
(410) 358-4355 seth@charm.net


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

Date: 23 Aug 1997 21:51:08 GMT
From: scott@lighthouse.softbase.com (Scott McMahan)
Subject: Re: Need WIN32's alternative for rename() (plz)
Message-Id: <5tnm0c$f4k$3@scully.new-era.net>

mbosley (mbosley@games-online.com) wrote:

: rename "$filename","$filename.old";

: The interpreter either skips the line or fails on executing it

I did this from the command prompt, in a directory containing
a.gif:

c:\perl\bin\perl -e "rename 'a.gif','b.gif' || die 'crap: $!';"

When I was through, there was no a.gif in the directory but there was a
b.gif. I do not know what is wrong: I would try printing the value of
$filename before executing the statement. It is probably some sort of
error concerning the filenames.

Scott



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

Date: Sat, 23 Aug 1997 16:08:56 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Scott McMahan <scott@lighthouse.softbase.com>
Subject: Re: Need WIN32's alternative for rename() (plz)
Message-Id: <Pine.GSO.3.96.970823160428.19088U-100000@julie.teleport.com>

On 23 Aug 1997, Scott McMahan wrote:

> c:\perl\bin\perl -e "rename 'a.gif','b.gif' || die 'crap: $!';"

You wanted 'or' instead of '||' in there, or some parens. Also, the $! in
the die message can't be interpolated unless you use double quoting; try
putting qq in front of the quoted string to enable that.

    perl -e "rename 'a.gif','b.gif' or die qq'rename failed: $!';"

Hope this helps! 

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Sat, 23 Aug 1997 18:15:16 -0400
From: "Jeff Bonhag" <lagos@earthling.net>
Subject: NEWBIE: Voting Script?
Message-Id: <5tnneg$t86$1@dartvax.dartmouth.edu>

 Does anyone know of a script that would allow people to vote on things they
type in, and then tally the results?

Example:

What is your favorite computer game?

<INPUT TEXTBOX>

It would also be nice if the results were ordered in most votes to least
votes and numbered, but I'll take what I can get.

If anybody knows of a script like this please e-mail me.

/\/\ lagos@earthling.net
\__/ http://free.xtel.com/~lagos





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

Date: Sat, 23 Aug 1997 16:30:30 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Jeff Bonhag <lagos@earthling.net>
Subject: Re: NEWBIE: Voting Script?
Message-Id: <Pine.GSO.3.96.970823162417.19088Y-100000@julie.teleport.com>

On Sat, 23 Aug 1997, Jeff Bonhag wrote:

>  Does anyone know of a script that would allow people to vote on things
> they type in, and then tally the results? 

Sure. Do you want it to be a CGI script? :-)

How many times do you wish to allow one person to vote? (Hint: My browser
is shared by me, my mother, two great aunts, my cousin Ferdie, my loving
wife, eight concubines, and my cat. So you'll be glad to let us vote 15
times from my browser, right? :-) 

Oh, and sometimes I'm not sure whether a form has been processed, so I
click on Submit eight or ten times to be sure. :-)

But it's not hard to write something like this, if you still think it
might be useful. Since you will need to maintain a file of votes, I think
you could use the methods in Randal's fourth Web Techniques column, which
explains how to use flock() to avoid problems when multiple processes need
to modify one file. 

   http://www.stonehenge.com/merlyn/WebTechniques/

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Sat, 23 Aug 1997 13:58:39 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Peter Staunton <pjs@iol.ie>
Subject: Re: Newbie: where can I find exercises?
Message-Id: <Pine.GSO.3.96.970823135220.19088v-100000@julie.teleport.com>

On Fri, 22 Aug 1997, Peter Staunton wrote:

> I'm a newcomer to perl and am looking for a collection of 
> exercises for practice in writing code. 

Method one: Get the Llama book, enjoy the exercises at the end of each
chapter, and the answers in the back.

    http://www.ora.com/catalog/lperl2/noframes.html

Method two: Watch this newsgroup until somebody says, "Does anybody have a
program which can frobnicate?" Then write one for them and see how it
compares to all of the other answers posted in reply.  :-) 

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 22 Aug 1997 12:16:34 -0500
From: Anthony Baker <abaker@InterVoice.com>
Subject: OS2 Perl socket.pm problem
Message-Id: <33FDC972.7BA7CD80@InterVoice.com>

Hi,

   Hopefully, someone has an answer for me...this is a complete
show-stopper:

I am running OS/2 3.0, on a machine with at least 32 meg...Pentium,
etc...
The version of perl is 5.003_93.  I am using EMX revision:

EMX : revision = 50
EMXIO : revision = 50
EMXLIBC : revision = 53
EMXLIBCM : revision = 53
EMXLIBCS : revision = 53
EMXWRAP : revision = 50

When I run the following script (with the "use Socket" included),
EMX.dll reports an
access violation (I have 200 handles defined in emxopt settings).  If I
remove the
"use Socket", the fork succeeds and everyone is happy.  I do need to use
sockets, btw
;)

Please help; I am dead in the water...

Anthony Baker
(abaker@intervoice.com)

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

use Socket;

if ($x=fork)
   { print "Parent $x\n"; }
elsif (defined $x)
   { print "Child $x\n"; exit; }
else
   { print "Nope  >8(\n"; }





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

Date: Sat, 23 Aug 1997 15:11:52 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Hedin Meitil <hm@NO-SPAMroyal.net>
Subject: Re: rand() does not work, HELP
Message-Id: <Pine.GSO.3.96.970823151004.19088O-100000@julie.teleport.com>

On Thu, 21 Aug 1997, Hedin Meitil wrote:

> I can't get the rand() function to return values higher than 1. 

You may have inadvertantly used the wrong value of RANDBITS when you 
compiled your Perl. 

> Is there a solution to my problem? I run perl 4.

Install 5.004 at once. Hope this helps! 

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Sat, 23 Aug 1997 20:36:56 GMT
From: Craig.Petty@m.cc.utah.edu (Craig Petty)
Subject: What do I pass to setsockopt() to get my program to join a muticast group?
Message-Id: <33ff4712.8472733@news.cc.utah.edu>

I've got a program that sends messages to a multicast address, and I
want to create a "listener" program to read those messages.

I'm using multicast so I can put just one packet on the network, and
be able to receive it from one or more listening workstations.

I'm not quite sure what to pass to getsockopt().
In a c example I've got they pass a pointer to a struct ip_mreq.
Can it be done in Perl?

Here's what I've got so far.

----------------------------------
#!/usr/local/bin/perl
use strict;
require 5.002;
use Socket;
use Sys::Hostname;
$| = 1;

my ( $count, $hisiaddr, $hispaddr, $histime, $buffer,
        $host, $iaddr, $paddr, $port, $proto, $mreq );

my($IP_ADD_MEMBERSHIP) = 0x13;
my($IPPROTO_IP)        = 0x0;

#$iaddr = gethostbyname(hostname());
$iaddr = inet_aton(0.0.0.0);
$proto = getprotobyname('udp');
$paddr = sockaddr_in(5010, $iaddr);
socket(SOCKET, PF_INET, SOCK_DGRAM, $proto) || die "socket: $!";
bind(SOCKET, $paddr)  || die "bind: $!"; 

# join multicast group
$mreq = join '', inet_aton(225.100.1.18), INADDR_ANY;

#Program always dies here
setsockopt(SOCKET, $IPPROTO_IP, $IP_ADD_MEMBERSHIP, $mreq)
        or die "error joining multicast group: $!";

for (;;) {
        $buffer = '';
        ($hispaddr = recv(SOCKET, $buffer, 1000, 0)) || die "recv:
$!";
        ($port, $hisiaddr) = sockaddr_in($hispaddr);
        $host = gethostbyaddr($hisiaddr, AF_INET);
        print "received from $host:  $buffer\n";
        sleep 1;
} 
--------------------------------------

Craig Petty
cpetty@westin.com



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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.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 912
*************************************

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