[11385] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4985 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 26 16:07:33 1999

Date: Fri, 26 Feb 99 13:01:54 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 26 Feb 1999     Volume: 8 Number: 4985

Today's topics:
        Perl comment dubing@lisco.com
    Re: Perl comment <hunt@queen.es.hac.com>
    Re: Perl comment <avm@atos.be>
    Re: Perl comment <jeromeo@atrieva.com>
    Re: Perl comment <tchrist@mox.perl.com>
    Re: Perl comment <stampes@xilinx.com>
    Re: Perl comment <droby@copyright.com>
    Re: Perl comment (Larry Rosler)
        perl open function <rajshreesankaran@hotmail.com>
    Re: perl open function (Larry Rosler)
    Re: perl server error with sendmail (Greg Ward)
        PerlEXE to run under Solaris 2.5? <tharold@portal.ca>
        Problem with opendir when running as CGI on NT!!!! (Gregg Seiler)
        regular expression: some confusion with "*" <zlhu@iastate.edu>
    Re: regular expression: some confusion with "*" <avm@atos.be>
    Re: regular expression: some confusion with "*" (Larry Rosler)
    Re: Remove a specific member of an array <Allan@due.net>
    Re: Remove a specific member of an array <wmwilson1@go.com>
    Re: Remove a specific member of an array (Bill Moseley)
    Re: Remove a specific member of an array <Allan@due.net>
    Re: Remove a specific member of an array (Bill Moseley)
    Re: Remove a specific member of an array (Larry Rosler)
        Scoping.  I thought this would work (Gene Johannsen)
        sort a list returned from a subroutine (Steve van der Burg)
    Re: Sorting trouble. Assistance appreciated. <droby@copyright.com>
        split(' ') confusion <tbryan@zarlut.utexas.edu>
    Re: split(' ') confusion <avm@atos.be>
    Re: split(' ') confusion <zenin@bawdycaste.org>
    Re: split(' ') confusion <tbryan@zarlut.utexas.edu>
    Re: split(' ') confusion <geckeler@gmx.net>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Fri, 26 Feb 1999 16:58:58 GMT
From: dubing@lisco.com
Subject: Perl comment
Message-Id: <7b6jsc$f8v$1@nnrp1.dejanews.com>

Hi there,

Is there any easy way to comment out a block of Perl code (like how /*....*/
is used in C) instead of putting '#' at the beginning of each line line by
line?

Any suggestion is greatly appreciated.

Bing

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Fri, 26 Feb 1999 09:16:34 -0800
From: KC <hunt@queen.es.hac.com>
Subject: Re: Perl comment
Message-Id: <36D6D6F2.F63AEC4E@queen.es.hac.com>

dubing@lisco.com wrote:
> Is there any easy way to comment out a block of Perl code (like how
> /*....*/
> is used in C) instead of putting '#' at the beginning of each line
> line by
> line?

Nope. The pound sign is it.
-- 
-----

KC


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

Date: Fri, 26 Feb 1999 18:31:26 +0100
From: Arnauld Van Muysewinkel <avm@atos.be>
To: dubing@lisco.com
Subject: Re: Perl comment
Message-Id: <36D6DA6E.400B0EC3@atos.be>

This comes from perlfaq7 (last topic) :

How can I comment out a large block of perl code?
Use embedded POD to discard it:


    # program is here

    =for nobody
    This paragraph is commented out

    # program continues

    =begin comment text

    all of this stuff

    here will be ignored
    by everyone

    =end comment text

    =cut
This can't go just anywhere. You have to put a pod directive where the parser is
expecting a new statement, not just in the middle of an expression or some other
arbitrary yacc grammar production.



dubing@lisco.com wrote:

> Hi there,
>
> Is there any easy way to comment out a block of Perl code (like how /*....*/
> is used in C) instead of putting '#' at the beginning of each line line by
> line?
>
> Any suggestion is greatly appreciated.
>
> Bing
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own

