[9485] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3079 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 7 10:17:34 1998

Date: Tue, 7 Jul 98 07:01:10 -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           Tue, 7 Jul 1998     Volume: 8 Number: 3079

Today's topics:
    Re: 'NEXT' and 'LAST' in do-until <tchrist@mox.perl.com>
    Re: better way of getting the last modified file? (Michael J Gebis)
    Re: better way of getting the last modified file? <rra@stanford.edu>
    Re: better way of getting the last modified file? <dgris@rand.dimensional.com>
    Re: better way of getting the last modified file? <tchrist@mox.perl.com>
    Re: better way of getting the last modified file? <rra@stanford.edu>
        Command line argument <naamah@haifa.vnet.ibm.com>
    Re: Command line argument <qdtcall@esb.ericsson.se>
    Re: delete key from array <jdf@pobox.com>
        Extracting portions of an HTML file using perl <phil.clark@takethisbitout.tpd.co.uk>
    Re: Extracting portions of an HTML file using perl (brian d foy)
    Re: Finding a value in a string <barnett@houston.Geco-Prakla.slb.com>
    Re: Forking, SIG handlers, etc. (Long) apc03@my-dejanews.com
    Re: Getting around javascript dialog box confirm button (brian d foy)
    Re: help I'm a beginner <sapapo@tukki.cc.jyu.fi>
    Re: How do I write data to a remote server? <jdf@pobox.com>
        How do you delete arbitrary elements of an array in one <quednauf@nortel.co.uk>
    Re: How do you delete arbitrary elements of an array in <quednauf@nortel.co.uk>
        how long does it take to execute some code? dwiesel@my-dejanews.com
    Re: how long does it take to execute some code? (Mike Stok)
        How to authenticate clients in perl server ste_jones@hotmail.com
        Passing open file descriptor to an unrelated process <tgdscpe6@gd2.swissptt.ch>
    Re: Passing open file descriptor to an unrelated proces <tchrist@mox.perl.com>
    Re: Q: DBI & Table/Column Names <fty@utk.edu>
    Re: Randomize number between -0.5 and 0.5 (Huang)
    Re: regexp s/// for removing tail end of string (John Moreno)
        rnews or inews for mail2news <silvio@admi.org>
    Re: Searching through a file <naamah@haifa.vnet.ibm.com>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 7 Jul 1998 12:00:13 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: 'NEXT' and 'LAST' in do-until
Message-Id: <6nt2kd$9ne$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    Morten Simonsen <mortensi@idt.ntnu.no> writes:
:I have tried to use NEXT and LAST in a do-until loop, but it won't
:work. I get this message:
:
:Label not found for "next LINE" at test.pl line 70
:
:I have read the Camel-book, to find if it says that you cannot use
:this constructs in a do-until loop, but it constantly refers to just
:"loops", so I wandered if any of you could tell me if this is allowed
:or not?

No, it's not allowed.

Here's how to do a "next" or "redo":

    do {{
	next if /whatever/;
	redo if /whatever/;
	....
    }} until something;

Here's how to do a "last".

    {
	do {
	    last if /whatever/;
	    ....
	} until something 
    }

Here's how to do it all:

    LAST: {
	do { NEXT: {
	    last LAST if /whatever/;
	    next NEXT if /whatever/;
	    redo NEXT if /whatever/;
	    ....
	}} until something 
    }

--tom
-- 
    #else /* !STDSTDIO */     /* The big, slow, and stupid way */
        --Larry Wall in str.c from the 4.0 perl source code


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

Date: 7 Jul 1998 03:36:10 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: better way of getting the last modified file?
Message-Id: <6ns53a$j6s@mozo.cc.purdue.edu>

