[6882] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 507 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 21 10:09:53 1997

Date: Wed, 21 May 97 07:00:28 -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           Wed, 21 May 1997     Volume: 8 Number: 507

Today's topics:
     Re: Anyone using perl5.004 ? lvirden@cas.org
     Re: AWKer needs Perl help (Andrew M. Langmead)
     BUG in matching ? (!KiChKaHa!)
     Re: BUG in matching ? (Mike Stok)
     Compounding <yv50@dial.pipex.com>
     Re: Compounding (Mike Stok)
     Differentiating between users :- HOW? <a.barnes@surrey.ac.uk>
     Re: File Exsists & get all files (brian d foy)
     Re: File Exsists & get all files (Mike Stok)
     GnuEmacs, ActiveWare Perl and debugging <per@mogul.no>
     Re: help: how to compare some dd:mm:yy date with sistem (Paco Hope)
     How do I call an external script, sending input and cap <alan-s@consultancy-services*.*com>
     http in perl for win32 <rheald@tfs.net>
     Re: machttp and perl (Adam Schneider)
     Re: New Perl User Question <craig@mathworks.com>
     Re: New warnings in perl 5.004. (Mike Stok)
     Re: NT Perl limitations... permanent? <cerlpvk@cestar.technion.ac.il>
     Re: open and redirect (Andrew M. Langmead)
     Perl 5.002 socket call on DEC OSF/1   -    HELP <lhuynh@newscorp.com.au>
     Perl and CGI <kendal@freenet.tlh.fl.us>
     Re: running ftp in Perl script <jbosch@tid.cdscc.nasa.gov>
     Simultaneous HTTP requests: LWP? Raw sockets? (Ken Shan)
     Re: Simultaneous HTTP requests: LWP? Raw sockets? <aas@bergen.sn.no>
     Software developing Dmitry
     Software developing Dmitry
     Re: Split function (Mike Stok)
     Re: Split function (Honza Pazdziora)
     Re: What's the quickest way in perl to determine if a s <plussier@synnet.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 21 May 1997 13:40:09 GMT
From: lvirden@cas.org
Subject: Re: Anyone using perl5.004 ?
Message-Id: <5lutvp$c96$2@cas.org>


I've been using during the development phase, and build the final
version a few days ago.  
-- 
Larry W. Virden                 INET: lvirden@cas.org
<URL:http://www.teraform.com/%7Elvirden/> <*> O- "We are all Kosh."
Unless explicitly stated to the contrary, nothing in this posting should
be construed as representing my employer's opinions.


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

Date: Wed, 21 May 1997 12:43:58 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: AWKer needs Perl help
Message-Id: <EAJ7DA.GwE@world.std.com>

ehughes@netcom.com (Elton Hughes) writes:


>Hello All,

>I have a problem that I hope someone can help me with. I have a
>text file, that is approximately 200 lines long. Each line represents
>a single recond, fields are seperated by commas. here is a snippet of
>what the text file and records look like:

>001Z220A,64,59,0,0,0,27,32,0,32,0,,0,0,0,0,56,,0
>001Z220B,1,1,0,0,0,0,1,0,1,0,,0,0,0,0,1,,0
>001Z220E,17,11,9,8,0,0,0,0,0,2,15.0556,2,0,9,0,12,8.35,0
>001Z220J,4,2,2,2,0,0,0,0,0,0,11.215,0,0,2,0,3,6,0
>011E220E,45,21,16,11,0,0,0,0,0,5,13.2494,0,0,16,0,35,7,0 

>In awk $1 would be a contract number, $2 the number of enrollments
>and so on. There are 19 fields overall, sometimes fields are left
>blank. In Perl they would be undef. This is acceptable, given the
>nature of the contracts.

>I need to be able to extract the data from a single line. Using awk,
>that is very simple. I have finished 86 pages of the llama book, but
>have not yet found that magic bit of code that puts it all together
>in a neat little package that I can use, modify, and learn from. 

Take a look at the split() function for taking a line of text and
dividing it at some delimiter. You'll need to save the results of
split in a list. Use an if() conditional to see if the line matches
the current contract you are looking for, and print it out as you
wish.

#!/usr/bin/perl -w

$search_contract = shift @ARGV;

while(<>) { # for each line of input
  ($contract, $num_enrollments, @and_so_on) = split /,/; # divide each field
  if($contract eq $search_contract) { # if we have found our contract
    print;
    last;
  }
}

or a more succinct:

  perl -F, -ane 'BEGIN{$search=shift} print if $F[0] eq $search'

Basically, it is the same, but it uses the "-a" and "-F," command line
options to do an implicit split on commas, and the "-n" switch to loop
implicitly.

