[11059] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4659 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 15 12:07:18 1999

Date: Fri, 15 Jan 99 09:00:18 -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           Fri, 15 Jan 1999     Volume: 8 Number: 4659

Today's topics:
        BUG in perl 5.00502? (Brian Wheeler)
    Re: cat filename | wc -l   perl equivalent <tbriles@austin.ibm.com>
    Re: cat filename | wc -l   perl equivalent <garethr@cre.canon.co.uk>
    Re: does globbing remember? (Greg Bacon)
    Re: does globbing remember? (Bart Lateur)
    Re: Fork me! need children <dgris@moiraine.dimensional.com>
        Getting port info from socket calls on NT? <guyrj@an.hp.com>
    Re: glob error (Tad McClellan)
    Re: How can I send mail with file ? (Bo Meyer)
    Re: Losing linefeeds when encrypting email [SOLUTION] <james@MatadorDesign.com>
    Re: mod_perl/images problem frogsmock@my-dejanews.com
    Re: Perl Criticism (Richard Clamp)
    Re: Regex challenge (Sean McAfee)
    Re: Regex challenge <garethr@cre.canon.co.uk>
    Re: Regex challenge (Larry Rosler)
    Re: Searching a string, with a headache <allan@due.net>
    Re: sockets: server-side problem (Greg Bacon)
    Re: sort 2-dim array (Andrew M. Langmead)
    Re: Stopping <ctrl>-c during perl Scripts (win32) (Clay Irving)
    Re: Treating Strings as FILEHANDLES (Tad McClellan)
    Re: Treating Strings as FILEHANDLES <garethr@cre.canon.co.uk>
        tricky question.. possible??? <outline@p3.net>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 15 Jan 1999 16:03:18 GMT
From: bdwheele@educ.indiana.edu (Brian Wheeler)
Subject: BUG in perl 5.00502?
Message-Id: <77nos6$7q8$1@jetsam.uits.indiana.edu>


This works in 5.00404, but fails under 5.00502.  I wrap a phrase with 'z's and
change spaces to underlines.  after I do some processing, I remove the z's and
underlines to get back the original text. 

Thanks!
Brian Wheeler
bdwheele@indiana.edu



########### file begins here ######################
$data=join("",<DATA>);
$data=~s/\n/ /g;
$NAME="ACCOUNTANTS AND AUDITORS";


$data=~s/($NAME)/"z".&uline($1)."z"/gie;
$uname=&uline($NAME);
$data=~s/z($uname)\z/&uuline($1)/gie;

print "data: $data\n";

sub uline { my ($foo)=@_; $foo=~s/\s/_/g; return $foo; }
sub uuline { my ($foo)=@_; $foo=~s/_/ /g; return $foo; }

__END__
Accountants and auditors keep track of financial matters.
Accountants and auditors prepare, analyze, and check 
financial information. They
prepare reports or taxes based
on the information they have.
Many accountants and auditors
do their work on a computer.
There are four major fields in accounting public, management,
government, and internal auditing. Accountants share some tasks
across these four fields. However, they work for different clients
and have some unique tasks. Within each of the four fields,
accountants often specialize in one area


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

Date: Fri, 15 Jan 1999 09:10:55 -0600
From: Tom Briles <tbriles@austin.ibm.com>
Subject: Re: cat filename | wc -l   perl equivalent
Message-Id: <369F5A7F.F44CDC21@austin.ibm.com>

Abigail wrote:

> Greg Bacon (gbacon@itsc.uah.edu) wrote on MCMLXII September MCMXCIII in
> <URL:news:77lo97$btp$1@info.uah.edu>:
> ;;
> ;; : I need a perl equivalent command for the following:
> ;; : cat filename | wc -l
> ;;
> ;;     #! /usr/bin/perl -w
> ;;     $lines++ while <>;
> ;;     print $lines, "\n";
>
>         perl -wlpe '}$_=$.;{' filename
>
> Abigail

Now that's cool.

Never had I been forced to understand so many perlvars by a single line.

- Tom



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

Date: Fri, 15 Jan 1999 15:32:25 GMT
From: Gareth Rees <garethr@cre.canon.co.uk>
Subject: Re: cat filename | wc -l   perl equivalent
Message-Id: <silnj4ft6e.fsf@cre.canon.co.uk>

Abigail <abigail@fnx.com> wrote:
> perl -wlpe '}$_=$.;{' filename

I think

  perl -wne 'END{print $.}' filename

though slightly longer, is a lot clearer.