--
  -- Arnauld Van Muysewinkel

     Atos SA [ http://www.atos.be ]




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

Date: Fri, 26 Feb 1999 09:38:42 -0800
From: Jerome O'Neil <jeromeo@atrieva.com>
To: dubing@lisco.com
Subject: Re: Perl comment
Message-Id: <36D6DC22.3FEC3975@atrieva.com>

dubing@lisco.com wrote:
> 
> Hi there,
> 
> Is there any easy way to comment out a block of Perl code (like how /*....*/
> is used in C) instead of putting '#' at the beginning of each line line by
> line?

My One True Beef with perl is the lack of C-like comments.  You will be
told to use POD markers to block lots of code, but I find this method
unsatisfactory.  I like to use documentation tools for documentation,
and comments for commenting my code.

I even went so far as to ask God to influence the Keepers-of-the-Perl to
add C-like commenting in future releases.  She told me "My Son, I don't
swing that kind of weight." 
 
> Any suggestion is greatly appreciated.

Use POD to block large areas of text.

Good Luck!

-- 
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947 
The Atrieva Service: Safe and Easy Online Backup  http://www.atrieva.com


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

Date: 26 Feb 1999 11:19:15 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Perl comment
Message-Id: <36d6e5a3@csnews>

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

In comp.lang.perl.misc, dubing@lisco.com writes:
:Is there any easy way to comment out a block of Perl code (like how /*....*/
:is used in C) instead of putting '#' at the beginning of each line line by
:line?

Somehow you appear to have missed the proper answer when you studiously
searched the standard Perl documentation on your very own system.
It was there waiting for you.

% man perlfaq8

  How can I comment out a large block of perl code?

    Use embedded POD to discard it:

        # program is here

        =for nobody
        This paragraph is commented out

        # program continues

        =begin comment text

        all of this stuff

        here will be ignored
        by everyone

        =end comment text

        =cut

    This can't go just anywhere. You have to put a pod directive where
    the parser is expecting a new statement, not just in the middle of
    an expression or some other arbitrary yacc grammar production.

--tom
-- 
 Nuclear war doesn't prove who's Right, just who's Left (ABC news 10/13/87)


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

Date: 26 Feb 1999 17:42:32 GMT
From: Jeff Stampes <stampes@xilinx.com>
Subject: Re: Perl comment
Message-Id: <7b6me8$7p1@courier.xilinx.com>

dubing@lisco.com wrote:
: Is there any easy way to comment out a block of Perl code (like how /*....*/
: is used in C) instead of putting '#' at the beginning of each line line by
: line?

Use pod....

perldoc perlpod will help you, you'll be interested in =pod and =cut

-Jeff

-- 
Jeff Stampes -- Xilinx, Inc. -- Boulder, CO -- jeff.stampes@xilinx.com


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

Date: Fri, 26 Feb 1999 18:41:19 GMT
From: Don Roby <droby@copyright.com>
Subject: Re: Perl comment
Message-Id: <7b6psd$l27$1@nnrp1.dejanews.com>

In article <7b6jsc$f8v$1@nnrp1.dejanews.com>,
  dubing@lisco.com wrote:
> Hi there,
>
> Is there any easy way to comment out a block of Perl code (like how /*....*/
> is used in C) instead of putting '#' at the beginning of each line line by
> line?
>
> Any suggestion is greatly appreciated.
>

Turn it into POD.

=head
 ...
=cut

--
Don Roby

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Fri, 26 Feb 1999 12:07:56 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Perl comment
Message-Id: <MPG.11409ef5cd1cb873989698@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <36d6e5a3@csnews> on 26 Feb 1999 11:19:15 -0700, Tom 
Christiansen <tchrist@mox.perl.com> says...
 ... 
> % man perlfaq8
> 
>   How can I comment out a large block of perl code?
> 
>     Use embedded POD to discard it:
 ... 
>     This can't go just anywhere. You have to put a pod directive where
>     the parser is expecting a new statement, not just in the middle of
>     an expression or some other arbitrary yacc grammar production.

I can think of at least three other ways:

1.  Embed the code in a subroutine definition.  It will be parsed and 
not executed.

2.  Embed the code in the consequent of a FALSE conditional.  It will be 
parsed and not executed.  (Is perl smart enough to optimize the 
conditional and the block away completely, as an optimizing C compiler 
would?)

3.  Bracket the code with C preprocessor statements:
    #if 0
    ...
    #endif
and run it with the '-P' flag.  It will not be parsed and it can appear 
anywhere (except in a string-like context, of course), unlike all the 
previous methods.

Perhaps the FAQ takes too narrow a view of the possible solutions.  
Isn't choosing among them simply a matter of taste?

-- 
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 26 Feb 1999 09:08:24 -0800
From: RS <rajshreesankaran@hotmail.com>
Subject: perl open function
Message-Id: <36D6D508.34C2@hotmail.com>

I guess I did not make myself clear last time.

My main problem with the open function seems to be the following:
When I use open in the following way I can't get it to work.

$DIR = E:\\Inetpub\\dir1;
open (WR, ">$DIR\\reg.htm$VAR1") || die "cannot open reghtmval";

For some reason, perl does not seem to like the $VAR1 in the open
function. Here $VAR1 is some variable that is set earlier in the script.
I am trying to create a file that has the value of $VAR1 appended to the
end of its name and that seems to be the problem. However the following
seems to work:

$DIR = E:\\Inetpub\\dir1;
open (WR, ">$DIR\\reg.htm") || die "cannot open reghtmval";

I am working on NT with Perl 5. Any help would be appreciated.

thanks,

Rajshree


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

Date: Fri, 26 Feb 1999 12:13:48 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: perl open function
Message-Id: <MPG.1140a059d902b7a989699@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <36D6D508.34C2@hotmail.com> on Fri, 26 Feb 1999 09:08:24 -
0800, RS <rajshreesankaran@hotmail.com> says...
> My main problem with the open function seems to be the following:
> When I use open in the following way I can't get it to work.
> 
> $DIR = E:\\Inetpub\\dir1;
> open (WR, ">$DIR\\reg.htm$VAR1") || die "cannot open reghtmval";
> 
> For some reason, perl does not seem to like the $VAR1 in the open
> function. Here $VAR1 is some variable that is set earlier in the script.
> I am trying to create a file that has the value of $VAR1 appended to the
> end of its name and that seems to be the problem. However the following
> seems to work:
> 
> $DIR = E:\\Inetpub\\dir1;
> open (WR, ">$DIR\\reg.htm") || die "cannot open reghtmval";

Except for the missing double-quotes around $DIR in each of those 
snippets, what you report makes no sense whatever.

If $DIR is interpolated properly in the filename, why should not $VAR1 
not be interpolated properly???  This has nothing to do with operating 
system or perl version.

Have you tried simply printing out the constructed filename, with 
suitable delimiters so that you can see, for example, a trailing newline 
in $VAR1?  I'm willing to wager that that is your particular problem, 
sight unseen.

-- 
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 26 Feb 1999 17:58:11 GMT
From: gward@cnri.reston.va.us (Greg Ward)
Subject: Re: perl server error with sendmail
Message-Id: <7b6nbj$bv5$3@news0-alterdial.uu.net>

andy_freeman@my-dejanews.com <andy_freeman@my-dejanews.com> wrote:
> when using sendmail with -t option, if an invalid email address is entered, ie
> aaaa or bbbbb@c. I get a server error. With a valid email address, sendmail
> works fine. Anyone have any ideas?

So what's the problem?  That sounds like a useful feature to me.

        Greg
-- 
Greg Ward - software developer                    gward@cnri.reston.va.us
Corporation for National Research Initiatives    
1895 Preston White Drive                      voice: +1-703-620-8990 x287
Reston, Virginia, USA  20191-5434               fax: +1-703-620-0913


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

Date: Fri, 26 Feb 1999 11:35:06 -0600
From: Terry Haroldson <tharold@portal.ca>
Subject: PerlEXE to run under Solaris 2.5?
Message-Id: <36D6DB4A.73AC1C0A@portal.ca>

Last month, I came across some info that indicated that there might be a
version of perl available that would compile scripts into an stand-alone
executable file on Unix machines (like perlEXE (for Win32)from
activestate).  I believe it was to be available by the end of February. 
Now I can't find that anywhere.

Does anybody know where to look or what the status is?

Thanks......Terry.


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

Date: Fri, 26 Feb 1999 19:25:24 GMT
From: greggs@gizmosoft.com (Gregg Seiler)
Subject: Problem with opendir when running as CGI on NT!!!!
Message-Id: <36d6f023.2059557@news.wco.com>

I'm getting a message in the log file (running a perl script as CGI on
a web server). Here's the message:

