[15753] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3166 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 25 18:15:54 2000

Date: Thu, 25 May 2000 15:15:30 -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: <959292930-v9-i3166@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 25 May 2000     Volume: 9 Number: 3166

Today's topics:
        Oraperl hangup - help! <tdunbar@vt.edu>
    Re: Oraperl hangup - help! <makarand_kulkarni@My-Deja.com>
    Re: Passing Objects between Scripts (Abigail)
    Re: Perl Editor for Linux (Csaba Raduly)
    Re: Perl unusable as a programming language (Simon Cozens)
    Re: Perl unusable as a programming language zenin@bawdycaste.org
        PerLotto 0.1a1. My first "real" Perl script!!! <y-o-y@home.com>
    Re: Printing of Tk Window in NT <bert@scanlaser.nl>
    Re: randomizing (anagramming words) <sariq@texas.net>
    Re: randomizing (anagramming words) <aqumsieh@hyperchip.com>
    Re: randomizing (anagramming words) (Abigail)
    Re: randomizing (anagramming words) (Abigail)
    Re: randomizing (anagramming words) (Abigail)
    Re: randomizing (anagramming words) (Abigail)
    Re: randomizing (anagramming words) <bert@scanlaser.nl>
    Re: reading lines of file into several arrays <lr@hpl.hp.com>
        security problems in Perl code jdimov@cis.clarion.edu
    Re: Simple alphabetical name sort <jeff@vpservices.com>
    Re: Sorting a Database jzoetewey@my-deja.com
    Re: Sorting a Database <lr@hpl.hp.com>
    Re: updated : Re: regexes *sigh* damn I hate these thin <godzilla@stomp.stomp.tokyo>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 25 May 2000 15:23:30 -0400
From: Thomas Dunbar <tdunbar@vt.edu>
Subject: Oraperl hangup - help!
Message-Id: <392D7DB2.975B1BBD@vt.edu>

The following script hangs our Oracle instance after 16,285 records.  It
doesn't appear to be anything related to the unix process, I've run
10,000 records on one process, and then switched to another process,
hangs after the same total number of records.  No error messages. Have
to restart Oracle to clear
the situation.

#!/usr/local/bin/perl5.00404 -w

use Oraperl
{
    my ($lda);
    my $tnsname = "";
    my $userid = "authsystem";
    my $password = "xxxxxx";

    $lda = $Oraperl::ora_login($tnsname, $userid, $password);
    if (not defined($lda)) {
        print "Error on oracle login\n";
        exit;
    }
    for ($i=0; $i<100000; $i++) {
        print "record " . (i + 1) . "\n";
        &Oraperl::ora_do($lda,
            "insert into ocitest (field1, field2) values('one',
'two')");
        if (defined($Oraperl::ora_errno)) {
            print $Oraperl::ora_errstr . "\n";
            exit;
        }
        &Oraperl::ora_do($lda, "commit");
        if (defined($Oraperl::ora_errno)) {
            print $Oraperl::ora_errstr . "\n";
            exit;
        }
    }
}




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

Date: Thu, 25 May 2000 13:20:31 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Re: Oraperl hangup - help!
Message-Id: <392D8B0F.9E4A7581@My-Deja.com>

> The following script hangs our Oracle instance after 16,285 records.  It

If you think this problem is Oraperl specific then you should try using
DBI and DBD::oracle. Oraperl was useful in the good old days when
Perl 4 was around. Oraperl as it exists for Perl 5 is just a cool wrapper
around DBI and DBD::Oracle. However, it does not expose all of the
power that DBI can provide to users.
--



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

Date: 25 May 2000 19:27:54 GMT
From: abigail@arena-i.com (Abigail)
Subject: Re: Passing Objects between Scripts
Message-Id: <8gjurp$4hu$1@news.panix.com>

On Thu, 25 May 2000 23:22:11 +0800, Aaron <vandemen@yahoo.com> wrote:
++ Hello,
++ 
++ Is it possible to pass an object reference from one script to another script
++ ??