Notice that you can either split into an array and index into the
fields (like the second example, or assign to a list of simple scalar
variables, or a mixture of both (like the first example.)

>BTW, after extract the data, I need to format it for display. I am
>assuming that printf should handle most of my needs in that respect.

Also take a look at formats and the "write" function. I'm not
necessarily saying use them instead of print or printf, but they can
be useful and you should know that they exist.
-- 
Andrew Langmead


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

Date: Wed, 21 May 1997 13:06:32 +0200
From: "Luca Barbetta (!KiChKaHa!)" <barbetta@itba.mi.cnr.it>
Subject: BUG in matching ?
Message-Id: <3382D738.5098@itba.mi.cnr.it>

Hello!

I have a little observation...


I used this

            while ($tmp=~m/^(.{1,32768})(.*)$/)
               {
               print OUTPUT $ID.$1.$End_Row;
	       $tmp=$2;
               }

to do $tmp printed splitted in rows with max 32768 char (and with his
ID),
and it work fine.

The problem is that if I use 32767 instead of 32768 this little
procedure dont work absolutely! The result is the ID and all $tmp string
(also if his lenght is > 32767) 

 
Know someone the reason of this?


Sorry for the poor english...

Ciao,
Luca "!KiChKaHa!" Barbetta.


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

Date: 21 May 1997 12:37:57 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: BUG in matching ?
Message-Id: <5luqb5$jk8@news-central.tiac.net>

In article <3382D738.5098@itba.mi.cnr.it>,
Luca Barbetta (!KiChKaHa!) <barbetta@itba.mi.cnr.it> wrote:
>Hello!
>
>I have a little observation...
>
>
>I used this
>
>            while ($tmp=~m/^(.{1,32768})(.*)$/)
>               {
>               print OUTPUT $ID.$1.$End_Row;
>	       $tmp=$2;
>               }

The perl manual page distributed with perl 5.004 says:

  While none of the built-in data types have any arbitrary size limits (apart
  from memory size), there are still a few arbitrary limits:  a given
  variable name may not be longer than 255 characters, and no component of
  your PATH may be longer than 255 if you use -S.  A regular expression may
  not compile to more than 32767 bytes internally.

and you may have run into that,  one workaround might use index (to check
for \n) and substr to carve up the string.
                                                        
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: Wed, 21 May 1997 13:01:18 -0700
From: Brian Roberts <yv50@dial.pipex.com>
Subject: Compounding
Message-Id: <3383548E.6228@dial.pipex.com>

I would like to compound a value x times over.

e.g.  100 compounded up by 10% repeatedly for say 50 times.

How do I get Perl to report each successive compound result in
table format .

i.e. 100 , 110 , 121 , 133.1 , etc.

Thanks



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

Date: 21 May 1997 13:23:37 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Compounding
Message-Id: <5lut0p$ngf@news-central.tiac.net>

In article <3383548E.6228@dial.pipex.com>,
Brian Roberts  <yv50@dial.pipex.com> wrote:
>I would like to compound a value x times over.
>
>e.g.  100 compounded up by 10% repeatedly for say 50 times.
>
>How do I get Perl to report each successive compound result in
>table format .
>
>i.e. 100 , 110 , 121 , 133.1 , etc.

Depending on what you mean by table format you might try

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

$start = 100;
$multiplier = 1 + (10 / 100);

for ($step = 0, $val = $start; $step < 50; $step++) {
  printf "%2d: %10.2f (%10.2f)\n", $step, $val, ($start * $multiplier ** $step);
  $val *= $multiplier;
}

__END__

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: Wed, 21 May 1997 14:04:00 -0700
From: Aj <a.barnes@surrey.ac.uk>
Subject: Differentiating between users :- HOW?
Message-Id: <33836340.47A0@surrey.ac.uk>

AS part of departmental research project I have been asked write a
questionnaire which deals with an emotive subject. With this in mind, I
feel that I need to identify machines that have completed the
questionnaire before, so that I am aware of multiple entries from one
machine (or other attempts to bias the results).
I know enough to know that I should use a magic(?) cookie to hold a
variable that I can use to identifly the machine (and is set to expire
after the questionnaire has finished).
I'm not after anyway to identify a correspondant personally, mearly
differentiating between them. Someone suggested capturing the IPAddress
but didn't say how it could be done.
Is there a site I can look up for help/inspiration?
Or any advice that can be offered?

Thanks in advance
-- 
Andrew J Barnes
  University of Surrey, UK
- The  Accidental  Tourist -


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

Date: Wed, 21 May 1997 05:05:25 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: File Exsists & get all files
Message-Id: <comdog-ya02408000R2105970505250001@nntp.netcruiser>

In article <338191D4.6D73@nettipaja.clinet.fi>, Lauri Laakso
<lauri@nettipaja.clinet.fi> wrote:

> 1) How I can check if file Exsists ?