Russ Allbery <rra@stanford.edu> writes:

}Larry Rosler <lr@hpl.hp.com> writes:

}> Can the application not intercept $SIG{'__DIE__'} and $SIG{'__WARN__'}
}> and send an appropriate message to its maintainer using sendmail (or an
}> equivalent on Windows/DOS systems)?

}Any software I'm using that I find automatically sending mail to *anyone*
}without my explicit permission will be shot at dawn.  No exceptions.
}*Way* too much potential for abuse.

Doesn't perl do this?

-- 
Mike Gebis  gebis@ecn.purdue.edu  mgebis@eternal.net


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

Date: 07 Jul 1998 05:21:17 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: better way of getting the last modified file?
Message-Id: <m3u34trgw2.fsf@windlord.Stanford.EDU>

Michael J Gebis <gebis@albrecht.ecn.purdue.edu> writes:
> Russ Allbery <rra@stanford.edu> writes:

>> Any software I'm using that I find automatically sending mail to
>> *anyone* without my explicit permission will be shot at dawn.  No
>> exceptions.  *Way* too much potential for abuse.

> Doesn't perl do this?

Not that I'm aware of, unless someone explicitly runs perlbug.  If it
does, this is the first I've heard of it; admittedly, I haven't manually
checked in great detail.  If it did, I'd be *extremely* disappointed.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Tue, 07 Jul 1998 12:52:57 GMT
From: Daniel Grisinger <dgris@rand.dimensional.com>
Subject: Re: better way of getting the last modified file?
Message-Id: <6nt52c$85f$1@rand.dimensional.com>

[posted and mailed to the cited author]
In article <m3u34trgw2.fsf@windlord.Stanford.EDU>
Russ Allbery <rra@stanford.edu> wrote:
<snip comments about programs automatically sending mail>
>> Doesn't perl do this?
>
>Not that I'm aware of, unless someone explicitly runs perlbug.  If it
>does, this is the first I've heard of it; admittedly, I haven't manually
>checked in great detail.  If it did, I'd be *extremely* disappointed.

Perl automatically sends mail to root if one tries to exploit a
race condition in an SUID script.

Daniel
-- 
Daniel Grisinger           dgris@perrin.dimensional.com
"No kings, no presidents, just a rough consensus and
running code."
                           Dave Clark


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

Date: 7 Jul 1998 12:55:01 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: better way of getting the last modified file?
Message-Id: <6nt5r5$e1g$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    Russ Allbery <rra@stanford.edu> writes:
:Not that I'm aware of, unless someone explicitly runs perlbug.  If it
:does, this is the first I've heard of it; admittedly, I haven't manually
:checked in great detail.  If it did, I'd be *extremely* disappointed.

Take the Perl Wizard Quiz, Russ.

--tom
-- 
:        And it goes against the grain of building small tools.
Innocent, Your Honor.  Perl users build small tools all day long.
		--Larry Wall in <1992Aug26.184221.29627@netlabs.com>


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

Date: 07 Jul 1998 06:06:56 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: better way of getting the last modified file?
Message-Id: <m3k95prerz.fsf@windlord.Stanford.EDU>

Daniel Grisinger <dgris@rand.dimensional.com> writes:
> Russ Allbery <rra@stanford.edu> wrote:

>> Not that I'm aware of, unless someone explicitly runs perlbug.  If it
>> does, this is the first I've heard of it; admittedly, I haven't
>> manually checked in great detail.  If it did, I'd be *extremely*
>> disappointed.

> Perl automatically sends mail to root if one tries to exploit a
> race condition in an SUID script.

Oh, *that*.  That doesn't count.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Tue, 07 Jul 1998 15:17:23 +0200
From: Naama Kraus <naamah@haifa.vnet.ibm.com>
Subject: Command line argument
Message-Id: <35A21FE2.1D65AB87@haifa.vnet.ibm.com>

Hi!
Here is a simple program (named my_prog) which reads a command line
argument:

if (@ARGV) {
    $a = shift;
}

Now, when running:
 > my_prog abc*
I receive the error:
> my_prog: No match
No error occurs when running:
> my_prog "abc*"

