[23528] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5737 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 31 21:06:01 2003

Date: Fri, 31 Oct 2003 18:05:09 -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           Fri, 31 Oct 2003     Volume: 10 Number: 5737

Today's topics:
    Re: Aps and Linux <me@privacy.net>
    Re: Help with script to move email files based on date  <mw@stopthespam.here>
    Re: Help with script to move email files based on date  <jurgenex@hotmail.com>
    Re: How Do I Use CGI->System Call As CronJob? (Kevin Shay)
    Re: How to tell what modules are installed? <me@privacy.net>
    Re: How to tell what modules are installed? <michael.p.broida@boeing_oops.com>
    Re: How to tell what modules are installed? <grazz@pobox.com>
        Human verifiable image of numbers, for CGI (brendan)
    Re: Human verifiable image of numbers, for CGI <jurgenex@hotmail.com>
    Re: Logic Flow Question (JR)
        newbie ?: expand variable within a variable <kkomoravolu@lucent.com>
    Re: newbie ?: expand variable within a variable <kkomoravolu@lucent.com>
    Re: newbie ?: expand variable within a variable <noreply@gunnar.cc>
    Re: newbie ?: expand variable within a variable <noreply@gunnar.cc>
    Re: newbie ?: expand variable within a variable <michael.p.broida@boeing_oops.com>
        Newbie: Difference between $array[0] and @array[0] <none@hotmail.com>
    Re: Newbie: Difference between $array[0] and @array[0] <pinyaj@rpi.edu>
    Re: Newbie: Difference between $array[0] and @array[0] <grazz@pobox.com>
    Re: Perl Cut Command <me@privacy.net>
    Re: Perl Cut Command <usenet@dwall.fastmail.fm>
    Re: UNIX domain sockets <jgibson@mail.arc.nasa.gov>
    Re: which host (David Efflandt)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 1 Nov 2003 09:21:55 +1300
From: "Tintin" <me@privacy.net>
Subject: Re: Aps and Linux
Message-Id: <bnugai$1584o0$1@ID-172104.news.uni-berlin.de>


"James Willmore" <jwillmore@remove.adelphia.net> wrote in message
news:20031031113501.46bff5d8.jwillmore@remove.adelphia.net...
> On Fri, 31 Oct 2003 12:00:02 -0500
> Chris Mattern <syscjm@gwu.edu> wrote:
>
> > James Willmore wrote:
> > > On Fri, 31 Oct 2003 13:33:42 +0100
> > > "Ste" <nonspammare@nospam.com> wrote:
> > > <snip>
> > >
> > > This is ASP code, not Perl.
> > >
> > > Wrong group :-(
> > >
> >
> > Nope, it's "Aps" code.  The OP said so.
> >
> >          Chris Mattern
> >
>
> Sorry, but I believe the OP is mistaken.  It appears, to me, to be
> ASP.  ASP is very similar to Visual Basic and it appears from the code
> published that it's ASP (because of the syntax used).
>
> But, of course, I could be wrong :-)

Your sarcasm radar should have been turned up a little more.




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

Date: Fri, 31 Oct 2003 20:49:54 GMT
From: Mark <mw@stopthespam.here>
Subject: Re: Help with script to move email files based on date field in header
Message-Id: <MPG.1a0c6b486ae2fba4989681@24.69.255.211>

In article <3ee08638.0310270721.20349de9@posting.google.com>, 
rjohnson@shell.com says...

> Basically I would a script that would move all emails with the word Apr 
> in the email date header to a directory called April. All emails with 
> the word May in the email date header to be moved to the May directory 
> and so on...


