[24009] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6207 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 3 06:05:37 2004

Date: Wed, 3 Mar 2004 03:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 3 Mar 2004     Volume: 10 Number: 6207

Today's topics:
    Re: /dev/pts/x, /proc/x/fd, reading stdout, writing std <jwillmore@remove.adelphia.net>
        Emacs modules for Perl programming (Jari Aalto+mail.perl)
    Re: File::Temp: opening the temp. file in "r+" mode? Al (A. Farber)
    Re: local and my variables in a subroutine (Jay Tilton)
    Re: local and my variables in a subroutine <pengtaoli@hotmail.com>
    Re: local and my variables in a subroutine <tassilo.parseval@rwth-aachen.de>
    Re: Macros <nobull@mail.com>
    Re: Need help sending a password to ftp (Himanshu Garg)
        passing arrays to function <yamini_rajan@nospam.com>
    Re: passing arrays to function <beable+unsenet@beable.com.invalid>
    Re: passing arrays to function <tassilo.parseval@rwth-aachen.de>
    Re: passing arrays to function <pengtaoli@hotmail.com>
    Re: Perl running on Windows and Berkeley DB (Malcolm Dew-Jones)
    Re: perl::api2 pdf problem... (michael vernersen)
    Re: process communication design (c++ <-> perl) <remove_Hannes.Krueger@uibk.ac.at>
    Re: Regex to replace unsafe chars? <jwillmore@remove.adelphia.net>
        Socked not valid - how to check it? <tjudycki@tv.com.pl>
    Re: Socked not valid - how to check it? <ali@packetknife.com>
    Re: use question <jwillmore@remove.adelphia.net>
    Re: webservices <nospam@bigpond.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 03 Mar 2004 00:17:47 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: /dev/pts/x, /proc/x/fd, reading stdout, writing stdin, not with open3
Message-Id: <pan.2004.03.03.05.17.45.755676@remove.adelphia.net>

On Tue, 02 Mar 2004 18:52:29 +0000, Andreas Persson wrote:

> are there any perl gods out there that could help me. :)
> 
> is it possible to open(?) /dev/pts/x that another program
> has created/using/virtual_console and read its stdout and let me write to
> its stdin?
> 
> is it possible to use /proc/$pid/fd/x in some way?
> 
> the only way i've found to work is with open3 call, but this not
> nice to the program that needs to be running 24/7. :)
> 
> 
> any tips/hints are very welcome, both on a perl solution and general info
> on /dev/pts/ and /proc/$pid/fd/.

Can you, instead, redirect or `tee` the output of the application you're
trying to monitor to a fifo and then let the script read that instead of
the virtual console?

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
In a medium in which a News Piece takes a minute and an
<"In-Depth" Piece takes two minutes, the Simple will drive out
the Complex.   -- Frank Mankiewicz 


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

Date: 03 Mar 2004 10:07:10 GMT
From: <jari.aalto@poboxes.com> (Jari Aalto+mail.perl)
Subject: Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_1078308364@rtfm.mit.edu>

Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
URL: http://tiny-tools.sourceforge.net/
Maintainer: Jari Aalto <jari.aalto@poboxes.com>

Announcement: "What Emacs lisp modules can help with programming Perl"

    Preface

        Emacs is your friend if you have to do anything comcerning software
        development: It offers plug-in modules, written in Emacs lisp
        (elisp) language, that makes all your programmings wishes come
        true. Please introduce yourself to Emacs and your programming era
        will get a new light.

    Where to find Emacs/XEmacs

        o   Unix:
            http://www.gnu.org/software/emacs/emacs.html
            http://www.xemacs.org/

        o   Unix Windows port (for Unix die-hards):
            install http://www.cygwin.com/  which includes native Emacs 21.x.
            XEmacs port is bundled in XEmacs setup.exe available from
            XEmacs site.

        o   Pure Native Windows port
            http://www.gnu.org/software/emacs/windows/ntemacs.html
            ftp://ftp.xemacs.org/pub/xemacs/windows/setup.exe

        o   More Emacs resources at
            http://tiny-tools.sourceforge.net/  => Emacs resource page

