[11260] in Perl-Users-Digest
Perl-Users Digest, Issue: 4860 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 10 03:07:20 1999
Date: Wed, 10 Feb 99 00:00:25 -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 Wed, 10 Feb 1999 Volume: 8 Number: 4860
Today's topics:
Big pbm with perl5.00502 solaris "package" (David Combs)
Re: CGI Programmer Needed! We'll Give... (Ronald J Kimball)
chmod query <Balanone@geocities.com>
Re: chmod query <thelma@alpha2.csd.uwm.edu>
file local or on nsf??? (Peter Bismuti)
file local or on nsf??? (Peter Bismuti)
Re: file local or on nsf??? (Daniel E. Macks)
Re: fun with strings... <uri@home.sysarch.com>
Re: fun with strings... (Larry Rosler)
Re: fun with strings... (Ronald J Kimball)
Re: how do I get a date in perl? (Ronald J Kimball)
Re: Is there another way <mpersico@erols.com>
Re: Is there another way <rick.delaney@home.com>
Re: lists within hashes (Ronald J Kimball)
Re: lists within hashes <brett_s_r@hotmail.com>
Re: Matching elements in arrays or hashes? <ebohlman@netcom.com>
Newbie from Intel Evil Empire wants to know how to get (Bob Tennant)
Re: Newbie from Intel Evil Empire wants to know how to <ebohlman@netcom.com>
Re: performance penalty: bareword, single quoting, doub (Ronald J Kimball)
Re: perl -T results in @INC not getting $PERL5LIB (Ronald J Kimball)
Re: perl floating points [benchmarking] (Ilya Zakharevich)
Re: perl floating points (Ronald J Kimball)
Re: Perl search string problem <rick.delaney@home.com>
Re: Perl search string problem (Ronald J Kimball)
Re: Perl vs. ASP for new project naken@i1.net
Re: Regular expressions and handleing new lines (Ronald J Kimball)
Re: Suppres special characters (Ronald J Kimball)
Re: testing for scalar/list/array (Ronald J Kimball)
Re: Understanding my (Mark-Jason Dominus)
Re: use/require question? (Ronald J Kimball)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 10 Feb 1999 03:58:12 GMT
From: dkcombs@netcom.com (David Combs)
Subject: Big pbm with perl5.00502 solaris "package"
Message-Id: <dkcombsF6x710.M7u@netcom.com>
Although have been happily writing useful programs with perl5.004,
am having problems with perl5.00502, as just downloaded as a solaris 2.5.1
already-compiled "package" from www.sunfreeware.com, via the file
"perl-5.005_02-sol25-sparc-local.gz", which I gunzipped and then
(solaris) "pkgadd'ed".
Yes, it works -- and no, it doesn't.
With BOTH "uses" commented out of hello.pl:
#use strict;
#use diagnostics;
print "hello\n";
it actually works OK:
535 ====> /david3/packages/LWperl/bin/perl5.00502 -I/david3/packages/LWperl/lib/perl5/5.00502/ -w ~/hello.pl
hello
AND with ONE of them "live":
use strict;
#use diagnostics;
print "hello\n";
it STILL works:
536 ====> !!
/david3/packages/LWperl/bin/perl5.00502 -I/david3/packages/LWperl/lib/perl5/5.00502/ -w ~/hello.pl
hello
BUT with BOTH "alive",
use strict;
use diagnostics;
print "hello\n";
I get THIS:
537 ====> !!
/david3/packages/LWperl/bin/perl5.00502 -I/david3/packages/LWperl/lib/perl5/5.00502/ -w ~/hello.pl
(NOTE: The resulting ERR-MSG was INCREDIBLY WIDE (440 chars)!;
so, before posting it, I did a M-q ("fill")):
couldn't find diagnostic data in
/usr/local/lib/perl5/5.00502/pod/perldiag.pod
/david3/packages/LWperl/lib/perl5/5.00502//sun4-solaris
/david3/packages/LWperl/lib/perl5/5.00502/
/usr/local/lib/perl5/5.00502/sun4-solaris /usr/local/lib/perl5/5.00502
/usr/local/lib/perl5/site_perl/5.005/sun4-solaris
/usr/local/lib/perl5/site_perl/5.005 . /home/dkc/hello.pl at
/david3/packages/LWperl/lib/perl5/5.00502//diagnostics.pm line 229,
<POD_DIAG> chunk 533.
BEGIN failed--compilation aborted at /home/dkc/hello.pl line 2, <POD_DIAG> chunk 533.
538 ====>
(I also tried this:
use strict;
#use diagnostics;
print "hello\n";
which worked OK.
SO, the PROBLEM is with the "use diagnostics".
)
But Note this: BOTH of them live in the SAME directory!
(the "dua.out" is result of my doing "du -a > dua.out")
538 ====> egrepi 'strict|diagnostics' /david3/packages/LWperl/dua.out
10 ./lib/perl5/5.00502/man/man3/diagnostics.3
7 ./lib/perl5/5.00502/man/man3/strict.3
14 ./lib/perl5/5.00502/diagnostics.pm
3 ./lib/perl5/5.00502/strict.pm
539 ====>
BY THE WAY, it works JUST FINE (evidently finds both) under 5.004:
539 ====> perl5.004 -w ~/hello.pl
hello
540 ====> alias perl5.004
/opt/gnu/perl/bin/perl5.004 -I/opt/gnu/perl/lib/ !*
541 ====>
(NOTE: for perl5.004, the .pl and .pm files are directly in
"/opt/gnu/perl/lib/", NOT two dirs further down as in
this perl5.005.)
541 ====> cat ~/hello.pl
use strict;
use diagnostics;
print "hello\n";
After grepping through ALL the pod (yes, faqs too!) for various things,
I also tried "use diagnostics -verbose;";
it worked fine for perl5.004, but for the perl5.005, gave same
error as before.
ANY IDEAS?
THANKS!
------------------------------
Date: Wed, 10 Feb 1999 02:02:14 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: CGI Programmer Needed! We'll Give...
Message-Id: <1dmzifo.1birpe9dbjgwN@bay2-161.quincy.ziplink.net>
<BagwellDesign@excite.com> wrote:
> Well, I am not made of money, so this is what I can offer you:
>
> 500,000 banner exposures on the website, for your website. You'll also be
> mentioned in the disclaimer as the newsboard programmer, on every page of the
> website. We'll have your e-mail address in the disclaimer, so others may
> contact you about programming their cgi, which can make you a lot of money as
> well.
Unless, of course, all the others who contact you with work based on
your e-mail address in the disclaimer offer you similar non-monetary
compensation. ;-)
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
perl -e'$_="\012534`!./4(%2`\cp%2,`(!#+%2j";s/./"\"\\c$&\""/gees;print'
------------------------------
Date: Tue, 09 Feb 1999 21:15:59 -0800
From: Balanone <Balanone@geocities.com>
Subject: chmod query
Message-Id: <36C1160F.588217C3@geocities.com>
Given the code in a perl CGI program called from an HTML form page:
# begin code sample
$ofilepfx = '/usr/home/mywww/reqfiles/ureq.' ; # define path to output file
$fpid = $$ - 1 ; # init pid
do { $ofile = $ofilepfx . ++$fpid } until ( not -e $ofile ) ; # ensure no
file overwrite
$openfile = '>' . $ofile ; # flag output only
open ( reqfile, $openfile ) || die "open of ofile failed " . $openfile ;
print reqfile ... # data written to file here
close ( reqfile ) ;
$tst = chmod O700, $ofile ; # change privs on file
print 'chmod O700, ' . $ofile . ' -- ' . $tst ; # debug print of results
($login,$pass,$uid,$gid) = getpwnam('xeper') ; # need numeric uid/gid
$tst = chown $uid, $gid, $ofile ; # change ownership on file
print 'chown ' . $uid . ', ' . $gid . ', ' . $ofile . ' -- ' . $tst ; #
debug print of results
# end code sample
The required data is being written to the output file, but the chmod and
chown don't work right.
The chown reports
> chown 1234, 678, /usr/home/mywww/reqfiles/ureq.5095 -- 0
which led me to suspect that I don't have chown privileges on this system.
Indeed, the chown shell command reports that the operation is not permitted.
That explanation was simple.
The chmod reports
> chmod O700, /usr/home/mywww/reqfiles/ureq.5095 -- 1
which indicates that the chmod *did* succeed, and indeed the permissions
have been changed. But instead of changing to the desired 700 (rwx------),
it changed to 000 (---------) -- nobody nowhere nohow has any file
read/write/exec access.
This leads me to suspect that I'm specifying the permissions number
incorrectly. My understanding from reading the perldoc (actually
perlfunc.html) was that chmod required a numeric (preferably octal) first
parameter to reflect the desired permissions. So I specified O (capital
letter o) 700. This did not produce the desired results.
What did I do wrong, and what should I have done?
Many thanks for your assistance.
Balanone
PP
------------------------------
Date: 10 Feb 1999 05:44:53 GMT
From: Thelma Lubkin <thelma@alpha2.csd.uwm.edu>
Subject: Re: chmod query
Message-Id: <79r6cl$eio$1@uwm.edu>
Balanone <Balanone@geocities.com> wrote:
: Given the code in a perl CGI program called from an HTML form page:
: # begin code sample
.
.....
: close ( reqfile ) ;
: $tst = chmod O700, $ofile ; # change privs on file
: print 'chmod O700, ' . $ofile . ' -- ' . $tst ; # debug print of results
...
: The chmod reports
:> chmod O700, /usr/home/mywww/reqfiles/ureq.5095 -- 1
: which indicates that the chmod *did* succeed, and indeed the permissions
: have been changed. But instead of changing to the desired 700 (rwx------),
: it changed to 000 (---------) -- nobody nowhere nohow has any file
: read/write/exec access.
...
: parameter to reflect the desired permissions. So I specified O (capital
: letter o) 700. This did not produce the desired results.
: What did I do wrong, and what should I have done?
set it to 0700 (leading zero, *not* capital O)
--thelma
: Balanone
: PP
------------------------------
Date: 10 Feb 1999 04:53:31 GMT
From: bismuti@cs.fsu.edu (Peter Bismuti)
Subject: file local or on nsf???
Message-Id: <79r3cb$3qe$1@news.fsu.edu>
I am writing a script that checks the quotas of all
the users on our solaris system. It is necessary to
know whether or not the file system in which a particular
user's directory is local or exists on another machine
on the NFS somewhere. I have conlcuded that no
such native command exists in Perl that can ascertain
this information.
So I guess the main question is, how can you find out
in Perl (as natively as possible,i.e. without relying
on external commands) what machine a particular filesystem
(or better yet file) resides on?
input: directory path output: local or not local?
Thanks in advance
------------------------------
Date: 10 Feb 1999 05:23:21 GMT
From: bismuti@cs.fsu.edu (Peter Bismuti)
Subject: file local or on nsf???
Message-Id: <79r549$5a2$1@news.fsu.edu>
> In short, I want you to research how in as native a way as possible in Perl
> can you find out whether a given file or directory name is local or NFS
> in origin.
A clarification of my previous message. This is a more precise statement
of the information that I am looking for.
Thanks again
_____________________________________________________________________
| |
| Pete Bismuti |
| Department of Computer Science |
| Florida State University |
| bismuti@cs.fsu.edu (850) 644-0516 |
|_____________________________________________________________________|
------------------------------
Date: 10 Feb 1999 06:27:06 GMT
From: dmacks@mail2.sas.upenn.edu (Daniel E. Macks)
Subject: Re: file local or on nsf???
Message-Id: <79r8rq$ftr$1@netnews.upenn.edu>
Peter Bismuti <bismuti@cs.fsu.edu> said:
:
: So I guess the main question is, how can you find out
: in Perl (as natively as possible,i.e. without relying
: on external commands) what machine a particular filesystem
: (or better yet file) resides on?
:
: input: directory path output: local or not local?
At least on the unixes I've used, the output of df has this info: the
path of each filesystem is machine:/path/to/dir if remote, just
/path/to/dir is local. I've never used the Filesys::Df module to know
whether that info is available from it. At worst, you'd just need to
wrap some xs around the core of the GNU Fileutils df source (unless
you break down and make the system call:).
dan
--
Daniel Macks
dmacks@a.chem.upenn.edu
dmacks@netspace.org
http://www.netspace.org/~dmacks
------------------------------
Date: 10 Feb 1999 00:48:00 -0500
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: fun with strings...
Message-Id: <x7soceq06n.fsf@home.sysarch.com>
>>>>> "M" == Marcos <alves@webmetro.com> writes:
M> constant with '\n' or '\t' (not "\n" or "\t"). I need to be expand
M> the \n and \t sequences to actual newlines and tabs. I tried using
M> print and sprintf on the
M> # I DON'T LIKE THIS, BUT IT WORKS!!!
i hate it.
M> sub tooMuchCode
true.
why not a simple s///?
$this_is_given =~ s/\\n/\n/g ;
$this_is_given =~ s/\\t/\t/g ;
if perl can do it, just let it do it for you.
hth,
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire ---------------------- Perl, Internet, UNIX Consulting
uri@sysarch.com ------------------------------------ http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Tue, 9 Feb 1999 12:53:22 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: fun with strings...
Message-Id: <MPG.112a401cfc57658b989a13@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <36C104ED.F4B2903C@webmetro.com> on Wed, 10 Feb 1999 03:53:27
GMT, Marcos <alves@webmetro.com> says...
...
> I am forced to deal with a scalar variable $this_is_given that was set
> to a string
> constant with '\n' or '\t' (not "\n" or "\t"). I need to be expand the
> \n and \t sequences to
> actual newlines and tabs.
...
> BTW, I need a solution general enough to work for something like
> $this_is_given = 'howdy\nfriends\tetc...';
$this_is_given =~ s/\\([nt])/$1 eq 'n' ? "\n" : "\t"/eg;
`perldoc perlre` for character classes, capturing parentheses, eval in
substitution...
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 10 Feb 1999 02:02:16 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: fun with strings...
Message-Id: <1dmzir6.14u24bmk0l37kN@bay2-161.quincy.ziplink.net>
Marcos <alves@webmetro.com> wrote:
> I need to be expand the \n and \t sequences to actual newlines and tabs.
s/(\\[nt])/"\"$1\""/gee;
The replacement expression is evaluated twice because of the two /e's.
First the string "\"$1\"" is evaluated, resulting in the string "\n".
Then "\n" is evaluated, which yields the character \n.
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
perl -e'$_="\012534`!./4(%2`\cp%2,`(!#+%2j";s/./"\"\\c$&\""/gees;print'
------------------------------
Date: Wed, 10 Feb 1999 02:02:17 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: how do I get a date in perl?
Message-Id: <1dmzj9b.1mir3okdgax8sN@bay2-161.quincy.ziplink.net>
Duc Le <bamboo@best.com> wrote:
> Subject: how do I get a date in perl?
Sorry, Perl is for computer programmers, who are widely known not to get
dates. If you want to get a date, try something more glamorous, like
racecar driving.
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
perl -e'$_="\012534`!./4(%2`\cp%2,`(!#+%2j";s/./"\"\\c$&\""/gees;print'
------------------------------
Date: Tue, 09 Feb 1999 23:19:39 -0500
From: "Matthew O. Persico" <mpersico@erols.com>
Subject: Re: Is there another way
Message-Id: <36C108DB.36720CD0@erols.com>
Also try this:
http://language.perl.com/style/slide37.html
And then there's the (in?)famous FMTEYEWTK on Switch Statements in Perl
(was: No switch statement in Perl??) memo where the illustrious Tom
Christiansen <tchrist@mox.perl.com> deails no less htan 22 ways to code
a switch in perl, which I found at this url:
http://x9.dejanews.com/[ST_rn=ps]/getdoc.xp?AN=386655735&CONTEXT=918619884.2089877537&hitnum=7&AH=1
Many of them are simply syntactic sugar, but that's the whole point of a
switch anyway, right: a more aesthetic if/else tree?
Enjoy.
Jonathan Feinberg wrote:
>
> "Bob Lally" <rlally1@nycap.rr.com> writes:
>
> > Does perl have a "switch" type statement?
>
> This is a FAQ. perlfaq7, " How do I create a switch or case statement?"
>
> > Also, what would be the statement to get the last few characters in
> > a variable up to but not including a period.
>
> You might want to check out the O'Reilly book _Learning Perl_ which
> features a gentle introduction to Perl regular expressions. Then you
> should read perlre and perlop which are thorough and definitive
> references to same.
>
> --
> Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
> http://pobox.com/~jdf
--
Matthew O. Persico
http://www.erols.com/mpersico
http://www.digistar.com/bzip2
------------------------------
Date: Wed, 10 Feb 1999 04:38:17 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Is there another way
Message-Id: <36C10F12.B3C75BAE@home.com>
[posted & mailed]
Bob Lally wrote:
>
> I have a variable that contains an ISO country code. I want to output
> text depending on which country is coming in.
You got answers to your question about switch statements, but you might
just want to use a simple hash here with country codes as keys and
associated text as values.
perldoc perldata
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: Wed, 10 Feb 1999 02:02:17 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: lists within hashes
Message-Id: <1dmzjju.1mdoxx9jtyipnN@bay2-161.quincy.ziplink.net>
Brett Randall <brett_s_r@hotmail.com> wrote:
> my %presets = ( AIX => \([qw(athena atlas dev sat titan detroit la
> lare do miami newark savannah seattle)]),
This is a reference to a reference to an anonymous array. [] is the
anonymous array constructor, and returns a reference; I think that \()
slipped in there by mistake.
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
perl -e'$_="\012534`!./4(%2`\cp%2,`(!#+%2j";s/./"\"\\c$&\""/gees;print'
------------------------------
Date: Wed, 10 Feb 1999 18:35:31 +1100
From: Brett Randall <brett_s_r@hotmail.com>
Subject: Re: lists within hashes
Message-Id: <36C136C3.32DA9B89@hotmail.com>
Right you are Ronald - thank you for the correction - one too many references!
Wil - remove the \() 's and of course use one less dereference when accessing
the array.
Brett
Ronald J Kimball wrote:
> Brett Randall <brett_s_r@hotmail.com> wrote:
>
> > my %presets = ( AIX => \([qw(athena atlas dev sat titan detroit la
> > lare do miami newark savannah seattle)]),
>
> This is a reference to a reference to an anonymous array. [] is the
> anonymous array constructor, and returns a reference; I think that \()
> slipped in there by mistake.
>
> --
> _ / ' _ / - aka - rjk@linguist.dartmouth.edu
> ( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
> / http://www.ziplink.net/~rjk/
> perl -e'$_="\012534`!./4(%2`\cp%2,`(!#+%2j";s/./"\"\\c$&\""/gees;print'
------------------------------
Date: Wed, 10 Feb 1999 04:57:36 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Matching elements in arrays or hashes?
Message-Id: <ebohlmanF6x9s0.1Gu@netcom.com>
mattd@ukcc.uky.edu wrote:
: Can the following be used to find matching elements in arrays or hashes?
: @matching = grep { /@some_array/ } @data;
Not as written.
: Here is the scenario: I have two files. One file contains one entry per
: line data. Here is an example:
: 123abc
: 456def
: 789efg
: In the other file is data of the following:
: 19990204^23:23:23^text^123^text^02/04/99^22:22:22^00405555^123abc^text
: 19990204^23:23:23^text^123^text^02/04/99^22:22:22^00405555^456def^text
: 19990204^23:23:23^text^123^text^02/04/99^22:22:22^00405555^789efg^text
: 19990204^23:23:23^text^123^text^02/04/99^22:22:22^00405555^123abc^text
: 19990204^23:23:23^text^123^text^02/04/99^22:22:22^00405555^456def^text
: I would like to take each element of the first file and compare it to
: the ninth field of the second file and calculate the number of
: occurrences. Then, add all those numbers to get a total value for
: occurrences of elements in file A for file B.
: I have tried the following. I know that it isn't the best way to go
: about this. What would work better, be more efficient?
[snip quadratic-time code]
Assuming that the elements of the first file are literal text rather than
regex patterns, a much more efficient way would be to use the values of
the ninth field in the second file (still following me?) as keys to a hash
whose values are counts of element occurrences. You'd first loop through
the second file, something like:
while (<SECOND>) {
++$el_count{(split /\^/)[8]};
}
And then loop through the first file, adding up the counts for the
elements found in it:
my $total=0;
while (<FIRST>) {
chomp;
$total += $el_count{$_};
}
This takes time proportional to the sum of the two file sizes, rather
than their product as your proposed solution (with nested loops) does.
------------------------------
Date: Wed, 10 Feb 1999 04:20:07 GMT
From: bobtennant@loop.com (Bob Tennant)
Subject: Newbie from Intel Evil Empire wants to know how to get started with basic Perl program
Message-Id: <XN7w2.129$7k4.266839@news2.randori.com>
I'm having difficulty getting started with Perl. My computer is an Intel
Pentium running Windows 95. Following is my sad tale of woe.
I downloaded Perl for Windows 32 (Pw32i316.exe) and installed it in a
directory called d:\perl.
I then created a very simple program that prints out "Hello, Im Bob!" as
follows:
print "Hello, Im Bob! \n";
I saved this program as "Hello.txt" (Notepad only saves under the .txt
extension) and put it into the same directory in which the PERL interpreter
(Perl.exe) is located -- i.e., d:\perl\bin
Next, I tried running the program, as follows:
I brought up Perl by double-clicking "Perl.exe" and an MS-DOS window opened
which was completely blank -- not even a prompt. So I typed the following:
% perl hello.txt
This resulted in the following message:
Bare word found where operator expected -- at line 1, near "%Perl hello"
(Missing operator before hello?)
syntax error at -- line 1, near "%Perl hello"
Next I tried entering the full path name for both the program and the file --
i.e.,
d:\perl\bin\perl.exe d:\perl\bin\hello.txt
-- but that only resulted in an MS-DOS window opening for 1 second then
disappearing!
Until I can learn the mechanics of running a simple PERL program like the
"Hello" program, I'm doomed! Any (and all) suggestions would be most welcome.
If you wish, you can send responses to my email box: bobtennant@loop.com
------------------------------
Date: Wed, 10 Feb 1999 05:33:36 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Newbie from Intel Evil Empire wants to know how to get started with basic Perl program
Message-Id: <ebohlmanF6xBG0.418@netcom.com>
Bob Tennant <bobtennant@loop.com> wrote:
: I'm having difficulty getting started with Perl. My computer is an Intel
: Pentium running Windows 95. Following is my sad tale of woe.
: I downloaded Perl for Windows 32 (Pw32i316.exe) and installed it in a
: directory called d:\perl.
That's a rather old version (5.003) of Perl. You can get version 5.005
from www.activestate.com.
: I then created a very simple program that prints out "Hello, Im Bob!" as
: follows:
: print "Hello, Im Bob! \n";
Why you want trailing spaces before the newline, I don't know, but that's
a reasonable first program.
: I saved this program as "Hello.txt" (Notepad only saves under the .txt
: extension) and put it into the same directory in which the PERL interpreter
: (Perl.exe) is located -- i.e., d:\perl\bin
Generally, it's a good idea to reserve bin directories for executables.
Make sure the executable is on your path, and put your programs in their
own director(y|ies).
: Next, I tried running the program, as follows:
: I brought up Perl by double-clicking "Perl.exe" and an MS-DOS window opened
: which was completely blank -- not even a prompt. So I typed the following:
: % perl hello.txt
: This resulted in the following message:
[snip error message]
: Next I tried entering the full path name for both the program and the file --
: i.e.,
: d:\perl\bin\perl.exe d:\perl\bin\hello.txt
: -- but that only resulted in an MS-DOS window opening for 1 second then
: disappearing!
Your problem is similar to that of the murder victim whose last day was
described in a newspaper article: "He got up, got dressed, and took a
shower." You're doing things in the wrong order. You need to bring up a
DOS window first, *then* type 'perl hello.txt' at the DOS prompt (which
is actually the Win32 console prompt, but...).
------------------------------
Date: Wed, 10 Feb 1999 02:02:18 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: performance penalty: bareword, single quoting, double quoting
Message-Id: <1dmzjss.1nx89hnbffik4N@bay2-161.quincy.ziplink.net>
Sean McAfee <mcafee@waits.facilities.med.umich.edu> wrote:
> In article <Pine.A41.4.02.9902081916590.13514-100000@ginger.libs.uga.edu>,
> Brad Baxter <bmb@ginger.libs.uga.edu> wrote:
> >I like barewords in those places where perl doesn't complain about
> >them. Actually, -w doesn't complain about lower-case barewords.
>
> Yes, it does.
>
> > perl -lwe 'print STDOUT foo'
> Unquoted string "foo" may clash with future reserved word at -e line 1.
> foo
> > perl -lwe 'print STDOUT Foo'
> Foo
I almost posted the same thing in response to Brad's message.
Unfortunately, when Brad wrote the above statement in his message he
left the context of the thread assumed rather than specified.
What Brad meant to say was:
I like barewords in those places where perl doesn't complain about
them. Actually, -w doesn't complain about lower-case barewords **as hash
keys**.
In other words, -w will not complain about things such as $x{foo}.
:-)
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
perl -e'$_="\012534`!./4(%2`\cp%2,`(!#+%2j";s/./"\"\\c$&\""/gees;print'
------------------------------
Date: Wed, 10 Feb 1999 02:02:20 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: perl -T results in @INC not getting $PERL5LIB
Message-Id: <1dmzk35.b5rwg01g43k7pN@bay2-161.quincy.ziplink.net>
John Bossert <jbossert@dazel.com> wrote:
> I note that when I execute perl (5.004 on a HP/UX system) with -T, the
> value of $PERL5LIB doesn't get into the @INC list. Thus, things like
> "use strict;" fail. :-(
This is not mentioned in perlrun under -T. It *is*, however, mentioned
in perlrun under PERL5LIB:
PERL5LIB
A colon-separated list of directories in which to look for Perl
library files before looking in the standard library and the current
directory. If PERL5LIB is not defined, PERLLIB is used. When
running taint checks (because the script was running setuid or
setgid, or the B<-T> switch was used), neither variable is used.
The script should instead say
use lib "/my/directory";
> What's the best way of addressing this? I can think of a few:
>
> 1) #!/usr/bin/perl -wTI/location/of/my/PERL5LIB as the first line of my
> script
I suppose that could work. It's not pretty.
> 2) adding 'unshift(@INC, $ENV{'PERL5LIB'});' to the top of my script.
If you try that, "use strict;" still won't work. use happens at
compile-time, unshift happens at run-time.
> Style mavens, any thoughts? Buehler? Buehler?
use lib, as mentioned above.
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
perl -e'$_="\012534`!./4(%2`\cp%2,`(!#+%2j";s/./"\"\\c$&\""/gees;print'
------------------------------
Date: 10 Feb 1999 07:40:04 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: perl floating points [benchmarking]
Message-Id: <79rd4k$n5a$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Abukar Mohamed
<abukar@insidewire.com>],
who wrote in article <36c0a703.0@diana.idirect.com>:
> Hi
About your subject: Perl has only one floating point, and it is
allowed to float upwards only. This point, though a scarce resource,
is very useful to implement the bubble sort algorithm, one which is
used when you do sort(@array) in Perl.
In fact it is quite interesting to listen to these tiny bubbles
created when this point floats upward (you need to have a pretty big
@array for the sound to be above the ear threshold). What I always
was interesting in is how the speed of sort algorithm depends on
having a desktop case vs. a tower case (with the same processor). I
would think that bubbles may accelerate to much higher speed given a
tower case.
Anybody ready for a benchmark?
Ilya
------------------------------
Date: Wed, 10 Feb 1999 02:02:21 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: perl floating points
Message-Id: <1dmzkaq.5z9n4m19qs5a3N@bay2-161.quincy.ziplink.net>
Abukar Mohamed <abukar@insidewire.com> wrote:
> My point is to print
>
> $value=8.9;
> $order=<<MOO
> $value
> MOO
>
> on the screen as 8.90
Perhaps you want something like this?
printf <<MOO, $value;
%.2f
MOO
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
perl -e'$_="\012534`!./4(%2`\cp%2,`(!#+%2j";s/./"\"\\c$&\""/gees;print'
------------------------------
Date: Wed, 10 Feb 1999 04:54:29 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Perl search string problem
Message-Id: <36C112DF.CF83460@home.com>
[posted & mailed]
Jason Boyd wrote:
>
> Jason (my name too),
>
> Without knowing what you've got in $abc, its hard to know what might
> be wrong, but the statement:
>
> $abc =~ tr/\D//;
>
> ought to remove all non-digit characters in the string stored in $abc,
What makes you think so? Please see Mike Stok's reply in this thread
for a thorough explanation. Or read the documentation for yourself.
perldoc perlop
> as will the more appropriate:
>
> $abc =~ s/\D//g;
This will do as you say and is only more appropriate because it's
correct. Some might prefer this:
$abc =~ tr/0-9//cd;
> Perhaps your problem lies in the value of either of the above when
> evaluated aas expressions. I'm not sure what ($abc =~ s/\D//g) evals
> as. Are you?
Yup, says so right in the docs. Again,
perldoc perlop
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: Wed, 10 Feb 1999 02:02:22 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Perl search string problem
Message-Id: <1dmzkf5.ewiklxskkrrkN@bay2-161.quincy.ziplink.net>
Jason Boyd <jboyd99@hotmail.com> wrote:
> Without knowing what you've got in $abc, its hard to know what might be wrong,
> but the statement:
>
> $abc =~ tr/\D//;
>
> ought to remove all non-digit characters in the string stored in $abc
A) You left off the /d, for Delete: tr/\D//d;
B) \D is meaningful only in regular expressions. tr/\D//d; deletes all
capital Ds from the target string.
tr/0-9//d;
> as will the more appropriate:
>
> $abc =~ s/\D//g;
That one works. :)
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
perl -e'$_="\012534`!./4(%2`\cp%2,`(!#+%2j";s/./"\"\\c$&\""/gees;print'
------------------------------
Date: Wed, 10 Feb 1999 04:15:40 GMT
From: naken@i1.net
Subject: Re: Perl vs. ASP for new project
Message-Id: <79r156$jbc$1@nnrp1.dejanews.com>
PHP works on NT and Win95 also with Win32 Apache, PWS, IIS,
and some others I think...
I set it up for Windows NT Apache before... (along with
Linux, FreeBSD, SGI)
Also.. if you already have ASP pages that you want to use
on Apache, I'm working on a tool to convert ASP pages to
PHP3
http://www.inlink.com/~naken/asp2php/
-Michael Kohn
naken@i1.net
http://www.inlink.com/~naken/
In article <RGuv2.51204$641.41565@news.san.rr.com>,
"Sameer Samat" <ssamat@ucsd.edu> wrote:
> first, thank you very much for your help ...
>
> >
> >Unix/perl will not be faster than ASP on NT unless your using modperl. If
> >you use modperl, it will be much faster (assuming Apache). You can't keep
> the
> >interpreter in memory, it will be spawned for each script I think.
>
> modperl. ok, I'll have to look into that. would you, or anyone else
> reading this, happen to know if most ISPs make use of modperl? is it
> expected that and ISP will have modperl up and running on their unix based
> Apache servers? ... or is it something that we may need to install?
> (i know this is probably on a ISP case by case basis, but I think that if
> modperl really does help this much any ISP would be crazy not to already
> have it installed)
>
> >Your not comparing apples to apples. Consider php3(www.php3.net), which
> >accomplishes what ASP does but under Unix. Compile it into apache, and use
> >its built in database access capabilities and you have a very fast
> solution.
> >Although php is for Unix, which is obviously perferred anyway for major
> sites.
>
> I'll give it a look. Thanks again
>
> Sameer
>
>
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 10 Feb 1999 02:02:23 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Regular expressions and handleing new lines
Message-Id: <1dmzkpi.sq6iwh1hlh4d1N@bay2-161.quincy.ziplink.net>
<chris_bordeleau@lotus.com> wrote:
> I want to have a regular expression which can scan for C++ style /* Comments
> */ and am having a hard time dealing with newlines which ocour inside of
> comments.
perlfaq6:
How do I use a regular expression to strip C style comments from a file?
While this actually can be done, it's much harder than you'd
think. For example, this one-liner
perl -0777 -pe 's{/\*.*?\*/}{}gs' foo.c
will work in many but not all cases. You see, it's too
simple-minded for certain kinds of C programs, in particular,
those with what appear to be comments in quoted strings. For
that, you'd need something like this, created by Jeffrey
Friedl:
$/ = undef;
$_ = <>;
s#/\*[^*]*\*+([^/*][^*]*\*+)*/|("(\\.|[^"\\])*"|
'(\\.|[^'\\])*'|\n+|.[^/"'\\]*)#$2#g;
print;
This could, of course, be more legibly written with the `/x'
modifier, adding whitespace and comments.
[Note: I had to split the regex in order to post it. Just remove all the
whitespace between the | and the '.]
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
perl -e'$_="\012534`!./4(%2`\cp%2,`(!#+%2j";s/./"\"\\c$&\""/gees;print'
------------------------------
Date: Wed, 10 Feb 1999 02:02:24 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Suppres special characters
Message-Id: <1dmzlns.i9hoy55do8apN@bay2-161.quincy.ziplink.net>
Milos Obradovic <mobradov@newbridge.com> wrote:
> I am just begginer.
> My question is how I can suppres special meaning of some characters
> from the command line argument??
>
> For example, script name is test1 and command line argument is
> /N$aaa11(12).
> I know that: test1 '/N$aaa11(12)'
> will do, but I would like to run it without ' ' signs,
> like : test1 /N$aaa11(12).
This is an issue with the shell, rather than with Perl. Your only other
option is to backslash all the characters with special meaning.
I generally prefer the single quotes.
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
perl -e'$_="\012534`!./4(%2`\cp%2,`(!#+%2j";s/./"\"\\c$&\""/gees;print'
------------------------------
Date: Wed, 10 Feb 1999 02:02:25 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: testing for scalar/list/array
Message-Id: <1dmzlrq.tntwbxrn2gmvN@bay2-161.quincy.ziplink.net>
Rick Delaney <rick.delaney@home.com> wrote:
> > $ref_outside = \test();
> >
> > calls test() in a list context, returning (1, 2, 'a', 'b', 'c', 'd').
> ^^^^^^^^^^^^
> Why is this in a list context? It looks like it should be scalar
> context to me.
I have no idea. All I know is that I stuck in a wantarray(), and it
returned 1 for list context. :)
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
perl -e'$_="\012534`!./4(%2`\cp%2,`(!#+%2j";s/./"\"\\c$&\""/gees;print'
------------------------------
Date: 10 Feb 1999 00:17:57 -0500
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Understanding my
Message-Id: <79r4q5$n9l$1@monet.op.net>
In article <79pr5c$h0d$1@nnrp1.dejanews.com>, <yong@shell.com> wrote:
>Programming Perl says "Subroutines called from within the scope of such a
>private variable cannot see the private variable unless the subroutine is also
>textually declared within the scope of the variable." But why does the code
>below print a my variable correctly?
The book is using slightly wrong language. A variable has two parts:
The first part is some memory, in which the value of the variable is
stored. The second part is its name. There is an association between
the name and the memory.
The name has a `scope', which is the part of the program in which the
name is assoicated with the memory. But the memory itself has a
`duration', which the a period of time during which it is available
for use. The memory might be accessible even if you don't know the
name; there might be a reference to it, for example. And the duration
of the memory might continue even when the current line is outside
the scope of the original name.
The `my' declaration in Perl allocates some memory, and binds a name
to it. The scope of the name is up to the end of the enclosing
block. The duration of the memory is until there are no names or
references to the memory any more.
When you write
&mysub($a)
you are passing `mysub' a reference to the memory referred to by `$a'.
Inside `mysub', even though the name `a' is out of scope, you still
have a reference to the memory; the reference has been placed into the
built-in variable $_[0]. This is the value used by `shift' to
retrieve the string `TEST'.
This separation of names and memory is very important and often
confuses beginning programmers. Consider this example:
$q = foo();
print $$q;
sub foo { my $z = 4; return \$z; }
Inside `foo', there is a variable, $z, whose name, `z', is private to
`foo' z is the name for some memory that contains the number 4.
`return \$z' means to return a reference to this memory to the caller
of the subroutine.
After the subroutine returns, the name `z' is out of scope, and no
longer refers to the memory that contains the 4. But the subroutine
has returned another reference to the memory, and the memory and the
value it contains will persist at least as long as this reference
does. We can put the reference into $q and use it to get at the 4
in the memory, even though the original name, z, has gone out of
scope.
I hope this wasn't too abstruse.
------------------------------
Date: Wed, 10 Feb 1999 02:02:26 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: use/require question?
Message-Id: <1dmzlzq.d7vh0q96enmxN@bay2-161.quincy.ziplink.net>
Chad Lawson <cdlawson@xnet.com> wrote:
> Then, at run time, the main file (index.cgi) will load all the files with
> thier pieces into itself. Meaning each of these snipits of code are all
> part of the main:: namespace.
If I understand you correctly, just don't put a package declaration in
any of the required files.
The general way, however, is to make the other files modules, and use
the Exporter module to import specific names into the main:: package.
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
perl -e'$_="\012534`!./4(%2`\cp%2,`(!#+%2j";s/./"\"\\c$&\""/gees;print'
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 4860
**************************************