[8676] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2293 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 10 17:07:15 1998

Date: Fri, 10 Apr 98 14:00:26 -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           Fri, 10 Apr 1998     Volume: 8 Number: 2293

Today's topics:
    Re: arrays in Format (Andrew M. Langmead)
    Re: can't copy gif file on NT? (Andrew M. Langmead)
    Re: Clunky Perl Prose (Mark-Jason Dominus)
        Details - Check if the URL is out there or not. <ben@wallroyds.demon.co.uk>
    Re: Details - Check if the URL is out there or not. <rootbeer@teleport.com>
    Re: Excessive (?) Memory Usage with Large Database <rootbeer@teleport.com>
        File download problem in IE4.0 bidyut@yahoo.com
    Re: File download problem in IE4.0 <rootbeer@teleport.com>
    Re: help for package problem (Mark-Jason Dominus)
    Re: HTTP server written in perl? <triche@tc.cornell.edu>
    Re: HTTP server written in perl? (Kevin Reid)
    Re: IPC::open2 and  $/ (sdm)
    Re: IPC::open2 and  $/ <danboo@negia.net>
    Re: Is it just me?  (error/bug? with "my") -- Interesti <cortez@tfn.com>
    Re: Is it just me?  (error/bug? with "my") -- Interesti <rootbeer@teleport.com>
    Re: Is it the code or is it the server? <rootbeer@teleport.com>
    Re: Is it the code or is it the server? <sanct@dlc.fi>
    Re: Is it the code or is it the server? <rootbeer@teleport.com>
    Re: Perl + UNIX login <rootbeer@teleport.com>
    Re: PERL SUBROUTINES.... <uri@sysarch.com>
    Re: problem printing long line to file <danboo@negia.net>
    Re: problem printing long line to file (Mark-Jason Dominus)
    Re: Sharing a constant between scripts (Andrew M. Langmead)
    Re: strange behaviour of s/// interpolation <rootbeer@teleport.com>
    Re: strange behaviour of s/// interpolation (Ilya Zakharevich)
    Re: Tail-like functionality (Kees Hendrikse)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Fri, 10 Apr 1998 19:18:52 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: arrays in Format
Message-Id: <Er7pnG.Mop@world.std.com>

kcohen@julius.ling.ohio-state.edu (Kevin B Cohen) writes:

>it's possible to get a format to print out a variable, or to print out
>the return value of a subroutine.  my question: is it possible to get
>a format to print out an array?

Besides the other suggestions on making formats at runtime, there are
some other things that you might want to do, depending on your
circumstances.

You might want to use an expression that takes the array, but returns
a scalar with the data contained in it:

@<<<<<<<<<<<<<<<<<<<<<<<<<
"@array"

or

@<<<<<<<<<<<<<<<<<<<<<<<<< 
pack 'A10' x @array, @array

this can be especially helpful with the multiline format directive:

@*
join "\n", @array

If you want to specify that that an array has overfilled its format directive,
you could put some marker like "..." if the number of elements are greater than
a certain number.

@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<@<<<
pack('A10' x @array,@array[0..6]), $#array > 6 ? '...' : ''

but sometimes it might be easier to put the array into a scalar variable before
before calling write, so you can use caret fields.

$scalar = pack 'A10' x @array, @array;
write;

# and later on ...

^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~
$scalar

You can also iterate through the elements of the array within the format.

@<<<<<<<<<<<  @<<<<<<<<<<<<<<
$array[$i=0], $array[$i++]
@<<<<<<<<<<<  @<<<<<<<<<<<<<<~~
$array[$i++],$array[$i++]
-- 
Andrew Langmead


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

Date: Fri, 10 Apr 1998 19:11:35 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: can't copy gif file on NT?
Message-Id: <Er7pBB.I2J@world.std.com>

"hsiwei yu" <yu.michael@epamail.epa.gov> writes:

>this script won't copy a gif file on NT (but OK on UNIX)

Have you seen the FAQ entry "How do I handle binary data correctly?"
<http://www.perl.com/CPAN-local/doc/manual/html/pod/perlfaq4/How
_do_I_handle_binary_data_cor.html>

It points out to you that on systems that handle text files and binary
files differently, you need to use the binmode() function on
filehandles handling binary data.

-- 
Andrew Langmead


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

Date: 10 Apr 1998 15:39:26 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Clunky Perl Prose
Message-Id: <6glshe$3vr$1@monet.op.net>

