[16165] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3577 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 10 17:33:23 2000

Date: Mon, 10 Jul 2000 14:33:11 -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: <963264790-v9-i3577@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 10 Jul 2000     Volume: 9 Number: 3577

Today's topics:
        Legal SSI procedure? <insley@aprsystems.com>
    Re: Legal SSI procedure? <care227@attglobal.net>
    Re: Legal SSI procedure? <rob13@rock13.com>
    Re: Legal SSI procedure? <insley@aprsystems.com>
    Re: Legal SSI procedure? (John Harden Borwick)
        Linking to TRIM API <allanon.69@no.spam.bigpond.com>
        loading array of arrays from file mneilly@yahoo.com
    Re: loading array of arrays from file (Keith Calvert Ivey)
    Re: Logical Not : 'not' vs '!' <jpl@research.att.com>
        Looking for a few validations <raphaelp@nr1webresource.com>
    Re: Looking for a few validations (Tad McClellan)
    Re: Looking for a few validations (Abigail)
    Re: Looking for mortgage calculations <bet@rahul.net>
        Looping thru recs scarey_man@my-deja.com
    Re: Looping thru recs (Tad McClellan)
    Re: Looping thru recs <graham.wood@iona.com>
    Re: Looping thru recs <graham.wood@iona.com>
    Re: Looping thru recs <adetalabi@clara.co.uk>
    Re: Looping thru recs scarey_man@my-deja.com
        making a simple proxy server in perl? <thierry.metoudi@netcourrier.com>
    Re: making a simple proxy server in perl? <care227@attglobal.net>
        map question (Brandon Metcalf)
    Re: map question (Rafael Garcia-Suarez)
    Re: map question <uri@sysarch.com>
    Re: map question <stephen.kloder@gtri.gatech.edu>
    Re: map question (John Harden Borwick)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Mon, 03 Jul 2000 19:36:55 GMT
From: pat <insley@aprsystems.com>
Subject: Legal SSI procedure?
Message-Id: <3960EB54.77A4B627@aprsystems.com>

