[29600] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 844 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 12 18:09:44 2007

Date: Wed, 12 Sep 2007 15:09:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 12 Sep 2007     Volume: 11 Number: 844

Today's topics:
    Re: Can't use an undefined value as an ARRAY reference  <dummy@example.com>
    Re: Commented braces <bik.mido@tiscalinet.it>
        Free guitars  nutsbreaker3@gmail.com
    Re: Free guitars <rspwsownthebede@yahoo.com>
    Re: Go Here to win a free guitar <fitzjarrell@cox.net>
    Re: Go Here to win a free guitar <zwsdotcom@gmail.com>
        Help with compiling Math::GMP on AIX 5.3 <btna@terra.com>
    Re: Help with compiling Math::GMP on AIX 5.3  usenet@DavidFilmer.com
    Re: Help with compiling Math::GMP on AIX 5.3 <btna@terra.com>
    Re: Help with compiling Math::GMP on AIX 5.3 <benoit.lefebvre@gmail.com>
    Re: Help with compiling Math::GMP on AIX 5.3  usenet@DavidFilmer.com
    Re: Help with compiling Math::GMP on AIX 5.3  usenet@DavidFilmer.com
    Re: Help with compiling Math::GMP on AIX 5.3  usenet@DavidFilmer.com
    Re: Help with compiling Math::GMP on AIX 5.3 <ben@morrow.me.uk>
    Re: Help with compiling Math::GMP on AIX 5.3 <btna@terra.com>
        passing variable to sub - $_='SendMessage' <steven.stone4@btopenworld.com>
    Re: passing variable to sub - $_='SendMessage' <ben@morrow.me.uk>
    Re: passing variable to sub - $_='SendMessage' <steven.stone4@btopenworld.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 12 Sep 2007 16:10:03 GMT
From: "John W. Krahn" <dummy@example.com>
Subject: Re: Can't use an undefined value as an ARRAY reference at search.cgi line 139.
Message-Id: <vbUFi.35023$Pd4.10783@edtnps82>

Paul Lalli wrote:
> On Sep 11, 5:37 pm, "John W. Krahn" <du...@example.com> wrote:
>> JimJx wrote:
>>
>>> I have what seems to me to be a strange problem....
>>> I have the script below:
>>> <code>
>>> if ($type eq 'alpha') {
>>> $query = sprintf (
>>>                 "SELECT name, address, city, phone
>>>                 FROM valley
>>>                                    where name like '$search%'
>>>                 ORDER BY name LIMIT %d,%d",
>>>                 $start - 1,         # number of records to skip
>>>                 $per_page + 1);     # number of records to select
>>>         } elsif  ($type eq '') {
>>> $query = sprintf (
>>>                 "SELECT name, address, city, phone
>>>                 FROM valley
>>>                                    where keywords like '%$search%'
>>>                 ORDER BY name LIMIT %d,%d",
>>>                 $start - 1,         # number of records to skip
>>>                 $per_page + 1);     # number of records to select
>>> }
>>> my $tbl_ref = $dbh->selectall_arrayref ($query);
>>> [ SNIP ]
>>> </code>
>>> It works great.
>> Are you sure that that "works great"?
>>
>> You have variable interpolation inside sprintf() format strings
> 
> Nothing about Perl prevents that.  There's no reason to think that
> wouldn't "work great"
> 
>> and you are using '%' without properly escaping it.  
> 
> Yes, but if the character following the % isn't a valid format
> specifier, it prints out as a % literal anyway:
> 
> printf "%d, %'\n", 5;   #prints  5, %'

And a warning message:

$ perl -Mwarnings -Mstrict -e "my \$x = q[aa]; printf qq[variable '%\$x%' five 
%d seven %d\n], 5, 7"
Invalid conversion in printf: "%a" at -e line 1.
Invalid conversion in printf: "%'" at -e line 1.
variable '%aa%' five 5 seven 7


And if it is valid then you get uninitialized values at the end of the list:

$ perl -Mwarnings -Mstrict -e "my \$x = q[dd]; printf qq[variable '%\$x%' five 
%d seven %d\n], 5, 7"
Invalid conversion in printf: "%'" at -e line 1.
Use of uninitialized value in printf at -e line 1.
variable '5d%' five 7 seven 0


> In short, there's nothing "wrong" with that part of the OP's code.  It
> could be made to look better, as you suggest, but there's nothing
> about it that suggests it doesn't work.



John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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

Date: Wed, 12 Sep 2007 22:34:34 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Commented braces
Message-Id: <j8jge350o7b055r42a4o1sc1blpdpsqf58@4ax.com>

On Wed, 12 Sep 2007 07:13:29 -0700, Paul Lalli <mritty@gmail.com>
wrote:

>`perldoc perlre` explains this just fine, IMO:

I wasn't suggesting that it doesn't. It's a little piece of info that
may just elude someone's attention and intuition.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Wed, 12 Sep 2007 20:17:43 -0000
From:  nutsbreaker3@gmail.com
Subject: Free guitars
Message-Id: <1189628263.196219.13780@r34g2000hsd.googlegroups.com>

Win a free guitar today!!!!

http://freeguitars.blogspot.com/



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

Date: Wed, 12 Sep 2007 15:51:59 -0500
From: "the Bede" <rspwsownthebede@yahoo.com>
Subject: Re: Free guitars
Message-Id: <EjYFi.83841$pu2.75186@bignews1.bellsouth.net>


<nutsbreaker3@gmail.com> wrote in message
news:1189628263.196219.13780@r34g2000hsd.googlegroups.com...
> Win a free guitar today!!!!
>
> http://freeguitars.blogspot.com/
>
woohoo, more spyware!!!!!!!!!!!!!




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

Date: Wed, 12 Sep 2007 11:20:27 -0700
From:  "fitzjarrell@cox.net" <fitzjarrell@cox.net>
Subject: Re: Go Here to win a free guitar
Message-Id: <1189621227.295110.18850@r29g2000hsg.googlegroups.com>

On Sep 11, 7:28 pm, larwe <zwsdot...@gmail.com> wrote:
> On Sep 11, 5:22 pm, joel garry <joel-ga...@home.com> wrote:
>
> > > that references a blogspot URL. They are all spam. Every last one.
> > > Without exception.
>
> > Freeman's).  There are so exceptions!
>
> This is like saying that there are honest online businesses and/or
> customers in Nigeria. While it might be possible to find one, it's a
> statistically insignificant number.

Prove it.  I want numbers.


David Fitzjarrell



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

Date: Wed, 12 Sep 2007 11:23:34 -0700
From:  larwe <zwsdotcom@gmail.com>
Subject: Re: Go Here to win a free guitar
Message-Id: <1189621414.391162.132430@r34g2000hsd.googlegroups.com>

On Sep 12, 2:20 pm, "fitzjarr...@cox.net" <fitzjarr...@cox.net> wrote:

> > This is like saying that there are honest online businesses and/or
> > customers in Nigeria. While it might be possible to find one, it's a
> > statistically insignificant number.
>
> Prove it.  I want numbers.

Sure! Based on the statistics I've collected to date (thousands, if
not millions of data points), there are zero honest online business in
Nigeria.



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

Date: Wed, 12 Sep 2007 09:18:03 -0700
From:  btna <btna@terra.com>
Subject: Help with compiling Math::GMP on AIX 5.3
Message-Id: <1189613883.180684.193860@w3g2000hsg.googlegroups.com>

Hello All,

I am not sure what I am missing but I think it must be something
simple. I am trying to install Net::SSH::Perl and it requires
Math::GMP which I have downloaded and when trying to install I get the
following errors:

