[16933] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4345 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Sep 17 03:06:02 2000

Date: Sun, 17 Sep 2000 00: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: <969174312-v9-i4345@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 17 Sep 2000     Volume: 9 Number: 4345

Today's topics:
        An identd faking ident. (Abigail)
        ANNOUNCE: Term::Sample v0.25 <jdb@wcoil.com>
        Controlling another program zolakk@geocities.com
    Re: Controlling another program <philipg@atl.mediaone.net>
    Re: Determining the length of a string (David H. Adler)
    Re: help with HTML::Parser please (brian d foy)
    Re: Help with scope and module <mjcarman@home.com>
    Re: Help with scope and module (Garry Williams)
        How to realize the cookies with perl script. i0519@my-deja.com
        How to write this?(#define) i0519@my-deja.com
    Re: How to write this?(#define) <philipg@atl.mediaone.net>
    Re: How to write this?(#define) (Mark-Jason Dominus)
    Re: How to write this?(#define) (Craig Berry)
        Is this terribly inefficient? <steph@hotkey.net.au>
    Re: Module for CGI Session Management? billmez@my-deja.com
        perl and mysql pohanl@my-deja.com
    Re: perl and mysql (brian d foy)
    Re: Pipe to string (Eric Bohlman)
        please help a newbie in a simple question <qiwu@students.uiuc.edu>
    Re: print and CGI scripts <admin@salvador.venice.ca.us>
    Re: Qualifications for new Perl programmer????? (brian d foy)
    Re: Recipe For Sorting LoL (Martien Verbruggen)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 17 Sep 2000 05:30:09 GMT
From: abigail@foad.org (Abigail)
Subject: An identd faking ident.
Message-Id: <slrn8s8lks.h8o.abigail@alexandra.foad.org>


[Tom, if you read this: I'd submit it for PPT, but you're bouncing my mail]


#!/opt/perl/bin/perl -wT

# A simple identd program, that has no intention of revealing any system
# information.
# The program expects to be run from inetd, and hence, only reads from
# STDIN. It will ignore all arguments given, nor will it pay attention
# to any of the environment variables.
# Appropriate errors are generated when the request is syntactically
# not valid, or when the given ports are out of bounds.
# For valid requests, regardless whether the ports are in use or not,
# a random OS and a random user name are picked from a fixed set of
# names. These random values are, appropriately formatted, returned.
#
# $Id: identd,v 1.2 2000/09/17 05:17:59 abigail Exp abigail $
#
# $Log: identd,v $
# Revision 1.2  2000/09/17 05:17:59  abigail
# Typo fixes in POD.
#
# Revision 1.1  2000/09/17 05:11:11  abigail
# Initial revision
#

use constant TIMEOUT    =>    30;   # How long we wait for input, in seconds.
use constant MAX_INPUT  =>   512;   # How much we read at most, in bytes.
use constant MAX_PORT   => 65535;   # Highest port number in valid request.
my @OSses = map {s/^\s+//; $_} split /\s*\n/ => <<EOT;    # Pick one.
    ACME OS
    APOLLO 13
    AQUARIUM LIFE
    BABYLON V
    BOOMBOX
    BUTTERKNIFE
    CANOPENER 2000
    COFFEE-MAKER
    CRASH-DUMMY
    DEAD/WINDOWS
    DEC CARDREADER
    ENIAC
    ENIGMA
    ESCALATOR-B
    HAIRDRYER-OS
    IBM TYPEWRITER
    ICECREAM MAKER
    IRON-BSD
    NINTENDO63
    ORIGAMI 98
    QUANTUM OS
    ROSETTA STONE
    SEGA/TURBO
    TOASTER/OS
    TURINGMACHINE
    TURKISH BATH
    UNIVAC
    VCR/MVS
EOT
my @names = map {s/^\s+//; $_} split /\s*\n/ => <<EOT;   # Pick one.
    abbeyroad
    beatles
    flower-in-hair
    flowerpower
    freelove
    hairpower
    hippie
    imagine
    karma
    lennon
    lovebug
    makelove
    moonchild
    mushroom
    peace
    potsmoker
    sixties
    strawberry-field
    woodstock
    yellowsub
EOT

##
## End of configuration
##


BEGIN {die "Don't run $0 as super user!\n" unless $< && $>}

my ($VERSION) = '$Revision: 1.2 $' =~ /([.\d]+)/;

my $CRLF  = "\015\012";             # Net line ending.


sub error {
    my ($error, $ports) = @_;
    $ports = [0, 0] unless $ports && @$ports == 2;
    local $" = ",";
    print "@$ports:ERROR:$error$CRLF";
}


# Set time out.
$SIG {ALRM} = sub {error "X-TIME-OUT"; exit};
alarm TIMEOUT;


# Read request.
my $request;
sysread STDIN, $request, MAX_INPUT or die "Failed to read any input\n";


# Parse request.
my  @ports  = $request =~ /^\s*(\d+)\s*,\s*(\d+)/;
if (@ports != 2) {
    error "X-INVALID-REQUEST";
    exit;
}


# Check bounds.
foreach my $port (@ports) {
    if ($port == 0 || $port > MAX_PORT) {
        error "INVALID-PORT" => \@ports;
        exit;
    }
}


# Generate an OS and a name.
my $OS   = $OSses [rand @OSses];
my $name = $names [rand @names];

# Print result of query.
local $" = ",";
print "@ports:USERID:$OS:$name$CRLF";

__END__

=pod

=head1 NAME

identd  --  Fake authentication daemon.

=head1 SYNOPSIS

identd

=head1 DESCRIPTION

Once upon a time, the Internet was a safe and respected place. Computer
time on hosts connected to the Internet was an expensive commodity,
and such hosts were shephered by trustworthy monks. And God said, Let
there be a simple protocol to check to see if you are who you claim
to be: and there was I<ident>. And God saw I<ident>, that it was good:
and God divided the unknown from the known.

But in the age of the Eternal September, the Internet is a crowded,
smelly, and dangerous place. Behold the Nazguls, dark angels and hordes
of script kiddies that roam the lands, destroying what was once a
promising future. Monks still rule their own lands, but have to spend
much of their time defending their monasteries against the shadow forces.

And were once I<ident> served a purpose, it can and will now be used
against you. Evil will knock on the door and misuse your answers. Sending
I<ident> to greener pastures is an option, but some white services still
require an answer to their inquiries, before they help you.

Hence this fake I<identd>. It will satisfy that need to be satisfied,
yet it won't give the black forces a foothold.

=head1 USAGE

I<ident> should typically be called by I<inetd>. An example entry of
L<inetd.conf(5)> would be:

    ident stream tcp nowait nobody /usr/sbin/identd identd

I<identd> does not take any argument.

=head1 CONFIGURATION

The configuration is all done in the source, and it's all on the
top of the file. C<TIME_OUT> specifies the time we wait for input; if
nothing was received by then, we issue an appropriate message and exit.
C<MAX_INPUT> specifies the maximum amount of data we read from the client,
while C<MAX_PORT> defines the maximum port of our system. It is probably
best to leave these values alone.

C<@OSses> and C<@names> take a list of OS names and user names; one
on each line, with leading and trailing whitespace being ignored. For
a valid query, I<identd> randomly picks an OS and a name, and returns
them as query result.

=head1 HISTORY

    $Log: identd,v $
    Revision 1.2  2000/09/17 05:17:59  abigail
    Typo fixes in POD.

    Revision 1.1  2000/09/17 05:11:11  abigail
    Initial revision


=head1 AUTHOR

This Perl implementation of I<identd> was written by Abigail,
I<abigail@foad.org>.

=head1 COPYRIGHT and LICENSE

This program is copyright 2000 by Abigail.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

=cut
-- 
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
#    A goldfish darts in
#    a river. Two doves fly towards
#    the east. A fly.


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

Date: 17 Sep 2000 03:23:30 GMT
From: "Josiah Bryan" <jdb@wcoil.com>
Subject: ANNOUNCE: Term::Sample v0.25
Message-Id: <8q1dfi$4kp$0@206.230.71.47>

Greetings Perlfolk,

Announcing the release of:
    Term::Sample 0.25

Recomended Download URL:
    http://www.josiah.countystart.com/modules/get.pl?term-sample:misc

It has also has entered CPAN as

   file: $CPAN/authors/id/J/JB/JBRYAN/Term-Sample-0.25.zip
  size: 25710 bytes
 md5: 4022b45eb91e4c8a0cd468f6f987aef1

** What is this?

Term::Sample (version 0.25) - Finger printing of your keyboard typing

** Huh?

Term::Sample implements simple typing analysis to find the "personality"
in your typing. It uses Time::HiRes and Win32::Console for best results.
If it is not run on a Win32 system, it defaults to Term::ReadKey instead
of Win32::Console. I'm not sure how well it works with ReadKey, as I have
not had a chance to test it out yet.

In this module we deal with three basic items: samples, analysis', and
sets. Samples are what you get from the sample() function and are raw
keyboard data. Samples can be averaged together to produce master
samples, or analyzed to produce unique sample analysis'. Analysis' are
produced by alanlyze()-ing samples from sample() or samples averaged
together(). You can store samples (averaged or analyzed) and analysis'
in sets according to unique, user-defined keys. You can then match new
samples against the samples in the set and find out which key it matched
in the set, as well as the percentage of error.

This module uses Time::HiRes to time both the key-press time (time
between the key-down signal and the key-up signal) and the key-interveal
(time between key-up of previous key and key-down of next key). This
creates what I call a keyboard sample, or just a "sample." This is created
by a custom prompt function, sample() which returns an array ref. This is
the raw keyboard sample data. It can be averaged together with multiple
sample to create a master sample to be used as a signiture, or it can be
individually saved with save().

You can create a unique 'print', or analysis from a sample, or samples
averaged together with analyze(). analyze() uses several factors to
make the unique analysis. First, it calculates average ASCII key codes,
as well as the average total key-press and inter-key times. Then it loops
through the sample and picks out the fastest key-press times and inter-key
times, and taking a three-key average around that high-point to create a
sample highlight. It creats highlights from every key in the sample,
fastest to slowest, and then sorts the hightlights by key-press times
and inter-key times, storing both lists in a final "analysis" object, along
with the averaged times created at the start. This gives a final,
hopefully unique, sample analysis.

Four examples and the synopsis is included. Enjoy, and PLEASE let me
know how it works for all of you that use it. Thankyou!

As always, included is a cleaned, CSS-ed, HTML-format of the POD docs.

Regards,

--
Josiah Bryan
jdb@wcoil.com
Tel: 937.316.6256





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

Date: Sun, 17 Sep 2000 05:16:05 GMT
From: zolakk@geocities.com
Subject: Controlling another program
Message-Id: <hak8ss42jh2i2285h5j9lerh0rk2d5tqdq@4ax.com>

As a part of learning how to program in Perl, I have decided to write
a front end program for the program mpg123 (someday I will have an MP3
box on my stereo system). I got nearly everything working just fine,
with a bit of research. My only question is how would I go about
passing commands to it (for pause, stop, etc) I can play files just
fine, but have to wait for the program to finish, (and end) before
continuing with anything else. I am guessing that I would need to use
fork() or something simillar (anyone have a good explanation of that
anyway? everything I read on that seemed a bit confusing) or maybe
even pipe()? From what I understand, with a fork, the parent program
(mine, I assume) recieves signals from the child (mpg123 in my case),
so what I need to do is just the opposite? or, does anyone know of a
console mp3 player that would lend itself to this kind of thing
easier?

Thanks


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

Date: Sun, 17 Sep 2000 06:17:38 GMT
From: "Philip Garrett" <philipg@atl.mediaone.net>
Subject: Re: Controlling another program
Message-Id: <6mZw5.12014$g35.1530851@typhoon.southeast.rr.com>

<zolakk@geocities.com> wrote in message
news:hak8ss42jh2i2285h5j9lerh0rk2d5tqdq@4ax.com...
> As a part of learning how to program in Perl, I have decided to write
> a front end program for the program mpg123 (someday I will have an MP3
> box on my stereo system). I got nearly everything working just fine,
> with a bit of research. My only question is how would I go about
> passing commands to it (for pause, stop, etc) I can play files just
> fine, but have to wait for the program to finish, (and end) before
> continuing with anything else. I am guessing that I would need to use
> fork() or something simillar (anyone have a good explanation of that
> anyway? everything I read on that seemed a bit confusing) or maybe
> even pipe()? From what I understand, with a fork, the parent program
> (mine, I assume) recieves signals from the child (mpg123 in my case),
> so what I need to do is just the opposite? or, does anyone know of a
> console mp3 player that would lend itself to this kind of thing
> easier?

I know absolutely nothing about mpg123, but it it's normally driven by
keystroke commands from a terminal, you can use the Expect module.  Look it
up on CPAN.  Last time I tried it, it wasn't as fully-implemented as the
Expect extension to Tcl, but it can probably do the job.

hth,
p




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

Date: 17 Sep 2000 06:03:21 GMT
From: dha@panix.com (David H. Adler)
Subject: Re: Determining the length of a string
Message-Id: <slrn8s8nl9.gol.dha@panix6.panix.com>

On Thu, 14 Sep 2000 03:53:29 GMT, Ala Qumsieh <aqumsieh@hyperchip.com>
wrote:

>Jeff Pinyan <jeffp@crusoe.net> writes:

>> Obfuscation alert.
>> 
>>   y ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc;
>
>Good one :-)
>But I can beat you at golf:
>
>	y cccc;

Golf, feh.

        /(.)\z/s;
	$length = rindex($_, $1)+1;

dha, who really hates this question... :-/

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"Take myself, subtract films, and the remainder is zero"
 - Akira Kurosawa


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

Date: Sat, 16 Sep 2000 22:05:44 -0400
From: brian@smithrenaud.com (brian d foy)
Subject: Re: help with HTML::Parser please
Message-Id: <brian-ya02408000R1609002205440001@news.panix.com>

In article <Pine.GHP.4.21.0009162341290.11602-100000@hpplus03.cern.ch>, "Alan J. Flavell" <flavell@mail.cern.ch> posted:

> On Sat, 16 Sep 2000 ptomsic@my-deja.com wrote:

> > The tags are consistent in the wording "Start content here" and "end
> > content here" but there is no consistency to the number of hyphens or
> > spaces, so it could be

> > <!----      START content here     ----------->
> 
> I hope you're aware that such a syntax would violate both the official
> SGML rules and the simplified HTML rules for comment syntax?

it sounds to me like the poster has to deal with stuff that he
did not produce.  he would surely simply the problem (and his
life) if he could affect the content generation.

of course, it's good to be liberal in what we accept, and strict
in what we return. ;)

-- 
brian d foy                    
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Mongers <URL:http://www.perl.org/>


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

Date: Wed, 13 Sep 2000 10:45:44 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Help with scope and module
Message-Id: <39BFA128.142276E1@home.com>

Phil Barone wrote:
> 
>   I have a main program and a module that contains some library
> subroutines.
> 
> What I would like to know if/how I can create a global variable in the
> main program accessable to the subroutines in my library?

Declare it as global in the main file:

use vars ($foo @bar %baz);

Access it from your modules via a fully-qualified name:

if ($main::foo) {
    #...
}
 
> How/If it is possible for a subroutine in my library can access a
> subroutine in my main program?

Again, a fully qualified name:

main::Do_It();

My personal preferences lean away from doing this sort of thing, so I
tend to pass any needed parameters into the subs I have in modules. It
isn't really wrong to do it this way -- I just find $main::foo to be a
little ugly. Similarly, when I need access to subroutines from my main
script, I create an auxillary module which contains aliases. e.g.

package mainsubs;

use vars qw(@ISA @EXPORT);
require Exporter;

@ISA    = qw(Exporter);
@EXPORT = qw(Do_It Do_Something_Else);

*Do_It = \&main::Do_It;
*Do_Something_Else = \&main::Do_Something_Else;

And then put a 'use mainsubs' in each module which needs access to those
functions.

-mjc


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

Date: Sun, 17 Sep 2000 06:30:31 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Help with scope and module
Message-Id: <byZw5.278$fa2.23490@eagle.america.net>

On Wed, 13 Sep 2000 10:45:44 -0500, Michael Carman <mjcarman@home.com> wrote:
>Phil Barone wrote:
>> 
>>   I have a main program and a module that contains some library
>> subroutines.
>> 
>> What I would like to know if/how I can create a global variable in the
>> main program accessable to the subroutines in my library?
>
>Declare it as global in the main file:
>
>use vars ($foo @bar %baz);

Did you try this?  

-- 
Garry Williams


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

Date: Sun, 17 Sep 2000 06:36:28 GMT
From: i0519@my-deja.com
Subject: How to realize the cookies with perl script.
Message-Id: <8q1opc$m6h$1@nnrp1.deja.com>

I am program a CGI with perl in solaris.
And we want to realize the cookie mechanism in the program.
Is their any function /example about this?


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


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

Date: Sun, 17 Sep 2000 05:44:33 GMT
From: i0519@my-deja.com
Subject: How to write this?(#define)
Message-Id: <8q1lnv$j1g$1@nnrp1.deja.com>

in c:
we write
#define TRUE 1
#define FALSE 0

then how to write this in perl?


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


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

Date: Sun, 17 Sep 2000 06:12:12 GMT
From: "Philip Garrett" <philipg@atl.mediaone.net>
Subject: Re: How to write this?(#define)
Message-Id: <0hZw5.12001$g35.1528986@typhoon.southeast.rr.com>

<i0519@my-deja.com> wrote in message news:8q1lnv$j1g$1@nnrp1.deja.com...
> in c:
> we write
> #define TRUE 1
> #define FALSE 0
>
> then how to write this in perl?

You probably shouldn't.  It's useless and ugly, IMNSHO.
Check out the Perl style guide:
http://www.cpan.org/doc/FMTEYEWTK/style/slide-index.html

But, if you feel that you absolutely must, you can do:

use constant TRUE => 1;
use constant FALSE => 0;

hth,
p




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

Date: Sun, 17 Sep 2000 03:44:18 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: How to write this?(#define)
Message-Id: <39c460c5.4b7c$318@news.op.net>


In article <8q1lnv$j1g$1@nnrp1.deja.com>,  <i0519@my-deja.com> wrote:
>#define TRUE 1
>#define FALSE 0
>
>then how to write this in perl?

use constant TRUE => 1;
use constant FALSE => 0;





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

Date: Sun, 17 Sep 2000 06:22:55 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: How to write this?(#define)
Message-Id: <ss8opvbgh3t45@corp.supernews.com>

i0519@my-deja.com wrote:
: in c we write
: #define TRUE 1
: #define FALSE 0
: 
: then how to write this in perl?

In theory, you can use the -P option (see perlrun) to get true
preprocessor-macro behavior.  But don't do that.

To get the semantics of constant values, the 'constant' module works
nicely.  'perldoc constant' for details.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Every force evolves a form."
   |              - Shriekback


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

Date: Sun, 17 Sep 2000 11:09:53 +1000
From: "Stephan Carydakis" <steph@hotkey.net.au>
Subject: Is this terribly inefficient?
Message-Id: <39c46383@news.iprimus.com.au>

Hello All,

I have written a sort subroutine which I think maybe a little inefficient.
Why do I think it's inefficient? Well, $a/$b are entire records from a flat
file db(1 line per record) and I use re's to extract the dates from the
record which I then split up into day/month/year using re's again. Is this
inefficient? Could someone suggest a better way?

My code:

sub byDate {

    my ($dateA, $dateB, $yearA, $yearB, $monthA, $monthB, $dayA, $dayB);

    $a =~ m/.*?\|.*?\|.*?\|(.*?)\|.*/;
    $dateA=$1;

    $b =~ m/.*?\|.*?\|.*?\|(.*?)\|.*/;
    $dateB=$1;

    $dateA =~ m|(.*?)/(.*?)/(.*)|;
    ($dayA,$monthA,$yearA)=($1,$2,$3);

    $dateB =~ m|(.*?)/(.*?)/(.*)|;
    ($dayB,$monthB,$yearB)=($1,$2,$3);

    $yearB <=> $yearA
                ||
    $monthB <=> $monthA
                ||
    $dayB <=> $dayA;

}




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

Date: Sun, 17 Sep 2000 03:24:37 GMT
From: billmez@my-deja.com
Subject: Re: Module for CGI Session Management?
Message-Id: <8q1dh7$ad8$1@nnrp1.deja.com>

Hello Matt,

Although this is somewhat of a platform specific solution, it does
offer an easy and workable solution.

On the WinNT platform (and others with additional software) PERL runs
beautifully in active server pages, which of course would give you
access to the session object.

I have changed a large portion of my development work from CGI to ASP
using PERL (the modules are also compatible).

Feel free to drop me a note if you have any questions about ASP and
PERL.

Bill

In article <mMiw5.43285$Qx4.1470559@news1.rdc1.il.home.com>,
  "Matt Kruse" <mkruse@netexpress.net> wrote:
> Is there a perl module available whose purpose is just to maintain a
> "session" in CGI programming?
>
> I haven't found one, and there doesn't seem to be a definitive answer
in
> past newsgroup postings.
>
> What I'd be looking for is a completely portable solution - that is,
not
> reliant on web server or OS.
> In a couple of minutes, I wrote down these thoughts:
>
>   - Sessions stored as files in a configurable directory
>   - Session ID's generated randomly (best way to do this?)
>   - Files hold name/value pairs of session data
>   - Check session file dates to see if session has expired (last
modified
> date).
>   - When a session expires, do full cleanup of old expired sessions
(won't
> scale well, depends on app)
>
> So, I could see it working like this:
>
> $Session = new CGI::Session($id);  # Reads in existing session or
creates
> new
> unless ($Session->isExpired()) {
>     $Session->setValue("requests",$Session->getValue("requests")++);
>     }
> if ($Session->getValue("requests") > 50) {
>     $Session->End();
>     }
> else {
>     $Session->Save();
>     }
>
> Makes logical sense to me. This wouldn't be too difficult, really.
Just
> takes time. If anyone has already written it, please let me know.
Also, I
> know that CGI.pm does some sort of session management, but it doesn't
really
> do what I would like, or in a way I would like to do it.
>
> Thanks!
>
> Matt Kruse
> mkruse@netexpress.net
> http://www.mattkruse.com/
>
>


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


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

Date: Sun, 17 Sep 2000 02:52:58 GMT
From: pohanl@my-deja.com
Subject: perl and mysql
Message-Id: <8q1bm5$8h7$1@nnrp1.deja.com>



In a tied hash to a database, you can check for the existence of
a key by the following...

if (defined $database{$key}) { bla bla bla }

If you have a mysql database instead, how do you check for the
existence of a field value in a table?  example,
if i have a table with one field called "name", how do
I check if there is a value of "name" called "john"?

(given a $dbh->do or $dbh->prepare/execute statement).



Also, how do you check if a table actually exists in the database
schema?  for example, if you do a "show tables" it shows you all
the tables.  but I would like a statement where I basically check
for the validity of one table.  like  "does table customers exists?"
and pass this sql statement to the database.

lastly, given a execute, and you followup with a fetch, how
do you convert the results into an array?  like..
select phone from customer table where customertype is adult.
(only one phone returned per row, but there could be multiple customers
that are adult).

quite new with mysql, so i need all the help i can get.


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


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

Date: Sun, 17 Sep 2000 01:13:38 -0400
From: brian@smithrenaud.com (brian d foy)
Subject: Re: perl and mysql
Message-Id: <brian-ya02408000R1709000113380001@news.panix.com>

In article <8q1bm5$8h7$1@nnrp1.deja.com>, pohanl@my-deja.com posted:

> In a tied hash to a database, you can check for the existence of
> a key by the following...
> 
> if (defined $database{$key}) { bla bla bla }
> 
> If you have a mysql database instead, how do you check for the
> existence of a field value in a table? 

see the DBI module.

-- 
brian d foy                    
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Mongers <URL:http://www.perl.org/>


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

Date: 17 Sep 2000 04:06:53 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Pipe to string
Message-Id: <8q1g0t$4t9$4@nntp9.atl.mindspring.net>

Heiko Gottschling (gottschl@in.tum.de) wrote:
: is there an easy way to establish a pipe to a string, like StringWriter
: in Java?
: 
: What I want is something like this:
: 
: open STRING, "| ?? don't know?";
: print STRING "This will be the content of the string";
: $content = <STRING>;
: close STRING;
: 
: (Please don't take this code fragment too literally. What I want is a
: filehandle to which I can "print" like usual, but the output is not to
: go to a file but to a string)

You want IO::Scalar, which is part of the IO::Stringy bundle.  It uses 
Perl's tie mechanism to let you create filehandles that read or write to 
strings or arrays.



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

Date: Sun, 17 Sep 2000 00:10:22 -0500
From: qi wu <qiwu@students.uiuc.edu>
Subject: please help a newbie in a simple question
Message-Id: <Pine.GSO.4.10.10009170002090.8364-100000@ux5.cso.uiuc.edu>

Hi gurus! I have a simple question that needs to be answered. Where can I
find a PERL module that enables me to set username and password to control
access to a certain webpage of a website. I checked some relevant sites
and found out that the only available modules are for UNIX system.
However, the website uses ZBserver pro(software that allows you to publish
your website right from your computer) as the server. I don't understand
whether there are any differences. If so, what should I do to impose
access control on the particular webpage? Thanks in advance!



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

Date: Sat, 16 Sep 2000 18:30:47 -0700
From: Pan <admin@salvador.venice.ca.us>
Subject: Re: print and CGI scripts
Message-Id: <39C41EC7.FBEB6E24@salvador.venice.ca.us>

Unless you show the relevent portions of your code, you are simply
wasting your time and that of anyone who is interested in trying to help
you at this point.  In fact, you should've posted it much sooner than
this.  You probably would've had your solution on wednesday, if you had
posted it.

Dave O'Brien wrote:
> 
> Uri Guttman wrote:
> >
> > >>>>> "DO" == Dave O'Brien <david.obrien@ssmb.com.au> writes:
> >
> >   DO> Gwyn Judd wrote:
> >   >>
> >   >> open SOME_FILE, "a_file.txt" or die "Couldn't open the file: $!";
> >                       ^^^^^^^^^^
> >
> > missing > for output files.
> >
> >   DO> That is the exact code I'm using, and it still outputs to the browser,
> >   DO> as well as the file.  It means when I'm processing 20 files, all those
> >   DO> files are output to the browser!  Very annoying.
> >
> > if that is true you have the same bug. getting output from a cgi script
> > and not sending it to a browser is easy. one debug trick is to create a
> > fifo and open it for output in the cgi. run tail -f on it from another
> > window. then you can see what you want in the cgi in realtime.
> >
> > uri
> >
> 
> Thanks Uri,
> 
> I am opening the file correctly, and the new file is being created, but
> as it is being created, each line is printed to the browser and file at
> the same time.  Could you explain the tail -f solution you suggested?
> 
> Thanks
> 
> Dave

-- 
Pan
admin@salvador.venice.ca.us
http://www.la-online.com


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

Date: Sat, 16 Sep 2000 22:17:57 -0400
From: brian@smithrenaud.com (brian d foy)
Subject: Re: Qualifications for new Perl programmer?????
Message-Id: <brian-ya02408000R1609002217570001@news.panix.com>

In article <8q0tsk$q2k$1@nnrp1.deja.com>, Brendon Caligari <bcaligari@my-deja.com> posted:

> In article <slrn8s7c9a.6uu.dha@panix6.panix.com>,
>   dha@panix.com (David H. Adler) wrote:

> > On Fri, 15 Sep 2000 13:36:26 GMT, Brendon Caligari
> > <bcaligari@my-deja.com> wrote:

> > Of course, all this assumes that the student in question isn't
> > impervious to learning in the first place...

> I believe that there is a consensus that while Perl is good,
> perl alone is not sufficient for a comprehensive education in
> programming. 

you assume that everyone wants to be a programmer.  some people
just want to do their job.  

> It would be pretentious of oneself to call
> himself or practice as a programmer if his exposure has been
> limited to one language.  

i don't agree. 

i think it's pretentious for you to set criteria or to assume
that you are the arbiter of titles.

> At the end of the day, a programming
> language is a tool with which to carry out solutions derived
> from certain theories and practices.

You seem to think that there is some sort of special handshake 
and membership card.  perhaps Perl's configure script should 
include a test that must be passed before it will generate the
Makefile.

remember that Perl "baby talk" is officially okay. Perl is easy
to use so that mere mortals can use it. it's a feature. at the end
of the day, most people care about having finished the task rather
than fulfilling some computer science idealist agenda.

Perl gets the job done.

-- 
brian d foy                    
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Mongers <URL:http://www.perl.org/>


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

Date: Sun, 17 Sep 2000 11:58:30 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Recipe For Sorting LoL
Message-Id: <slrn8s85pm.ntr.mgjv@martien.heliotrope.home>

On Sat, 16 Sep 2000 23:44:54 GMT,
	andre_sanchez@my-deja.com <andre_sanchez@my-deja.com> wrote:
> I am looking for a recipe for sorting a LoL. Thanks in advance for
> pointing me in the right direction.

Have you read the perl FAQ?

# perldoc -q sort
Found in /opt/perl/lib/5.6.0/pod/perlfaq4.pod
       How do I sort an array by (anything)?
[snip]
       How do I sort a hash (optionally by value instead of key)?
[snip]

Also, this question come sup so often on this newsgroup that you would
be well advised to search it. Use soemthing like www.deja.com, and
search for GRT and/or Schwartzian Transform. If you learn to do these
sorts of things, you won't have to come here to ask anymore. Both
techniques mentioned here may simply be overkill, even.

And you do know about the builtin sort, right? I'm just asking because
you don't mention it at all.

# perldoc -f sort

> I have a List of Lists (LoL) populated with words. I would like to

Array of array references. I really dislike that LoL misnomer.

> sort it alphabetically. Simplistic example (the actual LoL is
> populated by variable length lists):

This statement confuses me. You present data that has subarrays that
contain only two elements, the first one clearly being a (non-unique)
key, and the second a value. How can you make those lists longer? Why
don't you just use example data that looks more like the stuff you use
in your real application? It won't scare us off, I promise.

> 
> @LoL = ( ['Fruit', 'Banana'],
> 	 ['Vegetable', 'Lettuce'],
>          ['Fruit', 'Apple'],
> 	 ['Vegetable', 'Celery']);
> 
> @sorted_LoL = recipe(@LoL);
> 
> for $aref ( @LoL ) {
>     print "@$aref\n";
> }
> 
> for $aref ( @sorted_LoL ) {
>     print "@$aref\n";
> }
> 
> sub recipe{
> # Magical Routine Returns Sorted LoL

What sort of magic are we looking for? What have you tried? And why
don't you work with a sort sub that you can pass off to the builtin
sort?

> }
> 
> Would return:
> 
> Fruit Banana
> Vegetable Lettuce
> Fruit Apple
> Vegetable Celery
> 
> Fruit Apple
> Fruit Banana
> Vegetable Celery
> Vegetable Lettuce

This is not entirely clear and entirely ambiguous. Do you want to sort
by the first element of the subarrays first (Fruit, Vegetable), or just
the second one? Both strategies would give you above solution. Or is
there yet another sort strategy that would give this result, and that
you are thinking of[1]?  You really should try to say in words what you
want. Besides that, you aren't making it entirely clear what your data
will look like: 'the actual LoL is populated by variable length lists'.
What is in those lists? What are we sorting on?

my @sortedLoL = sort sortsub @LoL;

Sort only by first key of subarrays

sub sortsub { $a->[0] cmp $b->[0] }

Sort by second only

sub sortsub { $a->[1] cmp $b->[1] }

Sort by first key first, then by second:

sub sortsub { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] }

Sort ascending on the first key, and descending on the second:

sub sortsub { $a->[0] cmp $b->[0] || $b->[1] cmp $a->[1] }


I'll leave it up to you to work it out from here, or if you can't to
specify the problem a little more clearly, maybe using an example of
what your real data is, with a clear description what you want to sort
and how.

Martien

[1] An obscure one would be: sort ascending on the first element, and
descending on the reverse of the second. This is farfetched, but meant
to illustrate that there is a virtually inexhaustible supply of these
things based on just an example. SPECIFY what you want. Don't just give
a very limited example, which by your saying, doesn't even portray your
real data.
-- 
Martien Verbruggen              | 
Interactive Media Division      | The gene pool could use a little
Commercial Dynamics Pty. Ltd.   | chlorine.
NSW, Australia                  | 


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

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


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