[6400] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 25 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 27 15:37:14 1997

Date: Thu, 27 Feb 97 12:00:23 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 27 Feb 1997     Volume: 8 Number: 25

Today's topics:
     Re: [Q] Array and system <wkuhn@uconect.net>
     A eval() or substitution question <mconley@pms110.pms.ford.com>
     Re: bash to  perl script <wkuhn@uconect.net>
     Re: BEGINNER:  Help with <wkuhn@uconect.net>
     Re: Built-in variable for loop iteration#? <wkuhn@uconect.net>
     Re: Calling subroutines <wkuhn@uconect.net>
     Re: Can you create file on the fly with perl? <wkuhn@uconect.net>
     Re: File Locking <tchrist@mox.perl.com>
     File position, seek function (Brian Menke)
     Re: flock question <wkuhn@uconect.net>
     gzip, perl and libwww <jeffs@pop3.silverplatter.com>
     Re: help: date to time conversion <jeff@mdli.com>
     Re: modifying @INC <wkuhn@uconect.net>
     Re: Multiple values to/from subroutines... <wkuhn@uconect.net>
     Re: Newbie question: string replacement for MIF (Tad McClellan)
     Re: newbie question:manipulating strings (Shockwave Rider)
     Re: Object Perl Method <wkuhn@uconect.net>
     Re: PDF on the Fly with Perl5 <wkuhn@uconect.net>
     Re: Pel5, BSDI, Libwww and various other critters. <wkuhn@uconect.net>
     Perl and MS EXCEL <mikes@bl-mail1.corpeast.baynetworks.com>
     Re: Perl PRO needed here ! (Shockwave Rider)
     Re: PERL5 - reading from a socket is not interrupted by (Charles DeRykus)
     Re: Problems reading file using <> operator (Mike Stok)
     Re: Problems reading file using <> operator (Shockwave Rider)
     Re: Regular Expression question <ajohnson@gpu.srv.ualberta.ca>
     Re: Removing trailing and leading spaces (Mike Stok)
     Re: Removing trailing and leading spaces (Tad McClellan)
     Variable within a variable (Mark Komarinski)
     Re: weird behavior with my perl script (Tad McClellan)
     Digest Administrivia (Last modified: 8 Jan 97) (Perl-Users-Digest Admin)

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

Date: Fri, 21 Feb 1997 00:41:26 -0500
From: Bill Kuhn <wkuhn@uconect.net>
Subject: Re: [Q] Array and system
Message-Id: <330D3586.34371154@uconect.net>

Wouter de Boer wrote:
> 
> Hello,
> 
> Sorry, but I can't sent my complete message, I try it again.
> 
> I've two questions:
> 
> I have a module which returns three array, but when I want to use the
> second array from my module is it empty, because all the values are
> strored in the first array. The second and the thirth array are empy.
> I use this code:
> 
> sub test {
> 
> code....
> $string = .....
> $string1 = .....
> $array1[0] = ......
> $array2[0] = ......
> $array3[0] = ......
> 
> etc.
> 
> return ($string, $string1, @array1, @array2, @array3);
> 
> }
> 
> ($string, $string1, @array1, @array2, @array3) = test;
> 
> But when I look in @array2 it is still empty, why ?? Do I something
> wrong, or can it be done else ?? Can anybody help me to solve this
> problem ??

I responded to this via email.

The answer is to pass by reference.

If you don't have perl5, either get it or stop reading the rest of this.

In perl, when you pass results to/from a subroutine arrays are passed as
a generic list of scalars.  In other words, the number of elements in
each array is lost when passing to/from a subroutine.  Get it?

