[6301] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 921 Volume: 7

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 10 17:59:21 1997

Date: Mon, 10 Feb 97 08:00:27 -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           Mon, 10 Feb 1997     Volume: 7 Number: 921

Today's topics:
     Re: ??? Formating numbers <jander@jander.com>
     Re: [Q:] whitespace (Chris Nandor)
     Re: Accessing DB2 Database Thru Sybase Gateway w/out Us (Brian Jepson)
     Re: ANNOUNCEMENT: Perl documentation and FAQ discontinu <stesch@parsec.inka.de>
     Re: ANNOUNCEMENT: Perl documentation and FAQ discontinu (Bruce Stephens)
     Can I remove a require? <mark.brodziak@wpcorp.com.au>
     CD-R Media for Sale at G00d Prices febuary@november.com
     Re: CGI.pm - unintialized value (Ernesto Gianola)
     Re: delete/remove a file (Petr Prikryl)
     Re: Efficient keyword/value lookups using keyword subst <jander@jander.com>
     Re: Efficient keyword/value lookups using keyword subst (Dave Thomas)
     Re: Efficient keyword/value lookups using keyword subst (Mike Stok)
     Re: FTP Client (Andy Wardley)
     Help!read/write telnet process from perl <jakob@jake.hule.harryda.se>
     HELP!Telnet process in perl Basic PROBLEM! <jakob@jake.hule.harryda.se>
     Re: HELP!Telnet process in perl Basic PROBLEM! (Mike Stok)
     HELP: Pattern Matching Problem <geert.nijs@fys.kuleuven.ac.be>
     Re: HELP: Pattern Matching Problem (Tad McClellan)
     HELP: Week of year in perl only <jo@bergens-tidende.no>
     Re: HELP: Week of year in perl only (Dave Thomas)
     Re: HELP: Week of year in perl only (Mark Daku)
     How can i search in a html file on a remote server?? (Repo)
     Re: How can i search in a html file on a remote server? (Nathan V. Patwardhan)
     Re: Loops in perl (Jason Brazile)
     Re: Need help - just starting perl <jander@jander.com>
     Re: Need Perl Script to Telnet <merlyn@stonehenge.com>
     Re: Problems formating the number to be printed <jander@jander.com>
     Review date notifier <firment@mitchell.hitc.com>
     Re: Shouldn't HTML2PS output binary? (Harold Bamford)
     Re: Using $ENV{'QUERY_STRING'} (Tad McClellan)
     Re: Using $ENV{'QUERY_STRING'} (Chris Nandor)
     Re: Using $ENV{'QUERY_STRING'} (Tad McClellan)
     Re: XS problem - Can't find loadable object <jander@jander.com>
     Digest Administrivia (Last modified: 8 Jan 97) (Perl-Users-Digest Admin)

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

Date: 10 Feb 1997 09:01:34 -0500
From: Jim Anderson <jander@jander.com>
Subject: Re: ??? Formating numbers
Message-Id: <pvy8n4jl.fsf@jander.com>

"Daniel L. Kreitz" <kreitzd@atlantic.net> writes:

> 
> How do I get my variables to print out in a special format--specifically,
> currency formats? The output removes the extra zeros (i.e., $3.5 instead of
> $3.50). How do I fix this?
> 
> Do I use the format function? And if so, how?

sprintf or format, depending on wheether you're using print or write.

-- 
Jim Anderson			jander@jander.com
PGP Public Key Fingerprint:	0A 1C BB 0A 65 E4 0F CD
				4C 40 B1 0A 9A 32 68 44


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

Date: Mon, 10 Feb 1997 08:17:43 -0500
From: pudge@pobox.com (Chris Nandor)
Subject: Re: [Q:] whitespace
Message-Id: <pudge-ya02408000R1002970817430001@news.idt.net>

In article <aeqjd5.ga2.ln@localhost>, tadmc@flash.net (Tad McClellan) wrote:
# You asked to "strip out the whitespace". That's what this does:
# 
# s/ //g;

Hmmmm ... really?  Good thing he ain't using tabs ...

;-)

#================================================================
During the Middle Ages, probably one of the biggest mistakes was
not putting on your armor because you were "just going down to
the corner."

   --Jack Handey

Chris Nandor                                      pudge@pobox.com
PGP Key 1024/B76E72AD                           http://pudge.net/
Keyfingerprint = 08 24 09 0B CE 73 CA 10  1F F7 7F 13 81 80 B6 B6


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

Date: 10 Feb 1997 15:18:03 GMT
From: bjepson@crd03.ny.jpmorgan.com (Brian Jepson)
Subject: Re: Accessing DB2 Database Thru Sybase Gateway w/out Using Sybperl
Message-Id: <slrn5fueuv.v1.bjepson@crd03.ny.jpmorgan.com>

In article <32FA6CC4.1E43@gsd.state.nm.us>, Michael Owens wrote:
>I have to write a web application that accesses data 
>from a DB2 mainframe database thru a Unix-based Sysbase 
>gateway.  
>
>I'd like to write it in perl, but I'm under pressure 
>from the powers that be to write it in C using an 
>existing web app as a guide.
>
>To make my case for writing this app in perl, I need
>to demonstrate that I can turn out the app quicker
>using Perl rather than C.
>
>So: is it possible to interact with Sybase (on the
>Unix platform) using just plain old Perl 5.003, and 
>if so, how?
>
>Alternately, if I have to use Sybperl, could anyone
>give me pointers as to how to do it that way?
>
[...]