*** 'D:\html\bkcomputerscom\html\cgi-bin\bkerror.pl' error message at:
1999/02/24 19:23:38
Undefined subroutine &main::opendir called at
D:\html\bkcomputerscom\html\cgi-bin\bkerror.pl line 7.

That's right. Undefined subroutine "opendir"!

Now here's the script:

***************************************************************************************
#!/usr/bin/perl
print "HTTP/1.0 200 OK\n";
print "Content-type: text/html \n\n";
$OrderDirectoryPath  =
'D:\\html\\bkcomputerscom\\html\\cgi-bin\\orderdir';
$Worked = 0;
print "About to open $OrderDirectoryPath<BR>\n";
$Worked = opendir (ORDERS,"$OrderDirectoryPath"); 
print "<BR>Opendir did not work</BR>" if (!$Worked);
closedir (ORDERS);
print "<BR>Finished Opening $OrderDirectoryPath";
*****************************************************************************************
Notice, it's not complaining about the path, it's the opendir it
doesn't like!!!

I call orderdir all the time on other servers, this is the only one
that complains.

Please Help!

Gregg Seiler



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

Date: Fri, 26 Feb 1999 10:54:19 -0600
From: Zhiliang Hu <zlhu@iastate.edu>
Subject: regular expression: some confusion with "*"
Message-Id: <36D6D1BA.4B9C4201@iastate.edu>

