[9107] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2725 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 26 13:08:05 1998

Date: Tue, 26 May 98 10:00:27 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 26 May 1998     Volume: 8 Number: 2725

Today's topics:
    Re: -e under NT and UNIX (Jeffrey R. Drumm)
        [Perl] How to find the Perl FAQ <rootbeer&pfaq*finding*@redcat.com>
    Re: An unwelcome and undeserved slap (Greg Lindahl)
    Re: An unwelcome and undeserved slap (Greg Lindahl)
        Announce: Emacs TinyPerl.el module (POD mode) (Jari Aalto+mail.perl)
    Re: case insensitive checks, a=b (brian d foy)
    Re: Clearly define "free software" <burley@tweedledumb.cygnus.com>
    Re: Clearly define "free software" <ketil@ii.uib.no>
        Efficient Regex's (Wade Williams)
    Re: Getting hex codes from string <andy@wonderworks.co.uk>
        Getting rid of carriage returns <oban@brownrice.com>
    Re: GNU attacks on the open software community <vroonhof@frege.math.ethz.ch>
    Re: GNU attacks on the open software community (Tim Smith)
    Re: GPL documentation == unspeakable evil (Abigail)
    Re: GPL documentation == unspeakable evil (Abigail)
    Re: Handling Dates Help Please <aqumsieh@matrox.com>
        new to OO Perl <sjp6683@rit.edu>
    Re: new to OO Perl <two_step@bigfoot.com>
    Re: Problem reading large files under Win95 <david@solbors.no>
    Re: Problem with Renaming a file to a new name that's s <aqumsieh@matrox.com>
        reference to tom c's filehandles tutorial <lanier@shell6.ba.best.com>
        utility which can POST web queries <Jonathan_Epstein@nih.gov>
    Re: while, each & assoc array (John Porter)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Tue, 26 May 1998 16:15:34 GMT
From: drummj@mail.mmc.org (Jeffrey R. Drumm)
Subject: Re: -e under NT and UNIX
Message-Id: <356ae64b.352255055@news.mmc.org>

[posted and mailed]

On 26 May 1998 14:30:44 GMT, daniel.mendyke@digital.com (Daniel) wrote:

>
>I need to verify the existence of a file.
>My script must run under both NT and UNIX.
>I've used 
>
> &IsThere() if -e $fileName;
>
>But because $fileName is '/tmp/images/thing.gif'
>NT can't find it.

Do you have a directory named '\tmp\images' on your NT system? Is there a file
in it named 'thing.gif'?

>Is there a module that converts file names for
>OS independence?

Not sure why you need one. I created a directory called '\tmp\images' on my
system, and put a file in it named 'thing.gif':

C:\>perl -e "print qq(It's there!\n) if -e '/tmp/images/thing.gif'"
It's there!

C:\>

So where's the problem?

>Daniel Mendyke 
>==============================================
>daniel@virtualvoices.com
>Sell it OnLine at http://www.virtualvoices.com
>==============================================

-- 
                               Jeffrey R. Drumm, Systems Integration Specialist
                       Maine Medical Center - Medical Information Systems Group
                                                            drummj@mail.mmc.org
"Broken? Hell no! Uniquely implemented!" - me


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

Date: Tue, 26 May 1998 10:24:01 GMT
From: Tom Phoenix <rootbeer&pfaq*finding*@redcat.com>
Subject: [Perl] How to find the Perl FAQ
Message-Id: <pfaqmessage896178241.7657@news.teleport.com>

Archive-name: perl-faq/finding-perl-faq
Posting-Frequency: weekly
Last-modified: 18 May 1998

[ That "Last-modified:" date above refers to this document, not to the
Perl FAQ itself! The last major update of the Perl FAQ was in Spring of
1997; of course, ongoing updates are made as needed. ]

For most people, this URL should be all you need in order to find Perl's
Frequently Asked Questions (and answers).

    http://cpan.perl.org/doc/FAQs/

Please look over (but never overlook!) the FAQ and related docs before
posting anything to the comp.lang.perl.* family of newsgroups.

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 

Beginning with Perl version 5.004, the Perl distribution itself includes
the Perl FAQ. If everything is pro-Perl-y installed on your system, the
FAQ will be stored alongside the rest of Perl's documentation, and one
of these commands (or your local equivalents) should let you read the FAQ.

    perldoc perlfaq
    man perlfaq