> This ought to do what you want, except for simplicity, I named the
> directories with the three-letter month abbreviations expected in the
> files.
> 
> my @mons = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
> my $pat = join('|', @mons);
> 
> for (@mons) {
>     mkdir $_ or warn "Could not make dir $_: $!\n";
> }
> opendir DIR, '.' or die "Could not read .: $!\n";
> while (my $f = readdir DIR) {
>     next unless -f $f;
>     open IN, $f or warn "Could not open $f: $!\n";
>     while (<IN>) {
>         if (/^Date:/) {
>             if (/($pat)/o) {
>                 rename $f, $1/$f or warn "Could not move $f to $1\n";
>             }
>             else {
>                 warn "No month found in $f\n";
>             }
>             last;
>         }
>     }
> }
> 

There is a problem with this script. I run it and get an error message:
Illegal division by zero at datescript.pl (nameof the script)line 14, 
<IN> line 788.
It then deletes ALL the files in the current dicretory and leaves a file 
with the name of 0 (zero). This is not a good thing.....I am glad I 
tested it on a test directory.
Can anyone please tell me what needs to be fixed with this script

-- 
Regards,
Mark


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

Date: Fri, 31 Oct 2003 21:16:31 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Help with script to move email files based on date field in header
Message-Id: <PiAob.40471$AU.39846@nwrddc01.gnilink.net>

Mark wrote:
[...]
>>                 rename $f, $1/$f or warn "Could not move $f to $1\n";
[...]

> There is a problem with this script. I run it and get an error
> message: Illegal division by zero at datescript.pl (nameof the
> script)line 14, <IN> line 788.

Well, yeah, you are dividing $1 by $f.
Guessing from the rest of the code $f is probalby some file name and unless
this file name happens to start with digits its numerical value would be 0.
So sure, you are getting a division by zero error.

Maybe you meant
    rename $f, "$1/$f" or warn "Could not move $f to $1\n";

> It then deletes ALL the files in the current dicretory and leaves a
> file with the name of 0 (zero).

Well, not exactly. One by one it renames all files to "0", thereby removing
one by one whatever file it had renamed in the previous iteration.

jue




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

Date: 31 Oct 2003 15:00:26 -0800
From: kevin_shay@yahoo.com (Kevin Shay)
Subject: Re: How Do I Use CGI->System Call As CronJob?
Message-Id: <5550ef1e.0310311500.d3f1908@posting.google.com>

efflandt@xnet.com (David Efflandt) wrote in message
news:<slrnbq5bbf.dka.efflandt@typhoon.xnet.com>...
> In other words look for daemonize in 'perldoc perlipc'.  It shows how to 
> fork a child and disassociate itself from the parent (your CGI).  Of 
> course your CGI should provide some proper output to either just 
> acknowledge, or advise the browser if the fork fails.

Here's a good article by Randal that demonstrates how to do this in a
CGI context. It describes a method by which a CGI script can fork a
process, then "watch" the running child process and display an updated
status message in the browser without timing out:

http://www.stonehenge.com/merlyn/LinuxMag/col39.html