Can anyone help me understand the meaning of abc* as a command line
argument ?

 -Thanx in advance,
      - Naama.



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

Date: 07 Jul 1998 14:59:57 +0200
From: Calle Dybedahl <qdtcall@esb.ericsson.se>
Subject: Re: Command line argument
Message-Id: <isbtr1q0j6.fsf@godzilla.kiere.ericsson.se>

Naama Kraus <naamah@haifa.vnet.ibm.com> writes:

> Can anyone help me understand the meaning of abc* as a command line
> argument ?

This is a Unix-shell question, not a Perl question. Get a beginner's
guide to Unix.
-- 
		    Calle Dybedahl, UNIX Sysadmin
       qdtcall@esavionics.se  http://www.lysator.liu.se/~calle/


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

Date: 07 Jul 1998 08:27:57 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: dwiesel@my-dejanews.com
Subject: Re: delete key from array
Message-Id: <n2aloko2.fsf@mailhost.panix.com>

dwiesel@my-dejanews.com writes:

> I have an array and want to delete a key from it

perldoc -f splice

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf/


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

Date: Tue, 7 Jul 1998 12:50:25 +0100
From: "Phil Clark" <phil.clark@takethisbitout.tpd.co.uk>
Subject: Extracting portions of an HTML file using perl
Message-Id: <a12tn6.av4.ln@gate.tpd.co.uk>

Folks

This should be a simple request ...

Can someone tell me how to extract a portion of an HTML file in perl? For
example the <HEAD> ........ </HEAD> section - I want to extract just the
text in the middle of the tags, and not the tags themselves, nor anything
outside the tags.

Would that be easy to do in perl?

tia
Phil
phil@interactive.tpdDOTcoDOTuk




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

Date: Tue, 07 Jul 1998 09:49:40 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Extracting portions of an HTML file using perl
Message-Id: <comdog-ya02408000R0707980949400001@news.panix.com>
Keywords: from just another new york perl hacker

In article <a12tn6.av4.ln@gate.tpd.co.uk>, "Phil Clark" <phil.clark@takethisbitout.tpd.co.uk> posted:

>Can someone tell me how to extract a portion of an HTML file in perl? For
>example the <HEAD> ........ </HEAD> section - I want to extract just the
>text in the middle of the tags, and not the tags themselves, nor anything
>outside the tags.

use HTML::HeadParser;

good luck :)

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers Travel Deals! <URL:http://www.pm.org/travel.html>


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

Date: Tue, 07 Jul 1998 08:00:04 -0500
From: Dave Barnett <barnett@houston.Geco-Prakla.slb.com>
Subject: Re: Finding a value in a string
Message-Id: <35A21BD4.378A4ECE@houston.Geco-Prakla.slb.com>

Mike wrote:
> 
>   I am reading a text file and I need to search for a string in the
> file and get the value after the string.  The string I am searching
> for is BegMessageXX where XX is a number.  I can search the string for
> BegMessage but how do I find out what the number after that string is
> ?
> 
>   I am already doing s/^BegMessage*/i  to find out if the line has
I don't think that means what you think it means.

You've confused perl, and me.  That would be an unterminated search
pattern.  Perhaps you meant m//i?  You'd still be left with the problem
of extracting the number.

> that string on it, there is no space between the number and the text
> which why I am stuck or I would search for a space.
if ($string =~ /^BegMessage(\d{2})/i) {
	print "Number is $1\n";
}

Lets look at this for a second:
/		Start regex
^		Anchor at beginning of line
BegMessage	search for the characters BegMessage
(		First matching pattern to remember - stored in $1 by perl
\d		Any digit 0-9
{2}		Exactly 2 of them
)		End first matching pattern
/i		End regex, ignore case

When I set $string = 'BegMessage84', I get:
Number is 84
as output.

Is that what you were after?

I would suggest a read through perldoc perlre for more insight, and help
on the above.