No. A reference is a pointer into the private space of a program; anything
their will be gone (and reused by the OS) once the program is dead.

++ The goal is to be able to run a telnet session from a web browser.  Since
++ HTTP is connectionless I need to be able to find a way of maintaining a
++ reference to the telnet session between command submits from the web page.

Even if you could pass references between programs, that isn't going
to help you with that at all. You CGI program has no direct socket
to the browser anyway; the browser talks to the server, and the server
talks to the CGI program. 

Just send the browser a telnet URL, and let the browser sort it out.
The user might have to upgrade their browser; possibly to Lynx.

None of this has anything to do with Perl though.


Abigail


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

Date: 25 May 2000 18:12:25 GMT
From: csaba_r@my-deja.com (Csaba Raduly)
Subject: Re: Perl Editor for Linux
Message-Id: <8F3FC9BAEquuxi@193.82.145.131>

25 May 2000: A formal bug report was sent to Seti@Home, because the
following message originated from elaine@chaos.wustl.edu (Elaine
Ashton) was reported as containing signs of intelligence: 

>in article 8ghahj$qbt$1@nnrp1.deja.com, houseofpain@my-deja.com at
>houseofpain@my-deja.com quoth:
>
>> Can anyone recomend a good Perl Editor for Linux.  Someting i can
>> use to trace through my code.
>
>Try ed.
>

I think that suggestion just about qualifies as a "cruel and unusual 
punishment" (as per %dth ammendment). Does asking a FAQ justify that ?
:-)
-- 
Csaba Raduly, Software Developer (OS/2), Sophos Anti-Virus
mailto:csaba.raduly@sophos.com      http://www.sophos.com/
US Support +1 888 SOPHOS 9      UK Support +44 1235 559933
Life is complex, with real and imaginary parts.


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

Date: 25 May 2000 19:26:10 GMT
From: simon@brecon.co.uk (Simon Cozens)
Subject: Re: Perl unusable as a programming language
Message-Id: <slrn8iqvii.be1.simon@justanother.perlhacker.org>

The Glauber (comp.lang.perl.moderated):
>In article <8f498v$751$1@charm.magnus.acs.ohio-state.edu>,
>  ilya@math.ohio-state.edu (Ilya Zakharevich) wrote:
>[...]
>> Let me reiterate my current opinion on the topic: the reason for my
>> puzzlement (and your trouble) is the difference between Perl as a
>> scripting language and Perl as a programming language.  Perl is
>> absolutely fine as a scripting language.  Perl is pretty unusable as a
>> programming language.
>[...]
>
>Is it just me or did this scare the heck out of anybody else?

Not particularly. Scripting, if it has any meaning at all, means telling
a computer what you want it to do. Programming means telling a computer
what you want it to do. See the difference? Yup, it's just about the
impression you want to make on the reader. Nothing more.

I program in Perl. I've been doing so every day for the past three or
four years. Ilya may want to tell me that this is impossible, but this
does not change the fact that I have been doing it. If you've programmed
in Perl, it doesn't change the fact that you've been doing it either.

>After reading a lot of posts in this thread, i'm not sure if the
>problem is the quality of the perl interpreter or the lack of formal
>definition of the language. Which one is it?

I think Ilya's beef is with the lack of formal definition of the
language. But I think that's a cool feature. No formal definition
of the language means Perl is defined by what perl does. Ergo, perl
is a perfect, bug-free Perl interpreter. :)

-- 
I have had my television aerials removed.  It's the moral equivalent
of a prostate operation.
		-- Malcolm Muggeridge


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

Date: 25 May 2000 18:48:27 GMT
From: zenin@bawdycaste.org
Subject: Re: Perl unusable as a programming language
Message-Id: <959280718.733283@thrush.omix.com>