Kevin
--
perl -MLWP::UserAgent -e '$u=new LWP::UserAgent;$u->agent("japh");
print join(" ",(split(/\s+/,(split/\n/,$u->request(HTTP::Request->
new(GET=>join("",split(/\n/,"http://groups.google.com/groups?selm=
4365%40omepd.UUCP&output=gplain"))))->content)[60]))[0..3]),",\n"'


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

Date: Sat, 1 Nov 2003 09:28:05 +1300
From: "Tintin" <me@privacy.net>
Subject: Re: How to tell what modules are installed?
Message-Id: <bnugm4$15dbhk$1@ID-172104.news.uni-berlin.de>


"Steve Grazzini" <grazz@pobox.com> wrote in message
news:Lbvob.43111$4O1.7046@nwrdny01.gnilink.net...
> Bernard El-Hagin <bernard.el-haginDODGE_THIS@lido-tech.net> wrote:
> > Helgi Briem <HelgiBriem_1@hotmail.com> wrote:
> >> james.h.anderson@ssmb.com (Jim Anderson) wrote:
> >>> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> >>>> Jim Anderson wrote:
> >>>> > What's the best way to get a list of all the installed modules?
> >>>>
> >>>>      perldoc -q installed
> >>>
> >>> Unfortunately, this just tells me that there's no doc for 'installed'.
> >>
> >> Then you either do not have Perl installed on your system
> >> or the installation is broken.   Which is it?
> >
> > It's neither. There *is* no result for 'perldoc -q installed' except for
> > the "No documentation ... found" error.
>
> That FAQ is new in 5.8.1 (just another possible explanation).

$ perldoc -v
This is perl, v5.8.0 built for MSWin32-x86-multi-thread

$ perldoc -q installed
Found in C:\indigoperl\perl\lib\pod\perlfaq3.pod
  How do I find which modules are installed on my system?

$ perl -v
This is perl, v5.8.0 built for i386-linux-thread-multi

$ perldoc -q installed
Found in /usr/lib/perl5/5.8.0/pod/perlfaq3.pod
       How do I find which modules are installed on my system?





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

Date: Fri, 31 Oct 2003 21:41:46 GMT
From: MPBroida <michael.p.broida@boeing_oops.com>
Subject: Re: How to tell what modules are installed?
Message-Id: <3FA2D71A.D91680A0@boeing_oops.com>

Helgi Briem wrote:
> 
> On Fri, 31 Oct 2003 13:23:19 +0000 (UTC), Andreas Kahari
> <ak+usenet@freeshell.org> wrote:
> 
> >$ perl -v
> >
> >This is perl, v5.8.0 built for i386-openbsd
> >[...]
> >$ perldoc -q installed
> >No documentation for perl FAQ keyword `installed' found
> 
> So it's broken.  You should look into that.
> 
> It seems to be endemic, because the section in question,
> "How do I find which modules are installed on my system?"
> should be in perlfaq3 and is there on most of  my systems,
> but not on yours, not on my Linux ES 2.1 with perl 5.6.1 nor on
> http://perldoc.com/perl5.8.0/pod/perlfaq3.html
> where it should be.
> 
> Hmmm, indeed.

	In our installation:
	    (This is perl, v5.6.0 built for MSWin32-x86-multi-thread ...)

	that question is not in ANY of the FAQ3 files:
	   perlfaq3.html
	   perlfaq3.pod
	   ActivePerl-faq3.html
	(or in any other FAQ files).

	There are several ActivePerl-WinfaqX.html files, but the one
	named "ActivePerl-Winfaq3.html" is not there.
	Maybe that's where it belongs, but it's missing?

		Mike


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

Date: Fri, 31 Oct 2003 22:55:55 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: How to tell what modules are installed?
Message-Id: <%LBob.44404$4O1.26794@nwrdny01.gnilink.net>

Tintin <me@privacy.net> wrote:
> "Steve Grazzini" <grazz@pobox.com> wrote in message
> > That FAQ is new in 5.8.1 (just another possible explanation).
> 
> $ perldoc -v
> This is perl, v5.8.0 built for MSWin32-x86-multi-thread
> 
> $ perldoc -q installed
> Found in C:\indigoperl\perl\lib\pod\perlfaq3.pod
>   How do I find which modules are installed on my system?
> 
> $ perl -v
> This is perl, v5.8.0 built for i386-linux-thread-multi
> 
> $ perldoc -q installed
> Found in /usr/lib/perl5/5.8.0/pod/perlfaq3.pod
>        How do I find which modules are installed on my system?
> 

Well... it went in a couple of months after 5.8.0 (change 18185).
I know RedHat was distributing a patched version of 5.8.0; maybe
Indigo does the same thing.

-- 
Steve


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

Date: 31 Oct 2003 15:07:23 -0800
From: brendan@symonty.org (brendan)
Subject: Human verifiable image of numbers, for CGI
Message-Id: <282ee219.0310311507.5f2d0b3b@posting.google.com>

hi all,

I want to make sure it's a human posting to my webpage, by doing what
PayPal (and lots of other websites) now do: displaying a bitmap of
some numbers and asking the user to enter these numbers.

Are there any Perl scripts and/or tutorials explaining how to do this?

thanks!


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

Date: Fri, 31 Oct 2003 23:40:34 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Human verifiable image of numbers, for CGI
Message-Id: <SpCob.21003$Q9.13112@nwrddc02.gnilink.net>

brendan wrote:
> I want to make sure it's a human posting to my webpage, by doing what
> PayPal (and lots of other websites) now do: displaying a bitmap of
> some numbers and asking the user to enter these numbers.
>
> Are there any Perl scripts and/or tutorials explaining how to do this?

What do you mean by "this"?
- displaying a bitmap? no. Well, I guess you could use Perl-Tk or something
similar
- creating a graphic which contains text or digits: Sure, there are several
modules on CPAN. The first one on my list would be Image::Magick

jue




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

Date: 31 Oct 2003 11:31:10 -0800
From: jrolandumuc@yahoo.com (JR)
Subject: Re: Logic Flow Question
Message-Id: <b386d54b.0310311131.750deff8@posting.google.com>

ctcgag@hotmail.com wrote in message news:<20031031095824.136$cG@newsreader.com>...
> jrolandumuc@yahoo.com (JR) wrote:
> >
> > Thanks, Ben.  I removed the my from the for loop, the way it is
> > removed in recipe 4.3.  I didn't mean to have that in there-it was a
> > typo.  The results, even with my removed in the for loop, are still
> > the same.  Am I correct in guessing that the $i variable is not reset
> > to 0 every time the for loop is entered?
> 
> A new variable is created each time the loop is entered.  That new variable
> can be referred to as $i from within the loop for which it was created (and
> now where else).  This $i is set to 0, but there are still other variables,
> which are also called $i but only from within their respective loops, that
> are not affected here.  This is the main point of recursion, that each
> recursive layer has access to only it's own lexical variables.
> 
> Xho

Damn, I did miss something from my readings.  Page 222 of the 3rd
edition of Programming Perl states that "Subroutines may be called
recursively because each call get its own argument array, even when
the routine calls itself."  Thanks again to everyone for your
responses.

JR


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

Date: Fri, 31 Oct 2003 16:30:23 -0600
From: Krishna Komoravolu <kkomoravolu@lucent.com>
Subject: newbie ?: expand variable within a variable
Message-Id: <bnunpt$fah@netnews.proxy.lucent.com>


Hello!

Pardon me for this trivial question.
Is there a way to expand a perl variable with in a variable?
i.e. when I read a line "$line" from an input file,
   say the line in text(xml) file is like:
	$t:references([@CONTROLLER_TYPE = 0]/@$c) in ....,
when I print this line with print "$line", I want the variables $t and
$c in the above line to be expanded in the output.

In the code segment given below, the last case of the switch i.e.
print "$line"  literally prints $t and $c with out expanding them.

while (<IFH>) {
   my  $line = $_;
   SWITCH: for ($line) {
	/<TableDef[ 	]*name/i &&
	  do {$line =~ /(")(\w+)/; $t = $2; last;};	# set $t
	/<ColumnDef[ 	]*name/i &&
	  do {$line =~ /(")(\w+)/; $c = $2; last;};	# set $c
	/<RuleDef/i &&
	  do {$line =~ /(")(\w+)/; $rule = 1; last;};	# set rule
	/<\/RuleDef/i	&&
	  do {$line =~ /(")(\w+)/; $rule = 0; last;};	# unset rule
	/[aA-zZ]+/ &&	
	  do {print "$line" if $rule == 1; last;};
	}
}

Thanks in advance for any help!

Kris



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

Date: Fri, 31 Oct 2003 17:09:37 -0600
From: Krishna Komoravolu <kkomoravolu@lucent.com>
Subject: Re: newbie ?: expand variable within a variable
Message-Id: <bnuq3f$fl3@netnews.proxy.lucent.com>

Please ignore my previous posting.
Found the answer in perlop.html:

	$line =~ s/(\$\w+)/$1/eeg;

expands the variables with in $line

Kris


> 
> Hello!
> 
> Pardon me for this trivial question.
> Is there a way to expand a perl variable with in a variable?
> i.e. when I read a line "$line" from an input file,
>   say the line in text(xml) file is like:
>     $t:references([@CONTROLLER_TYPE = 0]/@$c) in ....,
> when I print this line with print "$line", I want the variables $t and
> $c in the above line to be expanded in the output.
> 
> In the code segment given below, the last case of the switch i.e.
> print "$line"  literally prints $t and $c with out expanding them.
> 



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

Date: Sat, 01 Nov 2003 00:15:56 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: newbie ?: expand variable within a variable
Message-Id: <bnuqgi$15mp7a$1@ID-184292.news.uni-berlin.de>

Krishna Komoravolu wrote:
> Is there a way to expand a perl variable with in a variable?
> i.e. when I read a line "$line" from an input file, say the line in
> text(xml) file is like:
> $t:references([@CONTROLLER_TYPE = 0]/@$c) in ....,
> when I print this line with print "$line", I want the variables $t
> and $c in the above line to be expanded in the output.

     perldoc -f eval

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Sat, 01 Nov 2003 00:43:36 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: newbie ?: expand variable within a variable
Message-Id: <bnus4n$16ap6n$1@ID-184292.news.uni-berlin.de>

Gunnar Hjalmarsson wrote:
> Krishna Komoravolu wrote:
>> Is there a way to expand a perl variable with in a variable? i.e.
>> when I read a line "$line" from an input file, say the line in 
>> text(xml) file is like:
>> $t:references([@CONTROLLER_TYPE = 0]/@$c) in ....,
>> when I print this line with print "$line", I want the variables
>> $t and $c in the above line to be expanded in the output.
> 
> perldoc -f eval

Hmm...  Kris solved the problem, and the above doesn't seem to help
much, so please disregard it.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Fri, 31 Oct 2003 23:37:20 GMT
From: MPBroida <michael.p.broida@boeing_oops.com>
Subject: Re: newbie ?: expand variable within a variable
Message-Id: <3FA2F230.8B0A098E@boeing_oops.com>

Krishna Komoravolu wrote:
> 
> Is there a way to expand a perl variable with in a variable?
> i.e. when I read a line "$line" from an input file,
>    say the line in text(xml) file is like:
>         $t:references([@CONTROLLER_TYPE = 0]/@$c) in ....,
> when I print this line with print "$line", I want the variables $t and
> $c in the above line to be expanded in the output.

	Try "perldoc -q expand" and look for one about
	expanding variables.

	The third example in that chunk worked well for me.

		Mike


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

Date: Fri, 31 Oct 2003 23:17:34 +0000
From: darren_uk <none@hotmail.com>
Subject: Newbie: Difference between $array[0] and @array[0]
Message-Id: <i4Cob.1219$J4.9350@newsfep4-glfd.server.ntli.net>

I'm completely new to Perl.

I've just read an introduction to arrays (in man perlintro).

It explains that to get a single value from an array, use the scalar prefix
"$"

E.g., 

$array[0]

Later it explains that to get multiple values, use the array prefix "@"

E.g.,

@array[0,1]

Is there any difference between:

$array[0]
and
@array[0]



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

Date: Fri, 31 Oct 2003 18:27:53 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: Newbie: Difference between $array[0] and @array[0]
Message-Id: <Pine.SGI.3.96.1031031182332.1092773B-100000@vcmr-64.server.rpi.edu>

On Fri, 31 Oct 2003, darren_uk wrote:

>Is there any difference between:
>
>$array[0]
>and
>@array[0]

Yes.  As the docs explain, @foo[$x,$y,$z] is the same as

  ($foo[$x], $foo[$y], $foo[$z])

SPECIFICALLY, it generates a LIST of array elements.  The fact that it is
a list is important.

  $size = @array;     # the number of elements in @array is put in $size
  ($first) = @array;  # the first element in @array is put in $first

If you write:

  $lines[$x] = <FILE>;

you read ONE line from FILE, and put it in $lines[$x].  If you write

  @lines[$x] = <FILE>;

you read ALL the (remaining) lines from FILE, and store the first in
$lines[$x].

-- 
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: Fri, 31 Oct 2003 23:30:11 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: Newbie: Difference between $array[0] and @array[0]
Message-Id: <7gCob.30561$294.19988@nwrdny03.gnilink.net>

darren_uk <none@hotmail.com> wrote:
> Is there any difference between:
> 
> $array[0]
> and
> @array[0]

The one-element-slice will give you this warning.

    Scalar value @array[0] better written as $array[0]

And perldiag explains:

    (W syntax) You've used an array slice (indicated by @) to select a
    single element of an array.  Generally it's better to ask for a scalar
    value (indicated by $).  The difference is that $foo[&bar] always
    behaves like a scalar, both when assigning to it and when evaluating its
    argument, while @foo[&bar] behaves like a list when you assign to it,
    and provides a list context to its subscript, which can do weird things
    if you're expecting only one subscript.
    
    On the other hand, if you were actually hoping to treat the array
    element as a list, you need to look into how references work, because
    Perl will not magically convert between scalars and lists for you.  See
    perlref.

It's an odd explanation, since "@foo[bar()]" won't actually generate the
warning... but the difference between something like "@x[0] = localtime"
and "$x[0] = localtime" is important.

-- 
Steve


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

Date: Sat, 1 Nov 2003 09:30:42 +1300
From: "Tintin" <me@privacy.net>
Subject: Re: Perl Cut Command
Message-Id: <bnugr1$15g796$1@ID-172104.news.uni-berlin.de>


"Michael Zawrotny" <zawrotny@jaguar.sb.fsu.edu> wrote in message
news:slrnbq4obd.6c9.zawrotny@jaguar.sb.fsu.edu...
> Tintin <me@privacy.net> wrote:
> >  "Michael Zawrotny" <zawrotny@jaguar.sb.fsu.edu> wrote in message
> > >
> > > You could try "cut -b1-20,41-60".
> >
> >  $ perldoc -f cut
> >  No documentation for perl function 'cut' found
>
> The "cut" in question was the *nix utility.  The OP was having trouble
> getting those columns from a file with cut, and went looking for a
> perl solution when it wasn't working, so I showed how cut could do the
> job.  See "man cut" for details.

I should have added my sarcasm tags.  This is a newsgroup for discussing
Perl.




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

Date: Fri, 31 Oct 2003 22:21:04 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Perl Cut Command
Message-Id: <Xns9425B0809D059dkwwashere@216.168.3.30>

Steve Grazzini <grazz@pobox.com> wrote:

> David K. Wall <usenet@dwall.fastmail.fm> wrote:
>> Buck Turgidson <jc_va@hotmail.com> wrote:
>> > That should read "just print 1-20 and 41 thru 60 on a line"
>> 
>> perl -ne "print substr($_,0,20), substr($_,40,20)" filename
> 
>   perl -pe 'substr($_, 20, 20, "")' filename

Ah, I'd forgotten that substr() will take a 4th argument...  :-)


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

Date: Fri, 31 Oct 2003 12:47:20 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: UNIX domain sockets
Message-Id: <3fa2ca69_2@127.0.0.1>



Erik Anderson wrote:
> I'm trying to implement IPC using IO::Socket::UNIX, but have come into 
> significant difficulty.  I've searched groups.google.com, and have been 
> able to find very few examples of the proper use of IO::Socket::UNIX.
> 
> I have written a very simple client and server system to test this.  The 
> code is below.  The client sends some data to the server, which should 
> display it...it's not working though.  Any ideas?

As Tim Heany pointed out, the main problem is that you are not sending 
any end-of-line characers from the client to the server, but the server 
is waiting for an EOL before proceeding. I have some additional comments:

> 
> Client Code:
> --------------------
> #!/usr/bin/perl

Always:

use strict;

> 
> use IO::Handle;
> use IO::Socket;
> 

> $socket = IO::Socket::UNIX->new( Peer => "/sckt",
>                                  Type => SOCK_STREAM,
>                                  Timeout => 10 ) or die "$!\n$@";
> 

my $socket = ...

> $socket->autoflush(1);

Sockets are autoflush be default, but this line shouldn't hurt.

> 
> $num=0;

my $num = 0;

> while(1) {
>         print $socket "$num";
>         $socket->flush();
>         $num++;
>         sleep(2);
> }

You are writing an infinite amount of data, but very slowly: 10 
characters total in the first 20 seconds. Is your client ever going to 
quit? Also, for consistency, use $socket->print():

while( $num < 10 ) [
   $socket->print("Line $num\n");
   $socket->flush();
   $num++;
   sleep(2);
}

> 
> exit;

No need to call exit as the last line in your program.

> --------------------
> 
> Server code:
> --------------------
> #!/usr/bin/perl
> 
> use IO::Handle;
> use IO::Socket;
> unlink "/sckt";
> my $Server = IO::Socket::UNIX->new( Local       => "/sckt",
>                                     Type        => SOCK_STREAM,
>                                     Listen      => 5
>                                         ) or die $@;

$@ contains the error for the last eval function call. You may want to 
check $! instead.

> while($session = $Server->accept) {
>         chomp($line = <$session>);

You are only reading one line from the client. You should put this in a 
while loop and read until <$session> returns undef.

>         print "From client: " . $line . "\n";
>         $Server->flush();

There should be no need to flush the $Server socket. You are not writing 
to this socket, and flushing an input buffer should rarely be done. You 
may be dumping incoming data.

> 
>         sleep(1);

You may want to call $session->close() here -- I am not sure if it will 
be closed automatically.

> }
> 
> exit;
> --------------------
> 
> Thanks!
> -Erik Anderson
> 

If you really need to read and write data without line endings, you 
should consider using syswrite and sysread instead of print and <>.

I recommend getting and reading a copy of "Unix Network Programming, 
Vol. 1", by W. Richard Stevens.



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

Date: Fri, 31 Oct 2003 19:18:01 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: which host
Message-Id: <slrnbq5db8.dka.efflandt@typhoon.xnet.com>

On Fri, 31 Oct 2003, Werner Winter <werner.winter@asamnet.de> wrote:
> Hello,
> I've setup a linux terminal server. Now I want to know, which user is logged
> in on which host . So I wrote a perl-script named "which_host"
> 
> # which user
> $uid=$<;
> $username=(getpwuid)$uid))[0];
> $username = $1;

Doesn't the above throw an error (getpwuid)$uid))[0].  Then you
immediately reassign $username (where does $1 get its value from?).  
Learn how to copy/paste, so your code examples are not munged by retyping.

> #which host
> @last= `/usr/bin/last -n 1 -a $username`;
> # line 18
> $host= (split (/\s+/, $last[0]))[9];
> 
> The last two lines cause an error: Use of uninitialized value in string eq
> at /usr/local/bin/which_host line 18
> 
> The problem is, that "last" shows only 8 columns, no host in column 9 is
> shown. If I change the line
> @last= `/usr/bin/last -n 1 -a $username`;
>  to
> @last= `/usr/bin/last -n 3 -a $username`;
> then I get 3 lines and in the third line the host is shown in column 9.

On my system, that column only indicates a remote host, and is typically
empty from localhost (local console login, xterm, etc.).  So you have to 
consider that possibility in your code.  Of course the 9th column would be 
the [8] item in the [0..8] list.

-- 
David Efflandt - All spam ignored  http://www.de-srv.com/


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

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


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