[12639] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 48 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 7 08:17:26 1999

Date: Wed, 7 Jul 1999 05:07:26 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 7 Jul 1999     Volume: 9 Number: 48

Today's topics:
        Sort Hash of Hash <peter.doyle@ireland.sun.com>
        Sort Hash of Hash <peter.doyle@ireland.sun.com>
    Re: Sort Hash of Hash (Michel Dalle)
        sort of stuck <wavey@pilot.infi.net>
    Re: sort of stuck (Michel Dalle)
    Re: sort of stuck (Mark-Jason Dominus)
    Re: sort of stuck (Mark-Jason Dominus)
        sorting hashes with some identical fields <ianmorty@nortelnetworks.com>
        sprintf, pack and unpack question! esalmon@packet.net
    Re: sprintf, pack and unpack question! <elaine@wustl.edu>
    Re: sprintf, pack and unpack question! (Philip 'Yes, that's my address' Newton)
    Re: SQL statement in Perl <walton@frontiernet.net>
        SSI Question... <soneill@marsworks.com>
    Re: SSI Question... <swiftkid@bigfoot.com>
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: Mon, 05 Jul 1999 09:49:45 +0100
From: Peter Doyle <peter.doyle@ireland.sun.com>
Subject: Sort Hash of Hash
Message-Id: <378071A9.A336C522@ireland.sun.com>


--------------B74DD595C1EDDC3D18858B3C
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi,
 I have a hash of hash data structure which I want to sort for printing. I need to
cascade the sorting some how, or sort it for one field in the record, then fill
temporary hashes with equal values to sort on the next field and so on.


This sorts fine but not recusively so it doesn't do what I want. It takes a
reference to a HoH & an array of fields to sort by.

sub sort_aDB
{
        my ($DB_ref, $order_ref) = @_;
        my @sorted = ();
        my %tmp = ();
        my @inherit_order = keys %{$DB_ref};
        for $f (0 .. $#{$order_ref})
        {
                my $field = pop @{$order_ref};
                print "<BR>Sorting by ", $field;
                @sorted = sort { ${$DB_ref}{$a}{$field} cmp ${$DB_ref}{$b}{$field}
} @inherit_order;
                #@sorted = sort sort_sub @inherit_order;
                @inherit_order = @sorted;
        }
        return @sorted;
}

Thanks if you can help,
Peter


--------------B74DD595C1EDDC3D18858B3C
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Hi,
<br>&nbsp;I have a hash of hash data structure which I want to sort for
printing. I need to cascade the sorting some how, or sort it for one field
in the record, then fill temporary hashes with equal values to sort on
the next field and so on.
<br>&nbsp;
<p>This sorts fine but not recusively so it doesn't do what I want. It
takes a reference to a HoH &amp; an array of fields to sort by.
<p><tt>sub sort_aDB</tt>
<br><tt>{</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my ($DB_ref, $order_ref)
= @_;</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my @sorted = ();</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my %tmp = ();</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my @inherit_order =
keys %{$DB_ref};</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for $f (0 .. $#{$order_ref})</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
my $field = pop @{$order_ref};</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
print "&lt;BR>Sorting by ", $field;</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
@sorted = sort { ${$DB_ref}{$a}{$field} cmp ${$DB_ref}{$b}{$field} } @inherit_order;</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
#@sorted = sort sort_sub @inherit_order;</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
@inherit_order = @sorted;</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return @sorted;</tt>
<br><tt>}</tt>
<p>Thanks if you can help,
<br>Peter
<br>&nbsp;</html>

--------------B74DD595C1EDDC3D18858B3C--



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

Date: Mon, 05 Jul 1999 09:53:38 +0100
From: Peter Doyle <peter.doyle@ireland.sun.com>
Subject: Sort Hash of Hash
Message-Id: <37807292.D5640246@ireland.sun.com>


--------------41AE9898849979FA2F395226
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi,
 I have a hash of hash data structure which I want to sort for printing. I need to
cascade the sorting some how, or sort it for one field in the record, then fill
temporary hashes with equal values to sort on the next field and so on.


This sorts fine but not recusively so it doesn't do what I want. It takes a
reference to a HoH & an array of fields to sort by.

sub sort_aDB
{
        my ($DB_ref, $order_ref) = @_;
        my @sorted = ();
        my %tmp = ();
        my @inherit_order = keys %{$DB_ref};
        for $f (0 .. $#{$order_ref})
        {
                my $field = pop @{$order_ref};
                print "<BR>Sorting by ", $field;
                @sorted = sort { ${$DB_ref}{$a}{$field} cmp ${$DB_ref}{$b}{$field}
} @inherit_order;
                #@sorted = sort sort_sub @inherit_order;
                @inherit_order = @sorted;
        }
        return @sorted;
}

Thanks if you can help,
Peter


--------------41AE9898849979FA2F395226
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Hi,
<br>&nbsp;I have a hash of hash data structure which I want to sort for
printing. I need to cascade the sorting some how, or sort it for one field
in the record, then fill temporary hashes with equal values to sort on
the next field and so on.
<br>&nbsp;
<p>This sorts fine but not recusively so it doesn't do what I want. It
takes a reference to a HoH &amp; an array of fields to sort by.
<p><tt>sub sort_aDB</tt>
<br><tt>{</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my ($DB_ref, $order_ref)
= @_;</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my @sorted = ();</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my %tmp = ();</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my @inherit_order =
keys %{$DB_ref};</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for $f (0 .. $#{$order_ref})</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
my $field = pop @{$order_ref};</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
print "&lt;BR>Sorting by ", $field;</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
@sorted = sort { ${$DB_ref}{$a}{$field} cmp ${$DB_ref}{$b}{$field} } @inherit_order;</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
#@sorted = sort sort_sub @inherit_order;</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
@inherit_order = @sorted;</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return @sorted;</tt>
<br><tt>}</tt>
<p>Thanks if you can help,
<br>Peter
<br>&nbsp;</html>

--------------41AE9898849979FA2F395226--



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

Date: Mon, 05 Jul 1999 17:24:38 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: Sort Hash of Hash
Message-Id: <7lqpru$f0r$1@news.mch.sbs.de>

In article <378071A9.A336C522@ireland.sun.com>, Peter Doyle <peter.doyle@ireland.sun.com> wrote:
> I have a hash of hash data structure which I want to sort for printing. I need
> to
>cascade the sorting some how, or sort it for one field in the record, then fill
>temporary hashes with equal values to sort on the next field and so on.
>

If I understand correctly, you're talking about sorting on different fields, 
which can be done with a simple || in your sort function. As it says
in perl FAQ 4 : How do I sort an array by (anything) ?

@sorted = sort {
        field1{$a} cmp field1{$b} # first sort on this field
        ||
        field2{$a} cmp field2{$b} # then sort on this field
        ||
        ... # etc.
} @data;

Obviously, the next step would be to transform this into sorting
keys of a hash :

@sortlist = ( 'field3', 'field1' ); # list of fields on which to sort

@sorted = sort {
        $href->{$a}{$sortlist[0]} cmp $href->{$b}{$sortlist[0]}
        ||
        $href->{$a}{$sortlist[1]} cmp $href->{$b}{$sortlist[1]}
        ||
        ...
} keys %{$href};

But what if you don't know the number of fields on which to sort in advance ?

Well, one way of doing this would be to build your sort function dynamically,
like this :

$sortstr = '';
foreach (@sortlist) {
        $sortstr .= "\$href->{\$a}{$_} cmp \$href->{\$b}{$_} || ";
}
$sortstr = substr($sortstr,0,length($sortstr) - 4);
$sortfunc = eval "sub { $sortstr }";
die "The sort function '$sortstr' is invalid" if $@;

@sorted = sort $sortfunc keys %{$href};

So you end up with the following script :

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

my $href = {
        'record1' => {
                'field1' => 'valueA',
                'field2' => 'valueB',
                'field3' => 'valueC',
        },
        'record2' => {
                'field1' => 'valueC',
                'field2' => 'valueB',
                'field3' => 'valueA',
        },
        'record3' => {
                'field1' => 'valueC',
                'field2' => 'valueA',
                'field3' => 'valueB',
        },
        'record4' => {
                'field1' => 'valueB',
                'field2' => 'valueA',
                'field3' => 'valueC',
        },
};

my @sortlist = ( 'field3', 'field1' );
my $sortstr = '';
foreach (@sortlist) {
        $sortstr .= "\$href->{\$a}{$_} cmp \$href->{\$b}{$_} || ";
}
$sortstr = substr($sortstr,0,length($sortstr) - 4);
my $sortfunc = eval "sub { $sortstr }";
die "The sort function '$sortstr' is invalid" if $@;

foreach my $item (sort $sortfunc keys %{$href}) {
        print "$item --> ";
        foreach (sort keys %{$href->{$item}}) {
                print "$href->{$item}{$_} ";
        }
        print "\n";
}

exit;

Of course, this may not be the cleanest way of doing things,
but since I'm not up to Schwartzian Transforms yet ... :-)

Michel.

--
aWebVisit - extracts visitor information from WWW logfiles and shows
the top entry, transit, exit and 'hit&run' pages, the links followed
inside your website, the time spent per page, the visit duration etc.
For more details, see http://gallery.uunet.be/Michel.Dalle/awv.html


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

Date: Tue, 06 Jul 1999 05:14:50 -0400
From: "Mr. Dave" <wavey@pilot.infi.net>
Subject: sort of stuck
Message-Id: <3781C909.CCE5960F@pilot.infi.net>

Is it possible to sort by 2 criteria in the same sort?

=rborg= Jun 29 12:20:28, moida
=rememu= Jun 29 23:34:17, kpanko

above is a piece of a loooooong log file I would sort through....  I'd
like to sort the "tech" (right of comma) in abc order and have all lines
w/ same tech in chronological order.

I thought I nailed this simply by sorting by the tech since the log file
starts in chronological order but then I'll end up with all lines being
in order by tech but per tech the time order will be all screwed up....

below is I guess as close as I've come and this for some reason puts
"customer" (1st name to the left) in abc order AND actually keeps
chronological order per customer....

I realize that to some of the gurus that frequent this group this
question may be quite basic...   So if is it so simple a post that it
hurts you, I'm sorry in advance(Yuri)

many thanx to whom may help!!

print "enter a date ";
chomp ($date = <>);

@data = `grep -i "$date" /var/adm/verfy.log`;   #grab days data from log
file

for (@data) {                                    # grabbing fields I
want to sort by
   $item = /:\d\d\S\s(\S+)\s/;               # grab "tech"
   $item2 = /\s(\d\d:\d\d:\d\d)\s/;         # grab time
   push (@bytech, $item);
   push (@bytime, $item2);
             }

@sorted = sort ( $bytech[$a] cmp $bytech[$b] &&   #seemed like  this
would do it??
     $bytime[$a] <=> $bytime[$b],  @data);

for (@sorted) {
   print "$_";}


output from above:

=rborg= Jun 29 12:20:28, moida
=rborg= Jun 29 12:30:06, dcorne
=rcpmd= Jun 29 19:49:32, khowell
=rcwjcw= Jun 29 12:04:47, kevinmg
=rdear10= Jun 29 21:19:57, ejhoffer
=rdear10= Jun 29 21:26:11, trmiller
=rdj29= Jun 29 00:33:34, krag
=rdj29= Jun 29 00:33:50, krag
=relmsinc= Jun 29 16:42:40, megw
=relmsinc= Jun 29 16:52:35, ejhoffer
=relmsinc= Jun 29 16:59:55, megw
=rememu= Jun 29 23:34:17, kpanko
=rememu= Jun 29 23:48:40, jamesgr
=restone= Jun 29 15:49:21, jslugg
=rfs1= Jun 29 13:04:48, jramsey
=rgrubbs= Jun 29 16:48:23, firvis






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

Date: Tue, 06 Jul 1999 09:39:56 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: sort of stuck
Message-Id: <7lsj08$52e$1@news.mch.sbs.de>

In article <3781C909.CCE5960F@pilot.infi.net>, "Mr. Dave" <wavey@pilot.infi.net> wrote:
>Is it possible to sort by 2 criteria in the same sort?
>
>=rborg= Jun 29 12:20:28, moida
>=rememu= Jun 29 23:34:17, kpanko
>

Actually, it's || instead of &&, but you're close :-)

See Perl FAQ 4, How to sort an array by (anything) ?

You may want to store your logfile directly into an array of arrays
rather than keeping the whole file in one array and building two
other arrays for the fields to be matched.

Or have a look at the Sort::Fields module on CPAN. It looks like
it might be the answer to your problem...

Michel.


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

Date: Mon, 05 Jul 1999 09:46:37 GMT
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: sort of stuck
Message-Id: <7lsjds$7sd$1@monet.op.net>

In article <3781C909.CCE5960F@pilot.infi.net>,
Mr. Dave <wavey@pilot.infi.net> wrote:
>Is it possible to sort by 2 criteria in the same sort?

Yes.  Please see the examples in the description of the `sort'
function in the on-line manual, `perlfunc' section.


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

Date: Mon, 05 Jul 1999 09:52:01 GMT
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: sort of stuck
Message-Id: <7lsjno$7tq$1@monet.op.net>

In article <3781C909.CCE5960F@pilot.infi.net>,
Mr. Dave <wavey@pilot.infi.net> wrote:
>Is it possible to sort by 2 criteria in the same sort?

Also please see
	http://www.perl.com/CPAN-local/doc/FMTEYEWTK/sort.html


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

Date: Tue, 06 Jul 1999 13:21:39 +0100
From: Ian Mortimer <ianmorty@nortelnetworks.com>
Subject: sorting hashes with some identical fields
Message-Id: <3781F4D3.8E04682@nortelnetworks.com>

Hi all,

I would really appreciate some help here !

I am trying to display a data file by a particular field.  The data is
stored like this -

Ian Mortimer:12-12-99:rusa.66:XPM12:XPM10:GPO:Original::lardy
telecom:wrwerwer344:blobby:12334343434:12-12-99

i.e. a single string (row) with fields seperated by a : and each row is
seperated by a \n.

What I want to do is sort these rows by a particular field.

What I am trying to do at the moment is split up each row into elements
and assign them to an array.  I then want use a particular element from
that array as a key in a hash (the hash value for that key would be a
whole row of data).
I then sort these keys and print out the hash in that order.

I'm not having much luck at the moment ! every time I get a repeated
value (quite common in my data) it gets ignored.  Only the first
occourence of that data appears. 

Any ideas on how to do this properly ?

Ian.


Here are some snippets of code:

This one just splits up the data and puts each element into another
array for sorting.

sub sort_prostar {

#Elements are:  0 - Prostar
#               1 - Date
#               2 - Requestor
#               3 - XPM Load
#               4 - Status
#               5 - VO Site

$count = 1;
open (LOGFL ,$logfile) || die "Couldn't open $logfile \n";
while (<LOGFL>) {

 $row = $_;

 if ($row ne "\n") {
  print "$row\n";
  print "<br>\n";
  @element = split(/:/,$row);
  $data_hash{$element[0]} = $row;

  print "<strong>$element[0]:</strong> $data_hash{$element[0]}\n";
  print "<br>\n";

  $elements_to_sort[$count] = $element[0];
  print "E2S: $elements_to_sort[$count]\n";
  print "COUNT: $count\n";
  print "<br>\n";
  print "<br>\n";

  $count++;

 }#if

} #while

close(LOGFL);

I then do the sorting and displaying with:

@elements_sorted = sort { $a <=> $b } @elements_to_sort;

foreach $value (@elements_sorted) {
 print "$data_hash{$value}\n";
}

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

I have also tried:

@keyfield = sort by_prostar keys(%data_hash);

foreach (@keyfield) {
 print "$_ has a value of $data_hash{$_}\n";
 print "<br>\n";
 print "<br>\n";
}#foreach

sub by_prostar {
 return (($data_hash{$a} <=> $data_hash{$b}) || ($a cmp $b));
}

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


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

Date: Sat, 03 Jul 1999 19:12:39 -0400
From: esalmon@packet.net
Subject: sprintf, pack and unpack question!
Message-Id: <377E98E7.3E13@packet.net>

If the following converts a string to a urlencoded or
x-www-form-urlencoded:

	$string =~ s/(\W)/'%' . unpack 'H2', $1/eg;

	or

	$string =~ s/(\W)/sprintf '%%%.2x', ord $1/eg;

and the following converts it back:

	$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

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

How would I convert to and from a base 64?


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: Sat, 3 Jul 1999 20:08:50 -0500
From: elaine ashton <elaine@wustl.edu>
Subject: Re: sprintf, pack and unpack question!
Message-Id: <Pine.GSO.4.05.9907032006530.454-100000@chaos.wustl.edu>

> How would I convert to and from a base 64?

I'm starting to wonder if anyone reads anymore.

'perldoc perlfaq9' from your command line 
or
http://language.perl.com/newdocs/pod/perlfaq9.html

e.
-- 

         -=]) elaine ashton // elaine@chaos.wustl.edu // r00t ([=-
   -=]) A dismal wasteland of banality, cliche' and casual obscenity ([=- 



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

Date: Tue, 06 Jul 1999 03:04:37 GMT
From: nospam.newton@gmx.net (Philip 'Yes, that's my address' Newton)
Subject: Re: sprintf, pack and unpack question!
Message-Id: <3780e58f.128483299@news.nikoma.de>

On Sat, 3 Jul 1999 20:08:50 -0500, elaine ashton <elaine@wustl.edu>
wrote:

>> How would I convert to and from a base 64?
>
>I'm starting to wonder if anyone reads anymore.
>
>'perldoc perlfaq9' from your command line 

That document also tells you why blindly replacing every \W in your
string is not a good idea for URL encoding, either.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.net>


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

Date: Sat, 03 Jul 1999 00:11:31 -0400
From: Bob Walton <walton@frontiernet.net>
To: paulm@dirigo.com
Subject: Re: SQL statement in Perl
Message-Id: <377D8D73.4F8F55EB@frontiernet.net>

> ...
> > > > Does anyone have any familiarity with writing SQL statements in
> > Perl?
> > >

 ...
Paul, I don't know if you found what you need yet or not -- since you are
dealing with Access 97, I assume you are on the Win32 platform.  Here is a
sample ODBC script using Win32::ODBC that lets Perl yak with Access:

# ODBC test program

# Seting up an ODBC database

#a) Click Settings/ControlPanel
#b) Click 32-Bit ODBC
#c) Select "System DSN" tab
#d) Click Add, select "Microsoft Access Driver", click Finish
#e) Enter the following properties
#   Data Source Name:  test_dsn  (This is the most important field)
#   Description: Anything
#f) Click on Create... and choose a filename, eg. c:\database\test.mdb
#g) Next time Click on Select ... and choose a filename, eg.
c:\database\test.mdb


use Win32::ODBC;

&insertData;
&getData;


exit(0);


sub insertData {
   $dsn = "test_dsn";

   $db = new Win32::ODBC($dsn);
   die "ERROR: Failed to open database\n" if(!$db);

   $sql = "CREATE TABLE test_table (";
   $sql .= "id char(02), ";
   $sql .= "name char(04), ";
   $sql .= "city char(03) )";

    $db->Sql($sql);
   ($ErrNum, $ErrText, $ErrConn) = $db->Error();

   $sql = "DELETE FROM test_table";
   $db->Sql($sql);

   $sql = "INSERT INTO test_table (id, name, city) VALUES ('01', 'Jack',
'NY')";
   $db->Sql($sql);

   $sql = "INSERT INTO test_table (id, name, city) VALUES ('02', 'John',
'Lon')";
   $db->Sql($sql);

   $sql = "INSERT INTO test_table (id, name, city) VALUES ('03', 'Mike',
'HK')";
   $db->Sql($sql);

   $sql = "INSERT INTO test_table (id, name, city) VALUES ('04', 'Carl',