In article <slrn6isb67.kkf.mist@fangorn.cs.monash.edu.au>,
Michael Stillwell <mist@yoyo.cc.monash.edu.au> wrote:
>If there's "more than one way to do it", 
>what are the alternatives to these:
>
>  1. Creating a reference to a list or hash returned by a function.
>     @{$foo} = split(' ', $blah);
>     
>     my @bar = split(' ', $blah);
>     $foo = \@bar;

Perhaps you'll prefer
	$foo = [split(...)];

>  2. Creating a copy of an object.  I do it with "$copy =
>     eval(Dumper($self))" with Deepcopy set to one, but there's got to
>     be a better way.

That's a good question.  Are there any other questions?  :)

A recursive copier wouldn't be hard, but there isn't one built in.

Hmm, let me see:

	# call with one argument, a reference to the thing to be copied
	sub copy {
	  my $thing = shift;
          croak "Your ad here\n" if @_;
	  my $type = ref $thing;
	  return $thing unless $type;  # Don't copy scalars
	  if ($type eq LIST) {
	    [map {copy($_)} @$thing];
	  } elsif ($type eq HASH) {
	    {map {$_ => copy($thing->{$_})} keys %$thing};
	  } elsif ($type eq SCALAR || $type eq REF) {
	    my $copy = copy($$thing);
	    \$copy;
	  } else {  # Is this right for glob refs?
	    $thing;  # Can't really copy
	  }
	}

That should probably do it, unless you want to copy circular
structures; for that you need a helper function.  I'm sure you can fix
that up yourself.

I do hope I got it right; test carefully.  I never needed to do this
before; the deepest copy I've ever needed was accomplished by

	[map {[@$_]} @$aref]