> 
>         Thanks for any help, sorry about the hotmail accout but this
> way I can ignore the spammers.
> 
>         mike
HTH.

Dave

-- 
"Security through obscurity is no security at all."
		-comp.lang.perl.misc newsgroup posting

----------------------------------------------------------------------
Dave Barnett                 U.S.: barnett@houston.Geco-Prakla.slb.com
DAPD Software Support Eng    U.K.: barnett@gatwick.Geco-Prakla.slb.com
----------------------------------------------------------------------


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

Date: Tue, 07 Jul 1998 12:45:04 GMT
From: apc03@my-dejanews.com
Subject: Re: Forking, SIG handlers, etc. (Long)
Message-Id: <6nt58g$q19$1@nnrp1.dejanews.com>

Very useful information. Please reserve my copy of the Perl Cookbook.

Actually, when I modified my code by replacing wait() with waitpid() call as
suggested here, I got a number of core dumps. If I deleted the statement:

$SIG{CHLD} = \&REAPER;	# install *after* calling waitpid in the sigchld
interrupt handler, then no core dump anymore. This is in Solaris 2.6.

Does anyone have the same experience with me?

In article <5qg1h64jah.fsf@prometheus.frii.com>,
  Nathan Torkington <gnat@frii.com> wrote:
>
> "Gabriele R. Fariello" <gabriele@kollwitz.doit.wisc.edu> writes:
> > Alas, it seems that some SIGs get lost.
>
> Excellent conclusion to draw.  There are a couple of things you can
> do:
>
> (1) make sure you're using version 5.004 of Perl.  It had some
> changes to make signal handlers a tad more reliable.
>
> (2) use waitpid() in a non-blocking fashion, and not wait(), so you
> can catch multiple deaths.
>
> Here's the relevant bit from The Perl Cookbook (by Tom Christiansen
> and Nathan Torkington, to be published by O'Reilly and Associates in
> August, plug plug :-):
>
>        Problem
>
>        Your program forks children, but the dead children
>        accumulate, fill up your process table, and aggravate your
>        system administrator.
>
>        Solution
>
>        If you don't need to record which children have
>        terminated:
>
>            $SIG{CHLD} = 'IGNORE';
>
>        To keep better track of deceased children, install a
>        SIGCHLD handler to call waitpid:
>
>            use POSIX ":sys_wait_h";
>
>            $SIG{CHLD} = \&REAPER;
>            sub REAPER {
>                my $stiff;
>                while ($stiff = waitpid(-1, &WNOHANG) > 0) {
>                    # do something with $stiff if you want
>                }
>                $SIG{CHLD} = \&REAPER;                  # install *after*
callin
> g waitpid
>            }
>
>        Discussion
>
>        When a process exits, the system keeps it in the process
>        table so the parent can check its status--whether it
>        terminated normally or abnormally.  Fetching a child's
>        status (thereby freeing it to drop from the system
>        altogether) is rather grimly called ``reaping'' dead
>        children,[FOOTNOTE: This entire recipe is full of ways to
>        harvest your dead children.  If this makes you queasy, we
>        understand.] and involves a call to wait or waitpid.  Some
>        Perl functions (piped opens, system, and backticks) will
>        automatically reap the children they make, but you must
>        explicitly wait when you use fork to manually start
>        another process.
>
>        The simplest way to avoid dead children accumulating is to
>        tell the system that you're not interested in them by
>        setting $SIG{CHLD} to "IGNORE".  If you want to know which
>        children die and when, though, you'll need to use waitpid.
>
>        The waitpid function reaps a single process.  Its first
>        argument is the process to wait for--use -1 to mean any
>        process--and its second argument is a set of flags.  We
>        use the WNOHANG flag to make waitpid immediately return 0
>        if there are no dead children.  A flag value of 0 is
>        supported everywhere, indicating a blocking wait.  Call
>        waitpid from a SIGCHLD handler, as we do in the Solution,
>        to reap the children as soon as they die.
>
>        There is another function to reap children, wait, but it
>        does not have a non-blocking option.  This means that if
>        you inadvertently call it when there are running child
>        processes but none that have exited, your program will
>        pause until there is a dead child.
>
>        Because the kernel keeps track of undelivered signals
>        using a bit vector, one bit per signal, if two children
>        die before your process is scheduled, you will get only a
>        single SIGCHLD.  This means you must always loop when you
>        reap in a SIGCHLD handler, and so can't use wait.
>
> The capsule summary is that when two children can die "simultaneously",
> your SIGCHLD handler is only called once.  This means you *must* loop
> in your SIGCHLD handler.  wait() blocks, so you can use it.  You then
> must call waitpid() with WNOHANG so it won't block.
>
> If you don't have WNOHANG, you're screwed.  Fortunately, it's part of
> the POSIX standard and most operating systems have it.
>
> Nat
>


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Tue, 07 Jul 1998 09:56:43 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Getting around javascript dialog box confirm button
Message-Id: <comdog-ya02408000R0707980956430001@news.panix.com>
Keywords: from just another new york perl hacker

