[19335] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1530 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 15 11:05:36 2001

Date: Wed, 15 Aug 2001 08:05:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <997887912-v10-i1530@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 15 Aug 2001     Volume: 10 Number: 1530

Today's topics:
        Another complex data structure syntax question (Stan Brown)
    Re: Another complex data structure syntax question (John J. Trammell)
    Re: Another complex data structure syntax question <ilya@martynov.org>
    Re: Another complex data structure syntax question (Stan Brown)
    Re: behavior in a while loop (djcabz)
    Re: Can someone critique my code and point to better wa (Tad McClellan)
    Re: Can someone critique my code and point to better wa (Tad McClellan)
    Re: File of Records (Anno Siegel)
        How do I: Count characters between < > in a string? <acacia@online.no>
    Re: How do I: Count characters between < > in a string? <peter.sogaard@tjgroup.com>
    Re: IF $FileArray[$index] CONTAINS..... (Pete Sohi)
    Re: Is $! a number or a string? (Anno Siegel)
    Re: newbie cgi question <paul@net366.com>
    Re: Not inserting duplicate elements into an array <jasper@guideguide.com>
    Re: Not inserting duplicate elements into an array <godzilla@stomp.stomp.tokyo>
    Re: OT: Why is there so much white space in perl docume <mjcarman@home.com>
    Re: perldoc is like Greek to a beginner?? <bernie@fantasyfarm.com>
    Re: regex question... <strawSPAM_BEGONEman@plexi.com>
    Re: Session Variables <ilya@martynov.org>
    Re: Session Variables <info@rippo>>REMOVE<<.co.uk>
    Re: Session Variables <ilya@martynov.org>
    Re: Sorting Hash of Arrays <nospam@newsranger.com>
    Re: Sorting Hash of Arrays <godzilla@stomp.stomp.tokyo>
        Switch on trace from command-shell in WinNT <Rui.Nogueira@de.bosch.com>
    Re: Test coverage without Devel::Coverage <mjcarman@home.com>
    Re: Why is there so much white space in perl documentat <miscellaneousemail@yahoo.com>
    Re: Why is there so much white space in perl documentat (Tad McClellan)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 15 Aug 2001 09:33:26 -0400
From: stanb@panix.com (Stan Brown)
Subject: Another complex data structure syntax question
Message-Id: <9ldtn6$6ag$1@panix1.panix.com>

Sigh, I really don't seem to have a good handle on this yet :-(

I have a data structure that contains a reference to an array, it looks
like this (as printed by Dumper);


$VAR1 = 'CONSUMER_BRKR_LEVEL';
$VAR2 = {
          'NULLABLE' => 'N',
          'DATA_LENGTH' => '22',
          'DATA_SCALE' => '0',
          'DATA_PRECISION' => '2',
          'MASTER_COL' => 'CONSUMER_BRKR',
          'DATA_TYPE' => 'NUMBER'
        };
$VAR3 = 'SOURCE_BRKR_LEVEL';
$VAR4 = {
          'NULLABLE' => 'N',
          'DATA_LENGTH' => '22',
          'DATA_SCALE' => '0',
          'DATA_PRECISION' => '2',
          'MASTER_COL' => 'SOURCE_BRKR',
          'DATA_TYPE' => 'NUMBER'
        };
$VAR5 = 'SOURCE_BRKR';
$VAR6 = {
          'NULLABLE' => 'N',
          'SLAVE_COLS' => [
                            'SOURCE_BRKR_LEVEL'
                          ],
          'DATA_LENGTH' => '5',
          'MASTER_FK' => 1,
          'DATA_SCALE' => undef,
          'SRC_TABLE' => 'BRKR',
          'SRC_COLS' => [
                          'BRKR',
                          'BRKR_LEVEL'
                        ],
          'DATA_PRECISION' => undef,
          'DATA_TYPE' => 'VARCHAR2'
        };
$VAR7 = 'CONSUMER_BRKR';
$VAR8 = {
          'NULLABLE' => 'N',
          'SLAVE_COLS' => [
                            'CONSUMER_BRKR_LEVEL'
                          ],
          'DATA_LENGTH' => '5',
          'MASTER_FK' => 1,
          'DATA_SCALE' => undef,
          'SRC_TABLE' => 'BRKR',
          'SRC_COLS' => [
                          'BRKR',
                          'BRKR_LEVEL'
                        ],
          'DATA_PRECISION' => undef,
          'DATA_TYPE' => 'VARCHAR2'
        };

I need to iteriate over the contents of the  SLAVE_COLS arra, for a given
major leaf. It gets passed inot a subroutine like this:

				$j = create_input_field($col,$j,\%cols,$table,1,$fk);

And here is the begining of that subroutine:

sub create_input_field($$$$$$)
#####################################################################
#
# Creates The Label and Entry widgets for a given data feild
# This is a bit ugly, and ties into the main programs data 
# structures a bit to tightly
# Optionaly adds a label in column 1 for the comment, if there
# is one in the DB
#
# INPUTS
#  1. The collum name
#  2. Row number within the parent table widget to place these widgets
#  3. pointer to the hash containing column info set for the table
#     being edited
#  4. The name of the table we are working on
#  5. Key/NonKey flag
#  6. Flag as to whether this is a free form data field
#	  or the vaules come from a foreign key
#
#  Retruns last used row number
#
####################################################################
{
my ($col,$j,$hash_pointer,$table,$is_key,$fk)=@_;

Then within that subroutine, I can access individual elemnts like this:


		-listwidth => ( "$$hash_pointer{$col}{'DATA_PRECISION'}" * 5),

So, how do I do a foreach over the SLAVE_COLS array?

I thought it would be:

foreach my $slave (@$hash_pointer{$col}{'SLAVE_COLS'})
{
	# Do something
}

But this seems to be a syntax error.


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

Date: 15 Aug 2001 13:52:45 GMT
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: Another complex data structure syntax question
Message-Id: <slrn9nkvld.4e8.trammell@haqq.hypersloth.net>

On 15 Aug 2001 09:33:26 -0400, Stan Brown <stanb@panix.com> wrote:
[snip]
> $VAR8 = {
>           'NULLABLE' => 'N',
>           'SLAVE_COLS' => [
>                             'CONSUMER_BRKR_LEVEL'
>                           ],
>           'DATA_LENGTH' => '5',
>           'MASTER_FK' => 1,
>           'DATA_SCALE' => undef,
>           'SRC_TABLE' => 'BRKR',
>           'SRC_COLS' => [
>                           'BRKR',
>                           'BRKR_LEVEL'
>                         ],
>           'DATA_PRECISION' => undef,
>           'DATA_TYPE' => 'VARCHAR2'
>         };
[snip]
> 
> foreach my $slave (@$hash_pointer{$col}{'SLAVE_COLS'})
> {
> 	# Do something
> }

This is discussed in perlref and perlreftut:

 foreach my $slave (@{ $hash_pointer{$col}{'SLAVE_COLS'} }) { ... }

-- 
It's clear that the crew to send to Mars must be comprised of midget
eunuchs.


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

Date: 15 Aug 2001 17:59:56 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Another complex data structure syntax question
Message-Id: <874rr977ab.fsf@abra.ru>


SB> [..skip..]

SB> I need to iteriate over the contents of the  SLAVE_COLS arra, for a given
SB> major leaf. It gets passed inot a subroutine like this:

SB> 				$j = create_input_field($col,$j,\%cols,$table,1,$fk);

SB> [..skip..]

SB> I thought it would be:

SB> foreach my $slave (@$hash_pointer{$col}{'SLAVE_COLS'})
SB> {
SB> 	# Do something
SB> }

SB> But this seems to be a syntax error.

It should be @{$hash_pointer{$col}{'SLAVE_COLS'}}

@$hash_pointer{$col}{'SLAVE_COLS'} is equivalent to

@{$hash_pointer}{$col}{'SLAVE_COLS'} which is incorrect construction.

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: 15 Aug 2001 11:00:57 -0400
From: stanb@panix.com (Stan Brown)
Subject: Re: Another complex data structure syntax question
Message-Id: <9le2r9$6km$1@panix3.panix.com>

In <slrn9nkvld.4e8.trammell@haqq.hypersloth.net> trammell@haqq.hypersloth.invalid (John J. Trammell) writes:

>On 15 Aug 2001 09:33:26 -0400, Stan Brown <stanb@panix.com> wrote:
>[snip]
>> $VAR8 = {
>>           'NULLABLE' => 'N',
>>           'SLAVE_COLS' => [
>>                             'CONSUMER_BRKR_LEVEL'
>>                           ],
>>           'DATA_LENGTH' => '5',
>>           'MASTER_FK' => 1,
>>           'DATA_SCALE' => undef,
>>           'SRC_TABLE' => 'BRKR',
>>           'SRC_COLS' => [
>>                           'BRKR',
>>                           'BRKR_LEVEL'
>>                         ],
>>           'DATA_PRECISION' => undef,
>>           'DATA_TYPE' => 'VARCHAR2'
>>         };
>[snip]
>> 
>> foreach my $slave (@$hash_pointer{$col}{'SLAVE_COLS'})
>> {
>> 	# Do something
>> }

>This is discussed in perlref and perlreftut:

> foreach my $slave (@{ $hash_pointer{$col}{'SLAVE_COLS'} }) { ... }

Thanks, actually I had most of that figured out, I was just making other
stupid errors, that were obscuring the basic problem.

Thanks, again.


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

Date: 15 Aug 2001 07:18:38 -0700
From: c_barbet@hotmail.com (djcabz)
Subject: Re: behavior in a while loop
Message-Id: <4256dfd1.0108150618.3ee08c75@posting.google.com>

tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrn9nj3c8.b3i.tadmc@tadmc26.august.net>...
> [ Please fix your word wrap. It breaks your code. ]
 ^^^^^ -- I am using google it breaks at 80chr/row -cb
> 
> djcabz <c_barbet@hotmail.com> wrote:
> >Hello!  I am looking for code that reads from a text file the name of
> >files to be moved and moves them.  The code I included works *HOWEVER*
> >there is a problem.  If the directory being searched 
> 
> 
> Eh? I don't see any directory searching going on anywhere in
> your code.
> 
> >is empty it then
> >moves the file associated with FSN_LIST.  Why?  *** this is the
> >important question.
>
> I do not understand the question.
> 
> If you can come up with a short and complete program that we
> can run, we can probably help you fix it.
> 
  ^^^^ - I did not see relevency in posting the entire program,
however I have realized that I was not giving adequate information
(thanks Ren Maddox for pointing this out).  I never considered the
problem was in creating the file.  I've included more[all] of the
program at the end. -cb

[snippage]

>    warn("./fsn/$_ already exists"), next if -e "./fsn/$_";
> 
> Don't want to go stomping over existing files (or do we?).
> 
   ^^^^ - thanks Tad!! excellent tip.  -cb
> 
> >    rename("$fsndir/$_", "./fsn/$_") || die ERROR_LOG, "\nCould not
> >copy $_: $!";
> 
> We dunno what is in $fsndir. You never showed us. So we can't
> help with debugging that part.
> And your diag message says "copy" when you are NOT doing
> any copying. That's kinda misleading.
>
   ^^^^ - I've corrected it to say move. I initially had "use
File::Copy" and was using the copy command. The final goal is to move
the file; I understand rename is better.  -cb

Tad, I hope you are having a better day...  I sincerly appreciate your
assistance although there is no need to attack a person who is asking
a question(s).  Educating me to appropriate etiquette for the
newsgroup is all one needs to do. Perl is NOT my first programming
language.  Admittedly I haven't coded anything other than a batch file
in years "use it or lose it" is the saying... and I've lost it :( 
Hopefully I'll get it back with practice.

<please excuse Google Post for any formating issue>

[The Problem Restated]:  If fromscan.lst is empty the program moves
the file fromscan.lst to the ./fsn directory.  If there are '*.fsn'
files to move, everything is good Life plays out as expected.  [Using
the Nutshell book to learn perl is not easy. I bought the wrong book
for Learning Perl. Bare with or correct any unusual coding habits, I
expect to get better.]


#!/usr/bin/perl -w

### perl modules


#### VARIBLE DEFINITIONS #####
$fsndir = shift || '.';

#### opening log files and creating directories
open(ERROR_LOG, ">>./fatal_error.log") or die "Could not open
ERROR_LOG: $!\n";
if (!chdir "./fsn") {
    mkdir("./fsn",0777);
    print ERROR_LOG "\nHad to create ./fsn Directory";
}

#### Create list of files FromScan
open(FSN_LIST, ">./fromscan.lst") or die ERROR_LOG, "\nCould not open
 ./fromscan.lst: $!";
opendir FSN_DIR, $fsndir or die "Error opening directory $fsndir: $!
\n";
while ($fileFSN = readdir FSN_DIR) {
    next if ($fileFSN=~/^\./ || $fileFSN!~/$\.fsn/);
    print FSN_LIST "$fileFSN\n";
}
close(FSN_LIST) or warn ERROR_LOG, "\nCould not close ./fsnlist.lst:
$!";
closedir(FSN_DIR) or warn ERROR_LOG, "Could not close $fsndir: $!";

open(FSN_LIST, "./fromscan.lst") or die ERROR_LOG, "\nCould not read
 ./fromscan.lst: $!";
while (<FSN_LIST>) {
    print "I passed this file: $_";
    chomp($_);
    rename("$fsndir/$_", "./fsn/$_") || die ERROR_LOG, "\nCould not
copy $_: $!";
}
#while ($fileFSNL = <FSN_LIST>) {
#    print "I passed this file: $fileFSNL";
#    chomp($fileFSNL);
#    rename("$fsndir/$fileFSNL", "./fsn/$fileFSNL") || die ERROR_LOG,
"\nCould not copy $fileFSNL: $!";
#}

#### closing temporary and log files   
close(ERROR_LOG) or warn ERROR_LOG, "\nfatal_error.log did not close:
$!";


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

Date: Wed, 15 Aug 2001 09:49:04 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Can someone critique my code and point to better way??
Message-Id: <slrn9nkveg.167.tadmc@tadmc26.august.net>

Carlos C. Gonzalez <miscellaneousemail@yahoo.com> wrote:
>In article <slrn9njv7o.c6u.tadmc@tadmc26.august.net>, Tad McClellan at 
>tadmc@augustmail.com says...
>
>> You should restrict variables to the smallest possible scope.
>> The variables are only needed in the while loop, so they should be
>> scoped to the while loop.
>> >  while (($key, $value) = each %file_hash)
>> >  { 
>>    while ( my($key, $value) = each %file_hash)
>>    {
>>      my @info;
>
>Makes sense Tad but I seem to recall reading somewhere that having a my 
>variable inside a looping structure recreated it for each instance of the 
>loop. Is this true?  


Yes.


>Is there truly some penalty associated with having a 
>my declaration inside of a loop?


   use Benchmark;


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


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

Date: Wed, 15 Aug 2001 09:53:03 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Can someone critique my code and point to better way??
Message-Id: <slrn9nkvlv.167.tadmc@tadmc26.august.net>

Carlos C. Gonzalez <miscellaneousemail@yahoo.com> wrote:
>In article <3B79FD3B.82259A9E@acm.org>, John W. Krahn at krahnj@acm.org 
>says...
>
>> printf $FILE_HANDLE "%-20.20s %-10.10s %-15.15s %-13.13s %-12.12s
>> %-3.3s\n", $key, (split/,/,$value)[0..4];
>
>Using the above line (- the [0..4]) has totally eliminated the need I 
>felt for the load_array sub.  I like it.  Much cleaner than my code.
>
>What's the [0..4] in your example for John?  


the ()[]  (stuff in parens followed by stuff in square brackets)
is called a "list slice".


>I am guessing it's some kind 
>of modifier to tell printf to split the value into 4 pieces and apply 
>each piece to each of the last four format specifiers??


You can read about "list slices" (and array slices, and hash slices)
in the "Slices" section of perldata.pod.


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


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

Date: 15 Aug 2001 14:33:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: File of Records
Message-Id: <9le18j$oub$2@mamenchi.zrz.TU-Berlin.DE>

According to Stephen Deken <shutupsteve@awdang.no.thanks.com>:

[...]

> foreach (<>)

This is nonsense.  "foreach" in this position is almost identical to
"while", but it reads all the file(s) into memory, for nothing.

Anno


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

Date: Wed, 15 Aug 2001 15:10:46 +0200
From: "Acacia" <acacia@online.no>
Subject: How do I: Count characters between < > in a string?
Message-Id: <8xue7.2023$Y53.43505@news1.oke.nextra.no>

It's like this... I have a webpage and on the main page I want only
the first 200 characters of each news post. However, when I include
a HTML link (or any other <> tag) such as <a href="http://yadadaya">
amongst the first 200 characters, it outputs only 174 visible characters
(200 minus the given link code). How would I go about editing the following
code in order for this to work?

$chars = 200;
$shortsummary = substr($newstext,0,$chars) . "...";

Thanks for your help!

T.Mandt
acacia@online.no




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

Date: Wed, 15 Aug 2001 16:53:31 +0200
From: "Peter Søgaard" <peter.sogaard@tjgroup.com>
Subject: Re: How do I: Count characters between < > in a string?
Message-Id: <3b7a8d00$0$20948$edfadb0f@dspool01.news.tele.dk>

> It's like this... I have a webpage and on the main page I want only
> the first 200 characters of each news post. However, when I include
> a HTML link (or any other <> tag) such as <a href="http://yadadaya">
> amongst the first 200 characters, it outputs only 174 visible characters
> (200 minus the given link code). How would I go about editing the
following
> code in order for this to work?

Maybe you can use something along the lines of this - it's not completely
foolproof( doesn't handle all tricky nested <'s and >'s ), but it's a step
in the right direction :)

$chars = 200;
$position = 0;
$flag = 0;
$subPos = 0;
foreach $char ( split(//,$newstext) ){
  $subPos++;
  if( $char eq "<" ) {$flag++;}
  if( $flag == 0 ) {$position++;}
  if( $char eq ">" && $flag > 0 ) {$flag--;}
  if($position == $chars) {last;}
}
$shortsummary = substr($newstext,0,$subPos);




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

Date: 15 Aug 2001 07:05:59 -0700
From: amanpreet.sohi@sbs.siemens.co.uk (Pete Sohi)
Subject: Re: IF $FileArray[$index] CONTAINS.....
Message-Id: <1ab8c4be.0108150605.61aea69e@posting.google.com>

Thanks folks. :-))

I think it was the Swedish Chef's code that worked for me, but perhaps
it just took me that long to get it right.

Cheers for all your help.

Pete.


Benjamin Goldberg <goldbb2@earthlink.net> wrote in message news:<3B79A40E.ABA0726F@earthlink.net>...
> Pete Sohi wrote:
> > 
> > Saviours and brave developers alike:
> > 
> > I am a Java (and ABAP) developer out of my normal territory and find
> > myself wrestling with Perl for the first time.
> > 
> > I have an array containing scalars (filenames [strings]) and want to
> > traverse it searching for filenames which CONTAIN x char sequence....
> > 
> > The conditions being CONTAINS. (I would have expected a nice keyword
> > like EXISTS or CS [as it is in ABAP] but there isnt one)
> 
> my @x = qw(foo bar blah ick);
> my $x = "b"; # all words with "b" anywhere in them
> my @y = grep { index($_,$x) != -1 } @y;
> my @z = grep /$x/, @y; # also works, but uses $x as a regular expression
> 
> Also, you don't need to store the intermediate results anywhere:
> foreach my $matched_word ( grep /$x/, @y ) {
> 	# do something with $matched_word
> }
> or even:
> foreach my $matched ( grep /$x/, qw(foo bar blah ick) ) {
> 	# do something with $matched
> }


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

Date: 15 Aug 2001 14:05:48 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Is $! a number or a string?
Message-Id: <9ldvjs$oub$1@mamenchi.zrz.TU-Berlin.DE>

According to John Lin <johnlin@chttl.com.tw>:
> Philip Newton wrote
> > On 14 Aug 2001 19:18:38 -0700, John Lin wrote:
> > 
> > > I guess there is a kind of variable that keeps a numeric value but
> > > display differently when stringified.
> > 
> > Precisely. It's even documented in the documentation, surprise surprise:
> > 
> > :  $OS_ERROR
> > :  $ERRNO
> 
> Thanks.  I did read this before I post.  But won't you feel curious about
> this kind of behavior?
> 
> $! = 5;
> my $x = $!;
> print $x;       #5: Input/output error
> print ++$x;     #6: 6
> 
> Now my question is: Is $x the same kind of variable as $! ?
 
It holds the same (slightly unusual) type of scalar.  Any scalar
has slots for both a string value and a numeric value (actually
it has two slots for numerics, but never mind that).  During the
normal course of a program these slots get filled with values that
result from converting one kind into the other, so that you normally
never know the difference.

$! however gives you a scalar whose numeric and integer slots are
filled with independent values (or rather, using an unusual conversion).
Depending on context, Perl gives you one or the other.

If you copy such a scalar to another variable (which doesn't have
the extra property of creating such values) the dual behavior will
at first remain.  Once you change the value, normal conversion rules
take over and the variable will behave normally.

More about this is in perlguts, the section "Double-Typed SVs".

Anno


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

Date: Wed, 15 Aug 2001 15:24:48 +0100
From: "Paul Fortescue" <paul@net366.com>
Subject: Re: newbie cgi question
Message-Id: <997885516.21.0.nnrp-01.d4f094e4@news.demon.co.uk>


"Yijia Zhao" <yzhao1@students.uiuc.edu> wrote in message
news:slrn9nj2ut.g40.yzhao1@ux13.cso.uiuc.edu...
> Hi, I just started programming in Perl for a web site, and I have a
> question. I would like to know how to make a perl file opens up a html
file
> in the browser after the perl file finishes all what it is supposed to do
to
> the database.
>
> So it will be like:
> the form in html
> fill in the form
> submit
> perl file gets called and does things to the database
> goes to a different html file in the browser
>
> Thanks in advance.
>
> Yijia

The way I do it is just to read in the HTML page that you want displayed,
and print it. It has the advantage that you can put some parameter
substituition into it, to be more friendly. But I expect you'll get a few
more, better replies than that!

Paul
$s="Jack runs most fast however, a snoot from Bart brashly accelerates
further spammongers. Paul sees Martynovs curly hair; has Tad picking tick
processes rather carefully.";
$i=0;$1=~m/[,.;]/?($i=0,print" "):print substr($1,$i++,1) while
$s=~m/(\w+[,.;]?)/g;






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

Date: Wed, 15 Aug 2001 14:25:34 +0100
From: Jasper McCrea <jasper@guideguide.com>
Subject: Re: Not inserting duplicate elements into an array
Message-Id: <3B7A784E.754A912D@guideguide.com>

Godzilla! wrote >

snip

> Odds of this being purely coincidental are zero.
> 
> Godzilla!
> --
> 
> #!perl
> 
> print "Content-type: text/plain\n\n";
> 
> @Array_Old = qw (http://la.znet.com/~callgirl
>                  http://la.znet.com/~callgirl/index2.html
>                  http://la.znet.com/~callgirl/rockmusi.html
>                  http://la.znet.com/~callgirl/poem-idx.html);

Try running this, and then swapping the names of Array_Old and
Array_New.
S'funny the way the 'unique' array output at the end isn't the same
length as you have below?

> 
> @Array_New = qw (http://la.znet.com/~callgirl/poem-idx.html
>                  http://la.znet.com/~callgirl/android.html
>                  http://la.znet.com/~callgirl/chahta.cgi
>                  http://la.znet.com/~callgirl/poem-idx.html
>                  http://la.znet.com/~callgirl/android.html
>                  http://la.znet.com/~callgirl/index2.html);
> 
> print "Old Array:\n";
> 
> for (@Array_Old)
>  { print "  $_\n"; }
> 
> for (@Array_New)
>  {
>   $list_old = "@Array_Old";
>   if (index ($list_old, $_) == -1)

Index may be very fast, but it's a crazy solution for this. I'm sure
Godzilla! was just testing us.

>    { push (@Array_Old, $_); }
>  }
> 
> print "\n\nUpdated Old Array:\n";
> 
> for (@Array_Old)
>  { print "  $_\n"; }
> 

I'd stick with a hash, but that's just me.

Jasper
-- 
      split//,'019617511192'.
      '17011111610114101114'.
      '21011141011840799901'.
            '17101174';
            foreach(0..
            $#_){$_[$_
            ++]^=$_[$_
            --]^=$_[$_
]^=$_[++    $_]if!($_%
2)}$g.=$_  ,chr($g)=~
 /(\w)/&&($o.=$1and
   $g='')foreach@_;
      print"$o\n"


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

Date: Wed, 15 Aug 2001 07:02:25 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Not inserting duplicate elements into an array
Message-Id: <3B7A80F1.4F6FD00C@stomp.stomp.tokyo>

Jasper McCrea wrote:
 
> Godzilla! wrote 

(snipped)

> Try running this, and then swapping the names of Array_Old and
> Array_New.
> S'funny the way the 'unique' array output at the end isn't the same
> length as you have below?

Why would I deliberately break my code?

I understand why you would.

 
> Index may be very fast, but it's a crazy solution for this. I'm sure
> Godzilla! was just testing us.


Chances are very good my code is the quickest and
the most efficient code posted in response. This
is most often the case.


Godzilla!


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

Date: Wed, 15 Aug 2001 08:26:44 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: OT: Why is there so much white space in perl documentation??
Message-Id: <3B7A7894.E230EC20@home.com>

Yves Orton wrote:
> 
> Carlos C. Gonzalez <miscellaneousemail@yahoo.com> wrote:

> If your on a *nix box then do thing the *nix way, if your on MS box
> then do it the MS way. TMTOWTDI)

What if you're on a Win* box with an Xterm session running on *nix? :)

> > On my Windows 98 the pod files look absolutely terrible from
> > the DOS prompt.  I feel like I am looking into a black hole
> > with little white letters in it =:).

You can change the color scheme, you know...

> Netscape at one time was the best browser out there. Then for whatever
> reason (I am no serious fan of MS) they got left behind. Far behind.
> IE is a MUCH better browser than NetSucks. period.

Not to fuel any holy wars here, but fortunately for those of us who are
old Netscape users this isn't true. (It *was* true until very recently,
though.) CNET's review of 6.1 at