(See <URL:http://www.plover.com/~mjd/perl/LOD/>.)

>  3. Removing some elements from a list.  I generally do something like

Oh, now you're into FAQ world, I believe.  

>     my $n = 0;
>     while ($n < @list) {
>       if (...) { # some expression involving $list[$n]
>         ...      # e.g. move $list[$n] somewhere
>	 splice(@list, $n, 1);
>       } else {
>         $n++;
>       }
>     }
>
>     But this is rather more complicated than the foreach
>     construction.


Rather.  

>     I suppose I could do something like
>     
>     @list = grep {
>       ...
>     } @list;
>     But it has an unusual syntax (I like my maps and greps to fit on one
>     line), the body requires some thinking about, and if the body is
>     large, it's hard to work out what list the grep is operating on.

Heh.  I hear that those canny FORTRAN guys have this problem all
figured out.  They have this thing called a subroutine, which lets you
put long, repeated code into a different part of the program file...

	@list = grep { is_desirable($_) } @list;

You could even cut it to

	@list = grep { is_desirable } @list;

by writing `is_desirable' to look at $_ if it was called without
arguments.  I suppose opinion will be divided about whether that is a
clever useful hack or a spotted abomination.

> Is it also less efficient than the while loop above?
>     (Because a copy of the list has to be built.)

You know the two rules of optimization?

	1. Don't do it.
	2. (Experts only) Don't do it yet.

This is exactly what those two rules are intended to cover.  I'm not
an expert, but I strongly suspect that your loop is usually slower.
When you splice an element out of an array, it has to move everything
else over to fill the gap.  If you splice a lot, you move a lot of
stuff over.  Also, in `grep' the iteration takes place in C, which is
faster. 

I didn't try it, so I'm not sure, but you really shouldn't be worrying
about the speed of microtwiddles like this.  If you have a speed
problem, there are three or four stages of investigation you need to
go through before you should start worrying about whether these petty
details matter; even then they usually don't.  I find your concern
about readability much more compelling.

Anyway, back to your original problem:  It may be that you're not
programming in a Perlish way, and that's the source of your real
trouble.  I imagined, for examlpe, that you have a list of things, and
you want to remove them, extracting them into another list, like this:

	# Get list of bad items...
	my @bad = grep { is_bad($_) } @list;
	# and remove them from the original list
        @list = grep { ! is_bad($_) } @list;

and perhaps you don't want to scan the list twice.

In this case the Perlish strategy is: Don't use a list.  A hash is
probably more appropriate.  For example, you might make the list items
hash keys, and let the hash value indicate goodness or badness or some
other status.  If you really want to separate the hashes, use:

	while ($key = each %hash) {
	  $bad{$key} = delete $hash{$key} if is_bad($key);
	}

In any event, it is easier to delete items out of the middle of a hash
than out of the middle of a list, because a hash hasn't any middle.


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

Date: Fri, 10 Apr 1998 20:01:50 +0100
From: "bjf" <ben@wallroyds.demon.co.uk>
Subject: Details - Check if the URL is out there or not.
Message-Id: <892234919.22710.0.nnrp-08.c2de5b4a@news.demon.co.uk>

>Please check out this helpful information on choosing good subject
>lines. It will be a big help to you in making it more likely that your
>requests will be answered.
>
>    http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post


I apologise. I'll try my best in the future :-) Is the subject above OK?

>
>> All I need the code to do is, to see if the URL is out there or not.
>
>Sounds as if you want to verify a URL. Just one, of a set of them? Maybe
>you want LWP.


Yes, just one URL. Not set of them. LWP - I've downloaded the module. Will
try to install it later.

>
>> But, this code doesn't work
>
>"Doesn't work" is a little vague. Does it give an error message? Does it
>give no output? Does it give the wrong output? Does it give too much
>output? Too little? Does it make smoke come out of the computer? Does it
>hang, dump core, or make the monitor jumpy? We need just a little more
>information.


Hehe ... I'm so sorry. I'm learning, ok! ... No, no error messages, ... It
did give me an output and it was uncorrected (The URL IS out there) ... When
the URL is something like 'yahoo.com/index.html' ... The output was 'The
file is NOT out there'. Which was wrong. See below ...

>
>> #!/usr/local/bin/perl
>
>When your code doesn't work, you should ask Perl to help you with the -w
>option. In fact, most people recomment using -w during all of the
>development phase, at least. Then perl will warn you if it sees anything
>suspicious happening...


Thanks for the great advice. I forgot about that, completely. Will use it in
all my new scripts.

>
>> $theurl = qw(http://www.yahoo.com/index.html);
>
>...like that. Don't use qw() in a scalar context! You probably wanted to
>use q() instead.


I've changed it to what you suggested ... And, something interesting
happened. When I changed it (From qw to q) ... The URL was
'http://yahoo.com/index.html' ... The output was 'The file is out there' ...
But, when the URL was something like 'http://ghiohdkaldg.com' .... The
output was the same ('The file is out there')??!!

>
>> if (PING $theurl) {
>
>Perl doesn't have a built-in PING function. And you can ping a machine,
>not a URL. I think you want to use LWP.


I will try to use it. The code below ... Someone gave me that code, ... Said
it will do the latrick with LWP ... I will try to install LWP later and see
if the code is OK or not.

>

>> sub PING
>>
>>     $_[0] =~ m!^(http):!;
>> }
>
>Hmmm. Well. No, I think that that code is not what you want.
>
>You can find LWP on CPAN. You can find the Llama book at any good
>bookstore. Hope this helps!
>


Llama book? What's it about? ... I've the Nutshell Perl book (You were
involved in it!) ... And, erm ... The CGI programming on the World Wide Web
book ... Couldn't find anything about detecting if the URL is out there or
not in these books. Or is there? Ie - Which functions I could use ...

You don't have to reply to this message, as I'll check out LWT later ...  If
I have any problems with it, I'll post a message with a better subject line
later!

Also, I've visited the Randal Schwartz Case website ... I was so shocked at
what Intel did to him ... It's really unfair, it's a multi-billion business!
What's the point?! ... I'd really appreciate it if anyone can tell me what's
going on at the CERTAINLY moment ... When bought two of his books ... I
thought, he must be a very rich person ... But I got it wrong. Couldn't
believe that Intel did something like that to someone as brilliant as him
who helps most of us in the newsgroups and all his brilliant scripts
(columns) on the site.

I wish him a really good future.

And, if you didn't go and sign .... Do it NOW! You can help him, ... Go to
 ...:   http://www.rahul.net/jeffrey/ovs/ ... And thank you very much!

Sorry about my bad English and spellings.

Best Regards

BJF.

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




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

Date: Fri, 10 Apr 1998 20:13:45 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: bjf <ben@wallroyds.demon.co.uk>
Subject: Re: Details - Check if the URL is out there or not.
Message-Id: <Pine.GSO.3.96.980410131137.19268J-100000@user2.teleport.com>

On Fri, 10 Apr 1998, bjf wrote:

> Is the subject above OK?

Yes, it's pretty good.

> Llama book? 

That's "Learning Perl". It's described in the perlbook manpage, along with
some other good ones. 

Cheers!

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



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

Date: Fri, 10 Apr 1998 20:06:18 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Tad Thurston <thurston@balrog.nssl.noaa.gov>
Subject: Re: Excessive (?) Memory Usage with Large Database
Message-Id: <Pine.GSO.3.96.980410125304.19268G-100000@user2.teleport.com>

On 10 Apr 1998, Tad Thurston wrote:

> for ($current_line = 1; $current_line <= $num_lines; $current_line++)
> {
>   chomp($current_line_check = (<DEM>));

Why the extra parens around <DEM>? (But that shouldn't be a problem.)

>   print "Error reading DEM file\n" if ($current_line_check !=
> 				       $current_line);

Hmmm... You're using the line you just read as a number. Is it, perhaps,
something like "17 some data blah blah blah"? It might be better to
extract just the number - but this may be sufficient for your needs. (Even
if the line has just the number, checking on it may prove useful.)

>   chomp($num_elevations = (<DEM>));
>   chomp($line_coord = (<DEM>));

You aren't checking for end-of-file here. Maybe that's not necessary for
your needs, but that can be a problem.

>   ($line_lon, $line_lat) = split(' ', $line_coord); 
>   
>   for ($j = 0; $j < $num_elevations; $j++)

You know that (all of) this would be faster with my() variables, right?

>   {
>     chomp($temp = (<DEM>));
>     push(@el, $temp); 
>   }
> }

You're going to make a list of all of those millions of elements? That's
where your memory is going! :-) 

If each of those elements is (for example) a small integer, you could make
this more memory efficient by using a tied array. If you implement it as
(say) a packed string, with two bytes per integer, you'll probably save a
lot of memory. Hope this helps! 

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



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

Date: Fri, 10 Apr 1998 14:54:00 -0600
From: bidyut@yahoo.com
Subject: File download problem in IE4.0
Message-Id: <6gltco$6at$1@nnrp1.dejanews.com>

Hi There,
I have a CGi script which sends the file to the client browser. Now the code
which i have written for this.

print "Content-type: application/$ext";
#where $ext is the extenxion of the file i.e. doc or pdf or xls.
open(FILE,$Filename);
open(STDOUT);
binmode FILE;
binmode STDOUT;
while(<FILE>){
print;
} ;
close(FILE);
close(STDOUT);

-----

Now this work fine with netscape 4.0 and IE3.02. But in IE4.0 it gives a
problem. HTML and TXt files don't have any problem. But when i open a doc or
Xls file, it says a registry problem. When i open a pdf file, it opens the
viewer, but doen't show the file.. instead a blank screen!!

any help for this,
thanks in advance
Bidyut

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Fri, 10 Apr 1998 20:31:04 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: bidyut@yahoo.com
Subject: Re: File download problem in IE4.0
Message-Id: <Pine.GSO.3.96.980410132332.19268M-100000@user2.teleport.com>

On Fri, 10 Apr 1998 bidyut@yahoo.com wrote:

> open(FILE,$Filename);

Even when your script is "just an example" (and perhaps especially in that
case!) you should _always_ check the return value after opening a file.

> open(STDOUT);

Two questions: What do you think this does? What does it actually do? :-)

> Now this work fine with netscape 4.0 and IE3.02. But in IE4.0 it gives a
> problem. 

If you're following the proper protocol but some browser or server doesn't
cooperate, then it's the other program's fault. If you're not following
the protocol, then it's your fault. If you aren't sure about the protocol,
you should read the protocol specification. If you've read it and you're
still not sure, you should ask in a newsgroup about the protocol.

Hope this helps!

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



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

Date: 10 Apr 1998 16:08:58 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: help for package problem
Message-Id: <6glu8q$49v$1@monet.op.net>

In article <352E4C09.D441FA8F@sqf.hp.com>,
Scott Finnie  <sfinnie@sqf.hp.com> wrote:
>If I try to invoke the method in the normal way, I get an error:
>
>  "Undefined subroutine &LinksetVerifier::isName called at
>LinksetVerifier.pm line 31, <P> chunk 342."
> 
> reportErr('invalId', $o->name) if (!isName($o->name));   # problem

That is not the normal way to invoke a method!

If you want a method, you have two choices.

	$something->method(arguments)

	method $something (arguments)

If you use one of these forms, perl starts looking in some appropriate
paackage depending on the value of $something, and if it doesn't find
the function in that package, it looks in that package's @ISA array
and does inheritance.

If you don't use one of these two forms, you're not making a method
call.  You're making an ordinary function call, and you don't get
inheritance.

The correct fix depends on what you really want to accomplish.

1. 

Perhaps you simply need to say, in LinkSetVerifier, that you want to
call the isName function in `Verifier'.  In that case, you do this:

	Verifier::isName($o->name);

or if you're sneaky you could import it:

	*isName = \&Verifier::isName; # Import function into this package
	isName($o->name); # Calls Verifier::isName

2. 

Perhaps you want isName to be a method call inherited from the
`Verifier' package.  In this case, you need to change isName so that
it can be called like this:

	$this->isName($o->name);

and then call it that way.




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

Date: Fri, 10 Apr 1998 16:16:17 -0400
From: "Tim Triche, Jr." <triche@tc.cornell.edu>
Subject: Re: HTTP server written in perl?
Message-Id: <352E7E11.4487@tc.cornell.edu>

Mcoe NT wrote:
> 
> Hello group,
> 
> Has anyone seen a HTTP server written only in perl?

I think I saw one in someone's .sig at one point...
 ...oh wait, that was a chat server.  Sorry.

-- 

    "...pi seconds is a nanocentury."

                            --Craig Berry


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

Date: Fri, 10 Apr 1998 16:39:10 -0400
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: HTTP server written in perl?
Message-Id: <1d7a30y.rgzn5t1ilch97N@slip166-72-108-34.ny.us.ibm.net>

Mcoe NT <root@mail.mcoe.k12.ca.us> wrote:

> Hello group,
> 
> Has anyone seen a HTTP server written only in perl?

#!perl -w

use HTTP::Daemon;
use HTTP::Status;

$WebDir = "Apps & Data:Web Shared Folder"; # set this appropriately
$| = 1;

$srv = new HTTP::Daemon(LocalPort => 80);

while ($con = $srv->accept) {
  $req = $con->get_request;
  if ($req) {
    $path = $WebDir . $req->url->path;
    $path =~ s!\/!:!g;
    setmsg($req->method, $path);
    if ($req->method eq "GET") {
      if (-d $path) {
        $con->send_file_response($path . "index.html");
      } else {
        $con->send_file_response($path);
      }
    } else {
      $con->send_error(RC_FORBIDDEN);
    }
  }
  $con = undef;
}

sub setmsg ($$) {
  my ($method, $file) = @_;
  printf "%-20s %-5s %s\n", scalar localtime, $method, $file;
}

__END__

-- 
  Kevin Reid.      |         Macintosh.
   "I'm me."       |      Think different.


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

Date: 10 Apr 1998 19:31:17 GMT
From: sdm@red.seas.upenn.edu (sdm)
Subject: Re: IPC::open2 and  $/
Message-Id: <6gls25$r8l$1@netnews.upenn.edu>

sdm (sdm@blue.seas.upenn.edu) wrote:
:   I have two scripts that communicate to each other using IPC::open2. 
: script1's output is unbuffered (undef $/), and script2's output
: is unbuffered. I've noticed that script2 does not stop under certain 
: conditions, and I was wondering if this was caused by the unbuffered 
: output, or totally unrelated. 

oops, I meant $|++, and $/. 

:   I've read the man page, and it mentions problems with sort, but I 
: thought this might be a bit different.

oh, and I am using the close writer then read reader trick thats in the 
camel book, so I'm not sure thats the problem.

:   On a related note, is there any way I can kill the script from within it
: if it is using too much cpu time? Certain times, it seems to be spinning 
: out of control with no end in sight. 

oh, so the right way to do this would be to set an alarm=some_seconds,
then have the sigalarm handler call die?

gosh, don't you love how the prospect of having usenet think you're a weenie
can make you fix all your bugs in less than 5 minutes? ;)

