[16325] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3737 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 18 18:05:45 2000

Date: Tue, 18 Jul 2000 15:05:20 -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: <963957920-v9-i3737@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 18 Jul 2000     Volume: 9 Number: 3737

Today's topics:
        "Missing coprocessor" ("Ian.")
    Re: [NEW-B] Array comparisement (Abigail)
    Re: [NEW-B] Array comparisement <?@?.?>
        ANNOUNCE: Net::AOLIM (new name) Module released (Riad S. Wahby)
        Any Perl experts in Austin, TX? <candy.taylor@whitakercos.com>
    Re: Attatchments from client (Cameron Laird)
    Re: ATTENTION PERL MACHOES!!!!!!!!!!!!!!! (Ben Coleman)
    Re: ATTENTION PERL MACHOES!!!!!!!!!!!!!!! (Randal L. Schwartz)
    Re: automating ms exchange server 5.5 ops... (Abigail)
        Clsid Number Changes <kennylim@techie.com>
    Re: comparing two arrays for similarities (Andrew J. Perrin)
        crypt for Perl 4.0 <Strongman28@hotmail.com>
        Curses v1.05 now available <William_Setzer@ncsu.edu>
        file permissions pooh23@my-deja.com
    Re: file permissions <lauren_smith13@hotmail.com>
        GUI Module <drzoso@my-deja.com>
    Re: GUI Module <lauren_smith13@hotmail.com>
        HELP: Pattern Match <heinsius@u.washington.edu>
    Re: HELP: Pattern Match (Cameron Kennedy)
    Re: HELP: Pattern Match <lauren_smith13@hotmail.com>
        How can I make variables global when I define them with <ewald@electronicfrontiers.com>
    Re: How can I make variables global when I define them  <lauren_smith13@hotmail.com>
    Re: How can I make variables global when I define them  <mike@crusaders.no>
    Re: How do you pass objects to a subroutine? <j_f9NOj_SPAM@yahoo.com.invalid>
    Re: how to convert "1.2.3.10" to "01020310"? (Abigail)
    Re: how to convert "1.2.3.10" to "01020310"? (Craig Berry)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 18 Jul 2000 20:47:51 +0000 (UTC)
From: ian.freedomnet@softhome.net ("Ian.")
Subject: "Missing coprocessor"
Message-Id: <20000718.2047.999snz@softhome.net>

Hi,

Ive just started looking into Perl. I collected a DOS version of
Perl 5 from ftp.demon.co.uk. Im ok with the DPMI bit but when
I try to run the .exe on my 386, its complaining about the lack
of a coprocessor. I know there are some 387 emulators around
somewhere but could someone please tell me the right one
to use with this Perl. I did try just making wemu387.386 from the
Perl 4 package available to it but it didnt do anything with it.

-- 
Bye now,
        Ian.


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

Date: 18 Jul 2000 16:04:45 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: [NEW-B] Array comparisement
Message-Id: <slrn8n9f43.3do.abigail@alexandra.delanet.com>

Kliffoth (?@?.?) wrote on MMDXIII September MCMXCIII in
<URL:news:vp%c5.408132$k22.1816323@flipper>:
|| Lets say we got two arrays, we don't know the number of variables in them. I
|| need to compare the arrays; if ALL the variables in the first array are also
|| in the second array (and this second array may contain a lot more than just
|| the variables in the first array) it should do some stuff. If not, it should
|| die. I've been reading the perl-documentory for over an hour, and just can't
|| find it. If the answer is there, please tell me where it is, and sorry to
|| have waisted your time. Any help would be appreciated.
|| Thanx anyway, for taking the time to read posts of a newbie like me, I
|| appreciate it, alot!


    @hash {@array1} = ();
    delete @hash {@array2};
    unless (keys %hash) {
        # Everything in first array is in second array.
    }


Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
 .qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
 .qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'


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

Date: Tue, 18 Jul 2000 20:33:17 GMT
From: "Kliffoth" <?@?.?>
Subject: Re: [NEW-B] Array comparisement
Message-Id: <ha3d5.410154$k22.1833198@flipper>