use the -e file test operator [1]

if ( -e 'whatever/the/filename/is' )
   {
   ...
   }
 
> 2) How I can get all files in directory to @files() for reading them.

use opendir() and readdir().  you might also want to through in the 
-f file test operator to ensure that you have a list of files (as
opposed to directories or symbolic links)

[1]
see the perlfunc man page or the Blue Camel, p. 85

-- 
brian d foy                              <URL:http://computerdog.com>                      

unsolicited commercial email is not appreciated


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

Date: 21 May 1997 09:41:32 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: File Exsists & get all files
Message-Id: <5lug0c$9pg@news-central.tiac.net>

In article <338191D4.6D73@nettipaja.clinet.fi>,
Lauri Laakso  <lauri@nettipaja.clinet.fi> wrote:
>1) How I can check if file Exsists ?

you can use one of the file tests, -e checks if a 'file' exists, and -f
can tell whether it's a plain file (i.e. not a directory, device, etc)

  if (-e $file) {
    ...
  }

>2) How I can get all files in directory to @files() for reading them.

you can use opendir and readdir for example on a unix system to get the
files in a directory:

  opendir DIR, $dir or die "opendir $dir failed ($!)\n";
  while (defined ($entry = readdir DIR)) {
    $fullName = "$dir/$entry";
    next unless -f $fullName;
    push @files, $fullName;
  }
  closedir DIR or warn "closedir $dir ($!)\n";

is a reasonably verbose way of doing it.

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: Wed, 21 May 1997 13:36:55 +0100
From: Per <per@mogul.no>
Subject: GnuEmacs, ActiveWare Perl and debugging
Message-Id: <3382EC67.4F69CB7C@mogul.no>

Hallo, I installed the perl5 distribution for winNT from ActiveWare on a
NT4 workstation. I also installed GNU Emacs 19.34.1.
 What I'm trying to do is to run the debugger from inside emacs 
(M-x perldb) and use it as I do on unix.
 Even though Perl for Win32 supports the debugger and Emacs seems to
recognize the M-x perldb command, the two applications do not appear to
be integrated as they are under UNIX (the only result I was able to
achieve was crashing emacs). So I would like to know which of the
following three holds:

1) Emacs for windows supports Perl and I'm probably getting something
wrong

2) Integration of debugging and emacs has never been attempted (M-x
perldb is not actually supported)

3) Doesn't work yet, but someone is working on it.

Thanx for attention

PS I have problem with Newsreader, CCs appreciated.

Luca <passani@eunet.no>


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

Date: Wed, 21 May 1997 13:23:58 GMT
From: bah6f@cs.virginia.edu (Paco Hope)
To: "Miran Sepic" <miran.sepic4@mss.tel.hr>
Subject: Re: help: how to compare some dd:mm:yy date with sistem date (localtime)?
Message-Id: <5lut1e$e1e@jazz.cs.Virginia.EDU>


"Miran Sepic" <miran.sepic4@mss.tel.hr> writes:
> I need to set the expiration date of an agreement and after that date user
> don't have a permission to enter in the download area of my Web site. How
> can I compare today's date (system date, localtime) with date in user
> database which should be something like :

Get the DateCalc and DateCalcLib module from CPAN.  I use this site:
ftp://uiarchive.cso.uiuc.edu/pub/lang/perl/CPAN/modules/by-module/Date

If you read the date into a variable, you can use a routine called
"CalcDays" to calculate an integer which represents that day.

Here's a tiny bit of code to demonstrate what I mean.

use Date::DateCalc qw( :all );
use Date::DateCalcLib qw( :all );

($year, $month, $date ) = parse_date(`/bin/date`);
$today = calc_days( $year, $month, $date );

# put your own routine in here to get the year, month, date of
# user's agreement
($useryear, $usermonth, $userdate) = @getDateFromFile(...);

$userday = calc_days( $useryear, $usermonth, $userdate );

if( $today > $userday )
{
    print "No access!";
}


Good luck,
Paco
-- 
Paco Hope                                         Computer Systems Engineer
paco@cs.virginia.edu                         Department of Computer Science
http://www.cs.virginia.edu/~bah6f/                   University of Virginia


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

Date: Wed, 21 May 1997 10:56:35 +0100
From: Alan Silver <alan-s@consultancy-services*.*com>
Subject: How do I call an external script, sending input and capturing output ?
Message-Id: <50AoULATbsgzEwQe@consultancy-services.com>

Tad McClellan <tadmc@flash.net> wrote ...
>Alan Silver (alan-s@consultancy-services*.*com) wrote:
>: Hi,
>
>: I have what I believe is a simple question, but being a bit of a perl
>                             ^^^^^^^^^^^^^^^
>
>Perl FAQ part 8:

Oops, sorry. I only came across the FAQ after I had posted the question.
Egg suitably smeared across face, apologies offered. I have changed the
subject of this reply.

>: I have a script (call it "ferret") that I want to call from within a
>: Perl script. I want to pass it data on stdin and capture the stdout. The
>               ^^^^^^^^^
>
>Yes, but do you *need* to pass it data on stdin and capture the stdout?
>
>Why not just write a short subroutine, and do it from within your script?

The other perl script is not mine and is quite large. I thought about
just including it as a subroutine, but I'm not altogether sure that it
would work. That's why I wondered if it was easy to call it as an
external script.

>: # some data processing has gone on here, resulting in $ferret containing
>: # the input for the script
>: call external_script < $ferret > @ferret;
>                                   ^
>                                   ^  ??

The intention was to suggest that I wanted to capture the output in an
array (this is pseudocode after all). Sorry if it was not clear.

>
>: for ($i=0; $i<+$#ferret)
>                ^        ^
>                ^        ^
>                =        ; $i++       ??

Oops, typos. Should have been :-

        for ($i=0; $i<=$#ferret; ++$i)

>: I hope that this is clear. Any help would be greatly appreciated.
>  ^^^^^^^^^^^^^^^^^^^^^^^^^
>
>It was until the pseudocode ;-)

Sorry again, I hope that I have made it clearer.

Thanx for the help, I will go and have a look at the module you
suggested.

Alan

NOTE - Asterisks may have been added to the e-mail address to discourage
       spams. Please remove them before replying.
-- 

====================================================================
|     Sent By : Alan Silver      alan@consultancy-services.com     |
|                                                                  |
|        Remember - The penalty for bigamy is two wives !!         |
====================================================================


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

Date: Wed, 21 May 1997 07:59:52 -0500
From: Rien used-to-be-sick-but-now-I'm-Heald <rheald@tfs.net>
Subject: http in perl for win32
Message-Id: <3382F1C8.1097@tfs.net>

I've installed perl for win32 on Win95 (similar to per previously) and
am needing to do some HTTP with this from a command line prompt.  I
understand I could use lwp to accomplish this, and have thus downloaded
lwp with this intent.  However, I can't get lwp to install.  I found a
script to help install it, supposedly, but that's not working.  So....

1) Any ideas on how to install lwp to get it to work w/ perl for win32?

2) Any other ideas on how to do http w/out lwp?

Thanks.

replies here or e-mail either way.  If you put it here we all benefit
except those who think NT and 95 are OS aberrations 8-).


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

Date: Tue, 20 May 1997 23:13:08 -0500
From: acs@bitstream.net (Adam Schneider)
Subject: Re: machttp and perl
Message-Id: <acs-2005972313080001@port135.bitstream.net>

Matthew Knight <matt@geenite.demon.co.uk> wrote:
> i've just got into perl... but don't know how to implement MacPerl to 
> run with MacHTTP..
> 
> can anyone email the definitive instructions of how to make it so that i 
> can run perl scripts like this?