-- 
Gareth Rees


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

Date: 15 Jan 1999 15:50:24 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: does globbing remember?
Message-Id: <77no40$qer$3@info.uah.edu>

In article <369EF629.63B7@jps.net>,
	Trent <trent@jps.net> writes:
: globbing-
: 
: I can open a series of text files and place the contents
: into an array, but is it possible to recover/identify what
: lines came from which original file? I'm thinking a hash,
: but then again I'm fairly new at this.

I'm not really sure what your question has to do with globbing (unless
you're invoking your program as `prog *.txt' or something).  Would
something like this work?

   #! /usr/bin/perl -w

   use strict;

   my %contents;

   foreach my $file (@ARGV) {
       unless (open FILE, $file) {
           warn "$0: failed open $file: $!\n";
           next;
       }

       local $/;

       $contents{$file} = <FILE>;
   }

Greg
-- 
Sam:  What'd you like, Normie? 
Norm: A reason to live. Gimmie another beer. 


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

Date: Fri, 15 Jan 1999 16:10:17 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: does globbing remember?
Message-Id: <36a167c2.9131995@news.skynet.be>

Trent wrote:

>I can open a series of text files and place the contents
>into an array, but is it possible to recover/identify what
>lines came from which original file? I'm thinking a hash,
>but then again I'm fairly new at this.

You mean coming from (<>)? Yeah, sure, just inspect the $ARGV variable.

   HTH,
   Bart.


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

Date: 15 Jan 1999 08:48:57 -0700
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: Fork me! need children
Message-Id: <m3ogo0h6za.fsf@moiraine.dimensional.com>

jim <webmaster@link-maker.com> writes:

>    hehe, I'd like a good reference to learn more about forking in perl...

fork() is perl has identical semantics to the underlying fork(2) call
of the unix box you are using.  Try man 2 fork for more details.

> I'm sure some one knows an excellent site or faq..or..book?

Advanced Programming in the Unix Environment
W. Richard Stevens
Addison-Wesely
1992
ISBN: 0201563177

dgris
-- 
Daniel Grisinger          dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print 
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'


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

Date: Fri, 15 Jan 1999 09:55:39 -0500
From: Guy <guyrj@an.hp.com>
Subject: Getting port info from socket calls on NT?
Message-Id: <369F56EB.EA4@an.hp.com>

I'm using perl 5.00502 on Win NT 4.0 sp3 
When I call &accept or &getpeername the sockaddr returned contains the 
IP address but the port is always '0', in this case I'm connecting on
port 58912.
Also calling getpeername after the connection is broken at the client
side results in the same info being returned.
code looks like:

$fh = new FileHandle '/dev/null';
$client_addr = accept($fh, $socket);
($port, $ip_addr) = &sockaddr_in($client_addr);
$ip_addr = &inet_ntoa($ip_addr);

and like

($port, $ip_addr) = sockaddr_in(gerpeername($fh));
$ip_addr = &inet_ntoa($ip_addr);

this code is being ported to WinNT from a unix system (where it works)

TIA Guy


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

Date: Fri, 15 Jan 1999 07:59:36 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: glob error
Message-Id: <8khn77.9ig.ln@magna.metronet.com>

Etienne Pollard (not@giving.it.out) wrote:
: I have the following code:

: !#/usr/bin/perl -w