The Glauber <theglauber@my-deja.com> wrote:
: In article <8f498v$751$1@charm.magnus.acs.ohio-state.edu>,
:   ilya@math.ohio-state.edu (Ilya Zakharevich) wrote:
: [...]
:> Let me reiterate my current opinion on the topic: the reason for my
:> puzzlement (and your trouble) is the difference between Perl as a
:> scripting language and Perl as a programming language.  Perl is
:> absolutely fine as a scripting language.  Perl is pretty unusable as a
:> programming language.
: [...]
: 
: Is it just me or did this scare the heck out of anybody else?

	No, not really.  It's just Ilya being Ilya, so far as I can see. 
	I've grown used to reading it.

: It's something to hear people ranting about Perl, but it's something else
: when someone as important to Perl as Ilya is, says that Perl is unusable
: as a programming language.

	That's just Ilya.  Few people are as brilliant and ridiculous at the
	same time.

: I'd really like to know what Larry Wall thinks of this (i wonder if he's
: lurking; i haven't seen a post from him for ages).
: 
: After reading a lot of posts in this thread, i'm not sure if the problem
: is the quality of the perl interpreter or the lack of formal definition of
: the language. Which one is it?

	If there is a problem at all depends on who you ask, really.  Perl
	is very DWIM.  Being DWIM is fairily at odds with having a formal
	definition and the ability to be DWIM is directly related to the
	quality of the interpreter. :-)

: Certainly Perl has enough features already? Should the effort now go
: towards cleaning up the interpreter? (Or towards learning Java? :-))

	What do you mean by cleaning it up?  The internals could use a lot
	of cleaning up, which is AFAIK what Topaz is about.  For better or
	worse however, the language can't be cleaned up or it wouldn't be
	Perl.

-- 
-Zenin (zenin@archive.rhps.org)         Caffeine...for the mind.
                                        Pizza......for the body.
                                        Sushi......for the soul.
                                             -- User Friendly


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

Date: Thu, 25 May 2000 18:13:32 GMT
From: A <y-o-y@home.com>
Subject: PerLotto 0.1a1. My first "real" Perl script!!!
Message-Id: <g3eX4.209048$Tn4.1829822@news1.rdc2.pa.home.com>

It's not perfect and it's not finished but it works. At least it does 
what I want, kinda/sorta. Thought I'd share my newfound success.

For Jeff, who told me that learning Perl was a good thing. ;-)

All suggestions and comments are highly appreciated. Enjoy!

#PerLotto 0.1a1 My first "real" Perl script, i.e. it does what I want, 
#May 25, 1999 by Andy Burns
#
#Lotto games checker
#
#Needs a text file "games" in the same dir as this script ???
#game file should be one line per game delimited by spaces:
#1 2 3 4 5 6
#1 2 3 4 5 7 etc.
#STDIN asks you for the winning numbers.
#Results are to STDOUT
#Need to do more error checking but I've learned enough for one day.