http://home.cnet.com/software/0-3227883-8-6804817-1.html

basically says that NS 6.1 and IE 5.5 are pretty even. Having run both,
I'd have to agree.

-mjc


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

Date: Wed, 15 Aug 2001 10:27:32 -0400
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <tq0lntg6i0uq64o8ih3usi900ur1tv976m@news.supernews.net>

tadmc@augustmail.com (Tad McClellan) wrote:

} >(Come to
} >think of it, I am sure i have seen something somewhere (maybe a faq)
} >that says that perl syntax in general is not propperly speaking
} >regular either.)
} 
} 
} Most programming languages are "Context Free Grammars" the
} next step up in Chomsky's hierarchy from "Regular Grammars".

Actually, I think that very very few programming languages manage to be
context-free.  That's just too restrictive for normal/effective use, and so
while most languages use CF expressions and many CF programming constructs,
there'll almost always inevitably be *some* little corner of the language
that ends up having to be context sensitive.

  /Bernie\
-- 
Bernie Cosell                     Fantasy Farm Fibers
bernie@fantasyfarm.com            Pearisburg, VA
    -->  Too many people, too few sheep  <--          


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

Date: Wed, 15 Aug 2001 11:03:34 -0400
From: A person <strawSPAM_BEGONEman@plexi.com>
Subject: Re: regex question...
Message-Id: <3B7A8F46.AF6661A@plexi.com>