If a recent version of Perl is not properly installed on your system,
you should ask your system administrator or local expert to help. If you
find that a recent Perl distribution is lacking the FAQ or other important
documentation, be sure to complain to that distribution's author.

If you have a web connection, the first and foremost source for all things
Perl, including the FAQ, is the Comprehensive Perl Archive Network (CPAN).
CPAN also includes the Perl source code, pre-compiled binaries for many
platforms, and a large collection of freely usable modules, among its
403_662_481 bytes (give or take a little) of super-cool (give or take
a little) Perl resources.

    http://cpan.perl.org/
    http://www.perl.com/CPAN/
    http://cpan.perl.org/doc/FAQs/FAQ/html/perlfaq.html
    http://www.perl.com/CPAN/doc/FAQs/FAQ/html/perlfaq.html

You may wish or need to access CPAN via anonymous FTP. (Within CPAN,
you will find the FAQ in the /doc/FAQs/FAQ directory. If none of these
selected FTP sites is especially good for you, a full list of CPAN sites
is in the SITES file within CPAN.)

    California     ftp://ftp.cdrom.com/pub/perl/CPAN/
    Texas          ftp://ftp.metronet.com/pub/perl/
    South Africa   ftp://ftp.is.co.za/programming/perl/CPAN/
    Japan          ftp://ftp.dti.ad.jp/pub/lang/CPAN/
    Australia      ftp://cpan.topend.com.au/pub/CPAN/
    Netherlands    ftp://ftp.cs.ruu.nl/pub/PERL/CPAN/
    Switzerland    ftp://sunsite.cnlab-switch.ch/mirror/CPAN/
    Chile          ftp://ftp.ing.puc.cl/pub/unix/perl/CPAN/

If you have no connection to the Internet at all (so sad!) you may wish
to purchase one of the commercial Perl distributions on CD-Rom or other
media. Your local bookstore should be able to help you to find one.
Another possibility is to use one of the FTP-via-email services; for
more information on doing that, send mail to <mail-server@rtfm.mit.edu>
(not to me!) with these lines in the body of the message, flush left:

    setdir usenet-by-group/news.announce.newusers
    send Anonymous_FTP:_Frequently_Asked_Questions_(FAQ)_List

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 

Comments and suggestions on the contents of this document
are always welcome. Please send them to the author at
<pfaq&finding*comments*@redcat.com>. Of course, comments on
the docs and FAQs mentioned here should go to their respective
maintainers.

Have fun with Perl!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/


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

Date: 26 May 1998 15:01:18 GMT
From: lindahl@pbm.com (Greg Lindahl)
Subject: Re: An unwelcome and undeserved slap
Message-Id: <6kelfu$aaa@news3.newsguy.com>

egkioule@u.washington.edu (E. Gkioulekas) writes:

> I have also contributed both to Perl, Tcl and FSF-related stuff. This is why
> I don't want to see the leaders of these communities to think and speak
> in territorial terms. There is no war between our communities, and I hope
> everyone realizes that no matter what Tom or anyone says, the _communities_ 
> should not allow such a war to begin.

I agree. This is a very good idea, and we should all practice it.

-- g


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

Date: 26 May 1998 14:56:19 GMT
From: lindahl@rt.com (Greg Lindahl)
Subject: Re: An unwelcome and undeserved slap
Message-Id: <6kel6j$aaa@news3.newsguy.com>

rodgerd@orwell.rm.gen.nz (Rodger Donaldson) writes:

> You really want *another* thread on this?

No. The entire "GNU Linux" thread was extremely non-constructive, so
everyone really should avoid it like the plague.

-- g


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

Date: 26 May 1998 18:47:12 +0300
From: <jari.aalto@poboxes.com> (Jari Aalto+mail.perl)
Subject: Announce: Emacs TinyPerl.el module (POD mode)
Message-Id: <tbwwb9ghkv.fsf@blue.sea.net>


    This is first announcement of a new Emacs package
    If you don't know what is Emacs, check 
    
        http://www.gnu.org/software/emacs/emacs.html

    More links on the page

        ftp://cs.uta.fi/pub/ssjaaa/elisp.html
        
    I decided to gather my private POD helper functions under one
    common module called tinyperl.el, with this you can browse
    the POD documentation very easily from inside your Emacs.

    Any future usefull Emacs lisp function relating to perl 
    will appear in this module.

    jari