In article <35A1C451.B404CA6E@ti.com>, Sofian Taha <sofian@ti.com> posted:

>I'm trying to write a client script that gets files from a web server
>without having to open up a browser (for automation purposes). However,
>the server asks for confirmation whether to go ahead or cancel the
>download (through a javascript dialog box). How do you go about doing
>this in perl to simulate the clicking of the "OK" or "Cancel" button?

don't let your client interpret the javascript.  just do what you want
to do while ignoring it.  

the server isn't involved unless the problem is different than what
you describe.

good luck :)

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers Travel Deals! <URL:http://www.pm.org/travel.html>


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

Date: 7 Jul 1998 16:04:36 +0300
From: "Sami P. Poikonen" <sapapo@tukki.cc.jyu.fi>
Subject: Re: help I'm a beginner
Message-Id: <6nt6d4$sjt@tukki.cc.jyu.fi>

Martien Verbruggen <mgjv@comdyn.com.au> wrote:

: $num = 8.10;
: print $num, " - ", length($num), "\n";

: $num = "8.10";
: print $num, " - ", length($num), "\n";

: You'll notice that in the first instance, perl gets rid of the last 0,
: because it interprets $num as a number, which is correct. If you want
: it to be a string, you should make that clear. Perl does make a
: distinction between numbers and strings, but it can convert silently
: from one to the other if needed. This is all explained in the
: documentation.

Well, how do I convert from string to number?
I tried $num = 0 + $num, but it gives warning if I use -w switch
and $num contains a string.

Ok, I know I could use regexp to extract numeric value from string, but
is there any other way to do it?

tukki:/home/sapapo/prog% cat ./strnum.pl
#!/opt/bin/perl -w

@myvals = (123,"234","cat","456abc");

for (@myvals) {
 if ((~$_ & $_) ne '0') {
    print "$_ is string\n";
 } else {
    print "$_ number\n";
 }

 $_ = 0 + $_;
 if ((~$_ & $_) ne '0') {
    print "$_ is now string\n";
 } else {
    print "$_ is now number\n";
 }

}

tukki:/home/sapapo/prog% ./strnum.pl
123 number
123 is now number
234 is string
234 is now number
cat is string
Argument "cat" isn't numeric in add at strnum.pl line 12.
0 is now number
456abc is string
Argument "456abc" isn't numeric in add at strnum.pl line 12.
456 is now number

-- 
Sami Poikonen 
  sp@iki.fi


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

Date: 07 Jul 1998 08:22:55 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: joker@inlink.com (John Hocking)
Subject: Re: How do I write data to a remote server?
Message-Id: <pvfhokwg.fsf@mailhost.panix.com>

joker@inlink.com (John Hocking) writes:

> open(DATA,">http://www.remote.com/data/datafile.txt") 
> does not work even if the directory is given 777 permissions.

This begs the question, "where on earth did you get the notion that
this would work?"

> is there a way to use something like Net:FTP or similar to transfer
> the files to the remote server?

That's just what it's for.  Install the Net modules if you haven't
already, and read the docs for Net::FTP.  It's very simple to use.

    #!/usr/local/bin/perl -Tw
    use Net::FTP;
    $ftp = Net::FTP->new('ftp.remote.com');
    $ftp->login('username', 'password');
    $ftp->cwd('/htdocs/data');
    $ftp->put('that.file');
    $ftp->quit;

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf/


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

Date: Tue, 07 Jul 1998 12:57:28 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: How do you delete arbitrary elements of an array in one go?
Message-Id: <35A20D27.E3F2439F@nortel.co.uk>

How can you efficiently delete arbitrary elements of an array in one go?
Consider the following code:

@arr = qw/ 0 first second third fourth fith sixth seventh eight ninth /;

sub splice_around {
  foreach (@_) { splice(@arr, $_, 1);}
}

&splice_around(0,5,6);

foreach (@arr) {
  print "$_ - ";
}

prints:
first - second - third - fourth - fith - seventh - ninth -

You can see what has happened (the zeroeth element gets deleted and now the
former sixth element becomes the fifth; bad luck), and quite probably it is not
what you want :)

So what can one do about that? Actually easier than I thought it would be (What
a lunch can do :-)

sub splice_around {
  my $i = 0;
  foreach (@_) { splice(@arr, ($_-$i), 1); $i++;}
}

&splice_around(0,5,6);

will now properly delete the elements that you considered. Ts, and I thought
there would be more to it. Anyone got a shorter solution?

-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: Tue, 07 Jul 1998 14:00:20 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: How do you delete arbitrary elements of an array in one go?
Message-Id: <35A21BE4.99B06E17@nortel.co.uk>

F.Quednau wrote:
> sub splice_around {
>   my $i = 0;
>   foreach (@_) { splice(@arr, ($_-$i), 1); $i++;}
> }

Won't work if the list of elements to be deleted comes in unordered, like
splice_around(6,2)

sub splice_around {
  my $i = 0;
  @args = @_;
  foreach (sort @args) { splice(@arr, ($_-$i), 1); $i++;}
}

Would do the job. Interestingly, one can't use a sort on @_. I am not exactly
sure, why...It would probably confuse something a lot.
 

-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: Tue, 07 Jul 1998 12:52:59 GMT
From: dwiesel@my-dejanews.com
Subject: how long does it take to execute some code?
Message-Id: <6nt5nb$qp2$1@nnrp1.dejanews.com>

How do I find out how long time it takes to execute some code?

// Daniel


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: 7 Jul 1998 13:33:55 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: how long does it take to execute some code?
Message-Id: <6nt843$7vr@news-central.tiac.net>

In article <6nt5nb$qp2$1@nnrp1.dejanews.com>,  <dwiesel@my-dejanews.com> wrote:
>How do I find out how long time it takes to execute some code?

You might want to look at the Benchmark module which allows you to time
several runs of code fragments.  If you're on a unix style system and want
to see how much time a program took to compile into byte code and be
executed thene there's the time command which might be helpful.  There are
some modules on the comprehensive perl archive network (CPAN, see
http://www.perl.com and follow the links, or go to ftp.funet.fi and look
under /pub/languages/perl/CPAN)

It's hard to give a more detailed & directed answer as your question is
quite general, some code is very sensitive to the data it's processing,
sometimes the initial loading & byte code compilation phase of execution
can swamp the real run time, sometimes code is IO bound etc.

Hope this helps,

Mike
-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: Tue, 07 Jul 1998 13:19:55 GMT
From: ste_jones@hotmail.com
Subject: How to authenticate clients in perl server
Message-Id: <6nt79r$ska$1@nnrp1.dejanews.com>

