[6305] in Perl-Users-Digest
Perl-Users Digest, Issue: 927 Volume: 7
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 11 14:30:52 1997
Date: Tue, 11 Feb 97 11:00:23 -0800
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, 11 Feb 1997 Volume: 7 Number: 927
Today's topics:
Re: Empty contents of a file without deleting it (I R A Aggie)
Re: File Mager Perl Script <nmljn@wombat.staff.ichange.com>
Help <SIDDIQM2@boat.bt.com>
Re: how to change of a given string? <kannawin@q.osmre.gov>
Re: How to check an environmental variable <nmljn@wombat.staff.ichange.com>
How to run shell program in perl with --date 'one mont (Brian Freeze)
Re: How to run shell program in perl with --date 'one (Tad McClellan)
How to tell if Perl is run in debug mode <dennerbw@lmco.lmtas.com>
initialization of hash while resolving? <sa@denkart.be>
learning perl <david@bradda.demon.co.uk>
Re: learning perl (Tad McClellan)
Need help with substituion pattern matching (Primal Fear)
Re: Need help with substituion pattern matching (Tad McClellan)
Nested calls from VBScript/PerlScript crash IIS <Tilmann.Haeberle@sap-ag.de>
opendir/readdir/closedir (The next Pele)
Re: opendir/readdir/closedir (Nathan V. Patwardhan)
Pasting between apps question <rdarnese@nortel.ca>
Re: Perl NT Command Line (Scott McMahan - Softbase Systems)
Perl Programmer Needed (Ron Brandt)
Re: PerlIS problem reading network drive (Kevin Smith)
Q: how best to share a hash between packages (Greg Haygood)
regexp help <williams@irc.chmcc.org>
Re: regexp help <nmljn@wombat.staff.ichange.com>
Re: SORT: trying to sort files on date. AND connecting (Bennett Todd)
UCE: savvy.com "Internet Banner Network" <tchrist@mox.perl.com>
wrapping comment-text (Stijn van Dongen)
Re: XS problem - Can't find loadable object (Mark Daku)
Digest Administrivia (Last modified: 8 Jan 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 06 Feb 1997 15:51:39 -0500
From: fl_aggie@hotmail.com (I R A Aggie)
Subject: Re: Empty contents of a file without deleting it
Message-Id: <fl_aggie-ya023180000602971551390001@news.fsu.edu>
In article <5dde5q$6om$1@marina.cinenet.net>, cberry@cinenet.net (Craig
Berry) wrote:
+ If you don't mind creating the file if it wasn't there previously, then
And to avoid creating it if it isn't there:
if (-e "say.goodbye") {
+ open(DOOMED, ">say.goodbye") or die("Can't open doomed file: $!");
+ close(DOOMED);
}
----
There are other file tests one may apply. See pag 85 of the Azure Camel.
James
--
Consulting Minster for Consultants, DNRC
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/perl/faq/idiots-guide.html>
------------------------------
Date: 11 Feb 1997 10:13:22 -0500
From: nelson <nmljn@wombat.staff.ichange.com>
Subject: Re: File Mager Perl Script
Message-Id: <w10ybcvidf1.fsf@wombat.staff.ichange.com>
umoraes <umoraes@mercurioterm.com> writes:
> Hi,
> I'm looking for a file manager script (writen in perl) that i can
> use to erase, rename, ... in my site
^^^^^^^^^^
A good file manager program is /usr/bin/sh, or, if you're so
unfortunate, c:\dos\command.
My question is, why do you need to write a mini operating system in perl?
If your answer to this question would contain the word CGI in it, then
note that CGI-compliant programs need not be written in perl, contrary
to the opinions of the mass media. If you know C, do it in C. If you
know sh, do it in sh. I'd say don't do it at all since that's what a
command line is in the first place.
I'm also going to guess that you're looking for some kind of
browser-UI-based way to administer the files in your web site. This
is NOT a good idea, since if whatever CGI-compliant file manager
program lives on the back end is powerful enough to be able to delete
files, then someone will figure out how to do that maliciously.
For better answers, see news:comp.infosystems.www.authoring.cgi.
Cheers,
Laird
--
<laird.nelson@netsinc.com> perl FAQ: http://www.perl.com/perl/faq Perl manual:
http://www.perl.com/CPAN/doc/manual/html/frames.html. If CGI/web appears in
your comp.lang.perl.* post, see news:comp.infosystems.www.authoring.cgi. CGI
stands for Common Gateway *Interface*, not Language or Program or Script.
Consolidated perl reference page: http://www.amherst.edu/~ljnelson/perl.html
------------------------------
Date: Tue, 11 Feb 1997 16:02:19 +0000
From: Muhammad Siddiqui <SIDDIQM2@boat.bt.com>
Subject: Help
Message-Id: <3300980B.2942@boat.bt.com>
Has anyone out there actually got 'oraperl' to work ??
I'm using Oracle 7.3 and Perl 5.003. I've downloaded the source code for
oraperl and when try to build it up, it complains that it can't find a
file namely 'uperl.o'..
--
Views expressed are my own, and do not represent those of my employer.
------------------------------
Date: 11 Feb 1997 09:22:25 -0700
From: Bill Kannawin <kannawin@q.osmre.gov>
Subject: Re: how to change of a given string?
Message-Id: <udafpbtiri.fsf@q.osmre.gov>
Tom Christiansen <tchrist@mox.perl.com> writes:
>
> [courtesy cc of this posting sent to cited author via email]
>
> In comp.lang.perl.misc, luis@ged.com writes:
> : I need to change the Case of a string that a client inputs for
> :instance ibm would be IBM, apple would be Apple. The string is obtained
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> :from the login that permits the user to enter the page. (Its a cgi perl
> :page)
>
> man perlfunc | egrep -i '(upper|lower)-*case'
>
> --tom
> --
> Tom Christiansen tchrist@perl.com
> echo $package has manual pages available in source form.
> echo "However, you don't have nroff, so they're probably useless to you."
> --Larry Wall in Configure from the perl distribution
something like this may be what you are looking for:
#!/usr/local/bin/perl -w
while (<>) {
s/ibm/IBM/i;
s/apple/Apple/i;
print;
}
------------------------------
Date: 11 Feb 1997 10:21:39 -0500
From: nelson <nmljn@wombat.staff.ichange.com>
Subject: Re: How to check an environmental variable
Message-Id: <w10wwsfid18.fsf@wombat.staff.ichange.com>
akench@cvimail.cv.com writes:
> Hi Perl Gurus,
> Is there a way to check if a environmental variable
> exists or no. Checking this way
> "if ($ENV{'variable'}) "
> works only if that environmental variable has a value.
> How can I check if it is declared but has no value?
I predict that you will receive two replies. One will say this:
if (exists($ENV{'variable'})) {
# do something
}
Another will say this:
if (defined($ENV{'variable'})) {
# do something
}
Both are correct, sort of. :-) exists() returns true if the specified
hash key exists. It says nothing about what that key stores.
defined() simply tests its argument to see if it's been initialized.
For example:
$HASH{'key'} = undef;
if(exists($HASH{'key'})) {
print STDOUT "\$HASH{'key'} exists.\n";
}
if(defined($HASH{'key'})) {
print STDOUT "\$HASH{'key'} has a defined value.\n";
}
The code above will tell you that $HASH{'key'} exists, but since the
value *in* $HASH{'key'} is undefined, the second if block won't run.
Cheers,
Laird
--
<laird.nelson@netsinc.com> perl FAQ: http://www.perl.com/perl/faq Perl manual:
http://www.perl.com/CPAN/doc/manual/html/frames.html. If CGI/web appears in
your comp.lang.perl.* post, see news:comp.infosystems.www.authoring.cgi. CGI
stands for Common Gateway *Interface*, not Language or Program or Script.
Consolidated perl reference page: http://www.amherst.edu/~ljnelson/perl.html
------------------------------
Date: 11 Feb 1997 15:33:18 GMT
From: freezeb@deltastar.nb.ca (Brian Freeze)
Subject: How to run shell program in perl with --date 'one month ago' +%b options
Message-Id: <5dq3fu$rr1@eggplant.nbnet.nb.ca>
Greetings
I am trying to write a small perl script and have run into this problem. I am
trying to call "/bin/date --date 'one month ago' +%b" into a perl script. I
assign this to a variable as follows:
$date_exe="/bin/date";
$date='$date_exe --date '1 month ago' +"%b"';
I then use "exec" and "print" to make the calls to the variables. I keep
getting syntax errors from the $date= variable and can't figure out what
needs to be escaped in order to allow all the options for the unix date
command.
Specific error is as follows:
Number found where operator expected at ./stats-script line 7, near
"'$date_exe
--date '1"
(Missing operator before 1?)
syntax error at ./stats-script line 7, near "'$date_exe --date '1"
Bare word found where operator expected at ./stats-script line 7, near "1
month"
(Missing operator before month?)
Execution of ./stats-script aborted due to compilation errors.
Could someone be so kind as to point out what I am doing wrong with this and
also explain the proper way to call a system program with options into the
script.
Thanks in advance.
------------------------------
Date: Tue, 11 Feb 1997 10:19:05 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: How to run shell program in perl with --date 'one month ago' +%b options
Message-Id: <p56qd5.3c2.ln@localhost>
Brian Freeze (freezeb@deltastar.nb.ca) wrote:
: I am trying to write a small perl script and have run into this problem. I am
: trying to call "/bin/date --date 'one month ago' +%b" into a perl script. I
: assign this to a variable as follows:
: $date_exe="/bin/date";
: $date='$date_exe --date '1 month ago' +"%b"';
^^^^^^^^^^^^^^^^^^^
There is the string with its two delimiters. See the problem?
$date='$date_exe --date "1 month ago" +"%b"';
^ ^
Would fix the syntax error.
But wait! It still won't work after you do that!
You can get one of two behaviours from exec() based on the LIST that
you provide when you call it:
1) single string
2) list of strings (which is what you are trying to do)
(and your list is not broken up properly either)
See exec() in the perlfunc man page...
: I then use "exec" and "print" to make the calls to the variables. I keep
^^^^^^^^^^
Don't need to...
: getting syntax errors from the $date= variable and can't figure out what
: needs to be escaped in order to allow all the options for the unix date
: command.
[ snip syntax error messages ]
: Could someone be so kind as to point out what I am doing wrong with this and
: also explain the proper way to call a system program with options into the
: script.
I'd just to it like:
# see perl FAQ #5.15
$date = `/bin/date --date "1 month ago" +"%b"`;
# ^ backwards single quotes ^
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Tue, 11 Feb 1997 10:53:03 -0600
From: Brett Denner <dennerbw@lmco.lmtas.com>
Subject: How to tell if Perl is run in debug mode
Message-Id: <3300A3EF.167E@lmco.lmtas.com>
I would like to add some code to my perl script that is executed only
when perl is started with the -d flag (either via the command line or
the #!/usr/bin/perl line). I envision something like this:
if ($DEBUG_MODE)
{
# do something
}
where $DEBUG_MODE (or some other such variable) is true only in debug
mode.
Does such a variable exist? Is there another way to tell if my script
is being run in debug mode?
Thanks,
Brett
-----------------------------------------------------------------------
Brett W. Denner "Visualize Whirled Peas"
DennerBW@lmtas.lmco.com
------------------------------
Date: Tue, 11 Feb 1997 17:32:51 +0100
From: Sven Akkermans <sa@denkart.be>
Subject: initialization of hash while resolving?
Message-Id: <33009F18.147E@denkart.be>
Hello,
take a look at this program.
#!/users/sa/mrperl/bin/perl
use strict;
my(%SGS,$x);
$SGS{AB} = 13;
if( exists($SGS{SE}))
{
print "SE exists from the first time on\n";
}
$x = $SGS{SE}{X};
if( exists($SGS{SE}))
{
print "SE exists from the second time on\n";
}
Surprisingly to me, this prints "SE exists from the second
time on". This means that SE exists after the assignment to
$x.
Is this a normal behaviour? I think it has something to do
with the fact that $SGS{SE} is used to resolve $SGS{SE}{X}.
I would expect that $SGS{SE} simply resolves to undef and that
would be it.
Sven Akkermans
sa@denkart.be
------------------------------
Date: Tue, 11 Feb 1997 15:34:13 +0000
From: David Darwent <david@bradda.demon.co.uk>
Subject: learning perl
Message-Id: <Dke0yDA1FJAzIweq@bradda.demon.co.uk>
Hi
Having realised that HTML has it's limits I decided that I would like to
write CGI for web pages and after reading about perl I decided that perl
was the ideal language for CGI. So I bought a book and started to read.
But I soon realised that it wasn't going to be as easy as I thought. As
this is my first experience with programming.
Is this why I am find perl difficult? Am I trying to run before I can
walk? Is there a langange that I should tackle first, maybe BASIC or
PASCAL? Or should I just persevere with perl?
Any help will be much appreciated
All the best,
David Darwent
------------------------------
Date: Tue, 11 Feb 1997 10:24:40 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: learning perl
Message-Id: <8g6qd5.oc2.ln@localhost>
David Darwent (david@bradda.demon.co.uk) wrote:
:
: Having realised that HTML has it's limits I decided that I would like to
: write CGI for web pages and after reading about perl I decided that perl
: was the ideal language for CGI. So I bought a book and started to read.
^^^^^^^^^^^^^^^
Hope this was "Learning Perl" by Randal Schwartz...
http://www.ora.com
: But I soon realised that it wasn't going to be as easy as I thought. As
: this is my first experience with programming.
: Is this why I am find perl difficult?
Yep. *programming* is what is difficult...
: Am I trying to run before I can
: walk? Is there a langange that I should tackle first, maybe BASIC or
: PASCAL? Or should I just persevere with perl?
I'd tough it out with perl.
Just learn how to do stuff with perl from the command line. Don't
try and learn 'programming' AND 'perl' AND 'CGI' all at the same time.
When you get 'good enough' with perl, then turn your attention to
using it for CGI scripting (and when you do _that_, ask your questions in:
comp.infosystems.www.authoring.cgi instead of comp.lang.perl.misc ;-)
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Tue, 11 Feb 1997 15:31:22 GMT
From: jader@rsabbs.com (Primal Fear)
Subject: Need help with substituion pattern matching
Message-Id: <33008d63.1919180@netnews.voicenet.com>
I am having a slight problem with substituting a bunch of commas for pipes in a string. The strings look like thiis.
08971987287771,CD,"10,000 MANIACS","TITLE OF ALBUM",10.49,13.49,EB,1
90702878398785,LP,"1,000 CLOWNS","TITLE OF ALBUM",7.00,9.50,TT,1
I need to make every comma a pipe except for the comma in 10,000 MANIACS. The problem is that there are
about +20000 strings. Some of them have commas just like above. I can't figure out a way to not reploace the
comma that should stay put. any suggestions would be helpful.
Here is what I have now:
foreach $line (<F>) {
$line =~ s/([A-Z])\,/$1 /g;
$line =~ s/\"//g;
$line =~ s/\,/\|/g;
$line =~ s/ +/ /g;
print NEW "$line";
}
After this runs I have to go back and search for any instances of 10|000 ,1|000 and 3|000 and
replace the | back with a comma. Not very effective.
------------------------------
Date: Tue, 11 Feb 1997 10:01:17 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Need help with substituion pattern matching
Message-Id: <d45qd5.l72.ln@localhost>
[ please limit your line lengths to 70-72 characters ]
Primal Fear (jader@rsabbs.com) wrote:
: I am having a slight problem with substituting a bunch of commas for pipes
^^^^^^^^^^^^^^^^
I think you meant to say "pipes for commas", right?
(I prefer 'vertical bar' which names the character, rather than 'pipe'
which names one of the functions often represented by that character)
: in a string. The strings look like thiis.
: 08971987287771,CD,"10,000 MANIACS","TITLE OF ALBUM",10.49,13.49,EB,1
: 90702878398785,LP,"1,000 CLOWNS","TITLE OF ALBUM",7.00,9.50,TT,1
: I need to make every comma a pipe except for the comma in 10,000 MANIACS. The problem is that there are
: about +20000 strings. Some of them have commas just like above. I can't figure out a way to not reploace the
: comma that should stay put. any suggestions would be helpful.
This sounds similiar to something from the perl FAQ:
4.28) How can I split a [character] delimited string except when inside
[character]?
So, let's use what it says there to split the fields (respecting
commas inside of double quotes), and then join them back together
with the vertical bar character:
---------------
#! /usr/bin/perl -w
foreach (
'08971987287771,CD,"10,000 MANIACS","TITLE OF ALBUM",10.49,13.49,EB,1',
'90702878398785,LP,"1,000 CLOWNS","TITLE OF ALBUM",7.00,9.50,TT,1'
) {
undef @fields;
push(@fields, defined($1) ? $1:$3) while
m/"([^"\\]*(\\.[^"\\]*)*)"|([^,]+)/g;
print join '|', @fields;
print "\n";
}
---------------
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Tue, 11 Feb 1997 16:25:09 GMT
From: "Dr. Tilmann Hdberle" <Tilmann.Haeberle@sap-ag.de>
Subject: Nested calls from VBScript/PerlScript crash IIS
Message-Id: <01bc1837$eace5570$0af3389b@p21907>
Are nested calls between different scripting engines
not allowed?
The ASP file below crashes the Internet Server
if you remove the tick from the indicated line.
It calls a method of the Request object to pass it to a Perl
function.
If you use a temporarily variable (MyPath) to store the intermediate
result, everything works fine.
I use PerlScript build 303, Peer Web Services 3.0, ASP Version 3.0.
Default scripting engine is VBScript
[start of ASP file]
<html>
<head>
<title>Welcome</title>
</head>
<body>
<%MyPath = Request.ServerVariables("PATH_TRANSLATED")%>
My path is <%=MyPath%><P>
My age is <%=get_age(MyPath)%> days<P>
If you remove the tick from
the next line, the internet server will crash: <%
'=get_age(Request.ServerVariables("PATH_TRANSLATED"))
%>
</body>
</html>
<script language=PerlScript RUNAT=Server>
sub get_age {
my $fname = shift;
return -M $fname;
}
</script>
[end of ASP file]
--
Disclaimer: This is the personal opinion of me. I'm not a spokesman of SAP.
Tilmann Haeberle
------------------------------
Date: 11 Feb 1997 16:37:44 GMT
From: gt1535b@acmex.gatech.edu (The next Pele)
Subject: opendir/readdir/closedir
Message-Id: <5dq78o$8cf@catapult.gatech.edu>
I'm running the Win95 port of perl, and I'm having some problems
with readdir. I previously had the script using a shell command
to read the dir., but I want it to be non-platform specific. I
changed it to this:
opendir(DIR, "$rlsdir");
@Rlse = readdir(DIR);
but it won't read anything into it (@Rlse, that is). Has anyone
else run into this problem?
thanks
Daryl
--
<>< Daryl Bowen <><
Georgia Institute of Technology
Internet: gt1535b@prism.gatech.edu
Siemens Stromberg-Carlson Co-op
------------------------------
Date: 11 Feb 1997 16:52:58 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: opendir/readdir/closedir
Message-Id: <5dq85a$moi@fridge-nf0.shore.net>
The next Pele (gt1535b@acmex.gatech.edu) wrote:
: opendir(DIR, "$rlsdir");
: @Rlse = readdir(DIR);
Why aren't you returning errors? I suspect your program can't
open the directory $rlsdir, and will output an error message
if you use die() or the subroutine below. :-)
sub output_error {
my($error_msg) = @_; ### pass in error message
print("ERROR: $error_msg\n");
exit;
}
opendir(DIR, "$rlsdir") || output_error("$!");
@Rlse = readdir(DIR);
closedir(DIR);
--
Nathan V. Patwardhan
nvp@shore.net
"send me mail"
--Jamie Zawinski
------------------------------
Date: 11 Feb 1997 17:14:36 GMT
From: Richard Arnesen <rdarnese@nortel.ca>
Subject: Pasting between apps question
Message-Id: <5dq9ds$puq@nrtphc11.bnr.ca>
[ Article reposted from comp.windows.x ]
[ Author was Richard Arnesen <rdarnese@nortel.ca> ]
[ Posted on 11 Feb 1997 17:12:52 GMT ]
What I want to do is have a script or whatever send it's output
to another X application via whatever utility available within X to do
this.
I had been pointed to xmh as an example. However upon looking through
it's docs it appears that that is just a function of xmh.
What I need to know is there a way to by X-windows standards send
output from a script into another X-window (through a buffer or whatever).
TIA
--
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
<>Riichard D. Arnesen Jr. <> "There's too much personal freedom. <>
<>Unix DCA Support <> We have to find a way to limit it. <>
<>Nortel, RTP, NC <> Bill Clinton, Apr,19 1994 speaking <>
<>My opinions only <> on the bill of rights. <>
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
--
Richard D. Arnesen Jr. - Unix DCA Support, Nortel, RTP
----------------------------------------------------------------
"..but I now know who he is, and what he is. There is nothing he
won't do, he is immune from shame...you find absolutely nothing,
nothing but an appetite" - Jesse Jackson speaking of Bill Clinton
----------------------------------------------------------------
The opinions stated above are mine and not that of Nortel
------------------------------
Date: 11 Feb 1997 15:07:08 GMT
From: softbase@mercury.interpath.com (Scott McMahan - Softbase Systems)
Subject: Re: Perl NT Command Line
Message-Id: <5dq1us$2pt@redstone.interpath.net>
Neal Hansch (tch@acpub.duke.edu) wrote:
: I am running NT Workastation with Perl 5 and I have associated ".pl"
: with the perl.exe :
: When I do "perl program.pl > test.txt" it outputs the program results
: in the file just fine.
: When I do "program.pl > test.txt" there is no output in the file (only
: difference is I left the perl call out).
: Why?
In the registry, .pl is associated with the command "perl.exe %1",
which only passes the *first* command line parameter to the perl
command. The others go off into the bit bucket. You need to add %2, %3,
etc to the registry entry to pass other parameters.
Scott
------------------------------
Date: Tue, 11 Feb 1997 13:22:07 LOCAL
From: ron@voicenet.com (Ron Brandt)
Subject: Perl Programmer Needed
Message-Id: <ron.7.04908CDC@voicenet.com>
P_O_S_I_T_I_O_N_S A_V_A_I_L_A_B_L_E
Perl Programmers
----------------
Perl programmers needed at our Ivyland, PA (Bucks County)
location to develop/debug database and related interface
modules. Knowledge of Solaris and or Sunos a must.
Fax Resume to Ron Brandt 215-674-9662 or call voice at
215-674-9290. Indicate position you are applying for on fax
or when calling.
USA's - Unix System Administrator & Assistants
----------------------------------------------
Assistant/apprentice to full administrators needed. Knowledge
of SUN Solaris/Sunos, and or Linux and the Internet mandatory.
Positions available at our Ivyland, PA (Bucks County) location.
Fax Resume to Ron Brandt 215-674-9662 or call voice at
215-674-9290. Indicate position you are applying for on fax
or when calling.
------------------------------
Date: 11 Feb 1997 15:31:39 GMT
From: kevin.smith@citicorp.com (Kevin Smith)
Subject: Re: PerlIS problem reading network drive
Message-Id: <5dq3cr$61r@spruce.citicorp.com>
After a little more deugging I found the error returned bu opendir is
No such file or directory
Still don't know why though.
TIA
--
Kevin Smith
------------------------------
Date: Tue, 11 Feb 1997 18:32:17 GMT
From: greg@iweb.net (Greg Haygood)
Subject: Q: how best to share a hash between packages
Message-Id: <3300b476.521895205@nntp.atlanta.com>
hi, all
i'm rewriting a CGI/perl application i wrote a while back . the
basics of the app are that it's composed of a number of scripts, which
share a bunch of code. previously, this shared code was partly
bundled in a 'util.pl' script, and the rest was, sadly, duplicated
among the different pieces of the app. this "structure" just
followed the code writing, with no real pre-planning involved.
anyway, i'm going back over the code to modularize and condense the
pieces.
so now i have a decent module which each main script calls for
subroutines and variables. the problem is that i really want to add a
hash to the variables which are exported. this is because each script
does a lot of work with one or two hashes currently, but would benefit
from this package'd hash(es), since both the scripts and the modules
subroutines access this hash.
i tried using hash refs as noted in Camel II, and in the FAQ,
resulting in something like:
# In file Util.pm:
package Util;
sub Function {
local *hash = shift;
# make normal hash calls here
}
# End Util.pm
# in file DoSomething.cgi
use Util;
my %hash;
# build up hash
# ...
# neither of these calls gains access to this script's %hash
Function(*hash);
Function(\*hash);
# end DoSomething.cgi
since neither of these works, but *should*, i must be doing something
wrong. can someone enlighten me?
to work around this, i thought it would be ok to just make a %hash
inside of the Util.pm module, export it, then simply work with it as
normal everywhere, but obviating the need to pass the reference.
thus, i thought something like:
# In file Util.pm:
package Util;
# this works fine for scalars, so it should work
# for hashes also, right?
%EXPORT_TAGS = ( Vars => [ qw( %hash ) ] );
Exporter::export_tags('Vars');
sub Function {
# make normal hash calls here
}
# End Util.pm
# in file DoSomething.cgi
use Util;
# build up %hash, which is imported from Util.pm
Function(); # which doesn't need to pass %hash ref
# end DoSomething.cgi
but, this doesn't work either. any suggestions?
thanks for any insights into my Q's.
greg
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: 2.6.2
mQCNAzIhxlcAAAEEAL8siYT/1eU9elrKBA8nuTI03ZBKhJvcnmcHSwpi1g+8BW41
AJKnyv4D8kTvmZAg+YnAlCb4tTqK3B4VXYOQsLjHhH6hsU3bK2z9dtpQVJETC2/p
h8o/7rXliMI5hcDZndqENq/62xOzG8PCqRhGq28Vr7+4LgVS3fnGyBDw3czZAAUR
tBxncmVnIGhheWdvb2QgPGdyZWdAaXdlYi5uZXQ+iQCVAwUQMiHGYfnGyBDw3czZ
AQGNmgQAgYP+vFYwU+aZPoNzwmyF+JWHswo3Y1d0aLM+JtNN1i7KnQMLwYqtX8cS
wWYhaD7CPHfDuUPOGDUkxD7ksFz49J8ycRqkrsjHfottARc83fteRiBsgqzsR9r/
pDNJHKwu+uVzZqO2Kzv1N5VU2Uzwo2seohprNg9uHUSjYeN0wMY=
=dr+k
-----END PGP PUBLIC KEY BLOCK-----
------------------------------
Date: Tue, 11 Feb 1997 11:31:00 -0500
From: Phil Williams <williams@irc.chmcc.org>
Subject: regexp help
Message-Id: <33009EC4.446B@irc.chmcc.org>
Sorry for the basic question but regexps are still very confusing to me.
Here's what I want to do. I have a user input string of items that may
be delimeted with spaces, commas, semicolons, carriage returns, etc. or
any combination of those. I want to substitute those with a single ,.
Here's what I do
$value =~ s/[,:; ][ \n]*/,/g;
Which works except that it leaves the last, sometimes unwanted character
in place. i.e. the user hit a <ret> at the end but did not enter
anything afterwards. How would I check and get rid of this last char in
the same regexp?
Thanks in advance,
Phil
--
/*******************************************************************/
Phil Williams, Ph.D.
Research Instructor
Children's Hospital Medical Center "One man gathers what
Imaging Research Center another man spills..."
3333 Burnet Ave. -The Grateful Dead
Cincinnati, OH 45229
email: williams@irc.chmcc.org
URL: http://scuttle.chmcc.org/~williams/
/*******************************************************************/
------------------------------
Date: 11 Feb 1997 12:28:50 -0500
From: nelson <nmljn@wombat.staff.ichange.com>
Subject: Re: regexp help
Message-Id: <w10sp33i759.fsf@wombat.staff.ichange.com>
Phil Williams <williams@irc.chmcc.org> writes:
> Here's what I want to do. I have a user input string of items that may
> be delimeted with spaces, commas, semicolons, carriage returns, etc. or
> any combination of those. I want to substitute those with a single ,.
Let's see if I got you right.
For every comma, whitespace, or semicolon, or combination thereof,
replace it with a single comma.
Try it in two passes, like so:
s/[\s,\;]/,/g;
s/,{2,}/,/g;
The first regexp turns any commas, any semicolons and any whitespace
at all (note that this is probably NOT what you want, but it is what
you said) into commas. The second regexp turns any occurrence of two
or more commas in a row into one comma.
I'm sure there are better ways to do it--someone will probably jump in
offering a one-pass solution, but will probably forget that you said
"any combination of those". :-)
Cheers,
Laird, eagerly awaiting the regex fray that will doubtlessly ensue
--
<laird.nelson@netsinc.com> perl FAQ: http://www.perl.com/perl/faq Perl manual:
http://www.perl.com/CPAN/doc/manual/html/frames.html. If CGI/web appears in
your comp.lang.perl.* post, see news:comp.infosystems.www.authoring.cgi. CGI
stands for Common Gateway *Interface*, not Language or Program or Script.
Consolidated perl reference page: http://www.amherst.edu/~ljnelson/perl.html
------------------------------
Date: Tue, 11 Feb 1997 15:20:47 GMT
From: bet@nospam.interactive.net (Bennett Todd)
Subject: Re: SORT: trying to sort files on date. AND connecting system commands via pipe ????
Message-Id: <slrn5g13ie.6g4.bet@onyx.interactive.net>
This looks like a pretty roundabout approach. See if you can do it entirely in
perl:
# Print files in any_file.dat, sorted by date
print map { $_->[0] }
sort { $a->[1] <=> $b->[1] }
map { [ $_, -M ] }
<any_file.dat/*>;
or something like that. I haven't used VMS perl; it might not translate
Unix-style globbing in the directory reading code, so you might have to turn
that last into a VMS-style pattern.
As for the preceeding lines, they are an efficient way to do a sort on an
alternate key, and are explained in detail in tchrist's tutorial on sorting,
available from either of
<URL:http://perl.org/CPAN/doc/FMTEYEWTK/sort.html>
<URL:http://perl.com/CPAN/doc/FMTEYEWTK/sort.html>
-Bennett
------------------------------
Date: 11 Feb 1997 16:54:30 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: UCE: savvy.com "Internet Banner Network"
Message-Id: <5dq886$suf$1@csnews.cs.colorado.edu>
The perlbug mailing list, comprising about four hundred members, has
received the attached unsolicited commercial email. Apparently they
have a bug in Perl but are unclear about standard reporting procedure.
Perhaps we should send them the latest version, uuencoded. :-)
Interestingly enough, they include an 800 number you can call. If you
call it, they answer the phone "Internet". I could not get them
to tell me their name, their manager's name, or the name or address
of their business. Isn't this against standard business practices?
Shouldn't the Better Business Bureau have something to say about this?
I would for each and every person reading this, particularly if you
use Perl has helped you out, to call Savvy.COM's tollfree number,
1-800-WEBPRO-1, and try to get them to divulge the following information:
1) Who the person answering the phone is, name and title.
2) What their business name and its mailing address are.
3) Who sold them the list that has your (our) name on it,
or how they otherwise acquired it.
4) Whether they realize that they are in violation of Title
47, Section 227 of the United States Code.
In fact, considering that it's on their nickel, you might even want to
call them back once or twice to confirm whatever story they previously
gave you. :-)
Their DNS record is enclosed at the end. Note that at least the (516)
626-2090 number is dysfunctional, as is its replacement. I have also
sent mail about this to abuse@alter.net, who seems to be their ISP,
because in theory, what they're doing is in violation of AlterNet's
acceptable use policy. AlterNet has not yet responded.
If anyone does in fact call these highly unsavvy and unsavory characters,
please send me email relating the story. I'll summarize the anecdotes
and results.
thanks,
--tom
Return-Path: email@savvy.com
Received: from pub.savvy.com ([204.177.159.9]) by jhereg.perl.com (8.7.4/8.7.3) with SMTP id IAA03612 for <perlbug@perl.com>; Tue, 11 Feb 1997 08:10:34 -0700
Received: (from email@localhost) by pub.savvy.com (8.6.11/8.6.11) id KAA24208 for perlbug@perl.com; Tue, 11 Feb 1997 10:01:35 -0500
Date: Tue, 11 Feb 1997 10:01:35 -0500
Message-Id: <199702111501.KAA24208@pub.savvy.com>
From: ibn@savvy.com
Reply-To: ibn@savvy.com
To: perlbug@perl.com
Subject: Internet Banner Network
Dear Webmaster,
Let me take this time to introduce you to the Internet Banner Network.
Being a website owner I'm sure you are familiar with the concept
of selling ad space on your site to generate revenue. However, if you've
tried, you've quickly found out that it's not so easy to find paying
advertisers.
Joining the IBN may be the best way to get your foot in the door and grab a
piece of the advertising pie. We find the advertisers. We display the ads.
We collect the money and remit your share directly to you. Here's how it
works:
As a user accesses an IBN member Website, an ad banner is automatically
and dynamically displayed matching an advertiser's target audience profile.
Your site starts generating revenue the moment you become a member of the IBN
and begin displaying ad banners. Letting the IBN find the advertisers for
your site allows you to concentrate on content, to attract more viewers,
and therefore, more banners and more revenue.
If you would like to join the IBN you must first apply and be approved.
Approval of all sites is based on content and traffic. There is no fee
required for joining the IBN. After approval, all you have to do is make
a simple change to the HTML of your Web site's homepage. The IBN will
verify that everything is functioning properly and activate your site.
When your site begins displaying IBN ad banners, you will be generating
revenue.
In addition, the IBN never wastes space or an opportunity. If there is no
advertiser's banner to display at a member site we use it as an
opportunity to advertise another IBN member site.
If you are interested in joining the IBN, visit our Web site
at: http://www.banner-net.com and fill out the order form or call
us at : 1-800-WEBPRO-1.
Regards,
Internet Banner Network
ibn@savvy.com
http://www.banner-net.com
Here's the DNS record:
[rs.internic.net]
USIC (SAVVY-DOM)
48 Harbor Park Drive
Port Washington, NY 11050
Domain Name: SAVVY.COM
Administrative Contact:
Pasternack, David (DP55) dave@SAVVY.COM
(516) 626-2090
Technical Contact, Zone Contact:
Schwartz, Phil (PS50) phil@OPEN-MIND.COM
516 255 0500
Record last updated on 20-Dec-96.
Record created on 10-Feb-94.
Domain servers in listed order:
NS.UU.NET 137.39.1.3
UUCP-GW-1.PA.DEC.COM 16.1.0.18 204.123.2.18
UUCP-GW-2.PA.DEC.COM 16.1.0.19
--
Tom Christiansen tchrist@perl.com
Logic is a systematic method of coming to the wrong conclusion with confidence.
------------------------------
Date: Tue, 11 Feb 1997 16:33:22 GMT
From: stijnvd@cwi.nl (Stijn van Dongen)
Subject: wrapping comment-text
Message-Id: <stijnvd.855678802@news.cwi.nl>
Hi, below I include a little script that
I wrote for wrapping large pieces of comment text in which each line
is preceded by a comment delimiter -- as is the case with non-pod
comments in perl. The wrapper needs one line to know the delimiting
pattern. The virtue of this is that passing this pattern as argument
can be a bit awkard. The script can be used conveniently in VI,
analoguous to fmt. Everything is totally basic. Comments are
welcome. Is there a well-known program that does all this already
(on the less welcome side)?
Regards,
Stijn van Dongen
stijnvd@cwi.nl
#!/usr/local/bin/perl
##
## [parwrap] should really have been named commentwrap, but I could not
## resist the temptation. This script reads in one argument, the desired
## width of the output text, *not* counting the left margin. Proceeds
## with reading input text from STDIN. The first line of STDIN should be
## a prefix of all other lines to follow. This line is the left margin;
## initially it is removed from all other lines in STDIN. The script
## returns the text found to the right of the margin, formatted with
## width as specified, and with the leftmargin again prepended as the
## first line and as prefix of the formatted lines. Calling it from VI
## is analoguous to calling fmt. E.g, the following paragraph resulted
## from putting '!}parwrap -50' in command mode at the top of this
## paragraph, causing the last sentences of this newly made paragraph to
## be nonsensical.
##
## [parwrap] should really have been named
## commentwrap, but I could not resist the
## temptation. This script reads in one argument,
## the desired width of the output text, *not*
## counting the left margin. Proceeds with reading
## input text from STDIN. The first line of STDIN
## should be a prefix of all other lines to follow.
## This line is the left margin; initially it is
## removed from all other lines in STDIN. The script
## returns the text found to the right of the
## margin, formatted with width as specified, and
## with the leftmargin again prepended as the first
## line and as prefix of the formatted lines.
## Calling it from VI is analoguous to calling fmt.
## E.g, the following paragraph resulted from
## putting '!}parwrap -50' in command mode at the
## top of this paragraph, causing the last sentences
## of this newly made paragraph to be nonsensical.
use strict;
my $textwidth = shift;
unless ($textwidth =~ s/^\-(\d+)$/$1/) {die "Input nrof columns\n"; }
my @content = <STDIN>;
my $margin = shift @content;
chomp $margin;
for (@content) {s/^\Q$margin\E//; }
my $newcontent = wrap ($textwidth, join ("", @content));
$newcontent =~ s/^/$margin/mg;
print "$margin\n$newcontent\n";
sub wrap
{
my $columns = shift @_;
my $old = shift @_;
my $new;
my $suffix;
my $bound = $columns - 1;
($suffix = $old) =~ s/\n/\ /g;
$suffix .= ' ';
## be smart, otherwise the last word will end
## up singularly on the last line, not unlike
## it is the case in Text::Wrap if I am not
## mistaken.
while ($suffix =~ s/^(.{0,$bound})\s//) {
$new .= $1 . "\n";
}
return $old if $suffix;
chop $new;
return $new;
## no trailing newline in return value.
##
}
------------------------------
Date: 11 Feb 1997 11:01:40 -0500
From: daku@nortel.ca (Mark Daku)
Subject: Re: XS problem - Can't find loadable object
Message-Id: <esqzpxb8h7f.fsf@nortel.ca>
"Geoff Mottram" <minaret@sprynet.com> writes:
> > I am experimenting with the XS tutorial (xstut). Following alone with
> > example one, I run across an error when I try to execute the script - it
> > complains about not being able find a loadable object.
>
> I recall that when I ran through the tutorial the same thing happened to
> me. I may have had to fiddle with the @INC array in order for the ".pm"
> perl module to be found and I maybe also some sort of PERLLIB variable or
> some thing like that for it to find the ".so" library with the object
> module. One thing is for sure, the tutorial did not work as documented.
>
Agreed the docs need updating in this regard. I curtainly had my
share of grief with the tuts.
I would recommend a comment on how to test in the local directory. I
do like having to install a bad extension over and over again just to
test it. Why do the install that is the only way the default set up
worked without having to muck with the .pm file more than mentioned.
Mark Daku
daku@nortel.ca
------------------------------
Date: 8 Jan 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Jan 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.
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 V7 Issue 927
*************************************