I'm a few days past newbie, but still unsure of the rules for using an
"<!--#include virtual" line in an .shtml page to call a perl script that
produces a table of data.  I'd like to put the script on one server and
call it from another, but this procedure errors out.  Is this "legal",
and if so, how do I address the call?  ("<!--#include
virtual=http://otherdomain.org/cgi-bin/..." doesn't work.







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

Date: Mon, 03 Jul 2000 15:46:39 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Legal SSI procedure?
Message-Id: <3960ED9F.F9B9B9E9@attglobal.net>

pat wrote:
> 
> I'm a few days past newbie, but still unsure of the rules for using an
> "<!--#include virtual" line in an .shtml page to call a perl script that
> produces a table of data.  

SSI is not defined by a standard, so the implementations are vendor
specific.  Check the documentation for your webserver and see what it
indicates.  Not much related to Perl in this question, as it is.


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

Date: Mon, 03 Jul 2000 18:02:45 -0400
From: "Rob - Rock13.com" <rob13@rock13.com>
Subject: Re: Legal SSI procedure?
Message-Id: <39610D85.A2B3350@rock13.com>

pat wrote:
> 
> I'm a few days past newbie, but still unsure of the rules for using an
> "<!--#include virtual" line in an .shtml page to call a perl script that
> produces a table of data.  I'd like to put the script on one server and
> call it from another, but this procedure errors out.  Is this "legal",
> and if so, how do I address the call?  ("<!--#include
> virtual=http://otherdomain.org/cgi-bin/..." doesn't work.

This really isn't Perl. SSI can't get files from other servers, only
local files.
-- 

Rob - http://rock13.com/
Web Stuff: http://rock13.com/webhelp/


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

Date: Mon, 03 Jul 2000 23:26:21 GMT
From: pat <insley@aprsystems.com>
Subject: Re: Legal SSI procedure?
Message-Id: <39612118.FB32A194@aprsystems.com>

Thanks for the direction on this.



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

Date: 3 Jul 2000 19:56:09 GMT
From: jhborwic@unity.ncsu.edu (John Harden Borwick)
Subject: Re: Legal SSI procedure?
Message-Id: <8jqr4p$5ik$1@uni00nw.unity.ncsu.edu>

[ Followups set, hopefully ]

In article <3960EB54.77A4B627@aprsystems.com>,
pat  <insley@aprsystems.com> wrote:
>I'm a few days past newbie, but still unsure of the rules for using an
>"<!--#include virtual" line in an .shtml page to call a perl script that
>produces a table of data.  I'd like to put the script on one server and
>call it from another, but this procedure errors out.  Is this "legal",
>and if so, how do I address the call?  ("<!--#include
>virtual=http://otherdomain.org/cgi-bin/..." doesn't work.

This does not seem to be a Perl question.  It does seem to be a web server
question.

-- 
John Borwick


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

Date: Thu, 6 Jul 2000 20:23:35 +1000
From: "Allanon69" <allanon.69@no.spam.bigpond.com>
Subject: Linking to TRIM API
Message-Id: <f_Y85.7038$c5.19109@newsfeeds.bigpond.com>

Hi,

Just wondering if anyone here has managed to successfully link to the TRIM
API, search for a document and display it? I'm wanting to then link the perl
script up to a HTML (index) page with links.

In case you're wondering, TRIM is a documentation management system.




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

Date: Thu, 06 Jul 2000 00:28:33 GMT
From: mneilly@yahoo.com
Subject: loading array of arrays from file
Message-Id: <8k0jr8$1ut$1@nnrp1.deja.com>

I'm trying to initialize an array of arrays
from a file but I'm having trouble using the
string retrieved from the file.

Example:

my @checks = ();

open(CFG, "config") || die "Can't open config";

while (<CFG>) {

    if (!/^\#/ && !/^\s/) {
	my ($item, $rules) = split(/,/,$_,2);
	my @check = [$item, $rules];
                     ^^^^^
                     ^^^^^
        # Not sure what needs to go here....
        # For the first line of "config" I want
        # it to be:
        #	 my @check = [yy::zz::STMT, $rules];
        #
        # and for the second:
        #
        # 	my @check = [yy::zz::DECL, $rules];
        # and so on so I can initialize this array
        # from a file that may change on a frequent
        # basis without changing the perl script.

        push(@checks, @check);
    }

}

Where "config" contains:

yy::zz::STMT, 1, 6, 7
yy::zz::DECL, 2, 3, 4

thanks
-M


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


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

Date: Thu, 06 Jul 2000 01:31:06 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: loading array of arrays from file
Message-Id: <3963ddf9.5499420@nntp.idsonline.com>

mneilly@yahoo.com wrote:

>I'm trying to initialize an array of arrays
>from a file but I'm having trouble using the
>string retrieved from the file.

You haven't explained what trouble you're having.  All you've
shown is how you constructed the array.  How are you using it?

[snip]
>while (<CFG>) {
>
>    if (!/^\#/ && !/^\s/) {
>	my ($item, $rules) = split(/,/,$_,2);
>	my @check = [$item, $rules];

Why are you assigning a scalar to an array variable?  That isn't
your problem, though, because it ends up doing the right thing
anyway, with @check having only one element.

[snip]
>        push(@checks, @check);
>    }
>
>}

I'd eliminate all those extra variables (and the extra level of
indention) and write

    while (<CFG>) {
        next if /^[#\s]/;
        push @checks, [ split /,/, $_, 2 ];
    }

Yes, you could even put the condition onto the "push" line (by
reversing its sense), but I'd leave it separate in case you
wanted to add something else to the loop later.  Also, leaving
it separate allows you to comment the "next" line ("# skip
comments and <whatever those lines starting with whitespace
are>").

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


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

Date: Sun, 9 Jul 2000 16:57:22 GMT
From: "John P. Linderman" <jpl@research.att.com>
Subject: Re: Logical Not : 'not' vs '!'
Message-Id: <3968AEF2.5C1CC952@research.att.com>

Jeff Pinyan wrote:

> On Jun 30, Ed Summers said:
>
> >Cool toy! I took a quick look around and couldn't find any mention for
> >the '-MO=Deparse' switch ( Camel, perldoc -f )... Is there any
> >description available for it?
>
> .... snip, snip
>
> The O hierarchy of modules is a frontend to the B hierarchy.  They allow
> you to do things like deparse your Perl code to what Perl sees (this
> usually works).
>
>   perldoc B
>   perldoc O
>
> --
> Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/

If the output of  -MO=Deparse,-p is (or can be made) sufficiently regular,
perhaps some public-spirited guru could produce some code to apply two
versions of perl to the same script, and warn of differences between the
versions.
(I have the spirit, but come up somewhat short on the guru-ness).

The goal, in case it isn't obvious, would be to call attention to existing
programs
that might change behavior with a new release.

John P. Linderman  jpl@research.att.com



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

Date: Wed, 5 Jul 2000 18:24:32 +0200
From: "Raphael Pirker" <raphaelp@nr1webresource.com>
Subject: Looking for a few validations
Message-Id: <8jvnu5$34a$13$1@news.t-online.com>

Hi,

I have a Form 2 Email script (written in Perl) and I want to do the
following validations:

1) Size of the message may not be larger than 50k
2) Code to remove all the text behind the comma (including the comma)
So "text1, text2, text3" turns into "text1"

Thanks in advance for any help!

Regards,

Raphael




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

Date: Wed, 5 Jul 2000 13:08:07 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Looking for a few validations
Message-Id: <slrn8m6qrn.hj8.tadmc@magna.metronet.com>

On Wed, 5 Jul 2000 18:24:32 +0200, Raphael Pirker <raphaelp@nr1webresource.com> wrote:
>
>I have a Form 2 Email script (written in Perl) and I want to do the
>following validations:
>
>1) Size of the message may not be larger than 50k


   perldoc -f length


>2) Code to remove all the text behind the comma (including the comma)
>So "text1, text2, text3" turns into "text1"