(Note:  I have successfully downloaded and installed GMP following the
standard instruction as and I have added the -L/usr/local/lib to the
LIBS in the Makefile.PL

Any help will be appreciated it!!

Thanks

BTNA

Math-GMP-2.04> perl Makefile.PL

Writing Makefile for Math::GMP

Math-GMP-2.04> make

        /usr/bin/perl -e 'use ExtUtils::Mksymlists;  Mksymlists("NAME"
=> "Math::GMP", "DL_FUNCS" => {  }, "FUNCLIST" => [], "DL_VARS" =>
[]);'
        cc_r -c    -D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE -
qmaxmem=16384 -qnoansialias -DUSE_NATIVE_DLOPEN -DNEED_PTHREAD_INIT -
q32 -D_LARGE_FILES -qlonglong -O    -DVERSION=\"2.04\"  -DXS_VERSION=
\"2.04\"  "-I/usr/opt/perl5/lib/5.8.2/aix-thread-multi/CORE"   GMP.c
Running Mkbootstrap for Math::GMP ()
        chmod 644 GMP.bs
        rm -f blib/arch/auto/Math/GMP/GMP.so
        LD_RUN_PATH="" ld  -bhalt:4 -bM:SRE -bI:/usr/opt/perl5/lib/
5.8.2/aix-thread-multi/CORE/perl.exp -bE:GMP.exp -bnoentry -lpthreads -
lc_r GMP.o  -o blib/arch/auto/Math/GMP/GMP.so   -L/usr/local/lib -lgmp
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_init
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_sqrt
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_tstbit
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_init_set
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_fac_ui
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_ior
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_xor
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_and
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_fib_ui
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_gcd
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_pow_ui
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_jacobi
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_cmp
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_mod
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_tdiv_qr
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_fdiv_q
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_mul
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_sub
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_add
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_fdiv_r_2exp
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_fdiv_r
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_powm
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_fdiv_q_2exp
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_mul_2exp
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_get_si
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_add_ui
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_get_ui
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_sizeinbase
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_get_str
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_clear
ld: 0711-317 ERROR: Undefined symbol: .__gmpz_init_set_str
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more
information.
make: 1254-004 The error code from the last command is 8.


Stop.



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

Date: Wed, 12 Sep 2007 18:06:43 -0000
From:  usenet@DavidFilmer.com
Subject: Re: Help with compiling Math::GMP on AIX 5.3
Message-Id: <1189620403.305703.57940@19g2000hsx.googlegroups.com>

On Sep 12, 9:18 am, btna <b...@terra.com> wrote:
> [problems installing Math::GMP]

I had this same problem (also AIX 5.3). I was able to build Math::GMP
after I copied /usr/local/include/gmp.h to the directory (top level)
where I was building Math::GMP.


--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)



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

Date: Wed, 12 Sep 2007 12:00:48 -0700
From:  btna <btna@terra.com>
Subject: Re: Help with compiling Math::GMP on AIX 5.3
Message-Id: <1189623648.055814.35520@w3g2000hsg.googlegroups.com>

On Sep 12, 2:06 pm, use...@DavidFilmer.com wrote:
> On Sep 12, 9:18 am, btna <b...@terra.com> wrote:
>
> > [problems installing Math::GMP]
>
> I had this same problem (also AIX 5.3). I was able to build Math::GMP
> after I copied /usr/local/include/gmp.h to the directory (top level)
> where I was building Math::GMP.
>
> --
> The best way to get a good answer is to ask a good question.
> David Filmer (http://DavidFilmer.com)

David,

Thank you . I copied the gmp.h to the directory where I was building
it . It has the following:

COPYING.LIB   GMP.exp_old   MANIFEST      blib          t
Changes       GMP.o         Makefile      gmp.h         typemap
GMP.bs        GMP.xs        Makefile.PL   lib
GMP.c         INSTALL       Makefile.old  libgmp.la
GMP.exp       LICENSE       README        pm_to_blib

I still have the same errors. Is this the directory you are talking
about?

Thanks for your response.

BTNA



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

Date: Wed, 12 Sep 2007 12:02:53 -0700
From:  Benoit Lefebvre <benoit.lefebvre@gmail.com>
Subject: Re: Help with compiling Math::GMP on AIX 5.3
Message-Id: <1189623773.865028.217820@50g2000hsm.googlegroups.com>

I'm having some problems too compiling Math::GMP.. (Required by a
requirement of Net::SSH::Perl)