: @another = </home/webroot*>;
                          ^^

   So you _want_ to find only files/dirs in /home that start with
   'webroot'?

   Or do you want to find files/dirs _within_ webroot's home?

   If the second, then you have specified the wrong glob:

      @another = </home/webroot/*>;
                               ^

   ???


: foreach (@another) {
:     print "$_\n";
: }

: When I run it I get the following error:

: Can't modify not in scalar assignment at glob.pl line 3, near
: "</home/webroot*>;"
: Execution of glob.pl aborted due to compilation errors.

: I'm running Red Hat Linux 5.02, Perl 5.004.

: I can't see anything wrong with this code and would really appreciate
: some assistance on this.


   Neither can I.

   Are you _certain_ that that is the same exact code?

   You cut/pasted it into this article, or you typed it in?


   You don't _have_ any scalar assignments in the above code.
   (other than the implied one to $_ in the foreach, and you
    are certainly allowed to modify that...
   )

   You don't have any "not"s either.

   We have entered the Twilight Zone...


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Fri, 15 Jan 1999 15:50:05 GMT
From: bmeyer@relief.dk (Bo Meyer)
Subject: Re: How can I send mail with file ?
Message-Id: <369f6398.448329695@news.euroconnect.dk>

On Tue, 05 Jan 1999 01:02:45 +0800, Mecer <k25@ms4.hinet.net> wrote:

>I want to send mail with mail...
>But I don't know how to use any module or function to
>compress files with base64...
>Is there any module or function which can do this ?
>How to decompress files ?
>Please teach me...Thanks...

PerlFAQ:

How do I decode a MIME/BASE64 string? 

The MIME-tools package (available from CPAN) handles this and a lot
more. Decoding BASE64 becomes as simple as: 

    use MIME::base64;
    $decoded = decode_base64($encoded);



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

Date: 15 Jan 1999 10:59:49 -0500
From: James Cameron <james@MatadorDesign.com>
Subject: Re: Losing linefeeds when encrypting email [SOLUTION]
Message-Id: <x7n23k8r2i.fsf@server.matadordesign.com>


Thanks to everyone who responded.  The solution is to turn on the
"text mode" option with the "-t" flag.  Even though I had ASCII
armoring on, it was the "-t" flag that resolved the carriage
return/linefeed problem.

Thanks again!

-James Cameron  
Matador Design, Inc.
http://www.MatadorDesign.com



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

Date: Fri, 15 Jan 1999 15:35:20 GMT
From: frogsmock@my-dejanews.com
Subject: Re: mod_perl/images problem
Message-Id: <77nn7n$ccj$1@nnrp1.dejanews.com>

For what it's worth, this was a configuration problem.	I had set httpd.conf
such that mod_perl would handle everything in /web/docs.  But I didn't
realize that it would try to handle EVERYTHING.  I had my perl scripts AND
images there, so mod_perl was trying to process the images instead of just
serving them up. When I changed httpd.conf so that mod_perl would kick in
based on file extension instead of file location, the images started
appearing fine.

In article <770lja$8v8$1@nnrp1.dejanews.com>,
  frogsmock@my-dejanews.com wrote:
> Folks,
>
> I am having a problem getting images to load in my mod_perl-generated web
> pages . . . At first I thought it was Apache, and I had posted this to
> comp.infosystems.www.servers.unix:
>
> -------
> I am having a problem getting Apache to serve up images (I'm running Apache
> 1.3.3 on RedHat Linux 5.1 w/ mod_perl installed). When I try to call up a page
> in Navigator that includes images, they fail to load. Apache reports the
> following in error_log (my image is "lm.gif"):
>
> lm.gif: Unrecognized character \030 at /web/docs/lm.gif line 1.
>
> However, the GIF loads fine in the GIMP, so I don't think the image itself is
> the problem.  Any ideas?
> -------
>
> I received a reply, "I don't think that's an Apache error. My guess is you
> have accidentally configured your server to execute the file."	While
this
> may be true, I'm afraid I'm still at a loss.  Does anyone recoginize this
> problem, or know how I can tweak my setup to load GIFs or JPGs properly?
>
> Thanks!
>
> Jim
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own
>

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Fri, 15 Jan 1999 16:25:30 GMT
From: richardc@tw2.com (Richard Clamp)
Subject: Re: Perl Criticism
Message-Id: <36a06b1a.10316966@news.highwayone.net>

On Thu, 14 Jan 1999 16:17:42 GMT, droby@copyright.com wrote:

>Perlers who think saving keystrokes is the ultimate goal?  Where?  Any of you
>guys think that?

Think it no, though it's occasionally been a game I've played with
myself.  
When  I do it's in the same context as an artist who makes a portrait
out of toast squares.  There for the challenge and fun of doing it,
not as a matter of course.

Damnit, and I so wanted to avoid this thread...

Richard
-- 
Richard Clamp         richardc@tw2.com
Frisbeetarianism, n.:
        The belief that when you die, your soul goes up on the roof and gets stuck


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

Date: Fri, 15 Jan 1999 15:08:46 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: Regex challenge
Message-Id: <2SIn2.2323$Ge3.10478046@news.itd.umich.edu>

In article <slrn79ueln.2m2.eric@eric.nafex.com>,
Eric Smith <eric@nafex.com> wrote:
>1) I want to match a word, say `table' but the character \& or ampersand
>can appear anywhere in table so all these are legal:
>\&table
>t\&able
>ta\&ble
>... [snip] ...
>table\&

>any elegant solutions for my regex?

I can't think of a single suitable regex, but:

$str = "tab&le"; # or "&table", or "tabl&e", etc.
$n = ($newstr = $str) =~ tr/&//d;
print "Match!" if $newstr eq "table" && $n == 1;

>2) I want to march a lower case, upper case or mixed word and _replace_ it
>with the same case layout in the new word

>Table becomes Chair
>TABLE becomes CHAIR
>table becomes chair

$from = "Table"; # or TABLE, or table, etc;
$to = "chair";

# Method 1:
$i = 0;
foreach (split /(?<=[A-Z])(?=[a-z])|(?<=[a-z])(?=[A-Z])/, $from) {
	$r = \substr($to, $i, length);
	$$r = /[A-Z]/ ? "\U$$r" : "\L$$r";
	$i += length;
}

# Method 2:
do {
	$r = \substr($to, $_, 1);
	$$r = substr($from, $_, 1) =~ /[A-Z]/ ? "\U$$r" : "\L$$r";
} foreach 0 .. length($from) - 1;

I shan't include a benchmark, as I imaging the results would depend heavily
on the string to be transformed.

(Neither method guaranteed to work with non-English character sets.)

>thanx guys. 
>this list is so big, so please cc me in case I miss a gem.

Sorry, I can't do that.

-- 
Sean McAfee | GS d->-- s+++: a26 C++ US+++$ P+++ L++ E- W+ N++ |
            | K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
            | tv+ b++ DI++ D+ G e++>++++ h- r y+>++**          | umich.edu


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

Date: Fri, 15 Jan 1999 15:56:29 GMT
From: Gareth Rees <garethr@cre.canon.co.uk>
Subject: Re: Regex challenge
Message-Id: <siiue8fs2a.fsf@cre.canon.co.uk>

Eric Smith <eric@nafex.comi> wrote:
> I want to match a word, say `table' but the character \& or ampersand
> can appear anywhere in table [...] any elegant solutions for my regex?

You need to be a bit more precise about what exactly you're prepared to
admit.  The regular expression

    ^(?:(?:\w|(&))(?!\1))+$

matches a string containing only alphamunders (\w) and zero or one
ampersands (&).  (Note that it'll match the string '&'.)  The regular
expression

    (?:\A|\s)(?:(?:\w|(&))(?!\1))+(?:\Z|\s)

matches a string containing a "word" consisting of alphamunders and zero
or one ampersands, delimited by whitespace or the ends of the string.

-- 
Gareth Rees


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

Date: Fri, 15 Jan 1999 08:15:14 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Regex challenge
Message-Id: <MPG.1109096ea193a14a989992@nntp.hpl.hp.com>

[This followup was posted to comp.lang.perl.misc and a copy was sent to 
the cited author.]

In article <slrn79ueln.2m2.eric@eric.nafex.com>, eric@nafex.comi says...
> Hi perl
> 
> Double barrelled s/gun/question/ ;)
> 
> 1) I want to match a word, say `table' but the character \& or ampersand
> can appear anywhere in table so all these are legal:

 ... I can't improve on Sean McAfee's solution.

> 2) I want to march a lower case, upper case or mixed word and _replace_ it
> with the same case layout in the new word

The following will work in any locale:

my $in = 'TaBlE';
my $xx = 'chair';

my @a = split //, $xx;
my $out = join "",
          map { uc eq $_ ? uc shift @a : lc shift @a }
          split //, $in;

produces 'ChAiR'.  There should of course be tests for differing lengths 
of the datum and the 'case-key'.

> this list is so big, so please cc me in case I miss a gem.

No problem for me, as you didn't munge your e-mail address.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 15 Jan 1999 15:51:39 GMT
From: "Allan M. Due" <allan@due.net>
Subject: Re: Searching a string, with a headache
Message-Id: <77no6b$cs2$0@206.165.165.143>

Giga Tron wrote in message <369f3db0.2660665@news.mtt.net>...
:Hi fellow nerds,
:I have a unique situation,
:I have to read a file that can be any size, and contain unstructured
:data. The file could be like this.
:stuff|morestuff*morestuff*morestuff*morestuff|evenmorestuff*evenmorestuff|stu
ff|morestuff*morestuff*morestuff*morestuff|evenmorestuff*evenmorestuff|stuff|m
orestuff*morestuff*morestuff*morestuff|evenmorestuff*evenmorestuff|
:Notice | and *
:The | specifies the beginning of a record, and the * specifies a field
:in a record. The tricky thing is to be capable to read the file until
:a | occurs, count the number of spaces and return that value to a sub
:routine. Say the value was 6. The good thing is that all records are
:one size only, and there are only about twenty. So depending on the
:size between the | a sub is run that collects the info between the |
:and puts then into a scalar.
:Then I must continue the search for the | and get the number of spaces
:between the last | and the one just found. I see a few ways of doing
:this but was wondering if there are a few PERL junkies that could
:suggest some code to make it work smoother.


Well if you just want the data separted out by fields how about:

my $data =
'stuff|morestuff*morestuff*morestuff*morestuff|evenmorestuff*evenmorestuff|stu
ff|morestuff*morestuff*morestuff*morestuff|evenmorestuff*evenmorestuff|stuff|m
orestuff*morestuff*morestuff*morestuff|evenmorestuff*evenmorestuff|';
my @fields = map {split /\*/} split /\|/,$data;

