[8417] in Perl-Users-Digest
Perl-Users Digest, Issue: 2034 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 5 15:17:25 1998
Date: Thu, 5 Mar 98 12:00:43 -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 Thu, 5 Mar 1998 Volume: 8 Number: 2034
Today's topics:
Add int, convert to string, substitute. HELP! (John Robson)
Re: Are perl $SIG{} handlers inherently unsafe? (Ken Fox)
Re: BIG integers (Jim Allenspach)
Re: BIG integers <zenin@best.com>
Building an array from a subroutine <bmaillet@cisco.com>
Re: Change Unix environment variable using Perl <barnett@houston.Geco-Prakla.slb.com>
Re: commandline arguments win32? (Kevin B Cohen)
Create directory from input in file? (John Robson)
Re: Displaying subdirectories and not filenames (Abigail)
Re: Formatting telephone numbers - How to? <gold@busybox.spam>
Re: Formatting telephone numbers - How to? <rets@meta3.com>
How to run a shell script which sets env vars? <yong@columbia.shell.com>
Re: How to run a shell script which sets env vars? <mph@pobox.com>
Re: How to use Perl Hashes? <jdporter@min.net>
Re: in the name of Baby Jesus PLEASE HELP ME... <jdporter@min.net>
Re: in the name of Baby Jesus PLEASE HELP ME... <mishra.aditya@emeryworld.com>
Re: isn't perl clever: short-circuit logic (Joe McMahon)
Re: isn't perl clever: short-circuit logic (Kevin B Cohen)
Musings on linking 'use' to CPAN.pm schwern@starmedia.net
Re: Newbie's question about package <jdporter@min.net>
Re: padding a file -- Better way?? (Craig Berry)
Re: padding a file -- Better way?? <barnett@houston.Geco-Prakla.slb.com>
Re: padding a file -- Better way?? <jdporter@min.net>
Pattern matching? <miller@bigsky.net>
Re: Perl (CGI)/database <jdporter@min.net>
Re: perl for win95? <earlw@kodak.com>
Re: Perl script from Unix to Win32 (Kevin B Cohen)
Re: QUIZ: answer and hash slice tutorial <cmargoli@world.northgrum.com>
Re: RegEXP HELP NEEDED <dballing@speedchoice.com>
Re: Special Characters <merlyn@stonehenge.com>
Re: Stripping (Most) HTML tags <jsd@hudsucker.gamespot.com>
Re: Sybase <sfarrell+usenet@farrell.org>
Re: The -w switch (was Re: better way to do this?) <joseph@5sigma.com>
Re: Variable not returning values (Monee C. Kidd)
Re: What is PERL? Learn JAVA instead? <zenin@best.com>
Re: What is PERL? Learn JAVA instead? <zenin@best.com>
Re: What is PERL? Learn JAVA instead? <evan@garrett.hpl.hp.com>
Re: What is PERL? Learn JAVA instead? (Ilya Zakharevich)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 5 Mar 1998 18:04:18 GMT
From: as646@FreeNet.Carleton.CA (John Robson)
Subject: Add int, convert to string, substitute. HELP!
Message-Id: <6dmpf2$7er@freenet-news.carleton.ca>
I have an input file that looks like this:
"0001","widget a"
"0002","widget b"
"0586","widget z"
I would like to convert "0001","0002" and "0586" to numbers, add
1000 to them, and then convert the numbers back to strings "1001",
"1002" and "1586".
Here's my attempt:
s/"([0-9][0-9][0-9][0-9])"/$1+1000/ge
You can assume that the numbers are always 4-char long (fixed length field).
The substitution gives this solution:
1001,"widget a"
1002,"widget b"
1586,"widget z"
But I want to see the numbers in quotes " " !
The numbers should be thought of as strings.
How do I do this? Is there a number-to-string function I can use in my
substitution expression? and then do a string concatenation . ?
Can anyone help?
Thanks!
------------------------------
Date: 5 Mar 1998 18:42:22 GMT
From: kfox@pt0204.pto.ford.com (Ken Fox)
Subject: Re: Are perl $SIG{} handlers inherently unsafe?
Message-Id: <6dmrme$dde4@eccws1.dearborn.ford.com>
John Porter <jdporter@min.net> writes:
> Gabor wrote:
> > In comp.lang.perl.misc, Randal Schwartz <merlyn@stonehenge.com> wrote :
> > # Two SIGCHLDs could come in before it's your turn for CPU ...
> > # Dangerous Code. Don't do this.
> >
> > Is this only true for Perl? In C I can use sigaction and block
> > signals, the kernel queues them, while I am in the handler.
^^^^^^^^^^^^^^^^^^
Are you sure? Run a test to really excercise this and I'll bet you
find out that you don't get as many SIGCHLDs delivered as you have
children terminate.
> The danger is not in when you're in the handler, it's when you're
> blocked (not in the run queue).
The danger is when a SIGCHLD gets delivered when there is already
a SIGCHLD pending. At least some, probably many, Unix variants
don't bother to queue the SIGCHLDs. If you write a SIGCHLD handler
and don't loop on wait(), you've got buggy code. Even in C.
This could happen because your program is blocked, ready to run
but not running, or if you temporarily disable signals, e.g. while
you're in the signal handler on a SVR4 box.
- Ken
--
Ken Fox (kfox@ford.com) | My opinions or statements do
| not represent those of, nor are
Ford Motor Company, Powertrain | endorsed by, Ford Motor Company.
Analytical Powertrain Methods Department |
Software Development Section | "Is this some sort of trick
| question or what?" -- Calvin
------------------------------
Date: 5 Mar 1998 11:49:46 -0600
From: jima@MCS.COM (Jim Allenspach)
Subject: Re: BIG integers
Message-Id: <6dmojq$cv@Mercury.mcs.net>
>Does anybody
>know of a module, etc, for handling BIG integer numbers with Perl?
Like, say... Math::BigInt ? I found that one doing a quick search
on the Perl modules list[1]. Try it at home, kids!
jma
[1] http://www.perl.com/CPAN/modules/00modlist.long.html
--
Jim Allenspach Laziness. Impatience. Hubris.
jima at mcs dot com
Chicago IL It's great to be a Perl programmer.
------------------------------
Date: 5 Mar 1998 17:57:54 GMT
From: Zenin <zenin@best.com>
Subject: Re: BIG integers
Message-Id: <889121011.853960@thrush.omix.com>
[ posted & mailed ]
Jeff Hay <jrhay@lanl.gov> wrote:
: I'm working on a reporting system based in Perl, for which I need to add
: really big integers - the results of these additions overflow the
: integer range of my version of Perl (running on SunOS). Does anybody
: know of a module, etc, for handling BIG integer numbers with Perl?
: Would be good...
Math::BigInt
It's in the standard distribution, at least for 5.00404.
See perldoc Math::BigInt for info.
--
-Zenin
zenin@best.com
------------------------------
Date: Thu, 05 Mar 1998 12:40:01 -0500
From: Bob Maillet <bmaillet@cisco.com>
Subject: Building an array from a subroutine
Message-Id: <34FEE370.EC3AF269@cisco.com>
I have written a subroutine which will print out directories users have
permissions to. When I run it as a small program and tell it to print
the directories it operates as it should - only printing the directories
which the user has permissions. When I tell it to return the variable
(directory) using: return $check it only returns the first iteration of
the loop. Lastly I have tried to create an array which the variable can
be stored and then read from the rest of the program but this produces
all files in the subdirectory to be displayed - this part is strange
because I have put the push command inside a subroutine.
What I would like is to create an array from the subroutine which
contains only the filnames with permissions. Below is the subroutine
which works but the array part is giving me grief..any suggestions?
Bob
sub findDirs{
opendir (DIR, "D:\\webber");
while (defined($check = readdir(DIR))){
if ($check=~/^[a-zA-Z]/){
$DIR_list = "D:\\webber\\$fnames\\authors.pwd";
open (FILE, $DIR_list);
@fun = <FILE>;
close(FILE);
foreach (@fun){
if (/$userid/){
push (@dirlist, $check);
}
}
}
}
}
------------------------------
Date: Thu, 05 Mar 1998 12:17:20 -0600
From: Dave Barnett <barnett@houston.Geco-Prakla.slb.com>
Subject: Re: Change Unix environment variable using Perl
Message-Id: <34FEEC30.ED34334@houston.Geco-Prakla.slb.com>
Snow White wrote:
>
> In article <x6eogzmm2vz.fsf@pearl.fi.bear.com> on 04 Mar 1998 18:50:56 -0500,
> Justin Vallon <vallon@pearl.fi.bear.com> wrote:
>
> > Environment variables are only passed down to children. They are
> > never passed up to parents.
>
> > That is, system runs your command in a shell, which changes the
> > value of MY_EV, then exits. perl's variables are not affected.
>
<snip>
> Will this work if I run a process using backquotes?
>
It should.
> It does not seem to with Perl5.003 under Solaris.
>
I'm using 5.004_01, and it seems to work fine.
> I have developed some code running Perl5.004 under OS/2
> which includes statements like:
>
> ...
>
> $ENV{'SOMETHING'} = "somevalue";
>
> ...
>
> $Result = `perl -x $Program`;
>
> ...
>
> but the script represented by $Program does not see the new value
> of SOMETHING
Perhaps you're not asking for the value correctly?
> when running under Solaris (SunOS 5.5) though it does
> under OS/2. I mentioned this to a colleague who replied that she
> thought it was a problem with the way Solaris handles its
> environment. Is she right? Anyone know what is wrong here?
Below are two scripts I called junk43, and junk44:
junk43:
#!/usr/local/bin/perl -w
#
$ENV{'SOMETHING'} = "somevalue";
$program = "./junk44";
$Result = `perl -x $program`;
print "junk43: ", $Result, "\n";
__END__
junk44:
This is some
junk
I typed in
before my
actual perl code
#!/usr/local/bin/perl -w
#
print "junk44: ", $ENV{'SOMETHING'};
__END__
This is my output:
dapd7:barnett [43] junk43
junk43: junk44: somevalue
dapd7:barnett [44]
That is exactly what I would have expected. If I do echo "$SOMETHING"
from the command line after the perl script(s) complete (command # 44),
SOMETHING is undefined, as it should be.
HTH
Dave
--
"Security through obscurity is no security at all."
-comp.lang.perl.misc newsgroup posting
------------------------------------------------------------------------
* Dave Barnett U.S.: barnett@houston.Geco-Prakla.slb.com *
* DAPD Software Support Eng U.K.: barnett@gatwick.Geco-Prakla.slb.com *
* Schlumberger Geco-Prakla (281) 596-1434 (Office Number) *
* 1325 S. Dairy Ashford (281) 596-1807 (Fax) *
* Houston, TX 77077 *
------------------------------------------------------------------------
------------------------------
Date: 5 Mar 1998 13:38:23 -0500
From: kcohen@julius.ling.ohio-state.edu (Kevin B Cohen)
Subject: Re: commandline arguments win32?
Message-Id: <6dmrev$ac2@julius.ling.ohio-state.edu>
In article <34FEDA1B.542C58C3@rocketmail.com>,
syrnyk <syrnyk@cadvision.com> wrote:
>I'm just learning perl and have tried to find a answer to this problem
>in the faq's, nevertheless, I am still wondering what the best way to
>provide command line arguments to a perl script called on a win32 system
>is.
>What are the options?
if you're using some sort of VB wrap-around, the -s command line
option works. this lets you give values to variables on the command
line. e.g.:
perl -s myscript.pl -iambic="daDA" -trochaic="DAda" -shakespeare=1
this kicks off a script called myscript.pl, and initializes the
following variables with the following values:
$iambic # daDA
$trochaic # DAda
$shakespeare # 1
you don't have to use this to pass a command line from VB--you can use
it on any command line. i just know that it works with VB, and
mention it cuz you're on a win32 system.
otherwise, use the contents of the @ARGV array. the first thing after
the script name is $ARGV[0].
perl myscript.pl daDA DAda 1
$iambic = $ARGV[0];
$trochaic = $ARGV[1];
$shakespeare = $ARGV[2];
OR
$iambic = shift(@ARGV);
$trochaic = shift(@ARGV);
etc.
i like the second better, 'cause it lets me change my mind easily
about what i want on the command line, and what order i want it in.
kev
------------------------------
Date: 5 Mar 1998 18:51:31 GMT
From: as646@FreeNet.Carleton.CA (John Robson)
Subject: Create directory from input in file?
Message-Id: <6dms7j$8sg@freenet-news.carleton.ca>
I have an input file that looks like this:
"1000","c:\dir0\file0.txt"
"1001","d:\dir1\file1.txt"
"1500","c:\dir2\file2.txt"
How do I read the first field of each line, create a directory with the
name of that first field, read the second field of the line, and then copy
the actual file from the second field into the directory created (from 1st
field) ???
For example, in the first line of the input file, the Perl program
should do this:
create the directory named 1000, search for and copy the file
c:\dir0\file0.txt to the directory 1000.
and so on...
create the directory named 1001, search for and copy the file
d:\dir1\file1.txt to the directory 1001.
How do I do this for Perl in Windows 95 or DOS ? In Unix?
Problem 2: How do I do the reverse? That is, read a directory and its
subdirectories and all the files, produce sequentially a number starting with
1000 and then assign that unique number to a file (with its full path) in
a file.
Help! and thanks! :)
------------------------------
Date: 5 Mar 1998 18:36:55 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Displaying subdirectories and not filenames
Message-Id: <6dmrc7$edk$2@client2.news.psi.net>
Koos Pol (koos_pol@bigfoot.com) wrote on 1647 September 1993 in
<URL: news:34FECB59.F7454FCC@bigfoot.com>:
++
++ Communciator is what I have been given by our admins.
++
++ S.C. Pol tel: +31 20 3116122
++ PC Systems Administrator email: Koos_Pol@nl.compuware.com
Say, what was the name of the admin again?
Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=new Math::BigInt+qq;$^F$^W783$[$%9889$^F47$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W98$^F76777$=56;;$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V%$^U;$^V/=$^U}while$^V!=$^W'
------------------------------
Date: Thu, 05 Mar 1998 10:05:22 -0800
From: Chris Goldman <gold@busybox.spam>
Subject: Re: Formatting telephone numbers - How to?
Message-Id: <34FEE962.56B23F32@busybox.spam>
Joanne,
You can add the dashes in place, without using an array, by using the
'substr' function. Check page 228 of the Camel book. Here's an
example:
----------
#!/usr/bin/perl -w
my $num = '4155551234';
substr($num, 6, 0) = '-';
substr($num, 3, 0) = '-';
print $num . "\n";
----------
Unless you insert the dashes in reverse order, you'll be pushing the
future insertion points forward. It's too early in the morning for me
to phrase that properly. Try switching the 'substr' statements, and
you'll see what I mean.
Without wanting to sound pedantic, you probably only want to post a
question like this to comp.lang.perl.misc, since it's not about modules
or tk. At best, no one will answer your question; at worst, you'll get
a lot of 'not appropriate to this newsgroup, and RTFM' replies. :)
Hope this helps!
Chris
Joanne James wrote:
>
> Hi. I'm helping out on a project using Perl and am learning as I go. I've
> been trying to show telephone numbers (numbers only are stored on database
> -no
> dashes) on an html page with dashes inserted. The database contains both
> US and international phone numbers. I want to put in dashes as in the
> following:
> 999-999-9999 in all cases. I just need an example. Assume you are getting
> a field from an Oracle database and want to put it into an array (I
> presume), then insert the dashes. How would you do it? I have been trying
> for hours to get this to work! I would appreciate some feedback. Thanks
> for the
> help!
--
Christopher D. Goldman | Busy Box Productions
gold@busybox.spam | www.busybox.com
'Perfection is achieved not when there is nothing more to add, but
rather when there is nothing more to take away.' -- Antoine de
Saint-Exupery
------------------------------
Date: Thu, 05 Mar 1998 10:51:36 -0600
From: Ken Holm <rets@meta3.com>
To: Joanne James <jjames@netguild.com>
Subject: Re: Formatting telephone numbers - How to?
Message-Id: <34FED818.6B4662CB@meta3.com>
Joanne James wrote:
>
> Hi. I'm helping out on a project using Perl and am learning as I go. I've
> been trying to show telephone numbers (numbers only are stored on database
> -no
> dashes) on an html page with dashes inserted. The database contains both
> US and international phone numbers. I want to put in dashes as in the
> following:
> 999-999-9999 in all cases. I just need an example. Assume you are
Here's how I'd do something like that:
################
sub phoneCheck {
my $Item = shift;
$Item =~ s/^\s+|\s+$//g;
my $length = length $Item;
return (0) if $length < 7;
if ($length == 7) {
if ($Item =~ /\D/) {
return(0);
} else {
my @Digits = split(//, $Item);
$Item = join "", @Digits[0..2], "-", @Digits[3..6];
return($Item);
}
}
if ($Item =~ /^\d\d\d(\-|\.)\d\d\d\d$/) {
$Item =~ s/\D//g;
my @Digits = split(//, $Item);
$Item = join "", @Digits[0..2], "-", @Digits[3..6];
return($Item);
}
if ($Item =~ /^\(?\d\d\d\)?(\-|\.)?\d\d\d(\-|\.)?\d\d\d\d$/) {
$Item =~ s/\D//g;
my @Digits = split(//, $Item);
$Item = join "", "(", @Digits[0..2], ")", @Digits[3..5], "-",
@Digits[6..9];
return($Item);
}
return (0);
}
You'd invoke as follows:
my $phone_number = phoneCheck(5551234);
$phone_number would be set to 555-1234. There's more to this function
than just that though.
-K
------------------------------
Date: Wed, 04 Mar 1998 17:53:19 -0600
From: Yong Huang <yong@columbia.shell.com>
Subject: How to run a shell script which sets env vars?
Message-Id: <34FDE96F.17426FAD@columbia.shell.com>
My question boils down to this. The shell script qq.sh is
#!/bin/sh
This=That
export This
and I want to set This by running a Perl script which may be
#!/usr/bin/perl -w
exec '. qq.sh';
or change the exec line to system '. qq.sh';
But still at the system prompt running echo $This gives Undefined
variable. Is there any way to set environment variables by calling the
first Perl script. If yes, how do I modify the two scripts?
A related question: can %ENV modify parent process environment
variables?
In fact my real work is done in a csh environment and I have to stick to
it because a long existing csh script sets env vars for the bulk part of
my work. But talking about sh sounds more native to Perl.
The reason I have to go through this route (a Perl calling a shell
script) is a CGI issue.
Thanks for any reply.
Yong
Email:yong@columbia.shell.com
------------------------------
Date: 5 Mar 1998 19:43:38 GMT
From: Matthew Hunt <mph@pobox.com>
Subject: Re: How to run a shell script which sets env vars?
Message-Id: <6dmv9a$1ncm@r02n01.cac.psu.edu>
[ Posted and mailed. ]
In article <34FDE96F.17426FAD@columbia.shell.com>,
Yong Huang <yong@columbia.shell.com> wrote:
> A related question: can %ENV modify parent process environment
> variables?
No, that is not possible, and it's also why the code you described
earlier didn't work.
One common solution is to have your Perl (or C, or whatever) program
emit the value you want on standard output, and write your script
thus:
BLAH=`myprogram`
or
senenv BLAH `myprogram`
(whichever is appropriate for your shell).
------------------------------
Date: Thu, 05 Mar 1998 14:30:21 -0500
From: John Porter <jdporter@min.net>
Subject: Re: How to use Perl Hashes?
Message-Id: <34FEFD4D.7A73@min.net>
sspiegle@crcg.edu wrote:
>
> Hi,
>
> I'm a newbie perl programmer tyring to learn about what hashes are and how to
> use them. I couldn't open a link to a PERLFAQ7 link on the web that I located
> via a search. Can someone point me to a good link for that? Also, has any one
> seen a good tutorial that deals with this?
If you have perl, you have perlfaq7, and all the rest of the docs,
several
megs worth.
You don't need to get at it through the web. You can use the perldoc
command at your command prompt:
perldoc perlfaq7
If you really want to waste time retrieving this stuff over the net,
you can go to www.perl.com and check out the "documentation" section.
There is also a section on tutorials there.
hth,
John Porter
------------------------------
Date: Thu, 05 Mar 1998 13:47:54 -0500
From: John Porter <jdporter@min.net>
Subject: Re: in the name of Baby Jesus PLEASE HELP ME...
Message-Id: <34FEF35A.23E8@min.net>
Swamp Midget wrote:
>
> Would someone please tell me how I can call a C executable from a PERL
> script. I know I'm an idiot. Please help.
Human creativity never ceases to amaze me.
1. "I have a perl question"
2. "I've read the FAQ, but ..."
3. "I've read the FAQ, the Llama, the Camel, the Panther, the Pearl,
the IG2CGI, WT, and FMTEYEWTK, but ..."
And now this.
John Porter
------------------------------
Date: Thu, 5 Mar 1998 11:16:08 -0800
From: "Mishra, Aditya" <mishra.aditya@emeryworld.com>
Subject: Re: in the name of Baby Jesus PLEASE HELP ME...
Message-Id: <6dmrm8$pdo@ljcqs003.cnf.com>
Buy perl for dummies
......
#!/usr/local/bin/perl
system(<pathtoyourexecutable>)
e.g. your executable is called a.out an resides in /tmp
then
it would be
system("/tmp/a.out")
If you are a prisoner of the Evil Empire and your dummy.exe resides in
c:\tmp the
command would be
system("c:\tmp\dummy.exe")
May the force be with you!
------------------------------
Date: Thu, 05 Mar 1998 12:53:48 -0500
From: joe.mcmahon@gsfc.nasa.gov (Joe McMahon)
Subject: Re: isn't perl clever: short-circuit logic
Message-Id: <joe.mcmahon-0503981253480001@prtims.stx.com>
># this first short-circuit line sets $onset if there be one, and puts the
>syllable into $rime # if there be'n't one.
>
>(($onset) = /^([$Conset]+)/) || ($rime = $syllable);
>
># the next short-circuit line takes care of setting the $rime in the normal
>case, i.e. # where there WAS an onset consonant.
>
>($rime) || ($rime = $');
>
>yes, i think perl IS clever, and i delight in it. question is, am I clever?
>is there a more efficient way of defining $onset and $rime?
How about
($onset,$rime) = /^([$Conset]+)(.*)$/ || ($rime = $syllable, $onset = "");
?
--- Joe M.
------------------------------
Date: 5 Mar 1998 13:57:45 -0500
From: kcohen@julius.ling.ohio-state.edu (Kevin B Cohen)
Subject: Re: isn't perl clever: short-circuit logic
Message-Id: <6dmsj9$ak5@julius.ling.ohio-state.edu>
In article <34FED346.CA3@min.net>, John Porter <jdporter@min.net> wrote:
>I think your "editing for clarity" has gone over to the dark side. :-)
*sigh* i'm afraid that's what happens when english majors are allowed
to program.
>That pattern match is implicitly matching $_, so I assume you set
>$syllable = $_ somewhere above that point.
yup.
>I also assume $Conset = $InitialConsonants, right?
yeah, sorry.
>I guess I'd do it this way:
>
> my( $onset, $rime ) = /^([$Conset]*)(.*)$/;
yep, that's much better.
now, if you're feeling REALLY charitable, i'll show you my code for
parsing syllables....
kevin
------------------------------
Date: Thu, 05 Mar 1998 11:59:44 -0600
From: schwern@starmedia.net
Subject: Musings on linking 'use' to CPAN.pm
Message-Id: <6dmp50$57m$1@nnrp1.dejanews.com>
One of the loudest arguments I always hear against using Perl modules is "what
if the user doesn't have module X installed???" Currently there's two options
there, make the user install the module themselves (after they decypher the
cryptic "Cannot find ... in @INC....") or bundle a copy of the module with
your program (assuming that the module is pure Perl.)
Okay... so what if there was a pragma/function which was used like...
CPAN-use(Module, [MinimumVersionNumber, [verbose?] ]);
Which acted just like a normal use, except that if the given Module cannot be
found it (or it is too old) will go off, download and install the necessary
module from CPAN (and any other necessary modules for this module), prompting
the user for a local perl directory to put stuff it if it can't use the
default install directory (due to permissions or whatever). It will also
modify itself, somehow, to remember to look in that local Perl directory next
time.
(Verbose simply decides if the program should do all this quietly, or prompt
the user for confirmation/interaction.)
The questions now are basic.
Is it technically feasible? I see no reason why not.
Is it ethical? Would this be providing waaaaaaay too much power for the
script to do rude things to your computer?
Is it worth it? Or will this simply be supplanted by some other tech I don't
know about (Penguin?)
And of course... should I go ahead and write it?
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Thu, 05 Mar 1998 13:58:44 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Newbie's question about package
Message-Id: <34FEF5E4.21C4@min.net>
xrfang@technologist.com wrote:
>
> 1. Is @ISA used only in oop or not? I wrote a simple module and if I do not
> write @ISA=qw(Exporter) all my fuctions are not usable. Why?
@ISA is a special array intrinsic. It is only meaningful for
"object-oriented" programming. That is how inheritance is implemented.
If you don't use oop, or at least if you don't use inheritance, you
don't need @ISA.
> 2. Why should I use "qw"? can I use @EXPORT=(suba,subb,subc...)???
If you don't like how
@EXPORT = qw( sub1 sub2 sub3 );
looks, you can of course say
@EXPORT = ( 'sub1', 'sub2', 'sub3' );
Look up how qw() works in man perlop (or perldoc perlop).
> 3. Many other questions (may be silly ones), the most important is, where to
> find document for such things as @ISA, @EXPORT, @EXPORT_OK etc. Especially
> that I read from the perltoot or other man pages that there's a "Exporter" man
> page and a "AutoLoader" man page, but when I typed man Exporter, the system
> said no such man pages. Where to find them???
If man Exporter doesn't find it, try perldoc Exporter. If that doesn't
find it, then your perl installation is screwed up.
@EXPORT, @EXPORT_OK, and the like are special to the Exporter.pm module.
Unless you "use Exporter", these variables won't mean anything special.
hth,
John Porter
------------------------------
Date: 5 Mar 1998 18:36:04 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: padding a file -- Better way??
Message-Id: <6dmrak$mj8$1@marina.cinenet.net>
Douglas Cordero (dcordero@giss.nasa.gov) wrote:
: I wrote a subroutine to space pad a variable length
: text array to 80 left justified characters.
: Does it look OK? Is there a better way?
Your code looks okay, but this is probably more efficient and Perlish:
my @padded = map { sprintf('%-80.80s', $_) } @unpadded;
HTH...
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Thu, 05 Mar 1998 12:52:16 -0600
From: Dave Barnett <barnett@houston.Geco-Prakla.slb.com>
Subject: Re: padding a file -- Better way??
Message-Id: <34FEF460.73A2AFA5@houston.Geco-Prakla.slb.com>
Douglas Cordero wrote:
>
> Hi all:
> I wrote a subroutine to space pad a variable length
> text array to 80 left justified characters.
> Does it look OK? Is there a better way?
> Is there a module or something that has this built-in?
>
> Thx.
>
> sub padder {
> my( @val ) = @_;
> my( @paddedval );
> @paddedval = ();
> foreach (@val) {
> @paddedval = (@paddedval, sprintf "%-80.80s", $_ );
> }
> return @paddedval;
> }
Well, may not be any better, but pack is very useful for this type of
thing:
sub padder {
my (@val) = @_;
my ($i) = 0;
for ( ; $i < scalar(@val); $i++) {
print "$val[$i]\n";
$val[$i] = pack("A80", $val[$i]);
}
return @val;
}
Have a look at pack. Could prove useful.
Dave
--
"Security through obscurity is no security at all."
-comp.lang.perl.misc newsgroup posting
------------------------------------------------------------------------
* Dave Barnett U.S.: barnett@houston.Geco-Prakla.slb.com *
* DAPD Software Support Eng U.K.: barnett@gatwick.Geco-Prakla.slb.com *
------------------------------------------------------------------------
------------------------------
Date: Thu, 05 Mar 1998 14:13:49 -0500
From: John Porter <jdporter@min.net>
Subject: Re: padding a file -- Better way??
Message-Id: <34FEF96D.6EB3@min.net>
Douglas Cordero wrote:
>
> sub padder {
> my( @val ) = @_;
> my( @paddedval );
> @paddedval = ();
> foreach (@val) {
> @paddedval = (@paddedval, sprintf "%-80.80s", $_ );
> }
> return @paddedval;
> }
Why do you have 80.80 ??? This works the same for me:
sprintf("%-80s",$_)
That's a horrible way to append something to a list.
What you *really* meant was push:
push( @paddedval, sprintf( "%-80s", $_ ) );
(I like parens. Randal will shoot me.)
Apart from that, it looks ok, if you like the look of a C program.
Now lets make that subroutine a one-liner:
sub padder {
map { sprintf("%-80s",$_) } @_;
}
Now if you want something that looks more like perl and less like C,
you could have
map { s/.*/$&.(' 'x(80-length($&)))/e } @_;
or
map { $_.(' 'x(80-length)) } @_;
Man, I love this kind of question.
John Porter
------------------------------
Date: Thu, 05 Mar 1998 12:24:56 -0700
From: "Keith L. Miller" <miller@bigsky.net>
Subject: Pattern matching?
Message-Id: <34FEFC08.E6A308DA@bigsky.net>
Okay, I can not figure this out. Below is a snippet of code form a
script I'm writing. it searches throught the shadow password file for a
specific string (stored in $FORM{'USER'}). For the most part, it works
great, however there is one little snag.
Let's say the user name is miller. It will search through and ignore
names such as:
gmiller
klmiller
vnmiller1
but, it returns
miller
j-miller
Does anyone know why?
------------------------------------
open(PASS, "/etc/passwd");
while (<PASS>){
@fields = split(/:/, $_);
if (/\b$FORM{'USER'}\b/){
print "$_<BR>";
}
}
close (PASS);
print @user;
------------------------------
Date: Thu, 05 Mar 1998 14:20:01 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Perl (CGI)/database
Message-Id: <34FEFAE1.68CE@min.net>
Gholam Reza Azimi wrote:
>
> [sybase]
Goto the CPAN at
ftp://ftp.cdrom.com/pub/perl/CPAN/CPAN.html
and look at DBD and DBI.
hth,
John Porter
------------------------------
Date: Thu, 05 Mar 1998 14:54:28 -0500
From: Earl Westerlund <earlw@kodak.com>
Subject: Re: perl for win95?
Message-Id: <34FF02F4.2298@kodak.com>
brain Lorraine wrote:
>
> n-e-one know where i can dload perl for win95?
>
> --
> peace,
> brain
> www.gl.umbc.edu/~blorra1
http://www.perl.com
--
+-----------------+----------------------------------------+
| Earl Westerlund | Kodak's Homepage: http://www.kodak.com |
+-----------------+----------------------------------------+
| The opinions expressed herein are mine and mine alone |
| (most people don't seem to want them anyway) |
+----------------------------------------------------------+
------------------------------
Date: 5 Mar 1998 14:06:29 -0500
From: kcohen@julius.ling.ohio-state.edu (Kevin B Cohen)
Subject: Re: Perl script from Unix to Win32
Message-Id: <6dmt3l$aqk@julius.ling.ohio-state.edu>
In article <6dl03b$8ce@news.seed.net.tw>,
DaveZhu <davezhu@notes.gcmail.com> wrote:
>I found some Unix-base scripts but I'd like to run those scripts on Win32
>system like NT4.0, can this be done ?
mostly. i've found that i generally need to make some modifications
to large scripts (not large, i guess, but rather non-trivial ones) to
get them to run on NT. it's certainly possible, though.
kevin
------------------------------
Date: Thu, 5 Mar 1998 17:58:01 GMT
From: Charles Margolin <cmargoli@world.northgrum.com>
Subject: Re: QUIZ: answer and hash slice tutorial
Message-Id: <34FEE7A9.83E@world.northgrum.com>
Jim Stern wrote:
>
> John Porter wrote:
> >
> > Charles Margolin wrote:
> > >
> > > Uri Guttman wrote:
> > >
> > > > @array{ @array } = ( [ @array ] ) x @array ;
> > >
> > > Is there a reason to copy the original array into an anonymous array?
> > > Why not use a reference to @array?
> > >
> > > @array{ @array } = ( \@array ) x @array ;
> >
> > It basically depends on whether you want to ensure that the
> > array referenced by each hash entry is protected from
> > modifications to @array later on.
> > In general, I would guess that making a "protected" copy
> > is more likely to be useful.
> >
> > John Porter
>
> This is correct. I reply only to clarify by means of an example:
>
> =snip
> #!/usr/local/bin/perl -w
> use strict;
> my @array = (1..5);
> my @a = (\@array) x 3;
> my @b = ([@array]) x 3;
>
> print "@{$a[0]}\n"; # 1..5
> print "@{$b[0]}\n"; # 1..5
> $array[0]=10;
> print "@{$a[0]}\n"; # 10, 2..5
> print "@{$b[0]}\n"; # 1..5
> $a[1][1]=20;
> print "@{$a[0]}\n"; # 10, 20, 3..5
> print "@{$b[0]}\n"; # 1..5
> =snip
>
> In short:
>
> @b consists of 3 elements and each is a reference to a different
> copy of @array
>
> @a consists of 3 elements and each refers to the same array, @array
>
> Normally, the aliasing going on inside @a is a Bad Thing.
>
You are both correct. It's important that the original programmer and
anyone doing maintenance/enhancements understand how it works.
It depends on whether you want the original array to be protected or
whether you expect all of the indirect uses to remain consistent.
The latter case is safe only if the original array contents are treated
as read-only or if you only change the base array. For a huge base
array you might consider the efficiency worth the risk.
--
Charles G. Margolin DSSD Internal Information Services
cmargoli@world.northgrum.com Northrop Grumman Corp. 0624/23
margolin@acm.org Hawthorne, California 90250-3277
------------------------------
Date: Thu, 05 Mar 1998 13:06:08 -0600
From: Derek Balling <dballing@speedchoice.com>
Subject: Re: RegEXP HELP NEEDED
Message-Id: <93BF12E2D68EB8A6.FACD58C6B9D3668D.E88B500BB83E9627@library-proxy.airnews.net>
George Kuruvilla wrote:
>
> Hello, i have this problem with regexp:
> i have to substitute a text on more than one line but i'm not able to do
> it.
> I have to substitute 2 or three lines in a file with other text. If I
> use s/// the program recognize the text which is to be replaced only if
> it is on one line. How to replace a text disposed on more than one line
That's fairly simple, it's just:
# man perlop
Then do:
/s\/PATTERN <return/enter>
and read.
------------------------------
Date: 05 Mar 1998 11:58:36 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: Special Characters
Message-Id: <8czpj50xsz.fsf@gadget.cscaper.com>
>>>>> "Russell" == Russell White <russwyte@pcisys.net> writes:
Russell> Can anybody tell me where I can find a list of special
Russell> characters that must be treated with the "\" symbol in print
Russell> statements? Such as \" Thanks.
It's a very short list.
$ @ \ and the string delimiter (like ").
Everything else is safe.
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 179 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: 5 Mar 1998 19:30:47 GMT
From: Jon Drukman <jsd@hudsucker.gamespot.com>
Subject: Re: Stripping (Most) HTML tags
Message-Id: <6dmuh7$420$1@its.hooked.net>
John Porter <jdporter@min.net> wrote:
: May I gently point out that you are going to a bit of trouble
: to do something perl will do for you? Instead of that "for"
: loop, try this:
: local $/;
: $p->parse( <> ); # slurps all files at once
: This doesn't verify that each file is readable, but man is it
: shorter.
maybe, but it doesn't work if you specify multiple files on the
command line. also, there's no way to tell which file you're in.
-j-
------------------------------
Date: Thu, 5 Mar 1998 17:45:24 GMT
From: stephen farrell <sfarrell+usenet@farrell.org>
Subject: Re: Sybase
Message-Id: <87en0hjakr.fsf@phaedrus.uchicago.edu>
Geert Roovers <etmgero@etm.ericsson.se> writes:
> I want to read from and write to a Sybase database on UNIX (SunOS, dunno
> what version, but 5.5.1 or later anyway). I know there are modules for
> this, and probably
All of these are written and maintained by michael peppler
<mpeppler@mbay.net> .... there is tons of info on his home page:
http://www.mbay.net/~mpeppler/
briefly:
DBD::Sybase--this is part of the DBD library, and has the advantage of
having a common api for different databases. it's a little less
mature and probably slower, but if the first is important to you, then
it's probably the way to go.
Sybase::DBlib--DBlib is an older sybase library that is still
supported by sybase current development is in the ctlib. one benefit
is i believe this library will successfully connect to microsoft sql
server.
Sybase::BCP--this is a special purpose library for accessing the "bulk
copy" api for sybase. you'd know if you need this.
Sybase::Sybperl--this umm... I think this is just the package that
contains the other sybase modules you've listed (not DBD)
Sybase:CTlib--this is probably the most robust and supported driver at
this point by both mr. peppler and sybase (well, sybase doesn't
support the perl driver, but the ctlib api).
So here's what you want: if you want a portable api that will work
with multiple databases then get the sybase DBI driver. if you want
just to connect to sybase, then you want the whole Sybperl module
installed, which includes BCP, CTlib and DBlib.
--sf
------------------------------
Date: Thu, 05 Mar 1998 11:43:23 -0700
From: "Joseph N. Hall" <joseph@5sigma.com>
Subject: Re: The -w switch (was Re: better way to do this?)
Message-Id: <34FEF1F1.45563702@5sigma.com>
My book speaks for itself, but I don't think that in general
end users should be exposed to -w messages. There are several
compelling reasons for this. The most difficult for the
proponents of "-w all the time" to dispel is that -w keeps
changing, which causes perfectly functional and correct code
to begin coughing up error messages. For example:
$a += "1 is good"
produces a message under warnings. It didn't a year or so ago.
(Note that $a += "0 but true" is special cased. Hrmph.)
The other analogy I make is that -w messages are like assertions
in C code, and it is a well-accepted rule that assert macros are
turned off in production code.
-w is good for developers, BAD for end users. But that's just
one man's opinion ... shared by at least some others, no doubt.
-joseph
--
Joseph N. Hall, prop., 5 Sigma Productions mailto:joseph@5sigma.com
Author, Effective Perl Programming . . . . . http://www.effectiveperl.com
Perl Training . . . . . . . . . . . . . . . http://www.perltraining.com
------------------------------
Date: Thu, 05 Mar 1998 14:30:40 -0500
From: MCK@CH0CO.COM (Monee C. Kidd)
Subject: Re: Variable not returning values
Message-Id: <MCK-0503981430410001@as3-27.apk.net>
In article <x7btvmxcvj.fsf@sysarch.com>, Uri Guttman <uri@sysarch.com> wrote:
> i think you should put a next here or the counter will go down and then
> up.
This solved it. Thanks.
> > for ($Yes) {
> > s/^\s+//;
> > s/\s+$//;
> > }
>
> this part may work but is VERY bad code.
Well, then you should speak to the FAQ maintainer; that code came directly
from the FAQ :)
Thanks again though. Now I gotta roll that subroutine into a bigger
script. Oy....
--
Monee C. Kidd - mck@choco.com - http://www.choco.com
What matters is not what you call me, but what I answer to
(When replying, make sure my address contains no numbers.)
------------------------------
Date: 5 Mar 1998 18:13:47 GMT
From: Zenin <zenin@best.com>
Subject: Re: What is PERL? Learn JAVA instead?
Message-Id: <889121965.365629@thrush.omix.com>
John Porter <jdporter@min.net> wrote:
: Perl and Java are essentially the same language.
hehehehe...
: When you've learned one, you know them both.
hehheheheheheheheheeheh...!
: By using different command-line options, you can get either behavior
: out of either compiler.
HEHEHEHEHEHEHEHEHEHEHEHEHEHEHEHEHEHEH!!!!!!!
: > Which one is better?
: As I say, they are basically the same; but Pure Java has as slight
: advantage in most areas (compilation speed, executable size, ease
: of use, platform-independence, etc.)
SOMEONE STOP ME! I'M LAUGHING MYSELF TO DEATH HERE! HAHAHAH!
: > What can I use it for?
: Both of these languages are really only suitable for web site
: development.
Hehehehehheheheheheheheheheheheh
: If you need to do heavy duty data processing,
: you should probably look at C++ or SQL.
SQL?!?!?! ROTFL!!!!! Ya, data processing with no 'if'
statement. Good luck! SQL is just barely a language. It's
much closer to a database API then it is a language.
Man, that was fun. I'm going out for coffee and see if I can
stop laughing by the time I get back. Thanks for the great
joke John, I haven't had a laugh like that in days. *grin*
--
-Zenin
zenin@best.com
------------------------------
Date: 5 Mar 1998 18:16:57 GMT
From: Zenin <zenin@best.com>
Subject: Re: What is PERL? Learn JAVA instead?
Message-Id: <889122155.454280@thrush.omix.com>
John Porter <jdporter@min.net> wrote:
: Nathan V. Patwardhan wrote:
: >
: > You're kidding, right?
: Right.
Thank god. For a second there I thought someone did a great job
at forging there headers. :-)
--
-Zenin
zenin@best.com
------------------------------
Date: 05 Mar 1998 10:52:03 -0800
From: Evan Kirshenbaum <evan@garrett.hpl.hp.com>
Subject: Re: What is PERL? Learn JAVA instead?
Message-Id: <v9hn2f5m0mk.fsf@garrett.hpl.hp.com>
Tom Christiansen <tchrist@mox.perl.com> writes:
> In comp.lang.perl.misc, Evan Kirshenbaum <evan@garrett.hpl.hp.com> writes:
> : - Anything involving multiple threads of control.
>
> First off, I get about 750 forks per second on my system. Not
> too shabby, eh?
Well, I'm not talking about writing an HTTP server that wants to
spawn a new thread, work independently, and then die. I'm talking
about partitioned tasks with cooperating threads and independent tasks
that all need to be able to see (and safely modify) basically all
reachable user-created data.
What's the relative cost (vs. lightweight threads) for context switch,
mutex lock/unlock, condition variable signal, etc? What's the extra
cost (in terms of performance and cognitive load) involved in setting
up and accessing a shared graph of 10k nodes or writing to a shared
file descriptor? How much swapping is introduced by having dozens of
processes, each with their own address space, rather than a single
address space with dozens of threads? Can Perl do reference
counting/shutdown gc of data that is sharable?
[And in answer to your actual question: yeah, it is. 1.3ms? On
HP-UX, with user-space threads, we were at around 0.5ms/launch. This
was a substantial part of the ~2ms round trip time that we were
budgeted in one system, so ways had to be found to pool the threads
to get acceptable performance. With kernel threads, the time should
drop by an order of magnitude to around 50us (that's the number I was
given for kernel threads on VxWorks). Of course, there are probably
other things in Perl which would make it unsuitable for such
time-starved applications, but I certainly wouldn't want to rule it
out just because there's an automatic 800us/task penalty.]
>
> Second off, have you seen the following?
>
> NAME
> IPC::Shareable - share Perl variables between processes
No, I hadn't. I'll have to take a closer look. The bit about
serializing to get into/out of shared memory segments is a bit scary
performance-wise, the application-level maintenance of unique keys
looks awkward/error-prone when multiple processes are creating
sharable data dynamically, and it looks as though application-space
still needs to treat shared and unshared data differently. I don't
see what stops a malicious process from eavesdropping on the shared
data. And, of course, there is the question of the performance
relative to true lightweight threads.
All in all, it looks like a very useful module, and I will definitely
have to pick it up. But to me it looks more useful for the sharing of
configuration information or work queues among otherwise independent
processes, not for implementing threads that have a high degree of
data or control sharing.
--
Evan Kirshenbaum +------------------------------------
HP Laboratories |The Elizabethans had so many words
1501 Page Mill Road, Building 1U |for the female genitals that it is
Palo Alto, CA 94304 |quite hard to speak a sentence of
|modern English without inadvertently
kirshenbaum@hpl.hp.com |mentioning at least three of them.
(650)857-7572 | Terry Pratchett
http://www.hpl.hp.com/personal/Evan_Kirshenbaum/
------------------------------
Date: 5 Mar 1998 19:21:44 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: What is PERL? Learn JAVA instead?
Message-Id: <6dmu08$pt1$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Wolfgang Denk
<wd@uebemc.siemens.de>],
who wrote in article <6dmd73$c1a$1@galaxy.mchh.siemens.de>:
> Evan Kirshenbaum <evan@garrett.hpl.hp.com> writes:
>
> > - Work with cyclic structures. (AFAIK, Perl still uses
> > reference counting rather than true garbage collection, and so
> > cannot reclaim them automatically.)
>
> Your knowledge is completely wrong.
Instead of rebuking an absolutely correct statement, care to explain
what made you come to this (wrong) conclusion?
Perl has no (and will not have in any forseeable future) garbage
collection. There is some vague talk on p5p about adding
user-triggered garbage collection, but I did not see any viable
approach so far.
Ilya
------------------------------
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 2034
**************************************