This might be a simple thing but I really don't understand why:

I want to get rid of a block of text between two lines of "*********".
Here is the script line I wrote for this:

#!/usr/bin/perl -w
open(FILE, ">$savefile") || die "cannot open $savefile";
 while (<>) {
 s/\*\*\*\*\*\*\*\*\*\d\w\s\*\*\*\*\*\*\*\*\*//g;
 print FILE "$_";
 }
close(FILE);

However in the resulting file the lines "*********" disappeared but the
text in between remains.  While I don't get any warning messages, (NOTE,
I also tried:
s/\*\*\*\*\*\*\*\*\*[0-9][a-zA-Z]*[\r\t\n]*\*\*\*\*\*\*\*\*\*//g; and
got the same thing) I am not sure how did the match with all the "*"s
go.  Is the "line mode" the thing that makes it work improperly?  How
may I get by then?

Zhiliang



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

Date: Fri, 26 Feb 1999 18:35:46 +0100
From: Arnauld Van Muysewinkel <avm@atos.be>
To: zlhu@iastate.edu
Subject: Re: regular expression: some confusion with "*"
Message-Id: <36D6DB72.5BDAD329@atos.be>

Zhiliang Hu wrote:

> This might be a simple thing but I really don't understand why:
>
> I want to get rid of a block of text between two lines of "*********".
> Here is the script line I wrote for this:
>
> #!/usr/bin/perl -w
> open(FILE, ">$savefile") || die "cannot open $savefile";
>  while (<>) {
>  s/\*\*\*\*\*\*\*\*\*\d\w\s\*\*\*\*\*\*\*\*\*//g;
>  print FILE "$_";
>  }
> close(FILE);

Try this :

$Delete = 0;
while (<>) {
  print FILE $_ unless $Delete;
  /^\*{9}$/ and $Delete = 1-$Delete;
  }

>
>
> However in the resulting file the lines "*********" disappeared but the
> text in between remains.  While I don't get any warning messages, (NOTE,
> I also tried:
> s/\*\*\*\*\*\*\*\*\*[0-9][a-zA-Z]*[\r\t\n]*\*\*\*\*\*\*\*\*\*//g; and
> got the same thing) I am not sure how did the match with all the "*"s
> go.  Is the "line mode" the thing that makes it work improperly?  How
> may I get by then?
>
> Zhiliang