Michael,

The name "Sybperl" may be throwing you off. In the 4.0x 
days, you needed to build a whole new perl executable to
use the Sybase module, producing the Binary Formerly 
Known as Sybperl. In these happier, more modern days, 
you can use the Sybase module, which is available from 
CPAN at:

  http://www.perl.com/CPAN/modules/by-module/Sybase

This module is used just like any other Perl module imported
with the 'use' function, and includes documentation that
can be read with:

  man Sybperl

You will need to have the Sybase client libraries in order
to build this extension. 

Hope this helps,

-- 
Brian Jepson * (bjepson@ids.net)  *  http://www.ids.net/~bjepson
  Int(ra|er)net Database Developer, Author, Crypto-Fluxologist
Non-Prophet Arts Technology Flux:      http://www.ids.net/~as220
WWW/Database/NT,Java/Database: http://www.ids.net/~bjepson/books


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

Date: 8 Feb 1997 16:12:28 GMT
From: Stefan Scholl <stesch@parsec.inka.de>
Subject: Re: ANNOUNCEMENT: Perl documentation and FAQ discontinued
Message-Id: <5di8lc$anc@parsec.inka.de>

-rw-r--r--   1 news     news        11774 Jan 27  1996 perl-faq/part0
-rw-r--r--   1 news     news        45609 Jan 27  1996 perl-faq/part1
-rw-r--r--   1 news     news        29640 Jan 27  1996 perl-faq/part2
-rw-r--r--   1 news     news        27388 Jan 27  1996 perl-faq/part3
-rw-r--r--   1 news     news        48166 Jan 27  1996 perl-faq/part4
-rw-r--r--   1 news     news        41339 Jan 27  1996 perl-faq/part5
                                                  ^^^^


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

Date: 10 Feb 1997 14:02:49 +0100
From: stephens@math.ruu.nl (Bruce Stephens)
Subject: Re: ANNOUNCEMENT: Perl documentation and FAQ discontinued
Message-Id: <wwa6800reyu.fsf@bommel.math.ruu.nl>

>>>>> "Piotr" == Piotr Piatkowski <kompas@galaxy.uci.agh.edu.pl> writes:

> Well, what about writing a perl script which will automagically find
> FAQ's in this group, then reply with FAQ copy and cancel them? :-)

Yeah, you could easily write that in Java, or Tcl.
-- 
Bruce Stephens			| email: B.Stephens@math.ruu.nl
Utrecht University              | telephone: +31 30 2534630
Department of Mathematics       | telefax:   +31 30 2518394
P.O. Box 80010, 3508 TA Utrecht, The Netherlands


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

Date: 10 Feb 1997 06:32:23 GMT
From: "Mark Brodziak" <mark.brodziak@wpcorp.com.au>
Subject: Can I remove a require?
Message-Id: <01bc171c$2c60dd40$5681c392@pc2488.wpcorp.com.au>

Hi;

I have a require statement in my code.  I want to be able to require
several different control files; each file has a similar structure, named
ctl, within it.  However, I strike a small problem as when I try to
subsequently require the next control files, it ignores it as there is
already a require with the same structure within it.  

Can I remove my first require before going on to the next control file?

-- 
Mark Brodziak
Business Information Technology
Western Power Corporation
mark.brodziak@wpcorp.com.au


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

Date: 10 Feb 1997 13:54:13 GMT
From: febuary@november.com
Subject: CD-R Media for Sale at G00d Prices
Message-Id: <5dn9a5$1eh@dfw-ixnews5.ix.netcom.com>


We have the following CD-R media for sale.


Brand: Pioneer
Type: Printable Media (Surface is blank for printing or labels)
Type: Gold on Green
Size: 74 min (650 mb)
Price: 6.99
Minimum Order: 10


Brand: Maxell
Type: Gold on Gold
Size: 74 min (650 mb)
Price: 6.55
Minimum Order: 10


Brand: TDK
Type: Gold on Green
Size: 74 min (650 mb)
Price: 6.55
Minimum Order: 10


Brand: Hewlett Packard
Type Gold on Gold
Size: 74 min (650 mb)
Price: 7.15
Minimum Order: 10
Lifetime Warranty



The Copy Cat Shop has all your CD duplication, replication, recorders,
software, and media needs.


If you have any questions feel free to call.

Cordially,


			The Copy Cat Shop
			213-650-1680
			213-650-9110 Fax

		




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

Date: 10 Feb 1997 11:14:20 GMT
From: netog@cs.bu.edu (Ernesto Gianola)
Subject: Re: CGI.pm - unintialized value
Message-Id: <5dmvuc$5bd@news.bu.edu>

gsi@visi.com wrote:
: Can someone point me to whatever FAQ explains this?

: I've installed CGI.pm, but when I run a program using it, I
: get the intended output along with the warning:
: Use of uninitialized value at /home/gsi/lib/perl/CGI.pm-2.30/CGI.pm line 83.

: The program is pretty basic:
: #!/usr/local/bin/perl5 -w
: use lib '/home/gsi/lib/perl/CGI.pm-2.30';
: use CGI;

: print "hello world\n";

CGI.pm version 2.30 line 83
--------
$NPH++ if $ENV{'SERVER_SOFTWARE'}=~/IIS/;
--------