all untested:

   substr( $_, index($_, ',') ) = '';

   $_ = substr($_, 0, index($_, ','));

   s/,.*//s;


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


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

Date: 05 Jul 2000 15:55:31 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: Looking for a few validations
Message-Id: <slrn8m75n8.ibb.abigail@alexandra.delanet.com>

Raphael Pirker (raphaelp@nr1webresource.com) wrote on MMD September
MCMXCIII in <URL:news:8jvnu5$34a$13$1@news.t-online.com>:
"" Hi,
"" 
"" I have a Form 2 Email script (written in Perl) and I want to do the
"" following validations:
"" 
"" 1) Size of the message may not be larger than 50k
"" 2) Code to remove all the text behind the comma (including the comma)
"" So "text1, text2, text3" turns into "text1"
"" 
"" Thanks in advance for any help!


man perl


Hope this helps!


Abigail
-- 
perl -we '$_ = q ?4a75737420616e6f74686572205065726c204861636b65720as?;??;
          for (??;(??)x??;??)
              {??;s;(..)s?;qq ?print chr 0x$1 and \161 ss?;excess;??}'


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

Date: Tue, 4 Jul 2000 12:54:45 -0400
From: Bennett Todd <bet@rahul.net>
Subject: Re: Looking for mortgage calculations
Message-Id: <20000704125445.H506@oven.com>


--PW0Eas8rCkcu1VkF
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

2000-06-22-12:57:09 nater@vlender.com:
> I am looking for the formulas for mortgage calculators,
> specifically rent vs own (buy) calculation.

Well, the basic annuity equation is pretty simple; given an interest
rate i, and number of terms n, you compute a factor

	F = (1 - 1/(1+i)^n)/i

then you can convert between the amount of the payment and the
present value of the annuity (== purchasing power of the mortgage,
for example) with

	PV = payment x F

Expressing that lot in perl is pretty easy:-).

-Bennett

--PW0Eas8rCkcu1VkF
Content-Type: application/pgp-signature
Content-Disposition: inline


Version: GnuPG v1.0.0 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE5YhbVL6KAps40sTYRApHbAJ9cUDI9G9XsM63zeRtol42gMDXerwCcCDBp
lhYnJ2ZgD4IzGhgElFGL9vQ=
=dEId
-----END PGP SIGNATURE-----

--PW0Eas8rCkcu1VkF--


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

Date: Tue, 04 Jul 2000 13:42:28 GMT
From: scarey_man@my-deja.com
Subject: Looping thru recs
Message-Id: <8jspk1$d51$1@nnrp1.deja.com>

I have a problem where I have 2000-3000 recs from a database and I need
to pick out the records with the newest date
The format is as follows (taken from a much larger list):
domain     fileset    Used    Avail     Recdate
abcd       def        1234     2345     01/05/2000
                                           .
                                           .
abcd       def        1234     2345     31/05/2000   (I need this one)
abcd       ghi        1234     2345     01/05/2000
                                           .
                                           .
abcd       ghi        1234     2345     30/05/2000   (I need this one)

