[19527] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1722 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 10 06:06:47 2001

Date: Mon, 10 Sep 2001 03:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1000116309-v10-i1722@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 10 Sep 2001     Volume: 10 Number: 1722

Today's topics:
    Re: Arrays, References and indexes. <goldbb2@earthlink.net>
        Can not run without -w (Batara Kesuma)
    Re: Can not run without -w <jbritain@home.com>
        color output in perl? <jason-hoffoss@prodigy.net>
    Re: color output in perl? <pne-news-20010910@newton.digitalspace.net>
    Re: color output in perl? (Chris Fedde)
    Re: color output in perl? <wyzelli@yahoo.com>
    Re: data structure to solve this puzzle..as it's Friday (mbower)
    Re: Getting DBD::CSV to write the collumn names as firs <goldbb2@earthlink.net>
    Re: guestbook <y_h@pi.be>
    Re: Happy Rollover (Chris Fedde)
    Re: Happy Rollover <bcaligari@fireforged.com>
    Re: Inter-Process Communication <Thomas@Baetzler.de>
    Re: Inter-Process Communication <goldbb2@earthlink.net>
    Re: lost children after fork() (Villy Kruse)
        Net::NNTP  <W_i_l_l@me.com>
        New module Net::Streamload (Tobias Gruetzmacher)
    Re: non-blocking Socket IO problem?  Help Req. <goldbb2@earthlink.net>
        Order of subroutines in perl script <justin@comms81.freeserve.co.uk>
    Re: Order of subroutines in perl script (Sam Holden)
    Re: Order of subroutines in perl script blah@blah.blah.invalid
        Perl SMS (SoftwareSleuth)
    Re: printing all even || odd numbers from array <goldbb2@earthlink.net>
    Re: Reverse DNS lookup <Thomas@Baetzler.de>
    Re: Shared Libraries <goldbb2@earthlink.net>
    Re: Shared Libraries <matt@m-centric.com>
    Re: SNMP.so? <josef.moellers@fujitsu-siemens.com>
        terminal Emulator  (Doyle Rivers)
    Re: terminal Emulator <pne-news-20010910@newton.digitalspace.net>
    Re: terminal Emulator <goldbb2@earthlink.net>
    Re: uploading files using CGI <goldbb2@earthlink.net>
    Re: Where can I find a Perl SSH Telnet Client? <diablo@prometheus.humsoc.utas.edu.au>
    Re: Where can I find a Perl SSH Telnet Client? (BUCK NAKED1)
    Re: Which Version............please? <Laocoon@eudoramail.com>
        writing a file on a different server <izz@sahara.com.sa>
    Re: writing a file on a different server <Thomas@Baetzler.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 10 Sep 2001 04:14:01 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Arrays, References and indexes.
Message-Id: <3B9C7649.7F3CB11@earthlink.net>

chengkai liang wrote:
> 
> This like a two-level file structure. You have a section and a number
> of lines in each section for a given file. For a better solution that
> I can have is a hash of lists or if each line has its own key then may
> be a hash of hashs will be your answer.
> 
> Suppose we have a file call sections.dat and it has the following data
> within it,
> 
> [section_1]
> key1 = abc
> key2 = def
> key3 = ghi
> 
> [section_2]
> key1 = abc
> key2 = def
> key3 = ghi

I would call it sections.ini, and use the Config::Ini module available
from CPAN to read from it and write to it.

my $sections = Config::Ini->new("sections.ini");

print $sections->get( "section_1", "key1" ), "\n"; # abc

my $section2 = $sections->get( "section_2" );
print $section2->{key2}, "\n"; # def

print join(" ", keys %{$sections->get}), "\n"; # section_1 section_2

-- 
"I think not," said Descartes, and promptly disappeared.


------------------------------

Date: 10 Sep 2001 01:24:36 -0700
From: bkesuma@yahoo.com (Batara Kesuma)
Subject: Can not run without -w
Message-Id: <8a89aec5.0109100024.2184bc01@posting.google.com>

Hi,

I found a strange thing with my script. It only runs if you put -w
options. If I don't put the -w options, file not found error will be
displayed. What happened? Please help me. Thank you very much.

--bk


------------------------------

Date: Mon, 10 Sep 2001 08:47:43 GMT
From: Jim Britain <jbritain@home.com>
Subject: Re: Can not run without -w
Message-Id: <oevopt473pl1lbfb20jpmocnj5i128b358@4ax.com>

On 10 Sep 2001 01:24:36 -0700, bkesuma@yahoo.com (Batara Kesuma)
wrote:

>Hi,
>
>I found a strange thing with my script. It only runs if you put -w
>options. If I don't put the -w options, file not found error will be
>displayed. What happened?

You uploaded your script from a DOS machine to a UNIX machine in
binary mode.  Upload it in text mode, and that will not happen.




------------------------------

Date: Mon, 10 Sep 2001 04:43:12 GMT
From: "JASON HOFFOSS" <jason-hoffoss@prodigy.net>
Subject: color output in perl?
Message-Id: <AxXm7.3906$FX1.347962569@newssvr17.news.prodigy.com>

I'm running perl under linux, and was wondering what the best way is to go
about printing with colored text.  For example, using the ls command (GNU
version I believe) when configured properly will display various filenames
in different colors based on it's properties.  Like dark blue for
directories, green for executable files, etc.  I would like to be able to
colorize my output from perl like this.  I'm looking for the easiest way to
do this; it doesn't have to have a billion other robust abilities I'll never
use. :)  That is nice, but nearly always makes things harder to use.  Anyone
have any suggestions?

   -Jason