Thanx a billion, I ended up having a triple loop wich did absolutely
nothing, and on the urge of slamming my face on the wall...




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

Date: 17 Jul 2000 16:46:55 GMT
From: rsw@mit.edu (Riad S. Wahby)
Subject: ANNOUNCE: Net::AOLIM (new name) Module released
Message-Id: <qX1d5.30065$8V2.917781@news-east.usenetserver.com>
Keywords: Net::AOLIM perl module AOL Instant Messenger


Hello,

The module Net::AOLIM is now available for download from CPAN.
Previously announced as Net::InstantMessenger, this module allows
programmers to conveniently access the AOL Instant Messenging service
in an Object-oriented manner from a perl script.

The current version, 0.12, is fully documented and fairly well-tested,
and is probably ready for version 1.0.  Please download and test!
E-mail me with any questions or bugs.

Riad Wahby
rswNOSPAM@mit.edu
droidNOSPAM@media.mit.edu

5105




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

Date: Tue, 18 Jul 2000 18:56:50 GMT
From: Whitaker IT <candy.taylor@whitakercos.com>
Subject: Any Perl experts in Austin, TX?
Message-Id: <8l2997$5e7$1@nnrp1.deja.com>

Our direct client in Austin, TX is looking for a Perl/Linux developer
and C/C++ would be very helpful.  They need someone to work on Perl and
Perl modules, doing strictly programming work, for about 8 weeks at
first.  There is a high possibility of another 2 months extension at
the end of this project.  They need someone who can use an OO approach
with 2-3 years experience.  Other flavors of Unix would work as well.
Perl is a mandatory skill and focus.

Client is a “FREE wireless communication service for receiving your
information anytime, anywhere. This service utilizes the text messaging
capabilities of digital pagers and other wireless devices, including
digital phones, PDAs, etc.)”

We are specifically targeting people with the following skills:
- PERL 5.0, beyond CGI scripting
- Object oriented PERL, using PERL modules
- Experience with SQL databases
- Network programming skills (i.e. developing using sockets)
- Performance tuning

For more information please call:

Candy Taylor
Whitaker Consulting
(800) 933-4883 ext 226
candy.taylor@whitakercos.com


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


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

Date: 18 Jul 2000 15:17:01 -0500
From: claird@starbase.neosoft.com (Cameron Laird)
Subject: Re: Attatchments from client
Message-Id: <8F3E6FFBF0447311.424CCC3C981BDAC2.576CF6E39931FC7E@lp.airnews.net>

In article <39735087.6482C059@muskegon.k12.mi.us>,
 <cpoole@muskegon.k12.mi.us> wrote:
			.
			.
			.
>I have installed Mail::Sender by JENDA and it works well for
>attatchments that reside on the server; however, what if I want to send
>an attatchment from my client workstation?  Does anyone know of the
>command I would use to to send a attatchment from my client workstation
>(i.e. like a MS word file from my PC) or is there another module out
>there which would be better for me to use.
			.
			.
			.
Perl modules happily do their work whether they're
on a server or client.  My guess is that you have a
specific model of operation that I don't yet under-
stand.

Are you working with Web pages, and you want the
ability to specify a way for the browser to generate
an item of e-mail, accompanied by an attachment that
the human client selects?  Is that it?  You're surely
not committing the rather hostile act of attaching 
a file *you* choose from the server; that's generally
regarded as some combination of privacy and security
risk.

If the human client is making the selection, my incli-
nation is to recommend that you do something that
involves the desktop's own e-mail client.  If there's
a compelling reason that's not feasible, we can come
up with a scheme to upload the attachment and mangle
it on the server; that's what would be necessary.
-- 

Cameron Laird <claird@NeoSoft.com>
Business:  http://www.Phaseit.net
Personal:  http://starbase.neosoft.com/~claird/home.html


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

Date: Tue, 18 Jul 2000 20:35:56 GMT
From: oloryn@mindspring.com (Ben Coleman)
Subject: Re: ATTENTION PERL MACHOES!!!!!!!!!!!!!!!
Message-Id: <3974bf87.621589318@news.mindspring.com>