-steve
how to speak like a guru:
http://www.pobox.com/~sdm/unix.shtml



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

Date: Fri, 10 Apr 1998 15:22:18 -0400
From: Dan Boorstein <danboo@negia.net>
To: sdm <sdm@blue.seas.upenn.edu>
Subject: Re: IPC::open2 and  $/
Message-Id: <352E716A.39EB3E78@negia.net>

sdm wrote:
> 
>   I have two scripts that communicate to each other using IPC::open2.
> script1's output is unbuffered (undef $/), and script2's output
                                  ^^^^^^^^
that does not set output to unbuffered, it undefines the input record
separator which is usually "\n".

perhaps you want $|++ instead.

>   On a related note, is there any way I can kill the script from within it
> if it is using too much cpu time? Certain times, it seems to be spinning
> out of control with no end in sight.

you could try 'alarm' in conjunction with $SIG{ALRM} set as a reference
to a subroutine that calls exit.

hope this helps,

dan boorstein


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

Date: Fri, 10 Apr 1998 15:32:45 -0400
From: Frank Cortez <cortez@tfn.com>
To: Frank Cortez <cortez@tfn.com>
Subject: Re: Is it just me?  (error/bug? with "my") -- Interesting Twist
Message-Id: <352E73DD.1F45@tfn.com>

