[7729] in Perl-Users-Digest
Perl-Users Digest, Issue: 1355 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 21 13:19:04 1997
Date: Fri, 21 Nov 97 10:00:27 -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, 21 Nov 1997 Volume: 8 Number: 1355
Today's topics:
Re: $a='001' ; $a++ ; print$a <rootbeer@teleport.com>
Re: ^D not working (Andrew M. Langmead)
Re: adding to the end of each element in an array <rootbeer@teleport.com>
analysing a html-document <r.goeggel@atos-group.de>
Re: analysing a html-document (Tad McClellan)
Re: Another s/// question (John Moreno)
Re: Another s/// question <rootbeer@teleport.com>
Detecting Memory Leaks in Perl dudley@msi.umn.edu
Re: Downcase/Upcase (Jeremy D. Zawodny)
Fehler in timelocal()??? <Christian.Broennimann@swisscom.com>
Re: Finding the longest common prefix over a list of st (Ken Fox)
Re: help: debugging perl scripts... <rootbeer@teleport.com>
Re: Is this an array of hashes, or what? (Paddy Spencer)
Re: Learning Perl in win95 (Jeremy D. Zawodny)
Re: Newbie, strange pop behavior? <rootbeer@teleport.com>
Re: OUTPUT of images and uploading <rootbeer@teleport.com>
Re: passing more than 1 variable in a href <rootbeer@teleport.com>
Re: Perl 5's glob() function <rootbeer@teleport.com>
Re: perl conversion of curly quotes out of web form <rootbeer@teleport.com>
perl does nonsensical lseek on audio device <czyborra@cs.tu-berlin.de>
Re: PERL Hourly Rates (Tad McClellan)
Re: Please help with user log (Pearl Fox)
Re: Reading single lines from a file . . . <rootbeer@teleport.com>
Re: Regex for three equal characters (Gabor)
Re: Removing Full file path from report <reibert@mystech.com>
Re: Rename Ref file (Bruce Davidson)
Re: Returning information from an nslookup ?? <chris@starkimages.com>
Re: Safe use of flock() -- was Re: giving up on flock (Andrew M. Langmead)
Sockets problem on NT <menyhert@acm.org>
Re: Sorting an array <eike.grote@theo.phy.uni-bayreuth.de>
Re: Sorting an array (Andrew M. Langmead)
Re: Sorting an array <markm@nortel.ca>
Re: Suppressing echo at STDIN <rootbeer@teleport.com>
Working with just part of an array. <kevinc@mobiletel.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 21 Nov 1997 08:07:51 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Eli the Bearded <usenet-tag@qz.little-neck.ny.us>
Subject: Re: $a='001' ; $a++ ; print$a
Message-Id: <Pine.GSO.3.96.971121080638.8884O-100000@usertest.teleport.com>
On 20 Nov 1997, Eli the Bearded wrote:
> :r! perl5.00401 -we '$section="4.2.07"; $section++; print "$section\n";'
> 5.2
>
> Not what one might expect reasonably....
Actually, it _is_ reasonable to expect that Perl will do what it's
documented to do. Mostly. :-)
--
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/
Ask me about Perl trainings!
------------------------------
Date: Fri, 21 Nov 1997 15:58:30 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: ^D not working
Message-Id: <EK071I.JM9@world.std.com>
Georg Edelmayer <ged@fortec.tuwien.ac.at> writes:
>> ^D is a Unix sort of thing. perhaps that other OS has a different key? how
>> do you normally signal the end of input?
>Ctrl C schould do it in dos (which then prints ^C on the screen)
No. Control-C, unless trapped aborts the script. (I guess that does
stop the readline operator from looking for input. But its a little
heavy handed for that purpose.)
For example, you wouldn't want to abort this script with Control-C:
use strict;
my ($word,%count);
while(<STDIN>) {
my @words = split '';
for $word (@count) {
$count{$word}++;
}
}
print "words used:\n";
for $word (sort { $count{$a} <=> $count{$b} } keys %count) {
print "$word: $count{$word}\n";
}
Using the systems EOF character. (On unix, Control-D by default,
unless someone has done some bizzare mucking with stty. On MS-DOS,
Windows, and if I remember correctly, VMS, Control-Z.) Seems a lot
more reasonable.
On Unix, the EOF indicator is handled by the tty driver. On MS-DOS and
its successors, it is handled by the C run time library (which is why
the enter key has to be hit after the control-Z. The line-input is
handled by the operating system, and it won't pass the Control-Z to
the program until it gets a complete line. The runtime library sees
the control-Z and reports EOF back to the calling function, which in
this case is perl.)
--
Andrew Langmead
------------------------------
Date: Fri, 21 Nov 1997 08:28:11 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Steve <syarbrou@ais.net>
Subject: Re: adding to the end of each element in an array
Message-Id: <Pine.GSO.3.96.971121082507.8884T-100000@usertest.teleport.com>
On Tue, 18 Nov 1997, Steve wrote:
> I know chomp can take a character or group of characters off each
> element in an array. Is there something that can do the opposite? In
> otherwords if I have an array, and want to add \n to the end of each
> element, is there a single command like chomp to do this? I know a
> simple foreach would do it, but what's the point. This is
> perl(shorter the better).
I already have too much problem with people thinking the efficiency
of a perl construct is related to its length. -- Larry Wall
...but you could use map:
@list = map "$_\n", @list;
This isn't strictly an unchomp, since this adds a newline whether it's
needed or not. 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/
Ask me about Perl trainings!
------------------------------
Date: Fri, 21 Nov 1997 16:51:39 +0100
From: "Ronald G\"oggel" <r.goeggel@atos-group.de>
Subject: analysing a html-document
Message-Id: <654aoh$3d8$1@news.pop-stuttgart.de>
Hi,
there are a lot of postings about how to find something like <b> and </b> in
a text file.
Is there a general method to analyse a html document?
In CPAN I found a lot of modules that generate html syntax; but how about
analysing?
What about including this question to the FAQ?
Thanks
Ronald
------------------------------
Date: Fri, 21 Nov 1997 11:36:17 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: analysing a html-document
Message-Id: <hqg456.gq1.ln@localhost>
Ronald G\ <r.goeggel@atos-group.de> (oggel) wrote:
: Is there a general method to analyse a html document?
^
^
That implies that there is a single definition of what HTML is.
Is it what WWW org says it is? (I'd say yes)
Is it what Netscape and/or IE will handle? (ie. 'extensions')
Anyway,
: In CPAN I found a lot of modules that generate html syntax; but how about
: analysing?
You could build something using the HTML::Parser module maybe?
: What about including this question to the FAQ?
The FAQ already suggests that you look for a module to help with
whatever you want to do ;-)
--
Tad McClellan SGML Consulting
tadmc@flash.net Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 21 Nov 1997 10:58:09 -0500
From: phenix@interpath.com (John Moreno)
Subject: Re: Another s/// question
Message-Id: <1d02doq.bkbhts125y6mcN@roxboro-172.interpath.net>
Juergen Heinzl <juergen@unicorn.noris.de> wrote:
] Vaughn Fox wrote:
] >hi all
] >
] >I'm new with Perl and am trying to replace an empty space in a
] >variable with a "?" and haven't had much luck with the following:
] >
] >$variable =~ s/ /?/gi;
]
] even you do not need the i here it should work. Could it be that your
] space is a tab ? Either here / / or in $variable. If you've the vi try
] set list, so tabs are displayed as ^I.
I also answered saying that it worked, but hadn't considered that it
might not be a space - if it's not working and he hasn't made a silly
mistake you're probably right. In which chase this will work (as long
as the string doesn't end a new line - in which case he probably doesn't
want to delete the last char).
$variable="this is\ta test";
$variable =~ s/\s/?/gi;
print "$variable\n";
Of course if it does contain a \n at the end then he can use
$variable =~ s/\s^$/?/gi;
--
John Moreno
------------------------------
Date: Fri, 21 Nov 1997 08:04:56 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Rhodri James <rhodri@wildebst.demon.co.uk>
Subject: Re: Another s/// question
Message-Id: <Pine.GSO.3.96.971121080336.8884N-100000@usertest.teleport.com>
On Thu, 20 Nov 1997, Rhodri James wrote:
> You are on the right track. The thing that you haven't noticed is that
> "?" is a metacharacter, meaning 'one or none of the preceeding'. You need
> to escape it:
>
> $variable =~ s/ /\?/gi;
Of course, the right part of an s/// command is a mere double-quotish
string. You needn't backwhack the question mark there.
--
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/
Ask me about Perl trainings!
------------------------------
Date: Fri, 21 Nov 1997 11:12:02 -0600
From: dudley@msi.umn.edu
Subject: Detecting Memory Leaks in Perl
Message-Id: <880131649.11282@dejanews.com>
Hello,
I am writing in the hope that there is someone that can help with a
rather large memory leak problem that I have in one of my perl scripts.
The Problem:
I have a (somewhat large) perl script - about 1300 lines - that has
several large memory leaks. I've seen it grow from 4 Meg to 20 Meg in only
a few days. I am using perl 5.004_01 on an IRIX 6.3 OS.
What I have already tried:
I have already nailed down a few leaks using the Devel::Peek module
by monitoring a few suspicious variables closely. I have also used the
-Dm command line option to no avail.
What I am looking for:
Even though I was able to fix a few leaks with the Devel::Peek module,
the program is just too large to go through and closely observe every
single variable. Might there be a program or module that will do this? Or
maybe the Devel will work and I'm just unaware.
Thanks very much in advance!
Jennifer Dudley
dudley@msi.umn.edu
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Fri, 21 Nov 1997 17:51:34 GMT
From: jzawodn@wcnet.org (Jeremy D. Zawodny)
Subject: Re: Downcase/Upcase
Message-Id: <3475c9f1.95391645@igate.hst.moc.com>
[original author automagically cc'd via e-mail]
On Fri, 21 Nov 1997 09:04:04 -0600, Mike Snyder
<accu-scan@worldnet.att.net> wrote:
>ANSWER CC'd to Email as well as newsgroup.
>
>I found this in the perlop manpage (I am a newbie too, didn't know what
>Perl *WAS* until about a week ago).
>
>the tr/ will the conversion for you. If your string was named $rr -->
>
>$rr="This Is A String To Convert"
>
>$rr =~ tr/a-z/A-Z/; ## convert to UPPER CASE
> ## $rr became "THIS IS A STRING TO CONVERT"
>
>$rr =~ tr/A-Z/a-z/; ## convert to LOWER CASE
> ## $rr became "this is a string to convert"
See perlfunc for uc() and lc() as well. They're more concise and
optimized (I believe).
>If you need to do mixed case, such as capitolizing the first letter and
>downcasing all others, there are probably really easy ways to do that as
>well, but having not needed to, I'm not sure how.
Ways to do that are suggested in the Perl FAQ.
Jeremy
--
Jeremy D. Zawodny jzawodn@wcnet.org
Web Server Administrator www@wcnet.org
Wood County Free Net (Ohio) http://www.wcnet.org/
------------------------------
Date: 21 Nov 1997 16:15:39 GMT
From: "Christian Broennimann" <Christian.Broennimann@swisscom.com>
Subject: Fehler in timelocal()???
Message-Id: <01bcf698$bf440860$c65bbe8a@gd2yld>
hallo
kann mir jemand sagen, warum das folgende programm f|r den "second check"
beide male jeweils gleichviel ausgibt, und f|r den "first check" den 2.
wert nicht wie den ersten wert ausgibt???
(das programm sollte die anzahl tage zwischen dem ersten und zweiten datum
ausgeben, dies sollte immer eine ganze zahl ergeben, was es eben im "first
check" nicht macht!!!)
Gruss und danke f|r die Hilfe!
christian
---------------------------------------------
#!/appl/perl/bin/perl -w
use strict;
use Time::Local;
#first check
print "", (timelocal(0,0,0,10,2,75) - timelocal(0,0,0,10,1,74)) / 86400,
"\n";
print "", (timelocal(0,0,0,10,2,98) - timelocal(0,0,0,10,1,97)) / 86400,
"\n";
#second check
print "", (timelocal(0,0,0,10,3,75) - timelocal(0,0,0,10,2,74)) / 86400,
"\n";
print "", (timelocal(0,0,0,10,3,98) - timelocal(0,0,0,10,2,97)) / 86400,
"\n";
exit 0;
---------------------------------------------
------------------------------
Date: 21 Nov 1997 16:50:49 GMT
From: fox@pt0204.pto.ford.com (Ken Fox)
Subject: Re: Finding the longest common prefix over a list of strings
Message-Id: <654e59$g392@eccws1.dearborn.ford.com>
Ilya Zakharevich <ilya@math.ohio-state.edu> writes:
> Ken Fox <kfox@ford.com> wrote:
> > ... finds the common string prefix in a list of strings.
>
> If *using* Text::Trie is an overkill, you may try to look for the
> *algorithm* used there.
The algorithm you use in the Trie module has much better performance
than mine. Theoretically that shouldn't be the case, but Perl is
very slow on substr() operations and your algorithm does a lot less
of them. Then again, computers aren't theoretical devices either. ;)
For everybody else, here's my implementation of Ilya's algorithm:
my @words = qw(the thick thesis thoroughly threw thor);
my $prefix = shift @words;
my $len = length($prefix);
foreach (@words) {
while (substr($_, 0, $len) ne $prefix) {
--$len;
$prefix = substr($prefix, 0, $len);
}
}
print "$prefix\n";
Perl's regex is *still* faster than Ilya's algorithm though, but only
by a few percent.
So, now there's a different question. Given the fact that this new
algorithm is just about as fast as the regex approach, which would you
rather use/maintain? Here's the regex again:
(join(',', @words).',') =~ /^(\w*)\w*,(\1\w*,)*$/;
print "$1\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: Fri, 21 Nov 1997 08:15:38 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: MrPc <tjbiuso@redrose.net>
Subject: Re: help: debugging perl scripts...
Message-Id: <Pine.GSO.3.96.971121081507.8884R-100000@usertest.teleport.com>
On Mon, 17 Nov 1997, MrPc wrote:
> i am sort of a newbie to perl. i have winnt 4.0 and redhat linux on my
> machine. i prefer to use windows. are there any debuggers out there
> for me?
Have you seen the perldebug manpage?
--
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/
Ask me about Perl trainings!
------------------------------
Date: Fri, 21 Nov 1997 17:46:33 GMT
From: paddy.spencer@parallax.co.uk (Paddy Spencer)
Subject: Re: Is this an array of hashes, or what?
Message-Id: <880134382.592374@red.parallax.co.uk>
adelton@fi.muni.cz (Honza Pazdziora) kirjoittanut::
: Yes you are right, but it seems to me that you do not run your script
: with -w or use strict;
<mea culpa>
I didn't use strict. I _did_ use -w ... but I'd turned it off after an earlier
incarnation of the code worked fine. I then went back and edited the code
without re"-w"ing...
I will now go and immolate myself or whatever it is I'm supposed to for failing
to be a good little Perl hacker...
</mea culpa>
--
Paddy Spencer Parallax Solutions Ltd (http://www.parallax.co.uk/)
"People in the enterprise want to be able to talk to Sybase databases,
and Oracle databases, but I don't think my mum's toaster wants to do that."
-- James Gosling
------------------------------
Date: Fri, 21 Nov 1997 17:54:06 GMT
From: jzawodn@wcnet.org (Jeremy D. Zawodny)
Subject: Re: Learning Perl in win95
Message-Id: <3476caa1.95567819@igate.hst.moc.com>
[original author automagically cc'd via e-mail]
On Thu, 20 Nov 1997 18:26:42 GMT, fox@securenet.net (Pearl Fox) wrote:
> If there is a site where I can get the information that I need to get
>me started in learning how to program in Perl with win 95
>environment, I would really appreciate it. I downloaded the Perl
>program but don't know how to use it with win 95?
Pick up a copy of "Learning Perl on Win32 Systems" from O'Reilly &
Associates. http://www.ora.com/
Jeremy
--
Jeremy D. Zawodny jzawodn@wcnet.org
Web Server Administrator www@wcnet.org
Wood County Free Net (Ohio) http://www.wcnet.org/
------------------------------
Date: Fri, 21 Nov 1997 07:59:32 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Bob Broad <rbroad@sprintmail.com>
Subject: Re: Newbie, strange pop behavior?
Message-Id: <Pine.GSO.3.96.971121074859.8884M-100000@usertest.teleport.com>
On Thu, 20 Nov 1997, Bob Broad wrote:
> When playing around with references to array elements I found
> that the reference still refered to the element after the element
> had been removed by 'pop'ing the array as in 'pop @ary'.
That's right; if you have a reference, it's guaranteed to point to a valid
object.
> However, when I did '$element = pop @ary', the reference was no longer
> defined.
> Is this a feature or bug,
I think bug. Here's my test case, which is a bit easier to understand (to
my simple brain. :-)
@list = qw(one two three);
$ref = \$list[1];
print "\$ref is $ref, which points to $$ref\n";
while (@list) {
pop @list;
}
print "\$ref is $ref, which points to $$ref\n";
@list = qw(one two three);
$ref = \$list[1];
print "\$ref is $ref, which points to $$ref\n";
while (@list) {
$foo = pop @list; # Only change
}
print "\$ref is $ref, which points to $$ref\n";
The last one loses the reference under 5.004_04. Please run perlbug to
submit this, and see what the developers say. Thanks!
--
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/
Ask me about Perl trainings!
------------------------------
Date: Fri, 21 Nov 1997 08:32:34 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Chris Schmidt <chris@starkimages.com>
Subject: Re: OUTPUT of images and uploading
Message-Id: <Pine.GSO.3.96.971121083057.8884V-100000@usertest.teleport.com>
On Fri, 21 Nov 1997, Chris Schmidt wrote:
> I am trying to set up a cgi to upload files from a web browser. I need
> to use a cgi so that I can make the upload user/passwd protected through
> a web interface.
I'm sure you mean that you want to write a CGI script. I recommend that
you write it in Perl, probably using some of the helpful modules from CPAN
to make it easier. Good luck!
--
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/
Ask me about Perl trainings!
------------------------------
Date: Fri, 21 Nov 1997 08:35:29 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: ATLOTO7 <atloto7@nbnet.nb.a>
Subject: Re: passing more than 1 variable in a href
Message-Id: <Pine.GSO.3.96.971121083442.8884X-100000@usertest.teleport.com>
On 21 Nov 1997, ATLOTO7 wrote:
> I'm trying to pass 2 variables in an href statement
> from a web page.
> I can't seem to pick up that 2 variable. What am I doing wrong?
You're not using CGI.pm, or a similar module, to help you to write your
code. 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/
Ask me about Perl trainings!
------------------------------
Date: Fri, 21 Nov 1997 08:14:48 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: jathan@nastything.com
Subject: Re: Perl 5's glob() function
Message-Id: <Pine.GSO.3.96.971121081224.8884Q-100000@usertest.teleport.com>
On Thu, 20 Nov 1997 jathan@nastything.com wrote:
> However, our production machine does not have Perl 5, but Perl 4
> Basically, the script itself will not work.
Step one: Remove Perl 4.
Step two: Install Perl 5.004, or re-write your script in sed. :-)
--
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/
Ask me about Perl trainings!
------------------------------
Date: Fri, 21 Nov 1997 08:30:37 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Bruce Wyman <bw@tiac.net>
Subject: Re: perl conversion of curly quotes out of web form
Message-Id: <Pine.GSO.3.96.971121082901.8884U-100000@usertest.teleport.com>
On Tue, 18 Nov 1997, Bruce Wyman wrote:
> I'm using perl to rewrite the material into an html page and therefore
> want to change the typographically correct stuff into " and ' marks.
>
> How the hell do I do it?
Use tr, something like this.
tr#\200\211\222\233#""''#;
Of course, you'll have to figure out what codes are used for those curly
quotes in your data. Good luck!
--
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/
Ask me about Perl trainings!
------------------------------
Date: Fri, 21 Nov 1997 17:13:24 +0100
From: Roman Czyborra <czyborra@cs.tu-berlin.de>
Subject: perl does nonsensical lseek on audio device
Message-Id: <Pine.LNX.3.95.971121162345.16055A-100000@czyborra.cs.tu-berlin.de>
Yo! The script below dies with:
$ sound
Cannot open /dev/audio: Operation not permitted at
/usr/local/bin/sound line 31, <> chunk 1.
Exit 2
strace reveals the following detail:
open("/dev/audio", O_WRONLY|O_APPEND|O_CREAT, 0666) = 3
fstat(3, {st_mode=S_IFCHR|0666, st_rdev=makedev(14, 4), ...}) = 0
mmap(0, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
= 0x400e1000
ioctl(3, TCGETS, 0xbffffb84) = -1 EINVAL (Invalid argument)
fstat(3, {st_mode=S_IFCHR|0666, st_rdev=makedev(14, 4), ...}) = 0
lseek(3, 0, SEEK_END) = -1 EPERM (Operation not permitted)
The lseek is totally unnecessary after the O_APPEND! Perl insists on
lseek also if I change the script to open the audio device for writing
with > instead of >>. The culprit doing this is
$ suidperl -v
This is perl, version 5.003 with EMBED
built under linux at Aug 21 1996 13:01:33
+ suidperl security patch
I get the same problem (Operation not permitted) with plain
$ perl -0777pe 'open(STDOUT,">/dev/audio")||warn $!' \
/usr/lib/java/demo/Animator/audio/spacemusic.au
I think that perl does have a serious bug here. I'd be glad to hear
an explanation and a perl workaround.
Perl will sing if the shell opens the audio device for her:
$ perl -0777pe 'print while 1' >> /dev/audio \
/usr/lib/java/demo/Animator/audio/spacemusic.au
But that is not an option for my script because the audio device is
not there yet before it runs. I guess I finally have to resort to:
open(STDOUT,"|exec cat >> /dev/audio")
Doeie
Roman
#!/usr/bin/suidperl
# script to vitalize the SoundBlaster compatible AudioDrive
# of my Linux 2.0.29 notebook
# $Id: sound,v 1.1 1997/11/21 15:20:53 czyborra Exp $
# insmod requires root privileges
$ENV{"PATH"} = "/bin:/usr/bin:/sbin:/usr/sbin";
$unprivileged = $<; $privileged = $>;
$< = $> = $privileged;
# use http://www.huwig.de/linux/acer_ess1688.c
for ("acer_ess1688", "sound")
{ !system("insmod", $_) || warn "Cannot install $_: $!"; }
# reduce volume
$< = $> = $unprivileged;
!system("volume","20") || warn "Cannot reduce volume: $!";
# load sample
$sounds = "/usr/lib/java/demo/Animator/audio/spacemusic.au";
open (STDIN, $sounds) || die "Cannot open $sounds: $!";
undef $/; $_=<> || die "Cannot read $sounds: $!";
# play until interrupted
$dev = "/dev/audio";
open (STDOUT, ">>$dev") || die "Cannot open $dev: $!";
print while 1;
------------------------------
Date: Fri, 21 Nov 1997 11:31:14 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: PERL Hourly Rates
Message-Id: <2hg456.gq1.ln@localhost>
Matthew Bonvicin (Matthew.Bonvicin@bridge.bellsouth.com) wrote:
: Could someone please provide for me an approximate hourly rate for
: advanced PERL CGI scripting. I may have the need shortly to outsource
^^^^^^^^
: some development but am unsure what to expect.
I'd guess $40-100 (US) perl hour ;-)
Hobbiests come cheaper.
--
Tad McClellan SGML Consulting
tadmc@flash.net Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 21 Nov 1997 16:25:06 GMT
From: fox@securenet.net (Pearl Fox)
Subject: Re: Please help with user log
Message-Id: <65412l$laf$1@news.securenet.net>
Hi Brian,
Thanks for your reply. I'm trying it. I'm new to Perl and didn't
realize that there is an exit command. Also would I need a \n at the
end of the new line?
Thanks
Pearl
comdog@computerdog.com (brian d foy) wrote:
>In article <651jjq$m29$1@news.securenet.net>, fox@securenet.net (Pearl Fox) wrote:
>>I have this user log file on my webpage to log the users. However I
>>would like to exclude my own entry when visiting my page. How would I
>>do this?
>before you let your script open files and so on, check to see that the
>user is not you. how you do this can vary, but let's assume that you
>have a development machine with a fixed IP number and your server isn't
>doing hostname lookups:
> #somewhere near the top. supply your IP
> exit if $ENV{'REMOTE_HOST'} eq 'aaa.bbb.ccc.ddd';
>if your situation is a bit different, just salt that test to taste :)
>--
>brian d foy <comdog@computerdog.com>
>NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
>CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Pearl S. Fox,
Montreal (Que.)
http://www.securenet.net/members/fox/index.html
------------------------------
Date: Fri, 21 Nov 1997 08:11:48 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Jon Turner <jt@cs.pdx.edu>
Subject: Re: Reading single lines from a file . . .
Message-Id: <Pine.GSO.3.96.971121080944.8884P-100000@usertest.teleport.com>
On Thu, 20 Nov 1997, Jon Turner wrote:
> I have found that it doesn't always read just 1 line at a time. When I
> step through it with the debugger I often get 5-6 lines in my variable
> $line.
Could you have set $/ somehow to something that's not a single newline
character?
> while ($line = <FILE>) {
It's better to write this using defined(), like this.
while (defined($line = <FILE>)) {
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/
Ask me about Perl trainings!
------------------------------
Date: 21 Nov 1997 17:38:17 GMT
From: gabor@vinyl.quickweb.com (Gabor)
Subject: Re: Regex for three equal characters
Message-Id: <slrn67bh9n.do2.gabor@vinyl.quickweb.com>
In article <3475FDC3.2727@cardiff.ac.uk>, Dean Jenkins wrote:
>Markus Bubendorf wrote:
>
>> I'm looking for a regex which matches three or more consecutive equal
>> characters. Any ideas?
>
>RTFM
>
>"Any item of a regular expression may be followed with digits in curly
>brackets of the form {n,m}, where n gives the minimum number of times to
>match the item and m gives the maximum. The form {n} is equivalent to
>{n,n} and matches exactly n times. The form {n,} matches n or more
>times. (If a curly bracket occurs in any other context, it is treated as
>a regular character.) The * modifier is equivalent to {0,}, the +
>modifier to {1,} and the ? modifier to {0,1}. There is no limit to the
>size of n or m, but large numbers will chew up more memory." Perlman
>
>So how about /.{3,}/
You didn't read the question carefully. 3 or more of the same
character not 3 or more of any.
And the answer is
/(.)\1\1+/
gabor.
--
I'll say it again for the logic impaired.
-- Larry Wall
mharris@gov.on.ca he, he, he
------------------------------
Date: Fri, 21 Nov 1997 08:49:40 -0700
From: "Mark S. Reibert" <reibert@mystech.com>
Subject: Re: Removing Full file path from report
Message-Id: <3475AD94.6F8BBB3A@mystech.com>
Perl 5 has a File::Basename standard library module that provides the
routines basename() and dirname(), which mimic the UNIX utilities of the
same name.
Mark Reibert
James Gryga wrote:
> Hi, Maybe someone can help me. I have written a short perl script which
> look through a bunch of files that I specify on the command line and
> prints out the subject line and associated file name. the code follows
> below this message. If this script is in the same directory as the
> files, then it works OK. But I have many directories and
> subdirectories. I really doesn't make sense to keep moving this script
> to differenct directories or having a copy of the same script in each
> directory.
-----------------------------
Mark S. Reibert, Ph.D.
Mystech Associates, Inc.
3233 East Brookwood Court
Phoenix, Arizona 85044
Tel: (602) 732-3752
Fax: (602) 706-5120
E-mail: reibert@mystech.com
-----------------------------
------------------------------
Date: Fri, 21 Nov 1997 17:02:51 GMT
From: b.davidson@webforums.net (Bruce Davidson)
Subject: Re: Rename Ref file
Message-Id: <880131938.16920.0.nnrp-06.9e982204@news.demon.co.uk>
ebohlman@netcom.com (Eric Bohlman) wrote:
>rename was successful, and you'll want to read the documention for
>rename() to see how it handles certain special cases that you might run into.
That was prophetic that was !
I used
sub etc {
rename($filea, $fileb)
}
I do this because the common config file between the two scripts has
the $filea and $fileb strings. They work fine.
Using the above example I got the file "name" ($filea) renamed to the
$fileb, but the contents were deleted and the old $filea was not
deleted. I read the man pages as you suggest for special cases, (I
guess free bsd is a special case)
I've tried "mv" and it bombed.
That leaves
1 - system("mv", $filea, $fileb);
2 - copy("$filea","$fileb");
It seems that file::copy is best but comments appreciated with syntax
errors pointed out if you'd be so kind. I'm too old for all this :)
thanks
b.davidson@webforums.net
------------------------------
Date: Fri, 21 Nov 1997 10:20:47 -0600
From: Chris Schmidt <chris@starkimages.com>
Subject: Re: Returning information from an nslookup ??
Message-Id: <3475B4DE.AC522B03@starkimages.com>
This is a multi-part message in MIME format.
--------------DFDDD8E8643A912A4CCD431B
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
libeson wrote:
> Burt Lewis wrote:
>
>> Hi,
>>
>> I'm capturing IP's using "$ENV{'REMOTE_HOST'} from an SSI page.
>>
>> I want to then do an nslookup to capture the domain as a variable
>> that I can read back to the
>> webpage and write to file.
>>
>> I have this but I don't know how to return the answer.
>>
>> print "Content-type: text/html\n\n";
>>
>> system "nslookup 207.180.0.20";
>>
>> Appreciate any help on this.
>>
>> Burt Lewis
>
> Try the following instead of system:
>
> $return = `nslookup 207.180.0.20`;
>
> then filter the output saved in $return.
>
>
> --
> libeson
>
>
Why not use gethostbyaddr(); it us faster then nslookup plus it drops
it into an array
--------------DFDDD8E8643A912A4CCD431B
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Chris Schmidt
Content-Disposition: attachment; filename="vcard.vcf"
begin: vcard
fn: Chris Schmidt
n: Schmidt;Chris
org: Stark Images
adr: 219 N Milwaukee st;;;Milwaukee;WI;53202;USA
email;internet: chris@starkimages.com
title: Systems Manager
tel;work: 4142262700
tel;fax: 4142262705
x-mozilla-cpt: ;0
x-mozilla-html: FALSE
end: vcard
--------------DFDDD8E8643A912A4CCD431B--
------------------------------
Date: Fri, 21 Nov 1997 16:01:23 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Safe use of flock() -- was Re: giving up on flock
Message-Id: <EK076B.qL@world.std.com>
Mark Mielke <markm@nortel.ca> writes:
>Oh yeah... Tom... I just found a section in the manpage that says that:
> To avoid the possibility of mis-coordination, Perl
> flushes FILEHANDLE before (un)locking it.
> (man perlfunc - flock)
but what if the flush fails?
--
Andrew Langmead
------------------------------
Date: Fri, 21 Nov 1997 11:46:53 -0500
From: George Menyhert <menyhert@acm.org>
Subject: Sockets problem on NT
Message-Id: <3475BAFD.DE9DD45@acm.org>
This is a multi-part message in MIME format.
--------------7569188AE64F93A03887850D
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
One of our customers is running our scripts on an NT web server. Our
script sends mail by connecting to a SMTP server via sockets. Their
SMTP
server is also NT.
When they try to connect, the script reports the following error when
the
connect fails:
Unknown Error: 0x00002741
A lucky guess and a quick look at the winsock documentation reveals
(0x2741=10049):
----------------------------------------------------------------------
WSAEADDRNOTAVAIL (10049) Cannot assign requested address.
Berkeley description: Normally results from an attempt to create a
socket
with an address not on this machine.
WinSock description: Partly the same as Berkeley. The "address" it
refers
to is the remote socket name (protocol, port and address). This error
occurs when the
sin_port value is zero in a sockaddr_in structure for connect() or
sendto().
In Berkeley, this error also occurs when you are trying to name the
local
socket (assign local address and port number) with bind(), but Windows
Sockets doesn't
ascribe this error to bind(), for some unknown reason.
Developer suggestions: Assume bind() will fail with this error. Let the
network system assign the default local IP address by referencing
INADDR_ANY in the
sin_addr field of a sockaddr_in structure input to bind(). Alternately,
you can get the local IP address by calling gethostname() followed by
gethostbyname().
WinSock functions: connect(), sendto(), FD_CONNECT
Additional functions: It seems odd that the v1.1 specification doesn't
ascribe this error to the function bind().
----------------------------------------------------------------------
The strange thing is that I can run the script on my NT box and point to
their SMTP server and it works.
The boiled down source is:
use Socket;
$server = 'their.server';
$address = 'them@their.address';
$sLocalhost = `hostname`;
chomp $sLocalhost;
$nProto = getprotobyname('tcp');
$nSmtpPort = getservbyname('smtp', 'tcp');
$them = sockaddr_in($nSmtpPort, inet_aton($server));
unless (socket(MYSOCKET, PF_INET, SOCK_STREAM, $nProto))
{
print "unable to create mail socket :$!:, ";
return;
}
unless (connect(MYSOCKET, $them)) # connect to the remote host - fails
{
print "unable to connect to the mail socket :$!:, ";
close MYSOCKET;
return;
}
Any help?
I'm running 5.003 on NT 4.0 sp3. I believe they are as well (waiting
for
the confirmation).
--
George Menyhert
----------
mailto:menyhert@acm.org
http://w3.one.net/~menyhert
"If there is one thing I can't tolerate it is intolerance."
me
why all the talk of "tolerance"? what happened to respect?
--------------7569188AE64F93A03887850D
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for George Menyhert
Content-Disposition: attachment; filename="vcard.vcf"
begin: vcard
fn: George Menyhert
n: Menyhert;George
adr: ;;;Cincinnati;OH;;USA
email;internet: menyhert@acm.org
title: Software Engineer
x-mozilla-cpt: ;0
x-mozilla-html: TRUE
version: 2.1
end: vcard
--------------7569188AE64F93A03887850D--
------------------------------
Date: Fri, 21 Nov 1997 16:55:29 +0100
From: Eike Grote <eike.grote@theo.phy.uni-bayreuth.de>
Subject: Re: Sorting an array
Message-Id: <3475AEF1.2781@theo.phy.uni-bayreuth.de>
Hi,
Yann wrote:
>
> I've some problems to sort an array.
> Could someone help me ?
Let's see ...
> For example I'd like to sort this array by the 3rd field.
>
> bcv64wd8:solaris:5.5:sun4m:SUN1.05:AGL
> bcv67wcb:solaris:5.5.1:sun4m:SUN0535:AGL
> bcv67w50:solaris:5.5.1:sun4c:SUN0424:AGL
> bcv67w5b:solaris:5.5:sun4m:SUN0535:AGL
> bcv66m14:AIX:3.2:::AGL
> bcv66w58:sun4:4.1.3_U1:sun4m:SUN1.05:AGL
> bcv95wc4:solaris:5.5.1:sun4c:SUN0424:AGL
>
> I've try the following program but it doesn't work (@INFOS is the
> array):
>
> local(@TEMP_INFOS);
> foreach (@INFOS)
> {
> push (@TEMP_INFOS, (split(/:/))[2]);
> }
> sub bydatakeys { $TEMP_INFOS[$a] <=> $TEMP_INFOS[$b]; }
> @SORT_INFOS=@INFOS[sort bydatakeys $[..$#INFOS];
> print join("\n",@SORT_INFOS);
You didn't exactly specify your problem when running the code above,
but I think you got errors like
Argument "5.5.1" isn't numeric in ncmp at ./test.pl line 20.
The reason is that '<=>' compares only numbers, but numbers usually
don't have two dots (at least in American style notation). If the
version numbers are only single digits you may try to use 'cmp'
(string comparison), but if not (HP's OS has already reached a
two-digit number) then you should read on ...
What you need is a way to compare two versions. The script I will
present you below compares the first numbers then the second ones
and so on. If the number of numbers ;-) is different, then
the version with fewer fields is chosen to be "less". Example:
'5.5' should be "less" than '5.5.1'.
If you don't understand my code at first glance, don't worry,
because I think I won't do so in a few days, too ... ;-)
Some hints where you can look to find out how it works:
- Perl's manual pages or the Camel book (-> map, sort, eval, refs)
- More about sorting at a CPAN site: CPAN/doc/FMTEYEWTK/sort.html
- The Schwartzian Transform: http://www.5sigma.com/perl/schwtr.html
-----------------------------------------------------------------------
@INFOS = map { $_->[0] }
sort by_version
map { [ $_, [ split(/\./, (split(/:/))[2]) ] ] } @INFOS;
sub by_version {
my $n1 = $#{$a->[1]};
my $n2 = $#{$b->[1]};
my $n = $n1<$n2 ? $n1 : $n2;
my @t = '';
for($i=0;$i<=$n;$i++) { $t[$i] = "\$a->[1][$i] <=> \$b->[1][$i]" }
if($n1 != $n2) { push(@t,'$n1 <=> $n2') }
eval(join(' or ',@t));
}
-----------------------------------------------------------------------
If you still have questions, ask again ... or wait for a posting
presenting a solution which is easier to understand ... ;-)
Bye, Eike
--
=======================================================================
>>--->> Eike Grote <eike.grote@theo.phy.uni-bayreuth.de> <<---<<
-----------------------------------------------------------------------
Home Page, Address, PGP,...: http://www.phy.uni-bayreuth.de/~btpa25/
-----------------------------------------------------------------------
PGP fingerprint: 1F F4 AB CF 1B 5F 4B 1D 75 A1 F9 C5 7B 3F 37 06
=======================================================================
------------------------------
Date: Fri, 21 Nov 1997 16:20:49 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Sorting an array
Message-Id: <EK082p.5M7@world.std.com>
Yann <ycueff@club-internet.fr> writes:
>I've some problems to sort an array.
>Could someone help me ?
>For example I'd like to sort this array by the 3rd field.
>bcv64wd8:solaris:5.5:sun4m:SUN1.05:AGL
>bcv67wcb:solaris:5.5.1:sun4m:SUN0535:AGL
>bcv67w50:solaris:5.5.1:sun4c:SUN0424:AGL
>bcv67w5b:solaris:5.5:sun4m:SUN0535:AGL
>bcv66m14:AIX:3.2:::AGL
>bcv66w58:sun4:4.1.3_U1:sun4m:SUN1.05:AGL
>bcv95wc4:solaris:5.5.1:sun4c:SUN0424:AGL
Try running the script with the "-w" switch. Perl doesn't think of
some of the items in the third field as numeric. Maybe you could
further split it into each dot separated component and compare each
section in turn. (Where does 4.1.3_U1 compare to 4.1.3? Should
everything after the third number be compared as a string? Or should
the the letter after the string sort alphabetically?)
Around the beginning of October, there was a thread here in
comp.lang.perl.misc titled "Sorting values such as 1.1, 1.1.1, 2.1
into order". You might want to search for it. There were a couple of
different solutions, including the Sort::Versions module on
CPAN. <URL:http://www.perl.com/CPAN/modules/by-module/Sort/
SortVersions-1.1.tar.gz>
--
Andrew Langmead
------------------------------
Date: 21 Nov 1997 11:52:25 -0500
From: Mark Mielke <markm@nortel.ca>
Subject: Re: Sorting an array
Message-Id: <lq1lnyitcja.fsf@bmers2e5.nortel.ca>
Yann <ycueff@club-internet.fr> writes:
> I've some problems to sort an array.
> Could someone help me ?
> For example I'd like to sort this array by the 3rd field.
> bcv64wd8:solaris:5.5:sun4m:SUN1.05:AGL
> bcv67wcb:solaris:5.5.1:sun4m:SUN0535:AGL
> bcv67w50:solaris:5.5.1:sun4c:SUN0424:AGL
> bcv67w5b:solaris:5.5:sun4m:SUN0535:AGL
> bcv66m14:AIX:3.2:::AGL
> bcv66w58:sun4:4.1.3_U1:sun4m:SUN1.05:AGL
> bcv95wc4:solaris:5.5.1:sun4c:SUN0424:AGL
> I've try the following program but it doesn't work (@INFOS is the
> array):
> local(@TEMP_INFOS);
> foreach (@INFOS)
> {
> push (@TEMP_INFOS, (split(/:/))[2]);
> }
> sub bydatakeys { $TEMP_INFOS[$a] <=> $TEMP_INFOS[$b]; }
> @SORT_INFOS=@INFOS[sort bydatakeys $[..$#INFOS];
> print join("\n",@SORT_INFOS);
You could try something like this... this method has a name,
unfortunately i forget it... (named after some perl guy :-) )
my @sorted_infos =
map { $_->[0] }
sort { $a->[1] <=> $b->[1] || $a->[0] cmp $b->[0]}
map { [$_, (split(/:/, $_))[2] ] }
@infos;
NOTE: The above is untested.
hope this helps,
mark
-- _________________________
. . _ ._ . . .__ . . ._. .__ . . . .__ | Northern Telecom Ltd. |
|\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ | Box 3511, Station 'C' |
| | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, ON K1Y 4H7 |
markm@nortel.ca / al278@freenet.carleton.ca |_______________________|
------------------------------
Date: Fri, 21 Nov 1997 08:23:34 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Ken Scott <kscott@pcisys.net>
Subject: Re: Suppressing echo at STDIN
Message-Id: <Pine.GSO.3.96.971121081959.8884S-100000@usertest.teleport.com>
On Thu, 20 Nov 1997, Ken Scott wrote:
> I am new to Perl programming, and have looked in the FAQs, etc, but have
> not found the solution to my question.
>
> I am writing an interactive script that needs to ask a user for a
> password. How do I keep from echoing whatever the user types to the
> terminal?
Check the FAQs again. :-) perlfaq8 has the question "How do I ask the
user for a password?" Good luck!
--
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/
Ask me about Perl trainings!
------------------------------
Date: 21 Nov 1997 15:53:27 GMT
From: "Kevin Cheramie" <kevinc@mobiletel.com>
Subject: Working with just part of an array.
Message-Id: <01bcf695$f9f6eac0$a6a2fbce@kevinc.cajunnet.com>
Say I have a variable @x where
@x = ("/dir1/dir2/filename1")
So that if I print @x, my output is
/dir1/dir2/filename1
I would like to extract, if you will, just the filename1 part and assign it
to $y so that
$y = ("filename1")
Any help with this would be appreciated.
------------------------------
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 1355
**************************************