Or you could throw the data in a hash of lists:

my %the_data;
my $i = 0;
foreach  (split /\|/,$data) {
   $the_data{$i} = [split /\*/];
   $i++;
}

And the access it like:
foreach my $keys (keys %the_data) {
    print "The data in key: $keys is :@{$the_data{$keys}}\n";
}

if you really want the lengths how about getting them all at once.

my @lengths = map {length} split /\|/,$data;

HTH

AmD




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

Date: 15 Jan 1999 15:46:47 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: sockets: server-side problem
Message-Id: <77nnt7$qer$2@info.uah.edu>

In article <77mred$bv7$1@tempo.news.iphil.net>,
	"Benjamin" <bench@surfshop.net.ph> writes:
: How do I handle the escape character "^]" when a client tries to
: connect to the server using "telnet  port#" and types the escape
: character and at the prompt " > quit " ?

There will be activity on the socket associated with that client, but
there will be no data to read.

ObPerl: I wrote a little module to check for the amount of data waiting
to be read on a socket (using the FIONREAD ioctl).  Enjoy:

#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.2).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 1999-01-15 09:42 CST by <gbacon@ettsn>.
# Source directory was `/home/gbacon/src/perl'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode       name
# ------ ---------- ------------------------------------------
#    628 -rw-r--r-- Fionread/Fionread.xs
#   1113 -rw-r--r-- Fionread/Fionread.pm
#    377 -rw-r--r-- Fionread/Makefile.PL
#    653 -rw-r--r-- Fionread/test.pl
#    121 -rw-r--r-- Fionread/Changes
#     60 -rw-r--r-- Fionread/MANIFEST
#
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=FAILED
locale_dir=FAILED
first_param="$1"
for dir in $PATH
do
  if test "$gettext_dir" = FAILED && test -f $dir/gettext \
     && ($dir/gettext --version >/dev/null 2>&1)
  then
    set `$dir/gettext --version 2>&1`
    if test "$3" = GNU
    then
      gettext_dir=$dir
    fi
  fi
  if test "$locale_dir" = FAILED && test -f $dir/shar \
     && ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
  then
    locale_dir=`$dir/shar --print-text-domain-dir`
  fi