I have no gmp.h in my system.

Anyone have an idea in what package it is ?

Thanks,
  --Ben



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

Date: Wed, 12 Sep 2007 19:12:46 -0000
From:  usenet@DavidFilmer.com
Subject: Re: Help with compiling Math::GMP on AIX 5.3
Message-Id: <1189624366.430709.268670@o80g2000hse.googlegroups.com>

On Sep 12, 12:00 pm, btna <b...@terra.com> wrote:
> I still have the same errors. Is this the directory you are talking
> about?

Yes.  OK, verify that you have this in your Makefile.PL (with the -
lgmp flag):

   'LIBS' => ['-L/usr/local/lib -lgmp'],

What is your $CFLAGS?  I used this:

   export CFLAGS="-g -O2 -mcpu=powerpc"

Also, /usr/vacpp/bin is in your $PATH, right?



--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)



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

Date: Wed, 12 Sep 2007 19:14:37 -0000
From:  usenet@DavidFilmer.com
Subject: Re: Help with compiling Math::GMP on AIX 5.3
Message-Id: <1189624477.612888.300400@22g2000hsm.googlegroups.com>

On Sep 12, 12:02 pm, Benoit Lefebvre <benoit.lefeb...@gmail.com>
wrote:
> I have no gmp.h in my system.

You must build GMP before you can install Math::GMP.

http://www.swox.com/gmp/


--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)



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

Date: Wed, 12 Sep 2007 19:14:53 -0000
From:  usenet@DavidFilmer.com
Subject: Re: Help with compiling Math::GMP on AIX 5.3
Message-Id: <1189624493.755286.273270@r29g2000hsg.googlegroups.com>

On Sep 12, 12:02 pm, Benoit Lefebvre <benoit.lefeb...@gmail.com>
wrote:
> I have no gmp.h in my system.

You must build GMP before you can install Math::GMP.

http://www.swox.com/gmp/


--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)



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

Date: Wed, 12 Sep 2007 20:20:46 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Help with compiling Math::GMP on AIX 5.3
Message-Id: <epqlr4-nl1.ln1@osiris.mauzo.dyndns.org>


Quoth btna <btna@terra.com>:
> On Sep 12, 2:06 pm, use...@DavidFilmer.com wrote:
> > On Sep 12, 9:18 am, btna <b...@terra.com> wrote:
> >
> > > [problems installing Math::GMP]
> >
> > I had this same problem (also AIX 5.3). I was able to build Math::GMP
> > after I copied /usr/local/include/gmp.h to the directory (top level)
> > where I was building Math::GMP.
> 
> Thank you . I copied the gmp.h to the directory where I was building
> it . It has the following:
> 
> COPYING.LIB   GMP.exp_old   MANIFEST      blib          t
> Changes       GMP.o         Makefile      gmp.h         typemap
> GMP.bs        GMP.xs        Makefile.PL   lib
> GMP.c         INSTALL       Makefile.old  libgmp.la
> GMP.exp       LICENSE       README        pm_to_blib
> 
> I still have the same errors. Is this the directory you are talking
> about?

Have you cleaned up the old GMP.c/GMP.o (uh, and probably GMP.exp/GMP.bs
as well, since this is AIX) from when you built before (make clean, or
simply re-extract from the tarball)? It sounds like the problem is that
the C compiler was picking up a different gmp.h from somewhere else, but
simply putting the correct header where the compiler will find it won't
make the makefile rebuild things...

Ben



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

Date: Wed, 12 Sep 2007 13:43:09 -0700
From:  btna <btna@terra.com>
Subject: Re: Help with compiling Math::GMP on AIX 5.3
Message-Id: <1189629789.476176.4270@50g2000hsm.googlegroups.com>