Emacs Perl Modules

    Cperl -- Perl programming mode

        ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl
        http://www.perl.com/CPAN-local/misc/emacs/cperl-mode/
        <ilya@math.ohio-state.edu>    Ilya Zakharevich

        CPerl is major mode for editing perl files. Forget the default
        `perl-mode' that comes with Emacs, this is much better. Comes
        standard in newest Emacs.

    TinyPerl -- Perl related utilities

        http://tiny-tools.sourceforge.net/

        If you ever wonder how to deal with Perl POD pages or how to find
        documentation from all perl manpages, this package is for you.
        Couple of keystrokes and all the documentaion is in your hands.

        o   Instant function help: See documentation of `shift', `pop'...
        o   Show Perl manual pages in *pod* buffer
        o   Grep through all Perl manpages (.pod)
        o   Follow POD references e.g. [perlre] to next pod with RETURN
        o   Coloured pod pages with `font-lock'
        o   Separate `tiperl-pod-view-mode' for jumping topics and pages
            forward and backward in *pod* buffer.

        o   Update `$VERSION' variable with YYYY.MMDD on save.
        o   Load source code into Emacs, like Devel::DProf.pm
        o   Prepare script (version numbering) and Upload it to PAUSE
        o   Generate autoload STUBS (Devel::SelfStubber) for you
            Perl Module (.pm)

    TinyIgrep -- Perl Code browsing and easy grepping

        [TinyIgrep is included in Tiny Tools Kit]

        To grep from all installed Perl modules, define database to
        TinyIgrep. There is example file emacs-rc-tinyigrep.el that shows
        how to set up dattabases for Perl5, Perl4 whatever you have
        installed

        TinyIgrep calls Igrep.el to to do the search, You can adjust
        recursive grep options, set search case sensitivity, add user grep
        options etc.

        You can find latest `igrep.el' module at
        <http://groups.google.com/groups?group=gnu.emacs.sources> The
        maintainer is Jefin Rodgers <kevinr@ihs.com>.

    TinyCompile -- To Browse grep results in Emacs *compile* buffer

        TinyCompile is a minor mode for *compile* buffer from where
        you can collapse unwanted lines or shorten file URLs:

            /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
            /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT

            -->

            cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
            file1:NNN: MATCHED TEXT
            file1:NNN: MATCHED TEXT

End



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

Date: 3 Mar 2004 00:56:57 -0800
From: Alexander.Farber@t-online.de (A. Farber)
Subject: Re: File::Temp: opening the temp. file in "r+" mode? Also "man in the middle"
Message-Id: <c9ccaf83.0403030056.38b4fc7f@posting.google.com>

Ben Morrow <usenet@morrow.me.uk> wrote in message news:<c22ka9$3en$2@wisteria.csv.warwick.ac.uk>...
> Alexander.Farber@t-online.de (A. Farber) wrote:
> > 
> > I'm working at a CGI-script which would receive a 20 MB
> > big file via HTTP-upload, then change few bytes in it,
> > then calculate an MD5 hash over a region of that file
> > and save that value into the file as well.

> If the $SEARCH and $REPLACE are the same length then you can run through
> the file and simply overwrite chunks that change with syswrite. If they
> are not then you have to make a copy.

Thank you, yes they are equal size. I haven't thought 
about just running syswrite. What I still don't know though, 
which buffer size to use while copying the uploaded file:

  ($fh, $filename) = tempfile(DIR => UPLOADDIR);

  while (<$upload>) {
      print $fh $_;
  }