The problem is $ENV{'SERVER_SOFTWARE'} which probably isn't defined 
if you are running your program on the command line. 

Ernesto


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

Date: 8 Feb 1997 10:42:35 GMT
From: prikryl@dcse.fee.vutbr.cz (Petr Prikryl)
Subject: Re: delete/remove a file
Message-Id: <5dhlar$4g3@boco.fee.vutbr.cz>

Her Yaw Seet (yaw@sunflowr.usd.edu) wrote:
>	Does anyone know a proper way to remove or delete a file (without
>using system call)?? Actually, I would like to remove a directory that
>contains some files and subdirectories...?  Thanks... 8-)

I tried it (as a chalenge ;-). I tried to make it small and efficient.
You should consider it as example. As the `unlink' and `rmdir' operations
can be dangerous, I have put there a print instead. The dangerous operations
are in comments. After you are sure you can use it properly, you can simply
erase all the lines marked `???' and uncomment `unlink' and `rmdir' lines.
Before doing so, you can see, what files would be deleted and what 
directories would be removed.

(As I am quite new in using perl, I would like to `hear' the comment
of others -- how it can be done better, nicer,...)

File rm.pm (module)
-----------------------------------------------------------------------
package rm;
#
# Simplified Unix-like rm [-r] *
# Example by Petr Prikryl (http://www.fee.vutbr.cz/~prikryl/)
#
require Exporter;
@ISA = ("Exporter");
@EXPORT = qw( rm );

########################################################
#
# rm() - simplified Unix-like rm [-r] *
#
#   rm($dir [, -r ])
#
# where -r stands for `recursively'. Removes also .files
#
sub rm {
    my $dir = shift;         # directory
    $dir =~ s/\/$//o;        # remove the last slash

    my $opt = (defined $_[0]) ? shift : "";  # optional option
    
    my (@files, @subdirs);   # must be my() (recursion)
    
    # now we create the lists of all directories and of files (separately)
    #
    opendir(DIR, "$dir") or die "Directory $dir cannot be opened";
    while ($_ = readdir(DIR)) {             # entry without the path
	if (-d "$dir/$_" && !/^\./) { 
	    push(@subdirs, "$dir/$_");      # non `dot' directories...
	} 
	elsif (-f "$dir/$_") { 
	    push(@files, "$dir/$_");        # ... and all files
	}                                   
    }
    closedir(DIR);
    
    # the following line...                 ???
    foreach (@files) { print "$_\n"; }      # remove the files  ???
    
    # ... should be replaced by             ???
    # unlink @files;                        # remove the files
    
    if ($opt =~ /r/o ) {     # if it should be done recursively
        my $subdir;
        foreach $subdir (@subdirs) { 
	    rm($subdir, $opt);
	    
	    # the following line...         ???
	    print "*** rmdir($subdir); ". "*" x 25 . "\n"; # ???
            
	    # ... should be replaced by     ???
       	    # rmdir($subdir) or warn "Directory $subdir cannot be removed";
	}
    }
}

1;
######### end of module
-----------------------------------------------------------------------

 ... and your testing script can look like
-----------------------------------------------------------------------
#!/usr/bin/perl

use rm;

rm("my/test/directory", "-r");
-----------------------------------------------------------------------

See you,

          Petr
--
Petr Prikryl (prikryl@dcse.fee.vutbr.cz)   http://www.fee.vutbr.cz/~prikryl/
TU of Brno, Dept. of Computer Sci. & Engineering;     tel. +42-(0)5-7275 218


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

Date: 10 Feb 1997 09:06:10 -0500
From: Jim Anderson <jander@jander.com>
Subject: Re: Efficient keyword/value lookups using keyword substrings
Message-Id: <ohdsn4bx.fsf@jander.com>

Ben Goldstein <bdg@endpoint.com> writes:

> 
> The associative arrays perl provides are great for doing fast lookups
> using keywords, but apparently the keywords can't be regular expressions
> (If they can, please tell me how!) so how does one go about efficiently
> doing keyword/value lookups when only substrings are provided for the
> keywords? (Yes, if "keyword substrings" are used, then potentially
> multiple keyword matches may be generated for any given lookup, so I
> suppose a list will have to be returned.)
> 
> I thought this would be a straightforward (and common) task to do in
> perl,
> but I'm stumped. Of course, a tree structure of some kind would handle
> the job. Is there a library module somewhere for this that I've missed,
> or some other perl hack that finesses the problem?

foreach (keys %myhash) {
   print "matched: $_\n" if /my regex here/;
}

-- 
Jim Anderson			jander@jander.com
PGP Public Key Fingerprint:	0A 1C BB 0A 65 E4 0F CD
				4C 40 B1 0A 9A 32 68 44


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

Date: 10 Feb 1997 14:28:43 GMT
From: dave@fast.thomases.com (Dave Thomas)
Subject: Re: Efficient keyword/value lookups using keyword substrings
Message-Id: <slrn5fubvj.1p7.dave@fast.thomases.com>

On Mon, 10 Feb 1997 00:01:02 -0600, Ben Goldstein <bdg@endpoint.com> wrote:
> The associative arrays perl provides are great for doing fast lookups
> using keywords, but apparently the keywords can't be regular expressions
> (If they can, please tell me how!) so how does one go about efficiently
> doing keyword/value lookups when only substrings are provided for the
> keywords? (Yes, if "keyword substrings" are used, then potentially
> multiple keyword matches may be generated for any given lookup, so I
> suppose a list will have to be returned.)

If `substrings' is limited to leading characters (OK - I know that's not
English), then the Text::Abbrev package will do what you want. It loads a
hash with all possible unambiguous truncations of a set of values.

Dave

-- 

 _________________________________________________________________________
| Dave Thomas - Dave@Thomases.com - Unix and systems consultancy - Dallas |
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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

Date: 10 Feb 1997 15:25:49 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Efficient keyword/value lookups using keyword substrings
Message-Id: <5dnelt$m40@news-central.tiac.net>

In article <32FEB99D.7705@endpoint.com>,
Ben Goldstein  <bdg@endpoint.com> wrote:
>The associative arrays perl provides are great for doing fast lookups
>using keywords, but apparently the keywords can't be regular expressions
>(If they can, please tell me how!) so how does one go about efficiently
>doing keyword/value lookups when only substrings are provided for the
>keywords? (Yes, if "keyword substrings" are used, then potentially
>multiple keyword matches may be generated for any given lookup, so I
>suppose a list will have to be returned.)

One approach might be

  @keys = grep (/$pattern/, keys %hash);

but you might want to do something more like

  for (@keys = (); ($key, $val) = each %hash;) {
    push @keys, $key if $key =~ /$pattern/;
  }

if you have a big hash.  You might want to consider the abbrev.pl or
Text::Abbrev modules if you're using a certain type of substring, and
consider the costs of various techniques:

#!/usr/local/bin/perl

use Benchmark;

$key = 'AAA0001A';
for ($x = 0; $x < 100000; $x++) {
  $hash{$key} = 1;
  $key++;
}
$pattern = '02';

timethese (10, {
           'grep var' => '@keys = grep (/$pattern/, keys %hash);',
           'loop var' => 'for (@keys = (); ($key, $val) = each %hash;) {
                            push @keys, $key if $key =~ /$pattern/;
                          }',
           'loop varo' => 'for (@keys = (); ($key, $val) = each %hash;) {
                             push @keys, $key if $key =~ /$pattern/o;
                           }',
           'grep fix' => '@keys = grep (/02/, keys %hash);',
           'loop fix' => 'for (@keys = (); ($key, $val) = each %hash;) {
                            push @keys, $key if $key =~ /02/;
                          }',
           'loop fixo' => 'for (@keys = (); ($key, $val) = each %hash;) {
                             push @keys, $key if $key =~ /02/o;
                           }',
            });

__END__

produces this on my linux box

Benchmark: timing 10 iterations of grep fix, grep var, loop fix, loop fixo, loop var, loop varo...
  grep fix: 13 secs (12.36 usr  0.11 sys = 12.47 cpu)
  grep var: 14 secs (14.48 usr  0.00 sys = 14.48 cpu)
  loop fix: 26 secs (25.34 usr  0.00 sys = 25.34 cpu)
 loop fixo: 25 secs (24.78 usr  0.00 sys = 24.78 cpu)
  loop var: 32 secs (31.05 usr  0.00 sys = 31.05 cpu)
 loop varo: 26 secs (26.24 usr  0.00 sys = 26.24 cpu)

and this on my alpha workstation :-)

Benchmark: timing 10 iterations of grep fix, grep var, loop fix, loop fixo, loop var, loop varo...
  grep fix: 36 secs (16.72 usr  0.45 sys = 17.17 cpu)
  grep var: 45 secs (22.05 usr  0.05 sys = 22.10 cpu)
  loop fix: 76 secs (37.03 usr  0.12 sys = 37.15 cpu)
 loop fixo: 79 secs (38.72 usr  0.15 sys = 38.87 cpu)
  loop var: 92 secs (45.25 usr  0.13 sys = 45.38 cpu)
 loop varo: 78 secs (39.10 usr  0.00 sys = 39.10 cpu)

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: 10 Feb 1997 08:34:04 -0000
From: abw@peritas.com (Andy Wardley)
Subject: Re: FTP Client
Message-Id: <5dmmhs$csf@aoxomoxoa.peritas.com>

A MAGIC STORE  <max@amagicstore.com> wrote:
>I've programmed a couple of scripts in Perl, I've uploaded them to my
>server (UNIX) but they are not working. My server said that there is a
>^M (new line) at the end of each line. I'm using Win95 Notepad.
>Does anybody know any FTP client or other program that transform MS-DOS
>based text files into UNIX text files (basically without the ^M at the
>end of each line)??

ws-ftp does the job (see http://www.ipswitch.com) if you transfer
in text mode.  Come to think of it, most decent ftp clients should
do this for you (if anything running under the '95 virus can truly 
be considered "decent") BUT only in text mode.  In binary transfer 
mode, no CR/LF conversion will be done.

Alternatively, you can zap the grogglies using perl to trawl through
a number of files (-p) and edit them in place (-i):

  perl -pi -e 's/\015//g' file1 file2 file3 ...


A


-- 
Andy Wardley <abw@peritas.com>          http://www.peritas.com/~abw 
A responsible and professional individual who has no need for silly 
comments, inane banter or bizarre "in-jokes" in his signature file.  


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

Date: Sun, 09 Feb 1997 01:52:53 +0100
From: jakob himmelman <jakob@jake.hule.harryda.se>
Subject: Help!read/write telnet process from perl
Message-Id: <32FD1FE5.48C4@jake.hule.harryda.se>

The idea is to let the script start a telnet session to get information
from a database located on another server.Eventually the result is to be presented as 
html.(I know, a perl socket connection is nicer in many ways,but I'm just a 
beginner....)
Now this code was meant to fire up telnet.It does,but then something goes wrong....
The logfile remains empty.It seems like a problem to get both read and write access
to telnet. :-(
Greatful for any useful hints or ideas.
//Jakob Himmelman, Gvteborg,Sweden

open(TELNET,"|/usr/bin/telnet addresstohost");
open (LOG,">>bib.log");
while (<TELNET>){
	print LOG;
	if (/Username:/){
		print TELNET "guest\n";
		print LOG "guest\n";
	}
	
}


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

Date: Sun, 09 Feb 1997 02:57:30 +0100
From: jakob himmelman <jakob@jake.hule.harryda.se>
Subject: HELP!Telnet process in perl Basic PROBLEM!
Message-Id: <32FD2F0A.7762@jake.hule.harryda.se>

The idea is to script a telnet session to a sever hosting a database,
fetch searchresults, and then convert these to html.(I know a perl socket connection is 
nicer, but I4m just a beginner....).
Well,the code gets a connection, but my logfile(bib.log) gets nothing, and it seems to 
be a problem in writing to telnet.Is there a better way to open the telnet process for 
reading and writing?Maybe there is a timing problem to?
Greatful for any constructive hints.
Jakob Himmelman, Goteborg, Sweden

open(TELNET,"|/usr/bin/telnet AdressToDatabaseServer");
open (LOG,">>bib.log");
while (<TELNET>){
	print LOG;
	if (/Username:/){
		print TELNET "netchans\n";
		print LOG "NETchans\n";
	}
}


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

Date: 10 Feb 1997 12:16:00 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: HELP!Telnet process in perl Basic PROBLEM!
Message-Id: <5dn3i0$6r3@news-central.tiac.net>

In article <32FD2F0A.7762@jake.hule.harryda.se>,
jakob himmelman  <jakob@jake.hule.harryda.se> wrote:
>The idea is to script a telnet session to a sever hosting a database,
>fetch searchresults, and then convert these to html.(I know a perl socket connection is 
>nicer, but I4m just a beginner....).
>Well,the code gets a connection, but my logfile(bib.log) gets nothing, and it seems to 
>be a problem in writing to telnet.Is there a better way to open the telnet process for 
>reading and writing?Maybe there is a timing problem to?
>Greatful for any constructive hints.
>Jakob Himmelman, Goteborg, Sweden

>open(TELNET,"|/usr/bin/telnet AdressToDatabaseServer");

This opens TELNET for writing down a pipe to the telnet process

>open (LOG,">>bib.log");
>while (<TELNET>){

You're trying to read from TELNET here.

There are a couple of things I could suggest, the first is to look at
open2.pl and open3.pl or (if you're not easily put off) chat2.pl if you're
using perl 4.  All of these come with the distribution.  Eric Arnols has
written Comm.pl which is on the Comprehensive Perl Archive Network (CPAN,
whose master site is at ftp.funet.fi under /pub/languages/perl/CPAN) in
modules/by-authors/Eric_Arnold - I think this works with both perl 4 and
5.

If you're using perl 5 them IPC::Open2 and IPC::Open3 might help, they're
the "new" versions of open2 and open3.

Please read the documentation, it's quite easy to deadlock when you're
pretending top be interactive.  If you decide to use a raw socket then be
awarte that there's some negotiation thet needs to heppen when you go to
the telnet port - this is covered in the telnet RFC.

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: Mon, 10 Feb 1997 12:27:30 -0800
From: Geert Nijs <geert.nijs@fys.kuleuven.ac.be>
Subject: HELP: Pattern Matching Problem
Message-Id: <32FF84B2.2CE2@fys.kuleuven.ac.be>

Hi all,

I'm very found at PERL and have already written some scripts, now
I need URGENT help:
My problem is a pattern matching problem. Let me explain. The sting
I want to examine is:

"\Title{This is the title}\Address{This is an address}"

(the \Address extension is optional, it is not always there)

I want to extract the title, so I thought this would work:

	/\\Title{(.*)}/

But no: PERL takes the last curly bracket, and gives as Title:

	This is the title}\Address{This is an address

How can I make PERL search until the FIRST } and then ignore the rest ?


GN
Network Manager
University of Leuven


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

Date: Mon, 10 Feb 1997 07:20:23 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: HELP: Pattern Matching Problem
Message-Id: <na7nd5.231.ln@localhost>

Geert Nijs (geert.nijs@fys.kuleuven.ac.be) wrote:

: I'm very found at PERL and have already written some scripts, now
: I need URGENT help:
         ^^^^^^^^^^^

You likely could have gotten your urgent help from the documentation
provided with the perl distribution.

( unless, of course, you have already complied with the instuctions
  to delete all perl documentation )

Everyone who has the perl distribution has many helpers (the man pages) 
ready to jump in _immediately_ to help them when the have an 
URGENT problem.

You missed an opportunity to impress everybody at work with how
quickly you dealt with the urgent problem...



: My problem is a pattern matching problem. Let me explain. The sting
                  ^^^^^^^^^^^^^^^^^^^^^^^^

So, looking in the perlre man page may well get you your answer
in a couple of minutes, rather than posting and waiting...


----- begin piece of perlre man page -----

By default, a quantified subpattern is "greedy", that is, it will match as
many times as possible without causing the rest of the pattern not to match.
The standard quantifiers are all "greedy", in that they match as many
occurrences as possible (given a particular starting location) without
causing the pattern to fail.  If you want it to match the minimum number
of times possible, follow the quantifier with a "?" after any of them.
Note that the meanings don't change, just the "gravity":

----- end piece of perlre man page -----


( I've been meaning to get around to deleting my documentation. But
  I'm hoping that I can just wait until everyone else deletes theirs,
  then I can Get Rich Quick by selling it on the Internet ;-)


: I want to examine is:
: "\Title{This is the title}\Address{This is an address}"
: (the \Address extension is optional, it is not always there)
: I want to extract the title, so I thought this would work:
: 	/\\Title{(.*)}/


  	/\\Title{(.*?)}/
                    ^
                    ^


: But no: PERL takes the last curly bracket, and gives as Title:
: 	This is the title}\Address{This is an address
: How can I make PERL search until the FIRST } and then ignore the rest ?


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


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

Date: Mon, 10 Feb 1997 10:45:04 +0100
From: Jo Havik <jo@bergens-tidende.no>
Subject: HELP: Week of year in perl only
Message-Id: <32FEEE20.2D75@bergens-tidende.no>

Hi!

I hope someone can help me on this one:

I need to find the week of year from a given date. My problem is that
the target system is without a compiler, so using C libraries or Perl
modules interfacing C is not an option.

Any help, hints or references is greatly appreciated!
-------------------------------------------------------------------------------
Jo Havik
jo@bergens-tidende.no
				- They gave me an offer I couldn't understand.


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

Date: 10 Feb 1997 14:34:02 GMT
From: dave@fast.thomases.com (Dave Thomas)
Subject: Re: HELP: Week of year in perl only
Message-Id: <slrn5fuc9i.1p7.dave@fast.thomases.com>

On Mon, 10 Feb 1997 10:45:04 +0100, Jo Havik <jo@bergens-tidende.no> wrote:
> I need to find the week of year from a given date. My problem is that
> the target system is without a compiler, so using C libraries or Perl
> modules interfacing C is not an option.

So how would you have done it in C? 

Do it the same way in Perl!

Alternatively, have a look at 'localtime' and some modular arithemtic.

Dave



-- 

 _________________________________________________________________________
| Dave Thomas - Dave@Thomases.com - Unix and systems consultancy - Dallas |
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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

Date: 10 Feb 1997 09:58:59 -0500
From: daku@nortel.ca (Mark Daku)
Subject: Re: HELP: Week of year in perl only
Message-Id: <esq20aoaerw.fsf@nortel.ca>

Jo Havik <jo@bergens-tidende.no> writes:

> I need to find the week of year from a given date. My problem is that
> the target system is without a compiler, so using C libraries or Perl
> modules interfacing C is not an option.
> 
> Any help, hints or references is greatly appreciated!

Your questions carries a little baggage with it.  As week number
algorithms differ.  Believe it or not they do. Corporate algorithms
are often vastly different from the real world.  The real world is
often harder.

Is the first week of your year week 0.
Is the first partial week of your year week 0.
Do you have a different week seperator than sat-sun.

Answer these questions first then maybe some one has the answer.

Mark Daku
daku@nortel.ca


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

Date: Sun, 09 Feb 1997 16:36:08 GMT
From: st.aim@a1.nl (Repo)
Subject: How can i search in a html file on a remote server??
Message-Id: <32fdf70d.9367184@news.xs4all.nl>

Hello reader,

I have to search  +/- 10,000 url's. Batching the list of url's works.
Finding a particulair word in a html file is also working.
But how do i get on the remote server and and search there index.htm
for example. I tryed to find some examples on the net but i could not
find some.

I'am using win95 and perl build 303.

Thanx in advance

Robert e Bakker




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

Date: 10 Feb 1997 14:38:26 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: How can i search in a html file on a remote server??
Message-Id: <5dnbt2$mi9@fridge-nf0.shore.net>

Repo (st.aim@a1.nl) wrote:
: I have to search  +/- 10,000 url's. Batching the list of url's works.
: Finding a particulair word in a html file is also working.

Get LWP from a CPAN near you!
http://www.perl.com/perl/CPAN/

--
Nathan V. Patwardhan
nvp@shore.net
"[news:alt.fan.jwz]"


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

Date: 10 Feb 1997 15:33:23 GMT
From: jason@ampersand.com (Jason Brazile)
Subject: Re: Loops in perl
Message-Id: <5dnf43$ktv$1@ftp.ampersand.com>

In article <5dj1ls$1p4$1@newshound.csrv.uidaho.edu>,
Thomas Patrick Bailey <baile934@harrier.csrv.uidaho.edu> wrote:
> I am fairly new to perl, but I have been doing ok in it.  What I need to
> know is how to do a simple loop.  
>
> A simple example would be very helpful.

No problem. Loops are pretty simple in perl:

	#!/usr/bin/perl

	use strict;

	sub simple_loop
	{
		my ($lcv, $code) = @_;

		($lcv) && (&$code, &simple_loop($lcv - 1, $code));
	}
	sub main
	{
		#
	 	# print "hello, world\n" 5 times
		#
		&simple_loop(5, sub {print "hello, world\n"});
	}

	&main;

---
Jason Brazile
Ampersand, Inc
Billerica, MA


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

Date: 10 Feb 1997 08:48:33 -0500
From: Jim Anderson <jander@jander.com>
Subject: Re: Need help - just starting perl
Message-Id: <wwsgn55a.fsf@jander.com>

Konrad Rokicki <acidik@geocities.com> writes:

> 
> I'd like to learn Perl but I could someone help me out with my first
> script? I do some html editing and my files are all named .htm. So when
> I go to put them on the server I have to rename them all one by one. I'd
> like to write a script to rename all the .htm files in any directory to
> .html files. Here's what I have so far.. 
> 
> #! /usr/local/bin/perl
> # htm2html - Fast multifile rename
> 
> $addl = "l";    
> 
> 'ls *.htm > temp001';
> open (DATFILE, "temp001");
>  while (<STDIN>) {
>    if (/*.*/) {
> #    ^^^^^^^^^
> # I'm really unsure here.. how do I extract each line from the txt file
> # # and use it as a variable?
> 
> $1 = $file;
> }
>    foreach $file
>      'mv $file $file+$addl'; 
> #      ^^^^^^^^^^^
> # I'm confused here too..
> 
> These are the biggest problem sfor me..
> Don't waste your time on the small syntax errors.. I'll figure them out
> Thanks a LOT. Konrad.

#!/usr/bin/perl -w

while (<*.htm>) {
  rename $_, $_.'l';
}





















-- 
Jim Anderson			jander@jander.com
PGP Public Key Fingerprint:	0A 1C BB 0A 65 E4 0F CD
				4C 40 B1 0A 9A 32 68 44


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

Date: 10 Feb 1997 08:29:22 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: sitaram@diac.com
Subject: Re: Need Perl Script to Telnet
Message-Id: <8cu3nkel2l.fsf@gadget.cscaper.com>

>>>>> "Sitaram" == Sitaram Chamarty <sitaram@diac.com> writes:

Sitaram> Possibly unrelated question: Was I dreaming or was there at
Sitaram> some time somewhere a program called expect.pl?  I recently
Sitaram> needed expect functionality (but didnt have and didnt want to
Sitaram> load and learn Tcl), so I went hunting for expect.pl.
Sitaram> Couldnt find it anywhere.  Did find comm.pl eventually, but
Sitaram> by then the need had passed.

Sitaram> If and when I need it again, I'll go by what you say above
Sitaram> and use comm.pl, but meanwhile I'm curious: where and what is
Sitaram> expect.pl?  Does anyone know?

expect.pl was the alpha-alpha.  chat2.pl was the alpha. Comm.pl is the
beta.  No one has done the final release yet. :-)

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 568 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: 10 Feb 1997 08:57:44 -0500
From: Jim Anderson <jander@jander.com>
Subject: Re: Problems formating the number to be printed
Message-Id: <sp34n4pz.fsf@jander.com>

Leonardo Chaves Machado <lcm@dcc.unicamp.br> writes:

> 
> 
> 	Hi, everybody,
> 
> 		I am trying to format he number to be printed, and
> 	I am using the variable $#, to make it, but it seems not to
> 	work. A very simple test program could be:
> 
> ------------------ Code begins here ---------------------
> #!/usr/bin/perl
> 
> $number = 1.2387;
> $# = "%.2f";
> print "This is the number: $number\n";
> 
> ------------------ Code ends here -----------------------

[...]

It's deprecated. Use sprintf instead.

#!/usr/bin/perl -w

$number = 1.2387;
$# = "%.2f";
print sprintf "This is the number: %.2f\n", $number;

-- 
Jim Anderson			jander@jander.com
PGP Public Key Fingerprint:	0A 1C BB 0A 65 E4 0F CD
				4C 40 B1 0A 9A 32 68 44


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

Date: Mon, 10 Feb 1997 09:13:14 -0500
From: Drew Firment <firment@mitchell.hitc.com>
Subject: Review date notifier
Message-Id: <32FF2CFA.2847@mitchell.hitc.com>

I am new to the world of PERL, but know enough to come here for help. 
For ISO compliance, I need a script that will check the dates on a set
of documents and send an email notification to an individual stating
which documents are 11 months old.   

Any suggestions?


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

Date: 10 Feb 1997 15:14:35 GMT
From: bamford@marconi.ih.lucent.com (Harold Bamford)
Subject: Re: Shouldn't HTML2PS output binary?
Message-Id: <5dne0r$1r6@ssbunews.ih.lucent.com>

In article <esqohdzq83l.fsf@nortel.ca>, Mark Daku <daku@nortel.ca> wrote:

>> I'm using html2ps on an HP-UX machine, with perl already pre-installed.
>> But, when I operate on an HTML document, I get a file with a whole bunch
>> of cryptic text output (supposedly postscript, but NOT in the expected
>> binary).  When I then print this resultant file, I just get a dump of
>> the text.
>
>Postscript is text.  Postscript has never been binary.

It is possible that there is some confusion here.  Postscript is indeed
text.  Encapsulated Postscript (.eps) often (but not always) has a
binary header which can contain a TIFF preview.  Some spoolers can
recognize files with this header and strip it off as needed.  Other
print spoolers are too dumb to recognize anything and have to be TOLD
that they are receiving postscript.

But the bottom line is that Postscript is generally consider text and
not binary.  I won't get into the Level II stuff with embedded binary
here...

-- Harold Bamford

require 'standard_disclaimers.pl';


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

Date: Mon, 10 Feb 1997 06:32:25 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Using $ENV{'QUERY_STRING'}
Message-Id: <pg4nd5.gu.ln@localhost>


[ Gautam, you should _say_ so when you are emailing something that
  has also been posted ]


Gautam Srikanth (morpheus+@andrew.cmu.edu) wrote:
: Excerpts from netnews.comp.lang.perl.misc:
: 9-Feb-97 Re: Using $ENV{'QUERY_STRING'} by Tad McClellan@flash.net 

: > 2) to set an _environment_ variable form a _perl_ variable:
: >  
: > $ENV{'QUERY_STRING'} = $quy;
: Tad, are you sure that'll work?  


Yeah, it'll work.


: I just tried setting an environment
: variable from inside a Perl script, and it doesn't carry through to the
: calling environment (Solaris 2.5.1).


That's the OS doing that. Perl did the Right Thing.

(Right Thing = set the new environment)

All the child processes of the script will see the new environment.


: I've been under the understanding that no program can modify the calling
: environment under Unix.  Is there indeed some way to do so?


Right. But it still 'works'.

Wanna try it out?



set QUERY_STRING to some value in your shell

run the perl script below, the shell (child process) sees _your_ value.

uncomment the two lines.

run the perl script, the shell (child process) sees the _scripts_ value.



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


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

Date: Mon, 10 Feb 1997 08:25:59 -0500
From: pudge@pobox.com (Chris Nandor)
Subject: Re: Using $ENV{'QUERY_STRING'}
Message-Id: <pudge-ya02408000R1002970826000001@news.idt.net>

In article <smzeodG00YUu1IJoA0@andrew.cmu.edu>, Gautam Srikanth
<morpheus+@andrew.cmu.edu> wrote:

# Excerpts from netnews.comp.lang.perl.misc:
# 9-Feb-97 Re: Using $ENV{'QUERY_STRING'} by Tad McClellan@flash.net 
# 
# > 2) to set an _environment_ variable form a _perl_ variable:
# >  
# > $ENV{'QUERY_STRING'} = $quy;
# 
# Tad, are you sure that'll work?  I just tried setting an environment
# variable from inside a Perl script, and it doesn't carry through to the
# calling environment (Solaris 2.5.1).
# 
# I've been under the understanding that no program can modify the calling
# environment under Unix.  Is there indeed some way to do so?

Please migrate this conversation to the appropriate place.  Followups set.

#================================================================
I hate it when my foot falls asleep during the day because that
means it's going to be up all night.

   --Steven Wright

Chris Nandor                                      pudge@pobox.com
PGP Key 1024/B76E72AD                           http://pudge.net/
Keyfingerprint = 08 24 09 0B CE 73 CA 10  1F F7 7F 13 81 80 B6 B6


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

Date: Mon, 10 Feb 1997 09:24:18 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Using $ENV{'QUERY_STRING'}
Message-Id: <2jend5.6u1.ln@localhost>

Chris Nandor (pudge@pobox.com) wrote:
: In article <smzeodG00YUu1IJoA0@andrew.cmu.edu>, Gautam Srikanth
: <morpheus+@andrew.cmu.edu> wrote:

: # Excerpts from netnews.comp.lang.perl.misc:
: # 9-Feb-97 Re: Using $ENV{'QUERY_STRING'} by Tad McClellan@flash.net 
: # 
: # > 2) to set an _environment_ variable form a _perl_ variable:
: # >  
: # > $ENV{'QUERY_STRING'} = $quy;
: # 
: # Tad, are you sure that'll work?  I just tried setting an environment
: # variable from inside a Perl script, and it doesn't carry through to the
: # calling environment (Solaris 2.5.1).
: # 
: # I've been under the understanding that no program can modify the calling
: # environment under Unix.  Is there indeed some way to do so?

: Please migrate this conversation to the appropriate place.  Followups set.
         ^^^^^^^                          ^^^^^^^^^^^^^^^^^


This is a discussion of the effect of changing environment variables
from within perl. (It would be more obvious if I had chosen to use
an env var name like NOT_A_CGI_VAR ;-)

I already pointed out the approprate place to discuss _parsing_
the string so retreived from the environment, but he didn't ask
about that part in c.l.p.m.


So, I feel that this _is_ the appropriate place. Followups set back.


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


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

Date: 10 Feb 1997 08:51:37 -0500
From: Jim Anderson <jander@jander.com>
Subject: Re: XS problem - Can't find loadable object
Message-Id: <vi80n506.fsf@jander.com>

> >I am experimenting with the XS tutorial (xstut).  Following alone with
> >example one, I run across an error when I try to execute the script - it
> >complains about not being able find a loadable object.
> 
>  -snip-

adding this usually doe the trick:

use ExtUtils::testlib;

-- 
Jim Anderson			jander@jander.com
PGP Public Key Fingerprint:	0A 1C BB 0A 65 E4 0F CD
				4C 40 B1 0A 9A 32 68 44


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

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 V7 Issue 921
*************************************

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