On Sep 12, 3:20 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth btna <b...@terra.com>:
>
>
>
>
>
> > On Sep 12, 2:06 pm, use...@DavidFilmer.com wrote:
> > > On Sep 12, 9:18 am, btna <b...@terra.com> wrote:
>
> > > > [problems installing Math::GMP]
>
> > > I had this same problem (also AIX 5.3). I was able to build Math::GMP
> > > after I copied /usr/local/include/gmp.h to the directory (top level)
> > > where I was building Math::GMP.
>
> > Thank you . I copied the gmp.h to the directory where I was building
> > it . It has the following:
>
> > COPYING.LIB   GMP.exp_old   MANIFEST      blib          t
> > Changes       GMP.o         Makefile      gmp.h         typemap
> > GMP.bs        GMP.xs        Makefile.PL   lib
> > GMP.c         INSTALL       Makefile.old  libgmp.la
> > GMP.exp       LICENSE       README        pm_to_blib
>
> > I still have the same errors. Is this the directory you are talking
> > about?
>
> Have you cleaned up the old GMP.c/GMP.o (uh, and probably GMP.exp/GMP.bs
> as well, since this is AIX) from when you built before (make clean, or
> simply re-extract from the tarball)? It sounds like the problem is that
> the C compiler was picking up a different gmp.h from somewhere else, but
> simply putting the correct header where the compiler will find it won't
> make the makefile rebuild things...
>
> Ben- Hide quoted text -
>
> - Show quoted text -

Thanks for the responses but no luck yet. I have the -L/usr/local/lib
and I have used the CFLAGS as David posted them. I still get the same
errors. I do a "make clean" before I start again.

I am not sure what I am missing.

BTNA



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

Date: Wed, 12 Sep 2007 13:39:14 -0700
From:  steve <steven.stone4@btopenworld.com>
Subject: passing variable to sub - $_='SendMessage'
Message-Id: <1189629554.142924.323960@o80g2000hse.googlegroups.com>

I have two routines, send tcp packet and receive tcp packet.
Rx packet is a Win32:GUI application.

Rx packet passes the packet contents to a subroutine to process the
contents, except the contents once they get to the sub is always
'SendMessage'???

if I put the subroutine in the main part things are OK with using
$buf.

any help would be great

Routines......

Rx-------------------------------
my $readable_handles = new IO::Select();
$readable_handles->add($main_sock);
	while (1) {
		Win32::GUI::DoEvents();
		( my $new_readable) = IO::Select->select($readable_handles, undef,
undef, 0);

		foreach my $sock (@$new_readable) {
			if ($sock == $main_sock) {
				my $new_sock = $sock->accept();
				$readable_handles->add($new_sock);
			} else {
				# It is an ordinary client socket, ready for reading.
				my $buf = <$sock>;
				if ($buf) {
					print "buf - $buf\n"; <<<<<<<<<--------here is correct contents
					RxMsg($buf);
				} else {
					# Client closed socket. We do the same here, and remove
					# it from the readable_handles list
					$readable_handles->remove($sock);
					close($sock);
				}
			}
		}
  }
}
sub RxMsg {
	print $_ . " here...\r\n";<<<<<<----------- here is 'SendMessage'
   my @actions = split(/,/, $_);
   print $actions[0] . " there...\r\n";
	switch ($actions[0]) {
    	case 1 {defined(my $win = $Win32::GUI::Loft::window{Rx_Window})
or return(1);
			$win->RxTextfield->Append("action 1\r\n");
			chomp($actions[1]);
			$win->RxTextfield->Append("$actions[1]\r\n");
            open ACTION, "< $actions[1]" or die "cant open file : $!";
            while (my $line = <ACTION> ) {
				$win->RxTextfield->Append("$line\r\n");
           }
        }
        case 2 {defined(my $win =
$Win32::GUI::Loft::window{Rx_Window}) or return(1);
			$win->RxTextfield->Append("action 2\r\n");
        }
        case 3 {defined(my $win =
$Win32::GUI::Loft::window{Rx_Window}) or return(1);
			$win->RxTextfield->Append("action 3\r\n");
 			chomp($actions[1]);
			$win->RxTextfield->Append("$actions[1]\r\n");
            open ACTION, "< $actions[1]" or die "cant open file : $!";
            while (my $line = <ACTION> ) {
				$win->RxTextfield->Append("$line\r\n");
            }
       }
        else {defined(my $win = $Win32::GUI::Loft::window{Rx_Window})
or return(1);
			$win->RxTextfield->Append("action unknown\r\n");
        }
    }
	return(1);
}



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