------------------------------

Date: Mon, 10 Sep 2001 06:58:51 +0200
From: Philip Newton <pne-news-20010910@newton.digitalspace.net>
Subject: Re: color output in perl?
Message-Id: <a1ioptg100047f729l961q8r7f99u4lmqs@4ax.com>

On Mon, 10 Sep 2001 04:43:12 GMT, "JASON HOFFOSS"
<jason-hoffoss@prodigy.net> wrote:

> I'm running perl under linux, and was wondering what the best way is to go
> about printing with colored text.

Please check the FAQ *before* posting. `perldoc -q color` would have
told you one way to go about it.

Cheers,
Philip, who notes that `perldoc -q colour` would not have been as
helpful
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


------------------------------

Date: Mon, 10 Sep 2001 05:09:02 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: color output in perl?
Message-Id: <OVXm7.275$Owe.245148160@news.frii.net>

In article <AxXm7.3906$FX1.347962569@newssvr17.news.prodigy.com>,
JASON HOFFOSS <jason-hoffoss@prodigy.net> wrote:
>I'm running perl under linux, and was wondering what the best way is to go
>about printing with colored text.  For example, using the ls command (GNU
>

Look for Term::ANSIColor in the CPAN.

Good Luck

-- 
    This space intentionally left blank


------------------------------

Date: Mon, 10 Sep 2001 15:15:47 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: color output in perl?
Message-Id: <ylYm7.30$XK6.625@wa.nnrp.telstra.net>

"Philip Newton" <pne-news-20010910@newton.digitalspace.net> wrote in message
news:a1ioptg100047f729l961q8r7f99u4lmqs@4ax.com...
>
> Cheers,
> Philip, who notes that `perldoc -q colour` would not have been as
> helpful

Yeah, well that's the yanks for you. :)

--
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;




------------------------------

Date: Mon, 10 Sep 2001 08:24:07 GMT
From: mbower@ibuk.bankgesellschaft.de (mbower)
Subject: Re: data structure to solve this puzzle..as it's Friday afternoon !
Message-Id: <3b9c7790.248935281@news>

>How did you do it in VBA? 
I slotted the values into a spreadsheet, and added a row aove the
values to have something to check against.   ok it's not elegant and
you could shorten it etc, but it took 2 mins to write and works....

Sub bottomvalues()

Sheet1.Application.ScreenUpdating = False
found = 0
    For a = 1 To 100
        Cells(29, 12) = a
        For b = 1 To 100
            Cells(29, 10) = b
            For c = 1 To 100
                Cells(29, 8) = c
                If Cells(24, 8) = Cells(25, 8) Then
                    If Cells(24, 10) = Cells(25, 10) Then
                        If Cells(24, 12) = Cells(25, 12) Then
                            MsgBox "Found it !!!!"
                            Sheet1.Application.ScreenUpdating = True
                            Exit Sub
                        End If
                    End If
                End If
            Next c
        Next b
    Next a
Sheet1.Application.ScreenUpdating = True

End Sub

 I hate to be suspicious of you, but you
>have to admit that it's strange that you don't ask more specific
>questions.  
I didn;t ask more questions becuase I wanted to see how other people
would approach it.

>Why not use the VBA version?
because I'm more interested in Perl than VBA, and it annoyed me that
one seemed more simply than the other.
>If you really want to solve the beer mat, I think the proper tool is
>algebra.
I didn't think it was possible without plugging in dummy values and
then testing the results ?


------------------------------

Date: Mon, 10 Sep 2001 02:03:06 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Getting DBD::CSV to write the collumn names as first line of file
Message-Id: <3B9C579A.6C9424F9@earthlink.net>

Stan Brown wrote:
[snip]
> $stho = $dbho->prepare("$insert_string");
> foreach (@$records_array_ref)
> {
>         $stho->execute ( @{$records_array_ref->[$i++]} );
> }
> 
> But still no first row. What am I doing wrong here?

Simple.  The first row of whatever you want has, for some reason, been
ommited from @$records_array_ref.

Show us the code which shows where $records_array_ref comes from, and
maybe we can tell you why it's missing the first row.

Oh, a couple of notes... you should use strict, use warnings, and take
advantage of the itertor that 'foreach' provides, and remember that a
bareword on the left side of the '=>' operator does not need to be
quoted.  Oh, and things will generally be simpler if you read the
docs... in particular, the stuff you have as parameters to connect() is
wrong.  It should be a single string, not a bunch of strings, and they
are split on semicolons, unless those are escaped... this means that [if
you fixed it so it was one string, not three], your connect line means:

$dbho = DBI->connect("DBI:CSV");
$dbho->{f_dir} = $save_dir;
$dbho->{csv_sep_char} = ",";
$dbho->{csv_quote_char} = "";
$dbho->{",csv_sep_char"} = "";
$dbho->{csv_eol} = "";

This is NOT what you want.  All you *really* want, is the connect line,
and maybe the f_dir part.  

Second... the keys of csv_tables are NOT filenames, they are
*tablenames* ... if you want to set the filename for a particular table,
then you should have it as the value of the 'file' subkey... that is.

$dbho->{csv_tables}{$tablename} = {
	file => $save_filename,
	....
};

Also... if the default value is good, you don't need to override it. 
Since the default eol is "\n", and quote_char and escape_char are by
default "\"", you don't need to change them.  Also, setting col names
automatically sets skip_first_row, so you don't need to set that
explicitly.

#!/usr/bin/perl -w
use strict;
use DBI;
my $dbho = DBI->connect("DBI:CSV");
$dbho->{RaiseError} = 1;
$dbho->{csv_tables}{input_table_name} = {
	file => $i_filename,
	skip_first_row => 0,
};
my @col_names = qw(foo bar baz qux quux);
$dbho->{csv_tables}{output_table_name} = {
	file => $o_filename,
	sep_char => ";",
	col_names => \@col_names,
}

my $input = $dbho->prepare(q[
	SELECT * from input_table_name
	WHERE ....
]);
my $output = $dbho->prepare(
	"INSERT INTO output_table_name (" .
	join(", ", @col_names) . ") VALUES (" .
	join(", ", ("?") x @col_names) . ")"
);
$input->execute;
while( my $arow = $input->fetchrow_arrayref ) {
	$output->execute( @$arow );
}

-- 
"I think not," said Descartes, and promptly disappeared.


------------------------------

Date: Mon, 10 Sep 2001 10:55:37 +0200
From: "Stewie" <y_h@pi.be>
Subject: Re: guestbook
Message-Id: <9nhv6a$a3o$1@news.planetinternet.be>

"Rob - Rock13.com" <rob_13@excite.com> wrote in message
news:Xns9117B2164BCA4rock13com@64.8.1.226...
> stewie <news:9nflen$dh$1@news.planetinternet.be>:
>
> You are posting upside down. Read this:
> http://www.xs4all.nl/%7ewijnands/nnq/nquote.html
>
> >> stewie wrote:
> >> >I've downloaded the perl code for a guestbook
> > http://www.cougasoft.org/guestbook/index.html
> >> >It works fine, but it needs one more thing:
> >> >The owner of the guestbook should be able to give a reaction
> >> >on the guestboard true the admin tool.
>
> Did you suggest this to the author? What you want sounds more like
> a BBS or forum.
>
> > I have tried to study the code, but it is too complex for me.
> > I found out that it is possible to add text in the data-file
> > manually. But to built in a function in the admin tool is too
> > complex for me.
>
> Chances are the author would rather not have you mucking about
> modifying his software beyond what is necessary.
>
> > Or: if you know where i can find a script on the net for a
> > guestbook in which the guestbook
> > owner can reply, i would be happy if you told me.
>
> Check cgi-resouces.com perlarchive.com google.com
>
> I'd offer to modify it for you, but I'm working on my own gb right
> now. And I'd rather not do it without explicit permission from the
> author.
>
> You could skip adding a feature to the admin tool and just write
> your own script to do just what you want. Just use flock and you
> shouldn't mess anything up.
> --
> Rob - http://rock13.com/
> Web Stuff: http://rock13.com/webhelp/

----------------------------------------------------------------------------
---------
If writing my own script was that simple......

I already considered a BBS or forum, but the problem there is that the
visitors als can reply also to messages, and that is not the intention.

Only the owner of the guestbook should be able to reply.

But nevermind, I'm giving it up anyway because this perl/cgi stuf is just
too complicated for me.

Thanks for the trouble
Cya

Stewie




------------------------------

Date: Mon, 10 Sep 2001 05:39:48 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Happy Rollover
Message-Id: <EmYm7.276$Owe.231323136@news.frii.net>
Keywords: Hexapodia as the key insight

In article <9nhapg$njh$1@news1.Radix.Net>,
revjack  <revjack@revjack.net> wrote:
>~$ perl -wle 'print length time'
>10
>
>Happy rollover. Is the world supposed to end now?
>

Rats! I missed it again!  Maybe I'll see the world end on the
the 2Gig rollover.

#!/usr/bin/perl
use POSIX 'strftime';

my $end =  2**31-1;

printf "%032b\n", time;
printf "%032b\n", $end;
print strftime("%d/%m/%Y %T\n", localtime($end));
$end++;
printf "%032b\n", $end;
print strftime("%d/%m/%Y %T\n", localtime($end));
-- 
    This space intentionally left blank


------------------------------

Date: Mon, 10 Sep 2001 05:44:50 -0000
From: "Brendon Caligari" <bcaligari@fireforged.com>
Subject: Re: Happy Rollover
Message-Id: <9nhjk30asc@enews4.newsguy.com>


"revjack" <revjack@revjack.net> wrote in message
news:9nhapg$njh$1@news1.Radix.Net...
> ~$ perl -wle 'print length time'
> 10
>
> Happy rollover. Is the world supposed to end now?
>

Yes

perldoc -f time

    time    Returns the number of non-leap seconds since whatever time the
            system considers to be the epoch (that's 00:00:00, January 1,
            1904 for MacOS, and 00:00:00 UTC, January 1, 1970 for most other
            systems). Suitable for feeding to "gmtime" and "localtime".

perldoc -f length

    length  Returns the length in characters of the value of EXPR. If EXPR
            is omitted, returns length of "$_". Note that this cannot be
            used on an entire array or hash to find out how many elements
            these have. For that, use "scalar @array" and "scalar keys
            %hash" respectively.

$ perl -wle 'print time'
1000100535
$perl -wle 'print length time'
10

on the other hand
$ perl -wle 'print scalar localtime'
Mon Sep 10 07:43:22 2001

B










------------------------------

Date: Mon, 10 Sep 2001 09:04:47 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: Inter-Process Communication
Message-Id: <aqoopt8n33h5o1v3kat746n69hm951tiar@4ax.com>

Hi,


On Sun, 09 Sep 2001, Andrew Paul Gorton <gortona@cs.man.ac.uk> wrote:
>I have written a client/server application.  On the server process I
>need it to parse the request from the client and run other processes
>(which run continually or until the client sends a stop).  I need to be
>able to pass parameters to these processes from the server and also get
>information back - bi-directional communication.

On Unix systems, you could use IPC::Open2 (see perldoc perlipc for a
sample code snippet) for your subprocesses. You would then have to
loop around a select() call in your server to see from which of your
children there's input pending. Since select() isn't implemented on
Win32 platforms, you'd have to take a different approach there.

Alternatively, check out a book like W. Richard Stevens' "Unix Network
Programming Vol. 2: Interprocess Communications" that teaches you
about the other methods to implement client/server architectures. Most
of the stuff he discusses should be implementable with Perl, too.

HTH,
-- 
Thomas Baetzler - http://baetzler.de/ - Clan LoL - http://lavabackflips.de/
I am the "ILOVEGNU" signature virus. Just copy me to your signature.
This post was infected under the terms of the GNU General Public License.


------------------------------

Date: Mon, 10 Sep 2001 03:46:18 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Inter-Process Communication
Message-Id: <3B9C6FCA.E46F77FB@earthlink.net>

Andrew Paul Gorton wrote:
> 
> Hi All,
> 
> I have written a client/server application.  On the server process I
> need it to parse the request from the client and run other processes
> (which run continually or until the client sends a stop).  I need to
> be able to pass parameters to these processes from the server and also
> get information back - bi-directional communication.
> 
> At the moment I am using fork to run the other processes from the
> server, which then read their parameters from a file and also write
> their output to a file which the server reads and sends the info back
> to the client.  This is going to cause me problems when I have several
> processes running because of concurrence.  Is there another way ie
> could I use pipes and is so how, I have been trying to sort this for
> days.

Yes, pipes are the way to go.

#!/usr/bin/perl -w
use strict;

my @children;
for( 0 .. 19 ) {
	my %child;
	pipe( $child{reader}, my $writer ) or die "pipe: $!";
	pipe( my $reader, $child{writer} ) or die "pipe: $!";
	defined($child{pid} = fork) or die "fork: $!";
	if( $pid == 0 ) {
		%child = @children = ();
		child_process( $reader, $writer );
		exit 0;
	}
	$child{pid} = $pid;
	push @children, \%child;
}

foreach my $child (@children) {
	my $fh = $child->{writer};
	print $fh, "Do something\n";
}

foreach my $child (@children) {
	my $fh = $child->{reader};
	print scalar <$fh>;
}

foreach my $child (@children) {
	if( waitpid $child->{pid}, 0 ) {
		my ( $sig, $ret ) = ( $? & 255, $? >> 8 );
		warn "$child->{pid} died from signal $sig" if $sig;
		warn "$child->{pid} exited with code $ret" if $ret;
	} else {
		warn "waitpid( $child->{pid}, 0 ) failed : $!";
	}
}

sub child_process {
	my ($reader, $writer) = @_;
	my $task = <$reader>;
	print $writer "Did something\n";
}

__END__

This should provide you with a simple framework for writing the type of
program you need.

NB: This code is untested.

-- 
"I think not," said Descartes, and promptly disappeared.


------------------------------

Date: 10 Sep 2001 07:41:57 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: lost children after fork()
Message-Id: <slrn9porm4.el.vek@pharmnl.ohout.pharmapartners.nl>

On Sun, 09 Sep 2001 19:38:58 GMT,
    Brandon Hines <brandon_usenet@2i.com> wrote:


>I am attempting to write some code that will run a few pools of sub 
>processes.  I think I've got this fork() thing figured out but I am 
>having one problem--I leave defunct children.
>
>Here are two code samples.  I stripped out all the redundancy and have 
>just enough code to demonstrate my problem.  The first one launches all 
>my children, does something useful, waits a seconds, and repeats.  My 
>something useful will probably be looking in a directory for new files 
>to process up provide status updates.  This works great but on occasion 
>leave defunct processes.  I am assuming that the signal handler gets 
>stepped on when two or more children die at the same time?
>


The normal way to fix this is to loop on a non-blocking version of
wait such as waitpid, and then exit the loop when wiatpid returns
an error.  The problem is that when two or more children dies the
CHLD signal handler is only invoked once.



>So I wrote a second bit of code (OK, I just modified it).  With this 
>one, instead of implementing a signal handler, I just wait at the bottom 
>of my loop.  This works great, but I can only do my periodic work after 
>a child dies.  In my real application this could take a few minutes. 
>I'd hate to stall all my other processing for that long.
>
>I guess my question is, is this a bug in the signal handling code in 
>perl?  Is there any clean way around it?  The cleanest method I can 
>think of is to use my second program and either send a signal from 
>another program or spawn another child whose sole purpose is to die 
>periodically.  Any advice or explanations?
>
>BTW, the problem become really pronounced when I launch a large number 
>of child processes:  for example:  'fork1.pl 100 2000'
>


That makes it very likely that you have zeveral zombies to reap every
time the CHLD signal handler is called.  It is not just a perl
problem but a general unix problem.


------------------------------

Date: Mon, 10 Sep 2001 06:29:21 GMT
From: W i l l <W_i_l_l@me.com>
Subject: Net::NNTP 
Message-Id: <qgnoptshefhvu6910des5gdtuut5bgahnk@4ax.com>

Does anybody have a sample of a Net::NNTP  script that connects to a
news server and posts messages with attachments? I looked over the
Net::NNTP doc and didn't find any real info, maybe I don't know what
im looking for.... If anybody can point me in the right direction I
would greatly appreciate it, and no, Im do not intending to post spam,
I post alot of messages to alt.binaries.sounds.mp3.2000s. At the
momnet I am using Forte Agent to post messages and attachment, posting
a whole album may take up to one minute.  Please remember the 3
virtues of a Perl Hacker, the first is lazyness....

Well I'd like to find, or make a script that will simply glob the
directory's contents and post it to a newsgroup, each attachment as
it's own message with maybe the filename as the subject line.

Again, Im not asking anyone to write this for me, but if you have
something like this laying around, or if you can point me in a good
place to start my research I'd greatly appreciate it.


Will


------------------------------

Date: 10 Sep 2001 09:19:57 GMT
From: nospam@portfolio16.de (Tobias Gruetzmacher)
Subject: New module Net::Streamload
Message-Id: <Xns9118734761A40nospamportfolio16@194.8.194.98>

Hi,

I have developed a new module for Perl to access the media file storing 
service Streamload (http.//www.streamload.com/). You can download it here: 
http://www.portfolio16.de/download/Net-Streamload-0.02.tar.gz

There is a command-line upload-tool called "slup".

I'm not very experienced in writing Perl modules (This is my first). Can 
someone review my code and say what to do better?

Greetings Tobi

-- 
2B OR NOT 2B - The answer is FF!
My, oh so small, homepage: http://www.portfolio16.de/
http://www.fli4l.de/ - ISDN- & DSL-Router on one disk!


------------------------------

Date: Mon, 10 Sep 2001 00:16:00 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: non-blocking Socket IO problem?  Help Req.
Message-Id: <3B9C3E80.44B72DBE@earthlink.net>

nv140a wrote:
> 
> Hello
> 
> I have a program that uses IO:Socket to connect to another black box
> on a different host.  If for some reason that host program terminates
> i.e. the connection is broken, my program hangs trying to read the
> socket. Eventually the program dumps but not for a long time.  What I
> need is to reopen the listen socket and await another connect.  I
> believe the problem revolves around the blocking IO used, but I am
> unsure.
> 
> If you know how to set the socket to non-blocking IO or what the real
> problem is please let me know.  Post a reply.

The problem *partially* results, I believe, from SO_LINGER.  Maybe
someone else will know more.  It's probably not a perl-specific problem,
so you might try asking on a unix newsgroup, or maybe a tcp newsgroup,
if there is one.

> Thank you,
> Lynwood Stewart
> 
> relevant code, there is more but I don't think it is involved.
> 
> use IO::Socket;
> 
> $Socket = IO::Socket::INET->new
>                       (LocalPort => $Port,
>                        Type      => SOCK_STREAM,
>                        Proto     => "tcp",
>                        Reuse     => 1,
>                        Listen    => SOMAXCONN );
> $count = sysread ( $Socket, $buffer, $length );

Considering this is a *listening* port, you should not be reading from
it directly.

my $ListenSocket = IO::Socket::INET->new(
    LocalPort => $Port, Reuse => 1, Listen => SOMAXCONN );
while( my $ClientSocket = $ListenSocket->accept() ) {
    my $blocksize = (stat($ClientSocket))[11] || (1<<15);
    print while sysread $ClientSocket, $_, $blocksize;
}

-- 
"I think not," said Descartes, and promptly disappeared.


------------------------------

Date: Mon, 10 Sep 2001 00:37:02 +0100
From: "Justin Wyllie" <justin@comms81.freeserve.co.uk>
Subject: Order of subroutines in perl script
Message-Id: <9nguss$g22$1@news5.svr.pol.co.uk>

Hi

i have a simple question relating to perl; if someone could help me
understand this i would be really grateful.

the following is ok:


sub A()
{

}

sub B()
{
subA();
}

but if I pass a parameter from B to A then unless I place B above A in the
file I get a complile error. So I have to do this:

sub B()
{
subA("my value");
}

sub A()
{
$val = $_[0];
}


Is this because the compiler ( I have just about grasped that there is an
intermediate stage of complilation and that this compiled code is then
interpreted) requires knowledge of what the data structure of the parameter
being passed into subroutine A() is before it will compile subroutine A?

Your answer will obviously help me take a necessary step forwards in my
understanding of perl.

with thanks

justin wyllie
oxford, uk
email: justin@mms-oxford.com





------------------------------

Date: 10 Sep 2001 05:53:14 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Order of subroutines in perl script
Message-Id: <slrn9polaa.c69.sholden@pgrad.cs.usyd.edu.au>

On Mon, 10 Sep 2001 00:37:02 +0100,
	Justin Wyllie <justin@comms81.freeserve.co.uk> wrote:
<snip>
>but if I pass a parameter from B to A then unless I place B above A in the
>file I get a complile error. So I have to do this:
>
>sub B()
>{
>subA("my value");
>}
>
>sub A()
>{
>$val = $_[0];
>}

If A is going to be passed an argument is shouldn't be prototyped to take
no arguments:

sub A
{
	$val = $_[0];
}
sub B
{
	subA("my value")
}

I suggest you have a read of the perl documentation, especially the bit that
documents subroutines...

perldoc perlsub

-- 
Sam Holden



------------------------------

Date: Mon, 10 Sep 2001 06:10:37 -0000
From: blah@blah.blah.invalid
Subject: Re: Order of subroutines in perl script
Message-Id: <tpomat2ucah5f0@corp.supernews.com>

Justin Wyllie <justin@comms81.freeserve.co.uk> wrote:
[ ... ]
> but if I pass a parameter from B to A then unless I place B above A in the
> file I get a complile error. So I have to do this:
> 
> sub B()
> {
> subA("my value");
> }
> 
> sub A()
> {
> $val = $_[0];
> }
[ ... ]

Justin,

See the section on 'Prototypes' in the perlsub manpage.  The problem is
that, by declaring the sub with the empty parens, you're saying that this
sub will brook no arguments (much like my mother, but I digress :).  If
you want to let A() accept a single scalar argument, you need to declare
it like:

  sub A($) { my $val = $_[0]; }

Note I've also scoped the variable $val with 'my' (perldoc -f my) since
everyone should be running under 'strict'.  Note also that perl does not
require you to use prototypes at all.  Simply saying:

  sub A { my ($val) = @_; }

would be fine, too.

HTH


------------------------------

Date: 9 Sep 2001 22:34:11 -0700
From: howhow82@hotmail.com (SoftwareSleuth)
Subject: Perl SMS
Message-Id: <8048c9d1.0109092134.4e891699@posting.google.com>

To send SMS using Perl, try Simplewire. They have a Developer Program
at http://devprogram.simplewire.com or just go to
http://www.simplewire.com. They have SMS Software Development Kits,
including ActiveX, Java, Perl, PHP and Shared Object, and a network to
connect to hundreds of networks.


------------------------------

Date: Mon, 10 Sep 2001 03:52:28 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: printing all even || odd numbers from array
Message-Id: <3B9C713C.9635F035@earthlink.net>

GunneR wrote:
> @array1 = qw(1 2 3 4 5 6);
[snip]
> Want it to print "2 4 6"

perl -e 'print join(" ", grep !($_ & 1), 1 .. 6 ), "\n"'

-- 
"I think not," said Descartes, and promptly disappeared.


------------------------------

Date: Mon, 10 Sep 2001 09:41:58 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: Reverse DNS lookup
Message-Id: <e7ropt04rl68rjue1pffq295e4ek1n4d4a@4ax.com>

On Sun, 09 Sep 2001, "Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:
>Gareth Horth wrote:
>> How can I do a reverse DNS lookup from a perl script?

>  use Socket;
>  $ENV{REMOTE_HOST}  = gethostbyaddr (inet_aton ($ENV{REMOTE_ADDR}), AF_INET);

That works fine if you can ensure scalar conext - because
gethostbyaddr() will return the Perl equivalent of a struct hostent in
list context. So for the sake of clarity I'd suggest either forcing
scalar context:

$dnsname = scalar gethostbyaddr (inet_aton ($ipaddr), AF_INET);

or using list context properly:

$dnsname = (gethostbyaddr (inet_aton ($ipaddr), AF_INET) )[0];

or using inet_ntoa() instead which does just what the OP needs without
any hidden pitfalls:

$dnsname = print inet_ntoa( inet_aton($ipaddr) );

HTH,
-- 
Thomas Baetzler - http://baetzler.de/ - Clan LoL - http://lavabackflips.de/
I am the "ILOVEGNU" signature virus. Just copy me to your signature.
This post was infected under the terms of the GNU General Public License.


------------------------------

Date: Mon, 10 Sep 2001 03:07:55 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Shared Libraries
Message-Id: <3B9C66CB.2320E300@earthlink.net>

Smiley wrote:
> 
> How do I compile Perl code into a shared library?

Do you mean turn a bunch of perl subroutines into a .dll or .so [which
is what "shared library" usually means], or do you mean, how do I take
my subroutines and make a module, which can be "use"d just like other
modules?

Making a .dll or .so is hard.  It's also probably not what you want.

Making a package isn't hard.  The documentation that comes with perl
describes how to do it.

-- 
"I think not," said Descartes, and promptly disappeared.


------------------------------

Date: Mon, 10 Sep 2001 11:55:03 +0200
From: "matt mcConnell" <matt@m-centric.com>
Subject: Re: Shared Libraries
Message-Id: <3b9c8d23$1@news.airtel.net>

> The documents said that I should compile these functions into a shared
> library in Linux, or a DLL in Windows.  I'm only a beginner at Linux
> but that's what the server's running off of, so I figured it meant
> that there was a way to compile your Perl scripts into a shared
> library file.

I think some of the confusion here may be resulting from two different
definitions of "shared library".  William Seeley is approaching the idea
from a "Perl-centric" viewpoint (though I amdit not understanding the
connection between OOP and shared libraries, shared libraries in their many
forms have been around since long before OOP).  Smiley seems to be talking
about a shared library in the more traditional sense - a binary file that
contains executable routines compiled into machine code that can be used by
any program that cares to link to them.

Sicne Perl is a an interpreted language, one doesn't normally work with
compiled binary, but it is possible to work with the compiled machine code
genereated as an intermediate step by the Perl interpreter.  I've never done
it myself, so can't offer many pointers.  The Perl compiler man page might
be the place to start looking
(http://www.perldoc.com/perl5.6/pod/perlcompile.html)

matt


---
The real problem is entropy.





------------------------------

Date: Mon, 10 Sep 2001 09:33:43 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: SNMP.so?
Message-Id: <3B9C6CD7.2E0B9C4B@fujitsu-siemens.com>

Garry Williams wrote:
> =

> On Fri, 07 Sep 2001 09:22:46 +0200, Josef Moellers
> <josef.moellers@fujitsu-siemens.com> wrote:
> =

> > I'm trying to get mib2c to work, but it requires SNMP.so which I
> > can't find on my system, neither is it built under ucd-snmp-4.1.2.
> > Where do I get SNMP.so from?
> =

> SNMP.so is built as a result of installing the Perl SNMP module.  This
> module is distributed in the perl subdirectory of ucd-snmp-4.1.2 and
> on CPAN.

Thanks, I did have the ucd-snmp-4.1.2 package installed, but didn't know
that a "big" make doesn't build SNMP.so. I even searched the entire
subdirectory for a file mentioning SNMP.so.

I have it now.

Thanks again,

Josef
(also mailed sparately)
-- =

Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett


------------------------------

Date: Mon, 10 Sep 2001 04:38:47 GMT
From: doylerivers@home.com (Doyle Rivers)
Subject: terminal Emulator 
Message-Id: <3b9c4273.5544943@news.cableone.net>

Does anyone know of an existing perl terminal emulator program?  
I would like to be able to connect to a server via telnet and run
various scripts, however the Net::Telnet module is not sufficient for
my needs.

Anyway, if you know of a perl terminal emulator out there please let
me know, it will save me a lot of time having to figure out how to
write one myself.

Thanks,
Doyle Rivers

Doyle Rivers

*********************************************************************
"But God did not send the Son into the world to judge the world,
but that the world should be saved through Him." John 3:17


------------------------------

Date: Mon, 10 Sep 2001 06:58:52 +0200
From: Philip Newton <pne-news-20010910@newton.digitalspace.net>
Subject: Re: terminal Emulator
Message-Id: <nuhoptccek3rqn3ckq98g1h7nl05uqkmbm@4ax.com>

[Newsgroups trimmed to comp.lang.perl.misc; please include a
Followup-To: header in crossposted messages]

On Mon, 10 Sep 2001 04:38:47 GMT, doylerivers@home.com (Doyle Rivers)
wrote:

> Does anyone know of an existing perl terminal emulator program?  
> I would like to be able to connect to a server via telnet and run
> various scripts, however the Net::Telnet module is not sufficient for
> my needs.

You know, it would help if you said what your needs were and how they
are not covered by Net::Telnet. Your message was about as informative as
"it doesn't work".

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


------------------------------

Date: Mon, 10 Sep 2001 03:24:21 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: terminal Emulator
Message-Id: <3B9C6AA5.D583FFAD@earthlink.net>

Doyle Rivers wrote:
> 
> Does anyone know of an existing perl terminal emulator program?
> I would like to be able to connect to a server via telnet and run
> various scripts, however the Net::Telnet module is not sufficient for
> my needs.
> 
> Anyway, if you know of a perl terminal emulator out there please let
> me know, it will save me a lot of time having to figure out how to
> write one myself.

Look into the following modules, available from CPAN:
Ptty
IO::Pty, IO::Tty

And things which use these:
Expect
IPC::Run

I'm sure one of these will do what you want.
Probably you'll want to use Expect and spawn the "telnet" program.

-- 
"I think not," said Descartes, and promptly disappeared.


------------------------------

Date: Mon, 10 Sep 2001 00:20:18 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: uploading files using CGI
Message-Id: <3B9C3F82.3D513B40@earthlink.net>

Arran wrote:
> 
> Hi all,
> Im a little confused in regard how to upload a file.
> I have a cgi script that a user will select a file to upload, press
> the upload button and the same script will do the actual uploading
> (all operation completed within the one script - it displays different
> pages dependant on what action button was used).
> 
> code extracts:
> 
> use CGI qw /:standard :html3/;   #using this
> start_html("my page title"),  start_multipart_form,   #starting form
> as multipart
> 
> print "File to upload: <input type=file name=upfile><br>",
>          $Q->submit('Action','Upload'),p;

You're missing a few very important things.

#!/usr/bin/perl -w
use strict;
use warnings;

Next thing... you use a query object, $Q, but never assign to it, and in
some places, you leave out the $Q-> from CGI subroutines.
Either assign a new CGI object to it, and use it consistantly, or leave
it out, and consistently *don't* use it.

Unless you're using multiple CGI objects, I would leave it out.

-- 
"I think not," said Descartes, and promptly disappeared.


------------------------------

Date: Mon, 10 Sep 2001 15:11:09 +1000
From: "Mr Q. Z. Diablo" <diablo@prometheus.humsoc.utas.edu.au>
Subject: Re: Where can I find a Perl SSH Telnet Client?
Message-Id: <diablo-F35444.15110910092001@newsroom.utas.edu.au>

In article <06Vm7.12$044.236667@news.interact.net.au>, "Tintin" 
<tintin@snowy.calculus> wrote:

> "What A Man !" <whataman@home.com> wrote in message
> news:3B9C1AA2.9A9A1AE2@home.com...
> > peter pilsl wrote:
> > Thanks, I really doubted that Perl had any SSH modules so I didn't
> > check, but admit that I should have. I did check www.openssh.org and it
> > said there was a unix client, but the only URL was in Finland, and it
> > would never respond. I've now looked at the SSH modules that the other
> > poster recommended, and still don't quite understand how to go about
> > putting it together in a script. I was really hoping there was a "perl
> > SSH telnet client script" already written by someone, so I wouldn't have
> > to re-invent the wheel. Seems like I saw a perl telnet client in one of
> > Randall Schwartz articles, if I can find it.
> 
> I'm really confused.  Why would you want a SSH "telnet" client?

I'm really confused.  Why is this ng full of such unpleasant, smug, 
arrogant wankers with no social skills.  A gentle pointer to the fact 
that SSH and telnet are not the same thing and the basics of why would 
be somewhat kinder (and more useful) than the above one liner.

I've seen it happen on more than a few occasions on c.l.p.m. and it 
really doesn't make the people who do it seem clever at all.  They just 
look like geeks who are merely trying to prove how immensely clever they 
are - shouting it from the rooftops but not using their cleverness to 
help anyone out.

</rant>

Mr Q. Z. D.
----
Drinker, systems administrator, wannabe writer, musician and all-round bastard.
"If chance supplied a loaf of white bread,
 Two casks of wine and a leg of mutton,
 In the corner of a garden with a tulip-cheeked girl
 There'd be enjoyment no Sultan could outdo." - Omar Khayyam.


------------------------------

Date: Mon, 10 Sep 2001 01:12:27 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: Where can I find a Perl SSH Telnet Client?
Message-Id: <12906-3B9C59CB-34@storefull-244.iap.bryant.webtv.net>

> peter pilsl wrote: 
> I'm really confused. Why would you 
> want a SSH "telnet" client? 


So that I can login to my webhost's SSH telnet from WebTV when I'm not
on the PC and enter Unix commands, chmod, install modules, use lynx,
etc. WebTV can't use any of the windows clients, such as SecureCRT.

Regards,
Dennis(aka whataman@home.com)



------------------------------

Date: Mon, 10 Sep 2001 07:01:32 +0200
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: Which Version............please?
Message-Id: <Xns911848D784EB3Laocooneudoramail@62.153.159.134>

"Dabhar" <dabhar@dabhar.org> wrote in
news:x4Wm7.156400$B37.3497955@news1.rdc1.bc.home.com: 

> Thanks for reading my post. I'm trying to figure out which distribution
> of Perl to start with. I'm working on a windows machine, 
*snip*

If your working on Windows i'd recommend using ActiveState


------------------------------

Date: Mon, 10 Sep 2001 10:11:56 +0300
From: "IzzEddeen Al Karajeh" <izz@sahara.com.sa>
Subject: writing a file on a different server
Message-Id: <3b9c683a$1@news.sahara.com.sa>

This is a multi-part message in MIME format.

------=_NextPart_000_0075_01C139E1.0583E7C0
Content-Type: text/plain;
	charset="windows-1256"
Content-Transfer-Encoding: quoted-printable

hello
I'm a newbie in perl
I have two site on two different servers.
I need to generate a HTML file by perl and save it on another server.
What do I need to do so? How could I set permissions for server1 to =
write on server2?
what is the statements I need to use?

--=20
_________________________________________
_______{Your_Internet_Services_Oasis}________
IzzEddeen Al Karajeh, Web Developer, P.O.Box: 5480,=20
Sahara Network, Dammam 31422, Kingdom of Saudi Arabia,=20
Phone: (966)(3)(8322299) Ext. 235 Fax: (966)(3)(8345652).
http://www.sahara.net.sa    izz@sahara.com.sa

------=_NextPart_000_0075_01C139E1.0583E7C0
Content-Type: text/html;
	charset="windows-1256"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1256">
<META content=3D"MSHTML 6.00.2479.6" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>hello</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I'm a newbie in perl</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I have two site on two different=20
servers.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I need to generate a HTML file by perl =
and save it=20
on another server.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>What do I need to do so? How could I =
set=20
permissions for server1 to write on server2?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>what is the statements I need to =
use?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2><BR>--=20
<BR>_________________________________________<BR>_______{Your_Internet_Se=
rvices_Oasis}________<BR>IzzEddeen=20
Al Karajeh, Web Developer, P.O.Box: 5480, <BR>Sahara Network, Dammam =
31422,=20
Kingdom of Saudi Arabia, <BR>Phone: (966)(3)(8322299) Ext. 235 Fax:=20
(966)(3)(8345652).<BR><A=20
href=3D"http://www.sahara.net.sa">http://www.sahara.net.sa</A>&nbsp;&nbsp=
;&nbsp;=20
<A=20
href=3D"mailto:izz@sahara.com.sa">izz@sahara.com.sa</A></FONT></DIV></BOD=
Y></HTML>

------=_NextPart_000_0075_01C139E1.0583E7C0--



------------------------------

Date: Mon, 10 Sep 2001 10:41:47 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: writing a file on a different server
Message-Id: <truoptgsktmph406vnnjkf8au3rnbs0b46@4ax.com>

Hi,

On Mon, 10 Sep 2001, "IzzEddeen Al Karajeh" <izz@sahara.com.sa> wrote:
>I'm a newbie in perl
>I have two site on two different servers.
>I need to generate a HTML file by perl and save it on another server.
>What do I need to do so? How could I set permissions for server1 to write on server2?
>what is the statements I need to use?

You don't give us enough info to make anything but educated guesses as
to what your problem may be. How you transfer a file from one server
to the other depends on the OS running on the machine and what kind of
services are running on the servers.

Off the top of my head I'd say you might want to consider pushing the
file from server A to B using FTP (with the Net::FTP module). A
different approach could be to pull in the document on server B only
on demand - if it isn't on Server B yet, launch a HTTP request to
server A and cache the result. For this, you might want to look into
the LWP suite. A totally different approach might be taken if your two
servers are on the same local network - you could use a shared
document directory using NFS or SMB filesharing.

HTH,
-- 
Thomas Baetzler - http://baetzler.de/ - Clan LoL - http://lavabackflips.de/
I am the "ILOVEGNU" signature virus. Just copy me to your signature.
This post was infected under the terms of the GNU General Public License.


------------------------------

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 1722
***************************************


home help back first fref pref prev next nref lref last post