Packages needed ftp://cs.uta.fi/pub/ssjaaa/

    [package]    

    tinyperl.el

        The core

    [support modules]

    tinyurl.el

        An additional package tinyurl.el is also need to enable
        jumping to pod page references like "See perlfunc manpage".
        This package also handles many different URL pointers, including
        programming code (lisp Perl C/C++ currently) and regular
        ftp:// and http:// pointers.

    tinycompile.el      

        This module is not needed if you don't use "grep" feature.
    
    [lisp libraries]

    tinylibb.el     
    tinylibm.el     
    tinylib.el

TinyPerl package description
        
    The POD pages are coloured with font-lock.

    Turning on tiperl-mode gives you commands:

        C-c ' f         tiperl-pod-find-file
        C-c ' P         tiperl-pod-by-module
        C-c ' p         tiperl-pod-by-manpage

        C-c ' m         tiperl-module-find-file
        C-c ' k         tiperl-pod-kill-buffers
        C-c ' g         tiperl-pod-grep


    * tiperl-pod-find-file

        run pod2text over file pointed by the function

    * tiperl-pod-by-module

        Complete the installed Perl modules, like "Getopt::Long"
        and run pod2text.

    * tiperl-pod-by-manpage

        Complete Perl manual pages, like "perlfunc.pod" and run
        pod2text.

    * tiperl-pod-kill-buffers

        Kill all *pod* buffers from Emacs

    * tiperl-module-find-file

        Complete installed module in @INC and load the file into Emacs.
        Like giving name "Getopt::Long"

    * tiperl-pod-grep

        Grep regexp from all Perl POD manual pages. Andwers to
        your question "Is this discussed in FAQ'.


    jari


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

Date: Tue, 26 May 1998 12:52:52 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: case insensitive checks, a=b
Message-Id: <comdog-ya02408000R2605981252520001@news.panix.com>
Keywords: from just another new york perl hacker

In article <3569881F.B73E1885@matrox.com>, Ala Qumsieh <aqumsieh@matrox.com> posted:

>Craig Berry wrote:
>
>> Ala Qumsieh (aqumsieh@matrox.com) wrote:
>> : You might also want to use regexps like so:
>> :
>> : if ($a =~ /$b/i) {
>> : # do your stuff
>> : }
>>
>> Better make that /^\Q$b\E$/i .  Otherwise $a = 'abcde' will compare
>> 'equal' to both $b = 'cd' and and $b = 'q?', for example.
>
>if ($a =~ /^\Q$b\E$/i) {
>    #do your stuff
>}

it gets even more complicated if there is a trailing newline.  why
use a complicated regexp for a simple case insensitive comparison?

ponder the output from this script:


   #!/usr/bin/perl
   
   $a1 = 'just another new york perl hacker';
   $a2 = "just another new york perl hacker\n";
   
   $b  = 'just another new york Perl hacker';
   
   print "a1 matches\n" 
      if $a1 =~ m/^\Q$b\E$/i;
   
   print "a2 matches without negative lookahead\n" 
      if $a2 =~ m/^\Q$b\E$/i;
   
   print "a2 matches with negative lookahead\n" 
      if $a2 =~ m/^\Q$b\E(?!\n)$/i;
      
   print "a1 matches with lc\n" 
      if lc $a1 eq lc $b;
   
   print "a2 matches with lc\n" 
      if lc $a2 eq lc $b;

   __END__

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers T-shirts! <URL:http://www.pm.org/tshirts.html>


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

Date: 26 May 1998 11:09:43 -0400
From: Craig Burley <burley@tweedledumb.cygnus.com>
Subject: Re: Clearly define "free software"
Message-Id: <y6solxkr0n.fsf@tweedledumb.cygnus.com>

les@MCS.COM (Leslie Mikesell) writes:

> In article <3569ac1f.0@news.ivm.net>,  <Klaus.Schilling@home.ivm.de> wrote:
> 
> >Irrelevant. Anyone who has not been spoilt by multimedia junk and evil 
> >proprietarists like M$, Lotu$, Apple, Oracle, ... , and is not a 
> >fool or teenie, can use the best software of all times, the GNU Emacs on a
> >vt100, instead of all the wysiwyg junk. 
> 
> How about a cave wall and some colored berries for pigment?

I'm not willing to share my cave and berries with just anyone who asks.

I *am* willing to share "my" copy of GNU Emacs with the rest of the
world.

