[22226] in Perl-Users-Digest
Perl-Users Digest, Issue: 4447 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 22 11:07:56 2003
Date: Wed, 22 Jan 2003 08:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 22 Jan 2003 Volume: 10 Number: 4447
Today's topics:
ANNOUNCE : Mail::Bulkmail 3.00 <jt_60004@yahoo.com>
ANNOUNCE: Language::Prolog::Yaswi (Salvador Fandino)
Re: commands after system call and before die? <krahnj@acm.org>
Re: commands after system call and before die? <bart.lateur@pandora.be>
Cross-dependency of packages <richard@zync.co.uk>
Re: How are named unary operators that take $_ created? <pinyaj@rpi.edu>
Re: identifying web host platform? <espenmyr@start.no.cretinfilter>
make minitest fails (-)
Pattern Matching (Taji)
Re: Perl Script not working on Win NT (Helgi Briem)
Re: Regenerating Activeperl html documentation <noemail@nowhere.net>
Re: Regex problem <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: Regex problem (Anno Siegel)
Re: Regex problem <pludi0aa@htl.minic.ac.at>
Re: server and client on the same port news@roaima.freeserve.co.uk
Re: split with pattern matching question <stremitz@consultant.com>
Re: split with pattern matching question (Christopher Hamel)
To extract a specific portion of a text file (John Smith)
Whois script? <r.noli@tin.it>
Re: Whois script? <ubl@schaffhausen.de>
Re: Whois script? <r.noli@tin.it>
Re: Whois script? <r.noli@tin.it>
Re: Whois script? <r.noli@tin.it>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 21 Jan 2003 00:28:34 GMT
From: Jim Thomason <jt_60004@yahoo.com>
Subject: ANNOUNCE : Mail::Bulkmail 3.00
Message-Id: <3e2eb528$1_5@news.teranews.com>
Finally. Finally. Finally. After a more than 2 year hiatus, I got my act
together and am updating Mail::Bulkmail.
Mail::Bulkmail is a platform independent Perl mailing list module
distributed under the Artistic License that gives a fairly complete set
of tools for managing mass-mailing lists. I initially wrote it because
the tools I was using at the time were just too damn slow for mailing
out to thousands of recipients. I keep working on it because it's
reasonably popular and I enjoy it.
In a nutshell, it allows you to rapidly transmit a message to a mailing
list by zipping out the information to them via an SMTP relay (your own,
of course). Subclasses provide the ability to use mail merges, dynamic
messages, and anything else you can think of.
The 2.x code was just old and clunky and out of date by this point. 3.00
modernizes things substantially, hopefully to everyone's benefit. Be
warned that it's not 100% backwards compatible, so some porting will be
required, but those items should be noted and easily done.
my $bulk = Mail::Bulkmail->new(
"LIST" => "./list.txt",
"Subject" => "A test message",
"Message" => "This is my test message",
"From" => "me@mydomain.com",
"Reply-To" => "replies@mydomain.com"
) || die Mail::Bulkmail->error();
$bulk->bulkmail || die $bulk->error;
>From the Changes file:
- Componentized the code.
(Mail::Bulkmail, Mail::Bulkmail::Dynamic, Mail::Bulkmail::Server, etc.)
- Added multiple server support.
- added support for timing out if there's no reply from a server
- Finally fixed the damn Tz bug.
- Cleaned up the code an awful lot.
- General bug fixes, etc.
- Brand spanking new docs.
- Errors now return error codes as well as error text
- should be fully RFC 2821 and RFC 2822 compliant
- defaults now set in a conf file
Mail::Bulkmail 3.00 should be making its way out to your friendly
neighborhood CPAN mirror as I write this, look for it soon. It is also
available at: http://www.jimandkoka.com/jim/perl/
Updates will no doubt take me much less than 2 years this time.
Enjoy.
-Jim Thomason...
------------------------------
Date: 22 Jan 2003 03:50:56 -0800
From: sfandino@yahoo.com (Salvador Fandino)
Subject: ANNOUNCE: Language::Prolog::Yaswi
Message-Id: <3e2eb53a$2_3@news.teranews.com>
NAME
Language::Prolog::Yaswi - Yet another interface to SWI-Prolog
SYNOPSIS
use Language::Prolog::Yaswi ':query';
use Language::Prolog::Types::overload;
use Language::Prolog::Sugar functors => { equal => '='
is => 'is' },
chains => { orn => ';',
andn => ',',
add => '+' },
vars => [qw (X Y Z)];
swi_set_query( equal(X, Y),
orn( equal(X, 27),
equal(Y, 'hello')));
while (swi_next) {
printf "Query=".swi_query()."\n";
printf " X=%_, Y=%_\n\n", swi_var(X), swi_var(Y);
}
print join("\n",
xsb_findall(andn(equal(X, 2),
orn(equal(Y, 1),
equal(Y, 3.1416))
is(Z, plus(X,Y,Y))),
[X, Y, Z]);
ABSTRACT
Language::Prolog::Yaswi implements a bidirectional interface to the
SWI-Prolog system (<http://www.swi-prolog.org/>).
DESCRIPTION
This package provides a bidirectional interface to SWI-Prolog. That
means that Prolog code can be called from Perl that can call Perl code
again and so on:
Perl -> Prolog -> Perl -> Prolog -> ...
(unfortunately, by now, the cicle has to be started from Perl, although
it is very easy to circunvent this limitation with the help of a dummy
Perl script that just calls Prolog the first time).
The interface is based on the set of classes defined in
Language::Prolog::Types. Package Language::Prolog::Sugar can also be
used to improve the look and readability of scripts mixing Perl and
Prolog code.
The interface to call Prolog from Perl is very simple, at least if you
are used to Prolog non deterministic.
SUBROUTINES
Grouped by export tag:
":query"
"swi_set_query($query1, $query2, $query3, ...)"
Compose a query with all its parameters and sets it. Return the
set of free variables found in the query.
"swi_set_query_module($query, $module, $ctx_module)"
Allows to set a query in a different module than the default.
"swi_result()"
Return the values binded to the variables in the query.
"swi_next()"
Iterates over the query solutions.
If a new solution is available returns true, if not, closes the
query and returns false.
It should be called after "swi_set_query(...)" to obtain the
first solution.
"swi_var($var)"
Returns the value binded to $var in the current query/solution
combination.
"swi_query"
Returns the current query with the variables binded to its
values in the current solution (or unbinded if swi_next has not
been called yet).
"swi_cut"
Closes the current query even if not all of its solutions have
been retrieved. Similar to prolog "!".
"swi_find_all($query, @pattern)"
iterates over $query and returns and array with @pattern binded
to every solution. i.e:
swi_find_all(member(X, [1, 3, 7, 21]), X)
returns the array "(1, 3, 7, 21)" and
swi_find_all(member(X, [1, 3, 7, 21]), [X])
returns the array "([1], [3], [7], [21])".
More elaborate constructions can be used:
%mothers=swi_find_all(mother(X,Y), X, Y)
There is also an example of its usage in the SYNOPSIS.
"swi_find_one($query, @pattern"
as "swi_find_all" but only for the first solution.
"swi_call"
runs the query once and return true if a solution was found or
false otherwise.
":interactive"
"swi_toplevel"
mostly for debugging pourposes, runs SWI-Prolog shell.
":assert"
"swi_assert($head => @body)"
"swi_assertz($head => @body)"
add new definitions at the botton of the database
"swi_asserta($head => @body)"
adds new definitions at the top of the database
"swi_facts(@facts)"
commodity subroutine to add several facts (facts, doesn't have
body) to the database in one call.
i.e.:
use Language::Prolog::Sugar functors=>[qw(man woman)];
swi_facts( man('teodoro'),
man('socrates'),
woman('teresa'),
woman('mary') );
":context"
$swi_module
$swi_ctx_module
allows to change the module and the context module for the
upcoming queries.
use ALWAYS the "local" operator when changing its value!!!
i.e.:
local $swi_module='mymodule'
swi_set_query($query_from_mymodule);
$swi_converter
allows to change the way data is converter from Perl to Prolog.
You should not use it for any other thing that to configure perl
classes as opaque, i.e.:
$swi_converter->pass_as_opaque(qw(LWP::UserAgent
HTTP::Request
HTTP::Result))
CALLBACKS
Yaswi adds to SWI-Prolog three new predicates to call perl back.
All the calls are make in array contest and the Result value is always a
list. There is not way to make a call in scalar context yet.
"perl5_eval(+Code, -Result)"
makes perl evaluate the string "Code" (really a Prolog atom) and
returns the results.
"perl5_call(+Sub, +Args, -Result)"
calls a perl sub.
"perl5_method(+Object, +Method, +Args, -Result)"
calls the method "Method" from the perl object "Object".
To get objects passed to prolog as opaques instead of marshaled to
prolog types, its class (or one of its parent classes) has to be
previously register as opaque with the $swi_converter object. i.e.:
perl5_eval('$swi_converter->pass_as_opaque("HTTP::Request")',_),
perl5_eval('use HTTP::Request',_),
perl5_method('HTTP::Request', new, [], [Request]),
perl5_method(Request, as_string, [], [Text]);
Registering class "UNIVERSAL" makes all objects to be passed to
prolog as opaques.
EXPORT
This module doesn't export anything by default. Subroutines should be
explicitely imported.
SEE ALSO
SWI-Prolog documentation <http://www.swi-prolog.org/>,
Languages::Prolog::Types, Language::Prolog::Sugar
AUTHOR
Salvador Fandiņo, <sfandino AT yahoo.com>
COPYRIGHT AND LICENSE
Copyright 2003 by Salvador Fandiņo
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
------------------------------
Date: Wed, 22 Jan 2003 12:43:12 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: commands after system call and before die?
Message-Id: <3E2E918C.AAD8099F@acm.org>
qanda wrote:
>
> Here is a script to explain my question ...
>
> [snip]
>
> # Set exit code for die.
> $ec = 5;
>
> # A system call that fails.
> open( ABC, "<abc" ) or
> die "Could not open abc - exiting!\n";
>
> # Another system call that fails.
> open( XYZ, "<xyz" ) or $ec = 6 &&
> die "Could not open xyz - exiting!\n";
>
> In the first failed system call (for ABC) everything is fine. What I
> would like to do, mainly for presentation, is to set $ec after the
> system call but before the die is executed, using something like &&.
> Can this be done?
The precedence for '&&' is too high for this to work.
$ perl -MO=Deparse,p -e'open( XYZ, "<xyz" ) or $ec = 6 && die "Could not open xyz - exiting!\n";'
$ec = die("Could not open xyz - exiting!\n") unless open XYZ, '<xyz';
-e syntax OK
You should use the lower precedence 'and' instead.
$ perl -MO=Deparse,p -e'open( XYZ, "<xyz" ) or $ec = 6 and die "Could not open xyz - exiting!\n";'
$ec = 6 and die "Could not open xyz - exiting!\n" unless open XYZ, '<xyz';
-e syntax OK
John
--
use Perl;
program
fulfillment
------------------------------
Date: Wed, 22 Jan 2003 13:15:41 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: commands after system call and before die?
Message-Id: <ga6t2vknh76v67h00llu37mmprav144rpm@4ax.com>
qanda wrote:
># Another system call that fails.
>open( XYZ, "<xyz" ) or $ec = 6 &&
> die "Could not open xyz - exiting!\n";
You have a precedence problem: the die() happens before the assignment.
Use "and" not "&&". I think it'll work well, then.
--
Bart.
------------------------------
Date: Wed, 22 Jan 2003 13:06:41 +0000
From: "Richard Gration" <richard@zync.co.uk>
Subject: Cross-dependency of packages
Message-Id: <20030122.130641.1987231011.1012@richg.zync>
Hi All,
I've had this problem before and struggled with it, but never found a
satisfactory solution.
I have an object (package SS::Survey) and a general purpose Library
(SS::Lib). The object methods need to use some functions in the Library
and the Library needs to use the object at times. So the tops of the two
files look like:
package SS::Survey;
use SS::Lib qw(:all);
...
and
package SS::Lib;
use SS::Survey;
...
This results in a slew of "subroutine such_and_such redefined at Lib.pm
line blah" errors when running "perl -c Lib.pm" (and in other
situations). I have several questions about this ...
Is this dangerous, merely irritating or somewhere in between?
Is it a result of poor coding practice, or is it unavoidable in some
situations?
I have read in the docs that Perl will only include a given file /
package once ... ?
Any thoughts, facts or help on this would be much appreciated
Cheers
Rick
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
------------------------------
Date: Wed, 22 Jan 2003 10:13:54 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: How are named unary operators that take $_ created?
Message-Id: <Pine.SGI.3.96.1030122100938.686023B-100000@vcmr-64.server.rpi.edu>
[posted & mailed]
On Wed, 22 Jan 2003, Bart Lateur wrote:
>J. Romano wrote:
>
>> Buongiorno 3|4; # prints "Buongiorno, 7!", not 3
>
>Maybe you're barking up the wrong tree. 3|4 is a bitwise OR, and the
>result is 7. Try
>
> buongiorno 3, 4;
>
>instead.
I don't think you followed the thread closely enough. Perl's
optional-unary-arg operators have HIGHER precedence than | does.
sleep 3 | 4; # sleep(3) | 4
--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: 22 Jan 2003 15:13:35 +0100
From: Espen Myrland <espenmyr@start.no.cretinfilter>
Subject: Re: identifying web host platform?
Message-Id: <87fzrl5l2o.fsf@chello.no>
"I'm Dan" <dg1261@cs-REMOVE_THIS-.com> writes:
> Some time ago (within the last year or two) I recall tinkering with a way to
> reveal the host platform and server of a website (ie., NT vs linux, IIS v
> Apache, etc). However, I can no longer recall how it was done. I don't
> remember whether it was a URL of some diagnostic site, or whether it was a
> perl CGI script, or whether it was some exe file to run. I don't even
> remember whether I learned about it from a magazine (PC Magazine, maybe?) or
> from a newsgroup. Does this ring a bell with anyone?
lynx does the job:
espen@diablo:~$ lynx -dump -head http://www.perl.org
HTTP/1.1 200 OK
Date: Wed, 22 Jan 2003 14:12:52 GMT
Server: Apache/2.0.42 (Unix) DAV/2
Accept-Ranges: bytes
Connection: close
Content-Type: text/html; charset=ISO-8859-1
--
espen
------------------------------
Date: 22 Jan 2003 08:01:37 -0800
From: cbdeja@my-deja.com (-)
Subject: make minitest fails
Message-Id: <611952a3.0301220801.fad0e5d@posting.google.com>
I'm building perl 5.6.1 on Solaris 2.8, and it appears to build OK,
except that there is an "Error Code 1 (ignored)" as shown below:
LD_LIBRARY_PATH=my_perl_build_dir ./miniperl -w -llib -MExporter -e
'<?>' || make minitest
*** Error code 1 (ignored)
rm -f lib/re.pm
cat ext/re/re.pm > lib/re.pm
LD_LIBRARY_PATH=my_perl_build_dir ./miniperl configpm configpm.tmp
sh mv-if-diff configpm.tmp lib/Config.pm
AutoSplitting perl library
As you can see the Error Code is easily missed. I think it is the
"make minitest" which has failed, but is this important as the rest of
the build completes without any other apparent problems.
Should I be concerned about this?
Any ideas what might be the cause?
Thanks
Colin
------------------------------
Date: 22 Jan 2003 07:55:26 -0800
From: gabsaga_tata@hotmail.com (Taji)
Subject: Pattern Matching
Message-Id: <15619060.0301220755.3ed84f24@posting.google.com>
I'm getting certain numbers in a process and if the number is one of
the numbers as shown below (separated with pipes), then I want to do
something but the pattern matching doesn't seem to be working
properly. Any ideas?
my $numbers = "112|126|140|154|168|196|224|252|280|308|322|331" ;
my $number = 12 ;
if ( $numbers =~ /$number/ ) {
print "Number found\n" ;
} else {
print "Number not found\n" ;
}
------------------------------
Date: Wed, 22 Jan 2003 12:51:13 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Perl Script not working on Win NT
Message-Id: <3e2e936b.1590483644@news.cis.dfn.de>
On 21 Jan 2003 14:53:43 -0800, electo7366@aol.com (Eric)
wrote:
>I have a perl script that works on Linux, Unix, and Win ME with
>Apache. I need it to run on Win NT/2000 web server with IIS 5.0.
>
>After going through the script I have determined it is not opening a
>file using the open command. I've tried using the standard unix file
>paths /cgi-bin/file.txt as well as the full disk path C:\directory\
>and C:/directory/ none work. The file does not return an error.
>
>Does anyone know how to fix this? Is it the file path or a problem
>with the perl open command?
Probably a problem with the CGI environment or
an incorrectly formed filename/path. Ask for
an error message
my $file = 'C:/directory/file.txt';
open IN, $file or die "Cannot open $file:$!\n";
--
Regards, Helgi Briem
helgi AT decode DOT is
------------------------------
Date: 22 Jan 2003 14:33:47 GMT
From: nobody <noemail@nowhere.net>
Subject: Re: Regenerating Activeperl html documentation
Message-Id: <Xns930B61E4DAAB6abccbaabc@129.250.170.100>
>> here's what I've done after manually installing modules from CPAN:
>
> I tweaked your code a bit - it didn't set the css path right (it
> needs to take into account the level of the file). $dots now takes
> care of this
You'll need to create the destination dirs for the HTML files,
if the dirs don't exist already. It's easy to figure out the dir
names from the error messages.
------------------------------
Date: Wed, 22 Jan 2003 12:04:30 +0100
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Regex problem
Message-Id: <1kus2vcug23p6bdd7iqcfjvu4vi2obvo5g@4ax.com>
On Wed, 22 Jan 2003 11:03:53 GMT, 130.149.2.130
[anno4000@lublin.zrz.tu-berlin.de] wrote:
>> > Could you please do something about your line wrapping? Much obliged.
>> Sorry, can't do much about it. Since we have no way to directly access
>> a NNTP Server I have to use the interface at nodevice.com
>> /peter
>
>If nodevice.com doesn't honor the user's line wrapping, shoot
>them to the moon -- thgey're not fit for usenet. But I find
>that hard to believe.
>
>Let's
>see
>about
>line
>wrapping.
I also posted from nodevice.com to a test group. Line wrapping worked
like a charm.
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: 22 Jan 2003 11:16:54 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Regex problem
Message-Id: <b0luj6$eca$2@mamenchi.zrz.TU-Berlin.DE>
Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net> wrote in comp.lang.perl.misc:
> On Wed, 22 Jan 2003 11:03:53 GMT, 130.149.2.130
> [anno4000@lublin.zrz.tu-berlin.de] wrote:
>
> >> > Could you please do something about your line wrapping? Much obliged.
> >> Sorry, can't do much about it. Since we have no way to directly access
> >> a NNTP Server I have to use the interface at nodevice.com
> >> /peter
> >
> >If nodevice.com doesn't honor the user's line wrapping, shoot
> >them to the moon -- thgey're not fit for usenet. But I find
> >that hard to believe.
> >
> >Let's
> >see
> >about
> >line
> >wrapping.
>
>
> I also posted from nodevice.com to a test group. Line wrapping worked
> like a charm.
Oh... I was looking for one, but didn't find a test group in their mix.
Anno
------------------------------
Date: Wed, 22 Jan 2003 12:45:29 +0100
From: "Peter Ludikovsky" <pludi0aa@htl.minic.ac.at>
Subject: Re: Regex problem
Message-Id: <50z6CvgwCHA.536@angel.support.htl.minic.ac.at>
I'm sorry for my bad behavior but I was quite under pressure (low on =
caffein, low on nicotine, low on time, annoying colleagues).
The script works fine, no more problems but now I'm sure that computers =
do have a soul.
I didn't change anything in the script, it didn't work.
I left it alone for about 2 hours.
I tried again and it worked. I haven't changed anything on the system or =
the script.
If it fails again in 2 hours I'll do a fdformat.
Sorry again for bugging you.
/peter
------------------------------
Date: Wed, 22 Jan 2003 13:46:05 +0000
From: news@roaima.freeserve.co.uk
Subject: Re: server and client on the same port
Message-Id: <ta7m0b.30v.ln@moldev.cmagroup.co.uk>
Markus Rachbauer <markus.rachbauer@chello.at> wrote:
> that is the problem. if i start a listening socket on port 9000, and i
> try to open a second socket with the same port on my local machine, i
> got an error message (port already in use).
Yes.
> how can i create a second socket in perl without any error?
The Perl bit is irrelevant to the question. You can't do that.
Quoting from the ip(7) manual page,
Only one IP socket may be bound to any given local (address,
port) pair.
Chris
--
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}
------------------------------
Date: Wed, 22 Jan 2003 08:18:48 -0500
From: Alexander Stremitzer <stremitz@consultant.com>
Subject: Re: split with pattern matching question
Message-Id: <3E2E9A38.9070302@consultant.com>
Paul Jensen wrote:
>Placing the following statement before you split $_ should remove all
>the whitespace before and after the text. It would also make your
>split function less complicated.
>
>s/\|\s*|\s*\|/\|/g;
>
>Let me know if it works.
>
>Paul
>
>
Your suggestion does not work. It does not remove all whitespace as desired.
[alex@gateway alex]$ cat xxx.pl
#!/usr/bin/perl -w
use strict;
$_ = "|TEXT1 | TEXTA TEXTB | TEXT3| TEXT4 |";
print "$_\n";
s/\|\s*|\s*\|/\|/g;
print "$_\n";
[alex@gateway alex]$ xxx.pl
|TEXT1 | TEXTA TEXTB | TEXT3| TEXT4 |
|TEXT1| TEXTA TEXTB| TEXT3|TEXT4|
Alex
--
All man's miseries derive from not being able to sit quietly in a room alone. (Pascal)
------------------------------
Date: 22 Jan 2003 06:16:49 -0800
From: hamelcd@hotmail.com (Christopher Hamel)
Subject: Re: split with pattern matching question
Message-Id: <4f60d5b3.0301220616.f6b7d65@posting.google.com>
Alexander Stremitzer <stremitz@consultant.com> wrote in message news:<3E2DE570.5010301@consultant.com>...
> Thanks, that did the trick.
>
> Tassilo v. Parseval wrote:
>
> >>|TEXT1 |TEXT2 | TEXT3| TEXT4 |
> >>
> >But what I really wonder about: Do you make these split contortions
> >simply to remove whitespaces? If so a mere
> >
> > s/\s*//g;
> >
> >would be easier.
> >
> >Tassilo
> >
> I did not describe my input data accurate enough. A field can also look
> like | TEXTA TEXTB |. I don't want to remove the space between TEXTA
> and TEXTB.
Nothing wrong with the final solution, however it seems to me you have
a gratuitous split-join:
my $line = join '|', split /\s*\|\s*/;
If you were doing something else with the split elements, I could see
doing this, but it appears that your only goal is to remove the spaces
adjacent to the delimiters, in which case, a simple regex would
suffice:
my ($line = $_) =~ s/\s*\|\s*/\|/g;
Not that the end-all in your program is performance, but the
eliminating the split and join has almost a two-fold increase in
performance:
regex: 2 wallclock secs ( 1.10 usr
split_join: 3 wallclock secs ( 1.90 usr
------------------------------
Date: 22 Jan 2003 07:28:24 -0800
From: clearguy02@yahoo.com (John Smith)
Subject: To extract a specific portion of a text file
Message-Id: <500f84f3.0301220728.30911d01@posting.google.com>
Hi all,
Thanks for your kind response for my problem that I had posted here a
couple of days ago.(in the perl deja news groups). Sorry for my typos
in that posting.
I am giving the file contents here one more time:
********************************** (start of the file,extract.txt)
Component : Main TestPiece
Language : C++
Creation Date : 20-03-2002
Test Key : test_hello_there
test_log_long_one
test_short_my_song
How are you doing there?
Copyright (C) Bla bla bla, All Rights Reserved
This software is for only the test purposes.
Test Key : test_hello_howareyou
test_log_hithere
test_hi_my_song
#ifndef TEST_H
#endif
.......
..........
#endif
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (end of file)
This time I have no typos. I need to have the output with only first
"Test Key" field and its corresponding values. Al these values, start
with test_ and each value has atleast two underscores in it.
The line following the last value of the first "Test Key" may be a
blank line or any line with valid text. In this case it happens to be
a line, " How are you doing there?".
The script should ignore any following "Test Key" fields after the
first "Test Key". Also it should ignore all the lines that have
"test_",except those in the first "Test Key" field.
The output should be just as below:
--------------------------------------------------------
Test Key : test_hello
test_log_hithere
test_short_my_song
---------------------------------------------------------------------------
Here is my code:
------------------------------
#! C:\\perl\\bin\\perl.exe
open (INPUT1, "C:\\scripts\\extract.txt") ||
die "Can not open the file: $!";
@array = <INPUT1>;
foreach (@array)
{
next unless ($_ =~ /\s*Test Key/ || $_ =~ /^\s*test_/);
print;
}
---------------------------------------
But the output for this script is:
-----------------------------------------------------
Test Key : test_hello_there
test_log_long_one
test_short_my_song
Test Key : test_hello_howareyou
test_log_hithere
test_hi_my_song
--------------------------------------------------
I don't want the last four lines in the output i.e. only the "Test
Key" that appears for the first time in the text file and its all
corresponding values.
Can any of you help me fixing me the issue?
Thanks,
S
------------------------------
Date: Wed, 22 Jan 2003 11:33:32 GMT
From: "Rix" <r.noli@tin.it>
Subject: Whois script?
Message-Id: <gkvX9.88250$AA2.3943320@news2.tin.it>
Is there a way to get, given a certain IP number, infos about the owner?
Some perl script that can easily return what is shown in the RIPE Whois DB
like
inetnum->netname and inetnum->descr
Example: 62.11.84.91
inetnum: 62.10.0.0 - 62.11.175.255
netname: TISCALINET
descr: Tiscali SpA
Thanks
------------------------------
Date: Wed, 22 Jan 2003 12:55:19 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Whois script?
Message-Id: <b0m435$rkg$1@news.dtag.de>
Rix wrote:
> Is there a way to get, given a certain IP number, infos about the owner?
>
> Some perl script that can easily return what is shown in the RIPE Whois DB
> like
> inetnum->netname and inetnum->descr
Does this help?
http://search.cpan.org/author/PAULG/Net-Whois-RIPE-1.19/RIPE.pod
CPAN is your friend.
->malte
------------------------------
Date: Wed, 22 Jan 2003 12:26:50 GMT
From: "Rix" <r.noli@tin.it>
Subject: Re: Whois script?
Message-Id: <e6wX9.88585$AA2.3953002@news2.tin.it>
WOW!
"Malte Ubl" <ubl@schaffhausen.de> wrote in message
news:b0m435$rkg$1@news.dtag.de...
> Rix wrote:
> > Is there a way to get, given a certain IP number, infos about the
owner?
> >
> > Some perl script that can easily return what is shown in the RIPE Whois
DB
> > like
> > inetnum->netname and inetnum->descr
>
> Does this help?
> http://search.cpan.org/author/PAULG/Net-Whois-RIPE-1.19/RIPE.pod
>
> CPAN is your friend.
>
> ->malte
>
------------------------------
Date: Wed, 22 Jan 2003 14:20:21 GMT
From: "Rix" <r.noli@tin.it>
Subject: Re: Whois script?
Message-Id: <FMxX9.65012$0v.1978460@news1.tin.it>
Ok installed it, but can't get it to do something, i get no results!
Did you try it? Any sample call?
Thanks
"Malte Ubl" <ubl@schaffhausen.de> wrote in message
news:b0m435$rkg$1@news.dtag.de...
> Rix wrote:
> > Is there a way to get, given a certain IP number, infos about the
owner?
> >
> > Some perl script that can easily return what is shown in the RIPE Whois
DB
> > like
> > inetnum->netname and inetnum->descr
>
> Does this help?
> http://search.cpan.org/author/PAULG/Net-Whois-RIPE-1.19/RIPE.pod
>
> CPAN is your friend.
>
> ->malte
>
------------------------------
Date: Wed, 22 Jan 2003 14:32:00 GMT
From: "Rix" <r.noli@tin.it>
Subject: Re: Whois script?
Message-Id: <AXxX9.65074$0v.1979824@news1.tin.it>
Ok got it to work!
"Malte Ubl" <ubl@schaffhausen.de> wrote in message
news:b0m435$rkg$1@news.dtag.de...
> Rix wrote:
> > Is there a way to get, given a certain IP number, infos about the
owner?
> >
> > Some perl script that can easily return what is shown in the RIPE Whois
DB
> > like
> > inetnum->netname and inetnum->descr
>
> Does this help?
> http://search.cpan.org/author/PAULG/Net-Whois-RIPE-1.19/RIPE.pod
>
> CPAN is your friend.
>
> ->malte
>
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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.
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 V10 Issue 4447
***************************************