If you're using MacPerl 5, you can save the scripts as MacHTTP CGI
programs, and they should work pretty seamlessly with MacHTTP, as long as
(1) MacHTTP knows that .pl or .cgi files are to be interpreted as CGI
scripts, and (2) you have AppleScript installed.  (If you have Perl 4, you
need a MacPerl extension called "PCGI" to be able to save the scripts as
CGI's.)

You may also want to check out Quid Pro Quo, a freeware Web server that's
a little easier to set up than MacHTTP.... and I believe it doesn't
require AppleScript to be able to run CGI's.  QPQ is at
http://www.slaphappy.com/.

For a lot of helpful server setup advice, I selfishly recommend "The Web
Server Handbook" by Prentice Hall.  It has a whole chapter on Mac stuff
and does a really good job (I think) of explaining how to write CGI
programs (in Perl), and how to implement them on your system.  If you're
interested, check out http://pobox.com/~handbook/order.html.

Adam


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Adam Schneider * schneider@pobox.com * http://pobox.com/~schneider/adam.html
Co-author of "The Web Server Handbook": http://www.prenhall.com/~palmer/
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


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

Date: Wed, 21 May 1997 09:33:00 -0500
From: Craig Ciquera <craig@mathworks.com>
Subject: Re: New Perl User Question
Message-Id: <3383079C.22C1@mathworks.com>

Troy Bull wrote:

You could probably do something like this:

while (<FILE>) {
    while( m/brown/gm) {
         $next = $';
         @input = split ' ', $next;
	     print "inputfilename: $input[0]\n";
}
}


NOTE: $' is a special variable (see the Camel book p. 128) that contains
the string following whatever was matched.  Then, I split the words in
the string and place them into an array.  The word you are looking for
is then the first element of that array.

Craig Ciquera

> 
> I am new to perl and I have a question.
> I am trying to write a perl program that will open a file, search for a
> word, then return the next word in the file and write the output to yet
> another file.
> 
> input:
> the quick brown fox jumped over the brown
> box quickly
> 
> if the "word" were brown the output would be
> inputfilename : fox
> inputfilename : box
> 
> Please help
> thanks
> Troy
> --
> ----------------------------------------------------------------------
> Troy Bull | University of Northern Iowa | troy.bull@uni.edu
> 
> The 2 most common elements in the universe are hydrogen and stupidity.
> ----------------------------------------------------------------------


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

Date: 21 May 1997 12:15:26 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: New warnings in perl 5.004.
Message-Id: <5lup0u$hu9@news-central.tiac.net>

In article <EAIIsz.MFJ@nonexistent.com>, Abigail <abigail@fnx.com> wrote:

>I've noticed that perl 5.004 is a lot pickier than perl 5.003.

This is a benefit, as long as you can tell it to shut up!

>   - If you do perl -c on a file that starts with
>     '#!/usr/local/bin/perl -wT' it'll whine "Too late for -T now"
>     and stop. Urgh. How I am supposed to do a syntax check
>     now other than actually executing the file or removing the
>     -T switch (with the danger to forget it to put back in when
>     moving it to common area)?

put the -T on the command line e.g.

vrooom.nis.newscorp.com> perl -c try.pl
Too late for "-T" option at try.pl line 1.
vrooom.nis.newscorp.com> perl -Tc try.pl
Name "main::var" used only once: possible typo at try.pl line 3.
try.pl syntax OK

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: 21 May 1997 09:02:30 GMT
From: cerlpvk <cerlpvk@cestar.technion.ac.il>
Subject: Re: NT Perl limitations... permanent?
Message-Id: <5ludn6$afa@news.huji.ac.il>

So far as I know WinNt got no such notion as fork

Regards



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

Date: Wed, 21 May 1997 12:26:06 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: open and redirect
Message-Id: <EAJ6JI.7p8@world.std.com>

Deyoung Hong <hong@taligent.com> writes:

>How do I use open to pipe STDOUT to one file and STDERR to another?

>For example, I can pipe a command output as open(FH, "/bin/ls |"),
>how about its error output?

This question is answered in the FAQ:
<http://www.perl.com/CPAN/doc/FAQs/> This one specifically at
<http://www.perl.org/CPAN/doc/manual/html/pod/perlfaq8/How_can_I_capture_STDER_from_an.html>

>  How can I capture STDERR from an external command?
>
>    There are three basic ways of running external commands:
>
>        system $cmd;                # using system()
>        $output = `$cmd`;           # using backticks (``)
>        open (PIPE, "cmd |");       # using open()
>
>    With system(), both STDOUT and STDERR will go the same place as the
>    script's versions of these, unless the command redirects them.
>    Backticks and open() read only the STDOUT of your command.
>
>    With any of these, you can change file descriptors before the call:
>
>        open(STDOUT, ">logfile");
>        system("ls");
>
>    or you can use Bourne shell file-descriptor redirection:
>
>        $output = `$cmd 2>some_file`;
>        open (PIPE, "cmd 2>some_file |");
>
>    You can also use file-descriptor redirection to make STDERR a
>    duplicate of STDOUT:
>
>        $output = `$cmd 2>&1`;
>        open (PIPE, "cmd 2>&1 |");
>
>    Note that you *cannot* simply open STDERR to be a dup of STDOUT in
>    your Perl program and avoid calling the shell to do the redirection.
>    This doesn't work:
>
>        open(STDERR, ">&STDOUT");
>        $alloutput = `cmd args`;  # stderr still escapes
>
>    This fails because the open() makes STDERR go to where STDOUT was
>    going at the time of the open(). The backticks then make STDOUT go to
>    a string, but don't change STDERR (which still goes to the old
>    STDOUT).
>
>    Note that you *must* use Bourne shell (sh(1)) redirection syntax in
>    backticks, not csh(1)! Details on why Perl's system() and backtick and
>    pipe opens all use the Bourne shell are in
>    http://www.perl.com/CPAN/doc/FMTEYEWTK/versus/csh.whynot .
>
>    You may also use the IPC::Open3 module (part of the standard perl
>    distribution), but be warned that it has a different order of
>    arguments from IPC::Open2 (see the IPC::Open3 manpage).

-- 
Andrew Langmead


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