After all, the copying costs of software are somewhat lower than for
caves, or even cave paintings.

;-)

(No, I don't think I agree entirely with Klaus.  I do think the
GUIs offered by the hide-the-source communities are pretty, but
pretty bad, in terms of being usable.  As an interface-designer-
wannabe who'd prefer writing GPL'd software anyway, I, too, probably
suffer somewhat from "NIH", but I have a computer-programmer friend
who is blind, as just one example of why I'd *also* like to make
sure the next "billion lines of code" I write are to an OS user-
interface paradigm that is at least somewhat well-thought-out vis-a-vis
the rest of humanity.)
-- 

"Practice random senselessness and act kind of beautiful."
James Craig Burley, Software Craftsperson    burley@gnu.org


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

Date: 26 May 1998 18:59:32 +0200
From: Ketil Z Malde <ketil@ii.uib.no>
Subject: Re: Clearly define "free software"
Message-Id: <KETIL-87hg2dm0i3.fsf@tosca.infotek.no>

les@MCS.COM (Leslie Mikesell) writes:

> >Intellectual property is theft from the collective consciousness, thus evil.

> Does that mean you believe that all ideas are 'discovered', as opposed
> to being created by individual effort?  

Alternate interpretation: since using an idea doesn't hinder other's use 
of it, ideas can treated like a common good, like air, which should be
freely available to anybody.

~kzm
-- 
If I haven't seen further, it is by standing in the footprints of giants


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

Date: Tue, 26 May 1998 11:34:21 -0500
From: wwilliam@cisco.com (Wade Williams)
Subject: Efficient Regex's
Message-Id: <wwilliam-2605981134210001@10.0.0.2>

Ok, don't kill me to badly on this one. :)

I've got a program that needs to read through a 2.8 MB file every 5
minutes. The file looks like:

ID,wade
fired,54000
hits,23000

etc - record after record.  While the fields are static, the length of
each field is not - i.e. fired could be 40 instead of 54000.

Naturally, I did something like

while (<MYFILE>)
{
   /^ID,(\d+)$/  && do
   {
      $id=$1;
      last;
   };

   /^fired,(\d+)$/  && do
   {
      $myhash{"$id"}{fired}=$1;
      last;
   };

   /^hits,(\d+)$/ && do
   {
      $myhash{"$id"}{hits}=$1;
      last;
   };
}

This is just snippet of the real code.  In reality, there's probably 40 or
so Regex's in the while loop.

What I'm finding, both through experience and research is that this may be
the most inefficient method possible to do this.  Currently, to read the
2.8 Mb file and create the large hash, takes 4:15.

Obviously, one reason for this is the linear nature of my loop.  If it's
the 39th regex that will match, my while loop forces it to try 38 other
regex's first.

So, my question is, how can I speed this up?  Yes, I've read the FAQ
section on matcing a large number of regex's, but quite frankly, it didn't
make a whole heck of a lot of sense to me.

Can someone explain in plain English how I should go about speeding this
up?  Or perhaps explain in plain English the example in the FAQ?

Thanks,

Wade

-- 
 --------------------------------------------------------------------------
 Wade Williams                      Fly WarBirds! (Mac or PC)
 Systems Engineer, CCIE #3373          http://www.icigames.com/warbirds
 Cisco Systems, Inc.                        
 Brentwood, TN                      
 615-221-2918                              
 wwilliam@cisco.com    
 --------------------------------------------------------------------------


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

Date: Tue, 26 May 1998 16:43:05 +0100
From: Andy Armstrong <andy@wonderworks.co.uk>
Subject: Re: Getting hex codes from string
Message-Id: <QnKp9CAJMua1Ewc0@wndrwrks.demon.co.uk>

In article <895845873.27136.0.nnrp-11.c246a788@news.demon.co.uk>, Simon
Fairey <sfairey@adc.metrica.co.uk> writes
>  printf "%02x", 'a'

The format specifier %02x wants a number and the string 'a' has the
numeric value 0 'cos it contains no digits.

-- 
** Don't CC any follow-ups to me - I *do* read the newsgroups I post to **
Andy Armstrong, Wonderworks, http://www.wonderworks.co.uk


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

Date: Tue, 26 May 1998 09:51:41 -0600
From: "Oban Lambie" <oban@brownrice.com>
Subject: Getting rid of carriage returns
Message-Id: <6keou9$2nf$1@sloth.swcp.com>


Little help please...