- is bad choice, because it's a binary file.
And if I use sysread/syswrite, then what $buffer 
size should I use? Should I use PIPE_BUF?

  while (sysread $upload, $buffer, $buf_size) {
      die "syswrite failed: $!"
          unless length $buffer == syswrite $fh, $buffer;
  }


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

Date: Wed, 03 Mar 2004 06:15:26 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: local and my variables in a subroutine
Message-Id: <4045742c.12696624@news.erols.com>

Bob Walton <invalid-email@rochester.rr.com> wrote:

: Note, though, that it is not really good practice to use a lexical 
: declared with my() as if it were a package global variable

Says who?  This sounds like you're peddling a style choice as a programming
axiom.

: it might be considered misleading.

By whom?  What misapprehension could it cause?

In my own code, declaring a file-scoped lexical visibly identifies it as
something the external world doesn't need to know and shouldn't muck around
with.  Package variables are reserved for information that the external
world might need to know or change.



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

Date: Wed, 3 Mar 2004 16:45:49 +0800
From: "Franklin Lee" <pengtaoli@hotmail.com>
Subject: Re: local and my variables in a subroutine
Message-Id: <c24602$t5m@netnews.proxy.lucent.com>

You can move the defination before the function.




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

Date: 3 Mar 2004 09:21:48 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: local and my variables in a subroutine
Message-Id: <c2483c$9sr$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Franklin Lee:

> You can move the defination before the function.

?

You can also put salt into your coffee.

Before making postings in a newsgroup, you should read how to do it
properly. Your posting contained no information whatsoever. Read this
for instance:

    <http://www.newsreaders.com/guide/netiquette.html>

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: 03 Mar 2004 09:21:17 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Macros
Message-Id: <u91xoamgky.fsf@wcl-l.bham.ac.uk>

"chatiman" <chatiman@free.fr> writes:

> "Ben Morrow" <usenet@morrow.me.uk> a écrit dans le message de news:
> c22kr2$3en$4@wisteria.csv.warwick.ac.uk...
> 
> > > Or is there a way to access the caller's function local variables ?
> >
> > Why do you want to do this? There is almost certainly a better way.
> >
> Has you saw in my previous post, I'm trying to "localize" my application
> (ie support different languages). I took a look at Locale::Maketext but it
> seems
> to complex to use and require additionnal packages.
> 
> So I thought to write a simple module which will do what I want :
> 
> The idea is to have a text file for each language (or a simple hash) like:
> id1: the text associated to id1 with $variableA
> 
> And also I will have a function:
> 
> sub my_gettext {
>     my ($id) = @_
>     return eval "return \"$localized{$id}\"";
> }

Oh, no not again!  Seems hardly a week since we had two (yes two)
threads on this FAQ.

Don't use double quotes to do this.  Double qoutes are quite common in
natural language.

If you want to do this use the chop/here-doc approach (or the approach
given in the FAQ).

sub my_gettext {
     my ($id) = @_
     chop ( my $r = eval "<<_END_\n$localized{$id}\n_END_");
     $r;
}

I really wish the FAQ would include this answer - since it is the real
answer to the question.  Pretending it doesn't exist just means
people, when they come upon it, may not be warned how dangerous it is
(your internationalization config file could contain arbitrary Perl
code) and will loose trust in the honesty of the FAQ. 


> This would work when variable are not localized with "my" ...
> 
> But to be "cleaner" I would like it to work in anycases


> > However, if you must: PadWalker.
> >
> I'll look at it

Well String::Interpolate will do what you think you want but even I
who wrote it wouldn't really recommend it.  Indeed the ability to use
PadWalker is experimental and was only only really an exercise to see
if it's possible.  I do not consider it clean.

If you use String::Interpolate there are better ways.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 3 Mar 2004 00:24:33 -0800
From: himanshu@gdit.iiit.net (Himanshu Garg)
Subject: Re: Need help sending a password to ftp
Message-Id: <a46e54c7.0403030024.6f7c5db7@posting.google.com>