Okay, I found out what was causing the problem (reference below--
problem w/ 'my').  It was a combination of factors.  First off,
the crashes were actually caused by a bug w/ the version of
Apache I'm running.  The reason I thought it was the 'my' was
because I couldn't "see" the contents of the lexicals within
the debugger, and if they weren't defined, that would have been
a valid reason for the crashes I was seeing.  The Apache bug
doesn't actually require me to restart my machine-- I can just
restart Apache (that's how I found out it wasn't Perl).  In
any case, I found a temporary work-around, but I'd like to get
the scoop on whether or not I'm going about things the right
way...

When in the debugger, say I've "stepped" into a routine
called 'Routine', resulting in my being on the first line
of Routine, which reads:

my ($var) = @_;

Now, if I step past this line (say two lines, just to be
sure it's executed), I *should* be able to see the value in
$var using 'X var'-- shouldn't I?  Well, I can't.  However,
if I type '$tmp = $var', and then type 'X tmp', I can then
see the value in $var.  Am I doing something wrong?  I
assume if I needed to somehow explicitly qualify the scope
of *which* $var I wanted to see (and just how would I do
that, BTW?), the 'tmp' substitution wouldn't work.  But it
*does* work.  Does anybody know why?

TIA,
-Frank

On Wed, 8 Apr 1998, Frank Cortez wrote:

> I discovered that this problem sometimes
> "goes away" if I reboot my machine.

That's a bad sign!

> Could this somehow be related to a memory leak issue with a beta
> version of Apache I'm running?

Mmmmmaybe. If Perl is running low on memory, though, it shouldn't do
weird things like this. But if you can find a way to replicate the
problem, someone should be able to find the cause. Good luck!

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


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

Date: Fri, 10 Apr 1998 20:23:11 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Frank Cortez <cortez@tfn.com>
Subject: Re: Is it just me?  (error/bug? with "my") -- Interesting Twist
Message-Id: <Pine.GSO.3.96.980410132142.19268L-100000@user2.teleport.com>

On Fri, 10 Apr 1998, Frank Cortez wrote:

> When in the debugger, say I've "stepped" into a routine
> called 'Routine', resulting in my being on the first line
> of Routine, which reads:
> 
> my ($var) = @_;
> 
> Now, if I step past this line (say two lines, just to be
> sure it's executed), I *should* be able to see the value in
> $var using 'X var'-- shouldn't I?  Well, I can't.  

Are you using 5.004? You couldn't see my() vars from the debugger in some
earlier Perl versions, as I recall. Hope this helps! 

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



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

Date: Fri, 10 Apr 1998 20:10:39 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Aleksi Asikainen <sanct@dlc.fi>
Subject: Re: Is it the code or is it the server?
Message-Id: <Pine.GSO.3.96.980410131007.19268I-100000@user2.teleport.com>

On Fri, 10 Apr 1998, Aleksi Asikainen wrote:

> So, does the script need some kind of flushing 

Check the docs for the magical $| variable. Hope this helps!

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



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

Date: Fri, 10 Apr 1998 23:34:23 +0300
From: Aleksi Asikainen <sanct@dlc.fi>
Subject: Re: Is it the code or is it the server?
Message-Id: <352E824F.F6738296@dlc.fi>

> Check the docs for the magical $| variable. Hope this helps!

No, I've set 'the magical $| variable' to 1, but it does not change the
result.

And yes, the code really sends something, because it starts like this:

  print "Content-type: mime/html\n\n";
  print "<HTML><BODY BGCOLOR=\"#ABCABCAB">\n";

And I can't get even those! (Well... ok, I can get them, if the program
ends, but that's not what I have in my mind...)

Does perl send some kind of "flush everything" command when it exits the
code? And if so, what is that "flush everything" command?

-aleksi


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

Date: Fri, 10 Apr 1998 20:47:37 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Aleksi Asikainen <sanct@dlc.fi>
Subject: Re: Is it the code or is it the server?
Message-Id: <Pine.GSO.3.96.980410134250.19268P-100000@user2.teleport.com>

On Fri, 10 Apr 1998, Aleksi Asikainen wrote:

> > Check the docs for the magical $| variable. Hope this helps!
> 
> No, I've set 'the magical $| variable' to 1, but it does not change the
> result.

You do that with the proper filehandle selected, right? And before doing
output to that filehandle? (Just double-checking....) 

> And yes, the code really sends something, because it starts like this:
> 
>   print "Content-type: mime/html\n\n";
>   print "<HTML><BODY BGCOLOR=\"#ABCABCAB">\n";
> 
> And I can't get even those! (Well... ok, I can get them, if the program
> ends, but that's not what I have in my mind...)

Sounds like buffering, and $| should do that. Maybe your system has some
non-standard buffering, although that's not likely. (Are you using a
non-Unix system? An old version of Perl?) 

> Does perl send some kind of "flush everything" command when it exits the
> code? And if so, what is that "flush everything" command? 

In Perl, unlike in plumbing, one flush always flushes everything. :-)

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



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