Okay, for those of you interested in the quick and dirty lessons on
references to arrays... (Listen up, I won't repeat this again!)

# create reference (pointer) to a named array
$ref = \@array ;

# create a reference to an anonymous array
$ref = [split(/,/,"hello,world"] ;

To dereference (get at the values of a referenced array)...
print join(",",@{$ref}),"\n" ;

So, to pass multiple arrays to/from a subroutine...
@array1 = (1..10) ;
@array2 = (11..20) ;
@array3 = (21..30) ;

($ref1, $ref2, $ref3) = shuffle(\@array1,\@array2,\@array3) ;

print
join("\n",join(",",@{$ref1}),join(",",@{$ref2}),join(",",@{$ref3})),"\n"
;

sub shuffle {
  $_[3],$_[2],$_[3] ;
}

The above should produce:
21,22,23....30
11,12,13....20
1,2,3...10

And that is how to pass by reference.

> 
> Second question:
> 
> when I use the shutdown command in a simple perl script it works, but
> when I use the same command in a CGI/Perl program it waits when the the
> shutdown command ends. My program:
> 
> first the simple perl program
> 
> #!/usr/bin/perl
> 
> system("shutdown -r +10");
> 
> All my users will see a warning that the system is going down, and my
> program ends. I can do other things.
> 
> the CGI program:
> 
> #!/usr/bin/perl
> 
> use CGI;
> 
> print form header etc.
> 
> system ("shutdown -r +10");
> print "<H1>System is going down</H1>\n";
> 
> end form header
> 
> But I see never the message "System is going down". My CGI program waits
> when the system command is ended. If I kill the shutdown command I see
> the message. Why ?? Can anybody help me ??
> 
> Thanks,
> 
>         Woute
Uh, you probably want to use non-parsed headers so that the output is
sent directly to the client instead of first being parsed by the web
server.  Maybe I'm wrong, but I think that the stdout is not output
until the end of the CGI script, but by then the system is going down.

By the way, what is the URL of that script? :-)

-- 
Bill Kuhn
Chief Developer
Wired Markets, Inc.
http://www.buyersindex.com


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

Date: Thu, 27 Feb 1997 13:03:52 -0500
From: Mike Conley <mconley@pms110.pms.ford.com>
Subject: A eval() or substitution question
Message-Id: <3315CC88.647F@pms110.pms.ford.com>

How can I get variable substitution to happen in an input string? 

This simple example shows the problem. Is there a solution?


#!/usr/local/bin/perl

$prefix="/usr/local";

$var1 = "$prefix/bin";         # OK, prints /usr/local/bin
print "1. ", $var1, "\n";

$input = '$prefix/bin';
print "2. ", $input,  "\n";    # OK, prints $prefix/bin

$code = q( $junk = "$input";);      # Do some magic here to 
print "evaluating: ", $code, "\n";  # get perl to do substitution
eval $code;                         # on the string
if ($@) {print $@, "\n"};           #

print "3. ", $junk, "\n";      # Ouch, still prints $prefix/bin
                               # I want /usr/local/bin



-- 
Mike Conley
mconley@ford.com


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

Date: Tue, 25 Feb 1997 16:13:42 -0500
From: Bill Kuhn <wkuhn@uconect.net>
To: Steve Vandiver <buxx@buxx.com>
Subject: Re: bash to  perl script
Message-Id: <33135606.23BCE1AE@uconect.net>

if (-f "/var/run/ppp0.pid") {
# true
} else {
# false
}

-- 
Bill Kuhn
Chief Developer
Wired Markets, Inc.
http://www.buyersindex.com


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

Date: Tue, 25 Feb 1997 09:25:41 -0500
From: Bill Kuhn <wkuhn@uconect.net>
To: Mark Hagan <mark.hagan@sophia.ncr.com>
Subject: Re: BEGINNER:  Help with
Message-Id: <3312F665.421B261C@uconect.net>

If $string contains the text you want to strip,

$string =~ s/\s+$// ;

will strip all trailing whitespace from $string.

-Bill
-- 
Bill Kuhn
Chief Developer
Wired Markets, Inc.
http://www.buyersindex.com


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

Date: Wed, 26 Feb 1997 13:39:01 -0500
From: Bill Kuhn <wkuhn@uconect.net>
To: "Michael N. Edmonson" <edmonson@yulara.fccc.edu>
Subject: Re: Built-in variable for loop iteration#?
Message-Id: <33148345.330D4EC3@uconect.net>

Short answer: Nope.

You can do a construct like the following, however:
for ($i=0;$i<=$#array;$i++) {
   $_ = $array[$i] ;
}

It isn't the ideal solution (e.g., the "magic counter variable") but it
is a little cleaner than what you are doing.

-Bill
-- 
Bill Kuhn
Chief Developer
Wired Markets, Inc.
http://www.buyersindex.com


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

Date: Tue, 25 Feb 1997 16:12:20 -0500
From: Bill Kuhn <wkuhn@uconect.net>
To: Luis Torres <ltorres@campus.ruv.itesm.mx>
Subject: Re: Calling subroutines
Message-Id: <331355B4.75F72773@uconect.net>

In order to call subroutines contained in another package you must do
one of the following:

1.  Identify the package to which the subroutine belongs when calling
the subroutine:
&package_name::parse_form_data(args)

2.  Export the subroutine name in the package:
use Exporter ;
@ISA = qw(Exporter) ;
@EXPORT = qw(parse_form_data) ;

Similarly, you can use one of the methods to access a package's
variables.

-Bill
-- 
Bill Kuhn
Chief Developer
Wired Markets, Inc.
http://www.buyersindex.com


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

Date: Tue, 25 Feb 1997 16:15:53 -0500
From: Bill Kuhn <wkuhn@uconect.net>
To: Dico Reyers <dico@isn.net>
Subject: Re: Can you create file on the fly with perl?
Message-Id: <33135689.FFC67E3@uconect.net>

You can open it for writing and close it using
open(FILE,">$filename") ;
close(FILE) ;
of use the unix touch command (if you are on unix) using
system("touch $filename")
if all you want is an empty file.

-Bill
-- 
Bill Kuhn
Chief Developer
Wired Markets, Inc.
http://www.buyersindex.com


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

Date: 27 Feb 1997 19:00:19 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: File Locking
Message-Id: <5f4lk3$169$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    jhoglund@skypoint.com (Jamie Hoglund) writes:
:Ok, here is something I find very confusing, is it possible to unlock a 
:file AFTER closing it? What if we don't, can other processes use it? 

The lock is on the file descriptor, so unless you have two stdio buffers
with the same fd, no, not really.

:I would have figured that as soon as a file is closed, we lose the lock. 
:(and if thats the case, I suppose unlocking it is kind of pointless)

Right.

:The fact that the data doesn't always go directly to disk, wow. There are 
:so many little hidden things that never dawn on me until someone points 
:them out, Thanks! I presume just using the code in flush.pl will work?

Sure, although this is still popular:

    select((select(FH), $| = 1)[0]);

if you'd like it run 100x slower and be 100x more readable,
then 

    use FileHandle;
    FH->autoflush(1);

is becoming popular.

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com


Ken is very smart but also very opinionated.  --Doug Gwyn


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

Date: 27 Feb 1997 18:57:44 GMT
From: bmenke@wasco.synopsys.com (Brian Menke)
Subject: File position, seek function
Message-Id: <5f4lf8$24f@hermes.synopsys.com>

Hi everyone, I would appreciate some help/clarification on the seek 
function. What I want to do is append to a file, but I want to append
to a specified position in the file. For example, I want the new text
to be appended to the third line, and have everything else move down.
I thought that I read some place in one of the Camel books that this
wasn't possible, but it looks like I can use seek somehow. I just can't seem
to figure out how?

for example:

open(FILE, ">>file_to_write_to");
print FILE "Here is some info\n";

What I am doing is writing to an html file. The next time I write to the file,
I want to insert the new info after the beginning html tags (say line 3) and
before the previous text that was inserted. Is seek the way to go, and if so,
can someone give me a clue how to use it?

I tried this:

$filepos = 232;
open(FILE, ">>file_to_write_to");
seek(FILE,$filepos,0);
print FILE "Here is some info\n";
close(FILE);

The new text is still inserted after the old text. I just must not
understand the seek function well enough. This problem must be common
enough.

Thanks for the help!

-Brian M.


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

Date: Wed, 26 Feb 1997 12:36:30 -0500
From: Bill Kuhn <wkuhn@uconect.net>
Subject: Re: flock question
Message-Id: <3314749E.70F228A7@uconect.net>

One solution is to open the file for read/write [open(FILE,"+<file")]
access, lock the file, read from the file, reposition the file position
pointer using seek() to the beginning of the file, write to the file,
release the lock, and close the file.

Of course, the above is simplified.

I assume that what you are reading and writing is always the same byte
count or greater as is the case of many counter programs (number of
digits will always be increasing).  If they weren't and you read
something like "hello world" and wrote something like "bye world" you
would wind up with the following in the file:
bye worldld

One way around this is obviously to pad the line with spaces.

Just one idea.

-Bill
-- 
Bill Kuhn
Chief Developer
Wired Markets, Inc.
http://www.buyersindex.com


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

Date: Thu, 27 Feb 1997 19:06:16 GMT
From: Jeff Seifer <jeffs@pop3.silverplatter.com>
Subject: gzip, perl and libwww
Message-Id: <3315DB28.46F32183@pop3.silverplatter.com>

Hi all,
I'm trying to gzip a set of large (> 100 MB uncompressed) files while
sending them through an http request using perl with libwww.

I can succesfully do this by doing the following:

In my CGI script:
=================
print $query->header('text/plain');
print `cat $filename | gzip`;


 
In my perl script:
==================
my $expected_length = $filelength;
my $bytes_received = 0;
my $chunksize = 30720;

open CHUNK, "|gunzip -q > $tofile 2> /dev/null";

my $res = $ua->request($req, \&getchunk, $chunksize);

close CHUNK;


where getchunk is:

sub getchunk
{
    my($chunk, $res) = @_;

    if ($res->is_success)
    {
        $bytes_received += length($chunk);
        unless (defined $expected_length) {
             $expected_length = $res->content_length || 0;
        }
        if ($expected_length) {
             printf STDERR "%d%% - ",
                   100 * $bytes_received / $expected_length;

        }
        print STDERR "$bytes_received bytes received\r";

        print CHUNK $chunk;
    }
}            


The problem is, the CGI script doesn't return anything until it has
finished gzip'ing the file!  This can take a quite a bit of time
(especially if many machines are trying to get different files at the
same time!)

The problem is, the request times out before the file has started being
transfered (I tried it with a smaller file and that works fine, so I
know my code is correct)!  This works fine without the gzip/gunzip stuff
(I can see the file size changing as the script is running)

I know I could increase the timeout time on the script, but I don't want
to do it that way.  I'd much rather have my script send a steady stream
of compressed data as it is being compressed!

I have also tried:
print `gzip -c $filename`;
on my CGI end, and got the same results...

Anyone know what else I can try???

Thanks in advance,
-- 
jeff -  http://jeffs.silverplatter.com (featuring the "JeffCam!")


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

Date: Thu, 27 Feb 1997 11:01:33 -0800
From: Jeff Younker <jeff@mdli.com>
To: Paul Rayson <paul@comp.lancs.ac.uk>
Subject: Re: help: date to time conversion
Message-Id: <3315DA0D.41C6@mdli.com>

Paul Rayson wrote:
> 
> I want to convert a string 'Wed Feb 26 13:17:09 GMT 1997' to a time
> stamp (number of seconds since 1970) in order to compare dates. I've
> looked at localtime and timelocal and so on, but I think I need the
> reverse of ctime. Has this already been done anywhere?
> 

use Time::Local ;

# Table to convert from month name to month number.
#
%month = ( 'Jan'=>0,  'Feb'=>1, 'Mar'=>2, 'Apr'=>3, 'May'=>4,
           'Jun'=>5,  'Jul'=>6, 'Aug'=>7, 'Sep'=>8, 'Oct'=>9,
           'Nov'=>10, 'Dec'=>11 ) ;

$date  = 'Wed Feb 26 13:17:09 GMT 1997' ;

# Convert $date to a time stamp.
#
@dt    = split(/[\s+:]/,$date,8) ;
$year  = substr $dt[7], 2, 2 ;
$time  = timegm( $dt[5], $dt[4], $dt[3], $dt[2],
                  $month{ $dt[1] }, $year ) ;


- Jeff Younker - jeff@mdli.com - These are my opinions, not MDL's -


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

Date: Fri, 21 Feb 1997 01:08:13 -0500
From: Bill Kuhn <wkuhn@uconect.net>
Subject: Re: modifying @INC
Message-Id: <330D3BCD.6DDB7DDC@uconect.net>

Hal Pomeranz (pomeranz@netcom.com) cleared up my problem.

He emailed me, but I don't think he posted the reply.

I think others might be interested in the solution to my problem:
Hal Pomeranz wrote...
> You need to modify @INC in a "BEGIN {}" block so that it gets evaluated
> as the program is interpeted, as the "use" statement will be.

Thanks for the responses.

-Bill
-- 
Bill Kuhn
Chief Developer
Wired Markets, Inc.
http://www.buyersindex.com


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

Date: Mon, 24 Feb 1997 21:03:43 -0500
From: Bill Kuhn <wkuhn@uconect.net>
To: Joe Tseng <jtseng@wauug.erols.com>
Subject: Re: Multiple values to/from subroutines...
Message-Id: <3312487F.458291D1@uconect.net>

The information is in your turqoise Camel book, you just don't realize
it...

The key is that the arguments to the return statement must be scalars. 
If you try to return an array, it is expanded into a list of scalars. 
Try it, you'll see what I mean.

What if you want to pass an array as an array to/from a subroutine?

In perl5, you can do this by using "references".  Use the camel book for
additional help, but I will summarize how to pass two arrays into and
from a subroutine:

@array1 = (1..10) ;
@array2 = (100..200) ;

# arrays are not passed, just references to arrays
# so $ref1 contains a reference to @array2
# a second array reference is returned, but I
# ignore it...
# the \ operator creates a reference to a named variable
($ref1,undef) = swap(\@array1,\@array2) ;
print join(",",@{$ref1}),"\n" ;
# so what does $ref1 contain?
print $ref1,"\n" ;

sub swap {
	# note the lack of an explicit
	# return; perl will take the last
	# expression evaluated as the return value
	$_[1],$_[0] ;
}

Read the section(s) on references.
These are the most powerful features added to perl5.

Good luck.

-Bill
-- 
Bill Kuhn
Chief Developer
Wired Markets, Inc.
http://www.buyersindex.com


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

Date: Thu, 27 Feb 1997 12:45:34 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Newbie question: string replacement for MIF
Message-Id: <eok4f5.j12.ln@localhost>

Lynne Frederickson (lynne@sweng.stortek.com) wrote:
: Hello,

: This is a newbie question from a new perl programmer
: with only a little C and some shell programming experience:

: I am trying to write a program to search for and replace
: strings for the purpose of applying a new template to
: FrameMaker MIF files.

: I know the basic "search and replace" syntax, and can
: do what I want from the command line via commands
: like this:

: perl -pi.bak -e 's/oldtext/newtext/g' filename

You can do the same thing with a script in a file (assuming Unix):


---------------------
#!/usr/bin/perl -pi.bak

s/oldtext/newtext/g;
s/another/anothernew/g;
 ...
---------------------

Not terribly efficient, but it works.


: My problem is I want to replace alot of strings, and I
: want to do this on multiple files supplied as command
: arguments, but I haven't yet figured out how to put that
: altogether in a script that works right. What is the basic 
: syntax for doing lots of string replacements?
: Do I need to do something with open() to open the files from 
: inside the script?  Do I need to do something with shift() to
: get to the next ARGV?

: As you can see, I'm embarassingly green. Any advice or
: better yet, code samples, would be GREATLY appreciated.


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: Thu, 27 Feb 1997 19:16:47 GMT
From: shockwave.rider@worldnet.att.net (Shockwave Rider)
Subject: Re: newbie question:manipulating strings
Message-Id: <3316dc91.26874049@netnews.worldnet.att.net>

In the spirit of Perl, 
There must be many to accomplish this.  I suspect 'unpack' would work,
but it was not cooperation with me.  I used a while substitution loop:

$long_string="hjjuhasdfgjkhasdfkjghouiegzxkdv09e4568624545";
$num=10;

while ($long_string) {
	print ">$long_string\n";	
	$long_string=~ s/(^.{0,$num})//;
	print ":$1\n";
	} 
	
Basically, while the sting still has stuff in it, remove the first 10
or less chars and stick them in $1 (love those regex), print some demo
output. repeat.

Thats one way...
Travis


On 26 Feb 1997 16:49:44 GMT, "jfreed" <jfreed@sigma6.com> wrote:

>having some problems getting up to speed with perl syntax, 
>be great if someone could help me out.
>
>I want to take a very long one line string and break it up into  lines of
>20 characters each.
>I've been able to do it using a very long and complicated looping process,
>but I'm sure
>there is a more efficient way.
>
>any input would be appreciated.
>
>thanks
>-jon
>



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

Date: Wed, 26 Feb 1997 12:14:33 -0500
From: Bill Kuhn <wkuhn@uconect.net>
Subject: Re: Object Perl Method
Message-Id: <33146F79.2898C8D0@uconect.net>

A "class method" is one that can be invoked on the class as a whole,
while an "instance method" is one that needs to be invoked on an object
(an instance of a class).

An example:

package circle ;

my $number_of_circles = 0 ;
my $pi = 3.1416 ;

sub new {
  my $class = shift ;
  my $this = {} ;
  my $this->{radius} = 12 ;
  $number_of_circles++ ;
  bless $this,$class ;
}

sub set_radius {
  my $this = shift ;
  $this->{radius} = shift ;
}

sub area {
  my $this = shift ;
  $pi*$this->{radius}**2 ;
}

sub get_number_of_circles {
  $number_of_circles ;
}

package main ;

$circle1 = new circle ;
$cirecl2 = new circle ;
#set_radius is an instance method
$circle1->set_radius(20) ;
#area is an instance method
print "area = ",$circle1->area(),"\n" ;
#get_number_of_circles is a class method
#note the lack of an object as an argument
print "circles created = ",&circle::get_number_of_circles(),"\n" ;

#############end of program##################

The above is just one simple example of how to get access to a class
variable via a class method.

Hope the above helps.

-Bill
-- 
Bill Kuhn
Chief Developer
Wired Markets, Inc.
http://www.buyersindex.com


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

Date: Tue, 25 Feb 1997 16:41:50 -0500
From: Bill Kuhn <wkuhn@uconect.net>
To: Jerome O'Neil <joneil@is.ssd.k12.wa.us>
Subject: Re: PDF on the Fly with Perl5
Message-Id: <33135C9E.67F8B895@uconect.net>

I have yet to find something like that, and I doubt that any will ever
be written.

The reason I doubt this is because I have altered existing PDF files
using perl and it is very complicated.  Each object you define in a PDF
file appears in a cross reference table at the end of the file with the
byte offset from beginning of the file to the beginning of the object
definition.  In addition, if an object has a stream of data, the byte
count of the stream must be provided either in the object containing the
stream or indirectly in an object referenced by the object containing
the stream.

If you really wanted to write a program, this is a great one for going
object-oriented.  The whole format screams OOP!

In summary, there are so many dependencies and counts, etc.  That is why
there is a "PDF on the Fly" module to create PDF documents, but nothing
(in perl) to modify existing documents.  With PDF it is easy to create
authoring tools, but more difficult to create editing tools.  This is
not a deficiency in the design of PDF, however, since PDF was designed
from the bottom up as a *distribution* format.

The first thing to do (if you haven't done so already) is go get the
Adobe PDF Reference Manual.  It is in PDF format (surprise!) and is
available on Adobe's web site in a real awkward location.  Look in the
technical notes for developers area.  That rings a bell.

Good luck.
-- 
Bill Kuhn
Chief Developer
Wired Markets, Inc.
http://www.buyersindex.com


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

Date: Sun, 23 Feb 1997 13:54:54 -0500
From: Bill Kuhn <wkuhn@uconect.net>
To: Dustin Andrews <dustin@icefog.polarnet.com>
Subject: Re: Pel5, BSDI, Libwww and various other critters.
Message-Id: <3310927E.4A043CBC@uconect.net>

First, when you say "poll" what exactly do you mean?  To me, to poll in
this context means to check that a server responds.  Once it responds,
you send/receive data so really you don't want to poll the server at
all, right?  It sounds like you want to connect with the server so that
you can exchange data.

Second, all telnet does is create a socket connection to a particular
host at a specific port so that you can send/receive data from a
terminal.  You don't need to use telnet to do this from within a perl
program.  All you have to do is create a socket connection within perl
using the internet socket functions provided by perl.

You can check (at CPAN?) to see if there are any socket
libraries/packages that facilitate the connection process.  If not, look
at the example in the Programming Perl (1st edition, not sure about 2nd)
book on how to create a simple client using internet sockets.  It is
very easy to create a simple client to accomplish what you want "from
scratch" (using the example(s) as a guide).

When you create a socket connection, you assign the connected socket a
name (like a filehandle) and you read/write from/to it as you would a
filehandle.  Very cool!

Hope this gives you some ideas and resources.

-Bill

-- 
Bill Kuhn
Chief Developer
Wired Markets, Inc.
http://www.buyersindex.com


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

Date: Thu, 27 Feb 1997 13:03:36 -0500
From: Mike Shannon <mikes@bl-mail1.corpeast.baynetworks.com>
Subject: Perl and MS EXCEL
Message-Id: <3315CC78.446B9B3D@bl-mail1.corpeast.baynetworks.com>

I would like to generate an EXCEL workbook
from Perl.

I'd like to generate a book that has multiple sheets 
in it 

Is there a way to write an ascii file that can be imported
into EXCEL that has multiple sheets as part of it?

thanks

mike 


--- 
Mike Shannon
Bay Networks Inc., Billerica MA
phone: 508-916-8244
email: mshannon@baynetworks.com


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

Date: Thu, 27 Feb 1997 19:52:49 GMT
From: shockwave.rider@worldnet.att.net (Shockwave Rider)
Subject: Re: Perl PRO needed here !
Message-Id: <3319e5d9.29249985@netnews.worldnet.att.net>

Try this, use the environmental variable 'HTTP_REFERER'.

Like so:
#!/usr/local/bin/perl

$|=0;

print "Content-type: text/html\n\n";


print <<EOF;
<html>
<head><title>PROJECT - PHASE #1 </title></head>
<frameset rows="60,*">
    <frame src="title.html" name="title"  SCROLLING=no>
    <frameset cols="180,*">
         <frame src="nav.html" name="nav" SCROLLING=auto>
         <frame src="$ENV{HTTP_REFERER}" name="main" SCROLLING=auto>
   </frameset>
</frameset>
</html>

EOF


On 27 Feb 1997 11:20:49 GMT, "Charles Robbie" <intaba@iafrica.com>
wrote:

>Hi
>Can anyone write me a good script that when a person clicks on a link in my
>site, it will bring up a frames page in my site and IMPORT the outside URL
>or site INTO the body of my frame - That way I do not lose the viewer from
>my site?
>
>Any Genius out there?
>Thanx
>Charles
>intaba@iafrica.com



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

Date: Thu, 27 Feb 1997 18:15:49 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: PERL5 - reading from a socket is not interrupted by an ALARM signal
Message-Id: <E69xEH.3t2@bcstec.ca.boeing.com>

In article <claudia.857043947@news.cern.ch>,
Claudia Bondila <Claudia.Bondila@cern.ch> wrote:
>	Hello there,
 > 
 > 	I've written a program which opens a datagram socket, writes something
 > to that socket and afterwards it reads from that socket. If writing and 
 > reading takes longer than 10 sec. I send an alarm signal and I close the 
 > connection. The program works fine in perl4.
 > Perl5, version 5.003_07 doesn't work on all platforms(HP-UX 10.10, 10.20,
 > Solaris, OSF), but on HP-UX 9.05. The reason for that is that reading from
 > a socket is not interrupted by an ALARM signal, I think.
 > 
 > 	Could somebody tell me if they had ever problems with that and how
 > they handled that?
 > 
 > 	Here it's a test program where the problem occurs:
 > $SIG{'ALRM'} = 'bingo';
 > 
 >     .... 
 >     alarm(10);
 >     print S "hello";
 >     $msg=<S>;
 >     close(S);
 >     alarm(0);
 > 
 > sub bingo{
 >     $timeout=1;
 > }
 > 

More likely with your recent perl, the socket read will restart
after the interrupt. Older perl versions didn't restart so 
this behavior was OS dependent. 


You might do something like this:

   $SIG{ALRM} = sub { die "timeout" };
   alarm 10;
   eval { $msg = <S> }; 
   alarm 0; 
   if ( $@ =~ /^timeout/ ) {
       close(S);
       ...
   } elsif {$@) {
       die "weird eval error\n";
   } else {     
     ...




HTH,

--
Charles DeRykus
ced@carios2.ca.boeing.com


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

Date: 27 Feb 1997 19:27:32 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Problems reading file using <> operator
Message-Id: <5f4n74$4o5@news-central.tiac.net>

In article <jloafoq3ymi.fsf@rasmussen.telco.stratus.com>,
Dan Rasmussen <dras@rasmussen.telco.stratus.com> wrote:

>Did the user of my module violate any common programming practices when
>they changed $/ without changing it back or should I always program defensively 
>in perl (i.e. never count on default behavior)?  I have asked the user of my 
>module to local $/.  Will this solve the problem or do I inherit his locals?
>Should the user of my module declare $/ to be local?  kevinl@eagles.casc.com
>suggested I consider using the strict module.  Will this solve all these
>strange (to me) global variable problems.

The user of your module is free to do whatever they like to $/, you have
to be aware that <> uses $/ and localise it yourself - it would be a huge
burden on the user of your modules for them to have to reset all of
perl's special variables to their defaults before calling a routine in a
module on the off chance that they would affect it.  Locals effectively
create a stack of values, the most recently careated of which is used, so 

A combination of the -w flag and the use strict pragma will lead to much
more robust code, but it's always wise to be especially defensive in
modules.

Hope this helps,

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com                |      Pencom Systems Administration (work)


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

Date: Thu, 27 Feb 1997 19:28:13 GMT
From: shockwave.rider@worldnet.att.net (Shockwave Rider)
Subject: Re: Problems reading file using <> operator
Message-Id: <3317ddb9.27169616@netnews.worldnet.att.net>

What are you splitting on?

$/  is the 'input record separator', thats what perls grabs up to each
iteration from the file handle <>.

By default it should be "\n" so you get one line at a time.  If you
set it to "\n\n" or "" it reads a paragraph (till it find a blank
line).  

So check the files you are reading from.  If has lines terminated with
\r instead of \n you will not get the bahavior you expect.  Or try to
find some other good pattern to use to separate your input records.

Perhaps you could use the pattern "coc":
$/="coc";

so each iteration $_ will contain one and only one occurance of "coc"
and you could grab '$par, $cocInd' easily.  Just set $/ before you try
to read from <>.

Good luck, 
Travis Jennings



On Wed, 26 Feb 1997 18:04:40 GMT, danr@hpwadjn.wal.hp.com (Daniel
Rasmussen) wrote:

>
>Hi,
>
>I have a perl module that reads from a file using the <> operator. 
>The exact code is as follows:
>
>    open(PFILE, $pFile);
>    while (<PFILE>)
>    {
>	if (/coc/)
>	{
>	    ($par, $cocInd) = /(\".*\")(.*)\)/;
>	}
>    }
>    close(PFILE);
>
>This code works as expected when called from my test app but I have
>problems when its used by the app it was designed for.  Specifically,
>it is reading more than one line at a time when used by the other
>app.  It behaves more like read() in that it seems to be reading a
>specific number of byes rather than a line at a time.  
>
>Is the <> operator somehow being toggled into a different mode?
>I can't find anything in my camel book about it.
>
>Any ideas?
>
>Perl version is 5.0.2.  Please follow up to the news group or to both
>danr@an.hp.com and dras@sw.stratus.com.
>
>Thanks.
>
>Dan Rasmussen
>danr@an.hp.com
>dras@sw.stratus.com
>



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

Date: Thu, 27 Feb 1997 12:46:15 -0600
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: Regular Expression question
Message-Id: <3315D677.4F085110@gpu.srv.ualberta.ca>

Jim Anderson wrote:
> 

> > $& does.
> 
> O'Reilly's "Mastering Regular Expressions" points out major problem
> with using $`, $&, and $'. See p. 282.

yes, i know, but in the case given it seemed like that might
have been what the poster was after seeing as how his $1...
variables had swallowed nulls at the end of the match

andrew


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

Date: 27 Feb 1997 19:12:26 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Removing trailing and leading spaces
Message-Id: <5f4maq$3v9@news-central.tiac.net>

In article <33158deb.1601922@news.ibm.net.il>, Avi <avi@tase.co.il> wrote:

>Here is what I'm trying:
>
>$a="    just a string    ";
>$a= s/^\s+|\s+$//g;

You're effectively saying

  $a = $_ =~ s/^\s+|\s+$//g;

You need to topicalise the maych using =~ like this:

  $a =~ s/^\s+|\s+$//g;

Hope this helps,

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com                |      Pencom Systems Administration (work)


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

Date: Thu, 27 Feb 1997 12:48:15 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Removing trailing and leading spaces
Message-Id: <ftk4f5.j12.ln@localhost>

Avi (avi@tase.co.il) wrote:
: Well it seems that I'm too novice.
: I got 3 answers (2 on E-mail so you can't see them here) and it seems
: that non of them is working. Maybe I'm doing something wrong ?
: I'm trying the following solution but the variable returned is "0"
: (??)

: Here is what I'm trying:

: $a="    just a string    ";
: $a= s/^\s+|\s+$//g;
    ^
    ^ an _assignment_. s/// returns the number of substitutions (zero)


$a =~ s/^\s+|\s+$//g;
    ^
    ^ this, on the other hand binds a pattern match to a string


: print("$a");

: exit;

: Here is what I'm getting:

: 0

: Thats all. A zero. I'm afraid that this zero describes exacly my Perl
: skills....


Spend some time reading the perl man pages. In particular:

perlop
perlre
perlfunc


: Can you help, I thought it is easy to remove leading and trailing
: blanks in a string...


It is easy. You just have to tell perl to do the right thing  ;-)


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: 27 Feb 1997 19:36:21 GMT
From: enry@shore.net (Mark Komarinski)
Subject: Variable within a variable
Message-Id: <5f4nnl$k38@fridge-nf0.shore.net>

Here's my dilema, but first:
5.003, Solaris 2.5, CGI.pm 2.30

I have a script which pulls in (via POST) a number of shipments to a single
source.  I named these 'product0', 'product1' and so on.  Actually, here's
the code:

    $cmd = join '\',\'',"insert into serial values ( '".$SHIP::serial0,
        $SHIP::product0,
        $SHIP::shipdate,
        $SHIP::version0,
        $SHIP::notes0,
        $SHIP::shipid."')";

What I want to do is replicate this (with a foreach?) so that I can
handle..say..4 shipments without haing to re-write this string 4 times.

What I have in mind is something like:

    foreach $i ( 0 .. 3 ) {
    $cmd = join '\',\'',"insert into serial values ( '".$SHIP::serial($i),
        $SHIP::product($i),
        $SHIP::shipdate,
        $SHIP::version($i),
        $SHIP::notes($i),
        $SHIP::shipid."')";
    }

Which would then presumably allow the $i to eval. first (with 0), then
create the string $SHIP::product0, which then gets evaled and inserted
into the string.  Unfort., this doesn't work as I get:

syntax error at /usr/local/etc/httpd/cgi-bin/enter.pl line 160, near
"$SHIP::serial(" 

Any way to get around this?  Or will I be forced to write 4 different
strings like this?

-Mark


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

Date: Thu, 27 Feb 1997 12:42:29 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: weird behavior with my perl script
Message-Id: <lik4f5.j12.ln@localhost>

Donna Schwede (schwede@hpcc) wrote:
: I am new at writing scripts in Perl and my latest attempt has me quite confused.
: Can someone explain what is going on?
  ^^^^^^^^^^^^^^^^^^^

I think so.


: My script file reads a file of runs to be done, copies files over to the names 
: expected by more FORTRAN program, writes the site name to a SITES.DAT, 


Insert a step here:

close() (or flush) the SITES.DAT file.


: then
: executes a FORTRAN program.  The FORTRAN program reads the SITES.DAT file to
: determine which site to process.

: If I run the FORTRAN program using my perl script, the FORTRAN program sees
: the SITES.DAT file as empty, which it isn't.  If I run the FORTRAN program 
                               ^^^^^^^^^^^^^^

Which it may well be, if you left out the step above.


: without the script, it runs fine.  I have hardcoded the file name (including path)
: in the FORTRAN file, so I know that the program is always reading the same
: SITES.DAT file.

: Please explain!
  ^^^^^^^^^^^^^^

Buffering.


: Thanks!

You're welcome.



--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: 8 Jan 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Jan 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.

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

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