joez3@yahoo.com (joe) wrote in message news:<5619c20c.0403020723.19151189@posting.google.com>...
> I need to create a perl/expect script that will telnet into a system
> then bring up ftp on that system to transfer some files over there. I
> can get the telnet session open. I then start up ftp but that looks
> like it doesn't take my password. The script fails with:
> 331 Password required for moose .
> Password:
> 530 Login incorrect.
> Login failed.
> ftp> cd /tmp 
> 530 Please login with USER and PASS.
> 
> This is what my script looks like:
>  #!/usr /bin/expect
>  # Usage:  "hold HOST USER PASS".
>  # Action:  login to node HOST as USER.  Offer a shell prompt for
>  #     normal usage, and also print to the screen the word HELD
>  #     every five seconds, to exercise the connection periodically.
>  #     This is useful for testing and using WANs with short time-outs.
>  #     You can walk away from the keyboard, and never lose your
>  #     connection through a time-out.
>  # WARNING:  the security hazard of passing a password through the
>  #     command line makes this example only illustrative.  Modify to
>  #     a particular security situation as appropriate.
>  set hostname [lindex $argv 0]
>  set username [lindex $argv 1]
>  set password [lindex $argv 2]
>  set server [lindex $argv 3]
> 
>       # There's trouble if $username's prompt is not set to "...} ".
>       #     A more sophisticated manager knows how to look for
> different
>       #     prompts on different hosts.
>  set prompt_sequence "} "
> 
>  spawn telnet $hostname
> 
>  expect "login: "
>  send "$username\r"
>  expect "Password:"
>  send "$password\r"
>       # Some hosts don't inquire about TERM.  That's another
>       #     complexification to consider before widespread use
>       #     of this application is practical.
>       # Note use of global  ? pattern matching to parse "*"
>       #     as a wildcard.
>  expect -gl "TERM = (*)"
>  send "\r"
>  expect $prompt_sequence
>  send "cd /opt/SUNWsymon/base/bin \r"
>  expect $prompt_sequence
>  send "ftp $hostname \r"
>  expect "Name ($server:$username):"
>  send "$username \r"
>  expect -gl "331 Password required for*"
>  expect -gl "Password:*"
>  send "$password \r"
>  expect "230 User $username logged in."
>  expect "ftp>"
>  send "cd /tmp \r"
>  interact


Did you try Expect.pm. It also has a sample script that does ftp. You
might want to take a look at it.

Ofcourse you have the other alternatives of using readymade modules
mentioned in other replies.

++imanshu


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

Date: Wed,  3 Mar 2004 01:04:09 -0600
From: "yamini" <yamini_rajan@nospam.com>
Subject: passing arrays to function
Message-Id: <a4c98e61c9e99e37979ef69c85731481@localhost.talkaboutprogramming.com>

hi,
i can't able to pass more than one array to a function in this program

#usr/bin/perl
@a=qw(a b c d e f);
@b=qw(h i j k l);
get(\@a,\@b);
sub get()
{
my (@ag,@bg)=@_;

print@ag;
print "\n@bg\n";
}
what is the mistake i have done here?
can anyone help me in tracing the soln?



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

Date: Wed, 03 Mar 2004 07:22:15 GMT
From: Beable van Polasm <beable+unsenet@beable.com.invalid>
Subject: Re: passing arrays to function
Message-Id: <yzfzcqz97i.fsf@dingo.beable.com>

"yamini" <yamini_rajan@nospam.com> writes:

> hi,
> i can't able to pass more than one array to a function in this program
> 
> #usr/bin/perl
This is wrong, should be:

#!/usr/bin/perl

You have two lines missing here:

use strict;
use warnings;

> @a=qw(a b c d e f);
> @b=qw(h i j k l);

Both these arrays should have "my" in front of them.

> get(\@a,\@b);
> sub get()

You shouldn't have those parentheses there.