On Fri, 14 Jul 2000 15:02:14 GMT, nvp@spamnothanks.speakeasy.org (NP)
wrote:

>"Ganesha" seems to be refering to "buy Randal a beer nights" that take
>place periodically at various Perl Mongers groups in various
>locations.  IIRC, "buy Randal a beer nights" have been a semi-regular
>occurance for the last couple of years.

Last I knew, Randal hasn't had any alcohol for the past year.

Ben


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

Date: 18 Jul 2000 14:38:20 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: ATTENTION PERL MACHOES!!!!!!!!!!!!!!!
Message-Id: <m1wvij5dbn.fsf@halfdome.holdit.com>

>>>>> "Ben" == Ben Coleman <oloryn@mindspring.com> writes:

Ben> On Fri, 14 Jul 2000 15:02:14 GMT, nvp@spamnothanks.speakeasy.org (NP)
Ben> wrote:

>> "Ganesha" seems to be refering to "buy Randal a beer nights" that take
>> place periodically at various Perl Mongers groups in various
>> locations.  IIRC, "buy Randal a beer nights" have been a semi-regular
>> occurance for the last couple of years.

Ben> Last I knew, Randal hasn't had any alcohol for the past year.

Just coming up on a year.  I promised myself last July 24th that I
would have no alcohol for a year so that I could clearly see what my
relationship to alcohol actually was.  And I haven't had a drink
since, despite the fact that I've been surrounded by the same amount
of consumption.  If only it were that easy with eating, I wouldn't be
20 pounds overweight. :) Given the new clarity in my life, I'm not
going to exactly rush back in to drinking, either.  I'm too old to
wake up in the bathroom, which is what I wanted to stop by taking this
year off.

"Buy Randal a beer night" was at only the very first perl conference
(or maybe the second, whichever one first had online BOF schedules).
I added it as a joke to the online BOF schedule to see how the
schedule system worked, and people were happy to take it seriously.

Anyone who says "take place periodically" about that event is clearly
disconnected from reality, and should be distrusted on at least that
item, and possibly others.

Amazing how a story can change to fit the speaker's (usually) hidden
agenda.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 18 Jul 2000 15:33:07 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: automating ms exchange server 5.5 ops...
Message-Id: <slrn8n9d8q.3do.abigail@alexandra.delanet.com>

psychoholic1213 (psychoholic1213@yahoo.com) wrote on MMDXIII September
MCMXCIII in <URL:news:8l226j$kus$1@news.chatlink.com>:
?? does any know how to add a new mailbox to ms exchange server 5.5, activate
?? it, and send out a welcome email?? any help would be useful...thanx


And your question has exactly what to do with Perl?



