[9613] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3207 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 20 17:07:21 1998

Date: Mon, 20 Jul 98 14:00:25 -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           Mon, 20 Jul 1998     Volume: 8 Number: 3207

Today's topics:
    Re: Array element translation (Greg Bacon)
    Re: Array element translation (M.J.T. Guy)
    Re: Array element translation (Abigail)
    Re: Can a Crontab run perl script <none@i_hate_spammers.com>
    Re: comp.lang.perl.moderate (Tad McClellan)
    Re: filename array (Craig Berry)
    Re: filename array (Greg Bacon)
        Flat-File Database <spurling@mindspring.com>
    Re: Flat-File Database <jdporter@min.net>
    Re: HELP : Integrating an Access DB with Perl <ssitter@uiuc.edu>
    Re: how to pass by reference (Larry Rosler)
    Re: how to pass by reference <Eric.Zylberstejn@wanadoo.com>
    Re: how to pass by reference (Greg Bacon)
    Re: how to pass by reference (M.J.T. Guy)
    Re: Interpolating variables in strings.... <JKRY3025@comenius.ms.mff.cuni.cz>
    Re: join and warnings on undef values (Charles DeRykus)
    Re: mail bomber source code for perl. <mgregory@asc.sps.mot.com>
    Re: mod_perl on RedHat 5.1 <khaines@oshconsulting.com>
    Re: need help: open file for write lindali@my-dejanews.com
    Re: Overriding builtin functions <tchrist@mox.perl.com>
    Re: perl file manipulation --help <jdporter@min.net>
    Re: Program to give day of the week from given date WedgeX@my-dejanews.com
    Re: prototypes and 'Bizarre copy of ARRAY' (M.J.T. Guy)
    Re: Q: Coding Quiz result format? <jdporter@min.net>
    Re: Turning 13 lines of text into one <jdporter@min.net>
    Re: Turning 13 lines of text into one (Larry Rosler)
    Re: What is awk better at than perl? (Larry quote) <tchrist@mox.perl.com>
    Re: Wierd behaviour of .. operator <jdporter@min.net>
    Re: Win32::Registry  QueryValue fails <JKRY3025@comenius.ms.mff.cuni.cz>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: 20 Jul 1998 19:41:28 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
Subject: Re: Array element translation
Message-Id: <6p06h8$2vl$1@info.uah.edu>

In article <8c67gsxza6.fsf@gadget.cscaper.com>,
	Randal Schwartz <merlyn@stonehenge.com> writes:
: >>>>> "Joseph" == Joseph June <jjune@midway.uchicago.edu> writes:
: 
: Joseph> I've tried
: 
: Joseph> (@seq = @comp) =~ tr/0123/3210/
: 
: Joseph> but doesn't seem to work..
: 
:     @comp = qw( 1 3 3 2 0 1 2 3 );
:     for (@seq = @comp) { $_ = 3 - $_; }
:     print "comp = @comp seq = @seq\n";

I'm surprised you didn't jump at the chance to use map. :-)

    @seq = map { $_ = 3 - $_ } @comp;  # TMTOWTDI

Greg
-- 
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF


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

Date: 20 Jul 1998 20:41:20 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Array element translation
Message-Id: <6p0a1g$46h$1@pegasus.csx.cam.ac.uk>

In article <6p06h8$2vl$1@info.uah.edu>, Greg Bacon <gbacon@cs.uah.edu> wrote:
>
>I'm surprised you didn't jump at the chance to use map. :-)
>
>    @seq = map { $_ = 3 - $_ } @comp;  # TMTOWTDI

I don't think you want to do that.    Assuming you want to leave @comp
unchanged, make that

     @seq = map { 3 - $_ } @comp;

or
     @seq = map { 3 ^ $_ } @comp;  # TMTOWTDI


Mike Guy


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

Date: 20 Jul 1998 20:55:10 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Array element translation
Message-Id: <6p0are$hrb$2@client3.news.psi.net>

Joseph June (jjune@midway.uchicago.edu) wrote on MDCCLXXXIV September
MCMXCIII in <URL: news:01bdb3c7$8b31c340$a5128780@joe>:
++ 
++ I have an array with numbers from 0 - 3.  I want to create another array
++ from the previous array... with a conversion... all of previous 0s should
++ be 3s and 1s should be 2s.. so 
++ 
++ I've tried
++ 
++ (@seq = @comp) =~ tr/0123/3210/
++ 
++ but doesn't seem to work..