'LA')";
   $db->Sql($sql);
}


sub getData {

   $sql = "SELECT * from test_table order by id";

   $db->Sql($sql);
   while ($db->FetchRow()) {
      ($id, $name, $city) = $db->Data("id", "name", "city");
      print $id, " - ", $name, " - ", $city, "\n";
   }
   $db->Close();
}

The above should create an Access database from scratch, put some stuff in
it, and retrieve it.  That should provide a good starting point.  It works
-- I use it.



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

Date: Sat, 03 Jul 1999 14:41:22 GMT
From: "Sean O'Neill" <soneill@marsworks.com>
Subject: SSI Question...
Message-Id: <mipf3.20656$ga.32993@news21.bellglobal.com>

I have no problem using server side includes inside a file named with an
 .shtml extension...however, if I have a perl script that is generating the
HTML page, how can I include say a common header and footer?

I.E. I can't just pop in the usual <!-- include --> stuff since the page
won't be parsed like the traditional .shtml files.  I am more used to using
ASP which will include files with almost the same syntax but I'm not sure
what to do when using Perl.

Thanks.




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

Date: Sat, 3 Jul 1999 19:52:31 +0500
From: "Faisal Nasim" <swiftkid@bigfoot.com>
Subject: Re: SSI Question...
Message-Id: <7lmbdb$ai52@news.cyber.net.pk>

$ga.32993@news21.bellglobal.com...
> I have no problem using server side includes inside a file named with an
> .shtml extension...however, if I have a perl script that is generating the
> HTML page, how can I include say a common header and footer?
>
> I.E. I can't just pop in the usual <!-- include --> stuff since the page
> won't be parsed like the traditional .shtml files.  I am more used to
using
> ASP which will include files with almost the same syntax but I'm not sure
> what to do when using Perl.

Just open the file you call be include and print it directly.

open FILE , "/blah/header.html";
    print <FILE>
close FILE;

OR

print `cat /blah/header.html`; #unix
print `type /blah/header.html`; #win


Or use mod_perl (http://perl.apache.org/)




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

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

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

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

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

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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


------------------------------
End of Perl-Users Digest V9 Issue 48
************************************


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