> {
> my (@ag,@bg)=@_;

You are passing in references to arrays, so this line should be:

  my ($ag_ref, $bg_ref) = @_;

> print@ag;
> print "\n@bg\n";

Because you are using array references, these lines should be:
print @$ag_ref;
print "\n@$bg_ref\n";

> }
> what is the mistake i have done here?
> can anyone help me in tracing the soln?

Here is the corrected program:

#!/usr/bin/perl

use strict;
use warnings;

my @a = qw(a b c d e f);
my @b = qw(h i j k l);

get(\@a, \@b);

sub get
{
    my ($ag_ref, $bg_ref)=@_;

    print "@$ag_ref\n@$bg_ref\n";
}

__END__



-- 
http://beable.org   


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

Date: 3 Mar 2004 07:24:45 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: passing arrays to function
Message-Id: <c2417t$fjn$1@nets3.rz.RWTH-Aachen.DE>

[ code slightly reformatted for the sake of readability ]

Also sprach yamini:

> i can't able to pass more than one array to a function in this program
> 
> #usr/bin/perl
> @a=qw(a b c d e f);
> @b=qw(h i j k l);
> get(\@a,\@b);
> sub get()
> {
>   my (@ag,@bg)=@_;
> 
>   print @ag;
>   print "\n@bg\n";
> }
> what is the mistake i have done here?
> can anyone help me in tracing the soln?

You already seem to know that you have to pass references. A reference
however is not an array, it is a scalar. Your 'get' function therefore
receives two scalars, both being references to arrays.

Furthermore, something like that

    my (@ag, @bg) = LIST;

will leave @bg empty since @ag will gobble up the complete LIST.

Finally, 'get' has a prototype that indicates to perl that you are not
going to pass any values to the function. Drop this as well:

    sub get {
	my ($ag, $bg) = @_;
	# turn references back into arrays
	my @ag = @$ag;
	my @bg = @$bg;
	...
    }

Or use a more suitable prototype:

    sub get (\@\@) {
	my ($ag, $bg) = @_;
	...
    }

    # and call it without references
    get(@a, @b);

With this prototype, perl will transform the two plain arrays and turn
them into references.

If you are going to use prototypes, the function definition must preceed
the function call. So either put the function definitions on top of your
program or add forward-declarations:

    sub get (\@\@);
    ...
    get(@a, @b);
    ...
    sub get (\@\@) {
	my ($ag, $bg) = @_;
	...
    }

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Wed, 3 Mar 2004 16:41:54 +0800
From: "Franklin Lee" <pengtaoli@hotmail.com>
Subject: Re: passing arrays to function
Message-Id: <c245op$t4l@netnews.proxy.lucent.com>

my @a,@b;

fun1(\@a, \@b);

sub fun1{
    my($a, $b)=@_;

    # @$a;
    # @$b;
}




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

Date: 2 Mar 2004 21:26:59 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Perl running on Windows and Berkeley DB
Message-Id: <40456ca3@news.victoria.tc.ca>

Bob Walton (invalid-email@rochester.rr.com) wrote:
: Researcher wrote:

: > I did everything I could to install Berkeley DB for perl running on a
: > windows system, I tryed unsuccessfully getting online help or reading
: > the README file but I only found help on installing it on a UNIX
: > machine. Can anybody help me?

: Hmmmm...If you have installed a recent version of ActiveState Perl on 
: your Windoze machine, the Berkeley Database package (DB_File) should 
: already be installed, and, in fact, be the default for dbmopen().  You 
: shouldn't have to do anything but use it.

BerkeleyDB is not the same as DB_File.  DB_File is an old interface that
provides access to just certain functions available in the database
software, and works with various databases (I think).  Berkeley DB is
specific to berkelely, and accesses "all" the functionality of what ever
version of berkeley db is installed.

--
Web Work Wanted, Perl Projects Programmed, Database Development Done.