I'm using numerous perl scripts that write to straight line text file
databases and I don't know how to get rid of carriage returns when they are
submitted via a web form.

$submittedText  =~ s/\n/\<br\>/g;

Above substitution line doesn't do it.

Eternal gratitude if someone can help me.






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

Date: 26 May 1998 18:03:51 +0200
From: Jan Vroonhof <vroonhof@frege.math.ethz.ch>
Subject: Re: GNU attacks on the open software community
Message-Id: <by7m39j9y0.fsf@bolzano.math.ethz.ch>

abigail@fnx.com (Abigail) writes:

> Could you point out why there is no comment about non-free books for
> the other items?

As I didn't write the document, no I cannot. Neither can I point
point out why the perl item is above the X books.

Does it matter that much?

Jan


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

Date: 26 May 1998 09:31:53 -0700
From: tzs@halcyon.com (Tim Smith)
Subject: Re: GNU attacks on the open software community
Message-Id: <6keqpp$l4g$1@halcyon.com>

Chris Nandor <pudge@pobox.com> wrote:
>No, I am not.  What I did not do is properly tie it in to the legal
>principle involved here, which is market effect (well, I did not tie it in
>the first time I mentioned this, though I did in later posts).
>
>  A.  Tom allows distribution on thousands of CD-ROMs
>  B.  A new CD-ROM comes out with perlfaq, Tom tries to stop it
>  C.  Tom has to prove that this new CD impacts the potential market, which I 
>      cannot see how he could do
>
>Tom has allowed this market to change, knowingly.  He cannot, therefore,
>come back and say that continued infringement affects his market, so the
>CD maker claims fair use and that's the end of it.

That's hardly the end of it.  Market affect is only one of the four
factors in determining fair use.  True, it is usually the most
important, but in a case where the use is of the entire work, and is
reproductive rather than productive, and is commercial and public rather
than private and non-commercial, I don't think fair use will be found by
the courts.

--Tim Smith


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

Date: 26 May 1998 16:09:31 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: GPL documentation == unspeakable evil
Message-Id: <6kepfr$svu$1@client3.news.psi.net>

Stuart Cooper (stuartc@ind.tansu.com.au) wrote on MDCCXXVIII September
MCMXCIII in <URL: news:yeohg2fytx6.fsf@kudu.ind.tansu.com.au>:
++ 
++ The FSF is to be applauded for trying to produce free (in their sense)
++ documentation for Perl. The O'Reilly Perl books, excellent as they are,
++ are not free- I can't photocopy them for friends, download them from the
++ web etc. etc. If the O'Reilly books are indispensable documentation for
++ Perl as a whole, than Perl as a whole is not free (in the GNU and the
++ monetary sense).

