[7324] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 949 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 29 19:07:17 1997

Date: Fri, 29 Aug 97 16:00:22 -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, 29 Aug 1997     Volume: 8 Number: 949

Today's topics:
     Re: A Complex Regex Needed (Terry Michael Fletcher - PCD ~)
     Re: Bizarre result with regex in -i -pe <rootbeer@teleport.com>
     Re: Crash in Perl for Win32 5.003_07 (and older version <rootbeer@teleport.com>
     Re: find command with perl <rootbeer@teleport.com>
     Re: gethostbyaddr or some such... <rootbeer@teleport.com>
     Re: having a Perl script time out <friedman@uci.edu>
     Re: Help - Displaying text files!!! (John Stanley)
     Re: Help - Displaying text files!!! <rootbeer@teleport.com>
     Re: Help Capturing Error Messages From sendmail <rootbeer@teleport.com>
     How can execute system executable on NT? <mike.schleif@aquila.com>
     Re: HTML --> Perl conversion <rootbeer@teleport.com>
     Re: I have to ASK <rootbeer@teleport.com>
     Re: I have to ASK <buxx@buxx.com>
     Re: My counter counts, but too munch <rootbeer@teleport.com>
     New to the business! <steve@mosby1.force9.net>
     Re: Newbievi  question <mikeg@slpma8.ed.ray.com>
     Re: Out of memory problem (Ronald L. Parker)
     Re: Perl script question for gurus <scotth@sgi.com>
     Re: Questions about passing by reference. <rootbeer@teleport.com>
     rsh a Perl script (Joseph Look)
     Re: stat a Socket <rootbeer@teleport.com>
     struct in perl <bill@dml0.wcupa.edu>
     Re: using unix commands for missing libwww module <rootbeer@teleport.com>
     webwatch stats... <jefpin@bergen.org>
     Re: Which version of PERL is running on the server? <ljaffe@dsdc.dla.mil>
     Re: Wrong status from system() in child process ? <rootbeer@teleport.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 29 Aug 1997 21:20:01 GMT
From: tfletche@pcocd2.intel.com (Terry Michael Fletcher - PCD ~)
Subject: Re: A Complex Regex Needed
Message-Id: <5u7ee1$ftl$1@news.fm.intel.com>

Christopher Stetson (cstetson@vsicom.com) so eloquently and verbosely pontificated:

hmmm.  this still seems difficult to understand, but i think i got it.

>  
>  What I need to do is generate an RE based on the fields that return
>  actual values (if a default value comes through (checked against
>  @defaultKey) then it is treated like a field with no value). My thinking
>  was to create a long-ass RE with:
>  
>  foreach $dbFieldName (@dbFieldNames) {
>       if ($searchKey = $query-param(-name = "$dbFieldName")) {
>          if ($searchKey ne $defaultKey{$dbFieldName}) {
>              $grepTerm .= ("$searchKey" . '.*?\S\t');
                                             ^^^^^
should this line be(?):

		$grepTerm .= ("$searchKey" . '\t');

it seems to make more sense that way, because your (.*) is optional, but
you are requiring at least one non-whitespace character between the search
key and the tab...

>            }
>          else {$grepTerm .= '.*?\S\t';}
>      }
>     else {$grepTerm .= '.*?\S\t';}
>  }

i hope that you initialized $grepTerm before you started building with
'.=' .  

>  with the ".*?\S\t" being the generic search between fields. This generic
>  search thing is what is stumping me.

it looks like the generic search should match whatever is in that field.
this one looks like it would be a fun one to debug with print statements
though.  hope i understood your idea properly.

-- 
#!/usr/local/bin/perl -w
@"=(qw; P ;,q*e*,qq,r,,q;l;);$_=<<'/\<<$_; :-) \' ^/<\'<>/\'$!=0/\'/<&@_';
^[^a-i*#,k-z@&]u[s,*]t$ ^[]/$%a!&]*not*\(anything\)*here*$ ^p[$_r%,.]i*nt$
[^hi]?[]MOM!#]$ #  tfletche@pcocd2.intel.com  # ^h*[^b$d-j%/,l-z(]\{3\}er$
/\<<$_; :-) ' ^/<'<>/'$!=0/'/<&@_
for(split){map{s;print;join"",@";eg;chop;print}q& &.qx;look -r '$_';}# TMF


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

Date: Fri, 29 Aug 1997 13:49:31 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: Bizarre result with regex in -i -pe
Message-Id: <Pine.GSO.3.96.970829134915.24796A-100000@julie.teleport.com>

On 28 Aug 1997, Jonathan Feinberg wrote:

> rootbeer@teleport.com said...
> 
> > That's because the [^\t] will match the newline, since that's not a tab. 
> > (But if [^\t] didn't match it, then the $ would.) 
> 
> Hmm.  I quote perlre:
> 
>   $ Match the end of the line (or before newline at the end)

Oops - my mistake!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 29 Aug 1997 14:48:13 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Peter de Vroomen <peterv@valkieser.nl>
Subject: Re: Crash in Perl for Win32 5.003_07 (and older versions too)
Message-Id: <Pine.GSO.3.96.970829144342.24796I-100000@julie.teleport.com>

On Fri, 29 Aug 1997, Peter de Vroomen wrote:

> I have a program written in Perl for win32 5.003_07 which crashes when I
> try to read from a file. 

Sounds like a bug! (It might be a bug in your system, though, rather than
in Perl itself.) If it still exists in Sarathy's most recent port of Perl
to Win32, you should file a bug report.

    http://www.perl.com/CPAN/authors/id/GSAR/

Good luck!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 29 Aug 1997 14:26:44 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "Stephane L. Couillaud [VOBio]" <stephane@titude.arc.nasa.gov>
Subject: Re: find command with perl
Message-Id: <Pine.GSO.3.96.970829141956.24796F-100000@julie.teleport.com>

On Fri, 29 Aug 1997, Stephane L. Couillaud [VOBio] wrote:

>     I hope I won't be wasting bandwidth by asking this question.

If it's a Perl question not answered in the FAQs and other docs, it's hard
for it to be a waste. :-) 

> Basically, I'm having a problem using either find or find2perl in a
> perl script.  When I type the following command on the command line
> 
> /usr/bin/find /admin/vobadm/tmp -name "WYNDE*" -mtime +10 -exec ls -l {}
> \;`);

I think the trailing few characters are extras that snuck in there. :-)

> I have no problem getting the info I'm looking for, howerver, if I put
> it in a Perl script like so
> 
> #!/usr/local/gnu/bin/perl -w
> system(`/usr/bin/find /admin/vobadm/tmp -name "file*" -mtime +10 -exec
> ls -l {} \;`);
> 
> then I get the following message:  /usr/bin/find: incomplete statement.

You're taking the output of the command in the backticks and giving that
to system. It's hard to believe that that's what you want! :-)

But as for the backticks, you may be using a different command line than
you think, since the contents of backticks are double-quote interpolated
by Perl before being passed to the shell, and that is changing the "\;" to
just plain ";". 

> I also tried this alternative but I get the same message.
> 
> #!/usr/local/gnu/bin/perl -w
> find2perl /admin/vobadm/tmp -name "WYNDE*" -mtime +10 -exec ls -l {} \;

Whups! find2perl is a command-line command, not a perl function. Try
typing that at the command line and you should get a perl script which you
can then modify to do what you need.

Good luck!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 29 Aug 1997 15:29:14 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Michael Budash <mbudash@sonic.net>
Subject: Re: gethostbyaddr or some such...
Message-Id: <Pine.GSO.3.96.970829152501.24796N-100000@julie.teleport.com>

On Fri, 29 Aug 1997, Michael Budash wrote:

> If I have an IP address (e.g., mine right now: 208.201.224.62) and I'd
> like to get the actual host name (e.g., mine right now: 
> d49.pm8.sonic.net), how would I do it in perl? Would I use perl's
> gethostbyaddr function? 

That sounds like a good way to do it.

> Response by email as well as this newsgroup preferred - I'm kinda in a
> hurry! 

There's an even faster way than email or usenet, but it involves reading
the docs and trying some code to see whether it works. :-)  

After you've read the docs, if it's still giving you troubles, post again!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: 29 Aug 1997 22:43:02 GMT
From: "Eric D. Friedman" <friedman@uci.edu>
Subject: Re: having a Perl script time out
Message-Id: <5u7j9m$ajk@news.service.uci.edu>

<On Sun, 24 Aug 1997, Aveek Datta wrote:
< Is there any way I can 'time out' these scripts so they exit if X
< seconds has passed out? 

Tom Christiansen sent me this when I asked the same question some
time back.

package TimeOut;

use Carp;
use English;

require Exporter;
@ISA    = qw(Exporter);
@EXPORT = qw(alarm_expired error);

sub usage {
  carp "Error calling alarm_expired: @_" if @_;
  croak "usage: alarm_expired seconds function";
} 

my $Debug = 0;

sub set_debug { $Debug = @_ ? shift : 1 } 

sub alarm_expired {
  my ($seconds, $user_code) = @_;
  
  @_   == 2                   || usage "Not enough args";
  $seconds > 0                || usage "Need valid seconds";
  ref $user_code eq 'CODE'    || usage "Need code reference";
  
  local $SIG{ALRM} = sub {
    warn "EXPIRED!!\n" if $Debug;
    die "sigalarm: caught one";
  };
  
  eval {
    alarm $seconds;
    &$user_code();
    alarm 0;
  };
  
  return 0 unless $@;
  return 1 if $@ =~ /^sigalarm/;
  die;				# reraise 
} 
1;

-- 
Eric D. Friedman
friedman@uci.edu


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

Date: 29 Aug 1997 22:02:17 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: Help - Displaying text files!!!
Message-Id: <5u7gt9$fur@news.orst.edu>

In article <01bb95da$f9ff7c20$5f867dc2@cathalmc>,
Masked <Masked@Masked.Masked> wrote:
>Hi. I'm new to Perl so please put up with my (perhaps silly?) question.
>What I want to know is how do I write a script that will read from a text
>or html file and then output it to the screen? I'd be delighted if you
>could give me some sample code!

1.
open( FILENAME, "<filename" ) || die "burble grok on open: $!\n";
while(<FILENAME>) { print; }

2.
system( "cat filename" );

3. 
print `cat filename`;

4.
open( FILENAME, "<filename" ) || die "burble grok on open: $!\n";
@wholefile = <FILENAME>;
print "@wholefile";

4a.
open( FILENAME, "<filename" ) || die "burble grok on open: $!\n";
@wholefile = <FILENAME>;
while( $_ = shift @wholefile ) { print; }

4b.
open( FILENAME, "<filename" ) || die "burble grok on open: $!\n";
@wholefile = <FILENAME>;
while( $_ = shift @wholefile ) { 
	@chars = split //;
	print "@chars";
}

4c.
open( FILENAME, "<filename" ) || die "burble grok on open: $!\n";
@wholefile = <FILENAME>;
while( $_ = shift @wholefile ) { 
	@chars = split //;
	while( $c = shift @chars ) { print $c; }
}

5.  
system( "cp filename /dev/tty" );

6. 
system( "tee /dev/null < filename" );





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

Date: Fri, 29 Aug 1997 15:13:30 -0700
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Help - Displaying text files!!!
Message-Id: <Pine.GSO.3.96.970829150739.24796K-100000@julie.teleport.com>

On 29 Aug 1997, Masked wrote:

> From: Masked <Masked@Masked.Masked>

> What I want to know is how do I write a script that will read from a
> text or html file and then output it to the screen? 

Use the line input operator and the print statement. Any beginning book on
Perl should include these in one of the first few chapters. I recommend
the popular Llama book.

    http://www.ora.com/catalog/lperl2/

> Please reply to me via email - cmccarthy@ccl.ie

That would be easy to do if you had put your email address in the proper
headers, where it belongs. If somebody has told you that putting it in the
body of your message instead of the headers somehow helps anyone in the
world, then you've been misinformed. It's less convenient for you; it's
less convenient for me; it's helpful to no one. Please fix that. Thanks!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 29 Aug 1997 14:42:54 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Adam Reeves <areeves@us.ibm.com>
Subject: Re: Help Capturing Error Messages From sendmail
Message-Id: <Pine.GSO.3.96.970829143509.24796H-100000@julie.teleport.com>

On Fri, 29 Aug 1997, Adam Reeves wrote:

> In the following code I can't seem to capture any error messages that
> arise from sendmail! The 'open or die' construct doesn't seem to do the
> trick. 

> open(MAIL, "|/usr/sbin/sendmail -F\"$name\" -f \"$email\" \"$to\"")
>    or die("Cannot send mail to $email: $OS_ERROR");

It does and it doesn't. The die will happen if the open fails, but once
sendmail has started, it's a separate process. It can't tell your script
what's gone wrong except by its exit status. 

But you can send its errors to a tempfile, and then see what it has put
there after it quits. Would that do what you need?

> Also I get the following warning message:
> Name "$Q::internalmail" used only once: pssible typo at send.pl line 27
> (#1)
> 	(W) Typographical errors often show up as unique variable names.
> 	If you have a good reason for having a unique name, then just
> 	mention it again somehow to supress the message (the use vars
> 	pragma is provided for just this purpose).

> I couldn't figure out how the use vars pragma worked because everytime I
> tried to declare $Q::internalmail with it, it gave me some error message
> about "you can't declare another packages variable with this pragma."
> How do I supress that message properly, in other words leaving the
> warnings, strict, and diagnostics turned on?

I'd use something like this.

    $Q::internalmail if 0;	# Use this var more than once :-)

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 29 Aug 1997 15:11:41 -0500
From: "Michael D. Schleif" <mike.schleif@aquila.com>
Subject: How can execute system executable on NT?
Message-Id: <34072CFC.7E969AD5@aquila.com>

I have just inherited several NT boxes with Perl v4.0 (perl for NT
$$Revision: 4.0.1.8; Patch Level 36; (c) 89,90,91 Larry Wall; NT (c)
1993, Intergraph Corp.)

I need to run some rather simple Perl programs on these boxes; but, I
cannot seem to execute system executables by:
	backticks
	system()
	open(X, "dir |")

When I call system "dir", it returns 65535; otherwise, all else is blank
and no error code/message.

I am more familiar with UNIX Perl.  I do NOT have an immediate option to
upgrade these boxes to Perl v5.x.  The code I want to run works on a
win95 laptop; but, NOT on any of these NT boxes.

What is happening here?  How do I get around this?
-- 
Best Regards,

mds

Dare to fix things before they break . . .


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

Date: Fri, 29 Aug 1997 14:14:15 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "Jeremy D. Zawodny" <zawodny@hou.moc.com>
Subject: Re: HTML --> Perl conversion
Message-Id: <Pine.GSO.3.96.970829140420.24796C-100000@julie.teleport.com>

On Fri, 29 Aug 1997, Jeremy D. Zawodny wrote:

> On Sat, 16 Aug 1997 11:05:49 +0200, Aitor <webmaster@dmedia.net>
> wrote:
> 
> >Is there any program (for Macintosh) to transtale to perl an HTML page?
> 
> Odd question. Not sure why you'd need to do it, but okay...
> 
> ---snip---
> 
> #!perl -w
> 
> my @lines;
> 
> @lines = <>;
> 
> print "<HTML><HEAD><TITLE>Perl Script</TITLE></HEAD>";
> print "<BODY><PRE>\n";
> print @lines;
> print "</PRE></BODY></HTML>\n";
> 
> exit;
> 
> ---snip---

I don't see any way in which that translates HTML to Perl. (Which, as you
say, is an odd question.) The output is not Perl, and if the input is
HTML, the output is useless. :-)  

In fact, if the input were either plain text or Perl or any other common
format, or multiple files, then the output would be pretty much useless,
wouldn't it? (The output starts out like HTML, but then it doesn't escape
any special characters in the body of the text.)

And, of course, it would be more memory efficient if you processed the
input a line at a time, instead of slurping in all of the lines at once.

Cheers!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 29 Aug 1997 14:01:20 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: COWBYS <cowbys@aol.com>
Subject: Re: I have to ASK
Message-Id: <Pine.GSO.3.96.970829135035.24796B-100000@julie.teleport.com>

On 29 Aug 1997, COWBYS wrote:

> I am looking for the FTP.pm module, I know what CPAN is and Ive been
> there, my understanding was that i could go there and download modules,
> Ive gone into "modules", "by module" and I dont see any ".pm" files,
> Isnt there an easier way of obtaining a particular ".pm" file from
> somewhere. 

Nope. And Yep. :-)  For 99% of all modules which aren't bundled, you need
more than one or two files. Besides the .pm file itself, there should be a
file of installation instructions for the human or computer which does the
installation, and a test script which makes sure it's properly installed,
among other things. It's easiest to bundle those up into a single
downloadable object, and traditionally this is done with a .tar.gz file.

But now for the opposing viewpoint: New versions of Perl come with the
module CPAN.pm, which automates the downloading, testing, and installation
of modules from CPAN. If you can use it, it'll make every module on CPAN
just a few keystrokes away. Cool, huh?

Ironically, one of the things that CPAN.pm will find useful is
Net::FTP.pm... But it'll get and install that, if you ask it to. :-)

> I am running Perl for Win32 5.003,

Oh, I don't know whether CPAN.pm is yet ported to Win32. If not, you may
have to install the modules the hard way - which is the way all of us did
that a year ago. :-)

Good luck!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 29 Aug 1997 17:34:30 -0500
From: Buxx <buxx@buxx.com>
Subject: Re: I have to ASK
Message-Id: <34074E76.1BA0@buxx.com>

Tom Phoenix wrote:
> 
> On 29 Aug 1997, COWBYS wrote:
> 
> > I am looking for the FTP.pm module, I know what CPAN is and Ive been
> > there, my understanding was that i could go there and download modules,
> > Ive gone into "modules", "by module" and I dont see any ".pm" files,
> > Isnt there an easier way of obtaining a particular ".pm" file from
> > somewhere.
> 
> Nope. And Yep. :-)  For 99% of all modules which aren't bundled, you need
> more than one or two files. Besides the .pm file itself, there should be a
> file of installation instructions for the human or computer which does the
> installation, and a test script which makes sure it's properly installed,
> among other things. It's easiest to bundle those up into a single
> downloadable object, and traditionally this is done with a .tar.gz file.
> 
> But now for the opposing viewpoint: New versions of Perl come with the
> module CPAN.pm, which automates the downloading, testing, and installation
> of modules from CPAN. If you can use it, it'll make every module on CPAN
> just a few keystrokes away. Cool, huh?
> 
> Ironically, one of the things that CPAN.pm will find useful is
> Net::FTP.pm... But it'll get and install that, if you ask it to. :-)
> 
> > I am running Perl for Win32 5.003,
> 

NET:FTP is broke for WinDoz


> Oh, I don't know whether CPAN.pm is yet ported to Win32. If not, you may
> have to install the modules the hard way - which is the way all of us did
> that a year ago. :-)
> 
> Good luck!
> 
> --
> Tom Phoenix           http://www.teleport.com/~rootbeer/
> rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
> Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/


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

Date: Fri, 29 Aug 1997 15:19:31 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Aaron Sherman <ajs@lorien.ajs.com>
Subject: Re: My counter counts, but too munch
Message-Id: <Pine.GSO.3.96.970829151401.24796L-100000@julie.teleport.com>

On 29 Aug 1997, Aaron Sherman wrote:

> 	$tmp2 = substr($temp,0,7);
> 	$stat[length($`)]++ while $tmp2 =~ /0/g;

That would be more efficient if it were re-written to use pos instead of
$` . (The variables $` $& and $' involve a performance penalty.) But I
think it would be even faster with index. 

    for (  $_ = index($temp,"0"); 
	   $_ >= 0 and $_ < 7 ; 
	   $_ = index($temp,"0",$_)
        ) {
            $stat[$_]++
    }

Cheers!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 29 Aug 1997 23:02:25 +0000
From: Joe Mosby <steve@mosby1.force9.net>
Subject: New to the business!
Message-Id: <34075501.CDA43EB8@mosby1.force9.net>


--------------72180882EA93D26A6E64EB24
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi there!
    I'm a 15 year old kid who's just started out in Perl. I've tried to
start out by looking at a couple of the scripts from Matt's Script
Archive and by buying myself a book. I have tried to play around with a
few scripts to add my own functions and have done so quite succesfully
with a chat script. Now I want to add a "Private Message" facility to
this script.
    The problem I am having is that when I try to add this function it
goes wrong. I want it to have three sort of variables...1. If you sent
the message you see "(You sent a private message to JDoe) The message"
2. If the message is to you "(JDoe sent a private message to you) The
message" 3. You didn't send the message and it's not to you "JDoe is
whispering".
    I want the message to be made private by either looking like "/JDoe
The message" OR "JDoe: The message" If anyone has any tips as to how to
achieve this (I know it's a lot to ask, or it seems it to me!) I would
be very grateful!

Thanks in advance,
Joe

--------------72180882EA93D26A6E64EB24
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<HTML>
Hi there!
<BR>&nbsp;&nbsp;&nbsp; I'm a 15 year old kid who's just started out in
Perl. I've tried to start out by looking at a couple of the scripts from
Matt's Script Archive and by buying myself a book. I have tried to play
around with a few scripts to add my own functions and have done so quite
succesfully with a chat script. Now I want to add a "Private Message" facility
to this script.
<BR>&nbsp;&nbsp;&nbsp; The problem I am having is that when I try to add
this function it goes wrong. I want it to have three sort of variables...1.
If you sent the message you see "(You sent a private message to <B>JDoe</B>)
<I>The message</I>" 2. If the message is to you "(<B>JDoe</B> sent a private
message to you) <I>The message"</I> 3. You didn't send the message and
it's not to you "<B>JDoe</B> is whispering".
<BR>&nbsp;&nbsp;&nbsp; I want the message to be made private by either
looking like "/JDoe <I>The message</I>" OR "JDoe: <I>The message</I>" If
anyone has any tips as to how to achieve this (I know it's a lot to ask,
or it seems it to me!) I would be very grateful!

<P>Thanks in advance,
<BR>Joe</HTML>

--------------72180882EA93D26A6E64EB24--



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

Date: Fri, 29 Aug 1997 16:35:03 -0400
From: Michael Genovese <mikeg@slpma8.ed.ray.com>
Subject: Re: Newbievi  question
Message-Id: <34073277.1B6F@slpma8.ed.ray.com>

M.J.T. Guy wrote:
> 
> Michael Genovese  <mikeg@slpma8.ed.ray.com> wrote:
> >Here are my questions :
> >    (1) why is only the FIRST element of the array changed ?
> >    (2) why does a for-loop and a foreach loop give me slightly
> >        different outputs ?  Admittedly, this is only for the first
> >        element, but why ?
> >    (3) The problem does NOT seem to happen (and the entire array IS
> >        changed) IF I use a foreach loop BOTH times.  Why ?
> 
> Yes  -  you can help yourself by running that script as
> 
>    perl -w -Mdiagnostics myscript
> 
> and it would have said ...

Plenty, as I had discovered AFTER I sent that post.
Back to the manual for me!
Actually, this was a part of a somewhat larger script;
turns out those were the ONLY lines tagged by "-w", so
I was "close", at least. 


Again, thanks.


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

Date: Fri, 29 Aug 1997 21:40:45 GMT
From: ron@farmworks.com (Ronald L. Parker)
Subject: Re: Out of memory problem
Message-Id: <340741db.33250283@207.126.101.82>

[my apologies for the other reply on this subject.  I pushed the wrong
button thingy.]

On Fri, 29 Aug 1997 08:17:36 -0700, Tom Phoenix
<rootbeer@teleport.com> wrote:

>> undef $/;
>> while(<TXT>){
>> 	while(/\d+\s/gs){
>
>I don't think that the /s option adds anything there. 

I think the original poster intended for the /s to make \s match
newline. (Doesn't it do that anyway?)


--
Ron Parker
Software Engineer
Farm Works Software       Come see us at http://www.farmworks.com
For PGP public key see http://www.farmworks.com/Ron_Parker_PGP_key.txt


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

Date: 29 Aug 1997 12:59:15 -0700
From: Scott Henry <scotth@sgi.com>
Subject: Re: Perl script question for gurus
Message-Id: <yd8u3g8lq0c.fsf@hoshi.engr.sgi.com>


[Cc-ed to mark@tmn.com>

>>>>> "c" == chris abraham <chris@purple.tmn.com> writes:

c> I'm trying to rename a few thousand files in sequential order.

c> ie.

c> I have:
c> I want to change it to:

c> blah.txt   -->			00000001.txt
c> blub.txt			-->			00000002.txt
c> this.txt   -->   00000003.txt
c> that.txt   -->			00000004.txt
c> etc.txt				-->			00000005.txt

A quick-n-dirty sketch, you may have to do a little debugging:

#!/usr/bin/perl

$dir = shift || ".";    # first argument is directory
$start = shift || "0";  # second argument is starting number

$fnbase = sprintf "%08d", $start;
open(D, $dir) || die "can't open $dir? $!\n";

@files = map { $_ if (-f $_ and $_ !~ /^0.*txt/)} readdir(D);
closedir(D);

foreach $file (@files) {
        rename($file, $fnbase.".txt");
        $fnbase++;
}
__END__


c> I'll probably be running off a Windows box... I've heard there are
c> differences in the versions of perl.

This one was only tested under Unix.

-- 
 Scott Henry <scotth@sgi.com> /  Help! My disclaimer is missing!
 IRIX MTS,                   /  GIGO *really* means: Garbage in, Gospel Out
 Silicon Graphics, Inc      /  http://reality.sgi.com/scotth/


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

Date: Fri, 29 Aug 1997 15:06:06 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Peter de Vroomen <peterv@valkieser.nl>
Subject: Re: Questions about passing by reference.
Message-Id: <Pine.GSO.3.96.970829144838.24796J-100000@julie.teleport.com>

On Fri, 29 Aug 1997, Peter de Vroomen wrote:

> In my program I try to pass array's and hash-tables by reference as much
> as possible, because I presume passing a reference to a large array is
> much faster than passing the array itself (passing them to a subroutine
> that is..). 

Yes, it is faster. Passing them to other things than subs is faster by
reference as well! :-)

> I want to create an array inside a function and then pass the reference
> to the array to the caller. I don't want to create a global array, and
> creating a 'my' array is one of the most stupid things I could do, 

Why would that be stupid? That's acceptable Perl, to return a reference to
a variable which is going out of scope. The variable will stay around,
although you can no longer reference it by name (of course).

    sub countdown {
	# Returns a reference to a list which counts down 
	# from a given value to 0
	my($given) = @_;
	my(@list) = reverse 0..$given;
	\@list;				# Return value
    }

Or, you could create an anonymous list with the anonymous list reference
constructor.

    sub countdown {
	# Returns a reference to a list which counts down 
	# from a given value to 0
	my($given) = @_;
	[ reverse 0..$given ];		# Return value
    }

> Next example... What if I wanted to use @foo as a parameter for another
> function, like this (I won't recite the above subroutine..):
> 
> -------------------------
> sub print_element
> {
>     *bar = shift;
>     my $element = shift;
> 
>     print $bar[$element], "\n";
> }
> 
> *foo = create_array;
> print_element( \@foo, 1 );
> -------------------------
> 
> This is also possible, and seems to work, but is this valid too? 

You should probably avoid typeglobs. I'd do that like this.

    sub print_element {
	# Given an array reference and element number,
	# print that element.
	my($aref, $elem) = @_;
	print "$$aref[$elem]\n";
    }

> My first reaction was to declare @bar as a 'my' variable (my *bar =
> shift).  This doesn't seem possible (why not, I'm passing a reference,
> isn't it?). 

You can't make a typeglob a my() variable, since my() variables are never
in the symbol table and typeglobs always are. If that doesn't make sense,
then you should just avoid typeglobs altogether. If that does make sense,
you know why you should just avoid typeglobs altogether. :-)

> Now the BIG question (it's getting trickier)... What if I wanted to
> _add_ new elements to the array, 

Once you've got the array reference in (say) $aref, just drop '$aref' in
wherever you would put the array name. So, instead of saying @array, say
@$aref. Instead of $array[1], put in $$aref[1]. It's easy to do.

    sub add_element {
	my($aref) = @_;
	push @$aref, 2;
    }

> Can I treat references in Perl as I would treat pointers in C? 

No.

> When I pass a reference, am I just passing an address to some kind of
> memory? 

Yes, except that references know what they point to. (You can't use a hash
reference as an array reference.)

> Can Perl become confused about where to allocate the memory for new
> elements in an array passed by reference (and does this count for
> hash-tables too)?

No, but the programmer can. :-)

> If I pass a variable by reference to a subroutine, and
> this subroutine passes the same variable by reference to another
> subroutine, will this work?

Yes.

> I ask these questions because I have a Perl program which keeps
> crashing, and I'm not sure I did things right.

If it's crashing, you probably didn't do things right. :-)  Using true
("hard") references instead of typeglobs and soft references should let
you write reliable programs. Good luck!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: 29 Aug 1997 13:50:00 -0700
From: joel@aracnet.com (Joseph Look)
Subject: rsh a Perl script
Message-Id: <5u7clo$mj0@shelob.aracnet.com>

 I have experienced a problem when I tried to run a perl script through
rsh.  I think the problem is when I waiting for an input.  For example, 
the following script will not print the first three line until a return
is pressed when you run it through rsh.  Any help will appreciated.
 
print "Line 1\n";
print "Line 2\n";
print "Line 3\n";
 
$in=<STDIN>;



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

Date: Fri, 29 Aug 1997 14:18:29 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: w.stanton@auckland.ac.nz
Subject: Re: stat a Socket
Message-Id: <Pine.GSO.3.96.970829141753.24796E-100000@julie.teleport.com>

On 29 Aug 1997 w.stanton@auckland.ac.nz wrote:

> It is very important to me to be able to test if there is any data
> available on a socket without blocking.  

You may want the four-argument form of select. Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 29 Aug 1997 17:28:09 -0500
From: bill <bill@dml0.wcupa.edu>
Subject: struct in perl
Message-Id: <34074CF9.2D4E@dml0.wcupa.edu>

okay, sorry if this is a stupid question, but how do i do a struct in 
perl?  i don't want to use the pack/unpack stuff 'cause i don't want to 
have to do that for each record i look at.  i just want to be able to 
say...
array_of_recs[i].first_name = "bill";

i'm using c for this program but i'd rather use perl because perl is so 
much easier than c (plus i don't know how to glob a file in c... 
@file=<FILE>;)

so, is this something i overlooked in the llama book or is it not there?

any info would be appreciated.

bill


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

Date: Fri, 29 Aug 1997 14:16:53 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Bob Maillet <bob@cafemedia.com>
Subject: Re: using unix commands for missing libwww module
Message-Id: <Pine.GSO.3.96.970829141504.24796D-100000@julie.teleport.com>

On 29 Aug 1997, Bob Maillet wrote:

> I am trying to get the following snippet of code to work..  The server I
> am currently working on does not have the libwww module installed so I am
> using unix commands to read the data from a remote sight..then parse out
> that data.

Wouldn't it be easier to just install the libwww modules? If I'm not
mistaken, you don't have to have root privileges to install them (although
you should have to install them in your own filespace, typically). 

Good luck!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 29 Aug 1997 16:07:04 -0400
From: Anagrams of the Word 'A' <jefpin@bergen.org>
Subject: webwatch stats...
Message-Id: <Pine.SGI.3.95.970829112526.3004B-100000@vangogh.bergen.org>

Ok, I'd like a critique of a script I've made... I am a Perl/CGI
Programmer who likes to remake the wheel... I've made my OWN chat,
guestbook, and stats scripts...  I would like your reaction to a script I
made called webWatch, my answer to AccessWatch.  AccessWatch
(http://www.accesswatch.com) may be graphical, but I think mine is just as
good, and in some cases, even better.

AccessWatch tells me:
Inside Accesses, Outside Accesses, Server Accesses

webWatch tells me:
Inside Accesses, Outside Accesses
	* note: Server Accesses can easily be added in.


AccessWatch tells me:
Hourly Hits

webWatch tells me:
(it doesn't)
	* note: I can just as easily make another array for it.


AccessWatch tells me:
Page Demand (which page, # of hits, percentage)

webWatch tells me:
Page Demand (which page, # of hits)
	* note: I felt that the percentage is superfulous.
		I highlight the top pages that have been hit.


AccessWatch tells me:
Accesses by Domain (i.e.: org, com, net, edu)

webWatch tells me:
(it doesn't)
	* note: If I *really* wanted to, I'd put it in.


AccessWatch tells me:
Accesses by Host (# of hits, percentage)

webWatch tells me:
Accesses by Host (separates INTERNAL from EXTERNAL hits, # of hits)


AccessWatch tells me:
Lists each Server and Hits by Domain (i.e. org, com, edu)

webWatch tells me:
Lists each Server and Hits by Most Hits and separates INTERNAL from EXTERNAL


AccessWatch tells me:
Number of Errors

webWatch tells me:
Number of Errors, what pages had errors, where the page was linked from


To see the difference, check out my AccessWatch stats at:
	http://users.bergen.org/~jefpin/SiteStats
And check out the webWatch stats at:
	http://users.bergen.org/cgi-bin/jefpin/webwatch.pl

----------------
| "Here we are now, entertain us!"
| 	- Nirvana
----------------
Jeff "TechMaster" Pinyan | http://users.bergen.org/~jefpin
I do: HTML!! CGI!! Perl!! JavaScript!! jefpin@bergen.org
Got a JavaScript/CGI/Perl question or problem?  Let me know!

webXS - the new eZine for WebProgrammers! TechMaster@bergen.org
Visit us @ http://users.bergen.org/~jefpin/webXS

- geek code -
GCS/IT d- s>+: a--- C+>++ UAIS+>+++1094++++ L E--->---- W++++ !o K--? w>+ !O M>- V-- PS PE+ !Y !PGP t+ !5 X+ R tv+ b>+
DI+++ D+>++ G>++ e- h- r y? 
- geek code -



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

Date: Fri, 29 Aug 1997 14:48:10 GMT
From: "Leonard A. Jaffe" <ljaffe@dsdc.dla.mil>
Subject: Re: Which version of PERL is running on the server?
Message-Id: <3406E129.9A130E1F@dsdc.dla.mil>

Bob Maillet wrote:

> How would I go about finding which version of PERL is running on a unix
> server?
>
> Bob

 $ perl -v

--
Leonard A. Jaffe               Consultant, Unify Corporation
@ DLA Systems Design Center                Columbus, OH, USA
ljaffe@dsdc.dla.mil                             614-692-8158
                     My Heart is a Flower





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

Date: Fri, 29 Aug 1997 14:34:41 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "M.J.T. Guy" <mjtg@cus.cam.ac.uk>
Subject: Re: Wrong status from system() in child process ?
Message-Id: <Pine.GSO.3.96.970829142749.24796G-100000@julie.teleport.com>

On 29 Aug 1997, M.J.T. Guy wrote:

> If the fork fails because of "Process table full", system will wait 5
> seconds then retry _ad infinitum_.   Eeek!

That seems bad, but it isn't in reality. That's because that error should
only be temporary. If it's not, putting a limit on retries wouldn't help
anyway! :-)

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

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

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