Abigail
-- 
map{${+chr}=chr}map{$_=>$_^ord$"}$=+$]..3*$=/2;        
print "$J$u$s$t $a$n$o$t$h$e$r $P$e$r$l $H$a$c$k$e$r\n";


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

Date: Tue, 18 Jul 2000 19:37:11 GMT
From: "Kenny Lim" <kennylim@techie.com>
Subject: Clsid Number Changes
Message-Id: <Hl2d5.1780$in.51331@newsread1.prod.itd.earthlink.net>


Hi All,

My objective here is to be able to perform the following task :

To only generate the clsid once, and then manually alter the last 4 digits
of the first batch of the clsid given. (The 4 digits will be incremented
sequentially)
[Please see Example below]

The reason to do this is to help better manage/identify all the clsid id
given specific to the product versioning.

Example :

(a) Given this clsid number generated from GuidGen.exe
{ADBE2CC0-5CD5-11D4-85DE-00105AE3A355}

(b) Get the first batch of the clsid which is "ADBE2CC0"

Problem :

(c) Manually increment "2CCO" ensuring that there would be no duplication
occurs during the generation. (ie. loop 10000 time)

ie. 0001
ie. 5101 and etc

I was given this theory to resolve the duplicate problem, but this is not my
field of expertise
and I am not sure that I would like to share with you guys.

if N > 8  then my_increment = -1
else my_increment = 1

Please let me know if you need more explicit information. Thanks All.

Any advise would be greatly appreciated.

Thanks All in advance.

Kenny-





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

Date: 18 Jul 2000 15:08:10 -0400
From: aperrin@socrates.berkeley.edu (Andrew J. Perrin)
Subject: Re: comparing two arrays for similarities
Message-Id: <u8zuz45ph.fsf@socrates.berkeley.edu>

djspillers@midsouth.ualr.edu.bbs@openbazaar.net (daniel spillers) writes:

> [snip] 
> I need to compare @bar (the "newly submitted" fields) to @foo (the "old"
> fields) to result in a list of only those fields which are in @foo but
> at the same time NOT in @bar.

perldoc perlfaq4

  How do I compute the difference of two arrays?  How do I compute the intersection of two arrays?

            Use a hash. Here's code to do both and more. It assumes
            that each element is unique in a given array:

                @union = @intersection = @difference = ();
                %count = ();
                foreach $element (@array1, @array2) { $count{$element}++ }
                foreach $element (keys %count) {
                    push @union, $element;
                    push @{ $count{$element} > 1 ? \@intersection : \@difference}, $element;
                }


In this case, you might want something like this UNTESTED code, which
assumes (among other things) that all entries in @foo are unique:

$inbar{$_} = 1 for @bar;
foreach (@foo) {
	push (@newfields, $_) unless exists $inbar{$_};
}


-- 
--------------------------------------------------------------
Andrew J. Perrin,  Ph.D.  Candidate,  Sociology,  UC  Berkeley
Consulting:     Solaris-Linux-NT-Samba-Perl-MS Access-Postgres
aperrin@socs.berkeley.edu - http://demog.berkeley.edu/~aperrin
--------------------------------------------------------------


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

Date: Tue, 18 Jul 2000 13:42:12 -0500
From: default <Strongman28@hotmail.com>
Subject: crypt for Perl 4.0
Message-Id: <3974A503.B4D96896@hotmail.com>

Does Perl v4.0.1.8 have a crypt or something that will encrypt text?

Thanks,

 ...Shawn



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

Date: 16 Jul 2000 18:40:01 -0400
From: William P Setzer <William_Setzer@ncsu.edu>
Subject: Curses v1.05 now available
Message-Id: <iX1d5.30063$8V2.917360@news-east.usenetserver.com>

The Curses extension, v1.05 for perl is now available.  The README
follows.  Enjoy!


William
             The Curses extension to perl v5
                       Version 1.05


	 Copyright (c) 1994-2000  William Setzer
                   All rights reserved.

    This program is free software; you can redistribute it and/or modify
    it under the same terms as perl, specifically:

        a) the GNU General Public License as published by the Free
        Software Foundation; either version 1, or (at your option) any
        later version, or

        b) the "Artistic License" which comes with this Kit.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    Artistic License for more details. 

    You should have received a copy of the Artistic License with this
    Kit, in the file named "Artistic".  If not, I'll be glad to provide one.

    You should also have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

This is a dynamic loadable curses module for perl.  You can get this
package at any CPAN archive.

Please see the INSTALL document for how to install it on your system,
the Curses pod (located at the end of "Curses.pm") for known
incompatibilities with other Perl programs, and the end of this
document for known compile or install problems.