Date: Fri, 10 Apr 1998 19:41:54 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: stephen@darwin.UCSC.EDU
Subject: Re: Perl + UNIX login
Message-Id: <Pine.GSO.3.96.980410123328.19268E-100000@user2.teleport.com>

On 10 Apr 1998 stephen@darwin.UCSC.EDU wrote:

> I have not been able to find out how to pass 'username' and 'password'
> to my Solaris system so as to allow users to execute several Perl
> scripts that I wish to install. 

Actually, there's nothing Perl-specific about this. That is, if your users
can execute programs written in FORTRAN or Lisp, they should be able to
execute Perl programs. Your system's docs should be able to help you with
this. 

And, although what you say is a bit ambiguous, I think you might be
wanting to make a set-id script. Hope this helps!

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



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

Date: 10 Apr 1998 13:13:51 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: PERL SUBROUTINES....
Message-Id: <x7emz5k3ao.fsf@sysarch.com>

>>>>> "TP" == Tom Phoenix <rootbeer@teleport.com> writes:

  TP> On Fri, 10 Apr 1998, Devjyoti Mookerjee wrote:
  >> Subject: PERL SUBROUTINES....

  >> Can you please tell me if there is any way a subroutine can be
  >> called directly from outside a script, as from the prompt, or as an
  >> URL?

  TP> There's no real way of invoking just a subroutine from a Perl
  TP> script and no other code. But you can write a script so that it
  TP> will call the subroutine of your choice, of course - in Perl, or
  TP> in pretty much any other language. Hope this helps!

