[6404] in Perl-Users-Digest
Perl-Users Digest, Issue: 29 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 28 09:17:25 1997
Date: Fri, 28 Feb 97 06:00:30 -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, 28 Feb 1997 Volume: 8 Number: 29
Today's topics:
Re: [Q] removing lines in a file.. (Andy Wardley)
Re: Class library to make C++ more Perlish? <rra@cs.stanford.edu>
Re: Delayed variable interpolation in string question <dbenhur@egames.com>
HELP! ~ in format is a blank space (Joan Pontius)
help!: RE parse comma separated list <suqstmbl@reading.ac.uk>
Re: How to delete a line from an array? <baku@india.ti.com>
Re: How to delete a line from an array? (Jon Bell)
Re: How to delete a line from an array? <stats9@mail.idt.net>
How to read files from Perl <fg6ops@ocean.com.au>
How to sort blocks in a file? (tei hou)
HTML Frame target (Lon Hosford)
http proxy in chroot'ed environment doesn't work - help <benedetto@camelotmusic.com>
Manipulating a file (efficiently) lpa@sysdeco.no
Re: Perl as a shared library? <nms@nns.ru>
Perl for X <kens@cannet.com>
Re: Perl Utility - compare two directories and make sim <suqstmbl@reading.ac.uk>
Re: pingecho() generates junk output (Russell Mosemann)
Re: Question about the SYSTEM function <seay@absyss.fr>
Re: Substituting a bunch of strings <dbenhur@egames.com>
SvNVOK and friends <remco@pc140.cemo.nioo.knaw.nl>
Threads? <tkc+@andrew.cmu.edu>
Undefining a single element in a multidimensional array <stats9@mail.idt.net>
Re: Undefining a single element in a multidimensional a <dbenhur@egames.com>
Re: Undefining a single element in a multidimensional a <wkuhn@uconect.net>
Re: Variable within a variable <dbenhur@egames.com>
Variables in array-names <arnold@otto.mpimf-heidelberg.mpg.de>
Re: Win95 can't always do this! ( Was: Re: Perl on Wind (Glenn Stanton)
Win95 Perl and COM?? <kw@dtc.rankxerox.co.uk>
Digest Administrivia (Last modified: 8 Jan 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 28 Feb 1997 08:55:11 -0000
From: abw@peritas.com (Andy Wardley)
Subject: Re: [Q] removing lines in a file..
Message-Id: <5f66hf$4t9@aoxomoxoa.peritas.com>
Eric D. Carter <ecarter@a-lincoln.hnet.uci.edu> wrote:
>I want to remove a single line from a file. So far, I have only been
>able to do this by opening an existing file, writing to a temp file
>and renaming when I'm done.
perl -i -ne 'print unless /line_you_want_zapped/' file_to_be_zapped
You might want to consider '-i.bak' to get perl to save a backup
of your file (file_to_be_zapped.bak) before it mungs it.
A
--
Andy Wardley <abw@peritas.com> http://www.peritas.com/~abw
A responsible and professional individual who has no need for silly
comments, inane banter or bizarre "in-jokes" in his signature file.
------------------------------
Date: 27 Feb 1997 23:39:52 -0800
From: Russ Allbery <rra@cs.stanford.edu>
Subject: Re: Class library to make C++ more Perlish?
Message-Id: <qumwwrttm47.fsf@cyclone.stanford.edu>
In comp.lang.perl.misc, Matt Austern <austern@isolde.mti.sgi.com> writes:
> Russ Allbery <rra@cs.stanford.edu> writes:
>> Until the language standard stabilized and the compilers got better at
>> optimizing out the cruft introduced by the language, I wouldn't write
>> any of those applications in C++ either. If you're worried about
>> speed, C is still the way to go. Operator overloading, virtual method
>> calls, and the like are major performance hits, as are the lack of
>> realloc(), memcpy(), and similar operations.
> C++ has both realloc and memcpy. I've used both of those functions in
> my C++ programs. (Not to mention printf, memcmp, and memset.) The
> entire standard C library is part of the standard C++ library.
*sigh* You know what I'm talking about. If the data structure is in any
way nontrivial, often even if it's an array of structs, you can't use
memcpy() to move it and you can't use realloc() to expand it because
mixing either with new and delete is bad news.
Sure, you can fall back on C, but if you're going to do that why are you
pretending to write in C++ in the first place? Just do the whole thing in
C, get the portability boost from a stable programming language, and don't
worry about dealing with semi-functional compilers.
> I'd be interested in measurements showing that operator overloading
> causes performance problems, by the way, especially if you've made those
> measurements using recent SGI compilers. There's no good reason why
> compilers shouldn't handle a function called operator*() just as well as
> they handle a function called multiply(). My experience is that most
> compilers do deal with overloaded operators fairly well, but I'm
> entirely willing to believe that there are still some compilers out
> there that have problems.
I don't have hard numbers to throw at it off-hand; I had them at one
point, but I don't have the necessary knowledge to defend them without a
great deal of research to get caught up again, and you're correct that I
haven't tried the new compilers. However, on the other hand, I feel like
I should point out that you're almost stuck programming for g++ as the
lowest common denominator these days if you want portability, since the
language still hasn't stabilized very well.
--
Russ Allbery (rra@cs.stanford.edu) <URL:http://www.eyrie.org/~eagle/>
------------------------------
Date: Fri, 28 Feb 1997 01:18:16 -0800
From: Devin Ben-Hur <dbenhur@egames.com>
To: Herschel Goldstein <herschel@waterw.com>
Subject: Re: Delayed variable interpolation in string question
Message-Id: <3316A2D8.595D@egames.com>
Herschel Goldstein wrote:
> The following script works, but seems to lack that perl prettiness (the eval
> line has backslash disease).
> $x = "The answer is \$y\n"; # don't interpolate $y here
> $y = 10 * 23 + 6; # set $y here
> eval "print \"$x\""; # now interpolate it
I like:
print eval qq["$x"];
HTH
--
Devin Ben-Hur <dbenhur@egames.com>
eGames.com, Inc. http://www.egames.com/
eMarketing, Inc. http://www.emarket.com/
"Don't run away. We are your friends." O-
------------------------------
Date: 28 Feb 1997 09:54:41 GMT
From: joan@ucmb.ulb.ac.be (Joan Pontius)
Subject: HELP! ~ in format is a blank space
Message-Id: <5f6a11$729@rc1.vub.ac.be>
I am a newbie, trying to use write to print data,
and the output has two blank spaces due to the
squiggles. What do I do.
thanks in advance,
joan
format STDOUT =
information: @<<<<<<< @<<<<<<<<<: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$f $category $info
~~^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$info
.
--
********************************************************************
joan pontius
e-mail: joan@ucmb.ulb.ac.be http://www.ucmb.ulb.ac.be/~joan/
*********************************************************************
------------------------------
Date: Thu, 27 Feb 1997 19:23:56 +0000
From: John Stumbles <suqstmbl@reading.ac.uk>
Subject: help!: RE parse comma separated list
Message-Id: <Pine.SOL.3.95q.970227185114.5682D-100000@suma3.reading.ac.uk>
I'm trying to extract data from a comma separated variable format file.
Obviously dealing with foo,bar,wizz,bang is easy enough with split(/,/),
but when there are commas within fields the field is quoted, like:
foo,"barr,roseanne",wizz,bang
So... I converted all commas to tabs with s/,/\t/g and, before
splitting on the tabs, converted back quoted fields with:
s/"([^"]*)\t([^"]*)"/\1,\2/g;
But this doesn't work for fields with multiple commas like:
foo,"bar,pub,tavern,hostelry",wizz,bang
This seems to call for some sort of recursive RE, which is beyond the
level of wizardry I can safely practice. Can someone help?
[Email copies of replies to newsgroup would be greatly appreciated as our
news server sometimes finds itself at a null point in the usenet news
space wave-function.]
--
John Stumbles j.d.stumbles@reading.ac.uk
Computer Services, University of Reading http://www.rdg.ac.uk/~suqstmbl
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
When love is gone, there's always justice
When justice is gone, there's always force...
(For Randal)
------------------------------
Date: Fri, 28 Feb 1997 10:58:45 +0530
From: Ajitesh Das <baku@india.ti.com>
To: Lee Johnson <ljohnson@isys.ca>
Subject: Re: How to delete a line from an array?
Message-Id: <33166D0D.ABD322C@india.ti.com>
Lee,
Do u want to delete an element from array ?
If so, try this: with undef
#!/usr/local/bin/perl5.002
@arry = ( "Reshma","is","a","Big","Boss");
foreach ( @arry) {
print ;
print " " ;
}
print "\n\a\n";
undef @arry[0];
foreach ( @arry) {
print ;
print " " ;
}
Lee Johnson wrote:
>
> I would like to do something like:
> delete @array[0]
>
> Is there a way to to this?
>
> Also, what about deleting the last line of an array when you don't know
> how many lines are in the array? I would like to do something like:
>
> ($ipaddress, $password, $number, $logdate, $logtime,
> $logtype, $inorout, $name) = split(/\:/, $matches[lastline]);
>
> if ($inorout eq 'login') {
> delete $matches[lastline];
> ...
>
> Any help would be appreciated.
>
> Thanks;
> Lee Johnson
> ljohnson@isys.ca
--
Ajitesh Das E-mail-id : baku@india.ti.com,baku@msg.ti.com
EDAS,Texas Instruments LTd Ph:(091)-(080)-526-9451-(174)
Wind Tunnel Road, Murugheshpalya Bangalore- 560017,India.
------------------------------
Date: Fri, 28 Feb 1997 06:06:42 GMT
From: jtbell@presby.edu (Jon Bell)
Subject: Re: How to delete a line from an array?
Message-Id: <E6AuB7.2wp@presby.edu>
Lee Johnson <ljohnson@isys.ca> wrote:
>I would like to do something like:
>delete @array[0]
shift @array;
>Also, what about deleting the last line of an array when you don't know
>how many lines are in the array?
pop @array;
(pages 215 and 198 of the Camel book, 2nd ed.)
--
Jon Bell <jtbell@presby.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
------------------------------
Date: Fri, 28 Feb 1997 00:30:59 -0500
From: Chris Plachta <stats9@mail.idt.net>
To: Lee Johnson <ljohnson@isys.ca>
Subject: Re: How to delete a line from an array?
Message-Id: <33166D93.51403E6D@mail.idt.net>
Lee Johnson wrote:
>
> I would like to do something like:
> delete @array[0]
>
> Is there a way to to this?
Try "undef($array[0]);"
>
> Also, what about deleting the last line of an array when you don't know
> how many lines are in the array? I would like to do something like:
>
> ($ipaddress, $password, $number, $logdate, $logtime,
> $logtype, $inorout, $name) = split(/\:/, $matches[lastline]);
>
> if ($inorout eq 'login') {
> delete $matches[lastline];
> ...
When you say "the last line", I assume you mean the last element.
Use the pop function:
pop(@matches);
Hope this helps.
Chris
------------------------------
Date: 28 Feb 1997 07:26:57 GMT
From: "fg6ops" <fg6ops@ocean.com.au>
Subject: How to read files from Perl
Message-Id: <01bc2548$df08cc20$cbea0ccb@internet-pc>
I'm currently trying to read text data from seven different files. These
files are generated by my Perl program. Each of them has two colums and try
to write them to a single file which will have fourteen colums in order
from left to right.
I 'm not sure how to do it. Please help!
My mail address is lem@ocean.com.au
------------------------------
Date: 28 Feb 1997 11:10:48 GMT
From: sp3102th@ex.ecip.osaka-u.ac.jp (tei hou)
Subject: How to sort blocks in a file?
Message-Id: <5f6efo$9c1@newsserver.ex.ecip.osaka-u.ac.jp>
Hello,
I have a file which is divided into blocks by "##*##" line.
Now i want to sort the blocks by its label, how can i do it
with [g]awk or perl[45]?
The format would be as below:
#########################
## LABEL: Cfoo
strings_1
strings_2
#########################
## LABEL: Afoo
strings_3
strings_4
#########################
## LABEL: Bfoo
strings_5
strings_6
I want the result:
#########################
## LABEL: Afoo
strings_3
strings_4
#########################
## LABEL: Bfoo
strings_5
strings_6
#########################
## LABEL: Cfoo
strings_1
strings_2
Thanks for any help.
tei hou
sp3102th@ex.ecip.osaka-u.ac.jp
------------------------------
Date: Fri, 28 Feb 1997 13:50:24 GMT
From: lon@hosfordusa.com (Lon Hosford)
Subject: HTML Frame target
Message-Id: <3316e064.2843809@news.eclipse.net>
Hello folks,
How do you have Perl5 generate an HTML page on client in an HTML frame
target window?
This is a case where the search HTML is in the same frame that I wish
the the results HTML to appear. I have the Perl program working just
great. But I have no clue on this one.
Lon Hosford
Perl5 Novice
May many happy bits flow your way!
------------------------------
Date: 28 Feb 1997 07:24:00 -0500
From: Bill Benedetto <benedetto@camelotmusic.com>
Subject: http proxy in chroot'ed environment doesn't work - help
Message-Id: <x6lo89m84f.fsf@rhythm.camelotmusic.com>
Good day.
I am attempting to use one of Randall's scripts from
WebTechniques and having trouble.
Background:
I use apache as a proxy server. This works swell except that
apache doesn't proxy gopher requests. I saw Randall's article in
February WebTechniques for an anonymous proxy server. So I got
the code and it works pretty much out of the box. I told it to
only serve gopher requests and had it listen on port 70. If I
start this on my bastion host it works swell.
Problem:
Now, I run my apache server in a chroot'ed environment. I would
like to do the same with Randall's anonymous proxy server. So I
put perl in the chroot'ed environment and when I try to run the
anonymous proxy script I get this message from it:
[Fri Feb 28 07:01:47 1997] [27052] HTTP::Daemon: Cannot
determine protocol at /opt/perl5/lib/IO/Socket.pm line 135
[Fri Feb 28 07:01:47 1997] [27052] Can't call method "url"
without a package or object reference at
/opt/perl5/bin/anon_proxy line 44.
This tells me that there is a problem in Socket.pm on line 135
and that propagated down to the anon_proxy (Randall's) script.
Although I have to admit that the exact nature of the error
escapes me.
I realize that this is asking a lot but mayhaps some other soul
has tried something similar in a chroot'ed environment and may
have a suggestion as to what I might try next? Is there
something else that I need to include in my chroot'ed
environment?
Pertinent details:
HPUX 10.10
perl -version yields:
This is perl, version 5.003 with EMBED
built under hpux at Jan 10 1997 16:17:53
+ suidperl security patch
IO-1.15
libwww-perl-5.07
Here is the code snippet from Socket.pm:
129 sub new {
130 my($class,%arg) = @_;
131 my $fh = $class->SUPER::new();
132
133 ${*$fh}{'io_socket_timeout'} = delete $arg{Timeout};
134
135 return scalar(%arg) ? $fh->configure(\%arg)
136 : $fh;
137 }
Here is Randall's code:
1 #!/opt/perl5/bin/perl -Tw
2 #?#use strict;
3 $ENV{PATH} = join ":", qw(/usr/ucb /bin /usr/bin);
4 $|++;
5
6 ## Copyright (c) 1996 by Randal L. Schwartz
7 ## This program is free software; you can redistribute it
8 ## and/or modify it under the same terms as Perl itself.
9
10 ## Anonymous HTTP proxy (handles gopher:)
11 ## requires LWP 5.04 or later
12
13 my $HOST = "rock";
14 my $PORT = "70";
15
16 sub prefix {
17 my $now = localtime;
18
19 join "", map { "[$now] [${$}] $_\n" } split /\n/, join "", @_;
20 }
21
22 $SIG{__WARN__} = sub { warn prefix @_ };
23 $SIG{__DIE__} = sub { die prefix @_ };
24 $SIG{CLD} = $SIG{CHLD} = sub { wait; };
25
26 my $AGENT; # global user agent (for efficiency)
27 BEGIN {
28 use LWP::UserAgent;
29
30 @MyAgent::ISA = qw(LWP::UserAgent); # set inheritance
31
32 $AGENT = MyAgent->new;
33 $AGENT->agent("anon/0.07");
34 $AGENT->env_proxy;
35 }
36
37 sub MyAgent::redirect_ok { 0 } # redirects should pass through
38
39 { ### MAIN ###
40 use HTTP::Daemon;
41
42 my $master = new HTTP::Daemon
43 LocalAddr => $HOST, LocalPort => $PORT;
44 warn "set your proxy to <URL:", $master->url, ">";
45 my $slave;
46 &handle_connection($slave) while $slave = $master->accept;
47 exit 0;
48 } ### END MAIN ###
49
50 sub handle_connection {
51 my $connection = shift; # HTTP::Daemon::ClientConn
52
53 my $pid = fork;
54 if ($pid) { # spawn OK, and I'm the parent
55 close $connection;
56 return;
57 }
58 ## spawn failed, or I'm a good child
59 my $request = $connection->get_request;
60 if (defined($request)) {
61 my $response = &fetch_request($request);
62 $connection->send_response($response);
63 close $connection;
64 }
65 exit 0 if defined $pid; # exit if I'm a good child with a good parent
66 }
67
68 sub fetch_request {
69 my $request = shift; # HTTP::Request
70
71 use HTTP::Response;
72
73 my $url = $request->url;
74 if ($url->scheme !~ /^(gopher)$/) {
75 my $res = HTTP::Response->new(403, "Forbidden");
76 warn "Not allowed to fetch $url";
77 $res->content("bad scheme: @{[$url->scheme]}\n");
78 $res;
79 } elsif (not $url->rel->netloc) {
80 my $res = HTTP::Response->new(403, "Forbidden");
81 warn "Not allowed to fetch $url";
82 $res->content("relative URL not permitted\n");
83 $res;
84 } else {
85 warn "fetching $url";
86 &fetch_validated_request($request);
87 }
88 }
89
90 sub fetch_validated_request { # return HTTP::Response
91 my $request = shift; # HTTP::Request
92
93 ## uses global $AGENT
94
95 ## warn "orig request: <<<", $request->headers_as_string, ">>>";
96 $request->remove_header(qw(User-Agent From Referer Cookie));
97 ## warn "anon request: <<<", $request->headers_as_string, ">>>";
98
99 my $response = $AGENT->request($request);
100 ## warn "orig response: <<<", $response->headers_as_string, ">>>";
101 $response->remove_header(qw(Set-Cookie));
102 ## warn "anon response: <<<", $response->headers_as_string, ">>>";
103 $response;
104 }
Thanks for any pointers!
- Bill Benedetto <benedetto@camelotmusic.com> Camelot Music, Inc.
------------------------------
Date: Fri, 28 Feb 1997 04:32:29 -0600
From: lpa@sysdeco.no
To: lpa@sysdeco.no
Subject: Manipulating a file (efficiently)
Message-Id: <857125286.742@dejanews.com>
Hallo,
I have to parse a file (and extract subparts of it). The file has the
nice property of containing a table in the beginning, which can guide me
directly to the exact position of relevant subparts into the same file.
I.e. the beginning of the file looks like:
file struct:
PART1 5468,280;
PART2 11826,630;
PART3 24993,1350;
PART4 38818,2095;
end struct;
the first number is the position of the first character of the relevant
part. The following number is the line number (this number would actually
be enough for me.
I would like to define a procedure like:
sub extract {
my ($file, $part) = @_;
:
}
which I can use like:
@part = extract(\*FILE, "PART2")
print $part[2]; #prints the second line of PART2
Of course, I could find a quick and dirty solution by myself, but since
the files could be quite big, I'd like to minimize the memory
consumption. Furthermore, even though I just got hold of the new Camel
book for Perl5, I'm familiar with Perl4, i.e. I'm not sure if there is
some wheel-reinvention disabling package out there.
Thanx for help
PS The syntax of the new Perl5 is pretty complex, It's like reading an
Latin grammar book: 1000 rules and 10000 exceptions. Isn't this pushing it
a bit too far? looks like "there's more than one way to hang yourself"
to me. How was it possible to make a parser for such a monster language?
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: 28 Feb 1997 08:52:54 GMT
From: Nickolay Saukh <nms@nns.ru>
Subject: Re: Perl as a shared library?
Message-Id: <5f66d6$blm$1@zware.rssi.ru>
Brett McCormick <brett@speedy.speakeasy.org> wrote:
> > 5.003 is able to be built with libperl.a as a shared library. The
> > Configure script didn't ask if you wanted it though, so you had to
> > edit config.sh by hand.
> Does anyone know how this can be done? I have many C programs linked
> with perl, and would like to decrease the disk usage.. (they're very,
> very, big)...
The recent perl5.003_90 did ask about libperl.so.
------------------------------
Date: Thu, 27 Feb 1997 08:11:29 -0500
From: Ken Schrock <kens@cannet.com>
Subject: Perl for X
Message-Id: <33158801.18CD4B10@cannet.com>
I learned Perl on NT...
which has hooks to GUI through OLE extensions.
Any way to do X programming using Perl in Linux?
I have heard references to Perl\Tk...
Does such a thing exist?
--
Ken Schrock
kens@cannet.com
Solutions Software
------------------------------
Date: Thu, 27 Feb 1997 18:45:15 +0000
From: John Stumbles <suqstmbl@reading.ac.uk>
To: Rob Cunningham <rkc@ll.mit.edu>
Subject: Re: Perl Utility - compare two directories and make similar
Message-Id: <Pine.SOL.3.95q.970227184342.5682C-100000@suma3.reading.ac.uk>
On 20 Feb 1997, Rob Cunningham wrote:
> I've searched the web for a simple utility that would do the following, but to
> no avail. Does anybody have a tool that:
> Compares two nearly identical directories and their subdirectories.
> Determines which directory has the most recent copy of a given file.
> Copies that file on top of the older version of the file.
>
> I need something like this for working on two copies of a single source tree
> that periodically need to be merged back together.
There's a similar prog in the Camel book (and source available from CPAN?
and other sites) which compares directories and hard links files from one
to the other to make them alike. Should be straightforward enough to hack
that to copy files instead.
--
John Stumbles j.d.stumbles@reading.ac.uk
Computer Services, University of Reading http://www.rdg.ac.uk/~suqstmbl
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
A consultant is a man who borrows your watch, tells you what time it is,
charges you and arm and a leg for the service ... and keeps the watch
------------------------------
Date: 28 Feb 1997 07:28:33 -0600
From: mose@ns.ccsn.edu (Russell Mosemann)
Subject: Re: pingecho() generates junk output
Message-Id: <5f6mi1$7o6@ns.ccsn.edu>
rgarg@rgarg-sun.us.oracle.com (Raman Garg) writes:
> I was just trying to use pingecho() function in the following script
>to check for All UP hosts on the network .For some reason, it prints junk
>binary data at the end .
Prints junk binary data where? On the screen or into the file? I
think your claim in the subject that pingecho() is generating the junk
output is more than just a tad misleading.
>Please take a look and email me any clues to this problem.
You post here, you read here. This is not your private help news
group, and other people may benefit from the answer to this problem.
Besides, if you are a frequent reader, you won't wind up asking the
same questions that several other people just asked.
>open(NOWDOWN, ">/tmp/.nowdown") || die ( "Can't open file for writing\n ");
[...]
>@out = <NOWDOWN>;
>print @out;
>close NOWDOWN;
Would you care to explain what you are trying to do here? You open
a file for OUTPUT and then you try to read the file IN to an array?
Does that make sense to you?
Either close the file and open it again for input, or add more
print statements which print to the screen as it prints to the file or
put the phrase you want into a variable and at the end of the loop
print it to the file and the screen at the same time.
--
Russell Mosemann Concordia College Voice: (402) 643-7445
Computing Center Seward, NE 68434 Fax: (402) 643-4073
"What are they going to do? Fire me and force me to get a
higher-paying job?" - Mike Reith
------------------------------
Date: Fri, 28 Feb 1997 14:10:54 +0000
From: Douglas Seay <seay@absyss.fr>
To: ataide@planetarium.com.br
Subject: Re: Question about the SYSTEM function
Message-Id: <3316E76E.6876@absyss.fr>
Efigenio Ataide wrote:
>
> In a Perl program I am trying to do the following:
>
> system("/sbin/diplogin", $user) == 0 || die "calling diplogin: $?\n";
> &mysub;
> .
> When the user closes the connection the
> program 'diplogin' ends (abnormaly?), and the subroutine
> mysub isn't called.
> Is there a way to have this subroutine called after the program
> diplogin?
do you mean that you want to call &mysub() irregardless of the
return code of /sbin/diplogin? simply changing the die() to
a warn() will cause the same error message, but the program
will continue and &mysub() will be called. maybe you would
prefer something like
my $status = system("/sbin/diplogin", $user) == 0
|| warn "calling diplogin: $?\n";
&mysub;
exit(1) if ( $status );
so you get the warning message, call &mysub() and still exit
without doing whatever comes later.
other tricks include putting your system() into an eval() call
or using END{}, but they might be more than you really need.
------------------------------
Date: Thu, 27 Feb 1997 23:44:15 -0800
From: Devin Ben-Hur <dbenhur@egames.com>
To: Michael Schuerig <uzs90z@uni-bonn.de>
Subject: Re: Substituting a bunch of strings
Message-Id: <33168CCF.43C4@egames.com>
Michael Schuerig wrote:
> I've written a script that does replacements of multiple strings on a
> directory sub-tree. The strings are read into a hash from a file (yes,
> it should be an array...). Currently the script iterates over the hash
> for each line in each file. And that's obviously not very efficient.
>
> Is there a better and more "idiomatic" way to do the same?
Is this the sort of thing your asking for?
my %replace_table = { # hash of strings to replace
'str1' => 'replace1',
'str2' => 'replace2',
...
);
# make a pattern which will match any of these strings
my $pattern = join('|', map(quotemeta $_, keys %replace_table));
while (<IN>) {
s/($pattern)/$replace_table{$1}/geo; # replace using table lookup
print OUT;
}
This is pretty consise and idiomatic. Whether it's more *efficient*
than what you're doing... well, that's what use Benchmark is for.
HTH
--
Devin Ben-Hur <dbenhur@egames.com>
eGames.com, Inc. http://www.egames.com/
eMarketing, Inc. http://www.emarket.com/
"Don't run away. We are your friends." O-
------------------------------
Date: 28 Feb 1997 09:32:11 +0100
From: Remco Wouts <remco@pc140.cemo.nioo.knaw.nl>
Subject: SvNVOK and friends
Message-Id: <m3u3mx1gc3.fsf@pc140.cemo.nioo.knaw.nl>
Hi,
Can anybody explain to me the intended behavior of SvNOK(sv*)?
I thought it could be used to find out whether an sv contains a number.
That is if SvPOKp(sv*) returns true then SvNOK(sv*) would return true
if the string also represents a number (ie. strtod() would work).
This does not seem to work in my code. (perl5.0003 on linux 2.0.28)
Thanx.
--
Remco Wouts (wouts@cemo.nioo.knaw.nl)|Centre for Estuarine and Coastal Ecology
tel/fax:+31-(0)1131-571920/3616 |Vierstraat 28, 4401 EA Yerseke
PGP:finger wouts@worldonline.nl |The Netherlands
------------------------------
Date: Fri, 28 Feb 1997 02:18:48 -0500
From: Timothy K Canfield <tkc+@andrew.cmu.edu>
Subject: Threads?
Message-Id: <Mn5cPMi00iWp0LimA0@andrew.cmu.edu>
I am writing a script to search many files, using unix grep. Is there a
way to thread this and make it more efficient?
Tim
------------------------------
Date: Fri, 28 Feb 1997 00:35:34 -0500
From: Chris Plachta <stats9@mail.idt.net>
Subject: Undefining a single element in a multidimensional array
Message-Id: <33166EA6.1043D2EA@mail.idt.net>
I have a multi-dimensional associative array that looks like this:
$hash{KEY1}{INFO1} = value;
$hash{KEY1}{INFO2} = value;
$hash{KEY1}{INFO3} = value;
$hash{KEY2}{INFO1} = value;
$hash{KEY2}{INFO2} = value;
$hash{KEY2}{INFO3} = value;
.
.
.
I want to undefine selected elements of this data structure. When
I try:
undef($hash{KEY1});
It doesn't work. After doing this, KEY1 still shows up in
keys(%hash). I need to completely wipe out KEY1 from this
data structure. Any slick ways of doing this? Thanks in advance.
Chris Plachta
------------------------------
Date: Thu, 27 Feb 1997 23:53:35 -0800
From: Devin Ben-Hur <dbenhur@egames.com>
To: Chris Plachta <stats9@mail.idt.net>
Subject: Re: Undefining a single element in a multidimensional array
Message-Id: <33168EFF.7A04@egames.com>
Chris Plachta wrote:
> I want to undefine selected elements of this data structure. When
> I try:
> undef($hash{KEY1});
> It doesn't work. After doing this, KEY1 still shows up in
> keys(%hash). I need to completely wipe out KEY1 from this
> data structure. Any slick ways of doing this? Thanks in advance.
delete($hash{KEY1});
should do the trick.
HTH
--
Devin Ben-Hur <dbenhur@egames.com>
eGames.com, Inc. http://www.egames.com/
eMarketing, Inc. http://www.emarket.com/
"Don't run away. We are your friends." O-
------------------------------
Date: Fri, 28 Feb 1997 08:14:46 -0500
From: Bill Kuhn <wkuhn@uconect.net>
To: Chris Plachta <stats9@mail.idt.net>
Subject: Re: Undefining a single element in a multidimensional array
Message-Id: <3316DA46.186C3D97@uconect.net>
You don't want to undefine the key, you want to delete it. Undefining
sets the *value* associated with the hash key to an undefined value:
delete($hash{KEY1}) ;
-Bill
--
Bill Kuhn
Chief Developer
Wired Markets, Inc.
http://www.buyersindex.com
------------------------------
Date: Thu, 27 Feb 1997 23:51:25 -0800
From: Devin Ben-Hur <dbenhur@egames.com>
To: enry@shore.net.REMOVEME
Subject: Re: Variable within a variable
Message-Id: <33168E7D.3ABF@egames.com>
What your asking for is called symbolic reference
(Camel p.254, or man perlref).
$name = 'field';
foreach (1..3) {
no strict 'refs'; # need this if you're using 'use strict;'
${"$name$_"} = $_;
}
print "$field1,$field2,$field3\n"; #prints: 1,2,3
--
Devin Ben-Hur <dbenhur@egames.com>
eGames.com, Inc. http://www.egames.com/
eMarketing, Inc. http://www.emarket.com/
"Don't run away. We are your friends." O-
------------------------------
Date: Fri, 28 Feb 1997 12:06:09 +0100
From: Arnold Andersson <arnold@otto.mpimf-heidelberg.mpg.de>
Subject: Variables in array-names
Message-Id: <3316BC21.41C6@otto.mpimf-heidelberg.mpg.de>
Hi folks,
Im trying to write a subrutine that process several
arrays. I would like to be able to refere to the
array-name by adding the calling variable to the name.
I could use a temporary variable like:
$temp = IP.$no._SORTED;
and then refere to the array-name by:
print @$temp;
But can't you do something like this (well, not exactly
like this since that dosn't work ;-))? A one liner?
------------------------------------------------------
@IP24_SORTED = (1..5);
sub ProcessArray
{
local($no) = @_;
print @IP.$no._SORTED;
print "\n";
}
ProcessArray(24);
------------------------------------------------------
Any suggestions?
/Arnold
+++++++++++++++++++++++++++++++++++++++++++
Arnold Andersson (Ph.D)
Max-Planck Inst. for Medical Research 69120 Heidelberg, Germany
Tel: +49-6221-486286 E-mail: arnold@otto.mpimf-heidelberg.mpg.de
------------------------------
Date: Fri, 28 Feb 97 13:25:06 GMT
From: gms@lucent.com (Glenn Stanton)
Subject: Re: Win95 can't always do this! ( Was: Re: Perl on Windows 95)
Message-Id: <5f6mbi$2fs_002@wcc.lucent.com>
In article <5f5mn9$8u@fridge-nf0.shore.net>, nvp@shore.net (Nathan V. Patwardhan) wrote:
>Ed Boren (boren@tngms1.mro1.dec.com) wrote:
>
>: I've had this problem in perl win32 (5.001m) when running under Netscape
>: Fasttrack Server 2.0 for Windows 95 (it seems to work in NT 4.0). It
>: seems to fail when doing a gethostbyname. If run from the command line
> ^^^^^^^^^^^^^
>Exactly. It was broken in NTPerl PL 110, but fixed in 5.003_07.
>
the problem isn't 5.001m, it's Window 95. because Win95 can't spawn
the second connection/socket, your CGI will fail even though the command
line (where presumably the "dos session" doesn't have a socket open)
works properly.
if you're going to run a CGI that uses socket calls, use NT instead.
HTH
Glenn Stanton
gms@lucent.com
------------------------------
Date: Fri, 28 Feb 1997 10:00:54 GMT
From: "Kieran Walshe" <kw@dtc.rankxerox.co.uk>
Subject: Win95 Perl and COM??
Message-Id: <01bc255d$c2b417e0$3c00cb0d@kraken>
Does Perl for Windows 95 support COM?
If the answer is Yes, where can I find infomation about using the COM
interface.
Cheers
Kieran
------------------------------
Date: 8 Jan 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Jan 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.
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 29
************************************