done
IFS="$save_IFS"
if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
then
  echo=echo
else
  TEXTDOMAINDIR=$locale_dir
  export TEXTDOMAINDIR
  TEXTDOMAIN=sharutils
  export TEXTDOMAIN
  echo="$gettext_dir/gettext -s"
fi
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
  shar_touch=touch
else
  shar_touch=:
  echo
  $echo 'WARNING: not restoring timestamps.  Consider getting and'
  $echo "installing GNU \`touch', distributed in GNU File Utilities..."
  echo
fi
rm -f 1231235999 $$.touch
#
if mkdir _sh21881; then
  $echo 'x -' 'creating lock directory'
else
  $echo 'failed to create lock directory'
  exit 1
fi
# ============= Fionread/Fionread.xs ==============
if test ! -d 'Fionread'; then
  $echo 'x -' 'creating directory' 'Fionread'
  mkdir 'Fionread'
fi
if test -f 'Fionread/Fionread.xs' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'Fionread/Fionread.xs' '(file already exists)'
else
  $echo 'x -' extracting 'Fionread/Fionread.xs' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'Fionread/Fionread.xs' &&
#ifdef __cplusplus
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#ifdef __cplusplus
}
#endif
X
#include <sys/ioctl.h>
#include <sys/filio.h>
X
#ifdef PerlIO
typedef PerlIO * InputStream;
#else
typedef FILE * InputStream;
#endif
X
MODULE = Fionread		PACKAGE = Fionread		
X
SV *
chars_ready(io)
X    InputStream io;
X    PREINIT:
X    int i = 0;
X    CODE:
X    ST(0) = sv_newmortal();
X    if (!io) {
X        ST(0) = &sv_undef;
X    }
X    else {
X        if (ioctl(PerlIO_fileno(io), FIONREAD, &i) == -1) {
X            ST(0) = &sv_undef;
X        }
X        else {
X            sv_setiv(ST(0), i);
X        }
X    }
SHAR_EOF
  $shar_touch -am 0522160797 'Fionread/Fionread.xs' &&
  chmod 0644 'Fionread/Fionread.xs' ||
  $echo 'restore of' 'Fionread/Fionread.xs' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'Fionread/Fionread.xs:' 'MD5 check failed'
