[8149] in Perl-Users-Digest
Perl-Users Digest, Issue: 1767 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 30 03:09:47 1998
Date: Fri, 30 Jan 98 00:00:28 -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 Fri, 30 Jan 1998 Volume: 8 Number: 1767
Today's topics:
Re: Access Log <subbotin@lpi.ac.ru>
Re: Another "uninitialized variable" problem <rjk@coos.dartmouth.edu>
Re: Array and Split? (Martin Vorlaender)
Re: Can anyone help me?????????????? (brian d foy)
Re: Can anyone help me?????????????? (Gabor)
Re: Can anyone help me?????????????? (Craig Berry)
daemonizing -- value of setpgrp()? (David Alan Pisoni)
Re: Don't use signal handlers (was Re: Child processes) <tchrist@mox.perl.com>
Re: Efficiently break a string of [a..z]+ into words us <joseph@5sigma.com>
Re: Enlightenment: regexes: fun with /x <rjk@coos.dartmouth.edu>
Re: Enlightenment: regexes: fun with /x (Ilya Zakharevich)
Re: Help needed: I cannot seem to get this variable to <rjk@coos.dartmouth.edu>
Re: Help with SORT <joseph@5sigma.com>
Re: Help with SORT <joseph@5sigma.com>
Re: HTML/CGI to play midi file? <snorris@post.cis.smu.edu>
Re: HTML/CGI to play midi file? (brian d foy)
Re: Problems converting Bourne shell to Perl <rjk@coos.dartmouth.edu>
Re: Problems converting Bourne shell to Perl (Charles DeRykus)
Re: regexes: fun with /x (brian d foy)
Re: regexes: fun with /x <rjk@coos.dartmouth.edu>
Re: regexes: fun with /x (Abigail)
Re: script does things as different user? <rjk@coos.dartmouth.edu>
Re: Survival Of perl (Chris Nandor)
Re: Win32 Perl & Internet Information Server 4.0 (NT) (Richard Rowell)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 30 Jan 1998 06:57:25 GMT
From: Alexei Subbotin <subbotin@lpi.ac.ru>
Subject: Re: Access Log
Message-Id: <6artkl$fl$1@jumbo.demos.su>
Geurt Schimmel <geurt@sybase.com> wrote:
> Hans Van Lint wrote:
>>
>> $logfile = "../logs/access_log";
>> open(best, $logfile) || "Error"
>>
>> I get the following error:
>> ../logs/access_log: Permission denied
>>
> In fact, you'r trying open(best,"> $logfile") - and that won't work if you're
> not root. When running this program as root, it will remove the logfile
> completely...
A curious idea to run cgi-scripts as root ...
Would you care to mail me the URL of your server?
------------------------------
Date: Thu, 29 Jan 1998 23:31:47 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: Another "uninitialized variable" problem
Message-Id: <34D157B3.B8954439@coos.dartmouth.edu>
faverNoSpam@austin.ibm.com wrote:
>
> The following code is resulting in an "uninitialized variable"
> warning:
>
> [snip]
> elsif ($xnode_num eq '1') <<---ERROR ON THIS LINE
> {$fence_bits = ($fence_bits | "01000")}
> [snip]
I believe this demonstrates part of the problem:
~> perl -w
if (1) {
$a = $b + 1;
}
Use of uninitialized value at - line 1.
The warning is referring to the line containing the if statement, rather than
the statement
in the BLOCK containing the use of an unitialized value.
This only occurs when the BLOCK contains a single statement: with multiple statements,
the correct line number is printed.
(A bug report on this has been sent.)
So, the uninitialized value could be in the line:
{$fence_bits = ($fence_bits | "01000")}
However, I noticed that you did initialize $fence_bits in your code.
My only advice is to make sure it really is initialized when you reach that line.
Perhaps a temporary debug statement:
warn '$fencebits is ', (defined($fence_bits) ? 'defined' : 'not defined'), "\n";
Hope that helps!
Chipmunk
------------------------------
Date: Fri, 30 Jan 1998 07:45:51 +0100
From: martin@RADIOGAGA.HARZ.DE (Martin Vorlaender)
Subject: Re: Array and Split?
Message-Id: <34d1771f.524144494f47414741@radiogaga.harz.de>
Craig A. Keefner (keefner@kinetic.com) wrote:
[...]
: ## Example returned list of values or @array
: '85-89 S.W., moveable item1, w/zzzzz, heated............. 1A9-1573A
: non-heated......... 1A9-1573C
: w/o zzzzz; heated........... 1A9-1573B
: non-heated....... 1A9-1573D
: stationary itemb, heated.................... 1A9-1573E
: non-heated................ 1A9-1573F
: exc. S.W.......................................... 1A9-1234B
: '90 (S.W.), moveable item1, w/zzzzz, heated........... 1A9-1573A
: non-heated....... 1A9-1573C
: w/o zzzzz; heated......... 1A9-1573B
: non-heated..... 1A9-1573D
: stationary itemb, heated.................. 1A9-1573E
: non-heated.............. 1A9-1573F
: The 9 digit numbers (1A9-1573B e.g.) are the ones I need to strip
: off or hide. What I really want to do is put a radio button next to each
: which when selected/entered, sends me the corresponding part number.
use CGI;
.
.
for $i (0..$#array)
{
$partno[$i] = substr( $array[$i], -9 );
$text = substr( $array[$i], 1, -9 );
$text =~ s/\.*\s*$//; # strip off trailing "..."
$label{$partno[$i]} = $text; # This assumes that part numbers are unique
}
print CGI->radio_group('group_name', \@partno, '-', 1, \%label);
Hope it helps,
Martin
--
| Martin Vorlaender | VMS & WNT programmer
Ceterum censeo | work: mv@pdv-systeme.de
Redmondem delendam esse. | http://www.pdv-systeme.de/users/martinv/
| home: martin@radiogaga.harz.de
------------------------------
Date: Thu, 29 Jan 1998 23:39:39 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Can anyone help me??????????????
Message-Id: <comdog-ya02408000R2901982339390001@news.panix.com>
Keywords: from just another new york perl hacker
Please read this information on how to choose a good subject for a post:
<URL:http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post>
In article <34CFF3EC.4FA@cse.bridgeport.edu>, seong@cse.bridgeport.edu posted:
>Please, Can anyone know the value of PERL language? I mean if I write
>200 lines of perl program, how much is this program worth? How much is
>this on the market?
the line count means nothing. the tool you use means nothing. the
problem that you solve is the only thing that counts. clients
don't care about the really cool techie stuff.
>As a CGI programmer in perl language, how much can I make a month?
with some of the offers i've seen lately, you could make nothing.
however, this isn't a perl issue. go to a bookstore and pick up
a book on operating a consultancy. the same problem exists for
any work of this type whether it is programming, housebuilding, or
lawn-mowing. perhaps the business newsgroups would be of more
assistance.
--
brian d foy <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
if you charge too little, some clients will ignore you.
------------------------------
Date: 30 Jan 1998 04:45:12 GMT
From: gabor@vmunix.com (Gabor)
Subject: Re: Can anyone help me??????????????
Message-Id: <slrn6d2mdo.a8k.gabor@vnode.vmunix.com>
In comp.lang.perl.misc, Seong Y. Kim <seong@cse.bridgeport.edu> wrote :
# Hi, there. . .
#
# Please, Can anyone know the value of PERL language? I mean if I write
# 200 lines of perl program, how much is this program worth? How much is
# this on the market?
Depends on what's on each line. ;-)
#
# As a CGI programmer in perl language, how much can I make a month?
That depends on how good you are. Anywhere from 0 to ??
------------------------------
Date: 30 Jan 1998 04:31:20 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Can anyone help me??????????????
Message-Id: <6arl2o$obq$1@marina.cinenet.net>
Seong Y. Kim (seong@cse.bridgeport.edu) wrote:
: Please, Can anyone know the value of PERL language? I mean if I write
: 200 lines of perl program, how much is this program worth? How much is
: this on the market?
What do those 200 lines do? More important, do they work? Are they
robust? Maintainable? Efficient? 200 lines of bug-ridden mess have
negative value; 200 lines of tight, well-documented, and correctly
operating code are a treasure. A 200 line feature-depleted FormMail
clone is worth less than (say) a 200-line CGI-database gateway optimized
for high capacity and simultaneous accesses.
I'm not just being difficult, either. What you can earn in the software
field depends very strongly on the quality of your designs and code.
: As a CGI programmer in perl language, how much can I make a month?
Anywhere from $0 upward. Most people I know doing this sort of thing
seem to be in the $30k - $60k /year range ($2500 - $5000 /month), but
there are plenty of people well outside this band in both directions.
---------------------------------------------------------------------
| 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, 29 Jan 1998 22:25:23 -0800
From: david@cnation.com (David Alan Pisoni)
Subject: daemonizing -- value of setpgrp()?
Message-Id: <david-2901982225230001@prokofiev.cnation.com>
Keywords: daemon setpgrp TIOCNOTTY
Hello,
I have a quick question regarding "daemonizing". I haven't written a
daemon script for a very long time, and so I thought my memory was in need
of refreshing on the subject. I looked in the Perl FAQ, and it stated
that using the TIOCNOTTY ioctl on /dev/tty, and closing the STDERR,
STDOUT, and STDIN pipes would effectively daemonize the process. But when
I looked back in some of my old code, I was using setpgrp() to achieve
this state. Is that a deprecated methodology? Is it not portable
(between UN*Xes, of course)? Or is it just "another way of doing it" (in
the spirit of Perl.)
Just curious,
David Pisoni -- <david@cnation.com>
CyberNation -- <http://www.cnation.com/>
310/656-3450 -- 310/656-3453 (fax)
"Virtue is more to be feared than vice, because its excesses
are not subject to the regulation of conscience."
-- Adam Smith
------------------------------
Date: 29 Jan 1998 14:47:26 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Don't use signal handlers (was Re: Child processes)
Message-Id: <6aq4pu$mnr$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
joseph@5sigma.com writes:
:I'm going to have to temper what I just said. It's pretty likely
:that $SIG{CHLD} = sub { wait } is going to cause a problem if
:your program is spawning and reaping children at a good clip
:for a period of time. I can't remember seeing it happen before
:since I've never had an application like that. But it will bite
:you sooner or later.
:
:You could avoid that particular problem with a double fork, or
:if you are certain that your script will run only on SysV machines,
:by setting setting $SIG{CHLD} to ignore.
Virtually all SysV machine these days have sigaction().
The problem you get from rabid spawning is that you might
miss kids. You have to use something more like this:
$SIG{CHLD} = sub
use POSIX ":sys_wait_h";
use vars '%Kid_Status';
my $child;
# -1 means no kids left, 0 means living kids still
# otherwise means we just zapped a zombie
while (($child = waitpid(-1,WNOHANG)) > 0) {
$Kid_Status{$child} = $?;
}
}
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
Love your enemies: they'll go crazy trying to figure out what you're up to.
------------------------------
Date: Fri, 30 Jan 1998 00:15:37 -0700
From: "Joseph N. Hall" <joseph@5sigma.com>
Subject: Re: Efficiently break a string of [a..z]+ into words using dictionary
Message-Id: <34D17DA5.44568BC7@5sigma.com>
Following is a program illustrating the general idea. /usr/dict/words
is missing plurals and conjugated verbs and whatnot, so it's not
perfect.
I would avoid using regexes (substr is faster when you can use it),
and would definitely not be passing the array around on the stack!
-joseph
print "digesting words, please wait ...\n";
open WORDS, "/usr/dict/words" or die "couldn't open words: $!";
my %words;
chomp, $words{$_}++ while <WORDS>;
close WORDS;
print "... words digested\n";
delete @words{'b'..'h','j'..'n','p'..'z'};
sub dictsplit {
my ($frag, $words) = @_;
unless (length $frag) {
print join("+", @$words), "\n";
return;
}
for (my $length = 1; $length <= length $frag; $length++) {
if ($words{substr $frag, 0, $length}) {
push @$words, substr($frag, 0, $length);
dictsplit(substr($frag, $length), $words);
pop @$words;
}
}
}
print "enter your words, one per line (^D to exit):\n";
while (<>) {
chomp;
dictsplit lc($_), [];
}
Zachary Brown wrote:
>
> For a random text generation program I'm working on (actually a set of
> programs whose tasks are to feed potential text to each other---it's
> weird), I've been trying to time-optimize the following recursive
> subroutine (which is heavily used by the program), [...]
>
> #!/usr/bin/perl -w
>
> %hash = ("at", "w", "eat", "w", "i", "w",
> "it", "w", "rye", "w", "try", "w");
> print join("\n", breakwords("itryeat")), "\n";
>
> sub breakwords {
> my($string, $sofar) = @_;
> my($newstring, $newsofar, @total);
>
> (exists $hash{$string} && $hash{$string} =~ /w/) &&
> push(@total, ($sofar ? "$sofar $string" : $string));
> while($string =~ s/(.)(.)$/$1/) {
> $newstring = defined $newstring ? "$2$newstring" : $2;
> if(exists $hash{$string} && $hash{$string} =~ /w/) {
> $newsofar = $sofar ? "$sofar $string" : $string;
> push(@total, &breakwords($newstring, $newsofar));
> }
> }
> @total;
> }
--
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: Fri, 30 Jan 1998 00:10:55 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
To: ilya@math.ohio-state.edu, rootbeer@teleport.com, comdog@computerdog.com, *@qz.to
Subject: Re: Enlightenment: regexes: fun with /x
Message-Id: <34D160DE.2C75D525@coos.dartmouth.edu>
[courtesy CCs to Ilya, Tom P, brian, and Eli]
Question:
Rx is a regex with whitespace and/or comments.
R is Rx with the comments and embedded whitespace removed.
Find a useful Rx such that /Rx/x works, but /R/ does not.
Answer:
Rx = '^\w*$ (?!\n)'
This regex can be used to determine if the target string consists entirely of word-characters.
Demonstration:
DB<1> $_ = "abc\n"
DB<2> p /^\w*$/
1
DB<3> p /^\w*$ (?!\n)/x
DB<4> p /^\w*$(?!\n)/
/^\w*15 60 15?!\n)/: unmatched () in regexp at (eval 10) line 2, <IN> chunk 4.
So, there you have it. I apologize for the confused attempts to explain the question.
I hope the answer has some interest to make up for all that.
As an aside, this will also work:
/^\w*\Z(?!\n)/
Chipmunk
------------------------------
Date: 30 Jan 1998 06:17:20 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Enlightenment: regexes: fun with /x
Message-Id: <6arr9g$kj7$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Chipmunk
<rjk@coos.dartmouth.edu>],
who wrote in article <34D160DE.2C75D525@coos.dartmouth.edu>:
> [courtesy CCs to Ilya, Tom P, brian, and Eli]
>
> Question:
> Rx is a regex with whitespace and/or comments.
> R is Rx with the comments and embedded whitespace removed.
> Find a useful Rx such that /Rx/x works, but /R/ does not.
>
> Answer:
> Rx = '^\w*$ (?!\n)'
This particular bug/feature is fixed in the current versions of Perl
(probably starting from 5.004_56). "$" is now special even before "("
(per(l) Larry's request).
But your solution is indeed ingenious, congratulations! We did not
realize that //x may fix it.
Enjoy,
Ilya
------------------------------
Date: Fri, 30 Jan 1998 01:04:09 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
To: Sylvain Juneau <sjuneau@microtec.net>
Subject: Re: Help needed: I cannot seem to get this variable to substitute in this pattern
Message-Id: <34D16D58.C7E3AC84@coos.dartmouth.edu>
[posted and mailed]
Sylvain Juneau wrote:
>
> $count1=@client_prod_list;
> for($b=0;$b<=$count1;$b++)
$count1 is now set to the *number* of elements in @client_prod_list.
Because the first element is at 0, the last element is at $count1 - 1;
So, that should be:
$count1=@client_prod_list;
for($b=0;$b<$count1;$b++)
But there is no need to use a temporary variable:
for($b=0;$b<@client_prod_list;$b++)
or
for($b=0;$b<=$#client_prod_list;$b++)
$#client_prod_list is the index of the last element in @client_prod_list
> Use of uninitialized value at /usr/cmis/cmisx/cz line 79, <> chunk
> 915. (line 79 is if(/^$client_prod_list[$b]/) )
>
> It is initialize since I can print that array @client_prod_list
The last time through the loop, $client_prod_list[$b] is
past the end of the array, which is why you got that warning.
Chipmunk
------------------------------
Date: Thu, 29 Jan 1998 21:10:48 -0700
From: "Joseph N. Hall" <joseph@5sigma.com>
Subject: Re: Help with SORT
Message-Id: <34D15258.A87D049F@5sigma.com>
use Benchmark;
use Sort::Fields;
@data = (qw(0 3 2 1 4 5 0.1 0.2 2.1 2.5 2.10 3.1 3.2 3.0 4.0 4.5 5.1
2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 11.11 22.22 33.33 44.44 55.55 66.66
2.3 3.4 4.5 5.6 6.7 7.8 8.9 9.0 10.12 23.23 34.34 45.45 56.56)) x 10;
timethese (100, {
fieldsort => q{ @sorted = fieldsort q/\./, ['1n', '2n'], @data },
larrysort => q{ @sorted = sort {
@a = $a =~ /(\d+)\.?(\d*)/;
@b = $b =~ /(\d+)\.?(\d*)/;
$a[0] <=> $b[0] or $a[1] <=> $b[1]
} @data },
schwartzsort => q{ @sorted = map {
$_->[0]
} sort {
$a->[1] <=> $b->[1] or $a->[2] <=> $b->[2]
} map {
[$_, split /\./]
} @data
},
merlynsort => q{ @sorted = map {
$_->[0]
} sort {
$a->[1] cmp $b->[1]
} map {
[$_, join "", map { sprintf "%09d", $_ } split /\./]
} @data
},
});
Benchmark: timing 100 iterations of fieldsort, larrysort, merlynsort, schwartzsort...
fieldsort: 41 secs (41.10 usr 0.03 sys = 41.13 cpu)
larrysort: 139 secs (138.72 usr 0.00 sys = 138.72 cpu)
merlynsort: 22 secs (21.19 usr 0.00 sys = 21.19 cpu)
schwartzsort: 21 secs (20.83 usr 0.00 sys = 20.83 cpu)
Aggh, apparently using a coderef in a sort slows things down
a bunch. Looks like I'll be tweaking that out of Sort::Fields.
(What Sort::Fields does is very similar to what schwartzsort
above does, except there's a level of indirection.)
-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, 29 Jan 1998 23:43:05 -0700
From: "Joseph N. Hall" <joseph@5sigma.com>
Subject: Re: Help with SORT
Message-Id: <34D17606.263F64D2@5sigma.com>
Ah, much better now:
Benchmark: timing 100 iterations of fieldsort, larrysort, merlynsort, schwartzsort...
fieldsort: 22 secs (22.04 usr 0.06 sys = 22.10 cpu)
larrysort: 133 secs (133.38 usr 0.00 sys = 133.38 cpu)
merlynsort: 21 secs (21.00 usr 0.01 sys = 21.01 cpu)
schwartzsort: 20 secs (19.78 usr 0.00 sys = 19.78 cpu)
Joseph N. Hall wrote:
> Benchmark: timing 100 iterations of fieldsort, larrysort, merlynsort, schwartzsort...
> fieldsort: 41 secs (41.10 usr 0.03 sys = 41.13 cpu)
> larrysort: 139 secs (138.72 usr 0.00 sys = 138.72 cpu)
> merlynsort: 22 secs (21.19 usr 0.00 sys = 21.19 cpu)
> schwartzsort: 21 secs (20.83 usr 0.00 sys = 20.83 cpu)
>
> Aggh, apparently using a coderef in a sort slows things down
> a bunch. Looks like I'll be tweaking that out of Sort::Fields.
> (What Sort::Fields does is very similar to what schwartzsort
> above does, except there's a level of indirection.)
--
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, 29 Jan 1998 21:13:51 -0600
From: "Scott Norris" <snorris@post.cis.smu.edu>
Subject: Re: HTML/CGI to play midi file?
Message-Id: <6argcd$q89$1@hermes.seas.smu.edu>
To recap, I had a cgi script print
Location: mymidifile.mid
I just realized that in MSIE (Netscape wins here) *all* MIDI links, even <a
href>, cause this open or save option. Fine. But when I press "open", but I
realize that it is trying to play my CGI script!!! I can't imagine what this
means... Is this still a
>server configuration issue, or a CGI/HTTP transaction if I am handling the
>transaction myself
?
Also, what/where is the CGI Meta FAQ?
thanks,
scott
------------------------------
Date: Fri, 30 Jan 1998 01:00:59 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: HTML/CGI to play midi file?
Message-Id: <comdog-ya02408000R3001980100590001@news.panix.com>
Keywords: from just another new york perl hacker
In article <6argcd$q89$1@hermes.seas.smu.edu>, "Scott Norris" <snorris@post.cis.smu.edu> posted:
>Also, what/where is the CGI Meta FAQ?
look at the bottom of any (well, most) of my posts. you'll see
two references. the CGI Meta FAQ is one of them. i'm considering
trashing the damn thing though because the time i save in not
typing the references in the CGI Meta FAQ are taken up answering this
stupid question.
just about every thing that's reference-able i reference. if
i mention a resource, you'll see it's address. i'm one of the
few persons that uses footnotes in my postings. and i still have
to deal with crap like this. i never wanted to be Sisyphus.
fuck it. i'm outta here for awhile. ever wonder why i left
comp.infosystems.www.authoring.cgi? same fucking reason i'm leaving
this group for awhile.
help save usenet:
THE FUCKING ADDRESS IS ON THE NEXT LINE!
<URL:http://www.boutell.com/boutell/usenet.html>
THE FUCKING ADDRESS IS ON THE PREVIOUS LINE!
--
brian d foy <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
even after taking a walk to the deli, i've decided to say "fuck"
------------------------------
Date: Fri, 30 Jan 1998 01:13:47 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: Problems converting Bourne shell to Perl
Message-Id: <34D16F9A.E22AF0E0@coos.dartmouth.edu>
Steve Bourgeois wrote:
>
> In Bourne shell, I can do the following to pass info to a command:
>
> COMMAND <<_EOF_
> line 1
> line 2
> ...
> _EOF_
>
> How can I do this in Perl? The Perl "here document" functionality
> seems similar, but it doesn't appear to work the same way.
I think you might want something like this:
open(COMMAND, "| command") or die "Error executing command: $!";
print COMMAND <<_EOF_;
line 1
line 2
...
_EOF_
close(COMMAND) or die "Error executing command: $!";
Chipmunk
------------------------------
Date: Fri, 30 Jan 1998 02:30:04 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Problems converting Bourne shell to Perl
Message-Id: <EnKsA5.2vI@bcstec.ca.boeing.com>
In article <6ar1io$fdl$1@bashir.ici.net>,
Steve Bourgeois <sbourgeo@ici.net> wrote:
>
>
>I've been going nuts with this one.
>
>
>In Bourne shell, I can do the following to pass info to a command:
>
> COMMAND <<_EOF_
> line 1
> line 2
> ...
> _EOF_
>
>
>How can I do this in Perl? The Perl "here document" functionality
>seems similar, but it doesn't appear to work the same way.
>
>
Where do perl here documents fall short ?
Here're some things here doc can do in Perl:
HTH,
--
Charles DeRykus
print <<END;
This is an example of
a Perl here document.
END
or things like this:
print <<END1, <<END2; # stacked
this is the 1st here doc.
END1
this is the 2nd here doc.
END2
print <<'END'; # prevent variable interpolation
this $variable's value
won't be be seen.
END
print <<`END`; # run commands note backticks
echo here's an echo and a cat :)
cat /some/path/file
END
print <<END x 10; # print something ten times
one of ten hello's
END
system "echo",<<END; # embedded in a system call
Do I hear an echo
in here?
END
$prompt = <<END; # set a variable
This is a sweet survery.
Enter your favorite sweet >
END
$prompt = <<END =~ s/\n//; # set a variable and modify it
This is a sweet survey.
Enter your favorite sweet >
END
print $prompt;
# set thing as above but succumbing to obfuscation
print STDOUT (($prompt = <<END) =~ s/\n$//s, "\r$prompt");
This is a sweet survey.
Enter your favorite sweet >
END
------------------------------
Date: Thu, 29 Jan 1998 23:01:56 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: regexes: fun with /x
Message-Id: <comdog-ya02408000R2901982301560001@news.panix.com>
Keywords: from just another new york perl hacker
In article <34D147E7.FA3E7965@coos.dartmouth.edu>, rjk@coos.dartmouth.edu posted:
>brian d foy wrote:
>> the regex method that i demonstrated will behave differently
>> if the x modifier is not set. are you assuming that you
>> know the pattern at compile time?
>
>It will behave differently because it still has the whitespace
>and comments in it. Therefore, it does not fit the definitions
>of Rx and R I supplied above, which specify that you should
>remove the whitespace and comments. :-)
it's a bit more complicated than that because the comments
are interpolated into the regular expression. for instance, what
if i had two bits of code:
$code_1 = 'do_this;';
$code_2 = 'do_this; #this is a comment';
and that in the problem space these are said to match because
they are the same.
and, for whatever reason, i was comparing them with m//. i could do
something like
if $code_1 =~ m/$code_2/x;
which won't work with
if $code_1 =~ m/$code_2/;
even though for in the microcosm i constructed for the problem
$code_1 matches #code_2.
it's not the same conceptual idea as commenting parts of a regex.
why you would want to do this is irrelevant. but i found it useful
for a couple of hacks.
otherwise, if you are going to say "do everything x would do" and
look at the result, the debate is pointless because you are doing
the x processing anyway. if you have something else in mind, out
with it already!
--
brian d foy <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
------------------------------
Date: Thu, 29 Jan 1998 23:57:30 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: regexes: fun with /x
Message-Id: <34D15DB9.994E2D5@coos.dartmouth.edu>
brian d foy wrote:
>
> In article <34D147E7.FA3E7965@coos.dartmouth.edu>, rjk@coos.dartmouth.edu posted:
>
> >brian d foy wrote:
>
> >> the regex method that i demonstrated will behave differently
> >> if the x modifier is not set. are you assuming that you
> >> know the pattern at compile time?
> >
> >It will behave differently because it still has the whitespace
> >and comments in it. Therefore, it does not fit the definitions
> >of Rx and R I supplied above, which specify that you should
> >remove the whitespace and comments. :-)
>
> it's a bit more complicated than that because the comments
> are interpolated into the regular expression.
No, it's not that complicated. For the question I'm asking, it's irrelevant
whether the regexes are interpolated from a variable or not. Either way,
the comments and whitespace need to be removed in the second part.
> for instance, what if i had two bits of code:
> $code_1 = 'do_this;';
> $code_2 = 'do_this; #this is a comment';
> and that in the problem space these are said to match because
> they are the same.
To be precise, in the problem space, if Rx is $code_2, then R is $code_1.
> and, for whatever reason, i was comparing them with m//. i could do
> something like
> if $code_1 =~ m/$code_2/x;
> which won't work with
> if $code_1 =~ m/$code_2/;
You're using Rx without the /x modifier. That's not what I'm asking for.
I want an Rx and R, where Rx is a regex with comments and/or whitespace
and R is Rx without the comments and whitespace, such that /Rx/x works
and /R/ does not.
> even though for in the microcosm i constructed for the problem
> $code_1 matches #code_2.
If you use $code_2 as Rx, then $code_1 is R, and /$code_2/x and /$code_1/
both work.
I do see where you're coming from with this, but it's not what
I have in mind for this question.
> [...]
> otherwise, if you are going to say "do everything x would do" and
> look at the result, the debate is pointless because you are doing
> the x processing anyway. if you have something else in mind, out
> with it already!
It would be pointless, except there are some cases where doing the /x
processing yourself results in the regex being interpreted differently.
Those cases are what I'm after.
Note that these cases are specific to Perl: if another language
implemented regexes with a /x-type modifier, this problem would not
necessarily exist.
I'd hoped I could explain this well enough so people could actually try
to figure out the kind of regex I had in mind. If I keep this up, no doubt
I'll just continue to frustrate everyone involved in the discussion.
So, my next post will contain one possible answer to my question.
Chipmunk
------------------------------
Date: 30 Jan 1998 06:04:53 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: regexes: fun with /x
Message-Id: <6arqi5$k29$1@client3.news.psi.net>
Chipmunk (rjk@coos.dartmouth.edu) wrote on 1613 September 1993 in
<URL: news:34D138E5.B2D5C8A6@coos.dartmouth.edu>:
++ Okay, let me try one more time:
++
++
++ We know that /x allows the programmer to add whitespace
++ and comments to a regex.
++
++ So, let's say we have a regex, call it Rx, that has
++ unescaped whitespace and/or comments embedded in it.
++
++ Now, take that regex, drop the /x modifier, and remove
++ all the unescaped whitespace and comments, resulting in
++ regex R.
++
++ Gnerally, Rx and R may be used interchangeably, as /x does
++ not change the meaning of the regex.
++
++ However, there are some choices for Rx that will result in
++ an R which cannot be used in a Perl program.
++
++
++ I have such an Rx in mind. Can anyone else come up with one?
I can't, though I did find an R where the only equivalent Rx seems
to be Rx == R.
Abigail
--
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
------------------------------
Date: Fri, 30 Jan 1998 00:25:26 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
To: Phil R Lawrence <prl2@lehigh.edu>
Subject: Re: script does things as different user?
Message-Id: <34D16445.BF54ED7@coos.dartmouth.edu>
[posted and mailed]
Phil R Lawrence wrote:
>
> I want a script to log into Oracle as a more powerful user than the person
> who starts the script. How can I protect the password that goes with that
> more powerful userID from prying eyes?
It sounds like you might want a setuid script. Make the more powerful
user the owner of the script and set the setuid bit. You won't even
have to worry about the passwords.
You'll have to read the perlsec documentation to get info about how to
make your script safe to run with setuid.
Chipmunk
------------------------------
Date: Thu, 29 Jan 1998 22:34:08 -0500
From: pudge@pobox.com (Chris Nandor)
Subject: Re: Survival Of perl
Message-Id: <pudge-2901982234090001@ppp-9.ts-1.kin.idt.net>
In article <6aqv40$krn$1@csnews.cs.colorado.edu>, tchrist@mox.perl.com
(Tom Christiansen) wrote:
# [courtesy cc of this posting sent to cited author via email]
#
# In comp.lang.perl.misc, jsd@bud.com writes:
# :use your imagination. our users use windows 95. they don't have
# :command lines.
#
# That's not my fault.
Which part? That they use Windows, or that you have trouble imagining it?
<NOTE TO SELF>Cancel this post.</NOTE TO SELF>
--
Chris Nandor mailto:pudge@pobox.com http://pudge.net/
%PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10 1FF7 7F13 8180 B6B6'])
#== New Book: MacPerl: Programming for the Rest of Us ==#
#== Publishing Date: Early 1998. http://www.ptf.com/macperl/ ==#
------------------------------
Date: Fri, 30 Jan 1998 05:55:21 GMT
From: rrowell@shreve.dot.net (Richard Rowell)
Subject: Re: Win32 Perl & Internet Information Server 4.0 (NT)
Message-Id: <34d169ae.38830895@news.shreve.net>
>IIS is not set up by default to handle perl scripts so I added .pl
>extension to be handled by <drive>:\perl\perl.exe. When I try to make a
>request like http://my_machine/some/directory/script.pl the IIS launches
I'm no expert, this is my first day with perl, and I just set up IIS
today too. But the help file that came with perl suggested the
following string for the .pl extension association:
pathtoperl.exe %s %s
I would wager that the %s bit will cure your problems... Also, I had
to include a ? after the ref like so:
http://my_machine/some/directory/script.pl?
Just my 2c
______________________
Richard Rowell
rrowell@shreve.net
------------------------------
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 1767
**************************************