[24977] in Perl-Users-Digest
Perl-Users Digest, Issue: 7227 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 9 06:07:58 2004
Date: Sat, 9 Oct 2004 03:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 9 Oct 2004 Volume: 10 Number: 7227
Today's topics:
Re: [newbie] Problems with character output. <postmaster@castleamber.com>
Announcing: Album 1.00 <jvromans@squirrel.nl>
Re: any tools to enable test automation for scripting l <Joe.Smith@inwap.com>
Re: Getting all directories/files from current director <tintin@invalid.invalid>
Re: Getting all directories/files from current director <usa1@llenroc.ude.invalid>
Re: getting telnet banner <lv@aol.com>
Re: getting telnet banner (David Efflandt)
Re: getting telnet banner <zebee@zip.com.au>
Re: getting telnet banner <zebee@zip.com.au>
Re: How to capture output of CVS via Perl? (Chris Weiss)
Re: linked list for string class (Anno Siegel)
locking items in a collection (Tim Keith)
Re: subtracting strings <noreply@gunnar.cc>
Re: subtracting strings <jurgenex@hotmail.com>
Re: While query <mritty@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 9 Oct 2004 03:10:25 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: [newbie] Problems with character output.
Message-Id: <Xns957CE18F4BBBDcastleamber@130.133.1.4>
Reven <reven.quita.esto@reven.y.esto.tambien.org> wrote in news:8rF9d.6586
$pl1.6396@twister.auna.com:
> Hi group.
>
> I've installed ActivePerl on win XP and I'm having some problems. I've
> tried documentation at activestate but found nothing on this topic.
>
> When a string contains a non-english character (for ex. á [thats
> á if you don't see it]) and the script prints that string to the
> screen, I get a lousy character, like if the cmd shell didn't support
> this character. But I can type it directly in a shell prompt and it
> shows ok.
The editor and your console use different code pages.
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Fri, 8 Oct 2004 15:27:27 GMT
From: Johan Vromans <jvromans@squirrel.nl>
Subject: Announcing: Album 1.00
Message-Id: <I5B9Dz.5CF@zorch.sf-bay.org>
Album is a tool to create HTML based photo albums. It allows you to
manage your digital pictures on your computer.
A photo album consists of a series of (large) originals, thumbnails,
and index pages. The large originals are the real originals that came
from the camera. Originals will never be touched or modified.
Note that a photo album is not a Web gallery. There are other tools
that are much more suited for that purpose.
Album is written in Perl, but requires a few helper programs for movies
and sounds.
URL: http://www.squirrel.nl/people/jvromans/Album/index.html
http://search.cpan.org/search?dist=album
----------------------------------------------------------------------------
Johan Vromans jvromans@squirrel.nl
Squirrel Consultancy Haarlem, the Netherlands
http://www.squirrel.nl http://johan.vromans.org
PGP Key 2048/4783B14D http://johan.vromans.org/pgpkey.html
----------------------- "Arms are made for hugging" ------------------------
------------------------------
Date: Sat, 09 Oct 2004 08:50:36 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: any tools to enable test automation for scripting language like perl?
Message-Id: <wDN9d.359316$Fg5.224518@attbi_s53>
matt wrote:
> is there any automatic test tools around?
Yes. Simply download the sources to perl and watch what happens as
you compile it. The 'make test' process runs thousands of tests.
Take a look at what is in the 't' directories for ideas.
-Joe
------------------------------
Date: Sat, 9 Oct 2004 14:10:55 +1300
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: Getting all directories/files from current directory and using -d flag for the directories
Message-Id: <2sos34F1o2bjdU1@uni-berlin.de>
"Adam Petrie" <adam.petrie@walgreens.com> wrote in message
news:9d42ced3.0410081205.7c9fec80@posting.google.com...
> Hi guys/gals,
>
> I'm pretty new to Perl, so please keep that in mind. :)
>
> It looks like File::Find goes through all the subdirectories of the
> current directory, which isn't what I want. I just want all the
> contents of the current directory.
in that case, just do
#!/usr/bin/perl
use strict;
foreach (</path/to/dir/*>) {
print "Directory: $_\n" if -d;
print "File: $_\n" if -f;
}
------------------------------
Date: 9 Oct 2004 03:14:40 GMT
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Re: Getting all directories/files from current directory and using -d flag for the directories
Message-Id: <Xns957CECB589197asu1cornelledu@132.236.56.8>
adam.petrie@walgreens.com (Adam Petrie) wrote in
news:9d42ced3.0410081205.7c9fec80@posting.google.com:
> However, the -d doesn't seem to be working right. Most of the output
> comes from the else part when it should be showing many directories
> instead.
>
> What is going on? Any other solutions?
It is always a good idea to actually read the documentation for the
functions you are using:
perldoc -f readdir
Sinan.
------------------------------
Date: Fri, 08 Oct 2004 22:43:28 -0500
From: l v <lv@aol.com>
Subject: Re: getting telnet banner
Message-Id: <41675c5c$1_4@127.0.0.1>
Zebee Johnstone wrote:
> I want to connect to a machine's telnet server, read its banner, and
> disconnect.
>
> Net::Telnet doesn't appear to read banners, it doesn't return info till
> you log on.
>
>
> A simple: perl -e 'print `telnet clone`;'
> will give the info back, but not till the telnet session has timed out.
>
> The following code doesn't time out and doesn't return anything either.
>
> I've tried printing \n to the socket before getting $answer, makes no
> difference.
>
> Anyone know what I can do to get the banner?
>
>
> #!/usr/bin/perl -w
> use strict;
> use IO::Socket;
>
> my $remote_host = shift;
> my $remote_port = 23;
> my $socket = IO::Socket::INET->new(PeerAddr => $remote_host,
> PeerPort => $remote_port,
> Proto => "tcp",
> Type => SOCK_STREAM)
> or die "Couldn't connect to $remote_host:$remote_port : $@\n";
>
> my $answer = join("\n",<$socket>);
> close($socket);
> print "answer is $answer\n";
>
>
>
>
>
Try using Net::Telnet's getlines ...... untested snippet follows ...
$t = new Net::Telnet (Timeout => $secs,
Prompt => "/$serverName:.+/");
$mode = $t->errmode('return');
$t->open("$serverName.xxx.com");
@lines = $t->getlines;
$t->close;
Len
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
------------------------------
Date: Sat, 9 Oct 2004 04:56:51 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: getting telnet banner
Message-Id: <slrncmersj.u.efflandt@typhoon.xnet.com>
On Fri, 08 Oct 2004 09:11:48 GMT, Zebee Johnstone <zebee@zip.com.au> wrote:
> I want to connect to a machine's telnet server, read its banner, and
> disconnect.
>
> Net::Telnet doesn't appear to read banners, it doesn't return info till
> you log on.
I don't know if a telnet banner typically has more than one line (I use
ssh instead), but following is a simple example that can read/print a line
(works as well for polling smtp servers, etc.):
use IO::Socket;
$remote = IO::Socket::INET->new (
Proto => "tcp",
PeerAddr => "localhost",
PeerPort => "telnet(21)",
)
or die "can't connect";
$_ = <$remote>;
print;
------------------------------
Date: Sat, 09 Oct 2004 06:31:56 GMT
From: Zebee Johnstone <zebee@zip.com.au>
Subject: Re: getting telnet banner
Message-Id: <slrncmf12g.45o.zebee@zeus.zipworld.com.au>
In comp.lang.perl.misc on Sat, 9 Oct 2004 04:56:51 +0000 (UTC)
David Efflandt <efflandt@xnet.com> wrote:
>
> I don't know if a telnet banner typically has more than one line (I use
> ssh instead), but following is a simple example that can read/print a line
> (works as well for polling smtp servers, etc.):
Mine does... it's one of the reasons I want to read it, as it changes
depending on certain events.
>
> use IO::Socket;
> $remote = IO::Socket::INET->new (
> Proto => "tcp",
> PeerAddr => "localhost",
> PeerPort => "telnet(21)",
> )
> or die "can't connect";
> $_ = <$remote>;
> print;
I can't find any of those items in the IO::Socket perldoc, where do they
come from? What's the "telnet(21)" thing, telnet's port 23?
I tested it on my system and tcpdump tells me it is connecting, but I
see no output and it doesn't exit, same symptoms as my original program.
If I turn off telnet, then it correctly dies.
Zebee
--
Zebee Johnstone (zebee@zip.com.au), proud holder of
aus.motorcycles Poser Permit #1.
"Motorcycles are like peanuts... who can stop at just one?"
------------------------------
Date: Sat, 09 Oct 2004 06:37:26 GMT
From: Zebee Johnstone <zebee@zip.com.au>
Subject: Re: getting telnet banner
Message-Id: <slrncmf1cr.45o.zebee@zeus.zipworld.com.au>
In comp.lang.perl.misc on Fri, 08 Oct 2004 22:43:28 -0500
l v <lv@aol.com> wrote:
>
> Try using Net::Telnet's getlines ...... untested snippet follows ...
>
> $t = new Net::Telnet (Timeout => $secs,
> Prompt => "/$serverName:.+/");
> $mode = $t->errmode('return');
>
> $t->open("$serverName.xxx.com");
> @lines = $t->getlines;
> $t->close;
>
As I said, Net::Telnet doesn't appear to return things till you log on.
This snippet times out and produces nothing.
Zebee
------------------------------
Date: 9 Oct 2004 01:59:44 -0700
From: cweiss@stickyc.com (Chris Weiss)
Subject: Re: How to capture output of CVS via Perl?
Message-Id: <653ab165.0410090059.11ace7b1@posting.google.com>
Paul Lalli <mritty@gmail.com> wrote in message news:<ck79n2$j7l$1@misc-cct.server.rpi.edu>...
> Chris Weiss wrote:
> > I'm trying to capture the output of a cvs update session to a log file
> > using ActivePerl and can't seem to get it captured - the CVS results
> > still dump to the screen and not to a file...
> >
> > Here's the snippit of code I'm trying:
> >
> > open(STDOUT, ">".$logfile);
>
> Always check the return value of open.
>
Will do - this was a first stab.
> > system($cvs." ".$cvsroot." ".$cvs_update_args);
>
> You're not even bothering to determine if this command ran successfully.
That's the intent of capturing the output. To parse for errors (of all
kinds) and send the log via email (that part I have working with other
portions of the script).
>
> > Any thoughts on what's going on?
>
> Yes. You have a misperception about the cvs command.
Feel free to enlighten - I should have started with "I'm new to
this...", but it seems pretty obvious.
>
> > Does ActivePerl not support SDTOUT?
>
> I've never heard of any language supporting SDTOUT. STDOUT, on the
> other hand...
I'm also a horrible typist.
>
> > Any help would be greatly appreciated!
>
> Forget perl for a moment. Try this command in your shell:
>
> cvs update > output.txt 2> err.txt
>
> The results of that should point you in the right direction.
>
> Paul Lalli
Sorry about the duplicate posts - The google post form timed out and
I'd assumed it did so before completing the operation.
------------------------------
Date: 9 Oct 2004 08:19:45 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: linked list for string class
Message-Id: <ck86v1$8ls$1@mamenchi.zrz.TU-Berlin.DE>
David K. Wall <dwall@fastmail.fm> wrote in comp.lang.perl.misc:
> Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>
> > I think we have been trolled, though not very effectively. I
> > mean, larry_wallet@yahoo...
>
> Possibly, but Xho's response was worth it. :-)
Agreed!
Anno
------------------------------
Date: 8 Oct 2004 23:52:34 -0700
From: tkeith@mindspring.com (Tim Keith)
Subject: locking items in a collection
Message-Id: <b9087743.0410082252.5a8f5e33@posting.google.com>
I have a collection of 10 named items from which I would like
to lock 1 to 10 items in a single request. Multiple processes
may request "tokens" from the collection. At any time 1 to 10
items of the collection can be assigned to unique process ids
during which time a lock is held on the token.
Each item must have a specific name, lock requests are made
for a count of items. When items are unlocked, the unlock
request can use either a handle returned by the original
lock request, or in a special case - unlocked by a request
using its ordinal value(1 - 10).
Each of the ten items will be tied to a process id (and possibly
other arbitrary data). When the process terminates the token
can be unlocked so that other processes may request a lock for
the token.
No two requests should be assigned the same token when multiple
requests for tokens occur simulaneously.
Is there a CPAN module that would provides this functionality?
------------------------------
Date: Sat, 09 Oct 2004 04:03:50 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: subtracting strings
Message-Id: <2sov84F1ml8j6U1@uni-berlin.de>
Gunnar Hjalmarsson wrote:
> Dan Jones wrote:
>> What's the generally accepted or most efficient way to "subtract"
>> one string from another, or to remove a substring from a string.
>> In other words, something like this:
>>
>> my $string = "This is a really neat string.";
>> my $stringtosub = "really neat ";
>>
>> #doesn't work
>> my $newstring = $string - $stringtosub;
>> #$newstring would now be "This is a string."
>
> (my $newstring = $string) =~ s/$stringtosub//;
It struck me that as long as we are talking about plain strings, it's
not necessary to involve the regex engine:
substr $string, index($string, $stringtosub),
length $stringtosub, '';
print "$string\n";
While it should be noted that $string is changed with that solution,
it may be more efficient than using the s/// operator. (But I haven't
benchmarked it, so I shouldn't really say that...)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 09 Oct 2004 02:41:40 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: subtracting strings
Message-Id: <EdI9d.1337$j15.1140@trnddc07>
Dan Jones wrote:
> What's the generally accepted or most efficient way to "subtract" one
> string from another, or to remove a substring from a string. In
> other words, something like this:
>
> my $string = "This is a really neat string.";
> my $stringtosub = "really neat ";
>
> #doesn't work
> my $newstring = $string - $stringtosub;
Well, no. This will typically yield 0-0 which assigns 0 to $newstring.
> #$newstring would now be "This is a string."
>
> If $stringtosub works as a regex, I could do it with backrefs but
You don't need backrefs, just a good old plain
$string =~ s/$stringtosub//;
> $stringtosub may contain characters which would need to be escaped in
> a regex.
Yep, that's a problem. But you may want to take a look at the "qr" operator.
A totally different approach would be to use index() to search for the
position of the substring and then substr() to remove that section.
I don't know which one would be faster, but REs are usually quite expensive.
jue
------------------------------
Date: Fri, 08 Oct 2004 23:12:06 -0400
From: Paul Lalli <mritty@gmail.com>
Subject: Re: While query
Message-Id: <ck7kuj$k6v$1@misc-cct.server.rpi.edu>
Ben Morrow wrote:
> The comma operator constructs lists; a list
> evaluated in scalar context evaluates all its members but the last in
> void context and the last in scalar context, which is then the list's
> value.
So the Perl FAQ is wrong? I refer you to the array vs list perlfaq:
As a side note, there's no such thing as a list in scalar
context. When you say
$scalar = (2, 5, 7, 9);
you're using the comma operator in scalar context, so it
uses the scalar comma operator. There never was a list
there at all! This causes the last value to be returned: 9.
And likewise, perldoc perlop is also wrong?
Binary "," is the comma operator. In scalar context it
evaluates its left argument, throws that value away, then
evaluates its right argument and returns that value. This
is just like C's comma operator.
> perl -MO=Graph,-dot -e'my $count = (1,2)' | dot -Tps
I admit to having no idea what any of the above arguments, nor the below
output mean. I will research tomorrow after a night's rest.
Paul Lalli
>
> produces output the pertinant parts of which look somewhat like:
>
> leave(LISTOP) { # end scope
>
> enter(OP) # start scope
> nextstate(COP) # start a statement
> sassign(BINOP) { # scalar assignment
>
> list(LISTOP) { # build a list
>
> pushmark(OP) # mark the start of the list on the stack
> null(OP) # the optimizer has deleted the 1
> const(SVOP) # refers to an IV, the 2
> }
> padsv(OP) # retreives $count to assign into
> }
> }
>
> (these op trees are executed inside-out, so the execution order is
>
> enter, nextstate, pushmark, null, const, list, padsv, sassign, leave
>
> as you would expect)
>
> Note the 'list(LISTOP)': perl is building a list and then performing a
> scalar assignment of that list to $count.
>
> Ben
>
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 7227
***************************************