d1bb5a95aca0789542e281bff07cb1cc  Fionread/Fionread.xs
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'Fionread/Fionread.xs'`"
    test 628 -eq "$shar_count" ||
    $echo 'Fionread/Fionread.xs:' 'original size' '628,' 'current size' "$shar_count!"
  fi
fi
# ============= Fionread/Fionread.pm ==============
if test -f 'Fionread/Fionread.pm' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'Fionread/Fionread.pm' '(file already exists)'
else
  $echo 'x -' extracting 'Fionread/Fionread.pm' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'Fionread/Fionread.pm' &&
package Fionread;
X
use strict;
use Carp;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD);
X
require Exporter;
require DynaLoader;
X
@ISA = qw(Exporter DynaLoader);
@EXPORT_OK = qw( chars_ready );
$VERSION = '0.01';
X
bootstrap Fionread $VERSION;
X
1;
X
__END__
X
=head1 NAME
X
Fionread - Perl extension to make an FIONREAD ioctl
X
=head1 SYNOPSIS
X
X    use Fionread qw( chars_ready );
X    use IO::Socket;
X
X    $socket = IO::Socket::INET->new(PeerAddr => 'www.perl.org',
X                                    PeerPort => http(80),
X                                    Proto    => 'tcp');
X
X    $len = chars_ready $socket;
X
=head1 DESCRIPTION
X
&Fionread::chars_ready uses the FIONREAD ioctl function to determine
how many characters are waiting to be read on a given socket.  It is
exactly equivalent to the following C code:
X
X    ioctl(fd, FIONREAD, &len);
X    return len;
X
=head1 DIAGNOSTICS
X
If it doesn't like the C<IO::Handle> or C<FileHandle> you pass it, or
the ioctl call fails, &Fionread::chars_ready returns undef.
X
=head1 AUTHOR
X
Greg Bacon, gbacon@cs.uah.edu
X
=head1 SEE ALSO
X
L<IO::Socket>, L<Socket>
X
=cut
SHAR_EOF
  $shar_touch -am 0601151797 'Fionread/Fionread.pm' &&
  chmod 0644 'Fionread/Fionread.pm' ||
  $echo 'restore of' 'Fionread/Fionread.pm' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'Fionread/Fionread.pm:' 'MD5 check failed'
b13b8e49fb10f8126d6d389e475e21ed  Fionread/Fionread.pm
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'Fionread/Fionread.pm'`"
    test 1113 -eq "$shar_count" ||
    $echo 'Fionread/Fionread.pm:' 'original size' '1113,' 'current size' "$shar_count!"
  fi
fi
# ============= Fionread/Makefile.PL ==============
if test -f 'Fionread/Makefile.PL' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'Fionread/Makefile.PL' '(file already exists)'
else
  $echo 'x -' extracting 'Fionread/Makefile.PL' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'Fionread/Makefile.PL' &&
use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
X    'NAME'	=> 'Fionread',
X    'VERSION_FROM' => 'Fionread.pm', # finds $VERSION
X    'LIBS'	=> [''],   # e.g., '-lm' 
X    'DEFINE'	=> '',     # e.g., '-DHAVE_SOMETHING' 
X    'INC'	=> '',     # e.g., '-I/usr/include/other' 
);
SHAR_EOF
  $shar_touch -am 0522142697 'Fionread/Makefile.PL' &&
  chmod 0644 'Fionread/Makefile.PL' ||
  $echo 'restore of' 'Fionread/Makefile.PL' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'Fionread/Makefile.PL:' 'MD5 check failed'