I'm looking for telecommute projects. (Paying that is, various
arrangements possible.)


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

Date: 3 Mar 2004 01:37:33 -0800
From: michael@webactor.dk (michael vernersen)
Subject: Re: perl::api2 pdf problem...
Message-Id: <b1c145db.0403030137.1dc7349@posting.google.com>

"Michele Ouellet" <ouellmi@videotron.ca> wrote in message news:<At_0c.101433$QM4.1496595@weber.videotron.net>...
> > As to your problem, I'm not sure how much luck you're going to have.
> > PDF::API2 (not the perl::api2 you have in your subject) is not a core
> > module, so I doubt many people here have used it.
> 
> Probably true, therefore you would have better luck with the following
> newsgroup:
> 
> perl-text-pdf-modules@yahoogroups.com
> 
> Enjoy!
> 
> Michèle Ouellet.

  Hi Michele

  After read for one hour i found the solution....

  http://groups.yahoo.com/group/perl-text-pdf-modules/message/2067

  #!/usr/bin/perl

  use PDF::API2;

  my $temp = PDF::API2->open('Template.pdf');
  my $mypdf = PDF::API2->new();
  my $page1 = $mypdf->importpage($temp, 1);
  $mypdf->saveas('apitest.pdf');

  This works and i'm very glad fro your advice....

  Thanks , Michael.


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

Date: Wed, 03 Mar 2004 07:54:06 +0100
From: Hannes <remove_Hannes.Krueger@uibk.ac.at>
Subject: Re: process communication design (c++ <-> perl)
Message-Id: <40458131@sia.uibk.ac.at>


> How often do you need to update the screen? And what latency can you
> live with? If not too fast, I would put a counter in shared memory and
> increment it everytime shared memory was updated. You can have each
> process poll the counter every second, compare the current value in
> shared memory with the previous value fetched, and fetch the values in
> shared memory when the counter changes.
> 
> Are you using a locking mechanism to protect shared memory from
> concurrent access? Something like semaphores?
> 
> I used the above scheme very successfully, but didn't need really fast
> update rates. The screens were changing every 10-15 seconds or so, and
> a fraction of a second latency was OK.


Thanks for the answer...
Since this is some graphical application, the update rates should be as fast 
as possible. (The Perl-script is some sort of analysing tool, the c++ part 
shows simultaneously a openGL 3D view).

Hannes


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

Date: Wed, 03 Mar 2004 00:22:26 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Regex to replace unsafe chars?
Message-Id: <pan.2004.03.03.05.22.23.599857@remove.adelphia.net>

On Wed, 03 Mar 2004 02:10:28 +0100, Jaap Karssenberg wrote:

> On Wed, 03 Mar 2004 01:03:12 GMT Bryan Coon wrote:
> : I need to remove unsafe characters from a filename, and replace them
> : all with underscores.
> 
> maybe it would be better to define the save characters, say a filename
> should only contain letters, digits, '.' and '-' then you could do this:
> 
> 	$filename =~ s/[^\w\.\-]/_/g;

I'll go one better and direct the OP to a CERT page on exactly this idea -
as applied to untainting variables in CGI scripts ....

http://www.cert.org/tech_tips/cgi_metacharacters.html

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
Elevators smell different to midgets 




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

Date: Wed, 03 Mar 2004 10:33:21 +0100
From: Tomasz Judycki <tjudycki@tv.com.pl>
Subject: Socked not valid - how to check it?
Message-Id: <4045A661.C97589BD@tv.com.pl>

Hi all!

I've got a problem - probably easy to solve but I practically don't know Perl
nor modules so it's hard for me.

The problem concerns two processes communicating via sockets. I need to know
that one of them died already and there is no point in sending anything to it.

This is a script iris_s.pl acting as server :
===========================================
#!/usr/bin/perl

use IO::Socket;
use IO::Select;