I cannot think of a method to scroll easily through the records and
select the ones with the newest dates (for every different
domain/fileset combination.

Any help will be appreciated.
Thanks,
Brain-dead Beginner!



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


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

Date: Tue, 4 Jul 2000 10:27:06 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Looping thru recs
Message-Id: <slrn8m3t1q.ekb.tadmc@magna.metronet.com>

On Tue, 04 Jul 2000 13:42:28 GMT, scarey_man@my-deja.com <scarey_man@my-deja.com> wrote:

>I have a problem where I have 2000-3000 recs from a database and I need
>to pick out the records with the newest date
                                  ^^^^^^^^^^^

If you can redefine the problem (looks like you can), then
the solution will be much easier.

Looks like you don't really need the "newest date". All you
need is the last line for each "key" (domain + fileset).

If you really need to compare the dates, then you will
need to extract the fields (maybe using unpack()) and
you will probably want to normalize the date for easy
comparison (or use a Date:: module).

If it is always the "last line per key" that you want,
you don't need to extract or compare dates, you will
only need the first two fields (to form the key).


>I cannot think of a method to scroll easily through the records and
>select the ones with the newest dates


Me either.

But it is pretty easy to select only the "last" ones:


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

my $current = '';   # concatenation of "current" domain and fileset
my $prev_line;      # the previous line of data

while ( <DATA> ) {
   my($domain, $fileset) = unpack "A11 A11", $_;
   if ( $current ne "$domain$fileset" ) {      # changing "key"
      print $prev_line if defined $prev_line;  # output cached line
      $current = "$domain$fileset";            # remember the new key
   }
   $prev_line  = $_;                           # cache the line
}
print $prev_line;  # for the very last one


__DATA__
abcd       def        1234     2345     01/05/2000
abcd       def        1234     2345     31/05/2000
abcd       ghi        1234     2345     01/05/2000
abcd       ghi        1234     2345     30/05/2000
 ------------------------------


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


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

Date: Tue, 4 Jul 2000 17:03:32 +0100
From: "Graham Wood" <graham.wood@iona.com>
Subject: Re: Looping thru recs
Message-Id: <8jt26u$f5s$1@bvweb.iona.com>

Hi Scary,

I realise I'm committing Perl heresy here by hand coding stuff that probably
exists in a modules somewhere.  I reckon you could probably get SQL to
select just the latest records for each domain/fileset combination too.  But
anyway...

Here's a script that will select the latest dates from records in the format
you specified.  Further heresy in the fact that I didn't use pack/unpack but
it worked and I enjoyed it!

Graham Wood

=================== START ================================
open(DATAFILE,"your input file");
@recs=<DATAFILE>;
close DATAFILE;

#---------------------------------------------------------------------------
-
# 1. Create a key from domain/fileset combination
# 2. Check in %rechash for an existing record for the current key.
# 3. if there is one, compare the dates from each record and keep the newer
one
#    see ("sub later" below)
# 4. if there isn't an existing record, add the current input record
#---------------------------------------------------------------------------
-
foreach(@recs){
 ($domain,$fileset,$used,$avail,$recdate) = split(' ',$_);
 $key="$domain"."_"."$fileset";
 if($rechash{"$key"}){ # if there is already an entry for this
domain/fileset combo
       @existing=split(' ',$rechash{"$key"});
      if(&later("$recdate","$existing[$#existing]") eq $recdate){
           # this record's date is later than the existing one so replace it
           $rechash{"$key"}=$_;
      }
      # if new record isn't later we don't need to do anything
 }
 else{
      # no existing record so this must be the latest
      $rechash{"$key"}=$_;
 }
}

#---------------------------------------------------------------------------
-
# print out the results from %rechash
#---------------------------------------------------------------------------
-

@hashkeys=keys(%rechash);
foreach(@hashkeys){
     print $rechash{"$_"};
     print "\n";
}

sub later{
     my $date1=$_[0];
     my $date2=$_[1];

     ($day1,$month1,$year1)=split(/\//,$date1);
     ($day2,$month2,$year2)=split(/\//,$date2);
     if( $year1 > $year2

          # year 1 is later
          return $date1;
     }
     elsif($year1 == $year2){
          if($month1> $month2){
               # month 1 is later
               return $date1;
          }
          elsif($month1 == $month2){
               if($day1 > $day2){
                    # day 1 is later
                    return $date1;
               }
               else{
                    # day 2 is later or the whole date is the same
                    # if date is the same, leave the old one
                    return $date2;
               }
          }
          else{
              # month 2 is the later
              return $date2;
          }
     }
     else{
          # year 2 is later
          return $date2;
     }
}

=========================== END =============================
<scarey_man@my-deja.com> wrote in message
news:8jspk1$d51$1@nnrp1.deja.com...
> I have a problem where I have 2000-3000 recs from a database and I need
> to pick out the records with the newest date
> The format is as follows (taken from a much larger list):
> domain     fileset    Used    Avail     Recdate
> abcd       def        1234     2345     01/05/2000
>                                            .
>                                            .
> abcd       def        1234     2345     31/05/2000   (I need this one)
> abcd       ghi        1234     2345     01/05/2000
>                                            .
>                                            .
> abcd       ghi        1234     2345     30/05/2000   (I need this one)
>
> I cannot think of a method to scroll easily through the records and
> select the ones with the newest dates (for every different
> domain/fileset combination.
>
> Any help will be appreciated.
> Thanks,
> Brain-dead Beginner!
>
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.




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

Date: Wed, 5 Jul 2000 09:49:10 +0100
From: "Graham Wood" <graham.wood@iona.com>
Subject: Re: Looping thru recs
Message-Id: <8jut4i$n3e$1@bvweb.iona.com>

Just thought of a shorter way of implementing the date comparison.  Turn the
date into a number by joining, year/month/day into a single integer value
then return the bigger of the 2 integers.



sub later{
    my $date1=$_[0];
    my $date2=$_[1];

    ($day1,$month1,$year1)=split(/\//,$date1);
    ($day2,$month2,$year2)=split(/\//,$date2);

    $firstdate=join('',$year1,$month1,$day1);
    $seconddate=join('',$year2,$month2,$day2);
    if($firstdate>$seconddate){
        return "$date1";
    }
    else{
        return "$date2";
    }
}

Graham Wood <graham.wood@iona.com> wrote in message
news:8jt26u$f5s$1@bvweb.iona.com...
> Hi Scary,
>
> I realise I'm committing Perl heresy here by hand coding stuff that
probably
> exists in a modules somewhere.  I reckon you could probably get SQL to
> select just the latest records for each domain/fileset combination too.
But
> anyway...
>
> Here's a script that will select the latest dates from records in the
format
> you specified.  Further heresy in the fact that I didn't use pack/unpack
but
> it worked and I enjoyed it!
>
> Graham Wood
>
> =================== START ================================
> open(DATAFILE,"your input file");
> @recs=<DATAFILE>;
> close DATAFILE;
>
>
#---------------------------------------------------------------------------
> -
> # 1. Create a key from domain/fileset combination
> # 2. Check in %rechash for an existing record for the current key.
> # 3. if there is one, compare the dates from each record and keep the
newer
> one
> #    see ("sub later" below)
> # 4. if there isn't an existing record, add the current input record
>
#---------------------------------------------------------------------------
> -
> foreach(@recs){
>  ($domain,$fileset,$used,$avail,$recdate) = split(' ',$_);
>  $key="$domain"."_"."$fileset";
>  if($rechash{"$key"}){ # if there is already an entry for this
> domain/fileset combo
>        @existing=split(' ',$rechash{"$key"});
>       if(&later("$recdate","$existing[$#existing]") eq $recdate){
>            # this record's date is later than the existing one so replace
it
>            $rechash{"$key"}=$_;
>       }
>       # if new record isn't later we don't need to do anything
>  }
>  else{
>       # no existing record so this must be the latest
>       $rechash{"$key"}=$_;
>  }
> }
>
>
#---------------------------------------------------------------------------
> -
> # print out the results from %rechash
>
#---------------------------------------------------------------------------
> -
>
> @hashkeys=keys(%rechash);
> foreach(@hashkeys){
>      print $rechash{"$_"};
>      print "\n";
> }
>
> sub later{
>      my $date1=$_[0];
>      my $date2=$_[1];
>
>      ($day1,$month1,$year1)=split(/\//,$date1);
>      ($day2,$month2,$year2)=split(/\//,$date2);
>      if( $year1 > $year2
>
>           # year 1 is later
>           return $date1;
>      }
>      elsif($year1 == $year2){
>           if($month1> $month2){
>                # month 1 is later
>                return $date1;
>           }
>           elsif($month1 == $month2){
>                if($day1 > $day2){
>                     # day 1 is later
>                     return $date1;
>                }
>                else{
>                     # day 2 is later or the whole date is the same
>                     # if date is the same, leave the old one
>                     return $date2;
>                }
>           }
>           else{
>               # month 2 is the later
>               return $date2;
>           }
>      }
>      else{
>           # year 2 is later
>           return $date2;
>      }
> }
>
> =========================== END =============================
> <scarey_man@my-deja.com> wrote in message
> news:8jspk1$d51$1@nnrp1.deja.com...
> > I have a problem where I have 2000-3000 recs from a database and I need
> > to pick out the records with the newest date
> > The format is as follows (taken from a much larger list):
> > domain     fileset    Used    Avail     Recdate
> > abcd       def        1234     2345     01/05/2000
> >                                            .
> >                                            .
> > abcd       def        1234     2345     31/05/2000   (I need this one)
> > abcd       ghi        1234     2345     01/05/2000
> >                                            .
> >                                            .
> > abcd       ghi        1234     2345     30/05/2000   (I need this one)
> >
> > I cannot think of a method to scroll easily through the records and
> > select the ones with the newest dates (for every different
> > domain/fileset combination.
> >
> > Any help will be appreciated.
> > Thanks,
> > Brain-dead Beginner!
> >
> >
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
>
>




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

Date: Wed, 05 Jul 2000 10:09:07 +0100
From: Ade Talabi <adetalabi@clara.co.uk>
Subject: Re: Looping thru recs
Message-Id: <3962FB33.204EE4B6@clara.co.uk>

scarey_man@my-deja.com wrote:
> 
> I have a problem where I have 2000-3000 recs from a database and I need
> to pick out the records with the newest date
> The format is as follows (taken from a much larger list):
> domain     fileset    Used    Avail     Recdate
> abcd       def        1234     2345     01/05/2000
>                                            .
>                                            .
> abcd       def        1234     2345     31/05/2000   (I need this one)
> abcd       ghi        1234     2345     01/05/2000
>                                            .
>                                            .
> abcd       ghi        1234     2345     30/05/2000   (I need this one)
> 
> I cannot think of a method to scroll easily through the records and
> select the ones with the newest dates (for every different
> domain/fileset combination.
> 
> Any help will be appreciated.
> Thanks,
> Brain-dead Beginner!
> 
> Sent via Deja.com http://www.deja.com/
> Before you buy.


WHat you need is to split the columns using split...

put the date column into a sort of Time:: method...you can pick a Time::
moduile form CPAN.

sort it according to date....sorry you have to loop through each record
and always store the latest one, until another comes along which is
later to replace that.

there are more efficient ways..as I am busy and I know thsi would
work...as in perl there are many ways to skina cat.
-- 
We see, whatever we want to see, whether visible or not 
- AT. June 2000.


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

Date: Wed, 05 Jul 2000 09:17:24 GMT
From: scarey_man@my-deja.com
Subject: Re: Looping thru recs
Message-Id: <8juueq$sfc$1@nnrp1.deja.com>

Graham, Tad
thanks for the replies.  I should be able to use the code to do what I
want.

Graham, I am using MySql to extract the records and could not see any
way of selecting the newest date for each domain/fileset combination
but this does not mean it can't be done.

Thanks,
Scarey Man


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


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

Date: Thu, 06 Jul 2000 14:37:02 +0200
From: TM <thierry.metoudi@netcourrier.com>
Subject: making a simple proxy server in perl?
Message-Id: <39647D6E.7CFA2A21@netcourrier.com>

Hello,

I'd like to make a very simple proxy server to go out of a firewall.
Does anyone did it before ?

Thanks

Tm



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

Date: Thu, 06 Jul 2000 10:07:07 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: making a simple proxy server in perl?
Message-Id: <3964928B.9D943F89@attglobal.net>

TM wrote:
> 
> Hello,
> 
> I'd like to make a very simple proxy server to go out of a firewall.
> Does anyone did it before ?
> 

http://search.cpan.org/search?mode=module&query=proxy

Took me all of 5 seconds to do that.  Next time maybe you can
save me the effort and do it yourself, eh?  I'm a lazy bastard
ya know.

(and God help you if you have to work with a SOCKS firewall...)


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

Date: 6 Jul 2000 06:10:05 GMT
From: bmetcalf@baynetworks.com (Brandon Metcalf)
Subject: map question
Message-Id: <8k17rt$fp8$1@bcrkh13.ca.nortel.com>

How can I use map to achieve the following?

for (@ary) { tr/a/b/; }

Using something like this

@ary = map { tr/a/b/ } @ary;

or

@ary = map { $_ =~ tr/a/b/ } @ary;

results in the elements of @ary containing the number of times tr///
replaced a with b.  I can't figure out how to actually modify *and*
return the elements of @ary.

Thanks,
Brandon


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

Date: Thu, 06 Jul 2000 06:29:06 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: map question
Message-Id: <slrn8m8a1v.54q.rgarciasuarez@rafael.kazibao.net>

Brandon Metcalf wrote in comp.lang.perl.misc:
>How can I use map to achieve the following?
>
>for (@ary) { tr/a/b/; }
>
>Using something like this
>
>@ary = map { tr/a/b/ } @ary;
>
>or
>
>@ary = map { $_ =~ tr/a/b/ } @ary;
>
>results in the elements of @ary containing the number of times tr///
>replaced a with b.  I can't figure out how to actually modify *and*
>return the elements of @ary.

@ary = map { tr/a/b/; $_ } @ary;

-- 
Rafael Garcia-Suarez


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

Date: Thu, 06 Jul 2000 06:37:35 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: map question
Message-Id: <x7em57rcgg.fsf@home.sysarch.com>

>>>>> "BM" == Brandon Metcalf <bmetcalf@baynetworks.com> writes:

  BM> How can I use map to achieve the following?
  BM> for (@ary) { tr/a/b/; }

  BM> @ary = map { tr/a/b/ } @ary;
  BM> @ary = map { $_ =~ tr/a/b/ } @ary;

those are the same.

  BM> results in the elements of @ary containing the number of times tr///
  BM> replaced a with b.  I can't figure out how to actually modify *and*
  BM> return the elements of @ary.

do you just want them back in the same array? then map is overkill.

	tr/a/b/ for @ary ;

also note if you do a map which modifies $_, it will modify the original
elements in the array. so

	@foo = map { tr/a/b/ ; $_ } @bar ;

will leave @foo and @bar the same.

someone else answered the same but with both arrays being @bar. that is
again overkill.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Thu, 06 Jul 2000 08:08:07 -0400
From: Stephen Kloder <stephen.kloder@gtri.gatech.edu>
Subject: Re: map question
Message-Id: <396476A6.5F14D445@gtri.gatech.edu>

Brandon Metcalf wrote:

> How can I use map to achieve the following?
>
> for (@ary) { tr/a/b/; }
>
> Using something like this
>
> @ary = map { tr/a/b/ } @ary;
>
> or
>
> @ary = map { $_ =~ tr/a/b/ } @ary;
>
> results in the elements of @ary containing the number of times tr///
> replaced a with b.  I can't figure out how to actually modify *and*
> return the elements of @ary.
>

The problem is that in both examples, you modify the elements in the
array via tr///, and then store the return value (# of characters
changed, not the resulting string) back into the same array, thus
destroying the data.  You have 2 options:
1) Don't bother with a return value:
  map {tr/a/b/} @ary;
2) Store the return value elsewhere (in case you have a use for it):
  @returnvals = map {tr/a/b/} @ary;




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

Date: 7 Jul 2000 06:15:14 GMT
From: jhborwic@unity.ncsu.edu (John Harden Borwick)
Subject: Re: map question
Message-Id: <8k3shi$372$1@uni00nw.unity.ncsu.edu>

In article <396476A6.5F14D445@gtri.gatech.edu>,
Stephen Kloder  <stephen.kloder@gtri.gatech.edu> wrote:
>The problem is that in both examples, you modify the elements in the
>array via tr///, and then store the return value (# of characters
>changed, not the resulting string) back into the same array, thus
>destroying the data.  You have 2 options:
>1) Don't bother with a return value:
>  map {tr/a/b/} @ary;

Map in a void context isn't a good idea.  Foreach was written for this sort
of thing:

tr/a/b/ foreach @ary;

>2) Store the return value elsewhere (in case you have a use for it):
>  @returnvals = map {tr/a/b/} @ary;

From my understanding of the question, this "option" isn't very helpful
to the poster.

What about

@newvals = map { my $new_value = $_; $new_value =~ tr/a/b/; $new_value } @ary;

Which seems to be what the poster had in mind?  This solution preserves
@ary and puts the appropriate transliterated values in the new array.

-- 
John Borwick


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

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


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