[9427] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3024 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 30 14:07:41 1998

Date: Tue, 30 Jun 98 10:58:42 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 30 Jun 1998     Volume: 8 Number: 3024

Today's topics:
    Re: Subroutine Variables (Gabor)
    Re: Subroutine Variables <rra@stanford.edu>
    Re: Subroutine Variables <quednauf@nortel.co.uk>
    Re: Subroutine Variables <metcher@spider.herston.uq.edu.au>
    Re: Subroutine Variables (Larry Rosler)
    Re: Subroutine Variables (M.J.T. Guy)
        substr() vs. $array[$i] (John Siracusa)
    Re: substr() vs. $array[$i] <bowlin@sirius.com>
        sybperl compilation - HEEELP <arturcz@hiperon.paa.gov.pl>
    Re: SybPerl Text/Image routine <wsanchez@tribune.com>
        system vs. backtick? (was: $CHILD_ERROR problems when c kevin@meso.com
        Telnet script <claudio@server.kefa.it>
    Re: Telnet script <rootbeer@teleport.com>
    Re: Testing perl knowledge (Michael Stillwell)
        Thanks! ppith@my-dejanews.com
    Re: The return status from system()? (M.J.T. Guy)
        Timeouts on receiving from a socket (Paul)
    Re: Timeouts on receiving from a socket (Ronald J Kimball)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 28 Jun 1998 12:53:41 GMT
From: gabor@vmunix.com (Gabor)
Subject: Re: Subroutine Variables
Message-Id: <slrn6pcf9o.6n.gabor@localhost.vmunix.com>

In comp.lang.perl.misc, Tom Christiansen <tchrist@mox.perl.com> wrote :
#  [courtesy cc of this posting sent to cited author via email]
# 
# In comp.lang.perl.misc, 
#     mikep@rt66.com (mikep) writes:
# :Doesn't the local function declare or at least limit an instance of a
# :variable to its current scope?
# 
# Not in the way most people expect.  local() doesn't create a local
# variable you know.  It's just called that to confuse you. :-(

Is there a historical reason for this?  I know it confused me at first.
'local' should be what 'my' is, in name I mean.


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

Date: 28 Jun 1998 06:06:55 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Subroutine Variables
Message-Id: <m3lnqhwu8g.fsf@windlord.Stanford.EDU>

Gabor <gabor@vmunix.com> writes:
> In comp.lang.perl.misc, Tom Christiansen <tchrist@mox.perl.com> wrote:

>> Not in the way most people expect.  local() doesn't create a local
>> variable you know.  It's just called that to confuse you. :-(

> Is there a historical reason for this?  I know it confused me at first.
> 'local' should be what 'my' is, in name I mean.

Yup.  local was around in Perl 4 days, and my was a Perl 5 invention.
local localizes the value of a variable to the current call stack, which
means that the name *does* make some sense for its function.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Sun, 28 Jun 1998 14:15:56 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: Subroutine Variables
Message-Id: <3596420C.568C11AE@nortel.co.uk>

Gabor wrote:
> 
> In comp.lang.perl.misc, Tom Christiansen <tchrist@mox.perl.com> wrote :
> #  [courtesy cc of this posting sent to cited author via email]
> #
> # In comp.lang.perl.misc,
> #     mikep@rt66.com (mikep) writes:
> # :Doesn't the local function declare or at least limit an instance of a
> # :variable to its current scope?
> #
> # Not in the way most people expect.  local() doesn't create a local
> # variable you know.  It's just called that to confuse you. :-(
> 
> Is there a historical reason for this?  I know it confused me at first.
> 'local' should be what 'my' is, in name I mean.

A pointless argument, but I don't think so :) 'my' is a very pictorial way to
say that the variable indeed belomgs to the current block, and to no one else.
local sounds a lot more open, and indeed just modifies a global variable to play
a 'local' role for a while.

-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: Mon, 29 Jun 1998 11:01:11 +1000
From: Jaime Metcher <metcher@spider.herston.uq.edu.au>
Subject: Re: Subroutine Variables
Message-Id: <3596E757.2A74BB0E@spider.herston.uq.edu.au>

Are you doing this:

# only foo is lexically scoped
my $foo, $bar, $baz;

when you should be doing this:

# all three are lexically scoped
my ($foo, $bar, $baz);

?

-- 
Jaime Metcher

Alex Svetlev wrote:
> 
> I have a subroutine with variables that I declare with "my". Each time I
> call this subroutine, the variables still have the values they did in
> the previous call. How can I clear them out? Nothing seems to be
> working. Not local, my, or undef. This doesn't seem like a complex
> thing, but I'm stumped.
> 
> Thanks in advance.
> - Alex


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

Date: Sun, 28 Jun 1998 18:50:54 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Subroutine Variables
Message-Id: <MPG.100092d67c51c7c39896ff@nntp.hpl.hp.com>

In article <3596E757.2A74BB0E@spider.herston.uq.edu.au> on Mon, 29 Jun 
1998 11:01:11 +1000, Jaime Metcher <metcher@spider.herston.uq.edu.au> 
says...
> Are you doing this:
> 
> # only foo is lexically scoped
> my $foo, $bar, $baz;
> 
> when you should be doing this:
> 
> # all three are lexically scoped
> my ($foo, $bar, $baz);
> 
> ?

use strict;

would warn about this common (derived from C?) error. 

-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 29 Jun 1998 10:00:51 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Subroutine Variables
Message-Id: <6n7okj$j9r$1@pegasus.csx.cam.ac.uk>

Jaime Metcher  <metcher@spider.herston.uq.edu.au> wrote:
>Are you doing this:
>
># only foo is lexically scoped
>my $foo, $bar, $baz;
>
>when you should be doing this:
>
># all three are lexically scoped
>my ($foo, $bar, $baz);

If so, he isn't using either -w or "use strict;".


Mike Guy


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

Date: 30 Jun 1998 15:34:04 GMT
From: macintsh@cs.bu.edu (John Siracusa)
Subject: substr() vs. $array[$i]
Message-Id: <6nb0hc$837$1@news1.bu.edu>

Say I have an arbitrary string: $data.  I want to process each
byte of that string.  For various lengths, which is more
efficient:

1. @bytes = split('', $data);
   for(...) { # Do stuff to $bytes[$i] }

2. for(...) { # Do stuff to substr($data, $i, 1) }

Obviously the substr() method saves memory, especially when
$data is very large.  But at what point does the memory saving
become dominated by (what I assume to be) the speed penalty of
substr() vs. array indexing?  (I'm looking for philosophy
here, not benchmarking numbers ;)  Any time I find myself doing
split or join with '' as the first argument, I immediately
think substr(), but in this case I'm not sure it's the best
solution...

-----------------+----------------------------------------
  John Siracusa  | If you only have a hammer, you tend to
 macintsh@bu.edu | see every problem as a nail. -- Maslow




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

Date: Tue, 30 Jun 1998 08:47:45 -0700
From: Jim Bowlin <bowlin@sirius.com>
To: John Siracusa <macintsh@cs.bu.edu>
Subject: Re: substr() vs. $array[$i]
Message-Id: <359908A1.9AF77CBD@sirius.com>

John Siracusa wrote:
> 
> Say I have an arbitrary string: $data.  I want to process each
> byte of that string.  For various lengths, which is more
> efficient:
> 
> 1. @bytes = split('', $data);
>    for(...) { # Do stuff to $bytes[$i] }
> 
> 2. for(...) { # Do stuff to substr($data, $i, 1) }
> 
> Obviously the substr() method saves memory, especially when
> $data is very large.  But at what point does the memory saving
> become dominated by (what I assume to be) the speed penalty of
> substr() vs. array indexing?  (I'm looking for philosophy
> here, not benchmarking numbers ;)  Any time I find myself doing
> split or join with '' as the first argument, I immediately
> think substr(), but in this case I'm not sure it's the best
> solution...

IMHO the Perl philosophy is to use Benchmark.

-- Jim Bowlin


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

Date: 30 Jun 1998 10:44:38 GMT
From: Artur Czechowski <arturcz@hiperon.paa.gov.pl>
Subject: sybperl compilation - HEEELP
Message-Id: <supersede.6nafgm$ti2$2@hiperon.paa.gov.pl>

Hello
I try to compile sybperl 2.07 from CPAN. And I still got the same error:

gcc -L/usr/local/lib -rdynamic -o perl -O2 ./perlmain.o  /usr/lib/perl5/i586-linux/5.00404/CORE/libperl.a /usr/lib/perl5/i586-linux/5.00404/auto/DynaLoader/DynaLoader.a /home/arturcz/SQL/sybperl-2.07/blib/arch/auto/Sybase/CTlib/CTlib.a `cat ./blib/arch/auto/Sybase/extralibs.all` -lndbm -lgdbm -ldb -ldl -lm -lc
gcc: Internal compiler error: program ld got fatal signal 11

when I do make test.

I dont think that is hardware dependent, because in the same time I compile
two version of kernel and everything looks OK.

OS: Linux Redhat 4.2, kernel 2.0.30

[arturcz@hiperon sybperl-2.07]$ perl -v

This is perl, version 5.004_04 built for i586-linux

Have You got any suggestion what I should to do?

Help, please
	Artur


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

Date: Sun, 28 Jun 1998 14:28:31 -0400
From: William Sanchez <wsanchez@tribune.com>
Subject: Re: SybPerl Text/Image routine
Message-Id: <35968B4C.8C8D7D15@tribune.com>

Thought someone else might have a problem with this routine.  This is
Michael Peppler's
response to the post on the comp.databases.sybase group.
-w

#!/usr/local/bin/perl -w

use strict;
use Sybase::DBlib;
require 'sybutil.pl';

my $file = shift;   # filename on the command line

my $dbh = new Sybase::DBlib user, pwd, server; ### change to suite your
site!

open(IN, $file) || die "Can't open $file: $!";

undef $/;
my $data = <IN>;
close(IN);

my $id = $dbh->sql("insert image_table(name, data) values('$file', 'okay')

                    select \@\@identity");
$dbh->dbcmd("select data from image_table where id = $id->[0]->[0]");
$dbh->dbsqlexec;
$dbh->dbresults;
$dbh->dbnextrow;

$dbh->dbwritetext('image_table.data', $dbh, 1, $data, TRUE);

# It should now be in there...

exit(0);

__END__

I've not really tested this, but it should work...

Michael
--
Michael Peppler         -||-  Data Migrations Inc.
mpeppler@datamig.com    -||-  http://www.mbay.net/~mpeppler
Int. Sybase User Group  -||-  http://www.isug.com

William Sanchez wrote:

> Has anyone been succesful with the sybperl image/text routine?
> I've tried to insert an image(JPG) into the database using the SybPerl
> man page example o but have not been able to acomplish this.
>
> Can someone provide me with a snippet of code where this routine is
> being used?
>
> Thank You,
> William





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

Date: Mon, 29 Jun 1998 19:44:46 GMT
From: kevin@meso.com
Subject: system vs. backtick? (was: $CHILD_ERROR problems when called by cron)
Message-Id: <6n8qre$rp2$1@nnrp1.dejanews.com>



Addendum to previous message:  If I use the system function instead
of the backtick, I get "correct" results.

I guess I don't understand the difference between using the system
command and the backtick operator in this case. According to
Programming Perl, p. 134, "$? is the status returned by the last pipe
close, backtick command, or system operator."  So it seems that
the backtick or the system function should work in the same way.

I've looked in Learning Perl and Programming Perl but don't really
catch the distinction between "system" and ``; could someone
help me out?

Thanks, Kevin

In article <6n8aij$7u4$1@nnrp1.dejanews.com>,
  ktyle@my-dejanews.com wrote:

>
> Hi all,
>
> Consider the following short script:
>
> #!/usr/bin/perl
> print "About to test ps command\n";
> `/bin/ps p 26155`;
> print "Status of ps command is $?\n";
> `/bin/ps p 8888`;
> print "Status of ps command is $?\n";
> `/bin/echo "Hello"`;
> print "Status of echo command is $?\n";
>
> In this case, process 26155 actually exists, while 8888 does not.
> If I run this interactively, I get return status values of
> 0, 256, and 0.  But, if I run this from cron, I get -1 for all
> return values.  This is perl, version 5.004_04 built for i386-linux,
> running on Red Hat Linux 5.1 (kernel 2.0.34).
>
> Curiously, if I use a c shell script in cron that calls the perl
> script, I get the "0,256,0" return values; using a bash shell
> script yields the "-1,-1,-1" results.
>
> Additionally, on another machine (This is perl, version 5.003 with EMBED
>         built under linux at Dec  4 1996 20:40:11
>         + suidperl security patch), running RH Linux 4.1 (2.0.27),
>         I get the "correct" values of 0,256,0.
>
> Can anyone help me understand why I am getting the -1 values
> in the above situations?  By the way, my $PATH variable is slightly
> different depending on what shell I'm running in cron, but /bin and
> /usr/bin are always present.
>
> Thanks,
>
> Kevin Tyle
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum
>


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Mon, 29 Jun 1998 13:07:36 +0200
From: "Claudio Pizzillo" <claudio@server.kefa.it>
Subject: Telnet script
Message-Id: <6n7rq8$7sh$1@news.IT.net>

If someone have a perlscript to telnet into port 79 to show users
please e-mail to claudio@server.kefa.it




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

Date: Mon, 29 Jun 1998 20:45:30 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Telnet script
Message-Id: <Pine.GSO.3.96.980629134515.28620D-100000@user2.teleport.com>

On Mon, 29 Jun 1998, Claudio Pizzillo wrote:

> If someone have a perlscript to telnet into port 79 to show users
> please e-mail to claudio@server.kefa.it

If you're wishing merely to _find_ (as opposed to write) programs,
this newsgroup may not be the best resource for you. There are many
freeware and shareware archives which you can find by searching Yahoo
or a similar service. Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 30 Jun 1998 02:46:07 GMT
From: mist@yoyo.cc.monash.edu.au (Michael Stillwell)
Subject: Re: Testing perl knowledge
Message-Id: <slrn6pgkbe.2ci.mist@fangorn.cs.monash.edu.au>

On 24 Jun 1998 03:36:16 GMT, John Stanley <stanley@skyking.OCE.ORST.EDU> wrote:
: In article <pudge-2306982254300001@dynamic448.ply.adelphia.net>,
: Chris Nandor <pudge@pobox.com> wrote:
: >I am a Certified Perl Engineer (CPE).  I sent e-mail to a guy who
: >certified me.  I also certified myself.
: 
: You should be careful with this. Many states assign special legal status
: to the title "engineer". 

Has this come about recently?

    Since _engineer_ became a title of prestige in America, it has
    been assumed by a wide spectrum of charlatans.  For a number
    of years the _Engineering News-Record_, the organ of the
    legitimate engineers, used to devote a column every week to
    uninvited invaders of the craft, some so fantastic that it was
    constrained to reproduce their business cards photographically
    to convince its readers that it was not spoofing.  A favorite
    exhibit was a bedding manufacturer who first became a
    _mattress engineer_ and then promoted himself to the lofty
    dignity of _sleep engineer_. No doubt he would have called
    himself a _morphician_ if he had thought of it.  A tractor
    driver advertised for a job as a _caterpillar engineer_.  A
    beautician burst out as an _appearance engineer_.

    		-- H.L. Mencken, _The American Language_, "American
		   and English"
				   
Michael

-- 
 .. ABSOLUT .SIG. ..
 .. Michael Stillwell ..
 .. mist@yoyo.cc.monash.edu.au ..
 .. http://yoyo.cc.monash.edu.au/~mist/ ..


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

Date: Mon, 29 Jun 1998 22:43:09 GMT
From: ppith@my-dejanews.com
Subject: Thanks!
Message-Id: <6n959t$abd$1@nnrp1.dejanews.com>

Thanks for the suggestion about using WRAP=HARD instead of WRAP=VIRTUAL Tom
Christiansen!  I still can't limit user input to 80 characters, but it
should be okay since that was something I was trying out.  I could chop
off data after 80 characters, but I don't think my users of the CGI script
would appreciate that so I will have to look for a HTML solution later.

I did look at Perl's text wrapping module, and I decided it would be easier
to use Tom's solution since new lines were embedded into text which I could
store in one variable and get it out of a hash table later(I love Perl).

Thanks for all your help everyone.

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: 29 Jun 1998 13:01:52 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: The return status from system()?
Message-Id: <6n8380$ql2$1@pegasus.csx.cam.ac.uk>

Martin Gregory  <mgregory@asc.sps.mot.com> wrote:
>
>A few days ago I posted a question about the return status from
>system() depending on the various things that can happen to the called
>program.
>
>There has been some off-line discussion about this, and my conclusion
>is that despite what perldoc & Blue Camel say, the only thing you can
>safely conclude is that if system() returns a non-zero, then something
>'abnormal' happened.  
>
>You can't say *with certainty* anything about whether a core was dumped,
>a signal was received or any of those good things that you might want
>to know.  

You need to distinguish the two cases of whether the shell is invoked
or not.   (You can always tell that / force that for yourself.)
If the shell is not invoked, you can get all this information from $?.

>There appear to be counter-examples to all the documentation that I
>have read, or examples of where the documentation is misleading at
>best.

I think the documentation is complete and accurate (and not _too_ bad
for clarity) for the case where the shell is not invoked.

The documentation is essentially non-existent for the case when the
shell is invoked.    Here is part of what I wrote in the offline
thread:

================================================================
To recap this thread, the return value from system() when the shell is
invoked involves several stages:

a)   the command returns some 16 bit wait status.   The values for this
     are standard and defined in the wait(2) man page and in the Perl
     documentation

b)   The shell converts this 16 bit wait status to an 8 bit exit status
     and calls exit() with it.    This is the step which might not
     be the same on all platforms, but the rules seem to be

     If the child terminated with signal s:    128 + s
     If the child exited with exit value e:       e

c)   Perl waits for the shell and returns its wait status.   This will
     be the shell's exit status shifted up 8 places.   In particular,
     if the child did not receive a signal, this wait status will be
     the same as the child's original wait status.

( There are of course extra cases, such as when the *shell* gets a signal,
  or when the shell does not call the command at all because of syntax
  or other errors.    These are left as an exercise for the reader.
)
================================================================

So you can get all the information, albeit in a different format,
*except* you lose the bit which says whether or not a signal caused
a core dump.

But it does need better documentation.


Mike Guy


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

Date: Sun, 28 Jun 1998 19:28:05 GMT
From: paul@cytech.net (Paul)
Subject: Timeouts on receiving from a socket
Message-Id: <35969804.102702259@nntp.bestweb.net>

I wrote a program that connects to a remote machine, sends a little
data, and waits for a response. However, if no response comes back,
the socket stays open and the program sits doing nothing. Is there any
way to force a timeout on receiving data from a socket? I've tried
using read(), recv(), while (<SOCK>) (which of course wouldn't work),
I've read section 8 of the FAQ, tried using Comm.pl, tried using
setsockopt using the SO_RCVTIMEO flag.

Is there any simple way to say "send this to the socket. If nothing
comes back within 5 seconds, exit."?

Regards,

Paul.


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

Date: Sun, 28 Jun 1998 15:42:51 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Timeouts on receiving from a socket
Message-Id: <1dbcbl6.1fonc067bcimxN@bay2-429.quincy.ziplink.net>

Paul <paul@cytech.net> wrote:

> Is there any simple way to say "send this to the socket. If nothing
> comes back within 5 seconds, exit."?

Four-argument select, as found in perlfunc.  (Or the module
implementation, IO::Select.)

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 3024
**************************************

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