--
  -- Arnauld Van Muysewinkel

     Atos SA [ http://www.atos.be ]




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

Date: Fri, 26 Feb 1999 11:56:34 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: regular expression: some confusion with "*"
Message-Id: <MPG.11409c4e4fe4a44a989697@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <36D6D1BA.4B9C4201@iastate.edu> on Fri, 26 Feb 1999 10:54:19 
-0600, Zhiliang Hu <zlhu@iastate.edu> says...
> I want to get rid of a block of text between two lines of "*********".
> Here is the script line I wrote for this:
> 
> #!/usr/bin/perl -w
> open(FILE, ">$savefile") || die "cannot open $savefile";
>  while (<>) {
>  s/\*\*\*\*\*\*\*\*\*\d\w\s\*\*\*\*\*\*\*\*\*//g;
>  print FILE "$_";

Just an observation:  The quotes are redundant, and so is $_.  This 
should say simply

   print FILE;

>  }
> close(FILE);

If the file fits conveniently into memory, the following is a very 
straightforward way of removing each flagged block, including the flag 
lines.  Read all about it in 'perlre'.

{ local $/; $_ = <DATA> }
s/^\*{9}\n.*?^\*{9}\n//gms;
print;

This regex is clearer (to me) and less typo-prone, but is (trivially) 
less efficient, I think:

s/(^\*{9}\n).*?\1//gms;

-- 
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 26 Feb 1999 11:17:11 -0500
From: "Allan M. Due" <Allan@due.net>
Subject: Re: Remove a specific member of an array
Message-Id: <7b6h1p$enp$1@camel19.mindspring.com>

Larry Rosler wrote in message ...
:In article <7b68e1$cs$1@plug.news.pipex.net>, on Fri, 26 Feb 1999
:13:40:20 -0000 r2-d2@REMOVEbigfoot.com says...
:> how can you remove a specific member of an array.
:> IE:
:> @array = ('fred','james','alex','andy');
:> and you want to delete james from the array.
:Assuming you don't know where 'james' is,
:
:  @array = grep $_ ne 'james', @array;
:
:There are many useful Perl functions.  Do `perldoc perlfunc` to get an
:overview, then `perldoc -f grep` for details on this one.
:

Well, I was just going to post that but first, can you guess, I wanted to
Benchmark the two approaches.  Still new to the Benchmark thing so I may
well have gone astray.  Here are my results.

Benchmark: timing 2000000 iterations of grep, splice...
      grep: 84 wallclock secs (82.55 usr +  0.00 sys = 82.55 CPU)
    splice: 94 wallclock secs (92.55 usr +  0.00 sys = 92.55 CPU)


#!/usr/local/bin/perl -w
use strict;

my $remove = 'three';

sub grep_it {
   my  @array = qw(one two three four five);
   @array = grep $_ ne $remove,@array;

}
sub splice_it {
    my ($i,%order);
    my  @array2 = qw(one two three four five);
    foreach (@array2) {$order{$_} = $i++}
    splice(@array2,$order{$remove},1);
}

use Benchmark;

timethese(2000000, {
'grep'  => \&grep_it,
'splice'  => \&splice_it
});

--
$email{'Allan M. Due'} = ' All@n.Due.net ';
--random quote --
All language designers are arrogant.  Goes with the territory... :-)
   Larry Wall in <1991Jul13.010945.19157@netlabs.com





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

Date: Fri, 26 Feb 1999 16:19:21 GMT
From: Mike Wilson <wmwilson1@go.com>
Subject: Re: Remove a specific member of an array
Message-Id: <7b6hhu$d1v$1@nnrp1.dejanews.com>

In article <7b68e1$cs$1@plug.news.pipex.net>,
  "Artoo" <r2-d2@REMOVEbigfoot.com> wrote:
> Hi All
>
> how can you remove a specific member of an array.
>
> IE:
> @array = ('fred','james','alex','andy');
> and you want to delete james from the array.
>
> Thanks
> Artoo
>
>
RTFM, check out pop, shift, splice..but the answer to this very specifice (I
hope this is really what you want) question is:
$array[1] = "";

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Fri, 26 Feb 1999 08:45:45 -0800
From: moseley@best.com (Bill Moseley)
Subject: Re: Remove a specific member of an array
Message-Id: <MPG.11406f964b7edd009896bf@206.184.139.132>

In article <7b6h1p$enp$1@camel19.mindspring.com>, Allan@due.net says...
> Benchmark: timing 2000000 iterations of grep, splice...
>       grep: 84 wallclock secs (82.55 usr +  0.00 sys = 82.55 CPU)
>     splice: 94 wallclock secs (92.55 usr +  0.00 sys = 92.55 CPU)

I guess it depends on how you do it.  I didn't create the lookup hash or 
the array each time.

I'd go with Larry grep suggestion, though, unless you know which element 
to remove but not it's value.

I'm not sure of how good a test this benchmark is.


46) ~ %perl test.pl
Benchmark: timing 2000000 iterations of grep, splice...
      grep: 59 wallclock secs (48.48 usr +  0.00 sys = 48.48 CPU)
    splice: 49 wallclock secs (40.52 usr +  0.00 sys = 40.52 CPU)

47) ~ %cat test.pl
#!/usr/local/bin/perl -w
use strict;

my $remove = 'three';
my  @array = qw(one two three four five);
my %order;
my $i;
foreach (@array) {$order{$_} = $i++}


sub grep_it {
   my @array1 = grep $_ ne $remove,@array;

}