# Start the RAD server
$server = new IO::Socket::INET(Listen => 10,
                               LocalPort => 2350,
                               Reuse => 1)
  or die "Could not establish a server\n";

print "Server started\n";

$client = $server->accept();
$message = <$client>;
push (@IrisReq, $client);
print "slepping for 10 seconds\n";
sleep 10;
$IrisPort = shift @IrisReq;
if ((@ready = IO::Select->new($IrisPort)->can_write(0))) {
  print "Can write\n";
} else {
  print "Can NOT write\n";
}
sleep 5;
$IrisPort->close;
===========================================

This is a script iris.pl that sends request to iris_s.pl and waits for an
answer but after 5 seconds finishes execution:

===========================================
#!/usr/bin/perl

#binmode(STDIN);
#binmode(STDOUT);
#binmode(STDERR);

use IO::Socket;
use IO::Select;

unless($sock = IO::Socket::INET->new("localhost:2350")) {
  print "NoRadErr\n";
}

$sock->autoflush(1);

$sel = IO::Select->new();
$sel->add($sock);

print $sock "Iris: Req \n";

print "Waiting for 5 seconds\n";

@ready = $sel->can_read(5);

if (@ready) {
  chomp($RexPort = <$sock>);
} else {
  print "RadTimeoutErr\n";
}

$sock->close;
$sel->remove($sock);
===========================================

Testing : start iris_s.pl and then iris.pl. Finally iris_s.pl will print 'Can
write'.

How can I check in iris_s.pl that iris.pl died already? Or: what should I do
in iris.pl to let iris_s.pl know that socked is closed?

Please be descriptive as  I'm far from being Perl expert.

Regards,

Tomasz Judycki

Textus Virtualis Sp. z o.o.
Szaserów 3
04-293 Warszawa
tel/fax (48 22) 879 82 00
http://www.tv.com.pl


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

Date: Wed, 03 Mar 2004 04:49:38 -0600
From: Ali-Reza Anghaie <ali@packetknife.com>
Subject: Re: Socked not valid - how to check it?
Message-Id: <LJidnQWxK9rfJdjdRVn-gw@speakeasy.net>

Tomasz Judycki <tjudycki@tv.com.pl> wrote:
> I've got a problem - probably easy to solve but I practically don't know Perl
> nor modules so it's hard for me.
> 
> The problem concerns two processes communicating via sockets. I need to know
> that one of them died already and there is no point in sending anything to it.
*snip*

Consider SO_KEEPALIVE.. problem is it's meant for connections that
last a little longer..

  $socket->sockopt(SO_KEEPALIVE, 1);


If they're on the same host you can check PIDs via written record
file or direct query. I doubt that's your end-state though..

Cheers, -Ali

--
Was I helpful?:  http://svcs.affero.net/rm.php?r=packetknife
--
Any sufficiently advanced technology is indistinguishable from
magic. -- Arthur C. Clarke


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

Date: Wed, 03 Mar 2004 00:12:19 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: use question
Message-Id: <pan.2004.03.03.05.12.17.382631@remove.adelphia.net>

On Tue, 02 Mar 2004 19:48:21 +0000, kj wrote:


> If I want all the symbols exported by default by a module, plus a
> few more, I find that the following works:
> 
> use Some_Module;
> use Some_Module qw(some extra symbols);
> 
> Is there a way to achieve the same results in one line?

Is there some reason why ....

use Some_Module qw(some extra symbols);

doesn't work for you?

Is this a specific module or one you created?

A little more information would be helpful :-)

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
Satellite Safety Tip #14:  If you see a bright streak in the sky 
coming at you, duck. 



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

Date: Wed, 03 Mar 2004 19:16:52 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: webservices
Message-Id: <4881562.lYQKc4rPMD@GMT-hosting-and-pickle-farming>

Michael Hill wrote:

> Does anyone know of a good example of a perl webservice?

LWP::Simple; print

gtoomey


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

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


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