That is true. But the condition ("the O'Reilly books are indispensable
documentation for Perl as a whole") is not true. Even the perlfaq which
has Tom's license is not indispensable, as it doesn't document Perl
directly. The indispensable manuals (like perlfunc, perlop, perlsyn,
etc) have the same license as Perl itself. The Artistic license, or,
if you wish, the more restrictive GPL.



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


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

Date: 26 May 1998 16:13:22 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: GPL documentation == unspeakable evil
Message-Id: <6kepn2$svu$2@client3.news.psi.net>

Stuart Cooper (stuartc@ind.tansu.com.au) wrote on MDCCXXVIII September
MCMXCIII in <URL: news:yeopvh3ug4q.fsf@kudu.ind.tansu.com.au>:
++ 
++ Here's what it says in the GNU task list:
++ (www.fsf.org/prep/tasks_3.html)
++ ================================================================
++   A good free manual for Perl. 
++   (There are proprietary books, but these are no good, because
++      they are being withheld from our community by their owners.) 
++ ================================================================
++ 
++ > That web page and the subsequent commentary offered by their attendant
++ > sycophants constitute nothing short of a veiled yet viscious insult
++ > hurled at those of us who've worked incredibly hard for more a decade
++ > to produce the free 1,000 page book that *is* the Perl documentation.
++ > They can play their games of petty sophistry all they like, but the
++ > bottom line remains that they have callously denigrated the efforts of
++ > the Perl development community--a community, I shall note, in which
++ > they have never played any role.  It is not ``GNU Perl'', you know.
++ 
++ As I read the web page; they are asking for a GNU-free manual. I imagine
++ they are thinking something in the vein of the GNU Emacs manual, or the
++ GNU Emacs Lisp reference manual. Something more akin to 'Programming Perl',
++ containing all the information of the free *.pod pages; but in a book-form.
++ You can order the GNU manuals from the FSF; once you get them you can share
++ them with your friends. 

Is there anything in the license that prevents you from printing out
the manual pages? That will give you a book akin to 'Programming Perl',
with the exception that 'Programming Perl' is out of date, and the
manuals aren't.




Abigail
-- 
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'


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

Date: Tue, 26 May 1998 11:43:37 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Handling Dates Help Please
Message-Id: <356AE329.2F2A68A7@matrox.com>

johnny99@sydney.dialix.oz.au wrote:

> Today is 26/5/98, so the "today" script would take you to a page called
> 98-05-26.html -- but what I'd like to do is enable browsers to go backward and
> forward with buttons on the pages marked "Next Day" and "Previous Day".
>
> I know how to do this by adding/subtracting from the 26 and making it 27 or 25
> etc., but what happens when I get to 1 June? I'll end up with Previous Day
> being the zero of June and so on, won't I?

# Previous day
$day--;
if ($day == 0) {
    $month--;
    # set $day to either 30 or 31 (maybe even 28/29 in the case of February)
depending on month
}

Was that hard to figure out?

--
Ala Qumsieh             |  No .. not just another
ASIC Design Engineer    |  Perl Hacker!!!!!
Matrox Graphics Inc.    |
Montreal, Quebec        |  (Not yet!)





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

Date: Tue, 26 May 1998 11:22:59 -0400
From: Shawn Porter <sjp6683@rit.edu>
Subject: new to OO Perl
Message-Id: <356ADE53.C71CF59C@bigfoot.com>

This is a multi-part message in MIME format.
--------------4A0E6E10892D1F1E82EE0AA8
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I've been writing Perl for a little over a year now, but I'm just now
learning how to write my own classes.  My first try is working
moderately well, but I need some help with it.  I'm creating an array of
objects but the data (particulary %props) from the first one carries
over to the second one and that to the third one, and so on.  I think
I'm using 'package' correctly.  The hash (%props) is being declared
local (my %props;) in the class file.  I don't know what I'm doing
wrong.  I'm attaching the code.  Any help would be greatly appreciated.

Shawn Porter
--------------4A0E6E10892D1F1E82EE0AA8
Content-Type: application/x-perl; name="translate.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="translate.pl"

#!/usr/local/bin/perl -w

use COBPerson;

@files = <./faculty/*.txt ./staff/*.txt>;

$i = 0;
foreach $filename (@files)
{
	$people[$i] = new COBPerson;
	$people[$i]->read($filename);
	$people[$i]->write();
	$i++;
}

--------------4A0E6E10892D1F1E82EE0AA8
Content-Type: text/plain; charset=us-ascii; name="COBPerson.pm"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="COBPerson.pm"

package COBPerson;
use Carp;

my %props;
my @format;

sub new 
{
	my $self = { };
	bless $self;
	print "creating: $i: $props{'email'}\n";
	$self->loadformat();
	return $self;
}

#
# read the source
#
sub read 
{
        my $self = shift;
	unless(ref $self) 
	{
		croak "bad method call";
	}
 	my $filename = shift;
	my $setting;

	open(SOURCE, $filename) || croak("Error opening $filename: $!");
	while(<SOURCE>) 
	{
		if(/^\$/)
		{	
			chomp;
			/^\$(.*)/;
			$setting = $1;
		}
		else
		{
			$props{"$setting"} .= $_;
		}
	}
	close(SOURCE);

	$props{'filename'} = $filename;

	$props{'outfile'} = $filename;
	$props{'outfile'} =~ tr/A-Z/a-z/;
	$props{'outfile'} =~ s/^.*?(\w*)\/(\w*)\.txt/..\/$1\/$2\.html/i;

	$props{'image'} = $filename;
	$props{'image'} =~ tr/A-Z/a-z/;
	$props{'image'} =~ s/(\w*)\.txt/images\/$1\.jpg/i;

	$props{'email'} = "<p><a href=\"mailto:$props{'email'}\">$props{'email'}</a>\n" if($props{'email'});
	$props{'url'} = "<p><a href=\"$props{'url'}\">$props{'url'}</a>\n" if($props{'url'});
	$props{'phone'} = "<p>$props{'phone'}\n";
	$props{'office'} = "<p>$props{'office'}\n";

	return 1;
}

#
# read the format
#
sub loadformat 
{
        my $self = shift;
	unless(ref $self) 
	{
		croak "bad method call";
	}
	my $format;

	open(FORMAT, "format.html") || die("Error opening file: $!\n");
	while(<FORMAT>)
	{
		$format .= $_;
	}
	@format = split(/\n/, $format);
	close(FORMAT);

	return 1;
}

#
# create output
#
sub write 
{
        my $self = shift;
	unless(ref $self) 
	{
		croak "bad method call";
	}
	my $subst;
	
	open(OUT, ">$props{'outfile'}");
	foreach (@format)
	{
		if(/\<\$(\w*)\>/)
		{
			$subst = '';
			$subst = $props{"$1"};
			s/\<\$(\w*)\>/$subst/g;
		}
		print OUT "$_\n";
	}
	close(OUT);

	return 1;
}

1;

--------------4A0E6E10892D1F1E82EE0AA8--



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

Date: Tue, 26 May 1998 12:42:37 -0400
From: Shawn Porter <two_step@bigfoot.com>
Subject: Re: new to OO Perl
Message-Id: <356AF0FD.7C0F7FB5@bigfoot.com>

This is a multi-part message in MIME format.
--------------A1F9640A7E3DC9D63B37C0EA
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Forget it, I decided to just do it the old-fashioned way...

Shawn Porter wrote:
> I've been writing Perl for a little over a year now, but I'm just now
> learning how to write my own classes.  My first try is working
> moderately well, but I need some help with it.  I'm creating an array of
> objects but the data (particulary %props) from the first one carries
> over to the second one and that to the third one, and so on.  I think
> I'm using 'package' correctly.  The hash (%props) is being declared
> local (my %props;) in the class file.  I don't know what I'm doing
> wrong.  I'm attaching the code.  Any help would be greatly appreciated.

Shawn Porter
--------------A1F9640A7E3DC9D63B37C0EA
Content-Type: application/x-perl; name="kludge.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="kludge.pl"

#!/usr/local/bin/perl -w

@files = <./faculty/*.txt ./staff/*.txt>;

$i = 0;
@format = loadformat('format.html');

foreach (@files)
{
	my %props;
	%props = readtemplate($_);
	writehtml(\@format, \%props);
	$i++;
}

#
# read the source
#
sub readtemplate
{
 	my $filename = shift;
	my %props;
	my $setting;

	open(SOURCE, $filename) || die("Error opening $filename: $!");
	while(<SOURCE>) 
	{
		if(/^\$/)
		{	
			chomp;
			/^\$(.*)/;
			$setting = $1;
		}
		else
		{
			$props{"$setting"} .= $_;
		}
	}
	close(SOURCE);

	$props{'filename'} = $filename;

	$props{'outfile'} = $filename;
	$props{'outfile'} =~ tr/A-Z/a-z/;
	$props{'outfile'} =~ s/^.*?(\w*)\/(\w*)\.txt/..\/$1\/$2\.html/i;

	$props{'image'} = $filename;
	$props{'image'} =~ tr/A-Z/a-z/;
	$props{'image'} =~ s/(\w*)\.txt/images\/$1\.jpg/i;

	$props{'email'} = "<p><a href=\"mailto:$props{'email'}\">$props{'email'}</a>\n" if($props{'email'});
	$props{'url'} = "<p><a href=\"$props{'url'}\">$props{'url'}</a>\n" if($props{'url'});
	$props{'phone'} = "<p>$props{'phone'}\n";
	$props{'office'} = "<p>$props{'office'}\n";

	return %props;
}

#
# read the format
#
sub loadformat 
{
	my $filename = shift;
	my $format;

	open(FORMAT, $filename) || die("Error opening $filename: $!\n");
	while(<FORMAT>)
	{
		$format .= $_;
	}
	@format = split(/\n/, $format);
	close(FORMAT);

	return @format;
}

#
# create output
#
sub writehtml
{
	my @format = @{$_[0]};
	my %props = %{$_[1]};
	my $subst;
	
	open(OUT, ">$props{'outfile'}");
	foreach (@format)
	{
		if(/\<\$(\w*)\>/)
		{
			$subst = '';
			$subst = $props{"$1"};
			s/\<\$(\w*)\>/$subst/g;
		}
		print OUT "$_\n";
	}
	close(OUT);

	return 1;
}

--------------A1F9640A7E3DC9D63B37C0EA--



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

Date: Tue, 26 May 1998 20:03:48 +0200
From: David Carter <david@solbors.no>
Subject: Re: Problem reading large files under Win95
Message-Id: <356B0404.6602BC09@solbors.no>

Hi,

> I have a problem with big files under  Win95.
> 
> The problem is that I can read only the first 4-5 Mb from the file (total length is 25 Mb).
> It works well by splitting the file in some little files of 4 Mb.
> 
> Is this a Perl limitation ? Or Win95 ? On Perl under Win95 ?
> Had anybody else this problem ? A solution ?

FDISK is what you need.


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

Date: Tue, 26 May 1998 11:36:07 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Problem with Renaming a file to a new name that's specified by a variable
Message-Id: <356AE167.C960DB@matrox.com>

Arthur Dardia wrote:

> In my CGI problem, I have the following code:
>
> rename "../htdocs/toast/matches/temp.html",
> "../htdocs/toast/matches/'.$in{filename}.'";
>

Well. ... assuming $in{filename} = "file1.txt" ... the second argument
of the rename function becomes:

 ../htdocs/toast/matches/'.file1.txt.'

which is definately not what you want!

> Why doesn't that work?  I tried:
>
> rename "../htdocs/toast/matches/temp.html",
> '../htdocs/toast/matches/'.$in{filename}.'';

That seems fine to me .. I actually tried it and it worked for me!But,
remembering that double quotes cause variable interpolation, you can do
something like this:

rename "../htdocs/toast/matches/temp.html",
"../htdocs/toast/matches/$in{filename}";

That should work.

>
>
> also, and neither statement works...please help me.
>
>                     Severely stumped,
>                     Arthur Dardia

 Nice one ;-)

--
Ala Qumsieh             |  No .. not just another
ASIC Design Engineer    |  Perl Hacker!!!!!
Matrox Graphics Inc.    |
Montreal, Quebec        |  (Not yet!)





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

Date: Tue, 26 May 1998 09:50:54 -0700
From: "matthew d. p. k. lanier" <lanier@shell6.ba.best.com>
Subject: reference to tom c's filehandles tutorial
Message-Id: <Pine.BSF.3.96.980526094829.6765E-100000@shell6.ba.best.com>

hello all-

about 3 weeks ago tom c posted an enlightening tutorial on using globs to
pass filehandles around in a much quicker way than using the FileHandle
module.

if anyone has a copy of that, could you please reforward it to me, or
repost it?

i'm sorry for the wasted bandwidth.


matthew d. p. k. lanier / professional hugger and empath / matt@lanier.org
- i web, therefore i am / matt@saturn5.com - i read too many mailing lists 





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

Date: Tue, 26 May 1998 12:19:00 -0400
From: Jonathan Epstein <Jonathan_Epstein@nih.gov>
Subject: utility which can POST web queries
Message-Id: <356AEB74.6AA8F988@nih.gov>

I am currently using url_get.pl to perform remote web processing in a
CGI script.
  http://dan.hcf.jhu.edu/ftp/Perl/
Unfortunately, it is only capable of handling the get protocol, and many
of remote sites which I'm using require the post protocol.  Which
utility should I using (preferably one which is commonly used by
others)?

- Jonathan




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

Date: Tue, 26 May 1998 16:41:15 GMT
From: jdporter@min.net (John Porter)
Subject: Re: while, each & assoc array
Message-Id: <MPG.fd4bc5736aeed059896eb@news.min.net>

On 26 May 1998 13:00:36 +0300,
in article <tb1zthic6z.fsf@blue.sea.net>,
jari.aalto@poboxes.com (jari.aalto@poboxes.com) wrote:
> 
>     if ( this and that and more on this condition last to the end ) {
>        code 
>        code
>        code
>     }
> 
> To me, the brace to the right is catasrophic :-) It's much more visually
> pleasent to read it like above. Code is also placed "even" when 
> braces surround it.
> 
>     if ( this and thant and more on this condition last to the end )
>     {           
>        code 
>        code
>        code
>     }

I like readable code too, which is why I usually do something like this:

    if ( 
          this
       and
          that
       and
          more on this condition last to the end
    ) {
       code 
       code
       code
    }

In long expressions, parens can be aligned like braces too,
as in this example.

John Porter


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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 V8 Issue 2725
**************************************

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