sub splice_it {
    my @array1 = @array;
    splice(@array1,$order{$remove},1);
}

use Benchmark;

timethese(2000000, {
'grep'  => \&grep_it,
'splice'  => \&splice_it
});   
-- 
Bill Moseley mailto:moseley@best.com


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

Date: Fri, 26 Feb 1999 12:19:17 -0500
From: "Allan M. Due" <Allan@due.net>
Subject: Re: Remove a specific member of an array
Message-Id: <7b6km9$3na$1@camel19.mindspring.com>

Bill Moseley wrote in message ...
:In article <7b6h1p$enp$1@camel19.mindspring.com>, Allan@due.net says...
:> Benchmark: timing 2000000 iterations of grep, splice...
:>       grep: 84 wallclock secs (82.55 usr +  0.00 sys = 82.55 CPU)
:>     splice: 94 wallclock secs (92.55 usr +  0.00 sys = 92.55 CPU)
:
:I guess it depends on how you do it.  I didn't create the lookup hash or
:the array each time.
:
:I'd go with Larry grep suggestion, though, unless you know which element
:to remove but not it's value.
:
:I'm not sure of how good a test this benchmark is.
:
:
:46) ~ %perl test.pl
:Benchmark: timing 2000000 iterations of grep, splice...
:      grep: 59 wallclock secs (48.48 usr +  0.00 sys = 48.48 CPU)
:    splice: 49 wallclock secs (40.52 usr +  0.00 sys = 40.52 CPU)
:
:47) ~ %cat test.pl
:#!/usr/local/bin/perl -w
:use strict;
:
:my $remove = 'three';
:my  @array = qw(one two three four five);
:my %order;
:my $i;
:foreach (@array) {$order{$_} = $i++}
:
:sub grep_it {
:   my @array1 = grep $_ ne $remove,@array;
:}
:
:sub splice_it {
:    my @array1 = @array;
:    splice(@array1,$order{$remove},1);
:}
:
:use Benchmark;
:
:timethese(2000000, {
:'grep'  => \&grep_it,
:'splice'  => \&splice_it
:});
:--

For me, the problem with the above is that in a real application if you
remove an element from the array then your hash no longer has the correct
locations for the array elements, so you would have to rebuild the hash each
time.  That's why I did it the way that I did it.  I think my simulation is
a better estimate of the relative preformance of the two procedures.


AmD
--
$email{'Allan M. Due'} = ' All@n.Due.net ';
--random quote --
Imagination is more important than knowledge.
  Albert Einstein





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

Date: Fri, 26 Feb 1999 09:59:31 -0800
From: moseley@best.com (Bill Moseley)
Subject: Re: Remove a specific member of an array
Message-Id: <MPG.114080e37184bc0f9896c0@206.184.139.132>

In article <7b6km9$3na$1@camel19.mindspring.com>, Allan@due.net says...
> For me, the problem with the above is that in a real application if you
> remove an element from the array then your hash no longer has the correct
> locations for the array elements, so you would have to rebuild the hash each

Oh, of course.

Next time, coffee first.

-- 
Bill Moseley mailto:moseley@best.com


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

Date: Fri, 26 Feb 1999 11:35:53 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Remove a specific member of an array
Message-Id: <MPG.11409772f9315a9a989696@nntp.hpl.hp.com>

In article <7b6hhu$d1v$1@nnrp1.dejanews.com> on Fri, 26 Feb 1999 
16:19:21 GMT, Mike Wilson <wmwilson1@go.com> says...
> In article <7b68e1$cs$1@plug.news.pipex.net>,
>   "Artoo" <r2-d2@REMOVEbigfoot.com> wrote:
 ...
> > how can you remove a specific member of an array.
> >
> > IE:
> > @array = ('fred','james','alex','andy');
> > and you want to delete james from the array.
> >
> RTFM, check out pop, shift, splice..but the answer to this very specifice (I
> hope this is really what you want) question is:
> $array[1] = "";

Gah!!!  Even if that were what Artoo wanted (to remove/delete the second 
element in the array, not the 'james' element), your code doesn't 
remove/delete the element at all.  It just sets its value to the null 
string.

-- 
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 26 Feb 1999 20:43:10 GMT
From: gej@spamalot.mfg.sgi.com (Gene Johannsen)
Subject: Scoping.  I thought this would work
Message-Id: <7b710u$75$1@murrow.corp.sgi.com>

Hey:

I'm trying to use the following code to find an open cell in a 3d
array:

    my ( $x, $y, $z );
FIND:
    for $x (1..3) {
        for $y (1..3) {
            for $z (1..3) {
                print "$x, $y, $z\n";
                last FIND if $form[$x][$y][$z]{occupied} == 0 &&
                             $form[$x][$y][$z]{include} == 1;
            }
        }
    }
    print "$x, $y, $z\n";

The last print has three undefined values.

Can someone suggest a simple way to make this work?

gene
--


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

Date: Fri, 26 Feb 1999 20:46:27 GMT
From: steve.vanderburg@lhsc.on.ca (Steve van der Burg)
Subject: sort a list returned from a subroutine
Message-Id: <7b70ve$rvg@falcon.ccs.uwo.ca>

This one had me stumped for awhile today (Perl 5.00404):

use strict;

sub blah {
   my @things = ( 5,4,3,2,1 );
   return @things;
}

foreach ( sort blah() ) {
   print "thing: $_\n";
}

- - -

After a bit of experimentation, and running with perl -w (which reported 
nothing), it finally occurred to me that sort was using blah() as its 
comparison routine.  A compile-time warning (with -w) would be a good way to 
catch this, since giving sort nothing to work on (syntactically) seems a bit 
silly.

Also, the only way I can find to fix this is to explicitly define a sort
     sort { $a <=> $b } blah()
which defeats my ability to get sort's default behaviour.

 ..Steve


--
Steve van der Burg
Technical Analyst, Information Services
London Health Sciences Centre
London, Ontario, Canada
Email: steve.vanderburg@lhsc.on.ca


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

Date: Fri, 26 Feb 1999 15:51:44 GMT
From: Don Roby <droby@copyright.com>
Subject: Re: Sorting trouble. Assistance appreciated.
Message-Id: <7b6fub$bgb$1@nnrp1.dejanews.com>

In article <7b5rfh$1ojf@news1.newsguy.com>,
  <par@spri.sven> wrote:
> Hello,
>
> I have a problem that I don't really know how to solve.
> I have this file consisting of a few hundred rows of text,
> each about 700 characters long. I want to sort it like this:
>
> First with regards to the text contents of position [32-48].
> All rows with identical text in [32-48], I want to sort by the
> text in [160-192]...and so on for about five levels.
>

You need to build an internal representation of this data, probably using
substr to divide each row into "fields" appropriately for this sort and
keeping all the data in probably a "list of lists".  For help with this, you
might want to consult the perllol document.

You then need to sort this by five "fields", as described in perlfaq4 under
the heading "How do I sort an array by (anything)?".

Then just print the new data back out to your file in an appropriate way.

Try some of this, and if you still have trouble, post some code.

--
Don Roby

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Fri, 26 Feb 1999 11:36:46 -0600
From: Tom Bryan <tbryan@zarlut.utexas.edu>
Subject: split(' ') confusion
Message-Id: <36D6DBAE.9733181E@zarlut.utexas.edu>

I use Perl on occasion, but I'm confused by the way split() was used
in a program I recently came across.  Why does split(' ') behave like 
split(/ +/)?  If anything, I would have expected split(' ') to do the
same thing as split(/ /).  See below.

#!/usr/bin/perl
$str = '1   2   3   4' ; 
@arr = split(' ',$str ); 
foreach $el (@arr){
  print "$el, " ;
}
print "\n";'

OUTPUT: 1, 2, 3, 4,


#!/usr/bin/perl
$str = '1   2   3   4' ; 
@arr = split(/ /,$str ); 
foreach $el (@arr){
  print "$el, " ;
}
print "\n";'

OUTPUT:  1, , , 2, , , 3, , , 4,

-- 
tbryan@zarlut.utexas.edu
Remove the z from this address to reply.
Stop spam!  http://spam.abuse.net/spam/


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

Date: Fri, 26 Feb 1999 19:02:57 +0100
From: Arnauld Van Muysewinkel <avm@atos.be>
To: Tom Bryan <tbryan@zarlut.utexas.edu>
Subject: Re: split(' ') confusion
Message-Id: <36D6E1D1.84315B63@atos.be>

As described in the perlfunc :

>>
As a special case, specifying a PATTERN of space (' ') will split on
white space just as split() with no arguments does. Thus, split(' ') can
be used to emulate awk's default behavior, whereas split(/ /) will give
you as many null initial fields as there are leading spaces. A split() on
/\s+/ is like a split(' ') except that any leading whitespace produces a
null first field. A split() with no arguments really does a split(' ',
$_) internally.
<<