Date: Wed, 12 Sep 2007 22:02:00 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: passing variable to sub - $_='SendMessage'
Message-Id: <8n0mr4-o32.ln1@osiris.mauzo.dyndns.org>


Quoth steve <steven.stone4@btopenworld.com>:
> I have two routines, send tcp packet and receive tcp packet.

The usual term in the Perl world for what you are calling 'routines' is
'programs' or 'scripts'. It's not terribly important, it just took me a
minute to work out what you meant.

> Rx packet is a Win32:GUI application.

One of the important skills in debugging a program is to reduce it to
the smallest example which still shows the problem. It is considered a
courtesy to do this *before* posting to Usenet, so people can see your
actual problem and not a whole lot of irrelevant code. In this case your
problem can be reduced to

    my $buf = 'foo';
    print "buf - $buf\n";
    RxMsg($buf);

    sub RxMsg {
        print "\$_ - $_\n";
    }

which instead of producing the output

    buf - foo
    $_ - foo

as you would have expected, produces

    buf - foo
    $_ -

instead. Your problem is that subroutine arguments are not passed in $_,
they are passed in @_. So if you replace RxMsg above with

    sub RxMsg {
        print "\$_[0] - $_[0]\n";
    }

it will behave as you expect. FWIW, it's usually better to use 'warn'
than 'print' for diagnostic messages, as they go to STDERR and tell you
where they came from.

Some more general comments on your code follow.