816de964553f8faf34af75ac7871c86e  Fionread/Makefile.PL
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'Fionread/Makefile.PL'`"
    test 377 -eq "$shar_count" ||
    $echo 'Fionread/Makefile.PL:' 'original size' '377,' 'current size' "$shar_count!"
  fi
fi
# ============= Fionread/test.pl ==============
if test -f 'Fionread/test.pl' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'Fionread/test.pl' '(file already exists)'
else
  $echo 'x -' extracting 'Fionread/test.pl' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'Fionread/test.pl' &&
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'
X
######################### We start with some black magic to print on failure.
X
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
X
BEGIN { $| = 1; print "1..1\n"; }
END {print "not ok 1\n" unless $loaded;}
use Fionread;
$loaded = 1;
print "ok 1\n";
X
######################### End of black magic.
X
# Insert your test code below (better if it prints "ok 13"
# (correspondingly "not ok 13") depending on the success of chunk 13
# of the test code):
X
SHAR_EOF
  $shar_touch -am 0522142697 'Fionread/test.pl' &&
  chmod 0644 'Fionread/test.pl' ||
  $echo 'restore of' 'Fionread/test.pl' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'Fionread/test.pl:' 'MD5 check failed'
c17b63846ad5e5fbb4f20075d2e4fcdb  Fionread/test.pl
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'Fionread/test.pl'`"
    test 653 -eq "$shar_count" ||
    $echo 'Fionread/test.pl:' 'original size' '653,' 'current size' "$shar_count!"
  fi
fi
# ============= Fionread/Changes ==============
if test -f 'Fionread/Changes' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'Fionread/Changes' '(file already exists)'
else
  $echo 'x -' extracting 'Fionread/Changes' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'Fionread/Changes' &&
Revision history for Perl extension Fionread.
X
0.01  Thu May 22 14:26:56 1997
X	- original version; created by h2xs 1.18
X
SHAR_EOF
  $shar_touch -am 0522142697 'Fionread/Changes' &&
  chmod 0644 'Fionread/Changes' ||
  $echo 'restore of' 'Fionread/Changes' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'Fionread/Changes:' 'MD5 check failed'
f89729297001f8a6085d2e0d89a9f558  Fionread/Changes
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'Fionread/Changes'`"
    test 121 -eq "$shar_count" ||
    $echo 'Fionread/Changes:' 'original size' '121,' 'current size' "$shar_count!"
  fi
fi
# ============= Fionread/MANIFEST ==============
if test -f 'Fionread/MANIFEST' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'Fionread/MANIFEST' '(file already exists)'
else
  $echo 'x -' extracting 'Fionread/MANIFEST' '(binary)'
  sed 's/^X//' << 'SHAR_EOF' | uudecode &&
begin 600 Fionread/MANIFEST
M0VAA;F=E<PI&:6]N<F5A9"YP;0I&:6]N<F5A9"YX<PI-04Y)1D535`I-86ME
/9FEL92Y03`IT97-T+G!L
`
end
SHAR_EOF
  $shar_touch -am 0522142697 'Fionread/MANIFEST' &&
  chmod 0644 'Fionread/MANIFEST' ||
  $echo 'restore of' 'Fionread/MANIFEST' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'Fionread/MANIFEST:' 'MD5 check failed'