Hi

I'm fairly new to perl and am writing a server which (owing to the functions
it performs) needs to be able to reliably authenticate connecting clients.

One simple check I can do is to authenticate the IP address of the
originating client, however as this can be spoofed I need a greater level of
security (such as some calculation based upon a shared secret etc.).

Is there a commonly used way of addressing this type of requirement in perl?
Are there any perl modules which would be worth looking into?  The clients
are most likely to be written in perl too, however if there is a client
neutral way of performing this then would be even more usefull.

Thanks in advance.

Ste

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Tue, 07 Jul 1998 14:37:14 +0200
From: Peter Schafer <tgdscpe6@gd2.swissptt.ch>
Subject: Passing open file descriptor to an unrelated process
Message-Id: <35A2167A.7F22DB58@gd2.swissptt.ch>

In C you can pass a file descriptor using a link between two Unix domain
sockets from one process to another, unrelated process (as described in
"Unix network programming", W. Richard Stevens, 1990, chapter 6.10).

Is there a way in Perl, to pass an open file descriptor to an unrelated
process?

Thanks,
Peter


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

Date: 7 Jul 1998 12:55:50 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Passing open file descriptor to an unrelated process
Message-Id: <6nt5sm$e1g$2@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    Peter Schafer <tgdscpe6@gd2.swissptt.ch> writes:
:In C you can pass a file descriptor using a link between two Unix domain
:sockets from one process to another, unrelated process (as described in
:"Unix network programming", W. Richard Stevens, 1990, chapter 6.10).
:
:Is there a way in Perl, to pass an open file descriptor to an unrelated
:process?

You'd have to write XS glue for this, because Perl doesn't normally
have sendmsg() linked in.

--tom
-- 
        "If Christianity were to disappear, in time, even the 
		churches would suffer."  --Jonathan Swift


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

Date: Tue, 07 Jul 1998 07:49:47 -0400
From: Jay Flaherty <fty@utk.edu>
Subject: Re: Q: DBI & Table/Column Names
Message-Id: <35A20B5B.E941365E@utk.edu>

zdpurvis@my-dejanews.com wrote:

>  The thing is, we use both
> mSQL and mySQL where I work.  So, I would like to be able to use DBI.  I need
> to know how to use DBI to show the names of databases, tables, and column
> names.

Get the DBI and the mSQL-mysql modules off of CPAN, install them and
then run the command perldoc DBI and perldoc mysql to get the excellent
documentation included in the module as PODs.

Hope this helps...jay

--
**********************************************************************  
Jay Flaherty                                               fty@utk.edu
"Once in awhile you get shown the light, in the strangest of places if
you look at it right" - R. Hunter
**********************************************************************


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

Date: Tue, 07 Jul 1998 12:43:50 GMT
From: wong2020@tm.net.my (Huang)
Subject: Re: Randomize number between -0.5 and 0.5
Message-Id: <35a217e0.3503205@news.tm.net.my>

Hi,

I am trying to get a set of randomize values between -0.5 and 0.5. And
the quantity of random value is equal to how many lines in input.txt

What I am getting now is the first random weight for example: 0.044445
and the second  --> the rest will be the same say 0.123456.

If I repeat and run again the programme, the output will be the same.
I wish to have all random value. And when I run next time, I wish to
see a set of random value again.

Am I misplace my srand () ??
Thanks in advance.
Huang

On 30 Jun 1998 22:13:45 GMT, kst@king.cts.com (Keith Thompson) wrote:

>Huang (wong2020@tm.net.my) wrote:
>>    I have wrote the segments of codes to randomized number between 0
>> and 0.1 
>> 
>[...]
>> 
>>     $randnum = ( rand (1));
>>     if ($randnum >=0.1) {
>>     $randnum = ($randnum)/10;}    
>
>Be aware that the above code segment is not only inefficient (just
>use rand(0.1)), it's also incorrect.  It yields numbers in the range
>0.0 .. 0.1, but it will yield substantially fewer numbers in the range
>0.0 .. 0.01 than in the range 0.01 .. 0.1.
>
>-- 
>Keith Thompson (The_Other_Keith) kst@cts.com <http://www.ghoti.net/~kst> <*>
>Qualcomm, San Diego, California, USA  <http://www.qualcomm.com>
>It takes a Viking to raze a village.



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

Date: Tue, 7 Jul 1998 08:44:30 -0400
From: phenix@interpath.com (John Moreno)
Subject: Re: regexp s/// for removing tail end of string
Message-Id: <1dbsfx4.1kdx3lyc840u9N@roxboro0-025.dyn.interpath.net>

Ronald J Kimball <rjk@coos.dartmouth.edu> wrote:

> John Moreno <phenix@interpath.com> wrote:
> 
> > Try $path =~ s/(.+\/)/$1/ or $path =~ s/[^\/]+$//
> 
> The first one doesn't accomplish anything.

Help, I dropped a .+ and can't get up.

> The second one works though. :-)

Well, at least something does.

-- 
John Moreno


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

Date: Tue, 07 Jul 1998 14:20:34 +0200
From: Silvio del Val Hinojal <silvio@admi.org>
Subject: rnews or inews for mail2news
Message-Id: <35A21292.601F18F1@admi.org>

This is a multi-part message in MIME format.
--------------6E259AE29E4828952FB80ABC
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

Hello:
    I'm trying to execute my perl script "mail2news.pl", but one of the
parameters required is my news reader, "rnews" or "inews", but i can4t
find one. I know ISC has one, which belongs to package "INN", but when i

download it, i must compile, etc, and i can't (maybe i'm not so good
using unix). Could anyone tell me where can i find such programs (i
don't mind if it is "rnews" or "inews") ?. I work on a Sun Ultra1, Sun
Solaris 2.6.
    Thanks.

--------------6E259AE29E4828952FB80ABC
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Silvio del Val
Content-Disposition: attachment; filename="vcard.vcf"

begin:          vcard
fn:             Silvio del Val
n:              del Val;Silvio
org:            Programa ADMI - SODERCAN
adr:            C/ Castilla, 16;;;Santander;Cantabria;39002;Spain
email;internet: silvio@admi.org
title:          Telecoms Engineer
tel;work:       +34 42 367240
tel;fax:        +34 42 314462
note:           Grupo de Desarrollo NOCILLA
x-mozilla-cpt:  ;0
x-mozilla-html: TRUE
version:        2.1
end:            vcard


--------------6E259AE29E4828952FB80ABC--



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

Date: Tue, 07 Jul 1998 15:42:26 +0200
From: Naama Kraus <naamah@haifa.vnet.ibm.com>
To: HU <hurban@snet.net>
Subject: Re: Searching through a file
Message-Id: <35A225C2.3B6DC70D@haifa.vnet.ibm.com>

Hi!
Using <> in a scalar context gives the next line of input*, or undef if
there are no more lines. (e.g. $a = <FH>).
Using <> in a list context produces all remaining lines as a list; each
element is one line, including its terminating newline. (e.g. @a = <FH>).

* Up to a newline or whatever you've set $/ to.
 - Naama.

HU wrote:

> New to Perl, I have a question maybe someone can answer.
>
> I have some code to search through a CPP file finding functions but I
> cannot get to find anything that is more then two lines, I thought I
> would search for a newline followed by at least a pair of parens
> followed but a \n\{ but this never works.
>
> What would be a better expression or can I not search over multiple
> lines in Perl using <>.
>
> open (fIfile, $sIfile);
>
> while(<fIfile>)
> {
>  chomp();
>  if (/\n*.\(*.\)*\n\{/)
>  {
>   print("begin\n");
>   print($_);
>   print("\nend\n");
>  }
> }
>
> close (fIfile);





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

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

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