there are indirect ways. you can parse the cammand line arguments given
to the script and call the desired sub. the arguments could be flags or
even the names of the sub if you use soft references.


also you could load the perl script/module and call it from the command
line using -e as in this example:

# foo.pl and foo.pm (linked for this test)

#!/usr/local/bin/perl

sub foo {
print "foo called\n" ;
}

sub bar {
print "bar called\n" ;
}

1 ;


perl -e 'require q(foo27.pl); &bar'
bar called
perl -Mfoo27 -e '&foo'
foo called


uri


-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire  ----  8 Years of Perl Experience, Available Immediately
uri@sysarch.com  ---------  Resume and Perl Example at http://www.sysarch.com
Use the Best Search Engine on the Net  --------  http://www.northernlight.com


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

Date: Fri, 10 Apr 1998 14:47:26 -0400
From: Dan Boorstein <danboo@negia.net>
To: Larry Rosler <lr@hpl.hp.com>
Subject: Re: problem printing long line to file
Message-Id: <352E693E.455B247D@negia.net>

Larry Rosler wrote:
>
> Usually when TMTOWTDI in Perl, there are tangible reasons for choosing
> one way over the other(s).  Can someone suggest why one would *ever*
> choose to use the HERE document style in preference to the one shown
> above, or to the concatenated strings discussed in the first paragraph?
> 
> All I can perceive is that the HERE delimiter can be made sufficiently
> elaborate to ensure that the syntax is correct.  What value was added to
> Perl by the HERE approach?  (Not that it could be removed now, of
> course; the question is why should one choose to use it in new code.)

i, for one, find the clarity of the heredoc to be it's primary advantage.
especially in function and subroutine calls:

$amount = 50/3;
printf <<EOTEXT, $amount;
hello sir,

  you owe \$%.2f. please
pay as a soon as possible.
EOTEXT

or:

$amount = sprintf "%.2f", 50/3;
($message = <<'EOTEXT') =~ s/_dollars_/$amount/;
hello sir,

  you owe $_dollars_. please
pay as a soon as possible.
EOTEXT
print $message;

i like having the text as an afterthought almost. i think of it like an
embedded __END__ of sorts. the 'qq' versions of these would place the
interesting bits at the end of a long line or several lines below the
beginning of the statement.

of course as you mentioned, TMTOWTDI. these could easily be changed
to pre-assign the text into a scalar and we're back to the point of
lesser advantage.

cheers,

dan boorstein


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

Date: 10 Apr 1998 15:49:11 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: problem printing long line to file
Message-Id: <6glt3n$42f$1@monet.op.net>

In article <352E5BF0.A0D773E5@hpl.hp.com>, Larry Rosler  <lr@hpl.hp.com> wrote:
>What value was added to Perl by the HERE approach?  (Not that it
>could be removed now, of course; the question is why should one
>choose to use it in new code.)