Ren Maddox wrote:

> On Tue, 14 Aug 2001, strawSPAM_BEGONEman@plexi.com wrote:
>
> > perlre is very interesting reading. The < threw me because I was
> > unaware of the distinction between look-ahead and look-behind. I
> > guess this is really a question for the implementors (you may be one
> > for all I know) , but isn't its position in the regular expression
> > itself enough to imply whether a (?<=.) or a (?=.) is look-ahead or
> > look-behind?
>
> Not really.  Consider:
>
>   $_ = "the original string\n";
>   s/(.*)(?<=orig)/\U$1/;
>   print;
>   s/(.*)(?=ORIG)/\L$1/;
>   print;
>   __END__
>   THE ORIGinal string
>   the ORIGinal string
>
> --
> Ren Maddox
> ren@tivoli.com

Rats. I thought I knew what was going on.

The second one seems clear. $MATCH would be 'THE ORIG' but (?=ORIG) has
$MATCH not include 'ORIG'.
Look ahead. Zero-width. Right???

Now the first one is not so clear. (.*) would match the entire sring of
course. Do you mean to say (?<=orig) looks from the end of the match for
'orig'? Having found 'orig' what happens next? In this example $MATCH is
'the orig'. How did 'orig' become a part of $MATCH?











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

Date: 15 Aug 2001 17:08:45 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Session Variables
Message-Id: <87zo9179nm.fsf@abra.ru>