Date: Wed, 21 May 1997 19:41:56 +1000
From: loi huynh <lhuynh@newscorp.com.au>
Subject: Perl 5.002 socket call on DEC OSF/1   -    HELP
Message-Id: <3382C363.25C6@newscorp.com.au>

Hi,

I am running Perl 5.002 on a DEC 2100 with OSF/1 v3.2.  I compiled
successfully compiled Perl using DEC C and ran h2ph without any error. 
However something didn't seem right when I use socket call to try the
following client/server sample below.

I got the following message for both the server and the client but line
3 in my Perl code is a blank line for both the client and the server.

I don't know what is happenning here.  Have I missed out something in
the h2ph conversion process?  Any help are greatly appreciated.

This is the MESSAGE:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Scalar found where operator expected at (eval 58) line 3, near "*($p"
        (Missing operator before $p?)

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Here is the sample SERVER:
#!/usr/bin/perl -w



require 'sys/socket.ph';

$port = 7011;

$sockaddr = 'S n a4 x8';
($name, $aliases, $proto) = getprotobyname('tcp');
($name, $aliases, $port)  = getservbyname($port, 'tcp') unless $port =~
/^\d+$/;
$this = pack($sockaddr, &AF_INET, $port, "\0\0\0\0");
socket(S, &PF_INET, &SOCK_STREAM, $proto) || die "socket: $!";
bind(S, $this) || die "bind: $!";
listen(S, 5) || die "connect: $!";

select(S);
$| = 1;
select(STDOUT);
for (;;) {
        print "Listening again\n";
        accept(NS,S) || die $!;
        ($addr = accept(NS,S)) || die $!;
        print "accept ok\n";
        ($af,$port,$inetaddr) = unpack($sockaddr,$addr);
        @inetaddr = unpack('C4',$inetaddr);
        print "$af $port @inetaddr\n";
        while (<NS>) {
          print;

        }
}


Here is the sample CLIENT:
#!/usr/bin/perl



($them,$port) = @ARGV;
$port = 7011 unless $port;
$them = 'localhost' unless $them;

require 'sys/socket.ph';

$sockaddr = 'S n a4 x8';
chop($hostname = `hostname`);

($name, $aliases, $proto) = getprotobyname('tcp');
($name, $aliases, $port) = getservbyname($port, 'tcp')
        unless $port =~ /^\d+$/;
($name, $aliases, $type, $len, $thisaddr) =
                                gethostbyname($hostname);
($name, $aliases, $type, $len, $thataddr) = gethostbyname($them);

$this = pack($sockaddr, &AF_INET, 0, $thisaddr);
$that = pack($sockaddr, &AF_INET, $port, $thataddr);

socket(S, &PF_INET, &SOCK_STREAM, $proto) || die "socket: $!";
bind(S, $this) || die "bind: $!";
connect(S, $that) || die "connect: $!";

select(S);
$| = 1;
select(STDOUT);

while (<STDIN>) {
        print S;
}

-- 
~~~~~~~~~~~~~~~~~~~~~~o~0~o~~~~~~~~~~~~~~~~~~~~~~~
News Interactive               (PH)+61-2-9288-3635
2 Holt Street Surry Hills      (FX)+61-2-9288-3171
NSW Australia 2010            http://www.ni.com.au
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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

Date: Wed, 21 May 1997 03:27:34 -0400
From: Kendal Van Dyke <kendal@freenet.tlh.fl.us>
Subject: Perl and CGI
Message-Id: <3382A3E6.79B3@freenet.tlh.fl.us>

I'm new to the newsgroup (and perl actaully), so forgive me if this is
off-subject (not sure which of the perl newsgroups was the correct one
for this), but I need a quick bit of programming help.

I'm writing a Java applet that uses a Perl script on the server to
retrieve a URL and spit it's contents out back to the applet (Necessary
since the URL is different from the original server where the applet
comes from, so I have to work my way around browser security using the
script). Anyways, I'm using lynx to get the contents of the URL and dump
it to a local file I can work with. The line of code giving me trouble
is this:

`/usr/local/bin/lynx -dump
http://www.nws.fsu.edu/data/text/roundup/ASUS42.KMIA > ASUS42.KMIA';

(all one line of course). The problem I'm having is that when I run it
from a command prompt it runs just fine, but when I run it as a cgi
script from a browser it doesn't ever create the file locally on my
server. I suppose I am calling the command line function wrong or
something, I dunno. That's where I figured someone in this newsgroup
could shed some light on the situation. If you need to see the script in
it's entirety it can be found at www.cs.fsu.edu/~vandyke/cgi-bin

Thanks!!
-- 
    *.........................................*
    .                |/                       .
    .                |\ENDAL                  .
    . WWW   => http://www.cs.fsu.edu/~vandyke .
    . EMail => vandyke@cs.fsu.edu             .
    . Pager => (904) 297-6658                 .
    .                                         .
    *.........................................*


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

Date: Tue, 20 May 1997 00:27:46 GMT
From: John Bosch <jbosch@tid.cdscc.nasa.gov>
Subject: Re: running ftp in Perl script
Message-Id: <3380F002.4B291791@tid.cdscc.nasa.gov>

cedric tio wrote:
> 
> I need to ftp a file from another server while running a Perl program. Does
> anyone know how I can pass arguments to the ftp program while running a
> Perl program? Is it possible for the Perl program to supply the user
> account name, password, and ftp commands to the ftp program so that the
> user does not have to enter anything.
> I am working on a Unix X-terminal.
> Thanx.

Here is an extract from a perl script I wrote to do exactly this :

# FTP the schedule from JPL
if( $ARGV[0] ne "NOFTP" ) {
        chdir $ROOT_DIRECTORY."downloads";
        open( GET, "| ftp -n -i 137.79.62.111" );
        print GET "user anonymous hello\n";
        print GET "cd /dsn/nss/sch\n";
        print GET "mget 7dayss.w*\n";
        print GET "mget forecast.w*\n";
        print GET "mget planning.w*\n";
        print GET "dir * modtime.dat\n";
        print GET "bye\n";
        close(GET);
}

Just open FTP as an output pipe and start printing your commands to it.


-- 

regards,

John Bosch
Electrical Engineer
Canberra Deep Space Communications Complex

email : jbosch@tid.cdscc.nasa.gov
        John.R.Bosch@jpl.nasa.gov
www :   http://tid.cdscc.nasa.gov/~jbosch

=====================================================
~!


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

Date: 21 May 1997 11:26:41 GMT
From: ken@digitas.harvard.edu (Ken Shan)
Subject: Simultaneous HTTP requests: LWP? Raw sockets?
Message-Id: <5lum5h$n84$1@news.fas.harvard.edu>

Hello,

For performance reasons, I'd like to make multiple HTTP requests at
once, in a single process and a single Perl script (without forking).
It seems that libwww-perl is unable to do this.  Do I have to resort
to raw IO::Socket, or is there some easier way or existing module
which I can reuse?

Thanks in advance.

--
Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig
I don' reck'n ah am not goin'ta kiall nobady. Um hmm.


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

Date: 21 May 1997 14:09:39 +0200
From: Gisle Aas <aas@bergen.sn.no>
Subject: Re: Simultaneous HTTP requests: LWP? Raw sockets?
Message-Id: <hiv0dauws.fsf@bergen.sn.no>

ken@digitas.harvard.edu (Ken Shan) writes:

> For performance reasons, I'd like to make multiple HTTP requests at
> once, in a single process and a single Perl script (without forking).
> It seems that libwww-perl is unable to do this.  Do I have to resort
> to raw IO::Socket, or is there some easier way or existing module
> which I can reuse?

Check out http://www.cs.washington.edu/homes/marclang/ParallelUA/

-- 
Gisle Aas <aas@sn.no>


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

Date: 21 May 1997 04:54:42 -0700
From: Dmitry
Subject: Software developing
Message-Id: <5lunq2$ciq@drn.zippo.com>

To decrease your expanses on software developing more then four times is now easy! Now the better choice available! You placing an order at Everest and having the four times down payment.

Everest Research: Increase your income now!

http://www.kaluga.com/users/everest  

everest_main@hotmail.com 




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

Date: 21 May 1997 04:50:35 -0700
From: Dmitry
Subject: Software developing
Message-Id: <5lunib$bms@drn.zippo.com>

To decrease your expanses on software developing more then four times is now easy! Now the better choice available! You placing an order at Everest and having the four times down payment.


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

Date: 21 May 1997 12:08:52 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Split function
Message-Id: <5luokk$h3m@news-central.tiac.net>

In article <5ltgil$4ah@sdcc13.ucsd.edu>, Greg <galoi@sdcc13.ucsd.edu> wrote:
>I am new to perl and am a little confused as to how the split
>functin works.  In particular I am trying to spilt up a string by
>the characters / and : and by whitespace.  I have not found a nifty
>way to do this.

  $string = 'this has a/few:fields in:it';
  @f = split (m{/[\s:/]}, $string);

leaves @f containing ('this', 'has', 'a', 'few', 'fields', 'in', 'it') 
which splits on single whitespace characters (so 2 spaces would have a
null field in between them) : and /.  If you want to allow multiple whit
space characters to be treated as a single delimiter then

  @f = split m{(?:[:/]|\s+)}, $string;

might be more use.  The perlre man page explains the regular expressions -
the (?: ... ) grouping only parentheses are new in recent perls.

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: Wed, 21 May 1997 12:36:49 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: Split function
Message-Id: <adelton.864218209@aisa.fi.muni.cz>

galoi@sdcc13.ucsd.edu (Greg) writes:

> I am new to perl and am a little confused as to how the split
> functin works.  In particular I am trying to spilt up a string by
> the characters / and : and by whitespace.  I have not found a nifty
> way to do this.

	split m![/:\s]!;
or
	split m![/:\s]+!;

The m// thing will match certain portions of the string and those will
be cut out and the string will be splitted on them. You specify the
portions as regular regular expressions. What's th edifference between
those two? Consider the following code:

$ perl -n
@a = split m![/:\s]!;
$" = "; ";
print "@a\n";
__END__

Input		one/two. three/four: five
will print	one; two.; three; four; ; five

The regular expression matches '/', space, '/', ':', and space and those
are the delimiters. Now if you use the second version m![/:\s]+!; for

input		one/two. three/four: five
you get		one; two.; three; four; five

where the matched substrings are '/', space, '/' and string ': '.
That's what the + does. You might need to polish the expression to you
needs but

I hope this helps.

--
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
                   I can take or leave it if I please
------------------------------------------------------------------------


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

Date: Mon, 19 May 1997 08:53:44 -0400
From: Paul Lussier <plussier@synnet.com>
To: "Andrew M. Langmead" <aml@world.std.com>
Subject: Re: What's the quickest way in perl to determine if a scalar is a list?
Message-Id: <Pine.GSO.3.96.970519083014.8859A-100000@pickett>

On Sun, 18 May 1997, Andrew M. Langmead wrote:

> [A copy of this article was e-mailed to the author of the referenced article]
> 
> Paul, in what way do you think your following code examples are better
> than the answer in the FAQ document?
> <http://www.perl.com/CPAN/doc/manual/html/pod/perlfaq4/How_can_I_tel_whether_an_aray_.html>

I never said my answers were better than the FAQ.  As a matter of fact, I
never even said my answers were good, and I did suggest that the poster
refer to the manual.  Someone asked a question, and trying to be helpful,
I gave some simple examples of how the problem could be solved.  If the
reader chooses to use examples obtained from Usenet, or the web, rather
than first consulting the manual or the FAQ, this is the risk they run.  I
tested the 3 examples with the search string the original poster gave, and
they worked.  Obviously any code will have to be tweaked and/or customized
to their specific purpose, since I cannot know exactly their intention,
but only have the simple example they posted to go  on.

> Besides, #1 could be an average of 50% faster if you put a "last"
> statement inside the "if". (Also a but faster if you said foreach
				     ^^^
	You mean a "bit"?

I did use a foreach.

> (@array). Array lookups are a little expensive, the implicit
> referencing done by foreach is cheap.)  Also, it would be faster if
> you put the /o modifier on the regular expression match.

Okay, didn't know about that one.  Thanks.

> #2 has a bug. "hi there" as a search string will match if "hi" and
> "there" are consecutive elements of the array. (And don't try to fix
> it by changing the separater characters. Any separater you change to,
> I can change $string to match it.)

Hmmm, I didn't think of that one.  Then again, if it were me writing the
program, I probably wouldn't choose to do it that way.  It was just an
example of "TMTOWTDI".

> #3 has a bug. The syntax of grep in "grep EXPR, LIST", not "grep RE,
> LIST". The expression "$string" will either always be true (if $string
> contains a boolean true value), or always false. 

Oops.  Thanks, no wonder it worked :)

> It also could use help from the /o modifier.

Most of my regex matches could probably benefit from the /o modifier,
especially since I never really knew it was there :)  Thanks for telling
me about it.
 
> All of your solutions have the bug that occurs when $string contains
> regular expression metacharacters.

Well, like I said, I never guaranteed that they were perfect.  I also
don't often encounter the need to match strings that have embedded
metacharacters, nor did the original poster mention that this was a
concern.  My examples were not meant to be the most robust, works for
every imaginable or conceivable character combination type of solution.
But rather, simple examples of how it "could" be done so the poster could
have something they could then look up in the manual.  Sometimes it's
quite difficult to find a solution if you don't have anything to go on.

Thanks for taking the time to point out my mistakes though.  I love it
when some one can show me mistakes, since that will help me write better
code in the future.

Seeya,
Paul
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- Paul Lussier		=   It is a good day	=The next best thing to doing -
= 3Com S2 Division	-    to put slinkies	-something smart is not doing =
- plussier@synnet.com	=     on escalators	=      something stupid.      -
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
     =			      Interesting trivia:			-
     -   If you took all the sand in North Africa and spread it out	=
     =		 ...it would cover the entire Sahara desert.		-
      -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=




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

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

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