New in 1.05:

 o Added the missing support functions c_chstrlen, c_Screen2sv.
   Oops. :)

 o Updated DIAGNOSTICS section of pod.

 o Added typedef detection support.

 o Rearranged PANELS support a little.

 o Removed support for wattr_get, wattr_off, wattr_on, and
   wattr_set (for now).  I got the prototypes from ncurses-1.9.9g,
   but they apparently differ from the "standard" ones.

 o Renamed "lines" everywhere, 'cause some curses library writer
   was stupid enough to #define it.  (Go figure.)

 o Reworked "optional" arguments, which only affects newterm(),
   panel_above() and panel_below().  Now, if you want to specify
   "NULL" as an argument, use "undef" instead of omitting the
   argument.  (Don't worry if this doesn't make sense.  You
   probably aren't affected anyway.)

 o Added the ncurses "curs_mouse" functions, but I have no idea
   if they work.  I couldn't even get the C versions to work, so
   I had no way of testing them.  Feedback on these functions
   would be appreciated.

The "demo" program is for demonstration purposes only.  If it
references a function your version of curses doesn't have, wrap it in
an "eval" and try again.  Same goes double for the "gdc" program.
You can type "make cdemo" to make a C language version of the demo.
If you get the same results via "demo" and "cdemo", but they don't
look right, then it's a bug in your libcurses, not in Curses.

Enjoy!


William Setzer
William_Setzer at ncsu.edu

Known Problems
--------------
NCurses
   getch() and getstr() don't work right under very old versions of
   ncurses (around v1.8.5).  Please upgrade to a newer version.

   panel_hidden() test is reversed in v1.9.9g.  Please upgrade to
   a newer version.

   Actually, there are several problems in v1.9.9g.  Please upgrade
   to a newer version.




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

Date: Tue, 18 Jul 2000 18:11:55 GMT
From: pooh23@my-deja.com
Subject: file permissions
Message-Id: <8l26ko$3ej$1@nnrp1.deja.com>

Hello,
I have a perl script that executes every time someone hits the submit
button.  It asks me if I want to download my script.  I think the
permission for others and groups are set to execute.  My website is
being hosted on a MS Windows server.  Is there anyway that I can set
the permissions on my file.  I've tried changing them, but I get an
error message.


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


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

Date: Tue, 18 Jul 2000 11:38:59 -0700
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: file permissions
Message-Id: <8l2860$squ$1@brokaw.wa.com>


<pooh23@my-deja.com> wrote in message news:8l26ko$3ej$1@nnrp1.deja.com...
> Hello,
> I have a perl script that executes every time someone hits the submit
> button.  It asks me if I want to download my script.  I think the
> permission for others and groups are set to execute.  My website is
> being hosted on a MS Windows server.  Is there anyway that I can set
> the permissions on my file.  I've tried changing them, but I get an
> error message.

If you are downloading the script instead of executing it, you have a server
configuration problem.  Talk to the sysadmin.  Or you can go ask in a group
that covers servers like comp.infosystems.servers.*

Lauren





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

Date: Tue, 18 Jul 2000 19:58:38 GMT
From: DrZoso <drzoso@my-deja.com>
Subject: GUI Module
Message-Id: <8l2ct2$8hs$1@nnrp1.deja.com>

What module would I use for win32 to make the gui?

and how do I change the gui and configure it and stuff?


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


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

Date: Tue, 18 Jul 2000 13:33:11 -0700
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: GUI Module
Message-Id: <8l2esc$2fg$1@brokaw.wa.com>


DrZoso <drzoso@my-deja.com> wrote in message
news:8l2ct2$8hs$1@nnrp1.deja.com...
> What module would I use for win32 to make the gui?
>
> and how do I change the gui and configure it and stuff?

Win32::GUI

Tk.pm

It's also in the ActivePerl FAQ:

perlwin32faq9: Is there a way to do GUI programming with Perl for Win32?

Lauren





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

Date: Tue, 18 Jul 2000 13:20:41 -0700
From: Nigel Heinsius <heinsius@u.washington.edu>
Subject: HELP: Pattern Match
Message-Id: <B59A0A29.13C0%heinsius@u.washington.edu>

I need to make sure customers are not abbreviating Street, Avenue, etc.

Why doesn't this pattern match work:

$address =~ s/\bst\.?\b|\bstr\.?\b/Street/ig;

It keeps giving me "Street." with the period on the end. Why can't I match
the period?

Nigel



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

Date: Tue, 18 Jul 2000 14:48:20 -0800
From: kenned57@NoSpam.edu (Cameron Kennedy)
Subject: Re: HELP: Pattern Match
Message-Id: <kenned57-1807001448200001@alexthinkpad.salk.edu>

In article <B59A0A29.13C0%heinsius@u.washington.edu>, Nigel Heinsius
<heinsius@u.washington.edu> wrote:


> Why doesn't this pattern match work:
> 
> $address =~ s/\bst\.?\b|\bstr\.?\b/Street/ig;
> 
> It keeps giving me "Street." with the period on the end. Why can't I match
> the period?

It looks to me like there is not be a word boundary after the '.'.

So what you may have is str?\.?(?: |\b|$) 
where the last (?:) holds three options i can think of that would come next
space, start of a new word, or end of line.
try 
$address=~s/(\bstr?\.?)/Street/ig;


Cameron


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

Date: Tue, 18 Jul 2000 14:48:06 -0700
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: HELP: Pattern Match
Message-Id: <8l2j8n$4nj$1@brokaw.wa.com>


Nigel Heinsius <heinsius@u.washington.edu> wrote in message
news:B59A0A29.13C0%heinsius@u.washington.edu...
> I need to make sure customers are not abbreviating Street, Avenue, etc.
>
> Why doesn't this pattern match work:
>
> $address =~ s/\bst\.?\b|\bstr\.?\b/Street/ig;
>
> It keeps giving me "Street." with the period on the end. Why can't I match
> the period?

'.' is a word boundary.

Lauren





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

Date: Tue, 18 Jul 2000 14:27:01 -0400
From: "Edward Waldspurger" <ewald@electronicfrontiers.com>
Subject: How can I make variables global when I define them with my?
Message-Id: <8l27pn$eap$1@triox.mtcibs.com>

I have a subroutine which parses an html template file for variable names
and replaces them with their values.  So, if I have $title in the template
file, the sub will replace $title with the string I have defined in the
program.

sub Template {
local(*FILE);         # filehandle
local($file);         # file path
local($HTML);         # HTML data

$file = $_[0] || die "Template : No template file specified\n";
open(FILE, "<$file") || die "Template : Couldn't open $file : $!\n";
while (<FILE>) { $HTML .= $_; }
close(FILE);

$HTML =~ s/\$(\w+)/${$1}/g;

return $HTML;
}

However, if I define the variable using my (in the main program), it isn't
seen by the sub.  Can I make this variable available to the sub without
directly passing it?  If I pass is to the sub, how do I know what the name
of the variable was?

--
Edward Waldspurger
Electronic Frontiers Consulting, Inc.




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

Date: Tue, 18 Jul 2000 12:09:10 -0700
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: How can I make variables global when I define them with my?
Message-Id: <8l29uj$vsv$1@brokaw.wa.com>


Edward Waldspurger <ewald@electronicfrontiers.com> wrote in message
news:8l27pn$eap$1@triox.mtcibs.com...
> I have a subroutine which parses an html template file for variable names
> and replaces them with their values.  So, if I have $title in the template
> file, the sub will replace $title with the string I have defined in the
> program.
>
> However, if I define the variable using my (in the main program), it isn't
> seen by the sub.  Can I make this variable available to the sub without
> directly passing it?  If I pass is to the sub, how do I know what the name
> of the variable was?

Don't declare global variables with my().  Declare them as global.

use vars qw($title);

perldoc vars

Lauren





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

Date: Tue, 18 Jul 2000 22:27:41 +0200
From: "Trond Michelsen" <mike@crusaders.no>
Subject: Re: How can I make variables global when I define them with my?
Message-Id: <%43d5.15985$MS3.295899@news1.online.no>


Edward Waldspurger <ewald@electronicfrontiers.com> wrote in message
news:8l27pn$eap$1@triox.mtcibs.com...
> I have a subroutine which parses an html template file for variable
names
> and replaces them with their values.  So, if I have $title in the
template
> file, the sub will replace $title with the string I have defined in
the
> program.
>
> sub Template {
> local(*FILE);         # filehandle

There's no need to localize the filehandle you're using in this sub.

> local($file);         # file path
> local($HTML);         # HTML data

These two should've been declared with my.

> $file = $_[0] || die "Template : No template file specified\n";

fair enough, but I prefer to assign the passed values immediately, like
this:

sub mysub {
    my $file = shift;
# or like this;
    my ($file) = @_;

I tend to use the first if I only expect one parameter, but it's
probably better to just use the second all the time. At least that will
save some typing if you suddenly decide to use two parameters.

When it's really important that your function is called with a
parameter, then you should consider prototypes for your function.

sub Template ($) {
[...]
}

now it'll be a compile-time error if you call it with anything other
than one scalar parameter.

> open(FILE, "<$file") || die "Template : Couldn't open $file : $!\n";
> while (<FILE>) { $HTML .= $_; }
> close(FILE);

The fastest way to read a file into a scalar variable is to undef $/
(the input record separator).

my $content;
open FILE, $file or die "Template: Couldn't open $file: $!";
{
    local $/;
    $content = <FILE>;
}
close FILE;

I prefer to include mjd's nifty readfile-function into my programs,
especially if I read from a lot of files.

sub readfile ($) {
    my $file = shift;
    local *F;
    local $/ unless wantarray;
    open F, $file or return;
    <F>;
}

my $content = readfile $file;
# or to get it into an array, like one mey be used to:
my @content = readfile $file;

if the open fails, $content will be undef and @content will be empty.
beware though. @file will also be empty if the file is 0 bytes.

> $HTML =~ s/\$(\w+)/${$1}/g;
> return $HTML;
> }

now - for your original question :-)

> However, if I define the variable using my (in the main program), it
isn't
> seen by the sub.  Can I make this variable available to the sub
without
> directly passing it?  If I pass is to the sub, how do I know what the
name
> of the variable was?

you should really use a hash for this. so instead of this:

$date  = localtime;
$title = "Frontpage"
$foo   = "bar"
$idliketobe = "@TPC4"

you just stickemall into a hash:

my %variables = ( date => scalar localtime,
                  title => "Frontpage",
                  foo => "bar",
                  idliketobe => "@TPC4",
                 );

now it's easy to pass all the vars to the sub.

Template($file, \%variables);

and the sub needs to be something like this:

sub Template {
    my ($file, $vars) = @_;
    my $HTML = readfile $file; # ok, I'm cheating ;)
    die "Couldn't open $file: $!" unless defined $HTML;
    $HTML =~ s/\$(\w+)/$vars->{$1}/g;
    return $HTML;
}

but, depending on your needs, it could be useful to only replace those
variables that you actually have in your program. If your template says:
"This thing cost me $50,-" you don't want to replace $50 with "".

changing the regex-line to this:

my $regex = join '|', map "\Q$_\E" => keys %$vars;
# now we now what the possible values in the template are.
$HTML =~ s/\$($regex)/$vars->{$1}/g;

solves that problem.

anyway - you might want to take a look at these manuals:

man perlref  # references
man perlre   # regex
man perlsub  # subrutines

hth

--
Trond Michelsen





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

Date: Tue, 18 Jul 2000 11:54:35 -0700
From: Frederic <j_f9NOj_SPAM@yahoo.com.invalid>
Subject: Re: How do you pass objects to a subroutine?
Message-Id: <09877504.6a695980@usw-ex0102-014.remarq.com>

Now I can make FTP scripts maintenance a lot easier.  Thanks.

#!/usr/bin/perl -w

use Net::FTP;
my $mdp = $ARGV[0];

sub process {
   my $obj = shift;

   $obj->login("ub1000","$mdp");
   $obj->cwd("/tmp");
   $obj->get("sh31284.1");
   $obj->quit;
}

my $ftp = Net::FTP->new("server1");

process($ftp);

Greetings,
Frederic

Samay <samay1NOsaSPAM@hotmail.com.invalid> wrote:
>
>use Obj
>my $obj = Obj->new("arguments");
>process($obj);
>
>
>sub process {
>  my $obj = shift;
>  $obj->method();
>  do whatever..
>}



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

Got questions?  Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com



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

Date: 18 Jul 2000 15:51:30 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: how to convert "1.2.3.10" to "01020310"?
Message-Id: <slrn8n9eb8.3do.abigail@alexandra.delanet.com>

Craig Berry (cberry@cinenet.net) wrote on MMDXIII September MCMXCIII in
<URL:news:sn95rngk1nk55@corp.supernews.com>:
;; Abigail (abigail@delanet.com.bbs@openbazaar.net) wrote:
;; : Where is this "intent" defined? Or is this arbirary, just as using
;; : tr/// to remove letters, and y/// to remove digits?
;; 
;; It is arbitrary to a degree; that's why I described it as "informal" and a
;; "convention".  Again, it falls into exactly the same category as
;; indentation of code; there are many potential styles, each with pluses and
;; minuses, and each with its devout defenders.  But I think we would all
;; agree that indented code, using any reasonable style, is far easier to
;; read (and hence maintain) than unindented code, despite the fact that perl
;; sees no difference between the two forms.
;; 
;; : But, for me, the intent of map is to mainly apply a function to each
;; : element of a list. Whether that function has a side effect or not is
;; : irrelevant. map {printf "%02d" => $_} @array couldn't be clearer.
;; 
;; Just as the intent of foreach is to apply a block to every element in a
;; list.

Not for me. The intent of foreach is to run a block of code repeatedly,
with a variant that iterates over the elements of the list. A small, but
subtle difference.

;;        foreach can thus be seen as a subset of map, to a first
;; approximation.  Yet both get used in many programs, and not just in those
;; cases where foreach does offer features not available in map (e.g., next).
;; My argument is simply that there are good reasons for this choice.  And
;; 
;;   printf '%02d', $_ foreach @array;
;; 
;; is equally clear, surely.

You seem to be advocating coding conventions, praising the few millisecond
it gains. Surely, you should not be using a recent construct then,
but use a construct that either has the map or for(each) at the beginning.

But if printf '%02d', $_ foreach @array; is equally clear, there's no reason
at all to prefer it over map {printf "%02d" => $_} @array;.

;; : I also find it utterly amazing that while someone can't grasp the
;; : string
;; : 
;; :     "Here's a very &//? long and sym&^bol-\$rich string blah blah!",
;; : 
;; : all at once, he apparently *can* grasp
;; : 
;; :     'Here\'s a very &//? long and sym&^bol-$rich string blah blah!'
;; :  
;; : all at once. After all, if one can't, it would not matter what quotes are
;; : used, would it?
;; 
;; When parsing the latter one, all I need to look for are a couple of
;; backslash cases, period.  Much simpler.

But you were going to parse the string entirely anyway, because you wanted
to see its meaning. Surely, the meaning cannot be derived from backslashes
only.

;; : Me, I would look at the first string, see there's no interpolation
;; : going on, so I wouldn't care at all what the quotes are. As for the
;; : single quotes form, I'd probably think "hmmm, $rich isn't a variable,
;; : oh, that's ok, it's single quoted anyway".
;; 
;; Yeah, and there go a precious few milliseconds. :)