Here documents were in Perl before the extended quotation syntax
qq{...}.  So the question of what was added by putting them in misses
what happened.  Perhaps if qq{} has been in from the beginning, here
documents would not be there too, but qq{} is a very recent addition.

The other reason to have them, of course, is that here documents are
present in all shells, and Perl has them to make shell programmers
happy.



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

Date: Fri, 10 Apr 1998 20:08:09 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Sharing a constant between scripts
Message-Id: <Er7rxL.HwK@world.std.com>

Robert Goheen <rsgoheen@pobox.com> writes:

>Sounds good.  But how would I apply this to an array or hash that I
>wanted to use across several scripts?

The constant pragma accepts a list as an argument.

use constant LIST => qw(foo bar baz);

but lists don't get inlined the way scalars do.

>Actually, on a nit-picky point too, is there any way to use a constant
>as defined above within double quotes, and have Perl substitute the
>value of the constant?

Since constants defined by the constant module are functions, you have
to use the method described in the FAQs entry "How do I expand
function calls in a string?"

print <<EOF;

bla bla bla.
<A HREF="mailto:@{[AUTHOR]}>mail me</A>
bla bla bla.

EOF

Or you could use something like Text::Template instead of double quotes.
-- 
Andrew Langmead


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

Date: Fri, 10 Apr 1998 19:50:06 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Christian Wetzel <cnwetzel@linguistik.uni-erlangen.de>
Subject: Re: strange behaviour of s/// interpolation
Message-Id: <Pine.GSO.3.96.980410124343.19268F-100000@user2.teleport.com>

On Fri, 10 Apr 1998, Christian Wetzel wrote:

> 1) Why is there no difference between zero /e's and one /e?

There is a difference, but a single scalar doesn't show it. That is,
s/foo/$bar/ is the same as s/foo/ "$bar" /e - the code produces the same
thing as the "string". But s/foo/$bar$baz/ would need to be s/foo/ $bar .
$baz /e , right?

> 2) Why can't I force s/// to take $replace, interpolate it,
>    yielding the same as s/$search/$2 $1/? (case A)

Interpolation is always a shortcut for an expression. If it won't do what
you need, you can use the equivalent expression. When you interpolate a
dollar sign into an expression, that's just a dollar sign. If you wish for
Perl to think of it as part of some code, you'll need to do something
fancier, like /ee. Or by using soft references: ${$1}, for example. 

Hope this helps!

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



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

Date: 10 Apr 1998 20:36:46 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: strange behaviour of s/// interpolation
Message-Id: <6glvsu$ccj$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Tom Phoenix 
<rootbeer@teleport.com>],
who wrote in article <Pine.GSO.3.96.980410124343.19268F-100000@user2.teleport.com>:
> On Fri, 10 Apr 1998, Christian Wetzel wrote:
> 
> > 1) Why is there no difference between zero /e's and one /e?
> 
> There is a difference, but a single scalar doesn't show it. That is,
> s/foo/$bar/ is the same as s/foo/ "$bar" /e - the code produces the same
> thing as the "string". But s/foo/$bar$baz/ would need to be s/foo/ $bar .
> $baz /e , right?

I found the following very helpful in understanding what means what:

  Consider

     s/RE/REPLACE/e

  as the basic operation, and 

     s/RE/REPLACE/

  as a shortcut to

     s/RE/"REPLACE"/e;

  (with a notable difference that you do not need to backwack
  doublequotes in REPLACE).

Ilya


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

Date: Fri, 10 Apr 1998 19:23:08 GMT
From: kees@echelon.nl (Kees Hendrikse)
Subject: Re: Tail-like functionality
Message-Id: <Er7puK.3DF@echelon.nl>

In <352DAFF6.43F51B61@coos.dartmouth.edu> Ronald J Kimball writes:

> Umm, no it doesn't  $#output will always be the index of the last element in
> @output.  It has nothing to do with the lengths of the elements in @output.
> 
> Whereever did you get this odd idea?

Guess what... I *did* need the following code to make it work. That's
where the odd idea came from :-)

> >         $length = 73;
> >         $tail = 10;
> >         push @output, $line;
> >         shift @output while @output > $length * $tail;
> 
> Are you sure you're not pushing the characters onto @output individually?

There's one typo in the code above; "$line" should read "@line" and @line 
happens to be a list of individual characters. 

-- 
Kees Hendrikse                               | email:     kees@echelon.nl
                                             | web:        www.echelon.nl
ECHELON consultancy and software development | phone: +31 (0)53 48 36 585
PO Box 545, 7500AM Enschede, The Netherlands | fax:   +31 (0)53 43 37 415


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

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

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