R> Hi All,
R> I have been programming websites using ASP on an NT IIS webserver for many
R> years. One of the benefits is that you can use session variables in the
R> GLOBAL.ASA file. These variables can be used on any ASP page for every
R> session that is open.

R> Does PERL have an equivalant?
R> If not what is the best work around? (I do not want to pass variables into a
R> database or as part of a query string in the URL)

Look at CPAN module Apache::Session.

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: Wed, 15 Aug 2001 13:14:05 GMT
From: "Rippo" <info@rippo>>REMOVE<<.co.uk>
Subject: Re: Session Variables
Message-Id: <xAue7.12$p61.407@newreader.ukcore.bt.net>

Whats the URL?
Rippo


"Ilya Martynov" <ilya@martynov.org> wrote in message
news:87zo9179nm.fsf@abra.ru...
>
> R> Hi All,
> R> I have been programming websites using ASP on an NT IIS webserver for
many
> R> years. One of the benefits is that you can use session variables in the
> R> GLOBAL.ASA file. These variables can be used on any ASP page for every
> R> session that is open.
>
> R> Does PERL have an equivalant?
> R> If not what is the best work around? (I do not want to pass variables
into a
> R> database or as part of a query string in the URL)
>
> Look at CPAN module Apache::Session.
>
> --
>  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> | Ilya Martynov (http://martynov.org/)
|
> | GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6
|
> | AGAVA Software Company (http://www.agava.com/)
|
>  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-




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

Date: 15 Aug 2001 17:17:54 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Session Variables
Message-Id: <87r8ud798d.fsf@abra.ru>


R> Whats the URL?
R> Rippo

Where are all Perl modules supposed to be? Of course on CPAN :)

    http://search.cpan.org/

P.S. Read 'perldoc -q CPAN' if you don't know what CPAN is.

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: Wed, 15 Aug 2001 13:14:08 GMT
From: Drew Myers <nospam@newsranger.com>
Subject: Re: Sorting Hash of Arrays
Message-Id: <AAue7.2034$2u.32657@www.newsranger.com>

In article <3B798A7B.36D0E05F@stomp.stomp.tokyo>, Godzilla! says...
>There are ample examples of how to sort a hash within the same
>chapter of this book from which you borrowed your example. These
>examples of how to sort literally immediately follow your quoted
>example and, to discover how to sort a hash would have taken you
>no more than two to three minutes to read and understand; solutions
>where right under your finger tips.

As it happens, I did read the entire chapter before I posted, and I was unable
to get the code to work.  I am not a professional programmer, and I do not claim
to be one.  I simply hack about with Perl in my spare time, in an attempt to
learn some programming.

>Have you considered writing code to discover how?

Not only considered, I've written the code.  And it doesn't work.  If the code I
had written had worked, or I was able to find a source that presented the
material in a way I understood better, I wouldn't have posted to the newsgroup
at all.  And after being flamed multiple times on this very newsgroup for
posting non-working code, I opted to select code from the Camel book.

>Here is an idea. Read your book.

I've read it.  And I continue to read it.  As well as Learning Perl and several
other Perl books, applying all of this reading to programs I write (as I
mentioned above) in my spare time.

>Another idea is your methodology is most illogical; it is
>cumbersome, slow and inefficient. A hash cannot be sorted.
>A hash is awkward and difficult to access. A hash is a bad
>choice when an array will suffice.

Question.  How do you learn this?  Did it occur to you that maybe I didn't know
this, or maybe, just maybe, don't know the "proper" way to write a program, and
have scrounged together ideas from books and code I've written on my own over
the last year-and-a-half?  My "methodology is most illogical" because I have
none!  I don't know any "methodology".  

>Use of a hash of arrays for single dimension is a poor
>programming choice compared to use of a simple old fashion
>associative array. A hash should be a second choice.

Is an associative array not a hash?  In the index of the Camel, next to
associative arrays it says "see hashes".  How is a hash a second choice to
itself?  Please don't misread this, I'm not being critical (in this paragraph).
I just don't understand if there is indeed a difference between these two items.

>Using hashes is yet another icon of Perl 5 Cargo Cultists.
>They use a hash to razzle and dazzle, and cut off their
>noses to spite their faces via cumbersome and slow code.

I don't know what a "Perl 5 Cargo Cultist" is.  I would deduce that it is
someone who's jumped on the proverbial bandwagon.  I'm just trying to learn
Perl, and to be incinerated like this is quite discouraging.  I've been on the
fringes of this newsgroup for long enough to know that if I post something, I
should ensure I've researched my question before I post anything.  I did, as I
mention in the opening paragraph of my original post.  Pardon me if my research,
or my understanding of said research is not on the same par as yours.

Please don't misunderstand me.  I appreciate you taking your time to look at my
code (and yes, to criticize).  This is how I will learn.  I just think the
"attack-like" nature of some of the responses was unnecessary.

Drew





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

Date: Wed, 15 Aug 2001 06:57:22 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Sorting Hash of Arrays
Message-Id: <3B7A7FC2.95CB4729@stomp.stomp.tokyo>

Drew Myers wrote:
 
>  Godzilla! wrote:

> >There are ample examples of how to sort a hash within the same
> >chapter of this book from which you borrowed your example. These
> >examples of how to sort literally immediately follow your quoted
> >example and, to discover how to sort a hash would have taken you
> >no more than two to three minutes to read and understand; solutions
> >where right under your finger tips.
 
> As it happens, I did read the entire chapter before I posted,
> and I was unable to get the code to work.

Is it this challenging to copy code from a book?


> I am not a professional programmer, and I do not claim
> to be one.

Why would you claim to be a professional programmer
after stating you are not?


> >Have you considered writing code to discover how?
 
> Not only considered, I've written the code.  And it doesn't work.

Why did you not post your code and ask for help?


> I opted to select code from the Camel book.

This code you posted is lifted from Programming Perl,
Chapter 9, section 9.2.1 which is immediately followed
by several examples of sorting hashes. Why did you not
use one of those several examples of sorting or write
code based on those examples?

 
> >Here is an idea. Read your book.
 
> I've read it.  And I continue to read it.

How did you fail to take notice of all those
excellent examples of hash sorting immediately
beneath this copied code you posted?


 
> >Another idea is your methodology is most illogical; it is
> >cumbersome, slow and inefficient. A hash cannot be sorted.
> >A hash is awkward and difficult to access. A hash is a bad
> >choice when an array will suffice.
 
> Question.  How do you learn this?  Did it occur to you that maybe I didn't know
> this, or maybe, just maybe, don't know the "proper" way to write a program, and
> have scrounged together ideas from books and code I've written on my own over
> the last year-and-a-half?  My "methodology is most illogical" because I have
> none!  I don't know any "methodology".

It occurs to me you are the CLPM Troll.

 
> >Use of a hash of arrays for single dimension is a poor
> >programming choice compared to use of a simple old fashion
> >associative array. A hash should be a second choice.
 
> Is an associative array not a hash?  In the index of the Camel, next to
> associative arrays it says "see hashes".  How is a hash a second choice to
> itself?  Please don't misread this, I'm not being critical (in this paragraph).
> I just don't understand if there is indeed a difference between these two items.

This could be an associative array: @Array_Associative

This cannot be any array: %Hash

Appears to me there is a distinct difference between those two.


 
> >Using hashes is yet another icon of Perl 5 Cargo Cultists.
> >They use a hash to razzle and dazzle, and cut off their
> >noses to spite their faces via cumbersome and slow code.

> I don't know what a "Perl 5 Cargo Cultist" is.

Sure.


> Please don't misunderstand me.

I understand your deceitful practices well.


>  I just think the "attack-like" nature of some of 
> the responses was unnecessary.

This is a consequence of playing mind games in this
group. Clearly you believe yourself excused from
accepting consequences of your actions.


Godzilla!


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

Date: Wed, 15 Aug 2001 16:24:05 +0200
From: "Rui Nogueira" <Rui.Nogueira@de.bosch.com>
Subject: Switch on trace from command-shell in WinNT
Message-Id: <9le0m7$g1f$1@proxy.fe.internet.bosch.com>

Hi to all,

I start the debugging of my perl script in the "normal" way like:

perl -d foo.pl

For tracing the debug-infos I normally have to type a "t" (for switching the
trace to on) and a "c" (for continuing debugging until the end).
As I want to do it automatically I would like to include those two switches
into my

perl -d foo.pl

As I did not found any solution I tried out to set the environment variable
"PERLDB_OPTS" to "N a F L=output.txt".
This worked well, but the line numbers did not appear in the file output.txt
(only the names of my subfunctions). But I NEED the line numbers.

Can somebody help me?

Thanks a lot.

Rui




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

Date: Wed, 15 Aug 2001 08:47:24 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Test coverage without Devel::Coverage
Message-Id: <3B7A7D6C.F62688A4@home.com>

You posted this same message on both comp.lang.perl.modules and 
comp.lang.perl.misc. If you're going to post to multiple groups, please
crosspost your article instead of posting seperately. Thank you.

[crossposted to c.l.p.misc]

Rui Nogueira wrote:
>
> I want to know the test coverage of my Perl-script (some thousands
> of code lines).
> I found the Devel::Coverage module. But as this tool is still in the
> alpha phase I now want to make something own.

I've played with Devel::Coverage a bit and it works fine, despite it's
alpha status. It's chief weakness is the level of detail it provides. 
It only tells you whether or not you've reached a given line in your
source. If that's all the more granularity you need, then this module
should work fine for you.

> Does anybody of you know how I can do it without using the
> Devel::Coverage module?

I poked around on CPAN and found that someone has started work on a
Devel::Cover module. It's also on 'alpha' status, but promises to have
much better coverage detail. I haven't been able to play with it yet, so
I can't comment on it's current functionality.

-mjc


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

Date: Wed, 15 Aug 2001 14:44:46 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Re: Why is there so much white space in perl documentation??
Message-Id: <MPG.15e438d6810add2e989752@news.edmonton.telusplanet.net>

In article <74f348f7.0108150251.1a97bdef@posting.google.com>, Yves Orton 
at demerphq@hotmail.com says...

> Their copy is exactly the same as that that would be produced by
> running the appropriate pod through pod2html.  

Not quite (I think).  Their copy shows up with double and triple spaced 
code examples in both Opera 5.12 and Internet Explorer 5.01.  I don't 
even use Netscape other than for testing.  It is wayyyyyyy too slow in 
loading and accessing pages. The www.perldoc.com documentation shows up 
just fine.  Nicely formatted with the code in nice little grey boxes.

> ... being able to browse your
> documentation (structured documentation as well, the index is
> heirarchical) for something that might look like its usefull has
> serious advantages over perldoc.  

Agreed.

> Regarding the original issue of triple spaced PRE blocks in Netscape
> there is a very simple way to resolve your problem:  get a real
> Browser. Like IE 5.5 (Yes I CAN hear the linux mob hissing...)
> Netscape at one time was the best browser out there. Then for whatever
> reason (I am no serious fan of MS) they got left behind. Far behind. 
> IE is a MUCH better browser than NetSucks. period. 

IE 5.01+ is definitely without a doubt IMHO better than Netscape right 
now.  

> (Throw more
> gasoline on fire) If you have serious moral probelsm with using IE
> cause of the MS thing then you could check out opera from
> www.opera.com (self styled 'fastest browser on earth')

I use Opera almost exclusively for a browser.  Opera 5.12 is a neat 
little browser which saves me a lot of frustration through some of it's 
unique abilities. Better than even IE IMO unless one is browsing a secure 
sight (many of these test for Netscape and IE and totally leave out Opera 
and others for no good reason).  

---
Carlos 
www.internetsuccess.ca
*NOTE*: Internet Success is NOT yet fully operational so although you are 
welcomed to visit and take a look, trying to subscribe will only be a 
frustration for you as your data will not be saved at this time.


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

Date: Wed, 15 Aug 2001 09:59:31 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Why is there so much white space in perl documentation??
Message-Id: <slrn9nl023.167.tadmc@tadmc26.august.net>

Carlos C. Gonzalez <miscellaneousemail@yahoo.com> wrote:
>In article <slrn9nk15o.c6u.tadmc@tadmc26.august.net>, Tad McClellan at 
>tadmc@augustmail.com says...
>

>Maybe I will have to switch editors.  I 
>have been toying with VIM lately but whew!  What a different way of doing 
>things.  Where did all the menus and nice clean, mouseable interfaces go?   
>=:).  Got to hand it to you Unix types.  


There were no GUIs when vi was developed.

I am a touch typist. I don't want to have to move my fingers
off of the home row to grope for the mouse.


>> Does AS give you the actual .pod files that the .html files
>> are derived from?
>
>Yup.  But trying to read them in an editor is not very good for me.  
>There are a bunch of =head1, =pod, etc.. statements in them.  


Then run them through pod2text :-)


>> If not, then I'd go get the *.pods. Once you have those, you
>> can run them through pod2html, pod2latex, or whatever.
>
>Oh.  I see what you mean.  I may try that but it sure is a lot easier 
>just to go to www.perldoc.com and link through everything that is already 
>created for me.  Did someone say laziness is a mark of a good programmer? 


You can't grep perldoc.com. You can't make your own "indexes".

   grep ^= perlfaq[1-9].pod >faq.heads

Now I can search any way I like:

   grep -i list faq.heads | grep -i array



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


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 1530
***************************************


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