Yeah, but I only lose the few precious milliseconds then, I don't waste
them on each and every quote encountered having to swap in the appropriate
parser.

;; : Tell me, which of your arguments you use to promote single quotes when no
;; : interpolation takes place, while reserving double quotes only when there's
;; : interpolation, doesn't apply to s///?
;; 
;; Honest answer?  Force of habit and others' convention.  I've been writing
;; substitutions long enough in the standard form, and read enough code using
;; that form, that it's easier to leave the dquote context than to do the
;; "right thing".  As I will now repeat again:  It's a matter of informal
;; convention and empirical eyeball-parsing optimization, *not* a rigid and
;; formally consistent rule set. 


I've coded long enough not to be tripped by double quotes.


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


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

Date: Tue, 18 Jul 2000 20:42:16 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: how to convert "1.2.3.10" to "01020310"?
Message-Id: <sn9g98m51nk62@corp.supernews.com>

Abigail (abigail@delanet.com) wrote:
[A reply to my reply to her reply to my reply to her reply to the OP]

I think we've reached the agree-to-disagree point; I do see your points.
Let's break off before the remainder of clpm dispatches a mob of angry
villagers with torches. :)

-- 
   |   Craig Berry - http://www.cinenet.net/users/cberry/home.html
 --*--  "Beauty and strength, leaping laughter and delicious
   |   languor, force and fire, are of us." - Liber AL II:20


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

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


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