> my $readable_handles = new IO::Select();
> $readable_handles->add($main_sock);
> 	while (1) {

Sort out your indentation. It makes a huge difference to how
comprehensible code is.

<snip stuff that's OK>

> sub RxMsg {
> 	print $_ . " here...\r\n";<<<<<<----------- here is 'SendMessage'

Variables will interpolate into strings, removing '.' operators which
just get in the way.

There is no need to print "\r\n" with messages to the user.

    print "$_ here...\n";

>    my @actions = split(/,/, $_);
>    print $actions[0] . " there...\r\n";
> 	switch ($actions[0]) {

Huh? This is not Perl as I know it... are you using Switch.pm? I would
recommend against it. It can do veeery strange things on occasion.

<snip>

>             open ACTION, "< $actions[1]" or die "cant open file : $!";

It's better to use lexical filehandle (filehandles in variables) than
global barewords, for the same reasons as its better to use local than
global variables. It's safer to use the three-arg form of open. It's
probably better to say what you were trying to open if it fails.

    open my $ACTION, '<', $actions[1]
        or die "can't open '$actions[1]': $!";

>             while (my $line = <ACTION> ) {
> 				$win->RxTextfield->Append("$line\r\n");
>            }

You don't really need to do multiple appends here. Something like

    $win->RxTextfield->Append(join "\r\n", <$ACTION>, '');

is simpler.

>         case 2 {defined(my $win =
> $Win32::GUI::Loft::window{Rx_Window}) or return(1);

This piece appears in all the cases. Move it outside the switch (or the
if/elsif/else I would recommend you replace it with).

Ben



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

Date: Wed, 12 Sep 2007 15:02:15 -0700
From:  steve <steven.stone4@btopenworld.com>
Subject: Re: passing variable to sub - $_='SendMessage'
Message-Id: <1189634535.035680.150760@19g2000hsx.googlegroups.com>

On Sep 12, 10:02 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth steve <steven.sto...@btopenworld.com>:
>
> > I have two routines, send tcp packet and receive tcp packet.
>
> The usual term in the Perl world for what you are calling 'routines' is
> 'programs' or 'scripts'. It's not terribly important, it just took me a
> minute to work out what you meant.
>
> > Rx packet is a Win32:GUI application.
>
> One of the important skills in debugging a program is to reduce it to
> the smallest example which still shows the problem. It is considered a
> courtesy to do this *before* posting to Usenet, so people can see your
> actual problem and not a whole lot of irrelevant code. In this case your
> problem can be reduced to
>
>     my $buf = 'foo';
>     print "buf - $buf\n";
>     RxMsg($buf);
>
>     sub RxMsg {
>         print "\$_ - $_\n";
>     }
>
> which instead of producing the output
>
>     buf - foo
>     $_ - foo
>
> as you would have expected, produces
>
>     buf - foo
>     $_ -
>
> instead. Your problem is that subroutine arguments are not passed in $_,
> they are passed in @_. So if you replace RxMsg above with
>
>     sub RxMsg {
>         print "\$_[0] - $_[0]\n";
>     }
>
> it will behave as you expect. FWIW, it's usually better to use 'warn'
> than 'print' for diagnostic messages, as they go to STDERR and tell you
> where they came from.
>
> Some more general comments on your code follow.
>
> > my $readable_handles = new IO::Select();
> > $readable_handles->add($main_sock);
> >    while (1) {
>
> Sort out your indentation. It makes a huge difference to how
> comprehensible code is.
>
> <snip stuff that's OK>
>
> > sub RxMsg {
> >    print $_ . " here...\r\n";<<<<<<----------- here is 'SendMessage'
>
> Variables will interpolate into strings, removing '.' operators which
> just get in the way.
>
> There is no need to print "\r\n" with messages to the user.
>
>     print "$_ here...\n";
>
> >    my @actions = split(/,/, $_);
> >    print $actions[0] . " there...\r\n";
> >    switch ($actions[0]) {
>
> Huh? This is not Perl as I know it... are you using Switch.pm? I would
> recommend against it. It can do veeery strange things on occasion.
>
> <snip>
>
> >             open ACTION, "< $actions[1]" or die "cant open file : $!";
>
> It's better to use lexical filehandle (filehandles in variables) than
> global barewords, for the same reasons as its better to use local than
> global variables. It's safer to use the three-arg form of open. It's
> probably better to say what you were trying to open if it fails.
>
>     open my $ACTION, '<', $actions[1]
>         or die "can't open '$actions[1]': $!";
>
> >             while (my $line = <ACTION> ) {
> >                            $win->RxTextfield->Append("$line\r\n");
> >            }
>
> You don't really need to do multiple appends here. Something like
>
>     $win->RxTextfield->Append(join "\r\n", <$ACTION>, '');
>
> is simpler.
>
> >         case 2 {defined(my $win =
> > $Win32::GUI::Loft::window{Rx_Window}) or return(1);
>
> This piece appears in all the cases. Move it outside the switch (or the
> if/elsif/else I would recommend you replace it with).
>
> Ben

Hi Ben,

Many thanks for fast response, I think the $_ / @_ was a 'cant see
wood for the trees' - should have seen that my self.

Your right about reducing problem to min code to help the helpers, I
would have if I'd under stood the issue :-(

Yep, use Switch;  working for this case and will replace it if things
go awry with if/elsif/else.

think I got all your points except the ->Append / join one, dont see
how it can be used to replace the 3 appends
case 3 {
   $win->RxTextfield->Append("action 3\r\n");
   chomp($actions[1]);
   $win->RxTextfield->Append("$actions[1]\r\n");
   open my $ACTION, '<', $actions[1] or die "cant open '$actions[1]' :
$!";
   while (my $line = <$ACTION> ) {
      $win->RxTextfield->Append("$line\r\n");
   }
}

but that ok got most of your very useful help

many thanks again

steve



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

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 V11 Issue 844
**************************************


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