print("Enter winning number separated by spaces: ");
$input = <STDIN>;
chomp($input);
@lotto = (split/ /, $input);
open(IN, 'games');
while ($line = <IN>)
{
  chomp($line);
  @win = (split/ /, $line);

  $picks = 0;

#Check for duplicate numbers in a game
for ($y=$#win ; $y>=0 ; $y--)
  {
  for ($x=$#win ; $x>=0 ; $x--)
    {
    if ($y == $x)
      {
      }
    else
      {
      if ($win[$y] == $win[$x])
         {
         print("INALID: Duplicate number in game below.\n");
         $y = 0;
         }
      }
    }
  }


#Check for too few entries in a game
if ($#win != $#lotto)
 {
  if ($#win < $#lotto)
   {
   print("INALID: Too few numbers in game below.\n");
   }
  else
   {
   print("INVALID: Too many numbers in game below.\n");
   }
 }


  for ($y=$#lotto ; $y>=0 ; $y--)
  {
    for ($x=$#win ; $x>=0 ; $x--)
    {
      if (($lotto[$y]) == ($win[$x]))
      {
      $picks++;
      }
    }
  }

 $last = $#lotto +2;
 $win[$last] = "--$picks";

 foreach $item (@win)
  {
  print("$item ");
  }

 print("\b\n");
 
}

close(IN);

Andy


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

Date: Thu, 25 May 2000 22:28:46 +0200
From: Bert IJff <bert@scanlaser.nl>
To: w-woerlinger@ti.com
Subject: Re: Printing of Tk Window in NT
Message-Id: <392D8CFE.84D836B4@scanlaser.nl>

Willibald Woerlinger wrote:
> 
> I cannot find any information neither in books nor in newsgroups
> on how to printout a Perl/Tk window from inside the perl program.
> 
> I'm using Activestate Perl 5.19 on Windown NT 4.0 system.
> 
> Any infos, docs or samples are appriciated.
> 
> Thanks,
> Willi

If you have the book Learning Perl/Tk, look at chapter 9 at 
"Rendering the Canvas as PostScript" (page 204 in my book)


If you don't have the book
perldoc Tk::Canvas
and search for postscript (page 13 in my version)

Regards,
Bert


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

Date: Thu, 25 May 2000 13:11:41 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: randomizing (anagramming words)
Message-Id: <392D6CDD.8F1C77BF@texas.net>

Ala Qumsieh wrote:
> 
> Tom Briles <sariq@texas.net> writes:
> >
> > Ala's
> > solution requires >= 5.005.
> 
> I don't think so. 'EXPR while EXPR' has been supported for a while
> (don't know when it was first introduced, but definitely before
> 5.005). I guess you might have confused this with 'EXPR for EXPR' which
> was introduced in 5.005.

No.  I was referring to four-argument substr, introduced in 5.005.

- Tom


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

Date: Thu, 25 May 2000 18:32:02 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: randomizing (anagramming words)
Message-Id: <7a3dn65vmi.fsf@Merlin.i-did-not-set--mail-host-address--so-shoot-me>


Tom Briles <sariq@texas.net> writes:

> No.  I was referring to four-argument substr, introduced in 5.005.

Oh cool. I didn't know that. Thanks!

--Ala


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

Date: 25 May 2000 18:50:33 GMT
From: abigail@arena-i.com (Abigail)
Subject: Re: randomizing (anagramming words)
Message-Id: <8gjslp$3qg$1@news.panix.com>

On Thu, 25 May 2000 12:33:59 +0100, Kevin Miles <kdmiles@lucent.com> wrote:
++ If I want to randomize a word 
++ 
++ i.e.
++ 
++ England   
++ 
++ to be (as an example)
++ 
++ glnEand
++ 
++ 
++ How do I do this in PERL??? Can I randmize a string??


Of course you can.

    for (my $i = length ($str); -- $i;) {
        substr $str, $i, 1, substr $str, rand $i + 1, 1, substr $str, $i, 1;
    }


Cute, don't you think?


Abigail


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

Date: 25 May 2000 18:52:36 GMT
From: abigail@arena-i.com (Abigail)
Subject: Re: randomizing (anagramming words)
Message-Id: <8gjspk$3qg$2@news.panix.com>

On 25 May 2000 17:48:03 +0100, nobull@mail.com <nobull@mail.com> wrote:
++ jacklam@math.uio.no (Peter J. Acklam) writes:
++ 
++ > Then shuffle the elements in @chars as described in perlfaq4: "How do I
++ > shuffle an array randomly?".  Finally join the shuffled characters
++ > together:
++ 
++ Since words tend not to be very long I wouldn't bother with
++ Fisher-Yates.
++ 
++ join '' => sort { 0.5 <=> rand } split // => $string;
++ 
++ Note: the perldoc page for sort() says this isn't safe, however
++ perldelta says it is safe as of 5.00503.  (I'm not 100% sure it's
++ actually random - anyone know for sure?)


Since it isn't defined how the sorting algorithm works, you cannot
conclude the above algorithm is fair (that is, have each possible
anagram the same chance of appearing).



Abigail


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

Date: 25 May 2000 18:54:52 GMT
From: abigail@arena-i.com (Abigail)
Subject: Re: randomizing (anagramming words)
Message-Id: <8gjstr$3qg$3@news.panix.com>

On Thu, 25 May 2000 11:49:50 GMT,
Rafael Garcia-Suarez <garcia_suarez@hotmail.com> wrote:
++ 
++ perldoc -q shuffle
++   Found in /usr/lib/perl5/5.00503/pod/perlfaq4.pod
++   How do I shuffle an array randomly?
++ 
++ Convert your string to an array of characters and apply the algorithm
++ described here.


You can apply the algorithm without converting the string to an array
of characters. After all, strings are mutatable and indexable by offset,
which is all you need for the algorithm from the FAQ.


Abigail


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

Date: 25 May 2000 18:59:13 GMT
From: abigail@arena-i.com (Abigail)
Subject: Re: randomizing (anagramming words)
Message-Id: <8gjt61$3qg$4@news.panix.com>

On Thu, 25 May 2000 11:08:16 -0500, Tom Briles <sariq@texas.net> wrote:
++ Kevin Miles wrote:
++ > 
++ > Ala Qumsieh wrote:
++ > >
++ > >         my $string = 'England';
++ > >         my $new;
++ > >
++ > >         $new .= $_ while $_ = substr $string =>
++ > >                                      rand length $string, 1, '';
++ 
++ Nifty.
++ 
++ > hmm doesn't seem to work.....I'm miffed!
++ 
++ It would be much more useful if you posted more detail than "doesn't
++ seem to work", but the problem is most likely your Perl version. Ala's
++ solution requires >= 5.005.


It also requires the string not to contain the character '0'.
But that can be fixed by adding a defined, or writing it as:

    $new .= substr $string => rand length $string, 1, '' while length $string;

Furthermore, because $string has to be reassembled each time a 
character was taken out, the running time is quadratic. Not a 
big deal for 7 character strings, but for larger strings, it is.



Abigail


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

Date: Thu, 25 May 2000 22:19:20 +0200
From: Bert IJff <bert@scanlaser.nl>
Subject: Re: randomizing (anagramming words)
Message-Id: <392D8AC8.FBE76649@scanlaser.nl>



Tom Briles wrote:
> 
SNIP
> 
> No.  I was referring to four-argument substr, introduced in 5.005.


Hmm, that's strange...

I run 5.004_04 and according to perldoc -f substr I could use the
REPLACEMENT
argument (i.e. the fourth)
but: apparently I need 5.005 as Tom says, because I get an error:

Too many arguments for substr at ..... near "'';"

Have to find out why documentation doesn't comply with running version
 ....

[ a few minutes later ]

Hmm, apparently someone installed 5.005_03, set up the docs for it and
forgot
to symlink /usr/local/bin/perl to the 5.005_03 version....

Tried 5.005_03 and it worked.
Thanks


Bert


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

Date: Thu, 25 May 2000 14:14:32 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: reading lines of file into several arrays
Message-Id: <MPG.13973793c9e3672198aae1@nntp.hpl.hp.com>

In article <87u2fmhdyu.fsf@limey.hpcc.uh.edu> on 25 May 2000 10:00:25 -
0500, Tony Curtis <tony_curtis32@yahoo.com> says...

 ...

>     my @lines;
>     
>     while (<DATA>) {
>       chomp;
>       my @words = split /\s+/;   # or / / if you KNOW it is one space
>       push @lines, \@words;
>     }

If you use the default split, the chomp() is unnecessary (that seems to 
be my theme today :-).

      push @lines, [ split ] while <DATA>;

Or, if the file isn't too large,

      my @lines = map [ split ] => <DATA>;

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


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

Date: Thu, 25 May 2000 18:38:26 GMT
From: jdimov@cis.clarion.edu
Subject: security problems in Perl code
Message-Id: <8gjrv0$lhu$1@nnrp1.deja.com>

Folx,

    I am trying to put together an extensive list of common security
  problems in Perl scripts.  More precisely, I'm looking for commonly
  used functions and other constructs that can result in compromised
  security if used improperly.  I'd like to know which of those
  problems can be automatically detected by statically scanning Perl
  source code.  I have compiled a short, pretty vague list of things
  that I'm aware of.  I'd appreciate help in extending and refining
  this list, as well as any ohter comments.

    Common security vulnerabilities in Perl code

    - opening files with user specified filenames
    - failure to escape backslash when filtering CGI metacharacters:
      @insecure_data =~ s/([;<>\*\|`&\$!#\(\)\[\]\{\}:'"])/\\$1/g;
    - forking a shell, as in the following:
    - using backticks with user input:
                  $output = `program $userinput`;
    - opening pipes with user input:
                  open (OUTPUT,"|program $userinput");
    - system() calls with user input:
                  system ("program $userinput");
    - exec() calls with user input:
                  exec ("program $userinput");
    - execing insecure external programs;
    - poison NULL byte  /r.f.p/ - passing \0 in user input to shell or
      other programs.  Solution: $userinput=~s/\0//g;
    - not using Perl taint mode for CGI scripts
    - security problems with eval() and with the /e regex modifier.
      (examples?  solutions?)
    - using rand() for security critical applications.
    - buffer overflows: Perl dynamically extends its data structures
      to prevent BO's.  Is certain code still vulnerable?
    - not using 'use strict' to limit the scope of declared variables
      from being destroyed accidentally by other subroutines in
      the system.
    - setuid scripts.  Perl programs should set the effective UID and
      GID to the real UID and GID of the process before any file
      manipulations:
       $> = $< # set effective user Ids to real id.
       $) = $( # set group id to real id.
    - failure to check enviromental variables (PATH, IFS, etc.).
      Scripts should force the path to a known value so that unknown
      programs cannot be inserted and executed from writable locations
in
      the path
    -

  Dangerous Perl functions:

    FUNCTION: system ()
    PROBLEM: Passing insecure data through the shell
    EXAMPLE: system ('/bin/program $userinput');
    SOLUTION: system ('/bin/program', '$userinput');
    RISKLEVEL:
    PROBLEM: Insecure enviromental variables
    EXAMPLE:  World modifiable directories in PATH
    SOLUTION: $ENV{"PATH"} = '/bin:/usr/biin:/usr/local/bin';
              $ENV{"IFS"} = '';
              system ("/bin/program");
    RISKLEVEL:

    FUNCTION: exec ()
    PROBLEM: Passing insecure data through the shell
    EXAMPLE: exec ('/bin/program $userinput');
    SOLUTION: exec ('/bin/program', '$userinput');
    RISKLEVEL:

    FUNCTION: open ()
    PROBLEM: Passing insecure data through the shell when opening pipes
    EXAMPLE: open (FH, "|/bin/program $userinput");
    SOLUTION: open (FH, '|-') || exec ("/bin/program", $userinput);
    RISKLEVEL:
    PROBLEM: Backward directory traversing
    EXAMPLE: $userinput = "../../../etc/passwd";
             open (FH, "/usr/local/myprog/data.txt");
    SOLUTION: if ($userinput=~/\.\./) {print $bad_input; exit(1);}
    RISKLEVEL:
    PROBLEM: Appending a pipe at end of userinput
    EXAMPLE: $userinput ="/bin/ls /etc|"
             open (FH, $userinput);
    SOLUTION: open (FH, "<$userinput");

    FUNCTION:
    PROBLEM:
    EXAMPLE:
    SOLUTION:
    RISKLEVEL:


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 25 May 2000 14:11:37 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Simple alphabetical name sort
Message-Id: <392D9709.B01756B0@vpservices.com>

tasher1234@my-deja.com wrote:
>
> Here is what my input file looks like:
>
> Location:Adel
> Name:Bill Guske
> Address:100 North 8th
> Phone:515-993-5555
> 
> Location:Adel
> Name:Mike Hammen
>
> [snip]

Others have already given you some very good information that may be
sufficient for your needs.  Another (though not necessarily better)
approach is to  treat this data as what it is -- a database.  Here is a
script that can read data like you've shown, create a database table
from it with fields for last name, first name, location, etc. and then
allow you to order it by any combination of fields you want.  This
treats "first name" as consisting of a first name plus zero or more
optional middle names or initials and last name as the last sequence of
non-whitepsace characters on the Name line.  

The output is the same set of records in the same format as your
original input but sorted by last name.  If you later want to sort by
location or by reverse order of last name, or by location and then last
name within each location, or have Astrid Smith to come before Zebidiah
Smith, or you want to only get people whose last names start with
letters in the first half of the alphabet, or only people with certain
area codes, those can all be done by minor changes in the SQL statement
in line 20 of the script.

---- start of script ----

#!perl -w
use strict;
use DBI;
my $dbh=DBI->connect('DBI:RAM:','','',{RaiseError=>1});
$dbh->func({
    data_type   => 'USR',
    data_source => join('',<DATA>),
    col_names   => 'location,f_name,l_name,address,phone,area_code',
    eol         => '^\s*\n',
    read_sub    => sub {
        my($location,$name,$address,$phone) = split "\n", $_[0];
        $location =~ s/^Location:(.*)/$1/;
        $name     =~ s/^Name:(.*)/$1/;
        $address  =~ s/^Address:(.*)/$1/;
        $phone    =~ s/^Phone:(.*)/$1/;
        my $area_code = $phone;
        $area_code =~ s/^(...).*/$1/;
        my($f_name,$l_name)= $name =~ /^(.+) (\S+)$/;
        return($location,$f_name,$l_name,$address,$phone,$area_code);
                       },
    },'import');
my $sth = $dbh->prepare('SELECT * FROM table1 ORDER BY l_name');
$sth->execute;
while (my($loc,$f_name,$l_name,$addr,$phone,undef)=$sth->fetchrow_array)
{
print <<EOR;
Location:$loc
Name:$f_name $l_name
Address:$addr
Phone:$phone

EOR
}
__END__
Location:Adel
Name:Bill Guske
Address:100 North 8th
Phone:515-993-5555

Location:Adel
Name:Mike Hammen
Address:100 North 8th
Phone:515-993-4551

Location:Adel
Name:Sherry L. Asher
Address:4447 Axel Rd.
Phone:515-288-3333

Location:Adel
Name:Mary B. Able
Address:555 West 1st
Phone:515-222-3333

---- end of script ----

-- 
Jeff


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

Date: Thu, 25 May 2000 19:11:55 GMT
From: jzoetewey@my-deja.com
Subject: Re: Sorting a Database
Message-Id: <8gjttb$n2e$1@nnrp1.deja.com>



> By the way, you can sort a list (usually created from an array), but
you
> cannot sort a hash, so your repeated references to sorting hashes are
> just mystifying, as well as bemusing.  :-)

I can understand why you'd be amused.  I'm pretty clueless about perl at
the moment.

And all the documentation I need is right in front of me.

Unfortunately, there's a certain critical mass of understanding required
before the documentation makes sense.

I'm hoping that if I beat my head against the problem a little bit more,
 things will suddenly become clear.

For what its worth though, I'm not completely clueless with regard to
hashes (though I'm close...).  My reference to sorting hashes
was more an imprecise use of language than confusion about sorting.  I'd
planned to sort information that was in a hash at one point in the
program--though not while it was in a hash.

Jim Zoetewey


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 25 May 2000 14:06:02 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Sorting a Database
Message-Id: <MPG.13973591b0a7e02f98aae0@nntp.hpl.hp.com>

In article <8gjttb$n2e$1@nnrp1.deja.com> on Thu, 25 May 2000 19:11:55 
GMT, jzoetewey@my-deja.com <jzoetewey@my-deja.com> says...
> 
> > By the way, you can sort a list (usually created from an array), but
> you
> > cannot sort a hash, so your repeated references to sorting hashes are
> > just mystifying, as well as bemusing.  :-)
> 
> I can understand why you'd be amused.  I'm pretty clueless about perl at
> the moment.

But 'bemused' ne 'amused', which would be mean.
 
> And all the documentation I need is right in front of me.
> 
> Unfortunately, there's a certain critical mass of understanding required
> before the documentation makes sense.
> 
> I'm hoping that if I beat my head against the problem a little bit more,
>  things will suddenly become clear.

Start with small learning examples.  Create an array of strings, each of 
which you can split into fields, then pick a field to sort the array by.  
Then use two fields, then ...

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


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

Date: Thu, 25 May 2000 13:21:25 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: updated : Re: regexes *sigh* damn I hate these things
Message-Id: <392D8B45.4BCFADDF@stomp.stomp.tokyo>

The WebDragon wrote:
> > (Bart Lateur) wrote:
>  | The WebDragon wrote:

(lots of random snippage)

> is there an easier way to get a count of the $name(s) 
> than this? I can do a scalar(keys %listing) to get a 
> count of the gametypes found, but how do I get a count
> of the $listing{*}{$name} keys ? is there a shortcut 
> or no?


Lots of schizoid shortcuts!

Telling ya Mr. Dragon, good old Perl 4 makes this
so simple and easy! You are coughing up hairballs
instead of spitting fire like I do!

Check out my schizoid code. So much shorter
and easier to understand than what I have
read so far. Notice I didn't say better nor
say other code is wrong, just shorter, easier
to understand and schizoid!

This code uses what you have posted so far
for input data. It cleans up the input first.
Next it sets an array for both counting games
and for a final print. This array, in this
example only has two elements based on the
input we have so far. Those elements are
delimited by my favorite snooker character.

My code pulls a variety of information as you
see in the final print out. Is there other 
information you wanted pulled? 

This is fun!

Godzilla!




PRINT RESULTS
_____________

  There are 2 distinct games included within
  these input data. Those 2 games are: 

     Name:  DM-Cyberwar  Author:  deadman  Rating: (1-10) 7.5 
     Name:  DM-Nitro  Author: Eric 'Ebolt' Boltjes  Rating: (1-10) 9 



   Tilt! Game Over!



TEST SCRIPT
___________

#!/usr/local/bin/perl

print "Content-Type: text/plain\n\n";


## Pretend Input!

$pretend_input = "Name:  <a href=\"http://www.planetunreal.com/dl/
 nc.asp? nalicity/utdm/dm-cyberwar.zip\">DM-Cyberwar</a><br>\n\n
 Author:  <a href=\"mailto:666deadman666\@email.msn.com\">deadman
 </a><br>\n\n Rating: (1-10) 7.5 <p></p>\n
 <p>Name:  <a href=\"http://www.planetunreal.com/dl/
 nc.asp?nalicity/\n utdm/dm-nitro.zip\">DM-Nitro</a><br>\n Author:
 <a href=\"mailto:ebolt\@planetunreal.com\">Eric \'Ebolt\' Boltjes</a>
 <br>\n Rating: (1-10) 9</p><!-- add correct image name below here
 -->\n";


## Take Out The Garbage!

$pretend_input =~ s/<([^>]+)>//g;
$pretend_input =~ s/\n\n|\n/¦/g;
$pretend_input =~ s/¦ ¦|¦¦/¦/g;
$pretend_input =~ s/:¦/:/g;
$pretend_input =~ s/¦ N/¡ N/g;

chop ($pretend_input);


## Count Games And Prepare Array For Print!

@Count_Games = split (/ ¡ /, $pretend_input);

$count = ($#Count_Games + 1);

print "
  There are $count distinct games included within
  these input data. Those $count games are: \n\n";


## Find And Print Details For Games!

foreach $element (@Count_Games)
 {
  local ($name, $author, $rating) = split (/¦/, $element);
  print "     $name $author $rating \n";
 }


## Godzilla Says!

print "\n\n\n   Tilt! Game Over!";

exit;


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

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

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 3166
**************************************


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