Tom Bryan wrote:

> I use Perl on occasion, but I'm confused by the way split() was used
> in a program I recently came across.  Why does split(' ') behave like
> split(/ +/)?  If anything, I would have expected split(' ') to do the
> same thing as split(/ /).  See below.
>
> #!/usr/bin/perl
> $str = '1   2   3   4' ;
> @arr = split(' ',$str );
> foreach $el (@arr){
>   print "$el, " ;
> }
> print "\n";'
>
> OUTPUT: 1, 2, 3, 4,
>
> #!/usr/bin/perl
> $str = '1   2   3   4' ;
> @arr = split(/ /,$str );
> foreach $el (@arr){
>   print "$el, " ;
> }
> print "\n";'
>
> OUTPUT:  1, , , 2, , , 3, , , 4,
>
> --
> tbryan@zarlut.utexas.edu
> Remove the z from this address to reply.
> Stop spam!  http://spam.abuse.net/spam/

--
  -- Arnauld Van Muysewinkel

     Atos SA [ http://www.atos.be ]




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

Date: 26 Feb 1999 18:06:22 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: split(' ') confusion
Message-Id: <920052348.481274@thrush.omix.com>

[posted & mailed]

Tom Bryan <tbryan@zarlut.utexas.edu> wrote:
: I use Perl on occasion, but I'm confused by the way split() was used
: in a program I recently came across.  Why does split(' ') behave like 
: split(/ +/)?  If anything, I would have expected split(' ') to do the
: same thing as split(/ /).  See below.
	>snip<

	Read The Fine Manual, ala `perldoc -f split'

            As a special case, specifying a PATTERN of space (`' '') will
            split on white space just as split with no arguments does. Thus,
            split(' ') can be used to emulate awk's default behavior,
            whereas `split(/ /)' will give you as many null initial fields
            as there are leading spaces. A split on /\s+/ is like a split('
            ') except that any leading whitespace produces a null first
            field. A split with no arguments really does a `split(' ', $_)'
            internally.

            Example:

                open(passwd, '/etc/passwd');
                while (<passwd>) {
                    ($login, $passwd, $uid, $gid, $gcos,
                        $home, $shell) = split(/:/);
                    ...
                }

            (Note that $shell above will still have a newline on it. See the
            chop, chomp, and join entries elsewhere in this document .)

-- 
-Zenin (zenin@archive.rhps.org)           From The Blue Camel we learn:
BSD:  A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts.  Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.)  The full chemical name is "Berkeley Standard Distribution".


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

Date: Fri, 26 Feb 1999 12:13:05 -0600
From: Tom Bryan <tbryan@zarlut.utexas.edu>
Subject: Re: split(' ') confusion
Message-Id: <36D6E431.B59D9C4D@zarlut.utexas.edu>

Oops. <blush>

Thanks.  I skimmed perlfunc, but I must have missed that part.
I guess I expected special cases to be mentioned more toward the 
beginning of the description.

-- 
tbryan@zarlut.utexas.edu
Remove the z from this address to reply.
Stop spam!  http://spam.abuse.net/spam/


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

Date: Fri, 26 Feb 1999 11:06:22 -0700
From: Carsten Geckeler <geckeler@gmx.net>
Subject: Re: split(' ') confusion
Message-Id: <Pine.OSF.4.05.9902261104220.30890-100000@newton.physics.arizona.edu>

On Fri, 26 Feb 1999, Tom Bryan wrote:

> I use Perl on occasion, but I'm confused by the way split() was used
> in a program I recently came across.  Why does split(' ') behave like 
> split(/ +/)?  If anything, I would have expected split(' ') to do the
> same thing as split(/ /).  See below.

It's not a bug, it's a feature. Just look at the documentation:

"As a special case, specifying a PATTERN of space (C<' '>) will split on
white space just as split with no arguments does.  Thus, split(' ') can
be used to emulate B<awk>'s default behavior, whereas C<split(/ /)>
will give you as many null initial fields as there are leading spaces.
A split on /\s+/ is like a split(' ') except that any leading
whitespace produces a null first field.  A split with no arguments
really does a C<split(' ', $_)> internally."

Cheers, Carsten
--
Carsten Geckeler <geckeler[AT]gmx[DOT]net>



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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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