cb32e14f9c17fe336d8317f200e0dd6e  Fionread/MANIFEST
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'Fionread/MANIFEST'`"
    test 60 -eq "$shar_count" ||
    $echo 'Fionread/MANIFEST:' 'original size' '60,' 'current size' "$shar_count!"
  fi
fi
rm -fr _sh21881
exit 0


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

Date: Fri, 15 Jan 1999 16:23:17 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: sort 2-dim array
Message-Id: <F5M06t.JH4@world.std.com>

Andreas Stauder <astauder@iiic.ethz.ch> writes:

>for example

>4	four	red
>2	two	green
>3	three	blue
>1	one	white

Assuming that you want to sort on the first column, and that you read
each row into an array of references to arrays, you could do something
like this:


#!/usr/bin/perl -w

my (@array,@sorted);

while(<DATA>) {
    push @array, [ split ' ' ];
}

# sort each row by the contents of its first element.
@sorted = sort { $a->[0] <=> $b->[0] } @array;

# sorted now contains new references to each row. Since they now point
# to the same data, use care when modifying either @sorted or @array.

for my $row (@sorted) {
    print "@$row\n";
}

__END__
4	four	red
2	two	green
3	three	blue
1	one	white

I'm not sure where you ran into problems. If it was with the
multidimensional data structures, you might want to look at the
perldsc and perllol man pages. If it was about creating sort
subroutines, you might want to look at either the sorting sections of
perlfaq4 or the "Far More Than Everything You Ever Wanted to Know
About Sorting" document at
<URL:http://www.perl.com/CPAN/doc/FMTEYEWTK/sorting>


-- 
Andrew Langmead


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

Date: 15 Jan 1999 11:55:23 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: Stopping <ctrl>-c during perl Scripts (win32)
Message-Id: <77nrtr$psm$1@panix.com>

In <369F5117.E0BAF4C6@cableregina.com> Gareth Jones <sheridan@cableregina.com> writes:

>I have a script I've written that I need all users to run.  I don't want
>them stopping it
>with a control - c or a control break.  Is there any way to do this?

>I will be running the scripts on evil 95 and NT stations.

# perldoc -q SIGNAL
=head1 Found in /usr/local/lib/perl5/5.00502/pod/perlfaq8.pod

=head2 How do I trap control characters/signals?

You don't actually "trap" a control character.  Instead, that character
generates a signal which is sent to your terminal's currently
foregrounded process group, which you then trap in your process.
Signals are documented in L<perlipc/"Signals"> and chapter 6 of the Camel.

Be warned that very few C libraries are re-entrant.  Therefore, if you
attempt to print() in a handler that got invoked during another stdio
operation your internal structures will likely be in an
inconsistent state, and your program will dump core.  You can
sometimes avoid this by using syswrite() instead of print().

Unless you're exceedingly careful, the only safe things to do inside a
signal handler are: set a variable and exit.  And in the first case,
you should only set a variable in such a way that malloc() is not
called (eg, by setting a variable that already has a value).

For example:

    $Interrupted = 0;   # to ensure it has a value
    $SIG{INT} = sub {
        $Interrupted++;
        syswrite(STDERR, "ouch\n", 5);
    }

However, because syscalls restart by default, you'll find that if
you're in a "slow" call, such as E<lt>FHE<gt>, read(), connect(), or
wait(), that the only way to terminate them is by "longjumping" out;
that is, by raising an exception.  See the time-out handler for a
blocking flock() in L<perlipc/"Signals"> or chapter 6 of the Camel.

-- 
Clay Irving
clay@panix.com


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

Date: Fri, 15 Jan 1999 08:45:45 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Treating Strings as FILEHANDLES
Message-Id: <pakn77.9ig.ln@magna.metronet.com>

dmulholl@cs.indiana.edu wrote:

:   I am writing to ask if there is a way I can use a string as
: a stream.  


   You don't need to.


: The scenario I have is a string that contains newlines
: (the string holds the contents of a whole file) and I would like
: to process it one line at a time.  


   Then you should save it as an array of lines as Rick suggests.

   Choosing the correct data structure can greatly simplify code.


: I would rather not split it
: up into an array (seems unduely memory consuming to have to
: copy the data).  Nor open an external shell (performance), so I
: *think* open(STRINGHANDLE, "echo $string |") is not an option either.

: What would be ideal might be:

:   while ( <$string> ) {

:    ...some processing...

:   }


   If you insist on slurping into a single scalar:


   while ( $string =~ /(.*\n)/g ) {
      $line = $1;

      ...some processing of $line...

   }


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Fri, 15 Jan 1999 15:40:01 GMT
From: Gareth Rees <garethr@cre.canon.co.uk>
Subject: Re: Treating Strings as FILEHANDLES
Message-Id: <sik8yofstq.fsf@cre.canon.co.uk>

dmulholl@cs.indiana.edu wrote:
> I am writing to ask if there is a way I can use a string as a stream.

Sure.  Use the IO::String module by Gisle Aas:

     The IO::String module provide the IO::File interface for
     in-core strings.  An IO::String object can be attached to a
     string, and will make it possible to use the normal file
     operations for reading or writing data, as well as seeking
     to various locations of the string.

The module requires Perl 5.005.
See http://www.perl.com/CPAN/modules/by-module/IO/IO-String-0.03.tar.gz

-- 
Gareth Rees


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

Date: Fri, 15 Jan 1999 11:57:43 -0500
From: "Paul Murphy" <outline@p3.net>
Subject: tricky question.. possible???
Message-Id: <77nruq$i1e$1@newsreader.jvnc.net>

I am wondering if anyone knows of a way with either perl or javascript to
read the location of a certain frame?  If i have a button on a top frame,and
a changing lower frame, i want the button when click to send the url to my
server of the lower frame.

ideas/suggestions would be greatly appreciated!!

i thought about trying to use referer somehow but couldn't figure a way to
use it for a page that is already displaying, since the botton wouldn't
actually be on that frame.

thanks,
paul





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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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