map {tr/0123/3210/} @seq = @comp;



Abigail
-- 
perl -weprint\<\<EOT\; -eJust -eanother -ePerl -eHacker -eEOT


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

Date: Mon, 20 Jul 1998 09:12:53 -0700
From: "DET" <none@i_hate_spammers.com>
Subject: Re: Can a Crontab run perl script
Message-Id: <6ovq5u$os3@netaxs.com>

Whenever I've had that type of problem with a program, it usually comes down
to the fact that a crontab process doesn't have a terminal device (no ctty),
and in addition doesn't have TERM defined. Any program that wants to do
screen i/o may get upset. (I say *may*. Many programs that just output an
error message don't care).


Wali Haidri wrote in message <35AFAB40.6076@ford.com>...
>I wrote a perl (actually an oraperl) program. It runs as expected when
>submitted from the command line. But when I run it from a crontab, it
>does not work.
>
>Thanks.




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

Date: Mon, 20 Jul 1998 13:56:50 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: comp.lang.perl.moderate
Message-Id: <it30p6.34v.ln@localhost>

Zheng Yuan (zyuan@hercules.acsu.buffalo.edu) wrote:


: Subject: Re: comp.lang.perl.moderate


   You should put a *real* subject in your Subject...


: I am using a perl script to manage a large text file/database. Every time
: I need to change one entry (one line) in the file, I have to open the file
: and read each line out and write it into another file directly if it is
: not the line I want to change. At the end, I rename the new file to my
: original file.

: This process seems to take a very long time if my data file is really big.
: I wonder if anyone out there knows a more efficient way to handle this
: matter? I tried to split the file at the line I want to change, using unix
: system call, but the command "head", "tail", "split", etc can not be
: excecuted in the perl script. 


  Yes they can.

  You are doing something else wrong, but since we don't get to see
  the code does that, we cannot help...


: And I don't like to use too many system call
: anyways.


  That's a much better reason for abandoning that method  ;-)


: I would appreciate it if anyone can give me a hand here.


  Do you find the explanation given for this Frequently Asked Question
  unsatisfactory in some way?

  perlfaq, part 5:

     "How do I change one line in a file/
      delete a line in a file/
      insert a line in the middle of a file/
      append to the beginning of a file?"



--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 20 Jul 1998 19:14:44 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: filename array
Message-Id: <6p04v4$fgs$4@marina.cinenet.net>

mikehoyt (mikehoyt@compassnet.com) wrote:
: Sorry I'm a newbie.  Actually this is my first real program.  I'm trying
: to make a crude search engine for a web site, and I need to know how to
: make an array out of every .htm file in the directory.

  @htmFiles = <*.htm>;

Be sure that you replace that with the full path to the dir you're
interested in, or chdir into it, or know *for sure* that's the working dir
at the time your program runs.

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: 20 Jul 1998 19:58:41 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
Subject: Re: filename array
Message-Id: <6p07hh$2vl$3@info.uah.edu>

In article <35B391A7.6D710948@compassnet.com>,
	mikehoyt <mikehoyt@compassnet.com> writes:
: Sorry I'm a newbie.  Actually this is my first real program.  I'm trying
: to make a crude search engine for a web site, and I need to know how to
: make an array out of every .htm file in the directory.

Read the perlfunc manpage.  Search for readdir, grep, and glob.  Then read
the perlre manpage.

Hope this helps,
Greg
-- 
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF


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

Date: Mon, 20 Jul 1998 15:27:26 -0400
From: "Sam Spurling" <spurling@mindspring.com>
Subject: Flat-File Database
Message-Id: <6p05p2$n43$1@camel19.mindspring.com>

I am new to perl and am wanting to write a database that can be added to
deleted from and modified.  Does anyone have an example that I can use to
see and understand how this works in perl.




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

Date: Mon, 20 Jul 1998 20:13:43 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Flat-File Database
Message-Id: <35B3A67A.546A@min.net>

Sam Spurling wrote:
> 
> I am new to perl ...

How new?  Have you read "Learning Perl", and worked the examples
therein?  Have you read any of the documentation that comes
with your installation of perl, such as perlfaq5?
Do you know how to use perldoc?

-- 
John Porter


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

Date: Mon, 20 Jul 1998 16:18:12 -0400
From: "Sean P. Sitter" <ssitter@uiuc.edu>
To: Steve Linberg <linberg@literacy.upenn.edu>
Subject: Re: HELP : Integrating an Access DB with Perl
Message-Id: <35B3A604.7BCF@uiuc.edu>

This post is a bit alte, but....
I just did a similiar thing (acces DB with perl). The easiest way to go
about this is to have access export the DB file into an ascii field
delimited file. I like to use semicolon's as the delimiter. Then, each
field of the DB is on one line and each separated value represents a
field. Then, if you want your perl script to write to the DB, you can
simply use the same delimiters and have it print values into a single
line where the fields are separated by these delimiters. Then simply
import the delimited file into access if you want to view it or use it
outside of the script. E-mail me if you're confused

-Sean


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

Date: Mon, 20 Jul 1998 12:20:50 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: how to pass by reference
Message-Id: <MPG.101d386a84bdce2298972b@nntp.hpl.hp.com>

In article <01bdb40d$2bbb1f60$c1620c8a@lnxcompaq.lexis-nexis.com> on 20 
Jul 1998 18:35:36 GMT, Sabre Taylor 
<nonspammers.cut.after.the.period.hot_redox@hotmail.com> says...
> Hi,
> 
> 	I'd like to alter subroutine parameters without using the return function.
> I've tried the relevent resources, but haven't understood a simple way to
> do this.
> 
> 	Something similar to the C++ pass by reference is what I'm looking for.
> Any help would be appreciated.
> 
> 	Right now I'm relegated to using global variables, and kludging my code.

Have you tried it?

my $x = "foo\n";
sub baz { $_[0] = "bar\n" }
baz($x);
print $x;

> nonspammers.start.after.this.period.hot_redox@hotmail.com

Sorry, I'm much too lazy to do that.

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


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

Date: Mon, 20 Jul 1998 21:31:39 +0200
From: Eric Zylberstejn <Eric.Zylberstejn@wanadoo.com>
Subject: Re: how to pass by reference
Message-Id: <35B39B1B.75E293E8@wanadoo.com>

Hello,

Sabre Taylor wrote:
>         I'd like to alter subroutine parameters without using the return function.
> I've tried the relevent resources, but haven't understood a simple way to
> do this.

I can't believe you didn't try 'perldoc perlref'. Even 'perldoc perl' (or 'man
perl' on Unix) contains the word 'reference'.

	Eric


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

Date: 20 Jul 1998 19:56:38 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
Subject: Re: how to pass by reference
Message-Id: <6p07dm$2vl$2@info.uah.edu>

In article <01bdb40d$2bbb1f60$c1620c8a@lnxcompaq.lexis-nexis.com>,
	"Sabre Taylor" <hot_redox@hotmail.com> writes:
: I'd like to alter subroutine parameters without using the return function.
: I've tried the relevent resources, but haven't understood a simple way to
: do this.
: 
: Something similar to the C++ pass by reference is what I'm looking for.

It seems to be a big secret that Perl passes arguments to subroutines by
reference.  See for yourself:

    [14:48] mork% cat try
    #! /usr/local/bin/perl -w

    use strict;

    sub mod_parms {
        print "Got: $_[0]\n";

        $_[0] = 'modified in sub';

        print "Put: $_[0]\n\n";
    }

    my $var = 'initial value';
    print "\$var = $var\n\n";

    mod_parms $var;
    print "After mod_parms() call, \$var = $var\n";
    [14:49] mork% ./try
    $var = initial value

    Got: initial value
    Put: modified in sub

    After mod_parms() call, $var = modified in sub

The nice (!) part about this is that it works for dynamic variables and
lexicals.  Playing funny games with typeglobs only works for dynamics.

: Right now I'm relegated to using global variables, and kludging my code.

This is asking for trouble.  I feel a little better putting my valuables
where the unscrupulous can't put their grimey hands on them. :-)

Hope this helps,
Greg
-- 
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF


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

Date: 20 Jul 1998 20:48:52 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: how to pass by reference
Message-Id: <6p0afk$4aq$1@pegasus.csx.cam.ac.uk>

In article <6p07dm$2vl$2@info.uah.edu>, Greg Bacon <gbacon@cs.uah.edu> wrote:
>
>It seems to be a big secret that Perl passes arguments to subroutines by
>reference.  See for yourself:

Shhh!  Don't tell anyone, but the secrets of the Temple Lore have been
revealed in perlsub:

     Any arguments passed to the routine come in as the array @_.
     Thus if you called a function with two arguments, those
     would be stored in $_[0] and $_[1].  The array @_ is a local
     array, but its elements are aliases for the actual scalar
     parameters.  In particular, if an element $_[0] is updated,
     the corresponding argument is updated (or an error occurs if
     it is not updatable).


Mike Guy


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

Date: Mon, 20 Jul 1998 20:46:54 -0700
From: Jan Krynicky <JKRY3025@comenius.ms.mff.cuni.cz>
Subject: Re: Interpolating variables in strings....
Message-Id: <35B40F2E.126A@comenius.ms.mff.cuni.cz>

Khalid Khidhir wrote:
> 
> Hi All, I have a questioN about interpolating strings, I guess the best
> way is to shw you my code and then ask the question:
> 
> my $str = "AAbbAA";
> my $string = "this is a string that contain \$str, in it";
> 
> print "Str = $str\n";
> print "String = $string\n";
> 
> The last print statment will print $string with $str.
> 
> My question is how can I force the interpolation of the variable
> $str inside $string.
> 

print "String = ${str}ing\n";

> Thanks
> 
> +------------------------------------+
> |  Khidhir Khalid                    |

HTH, Jenda


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

Date: Mon, 20 Jul 1998 19:22:43 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: join and warnings on undef values
Message-Id: <EwEr5v.76v@news.boeing.com>

In article <EwEprv.5DG@news.boeing.com>,
Charles DeRykus <ced@bcstec.ca.boeing.com> wrote:
>In article <x7iuktmm7l.fsf@sysarch.com>, Uri Guttman  <uri@sysarch.com> wrote:
>>
>>i am using dbi/dbd and fetching rows of records, some of which have null
>>fields. these are converted to undef by dbi/dbd. i then join them for
>>printing to a file. if i have warnings enabled (which i do as a standard
>>matter, tom c) i of course get warnings with the join of undef values. i
>>currently disable warnings around that join with $^W=0. i don't want to
>>do a
>>
>>@row = map { defined( $_ ) ? $_ : '' ) @row ;
>>
>>is there any better way to do this? 
>
>
>map { $_ ||= '' } @row   
>
>is a bit shorter unless you worry about "0".
>

Or numeric 0 either.

--
Charles DeRykus


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

Date: 20 Jul 1998 13:00:30 +0930
From: Martin Gregory <mgregory@asc.sps.mot.com>
Subject: Re: mail bomber source code for perl.
Message-Id: <r8lnppmc6h.fsf@asc.sps.mot.com>

the_wildman_98@hotmail.com (The Wildman) writes:

> On 15 Jul 1998 23:29:45 GMT, Wildman's eyes rolled up in his head and
> froth dripped from his fangs when Matthew Flinchbaugh
> <matthew@nofear.hjsoft.com> said the following fighting words:
> >hey does any one have the perl source code for a mail bomber?
> Honor the followup header and repeat the question, and I'm sure somebody will
> let you have it.
> 
> >r does anyone know of any pages that have the perl or c sources to Linux
> >games?
> Two points:
> 1. The vast majority of Linux software is under the GNU GPL or an equivalent
> free software license - meaning you can get the source just by asking for it
> 2. The vast majority of Linux software are not games, and I haven't yet seen
> a game in perl.

http://www.gamerz.net/~fm

Actually, perl would have to be the language of choice for any
play-by-email game.

Martin.


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

Date: Mon, 20 Jul 1998 13:11:24 -0600
From: "Kirk D. Haines" <khaines@oshconsulting.com>
To: "Jonathan B. Joseph" <josepj00@molbio.sbphrd.com>
Subject: Re: mod_perl on RedHat 5.1
Message-Id: <6p04ip$7b$1@news-1.news.gte.net>

[email reply also sent]

> How can I determine whether mod_perl is really running on the apache web
> server (for RedHat Linux 5.1) ?
 .
 .
 .
[stuff deleted]
 .
 .
 .
> Can  anyone help me determine more conclusively on whether or not I'm
> really running mod_perl ?  Or am I really running the  perl program
> under CGI control ?

RTFM?

>From the mod_perl manpage:

       GATEWAY_INTERFACE
           The standard CGI environment variable
           GATEWAY_INTERFACE is set to CGI-Perl/1.1 when running
           under mod_perl.

       MOD_PERL
           The environment variable `MOD_PERL' is set so scripts
           can say:

            if(exists $ENV{MOD_PERL}) {
                #we're running under mod_perl
                ...
            }
            else {
                #we're NOT running under mod_perl
            }


Kirk Haines


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

Date: Mon, 20 Jul 1998 19:56:41 GMT
From: lindali@my-dejanews.com
Subject: Re: need help: open file for write
Message-Id: <6p07dq$gae$1@nnrp1.dejanews.com>

Thanks (to both Larry and Andrew)
the brackets solved the problem.

-linda

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


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

Date: 20 Jul 1998 19:48:25 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Overriding builtin functions
Message-Id: <6p06u9$keg$1@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, Yary H <yary@apicom.com> writes: :Many, not all.
I can't figure out what the exceptions are, or what :happens when you
try to override something that may not be.

Those that return a negative number in the C-language keyword()
function in the toke.c file in your Perl source kit may be overridden.
Keywords that cannot be overridden are chop, defined, delete, do, dump,
each, else, elsif, eval, exists, for, foreach, format, glob, goto, grep,
if, keys, last, local, m, map, my, next, no, package, pop, pos, print,
printf, prototype, push, q, qq, qw, qx, redo, return, s, scalar, shift,
sort, splice, split, study, sub, tie, tied, tr, undef, unless, unshift,
untie, until, use, while, and y.  The rest can.

--tom
-- 
Intel chips aren't defective.  They just seem that way.


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

Date: Mon, 20 Jul 1998 19:36:06 GMT
From: John Porter <jdporter@min.net>
Subject: Re: perl file manipulation --help
Message-Id: <35B39DA9.161F@min.net>

Zheng Yuan wrote:
> 
> I am using a perl script to manage a large text file/database. Every time
> I need to change one entry (one line) in the file, I have to open the file
> and read each line out and write it into another file directly if it is
> not the line I want to change. 
>[...]

You need to read perlfaq5.

-- 
John Porter


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

Date: Mon, 20 Jul 1998 14:44:20 GMT
From: WedgeX@my-dejanews.com
Subject: Re: Program to give day of the week from given date
Message-Id: <6ovl45$maf$1@nnrp1.dejanews.com>

In article <35b25c45.66438163@news2.cais.com>,
  root.noharvest.\@not_even\here.com wrote:
> "Quinn,M" <melinda@acm.org> Said this:
>
> >Here's what worked for me (refer also to man page "date":
> >  #!/usr/bin/perl -w
> >  #--This uses Linux system command "date" with
> >  #-- optional formatting
> >  $DateDay = `date -d 16-July-1998 '+%A'`;
> >  print ("DateDay is $DateDay \n");
> >Melinda Quinn  melinda@acm.org
> >==============================================
> >Hari Patel wrote:
> > Does anybody know how to output day of teh week for a given date
> >> in perl
> > e.g. if you have date as 13/5/98 pass it to some function which
> >> would output
> >>     Wednesday........
> >>     Please email me with any suggestions
> >>     hari.patel@bt.com
> >> Many thanks -  hari
>
> Want the day of the week?  or the number of that day of the week?
> It's all in localtime() - one way or the other:
>
>    ($sec, $min, $hour, $mday, $mon, $yr, $wday, $yday, $isdst) =
> localtime(time);
>    @days = ("Sunday", "Monday", "Tuesday", "Wednedsday", "Thursday",
> "Friday", "Saturday");
>
> $weekday = $days[$wday];
>
> For example, if you ran this snippet on monday, the value of $wday
> would be 1, and $weekday would be Monday.
>
> Obviously you can modify the list @days so it's Mon, or Monday or
> whatever.
>

I too have wondered about computing the day of the week, but I noticed
something.  These examples using time() as the input only computes today's day
of the week.  Does perl have the equivilent of mktime() to compute the number
of seconds since 1970 for arbitrary dates, so I can then pass into these
examples?

I suppose one could save the current time, set the time to whatever date, do
this, reset the time back to the saved time + 2 seconds.  But that's just ucky
(and complicated if users cannot change the system time).


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


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

Date: 20 Jul 1998 20:55:26 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: prototypes and 'Bizarre copy of ARRAY'
Message-Id: <6p0aru$4h0$1@pegasus.csx.cam.ac.uk>

F.Quednau <quednauf@nortel.co.uk> wrote:
>M.J.T. Guy wrote:
>
>> >I get a 'Bizarre copy of ARRAY in aassign at ./t line 9 (#2)' error
>> 
>> This bug is mended in both the development and maintenance branches of Perl,
>> so will be fixed in Perl 5.004_05 and in Perl 5.005.
>
>One shouldn't get rid of such a classy error message, though :)

The error message is still there.   But it is a "should not happen"
error.   And until the next bug is discovered, it won't happen.


Mike Guy


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

Date: Mon, 20 Jul 1998 14:43:45 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Q: Coding Quiz result format?
Message-Id: <35B35921.554@min.net>

Uri Guttman wrote:
> 
> some answers are basically on the money but worded slightly differently,

What's the value in scoring well on Uri's quiz?


> some are sarcastic/silly

Why not?  25% of the questions were silly.


> my answers are not right by fiat but by
> many years of coding and learning about other people's coding
> methodologies and styles.

"I am now qualified to say that my answers are authoritative."


> no one has yet shown me a better
> set of answers and backed it with logic

"better" is pretty qualitative, isn't it.


> and only a few so totally disagree with
> them that we have to agree to disagree (but they are wrong :-).

Smiley or no, that sums up your attitude.

-- 
John Porter


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

Date: Mon, 20 Jul 1998 20:26:58 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Turning 13 lines of text into one
Message-Id: <35B3A994.53EC@min.net>

Larry wrote:
> 
>             I'm just feeling my way around here, and have a little project
> I'm trying to get a bead on.  I've got a text file that contains about
> 10,000 records in it, each record consisting of 13 lines of text, while each
> line is exactly 80 characters long.  I need to take each "record", and turn
> the 13 lines of text into one really long line.  What's the best way to do
> so?  Thanks for any and all suggestions!

Larry, is there any distinguishing feature (such as a blank line) that
separates each record?  If so, then I would make the $/ be that string,
and that way you get automatic parsing of input into records.
E.g., if it's an empty line, then:

$/ = "";     # parse on empty lines
$\ = "\n"    # append newline to each print
while (<>) { # get next record from stdin
  s/\n//g;   # remove all newlines, effectively concatenating all 13
lines
  print;     # to stdout
}

If the 13-line records are quite contiguous, then you could try this:

while (<>) {
  chomp if $. % 13;
  print;
}

This strips the newline from all lines except every 13th line.

In any case, because you have a large number of records, I would avoid
reading the entire input into memory at once.  while(<>){print} is good.

-- 
John Porter


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

Date: Mon, 20 Jul 1998 13:42:05 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Turning 13 lines of text into one
Message-Id: <MPG.101d4b773b961c9798972c@nntp.hpl.hp.com>

[This followup was posted to comp.lang.perl.misc and a copy was sent to 
the cited author.]

In article <6p02uq$mt0$1@heliodor.xara.net> on Mon, 20 Jul 1998 19:41:48 
+0100, Martin <minich@globalnet.co.uk> says...
> >            I'm just feeling my way around here, and have a little project
> >I'm trying to get a bead on.  I've got a text file that contains about
> >10,000 records in it, each record consisting of 13 lines of text, while each
> >line is exactly 80 characters long.  I need to take each "record", and turn
> >the 13 lines of text into one really long line.  What's the best way to do
> >so?  Thanks for any and all suggestions!
> 
> I've just spent a few weeks programming a lot of Perl and this was one of
> the functions I used. I'm sure there's a much more elegant - shorter way of
> doing it involving the odd / here and there; but this is what I used.

Well, yes there is.  From `perldoc -f join`:  'The most efficient way to 
concatenate many strings together is to ~join~ them with a null string.'

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

$s = 'x' x 80;

timethese(1 << (shift || 0), {
    'Concat' => sub { my $i; $_ = ''; for ($i = 0; $i < 13; ++$i)
        { $_ = "$_$s" } },
    'Join'   => sub { $_ = join '', ($s) x 13 },
});
__END__

Benchmark: timing 16384 iterations of Concat, Join...
    Concat: 56 secs ( 5.67 usr  0.07 sys =  5.74 cpu)
      Join: 17 secs ( 1.03 usr  0.02 sys =  1.05 cpu)

>From Blue Camel, p. 541:  'Prefer join("", ...) to a series of 
concatenated strings.  Multiple concatenations may cause strings to be 
copied back and forth multiple times.  The ~join~ operator avoids this.'

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


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

Date: 20 Jul 1998 20:42:46 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: What is awk better at than perl? (Larry quote)
Message-Id: <6p0a46$mtc$1@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, 
    Uri Guttman <uri@sysarch.com> writes:
:this wish has been discussed before. since perl's re can do so many
:powerful things, it can lead into deep re recursion that will not return
:in your lifetime. 

Recursion in not necessary for that.  Solving regexes with backreferences
is an exponential problem, which is itself a problem.

--tom
-- 
A factor of 3000 is actually significant --Andrew Hume


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

Date: Mon, 20 Jul 1998 19:42:58 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Wierd behaviour of .. operator
Message-Id: <35B39F45.5F03@min.net>

Richard Proctor wrote:
> 
> (Ok I am new to posting here, but have lurked for months and used Perl for a
> year or so, so not a newbie).

Newbie enough not to have RTFM first!


> foreach('A1'..'A13') ...
> 
> And had expected the loop to operate with A1, A2, A3, A4, A5, A6, A7, A8, A9,
> A10, A11, A12 and A13.  BUT was rather surprised to find it generate A1..A9,
> then B0..B9 ... Z9 then continue with AA0..AA9 ... ZZ0..ZZ9!  Thus
> generating  7019 values rather than the 13 I had expected (it never did
> generate A10 .. A13). 'A1'..'A9' behaves as expected.
> 
> Now when I realised what had happend, I trivially corrected the problem,
> however could somebody explain why it did this?  Is it a bug?  Should
> it generate a warning?

perldoc perlop:
	The range operator (in a list context) makes use of the
	magical auto-increment algorithm if the operands are
	strings.

see also the section on the auto-increment operator.

-- 
John Porter


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

Date: Mon, 20 Jul 1998 21:03:23 -0700
From: Jan Krynicky <JKRY3025@comenius.ms.mff.cuni.cz>
To: Mark Stang <markstang@ncgroup.com>
Subject: Re: Win32::Registry  QueryValue fails
Message-Id: <35B4130B.7A0D@comenius.ms.mff.cuni.cz>

Mark Stang wrote:
> 
> I admit from the start I am a newbie at perl.
> I am using Activestate Perl for Win32 build 316
> which is Perl 5.003_07
> 
> I am simply trying to read a value in the registry.
> The code:
> ===================================
> #!/perl/bin/perl -w
> use Win32::Registry;
> 
> $HKEY_CURRENT_USER->Open('Console', $NewObj) || die $!;
> $NewObj->QueryValue('CursorSize', $testval) || die $!;
> print $testval;
> ======================================
> 
> The QueryValue Method fails
> 
> Would someone please tell me what I'm doing wrong?

The QueryValue function ,looks for the default value in a specified
subkey, instead of for a specified value. You have to use QueryValueEx.
I'm afraid that the method is not present in Registry.pm though 
the underlying call is provided. You should either use


 RegQueryValueEx($reg->{handle},...)

or get a patch for Registry.pm.

Say from http://www.fmi.cz/private/Jenda
This one contains also many additonal methods.
Eg. Import/Export, Load/UnLoad/Save, FindKey/FindValue, etc.


HTH, Jenda


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

Date: 12 Jul 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 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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

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