[6979] in Perl-Users-Digest
Perl-Users Digest, Issue: 604 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 12 05:17:18 1997
Date: Thu, 12 Jun 97 02:00:25 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 12 Jun 1997 Volume: 8 Number: 604
Today's topics:
(no subject) <dcroft@zoo.uvm.edu>
Re: AWK to perl translation problem (Russell Schulz)
Berkeley DB file interface, bug report (Joseph Davidson)
Re: converting mode from stat into ls style mode string (Tad McClellan)
Debugging Extensions <cameron@advancedsw.com>
GD.pm for BUILD 306 (die at line 13) <cwt1959@rit.edu>
Re: global regex in an "if" statement (Tad McClellan)
Re: global regex in an "if" statement (Tad McClellan)
Re: Help! perl -d under OpenWindows (Ilya Zakharevich)
Re: MS-DOS port of the Perl programming language <rootbeer@teleport.com>
Re: Need a list of all subdirectories (but no files) <flg@vhojd.skovde.se>
Need help with Perl command <dcroft@zoo.uvm.edu>
Re: Need help with Perl command <rootbeer@teleport.com>
Re: Newbie:To PUSH or not to PUSH? <rootbeer@teleport.com>
Re: Perl 5.004/Tk402.000 MainWindow (Nathan V. Patwardhan)
Re: Perl for NT and Serial Port Communications (Scott McMahan)
Re: Perl obfuscated contest (Jon Orwant)
Re: Printing Prime Numbers spg1@ix.netcom.com
Running other Perl scripts within and returning the res <brian@nemonet.com>
Re: Sorting Numerically (Tad McClellan)
Un-taint a variable how? (Ben Neil Gerdemann)
Re: What does "UNIX" stand for.. (Kaz Kylheku)
Re: What does "UNIX" stand for.. (Kaz Kylheku)
Re: while(<>){if(/cond/){while(<> ~= /cond2/) ... (Tad McClellan)
Re: while(<>){if(/cond/){while(<> ~= /cond2/) ... (Pythagoras Watson)
Re: write a new htmp page (Matthew Burnham)
Re: XS:Keeping a variable btwn c calls (Ken Fox)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 11 Jun 1997 14:28:38 -0400
From: "Douglas M. Croft" <dcroft@zoo.uvm.edu>
Subject: (no subject)
Message-Id: <339EEE56.388D@zoo.uvm.edu>
where did my posting go?
------------------------------
Date: Wed, 11 Jun 1997 09:34:33 -0600
From: Russell_Schulz@locutus.ofB.ORG (Russell Schulz)
Subject: Re: AWK to perl translation problem
Message-Id: <19970611.093433.5r1.rnr.w164w@locutus.ofB.ORG>
Brian Freeze <webmaster@deltastar.nb.ca> writes:
> I have run it through the "a2p" program
> substr($0, 216, length) > output_file2; # sent to o/p file
assuming you wanted a `print' in there:
from the FAQ:
6.8 a2p
translator to Perl
comes with Perl
doesn't handle multiple concatenations: e.g., var="x" "y" "z"
-> must be in pairs: e.g., var=( "x" "y" ) "z"
doesn't handle redirection: e.g., { print("foo") > "bar" }
-> no known workaround
--
Russell_Schulz@locutus.ofB.ORG Shad 86c
------------------------------
Date: 11 Jun 1997 18:33:49 GMT
From: jhd@Radix.Net (Joseph Davidson)
Subject: Berkeley DB file interface, bug report
Message-Id: <5nmr2d$ou1@news1.radix.net>
The code below will only open the file in read-only mode (with no error)
{
package ABC;
tie %CUSTDB, "DB_File",$database,
O_RDWR|O_CREAT, 0666, $::DB_HASH ;
}
Because it is inside a package, the barewords O_RDWR and O_CREAT are assumed
to exist within the package (which they don't). They evaluate as 0 and give
you read-only. To use the Berkeley DB interface from within a package, you
must do the following.
{ package ABC;
tie %CUSTDB, "DB_File",$database,
&::O_RDWR|&::O_CREAT, 0666, $::DB_HASH or
}
--
----------------------------------------------------------------------
Joseph Davidson Ph.D.
InterGuru -- Internet Training and Consulting
Technical Web Service, Perl/CGI, E-mail address conversion service
1501 Dublin Drive, Silver Spring, Md. 20902
voice 301 593 4152 ; fax 301 593 2541
jdavidson@interguru.com, http://www.interguru.com
----------------------------------------------------------------------
------------------------------
Date: Wed, 11 Jun 1997 23:25:45 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: converting mode from stat into ls style mode string
Message-Id: <9otnn5.2da.ln@localhost>
Sylvain Robitaille (sp_robi@sinclair.concordia.ca) wrote:
: I hope someone can help me here. I've read many web pages, scanned
: deja-news, and dug through the camel book, (2nd edition), and still
^^^^^^^^^
^^^^^^^^^ ???
: haven't found what I need. I've downloaded some sample scripts, some
: public scripts, some free scripts, and some script fragments, all to no
: avail...
: I'm trying to write a routine which will take the mode of a file, as
: returned by stat, and convert it into the ls style -rwxr-xr-x, (for
: example), string.
: If anybody's already done this, or knows how I could do it, I'd really
: appreciate it if you would post the solution.
After looking up stat() in the perlfunc man page, I see that the
permissions are in the 'mode' field.
A DejaNews search in c.l.p.m for "stat mode" found 82 matches...
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: 11 Jun 1997 22:12:00 GMT
From: "Cameron W. Skinner" <cameron@advancedsw.com>
Subject: Debugging Extensions
Message-Id: <01bc76b4$1e5ddcf0$351883cc@uther>
Hello,
Just wondering how one would go about debugging a perl extension in context
with the C++ app that is calling subroutines in that extension. What would
REALLY be cool, is if the debugger would pop up, causing the calling app to
stop processing while we step through the perl debugger.
Any suggestions?
Please reply to cameron@advancedsw.com.
Thanks,
Cam
Cameron W. Skinner
Advanced Software Technologies, Inc.
phone: (303)730-7981
email: cameron@advancedsw.com
fax: (303)730-7983
http://www.advancedsw.com
------------------------------
Date: Wed, 11 Jun 1997 19:25:37 -0600
From: Chad Taylor <cwt1959@rit.edu>
To: cwt1959@rit.edu
Subject: GD.pm for BUILD 306 (die at line 13)
Message-Id: <866074313.6941@dejanews.com>
Am having problems with running TEST.PL for GD.pm - because it died at
LINE 13 -- here is what is on LINE 13:
open(GRFILE, "< $FileIn") || die;
I am new to PERL - and understand a little of them. I am currently on a
PERL for WIN32 Build 306. The GD.pm and GD.pll are working, and placed in
the right PERL directories.
I don't know what to change on line 13... I did tried and change line 13
into:
open(GRFILE,">> $FileIn") || die;
However, I got died on line 15 -- here's what is on LINE 15:
$im = newFromGif GD::Image(GRFILE) || die;
Im lost here on what I'm supposed to "change". Hope one of you can help
me out here - please send your post to my email address too, if you don't
mind.
Thanks for your help and appreciate your time!
Chad Taylor
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Wed, 11 Jun 1997 23:16:35 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: global regex in an "if" statement
Message-Id: <37tnn5.naa.ln@localhost>
Michael Stearns (staci@datahost.com) wrote:
: Tad McClellan wrote:
: >
: > Michael Stearns (staci@datahost.com) wrote:
: > : put it into one scalar variable and then do a bunch of global
: > : replacements. My problem is with the if statement at the bottom. I
: > : cannot figure out how to make this work globally. It only works on the
: > : first instance that it matches.
: >
: > I don't understand what it is you want. If you had supplied some
: > sample data illustrating your problem, I would have attempted to
: > answer your question.
: Fair enough. This is what a relevant section of my document looks like
: when I get to this point in the script:
[ snip data. See example script below ]
: There are many instances of this pattern throughout my set of documents.
: I am trying to get the credit requirements to be listed in html tables.
Thanks. Now we have something to work with.
: > : open (INFILE,"$_") || die ("Cannot Open $_\n");
You do not need the double quotes around the $_. I tend to not use
double quotes unless I want/need variable interpolation. (just a
"style" nitpik)
$! will contain some helpful text explaining why the open() failed.
( eg: "Permission denied" )
If you leave the \n off of the die, the perl will supply the line
number that generated the die message. This can be helpful if you
have a bunch of open()s with the same die text.
open (INFILE,$_) || die ("Cannot Open $_ [$!]");
: >
: > : @text=<INFILE>;
: > : $text=join("",@text);
: >
: > You don't need that @text intermediate array:
: >
: > $text = join '', <INFILE>; # this is slower than other slurping methods...
: I came up with this method on my own and it has seemed to work for me.
Very good! There's More Than One Way To Do It ;-)
: Do you have a better method you would suggest?
With the join() method, the <INFILE> reads each line and puts it into
a list, then the join concatenates the list into a string.
undef $/;
$text = <INFILE>;
close(INFILE); # may as well close it right now, because it is at EOF
Doesn't bother with the breaking into lines, only to join the lines
again. It just slurps the whole file into the string.
: >
: > : <--------lots of other stuff in here----------------->
: >
: > : ####This is what many of my lines look like. This works well for doig a
: > : global search and replace.
: >
: > : $text=~ s^foo^bar^gs;
: >
: > The 's' modifier has no effect on matching that regex, you don't it.
: Are you referring to the "trailing" s? I do need the preceding s, don't
: I?
Yes and Yes ;-)
s///s is only needed if there is a dot in your regex. It makes the dot
match a newline.
s///m is only needed if there is a caret (^) or dollar ($) for
matching the beginning/end of a line in your regex.
: >
: > [ using a regex metacharacter as your regex delimiter is not a good habit
: > to get into
: > ]
: It seemed like every special character I could think of had some regex
: meaning. What character shoud I use?
The first choice should be the usual slash '/'. If you have slashes
in your pattern, then turn to something else "to avoid LTS (leaning
toothpick syndrome)". [ quote from the perlop man page ]
I like to use # (at least until Perl 5's extended regexes came around).
If I need the # for comments in an extended regex then I usually go
for ! instead.
But, a quick scan of this keyboard in front of me reveals all of these
other punctuation characters that are not regex metacharacters to
choose from:
~ ! @ # % & _ = ; : ,
Or even the "balanced" chars:
s{foo}[bar]g;
[ snip bad example ]
: So I guess what I am trying to figure out is a way to pull out a section
: of my document (since this is a course catalog, there are lots of
: sections like this) and convert it into a table.
: These paragraphs are unique in that they have 5 spaces followed by a
: digit. I believe I can turn lines that have this pattern into a two cell
: table line, but I do not see how to establish, in the context of my
: document where the table starts and where it ends. Any help would be
: appreciated?
Maybe this will help:
--------------------------
#! /usr/bin/perl -w
while (<DATA>) {
if (/([^>]+) {5}(\d+)/) { # found the first table row
printf "%-30s %3d\n", $1, $2; # change this to markup the table
while (<DATA>) { # get the rest of the rows
last unless /([^>]+) {5}(\d+)/; # exit the inner while loop
printf "%-30s %3d\n", $1, $2; # change this to markup the table
}
}
}
__DATA__
<P>Curriculum requirements are being reviewed by the faculty. A list of
requirements for 1997­98
is available from the program's graduate secretary.
<P><B><I>Ph.D. Degree Requirements 155 credits</I></B>
<P>Psychological foundations 27
<P>Research competencies 41
<P>Practitioner competencies 63
<P>Professional competencies 9
<P>Elective seminars 15
<P>The D.Ed. program in counseling psychology is inactive.
<H3>
<B>School Psychology</B>
--------------------------
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Wed, 11 Jun 1997 14:46:14 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: global regex in an "if" statement
Message-Id: <6avmn5.ij8.ln@localhost>
Michael Stearns (staci@datahost.com) wrote:
: I have a large (by my standards) regex script. I have taken input and
: put it into one scalar variable and then do a bunch of global
: replacements. My problem is with the if statement at the bottom. I
: cannot figure out how to make this work globally. It only works on the
: first instance that it matches.
I don't understand what it is you want. If you had supplied some
sample data illustrating your problem, I would have attempted to
answer your question.
: Are there any modifiers I can use to make this work globally or are
: there other techniques that will make it work?
: ################################
: foreach (@ARGV) {
: open (INFILE,"$_") || die ("Cannot Open $_\n");
: @text=<INFILE>;
: $text=join("",@text);
You don't need that @text intermediate array:
$text = join '', <INFILE>; # this is slower than other slurping methods...
: <--------lots of other stuff in here----------------->
: ####This is what many of my lines look like. This works well for doig a
: global search and replace.
: $text=~ s^foo^bar^gs;
The 's' modifier has no effect on matching that regex, you don't it.
[ using a regex metacharacter as your regex delimiter is not a good habit
to get into
]
: #### Here's where I am stuck. This only works on one instance and I so
^^^^^^^^^^^^^^^^^^^^^
I wonder what that instance looks like. Hard to interpret a pattern
match when the string to be matched against is not given...
: far can't get any modifiers to make it work differently.
: if ( $text =~ /foo/ && $text !~ /bar/) {
^^^^^^^^^^^^^^
This part will always be false, if you ran that s^foo^bar^s first.
So the second part never needs to be evaluated...
: print "YEAH\n";
: }
: ###################################
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: 11 Jun 1997 21:10:26 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Help! perl -d under OpenWindows
Message-Id: <5nn482$hru$2@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Mark Shaw
<mshaw@asic.sc.ti.com>],
who wrote in article <5nn14r$p2d$1@spock.asic.sc.ti.com>:
> Anyone run into this problem?
>
> I'm using OpenWindows version 3 on a Sun Sparc20 running SunOS 5.5.
> If I try to run the perl (version 5.003) debugger in a cmdtool win-
> dow, I get the following (the first line is my script invokation,
> where the script has #!/usr/local/bin/perl -d as the first line):
>
> resize: Time out occurred
> Unable to get Terminal Size. The TIOCGWINSZ ioctl didn't work. The COLUMNS
> and LINES environment variables didn't work. The resize program didn't work.
> at /apps/perl5.003/lib/site_perl/Term/ReadKey.pm line 291.
As you see, it is a Term::ReadKey problem. Fix it at this end, if you
want to use an obsolete broken software like cmdtool.
Ilya
P.S. On the other hand, try to change
local($num_cols,$num_rows) =
Term::ReadKey::GetTerminalSize($term_OUT);
to
local($num_cols,$num_rows) =
eval { Term::ReadKey::GetTerminalSize($term_OUT) };
in Term/ReadLine/readline.pm.
Please report the results.
Ilya
------------------------------
Date: Wed, 11 Jun 1997 11:40:42 -0700
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: MS-DOS port of the Perl programming language
Message-Id: <Pine.GSO.3.96.970611113736.18839L-100000@kelly.teleport.com>
On 10 Jun 1997, it was written:
> From: 13j5;l@jumbo.com
Hmmm... Smells like spam...
> Get NEW MS-DOS port of the Perl programming language Shareware As It's
> Written!
Perl is not shareware. Never has been. Never will be.
What do you do for Perl that CPAN doesn't already do better?
http://www.perl.org/CPAN/
http://www.perl.com/CPAN/
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 12 Jun 97 06:32:18 GMT
From: "Fredrik Lindberg" <flg@vhojd.skovde.se>
Subject: Re: Need a list of all subdirectories (but no files)
Message-Id: <01bc76fa$60e8c3a0$e20f10c2@odens.di.vhojd.skovde.se>
Stephan D. Cote <sdcote@lci.net> wrote in article
<339EA905.AEC21D05@lci.net>...
> Does anyone have a simple way to get a listing of all the sub
> directories under a given directory with a PERL script without listing
> all the files?
>
Hi!
You can use the File::Find module in Perl, which makes it easy to
traverse directory trees.
Here is one way of doing it:
#!/usr/bin/perl
#
use File::Find;
# Pick up starting directory from commandline
my $directory = shift;
# Our list of directories.
my %Dirs = ();
sub wanted {
# I use a hash to store the directory name.
$Dirs{$File::Find::dir} ++;
}
# Ok, execute the find function
find(\&wanted, $directory);
# ... and traverse our hash.
foreach $dir (sort keys %Dirs) {
print $dir, "\n";
}
__END__
Hope this helps
/fredrik
------------------------------
Date: Wed, 11 Jun 1997 14:22:22 -0400
From: "Douglas M. Croft" <dcroft@zoo.uvm.edu>
Subject: Need help with Perl command
Message-Id: <339EECDE.206C@zoo.uvm.edu>
Does anyone know how the Perl commands for:
Reckognizing whether a string exists in a file with a bunch of strings
(one on top of another)?
------------------------------
Date: Wed, 11 Jun 1997 15:42:22 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "Douglas M. Croft" <dcroft@zoo.uvm.edu>
Subject: Re: Need help with Perl command
Message-Id: <Pine.GSO.3.96.970611154110.5767O-100000@kelly.teleport.com>
On Wed, 11 Jun 1997, Douglas M. Croft wrote:
> Does anyone know how the Perl commands for:
>
> Reckognizing whether a string exists in a file with a bunch of strings
> (one on top of another)?
I think you're looking for something like this.
while (<>) {
next unless /mystring/i;
# Do something here....
}
Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 11 Jun 1997 12:01:02 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "P.M.Wong" <s11976@ctsc.hkbc.hk>
Subject: Re: Newbie:To PUSH or not to PUSH?
Message-Id: <Pine.GSO.3.96.970611115522.18839Q-100000@kelly.teleport.com>
On 11 Jun 1997, P.M.Wong wrote:
> Being a newbie in perl, i often seen scripts that read the whole file
> into an array, so that further manipulation of the file can be done.
You don't have to be a 'newbie' to see those!
> There are mainly 2 ways of doing so:
> 1. open (FILE, $filespec);
> @LINES=<FILE>;
> ... etc
>
> 2. open (FILE, $filespec);
> while (<FILE>) {
> push(@lines, $_);
> }
Of course, you'll check that the open() succeeded...
> a) For both methods, is there any limit on the size of the file that it
> won't break down, i.e. will all the lines in the FILE be read into the
> array @LINES , for most files ? If not, what are the max. size of FILE
> for these to work ok?
Either one will work until you run out of (virtual) memory.
> c) generally speaking, which method is preferable, 1 or 2
I prefer the first, which should be faster without any real disadvantages.
But don't use either when you can process the file a line at a time, or
when you can extract just part of the data and work with that.
Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 11 Jun 1997 23:24:44 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Perl 5.004/Tk402.000 MainWindow
Message-Id: <5nnc3s$i1o@fridge-nf0.shore.net>
Mike Roth (mroth@wgate.com) wrote:
: After having installed perl5.004/Tk402.000 on
: FreeBsd I cannot run the demos (even the simplest).
: I get an error that is the following:
To my knowledge, Tk402.000 is a "developer" or alpha release. 400.202
is the lastest version according to the recently updated pTk FAQ. You
should also check comp.lang.perl.tk.
--
Nathan V. Patwardhan
nvp@shore.net
------------------------------
Date: 11 Jun 1997 19:43:57 GMT
From: scott@lighthouse.softbase.com (Scott McMahan)
Subject: Re: Perl for NT and Serial Port Communications
Message-Id: <5nmv5t$3ik$2@mainsrv.main.nc.us>
Gary Dewrell (gary@vvm.com) wrote:
: I need to be able to access a serial port using perl for NT and also send
: data in octal and receive data in octal and then decode that data. Can
: anyone please point me in the right direction to find this info.
Perl is not really a good language for this kind of stuff because it is
not integrated into the Win32 API the way it is the UNIX kernel calls.
You'd have to make calls down into the guts of the kernel API to do
this, and deal with kernel object handles, and Win32 Perl is nowhere
near able to do this.
I'd seriously look for a C solution that can call OpenFile directly and
deal with kernel objects. I can't think of any way this kind
of low-level system code could be done in NT Perl as it
exists now.
Scott
------------------------------
Date: 11 Jun 1997 15:26:46 GMT
From: orwant@fahrenheit-451.media.mit.edu (Jon Orwant)
To: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: Perl obfuscated contest
Message-Id: <ORWANT.97Jun11112646@fahrenheit-451.media.mit.edu>
Andrew Johnson <ajohnson@gpu.srv.ualberta.ca> writes:
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Newsgroups: comp.lang.perl.misc
Date: Sat, 07 Jun 1997 20:27:47 -0500
Organization: RTS
Andrew M. Langmead wrote:
>
> "CS" <cswanson@io.com> writes:
>
> >Can any kind soul tell me where the Perl obfuscation contest hangs out.
> >Web site, email, news group, etc?
>
> The first offical obfuscated perl contest was conducted by The Perl
> Journal. The results are at
> <http://orwant.www.media.mit.edu/tpj/contest-obfusc-entries>
actually that was the 0th annual obfuscated perl contest :-)
and the 1st is to be formally announced in the next issue (#6) of
the Perl Journal
regards
andrew
Yup! I'll post the official announcement here soon, probably this
weekend. In short: the deadline is July 25, and each of the four
category winners will win $100, a trophy, and eternal infamy.
-Jon
----------------
Jon Orwant
The Perl Journal
http://tpj.com/
------------------------------
Date: Wed, 11 Jun 1997 22:33:59 -0600
From: spg1@ix.netcom.com
To: abigail@fnx.com
Subject: Re: Printing Prime Numbers
Message-Id: <866048831.15678@dejanews.com>
In article <EBHHMv.2Ft@nonexistent.com>,
abigail@fnx.com wrote:
>
> Uhm, it took 63s on my sparc, vs 17s for my list implementation.
>
> Simple analysis shows your solution is real bad, and doesn't scale
> well at all. [1]
> [1] Using $max = 500000, your solution took 75m 1s, vs 3m 35 for the
> traditional sieve.
[to beat a dead horse...] If you eliminate the even numbers from your
array, you gain a considerable speedup.
For 500K, your previous script gives me 60s, while I get 32s with my
version (of your very good program) [this is with output redirected to
null - it's a bit slower otherwise, and we're really interested in how
fast it finds the answer here, and not how long it takes to print :) ]
It is difficult to tell the difference between the two versions until
it's given a number larger than 1000.
########################
#!/usr/local/bin/perl
my ($prime, $max) = (3, shift || 50);
$iprime = 0;
$imax = int(($max - 3)/2);
my @sieve = (map {1;} ($iprime .. $imax) );
while (($product = $prime * $prime) <= $max)
{
$iproduct = int(($product - 3)/2); #compute index
print "$prime ";
# this skips even numbered multiples implicitly
do {$sieve [$iproduct] = 0;} while (($iproduct += $prime) <= $imax);
do {$iprime ++;} while !$sieve [$iprime];
$prime = 2 * $iprime + 3; #compute next prime from index
}
print "2 ";
map
{
print 2*$_+3, " " if $sieve[$_];
} ($iprime .. $imax);
print "\n";
#####################
-Shaun
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: 11 Jun 97 19:42:37 GMT
From: "Brian Caldwell" <brian@nemonet.com>
Subject: Running other Perl scripts within and returning the results to a variable
Message-Id: <01bc769f$8e0b3cb0$40b08acd@cueball>
Hello. I'm running a simple perl script "account_info.pl" that calls
another script via the line:
$info=`userlog.pl`;
Userlog.pl is SUPPOSED to return text which will be stored in the variable
$info as stated above. The programs are run but nothing is returned. Is
the above the wrong syntax for Perl 5 for NT? I've even set the userlog.pl
file to a two line script that prints "Hello World" but it is not returned
even.
thanks in advance..
gw
------------------------------
Date: Wed, 11 Jun 1997 23:53:47 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Sorting Numerically
Message-Id: <rcvnn5.0ia.ln@localhost>
TechMaster Pinyan (jefpin@bergen.org) wrote:
^^^^^^
: how do I sort it numerically? i.e.:
^^^^^^^^^^^
^^^^^^^^^^^
You search for "numerically" in the perlfunc man page...
A true Master would RTFM, at least a little tiny bit, before posting.
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: 12 Jun 1997 05:03:41 GMT
From: gerdemb@rice.edu (Ben Neil Gerdemann)
Subject: Un-taint a variable how?
Message-Id: <5nnvvd$if2$1@joe.rice.edu>
Hello,
We are running a setuid script and have need to un-taint a variable. How
is this possible?
Thanks,
Ben
------------------------------
Date: 11 Jun 1997 19:18:33 GMT
From: kaz@vision.crest.nt.com (Kaz Kylheku)
Subject: Re: What does "UNIX" stand for..
Message-Id: <5nmtm9$qnc@bcrkh13.bnr.ca>
In article <slrn5prurf.ioe.darin@connectnet1.connectnet.com>,
Darin Johnson <darin@usa.net.delete_me> wrote:
>In article <339D7121.F121CA82@inorbit.com>, av wrote:
>>I don't know what the "UNIX Haters Handbook" is, but sounds like
>>bullshit...
>
>It is :-) It's basically written by a bunch of disgruntled Lisp
>Machine users and the like, bummed out that UNIX got popular despite
>all the bugs and oddities. For every point they make that is valid,
>they have another two points that are spurious, silly, illogical,
>or ad-hominem.
Most of the book is inaccurate. For example, at one point it implies that
UNIX doesn't have memory mapped files or virtual memory. In other words,
it's largely based on operating systems that were formerly known as UNIX
(like before 1978).
I also don't like that the book makes fun of 'trn', the newsreader which I'm
using right now, because it has a display for each article which looks like
this:
comp.unix.advocacy #43844 (2 + 3 more) --(?)--(?)--(?)+-(1)
From: darin@usa.net.delete_me (Darin Johnson) \-(?)+-[1]
Newsgroups: comp.lang.perl.misc,comp.lang.c++, \-[1]--[1]
The graphical display on the right represents the article thread tree, of which
you see a small ``window'' at a time. The question marks are articles that are
not available on the news server but may become available soon. You can move a
highlighted marker around this virtual tree using the arrow keys, thus cruising
around the thread of replies with ease. It's very intuitive and ``visual'',
and beats graphical newsreaders hands down. Only a clueless twit could have
written the inane remarks that appear in the book.
------------------------------
Date: 11 Jun 1997 19:20:35 GMT
From: kaz@vision.crest.nt.com (Kaz Kylheku)
Subject: Re: What does "UNIX" stand for..
Message-Id: <5nmtq3$qrj@bcrkh13.bnr.ca>
In article <slrn5prurf.ioe.darin@connectnet1.connectnet.com>,
Darin Johnson <darin@usa.net.delete_me> wrote:
>In article <339D7121.F121CA82@inorbit.com>, av wrote:
>>I don't know what the "UNIX Haters Handbook" is, but sounds like
>>bullshit...
>
>It is :-) It's basically written by a bunch of disgruntled Lisp
>Machine users and the like, bummed out that UNIX got popular despite
^^^^^^^^^^^^^
Ah, that would explain the information content in the book, which is largely
out of date by at least 22 years. UNIX doesn't have memory mapped files? Get
real...
------------------------------
Date: Wed, 11 Jun 1997 23:42:53 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: while(<>){if(/cond/){while(<> ~= /cond2/) ...
Message-Id: <dounn5.gha.ln@localhost>
Darwin O.V. Alonso (dalonso@u.washington.edu) wrote:
: My general goal is to match a start pattern (START) in a file, then
: do something to all the lines until a stop pattern (STOP) is reached.
: The following perl script does that (5.000).
: However, the more concise construct commented out below, doesn't work.
: #!/usr/local/bin/perl -w
: open(IN,"infile");
: while(<IN>){
: if ( /START/){ TB: { while( <IN> ){ (/STOP/) and last TB; print ;}}} #works
: #if ( /START/){ while( <IN> !~ /STOP/){ print $_; }}
: }
: I.E.:
: The above prints: yes1\nyes2\n for "infile" (see below).
: However if the comment is shifted to the first if statement,
: it prints: START\nSTART\n for the infile. I.E. the $_ no longer
: contains to the current line, but (/STOP/) compares to the current line.
: Why?
Because <IN> is assigned automagically to $_ when it is the *only thing*
in the while conditional (like in the first if statement).
If you want to have anything else in the conditional, then it is up
to you to assign the input line to a variable.
: How can I make the second construct work?
by assigning the input line to $_ (I cannot leave it formatted that
way either):
----------------------------
while(<IN>){
if ( /START/) {
while( ($_=<IN>) !~ /STOP/)
# ^^^^^^^^^
{ print }
}
}
----------------------------
: I can't use
: "print if /START/ .. /STOP/"
: due to the complexity of what I want to do before, after and between
: these conditions.
: Thanks,
You're welcome.
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: 12 Jun 1997 05:58:00 GMT
From: py@ecst.csuchico.edu (Pythagoras Watson)
Subject: Re: while(<>){if(/cond/){while(<> ~= /cond2/) ...
Message-Id: <5no358$dd7@charnel.ecst.csuchico.edu>
According to Darwin O.V. Alonso <dalonso@u.washington.edu>:
:My general goal is to match a start pattern (START) in a file, then
:do something to all the lines until a stop pattern (STOP) is reached.
:The following perl script does that (5.000).
:However, the more concise construct commented out below, doesn't work.
:
:#!/usr/local/bin/perl -w
:open(IN,"infile");
:while(<IN>){
: if ( /START/){ TB: { while( <IN> ){ (/STOP/) and last TB; print ;}}} #works
: #if ( /START/){ while( <IN> !~ /STOP/){ print $_; }}
:}
Try:
if ( /START/){ while( defined ($_ = <IN>) && !/STOP/){ print $_; }}
Your second one didn't work because the "<IN>" construct only assigns to $_
when it is the only thing in the while loop. Also, it wouldn't have ever
ended if the STOP pattern wasn't in the input file.
:I.E. The above prints: yes1\nyes2\n for "infile" (see below). However if
:the comment is shifted to the first if statement, it prints:
:START\nSTART\n for the infile.
Which is what the outer while loop assigned to $_.
:I.E. the $_ no longer contains to the current line, but (/STOP/) compares
:to the current line.
The inner loop was never told to assign anything to $_. Instead it was
instructed to read in a line and search for "STOP" returning true if it
wasn't found.
--
Py -- 3.141592653589793238462643383279502884197169399375105...
Pythagoras Watson -- "Live long and may all your kernels pop."
INET: py@ecst.csuchico.edu ============ COMPUSERVE: 72162,2676
------------------------------
Date: Wed, 11 Jun 1997 19:01:41 GMT
From: danew@enterprise.net (Matthew Burnham)
Subject: Re: write a new htmp page
Message-Id: <33b0bde6.19577687@194.72.192.4>
"DAVID GILMARTIN" <surgery@powernet.co.uk> wrote:
>i am new and you may think i am stupid
>
>please give a bit of code to for a cgi file that creates a new page in the
>same directory.
>
>i can write a page on the fly but it's not saved
open(FILE, ">newfile.html");
print FILE "Whatever you want";
close(FILE);
You'll need to check that you've chmodded the directory to allow the
webserver to write new files in the directory you've chosen (use chmod
777).
--
Matthew Burnham, Manager, MindWeb | danew@enterprise.net
Commercial web design and hosting, reasonable rates
UKP24/Mb/Year for DIY space | mindweb@pobox.co.uk
FTP, CGI, password protection, etc. too!
http://www.virtual-pc.com/mindweb/
------------------------------
Date: 11 Jun 1997 21:24:56 GMT
From: fox@pt0204.pto.ford.com (Ken Fox)
Subject: Re: XS:Keeping a variable btwn c calls
Message-Id: <5nn538$o1g9@eccws1.dearborn.ford.com>
James Heck <jheck@merck.com> writes:
> I would like to call one C program from my Perl file, get it's
> return value as well keep track of a pointer it used. I then
> need to make that pointer available to another C program.
First off, please read the perlxs documentation and tutorial. It's
really good stuff put together by a lot of talented people.
I'm not sure if you mean a separate executable program, or just a
function. XS only helps with functions. There are many ways to
pass data between functions. The best way is to create a logical
Perl interface and have Perl manage your program state rather than
using lots of secret internal variables in your C code. You'll be
happy you did this, even if it means writing new C wrapper
functions around your existing code.
> Can i just put the variable in the OUTPUT section
> of my .xs file where i have the function prototype?
I don't know what variable you mean. Is it the return value of
the function? Or is it some sort of state variable that the
function used? I'm sure that XS and Perl can do what you need.
You just have to tell us more about your problem. If you want
help, you'll have to show us the function prototypes and an
example of how they are used together.
Here's a bit of code that I frequently use to lookup a value and
then pass the value to another routine. (This is using C++ code
but the concept is identical in C. It's also missing some error
checking, etc.)
This function finds an object:
apParameterRef *
apAppContext::find_ref(name)
char * name
This function takes the object returned from above and does
something with it:
SV *
apParameterRef::get_value()
CODE:
RETVAL = THIS->get_value().as_perl_scalar();
OUTPUT:
RETVAL
In Perl it works something like this:
my $foo = $context->find_ref("foo");
print "foo = ", $foo->get_value(), "\n";
- 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: 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 604
*************************************