[8776] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2393 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 22 18:07:48 1998

Date: Wed, 22 Apr 98 15:00:34 -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, 22 Apr 1998     Volume: 8 Number: 2393

Today's topics:
    Re: 1st cgi script doesn't work <rootbeer@teleport.com>
    Re: ActiveStates vs. Standard Distribution (Jan Dubois)
        beginnings.... (Peter Kendal)
    Re: CGI-Mail Problem <qdtcall@esb.ericsson.se>
        Changing case of specific characters in string martinja@exis.net
        Count some word in a string. (Chao-cheng Huang)
    Re: Eat my dust - Perl running on Windows 95 <mindmore@mindless.com>
        float to hex conversion <rshipp@acclrx.com>
    Re: float to hex conversion <rootbeer@teleport.com>
    Re: Help sorting nested hashes by value (Sitaram Chamarty)
    Re: Help! <mindmore@mindless.com>
        How to read lines between two keywords in a file <peng@cae.cig.mot.com>
        if ($string eg "y") or if ($string == "y") <ynieh@fhcrc.org>
    Re: if ($string eg "y") or if ($string == "y") steven@DK.net
    Re: if ($string eg "y") or if ($string == "y") (Joel Coltoff)
        Interactive replace on multiple files... <dfetter@shell4.ba.best.com>
    Re: Interactive replace on multiple files... <rootbeer@teleport.com>
        Memory usage <robban@it-konsult.com>
        Newbie Q: How do I run Perl on WinNT? <gustav@fakta.se>
        parsing data <ottojt@mailhost.netdot.com>
        PL/SQL and perl <zhlei@beijing.china.com>
        POSIX::setuid and changing the UID <holt@kelp.usc.edu>
        Pragma error <giles@agentware.com>
    Re: Pragma error <rootbeer@teleport.com>
    Re: print multiple lines before or after match ? <mhammer@execpc.com>
        Problem with Perl read on NT <virg@shell5.ba.best.com>
        Q: How do I ring the terminal bell <lsj@bnl.gov>
    Re: Q: How do I ring the terminal bell (Brian Wheeler)
    Re: Q: How do I ring the terminal bell <cantrela@agcs.com>
    Re: Q: Simple RegExp match help required... <hsommer@micro.ti.com>
        QUESTION: foreach $scalar can this be foreach $hash{ref <brannon@lnc.usc.edu>
    Re: recursive file renaming <ynieh@fhcrc.org>
    Re: recursive file renaming <rootbeer@teleport.com>
    Re: regexp to return list of matches from string <william@mathworks.com>
    Re: Removing spaces from a variable, how? (Jason Gloudon)
    Re: Removing spaces from a variable, how? <ben@wallroyds.demon.co.uk>
    Re: Removing spaces from a variable, how? (Kevin Reid)
    Re: Sending a text file via perl (Fritz Knack)
    Re: Sendmail Attach <grupo@nevado.cui.edu.co>
    Re: spoiled noobie <mindmore@mindless.com>
    Re: Testing <mindmore@mindless.com>
    Re: using unpack to generate checksums. (Fergus McMenemie)
    Re: where's the faq? (Michael Fuhr)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Wed, 22 Apr 1998 18:59:17 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Bill Chapman <bchapman@best.com>
Subject: Re: 1st cgi script doesn't work
Message-Id: <Pine.GSO.3.96.980422115823.6132g-100000@user2.teleport.com>

On Wed, 22 Apr 1998, Bill Chapman wrote:

> If I go to the directory and run "perl htmlhello.cgi" it works, except
> of course it's not in a browser.

When you're having trouble with a CGI program in Perl, you should first
look at the please-don't-be-offended-by-the-name Idiot's Guide to solving
such problems. It's available on CPAN.

   http://www.perl.com/CPAN/
   http://www.perl.org/CPAN/
   http://www.perl.org/CPAN/doc/FAQs/cgi/idiots-guide.html
   http://www.perl.org/CPAN/doc/manual/html/pod/

Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 22 Apr 1998 22:20:40 +0200
From: jan.dubois@ibm.net (Jan Dubois)
Subject: Re: ActiveStates vs. Standard Distribution
Message-Id: <35484a3e.7955899@news2.ibm.net>

[mailed & posted]

"Michael Wil. Swiercz" <mike@borg.com> wrote:

>TO THE QUESTION: Has anyone tried to use ActiveState's ISAPI version of
>Perl (PerlIS) with the Standard Distribution? Is it even possible? I
>find myself between two extremes. I prefer the Standard Distribution due
>to its completeness, however, ActiveState's ISAPI version provides
>better response time and performance (yes, I'm forced to use MS IIS).

No, it is not (yet) possible. ISAPI uses the PERL_OBJECT stuff
internally which has not been ported back to standard Perl. It will be
included in the next release of Perl 5.005.

-Jan


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

Date: 22 Apr 1998 08:04:49 GMT
From: in5692@wlv.ac.uk (Peter Kendal)
Subject: beginnings....
Message-Id: <6hk8b1$g3m@ccuh.wlv.ac.uk>

Thanks to all who responded. You're all heroes. 



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

Date: 22 Apr 1998 14:19:12 +0200
From: Calle Dybedahl <qdtcall@esb.ericsson.se>
Subject: Re: CGI-Mail Problem
Message-Id: <isaf9eyrpb.fsf@godzilla.kiere.ericsson.se>

GRau@alcatel.de (Gaby Rau) writes:

> So I guess, I have to provide somehow my identity to the CGI-Script?
> But how? Any idea?

No, you have to configure mail correctly at the machine where the CGI
program runs (i.e., this is not a Perl problem). Or you could send the
mail in a more hands-on fashion, preferably using Net::SMTP.
-- 
		    Calle Dybedahl, UNIX Sysadmin
       qdtcall@esavionics.se  http://www.lysator.liu.se/~calle/


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

Date: Wed, 22 Apr 1998 07:37:20 -0600
From: martinja@exis.net
Subject: Changing case of specific characters in string
Message-Id: <6hkoa0$29f$1@nnrp1.dejanews.com>

Hello Perl Gurus!

I believe Perl can do this, but I'm not sure how to do it. I want uppercase
all characters inside of <>, but not uppercase characters inside of inner
quotation marks. Example <img src="home.gif"> becomes <IMG SRC="home.gif">.
Could anybody help me out here?

Thanks a bunch,

Joseph Martin
martinja@exis.net

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: 22 Apr 1998 11:00:30 GMT
From: cchuang@ms.nctu.edu.tw (Chao-cheng Huang)
Subject: Count some word in a string.
Message-Id: <6hkike$a93$2@news2.nctu.edu.tw>


Assume I have a string 
$s = "aa....aa....aa....aa....aa" ;
Ans I would like to calculate how much times "aa" happened.
I have these two code:

$cnt = $s =~ s/(aa)/$1/g ;  # $cnt = 5
$cnt = $s =~ /aa/g ;         # $cnt = 1

When I read perl man page , the modifier 'g' means global match.
So, the code should get the same value. Why they are different?
Or something wrong? Thanks in advice!

With regards,
Chao-cheng Huang

-- 
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/ Chao-cheng Huang(6@,L5{)  Department Management Science 87G of NCTU  _/
_/ E-mail: cchuang@msbsd.ms.nctu.edu.tw or u8331056@cc.nctu.edu.tw      _/
_/ URL: http://www.cc.nctu.edu.tw/~u8331056  Phone:(03)5712121x78307    _/
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/


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

Date: Wed, 22 Apr 1998 15:20:49 +0300
From: Fain <mindmore@mindless.com>
Subject: Re: Eat my dust - Perl running on Windows 95
Message-Id: <353DE0A1.4423FB4F@mindless.com>

Bill 'Sneex' Jones wrote:

> Bob Trieger wrote:
>
> >
> >
> > I download nekkid pics from USENET using my win32 perl. You bet I have
> > fun. 8-)
> >
> > --
> > Bob Trieger               |  Titanic: big boat, bigger
> > sowmaster@juicepigs.com   |           iceberg, big deal
>
>  If I 'member correctly, you're 70?  Right?
>
> Just wondering if I would be interested in naked pics at 70  %)
> __________________________
> Bill Jones...............|
> Sneaker's Nest...........|
> Chasecreek Systemhouse...|

  Wow! you guys really know how to get off subject!

- Nathan



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

Date: Wed, 22 Apr 1998 14:59:39 -0500
From: "Ron Shipp" <rshipp@acclrx.com>
Subject: float to hex conversion
Message-Id: <6hli6p$90s@news.outer.net>

A colleague generated some C code to convert a floating point number
into a hex value. This code works fine, and looks like this:

    int main (argc, argv)
    int   argc;
    char *argv[];
    {
      float fval;
      sscanf( argv[1], "%f", &fval );
      printf("%08x \n", *((int*)&fval) );
    }

Is there an equivalent to this in perl? I realize that I can compile this
into an executable, and use some sort of system call, but I would like
to do it without that.

TIA

Ron Shipp
Accelerix, Inc.
email - rshipp@acclrx.com     voice - 512/231-0331 X265     fax -
512/231-0334




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

Date: Wed, 22 Apr 1998 21:38:44 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Ron Shipp <rshipp@acclrx.com>
Subject: Re: float to hex conversion
Message-Id: <Pine.GSO.3.96.980422143649.6132r-100000@user2.teleport.com>

On Wed, 22 Apr 1998, Ron Shipp wrote:

> A colleague generated some C code to convert a floating point number
> into a hex value. 

[ All C code, except for one line, snipped. ]

>       printf("%08x \n", *((int*)&fval) );

> Is there an equivalent to this in perl? 

Sure, Perl has (s)printf, which supports the %08x format. I think that'll
do what you're needing. Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 22 Apr 1998 14:49:49 -0700
From: sitaram@diac.com (Sitaram Chamarty)
Subject: Re: Help sorting nested hashes by value
Message-Id: <slrn6jsfe7.ti.sitaram@localhost.localdomain>

On Mon, 20 Apr 1998 20:26:19 -0400, Don Silvia <lyanddon@peapod.com> wrote:

>I have data structure that consists of nested hashes, in which I
>need to sort keys based on the value of subkeys.  The data
>structure looks something like this:
>%Data   %Route    %Point
>----- ----------  -------  ------
>$Data{'Route_21'}{'72586'}{'Type'} = "DMP8";
>$Data{'Route_21'}{'72586'}{'Sta'} = "21856.3";

[snip]

>What I need to do is to print a list of Points, sorted by the
>value of their 'Sta' keys.  So I tried something like this:  (I
>know this example doesn't work)
>
># For each Route in %Data
>foreach $Route ( keys %Data )
>    # For each Point on this Route, ordered by {'Point'}{'Sta'}
>    foreach $Point ( sort { keys %{$Data{$Route}{Sta}{$a}} <=> keys
>%{$Data{$Route}{Sta}{$b}} }
>        keys %{$Data{$Route}} )
>        print OUTPUT_FILE ("\t$Point\n");

You're trying to compare 2 arrays (keys produces a list) using the
spaceship op.

Here's one solution.  You were on the right track, of course - I
just took it along further.

#!/usr/bin/perl -w

for $route (keys %Data)
{
    for $point (keys %{$Data{$route}})
    {
        $sorted{$route,$point} = $Data{$route}{$point}{'Sta'};
            # use the $; trick to get one composite key; this assumes that
            # your $route and $point do not have this character in them.  On
            # my perl this is hex 1C.
    }
}

# Your 'Sta' values seem to be numbers, change <=> to cmp if this
# is wrong.
for (sort { $sorted{$a} <=> $sorted{$b} } keys %sorted)
{
    s/^/Route = /;
    s/\x1C/, Point = /;
    print "$_\n";
}

__END__

Please note that I'm not a guru - someone else may have a more
Perl-ish or more elegant way.  This works, though; I have tested
it.

Ideally, of course, you would split on /\x1C/ to get at the two
parts of the composite key.  I just used a different method to get
a somewhat pretty print...

I'm also assuming that, when you say "print a list of Points", you
really mean "route+point".  Not knowing anything more about your
problem domain (for instance, can you have the same point value in
2 different routes?  I assumed yes).

HTH


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

Date: Wed, 22 Apr 1998 15:30:21 +0300
From: Fain <mindmore@mindless.com>
Subject: Re: Help!
Message-Id: <353DE2DD.B1BFE2C7@mindless.com>

johnnie@NOPERSONALMAIL.edu wrote:

> Keith L. Miller <miller@bigsky.net> bravely wrote:
> : open (IN, filename);
> :    while(<IN>){
> :       @fields = split(/:/, $_);
>
> :       if($fields[0] =~ /\0/){       # Attemp 1
>
> :       if(length($fields) < 1){       # Attemp 2
>
>    Attempt #1 is wrong because that \0, well, I don't know what it's
> going to do!  \0 may be giving you NULL, but I'm not sure.  What you want
> is ^\s*$ instead. (That checks for nothing but spaces)
>    Attempt #2 will never work cause $fields is not a variable yet.
> I suspect you meant length($fields[0]).  But that wouldn't work
> because each space is a character and you'd only be checking for lines
> of the form:
>
> :la:dee:da
>
>    Go with:
>
> :       if($fields[0] =~ /^\s*$/){       # Attemp 1
>
> : Also, here's an interesting note.  If I print the length of the blank
> : field, it always comes up 38 UNLESS the filed is longer than 38, then
> : it comes out with the correct length.
>
> : Any help would be VERY appreciated!
>
>    - Johnnie B
> --
>    - Johnnie Blanco Jr.
>    - "Just can't sit.  Gotta get jiggy wit it, mmm, that's it!"
>    -    Will Smith [Gettin Jiggy Wit It]

  This probably isn't at all helpful but I'm learning C and \0 is what is
used at the end of the string.




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

Date: Wed, 22 Apr 1998 08:49:32 -0500
From: Ying Peng <peng@cae.cig.mot.com>
To: Byron Brummer <byron@omix.com>
Subject: How to read lines between two keywords in a file
Message-Id: <353DF56B.9A858CBA@cae.cig.mot.com>

Hi Folks:




I'd like read through lines between two keywords. For example:

H-daok-N/A-1998<--Keyword1
/home/daok/f1
/home/daok/f2
 .
 .
/home/daok/f?
H-peng-N/A-N/A<--Keyword2

What I want to do is to find the first keyword and start reading the
following lines before the next keyword. Suppose the data in a file
called "data.txt". My problem is that which statement can read line by 
line in a file like $newline=<INFILE>?. Hope I can get answers from you 
experts. Thanks for your thoughts and help.

Your help will be highly appreciated.

************************************************************************
* Ying Peng                             Motorola                       *
* CAD/CAE/CAM Support Group             Cellular Infrastructure Group  *
* (V):(847)632-3069 (F):(847)-632-6436  1475 Shure Dr. MS:IL75/3G10    *
* email: ypeng1@email.mot.com           Arlington Heights, IL 60004    *
************************************************************************


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

Date: Wed, 22 Apr 1998 16:48:29 -0700
From: Yeu-Perng Nieh <ynieh@fhcrc.org>
Subject: if ($string eg "y") or if ($string == "y")
Message-Id: <353E81CD.167E@fhcrc.org>

Dear all,

 Does anyone know the difference b/w 

if ($string eg "y") and if ($string == "y")?

It seems to me that the latter does not work for string matching.
Even $string is something totally different from "y",
the if statement is always true. Any comments?


-- 
Yeu-Perng Nieh


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

Date: 22 Apr 1998 20:40:38 GMT
From: steven@DK.net
Subject: Re: if ($string eg "y") or if ($string == "y")
Message-Id: <6hlkk6$22c$1@news.dknet.dk>

Yeu-Perng Nieh <ynieh@fhcrc.org> wrote:
> Dear all,

>  Does anyone know the difference b/w 

> if ($string eg "y") and if ($string == "y")?

You mean 'eq' instead of 'eg'.

> It seems to me that the latter does not work for string matching.
> Even $string is something totally different from "y",
> the if statement is always true. Any comments?

eq is used when testing string equality, == is the numerical equivalent.
But you worked that out already :)

--
Steven Cotton, Backbone Manager, DKnet A/S, Denmark


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

Date: Wed, 22 Apr 1998 21:03:50 GMT
From: joel@wmi0.wmi.com (Joel Coltoff)
Subject: Re: if ($string eg "y") or if ($string == "y")
Message-Id: <6hllup$8e8@netaxs.com>

In article <353E81CD.167E@fhcrc.org>, Yeu-Perng Nieh  <ynieh@fhcrc.org> wrote:
>Dear all,
>
> Does anyone know the difference b/w 
>
>if ($string eg "y") and if ($string == "y")?

I assume you already know the answer to your question. It is,
of course, yes.  Anyone who read the docs knows the difference.

>It seems to me that the latter does not work for string matching.
>Even $string is something totally different from "y",
>the if statement is always true. Any comments?

That is a good observation. You've discovered that something that
isn't supposed to work indeed doesn't. That is why the very clever
people who wrote perl invented "eq" (patent pending)

	"==" (and its cousins) are used for numerical comparison.
	"eq" (and its cousins) are used for string comparison.

-- 
Joel Coltoff

I'd explain it, but there's a lot of math. -- Calvin


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

Date: 22 Apr 1998 20:06:16 GMT
From: David Fetter <dfetter@shell4.ba.best.com>
Subject: Interactive replace on multiple files...
Message-Id: <6hlijo$jco$1@nntp1.ba.best.com>

Kind people,

Is there some way to do interactive edits in place?

For a simple bunch of files, things like

perl -pi -e 's/foo/bar/g' baz* *bat

are handy.  There's also the interactive, but memory-hogging

foreach $filename (glob('baz*','*bat')) {
    $modified = 0;
    open FILE, "$filename";
    chomp(@line = <FILE>);
    for $i (0..$#line) {
        next unless $line[$i] =~ /foo/;
        print "$filename:$line[$i]? (Y/n)";
        chomp($yes = <STDIN>);
        next if $yes=~/n/i;
        ++$modified;
        $line[$i] =~ s/foo/bar/g;
    }
    print FILE join("\n",@line) if $modified > 0;
    close FILE;
}

Thanks in advance for any help, tips or suggestions for FM's to R :)
D.
-- 
            David Fetter         888 O'Farrell Street Apt E1205
   shackle@ren.glaci.com          San Francisco, CA 94109-7089 USA
  http://www.best.com/~dfetter     +1 415 567 2690 (voice)
print unpack ("u*",q+92G5S="!!;F]T:&5R(%!E<FP@2&%C:V5R"@``+)

"Usenet is like a herd of performing elephants with diarrhea --
massive, difficult to redirect, awe-inspiring, entertaining, and a
source of mind-boggling amounts of excrement when you least expect it."
                                       spaf@cs.purdue.edu (1992)


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

Date: Wed, 22 Apr 1998 21:41:53 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: David Fetter <dfetter@shell4.ba.best.com>
Subject: Re: Interactive replace on multiple files...
Message-Id: <Pine.GSO.3.96.980422143852.6132s-100000@user2.teleport.com>

On 22 Apr 1998, David Fetter wrote:

> Is there some way to do interactive edits in place?
> 
> For a simple bunch of files, things like
> 
> perl -pi -e 's/foo/bar/g' baz* *bat
> 
> are handy.  

Yes, and you can access all of those command-line features within Perl. 

-p	Make a while loop, using the diamond operator and print, more or
	less like this:

	    while (<>) {
		print;
	    }

-i	Use the magical $^I variable.

-e	That's just code. :-)  Put it into the while loop.

baz*	Filename glob. Use glob() or equivalent.

Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 22 Apr 1998 13:00:47 GMT
From: "Robert Friberg" <robban@it-konsult.com>
Subject: Memory usage
Message-Id: <01bd6dee$a3281900$c82da8c0@robban.ittek.org>

Hi all,

The following script runs happily except under cgi-wrap, where
it sometimes fails with an internal error. I would
appreciate some tips on minimizing memory usage which I believe
is the offending issue. Another possibilty might be an offensive 
regexp not known at compile time, but I haven't been able to
duplicate the errors in a different environment (NT4 / PerlIIS).

I included the complete script for reference only. Please observe
that the program is miles from completion and has tons of 
logical errors, is badly structured, has security holes and plenty
of other bugs.

All comments welcome,
/robban

================= BEGIN_SCRIPT================================
#
# The INTERESTING PART is about 50 lines further down
#

sub dye;
sub buildrow;
sub insert_link;

$dbmapp = '';
$butikmapp = 'http://secret.path/secret';
$prisfil = $dbmapp . 'priser.tab';
$saldofil = $dbmapp . 'saldon.tab';
$mallfil = $dbmapp . 'small.htm';
$margfil = $dbmapp . 'marg.tab';
$ssaknasfil = $butikmapp . 'ssaknas.htm';
$expiredfil = $butikmapp . 'expired.htm';


$maxhits=499; # OB1
$d{'max'} = 500;
@outfields = (0,4,7,8);

%fnames = (0, 'Artikelnr', 
           4, 'Artikelnamn',
           7, 'Tillverkare',
           8, 'Pris');

%fsize =  (0, 40, 
           4, 115,
           7, '*',
           8, 60);

#
#
# parse input-line
#
   $_ = $ENV{'QUERY_STRING'};
   @par = split /&/;
   for (@par){ 
	/(.*)=(.*)/;
	$d{$1} = $2;
   }

$d{'max'}--; #OB1

# decode input
   $d{'what'} =~ s/\+/ /g;
   $d{'what'} =~ s/%(..)/chr(hex($1))/eg;

@a = (0);
@p = (1,3,4,5,6,7);
@k = (11);
@fields = eval "\@$d{'a1'}";


#
#  Validate the user
#

if (defined ($_ = $ENV{'HTTP_COOKIE'})){
      /usrdata=(.*)/;
      ($data{'user'}, $data{'prisklass'}, $cs) = split /:/, $1, 3;
      $salt = substr((gmtime time)[3], 0, 2);
      print "Location: $expiredfil\nSet-Cookie: usrdata=x;"
         ."expires=Thu, 14-Aug-97 05:19:07 GMT;\n\n" and exit 
         unless ($cs eq crypt($data{'user'}, $salt));
}else{
   $data{'user'} = '';
   $data{'prisklass'} = '';
}



# Get the price-list %marg
 
   open FIL, "<$margfil" or dye "Kan inte oppna $margfil: $!\n";
   @rader = <FIL>;
   close FIL;
   
   for (@rader){
      /^(.*?)\t/;
      $marg{$1} = (split /\t/)[$data{'prisklass'}+1]/100;
      }


# Search the file and build the @hitdata
#
$hits = 0;
@header = map {
    "<td width=\"$fsize{$_}\"><b>$fnames{$_}</td>"
    } @outfields;

@hitdata = ();

# INTERESTING PART
#
# The file is big, about 10 MB
# The average line is about 1K
#
open FIL, "<$prisfil" or dye "Kan inte vppna filen $prisfil: $!\n";

#
# match a'n'y searchword
# in @fields - fields
#
if ($d{'a2'} eq 'n'){
	@words = split /\s+/, $d{'what'};
	while (<FIL>){
	   last if ($hits > $maxhits or $hits>$d{'max'});
	   for $w (@words){
	      $hitdata[$hits++] = buildrow and last if 
                   join( '',(split /\t/)[@fields]) =~ /$w/i;
	   }
	}
#
#  match 'b'eginning of word
#
}elsif ($d{'a2'} eq 'b'){
	while (<FIL>){
	   last if ($hits > $maxhits or $hits>$d{'max'});
	   @tdata = split /\t/;
	   for $f (@fields){
	      ($hitdata[$hits++] = buildrow and last) if 
                       ($tdata[$f] =~ /^$d{'what'}/i);
	   }
	}
#
# match 'e'xactly (besides case)
#
}elsif ($d{'a2'} eq 'e'){
	while (<FIL>){
	   last if ($hits > $maxhits or $hits>$d{'max'});
	   @tdata = split /\t/;
	   for $f (@fields){
	      ($hitdata[$hits++] = buildrow and last) if 
                      ($tdata[$f] =~ /^$d{'what'}$/i);
	   }
	}
#
# match 'a'll searchwords
#
}elsif ($d{'a2'} eq 'a'){
	@words = split /\s+/, $d{'what'};
	while (<FIL>){
	   last if ($hits > $maxhits or $hits>$d{'max'});
	   @tdata = split /\t/;
	   $whit = 0;
	   for $f (@fields){
	      for $w (@words){
	         $whit++ if $tdata[$f] =~ /$w/i;
	         ($hitdata[$hits++] = buildrow and last) if $whit > $#words;   
	      }
	      last if $whit > $#words;
	   }
	}
}
close FIL;


#
# No hits, redirect
#
print "Location: $ssaknasfil\n\n" unless ($#hitdata > 1);

$d{'antal'} = $hits;
$d{'sokrader'} = join '', (@header, @hitdata);


#
# Vpen template and replace !! -- !!-tags
#
open FIL, "<$mallfil" or dye "Kan inte oppna $mallfil: $!\n";
undef $/;
$_ = <FIL>;
close FIL;
s/!!([a-zA-Z]+?)!!/$d{lc($1)}/eg;
print "Content-type: text/html\n\n$_";

#
# Sub - declarations
#

sub dye
{
   print "Content-type: text/plain\n\n";
   print @_;
   exit;
}

sub buildrow
{
   '<tr><td>' . 
   join ('</td><td>',insert_link((split /\t/)[@outfields, 2])) .
   "</td></tr>\n";
}

sub insert_link
{
   $_[0] = "<a href=\"http://secret/pinfo.pl\?pid\=$_[0]\">$_[0]</a>";
   $_[3] = sprintf('%2.2f kr',$_[3] / (1 - $marg{$_[-1]}));
   undef $_[-1];
   @_;
}




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

Date: Wed, 22 Apr 1998 13:44:28 +0200
From: "Gustav" <gustav@fakta.se>
Subject: Newbie Q: How do I run Perl on WinNT?
Message-Id: <353dd7ac.0@d2o71.telia.com>

Hi,
I have installed Pw32i316.exe on the server and I try to run WWWBoard (from
Matt's Script Archive) but I can't get it to work! I am a total Newbie and I
need (some) help.

I try to run the script but I get the following error:

HTTP Error 405
405 Method Not Allowed

The method specified in the Request Line is not allowed for the resource
identified by the request. Please ensure that you have the proper MIME type
set up for the resource you are requesting.

How should I configure the server to run the WWWboard?
Is there any safety-issues I shall think of?

(I'm running NT4 with IIS4 with FP98 extentions if that helps. Earlier I
tried to make a discussionWEB with Frontpage but it didn't work as I wanted)

/Gustav





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

Date: Wed, 22 Apr 1998 15:21:51 -0500
From: "John T. Otto" <ottojt@mailhost.netdot.com>
Subject: parsing data
Message-Id: <353E515F.7EA5@mailhost.netdot.com>

I'm having trouble parsing data from an INFILE, and placing it in the
appropriate place in my OUTFILE.

I'm assigning a variable to the INFILE, and trying to grab a substring
out of it.  For instance, a variable called $name, which is a substring
of the INFILE variable occurring at position 75, and is 7 characters
long.  The script pulls out data from that position if its there, but
not the right stuff, resulting in lots of repeats, wrong data, etc.

The format works, and the script doesn't crash, it's just a matter of
getting the right data from the approprite place, and putting it where I
need it.  I can't seem to find the answer in my manuals.  Does anyone
have any experience reformatting large files, and if so, can you help me
out?

I'd be glad to give you some of my sample data, and the a copy of the
initial script if needed.  

thanks,

Ottoman


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

Date: Wed, 22 Apr 1998 16:06:27 +0800
From: zhanglei <zhlei@beijing.china.com>
Subject: PL/SQL and perl
Message-Id: <353DA503.EBFB9062@beijing.china.com>

How can I make Oracle PL/SQL into perl program?



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

Date: 22 Apr 1998 09:33:13 -0700
From: Gary Holt <holt@kelp.usc.edu>
Subject: POSIX::setuid and changing the UID
Message-Id: <85son5yfxy.fsf@kelp.usc.edu>

I've got a perl script that runs as root that needs to fork off child
processes running under a different UID.  I must be misunderstanding
something; POSIX::setuid doesn't work as I expected.  Here's an
example.  As root, I issue the following commands:

# perl -e 'use POSIX; setuid(500); open(X, ">x");'
# ls -l x
-rw-r--r--   1 root     root            0 Apr 22 09:16 x

The setuid was completely ignored; the created file is still owned by
root.  (By the way, there was no error message in $!, so the setuid did
not return an error message.)  Why did this happen?  Is POSIX::setuid
simply broken?

Instead of using POSIX::setuid, I've tried several other techniques:

o Assigning to $UID ($REAL_USER_ID).  This has no effect at all, just as
  above.  No error messages, either.  (I do get an error message if I
  try to set $UID = 0 when I'm not root, however, so assigning to $UID
  seems to be doing something.)

o Assigning to $EUID.  This works:

# perl -e 'use English; $EUID = 500; open(X, ">x");'
# ls -l x
-rw-r--r--   1 holt     root            0 Apr 22 09:18 x

  which changed the user name, as I wanted.  However, there seems to be a
  security problem with this: I can change the $EUID back.  For example,

# perl -e 'use English; $EUID = 500; $EUID = 0; open(X, ">x");'
# ls -l x
-rw-r--r--   1 root     root            0 Apr 22 09:19 x

  When my daemon process forks off other processes running under other
  UIDs, I don't want them to be able to change UID back to root.  (This
  is for a batch queuing system; arbitrary code can be run, and it's an
  unnacceptable security risk if the code can simply change uid to
  root.)  How do I prevent this?

o Trying to change both $EUID and $UID doesn't work any differently from
  changing $EUID alone.

Operating system: linux 2.0.30 (libc5 or libc6, both do the same thing)
Perl version: 5.003_07 and 5.004_04.

What's the right way to have a daemon process fork off processes running
as other users without allowing the subprocesses to switch back?

-- 
Gary Holt			(213)-740-3397
holt@lnc.usc.edu		http://lnc.usc.edu/~holt/


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

Date: Wed, 22 Apr 1998 13:03:04 -0700
From: "Beau Giles" <giles@agentware.com>
Subject: Pragma error
Message-Id: <6hligt$q0l$1@owl.slip.net>

>From time to time I get syntax error on scripts using pragmas.  For instance
the following script produced this error:
syntax error in file Hello.pl at line 3, next 2 tokens "use Socket"
execution aborted due to compilation errors.

Here is the script:
#!/usr/local/bin/perl

use Socket;

print "Hello world\n";

End Script.

This script was made to test the module linkage after more complex scripts
using socket calls produced the same error.  These errors occurred on a
FreeBSD system running Perl 5.00404.  This same script (and the more complex
scripts) worked on an NT box using the ActiveState interpreter.  Also the
Socket.pm module file is installed at
/usr/local/lib/perl5/i386-freebsd/5.00404/.  It seems like I'm missing
something simple, can anyone help?

-- Beau Giles
   San Francisco, Ca




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

Date: Wed, 22 Apr 1998 21:36:04 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Beau Giles <giles@agentware.com>
Subject: Re: Pragma error
Message-Id: <Pine.GSO.3.96.980422143119.6132q-100000@user2.teleport.com>

On Wed, 22 Apr 1998, Beau Giles wrote:

> From time to time I get syntax error on scripts using pragmas. 

Just a point of terminology: In Perl, pragmas are a special class of
modules. By convention, their names begin with a lower case letter. So,
'Socket' is a module, but 'strict' is a pragma. 

> For instance the following script produced this error: 
> syntax error in file Hello.pl at line 3, next 2 tokens "use Socket"
> execution aborted due to compilation errors.
> 
> Here is the script:
> #!/usr/local/bin/perl
> 
> use Socket;

The image in my crystal ball is becoming clearer. You're using an old
perl, probably without realizing it.

> These errors occurred on a FreeBSD system running Perl 5.00404. 

Are you sure? My crystal ball is rarely wrong. :-)  Try using the -v
invocation option to double-check the version of perl you're actually
running. Be sure to give the full path name, just as you have it on the #!
line. 

Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 22 Apr 1998 14:17:09 -0600
From: Mike Hammernik <mhammer@execpc.com>
Subject: Re: print multiple lines before or after match ?
Message-Id: <6hlisv$4pc@newsops.execpc.com>

Sorry 

I put the information in and forgot to ask the question.

I would like to print the matched line and the next x lines whether that
might be 2 or 10 additional lines.  Conversely it seems to make sense to
be able to do it in reverse.  $prev is one line but how to print the
previous 2 or 10 lines. 

My apologies for not checking what I was writing.

Hammer


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

Date: 22 Apr 1998 08:24:13 GMT
From: <virg@shell5.ba.best.com>
Subject: Problem with Perl read on NT
Message-Id: <6hk9fd$7hk$1@nntp1.ba.best.com>

Hi,

We are running Perl 5.04 on an NT 4.0 server.  When we
try to read from a file that we have opened successfully
using 
   while (<INPUT_FILE>)
we can't manage to enter the while loop eventhough stat
shows that the file exist and the file size is not 0.

This Perl script runs successfully on a FREBSD server
and only fails on NT. Can someone please shed some light?


-Thanks,
Virginia-


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

Date: Wed, 22 Apr 1998 16:12:37 -0400
From: "Lance" <lsj@bnl.gov>
Subject: Q: How do I ring the terminal bell
Message-Id: <6hlivp$m5f$1@sun20.ccd.bnl.gov>

I know
     echo -n '^G'
, or
     echo '\007\c'
do the work in Unix shell script.
But what about in Perl?
Is there anything other than
     system "echo '\007\c'
?
Thanks in advance!
--
Regards,
Lance j.




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

Date: 22 Apr 1998 21:00:26 GMT
From: bdwheele@indiana.edu (Brian Wheeler)
Subject: Re: Q: How do I ring the terminal bell
Message-Id: <6hllpa$fk9$1@jetsam.uits.indiana.edu>

In article <6hlivp$m5f$1@sun20.ccd.bnl.gov>,
	"Lance" <lsj@bnl.gov> writes:
> I know
>      echo -n '^G'
> , or
>      echo '\007\c'
> do the work in Unix shell script.
> But what about in Perl?
> Is there anything other than
>      system "echo '\007\c'
> ?
> Thanks in advance!

	Easy.  print "\a";  will do it.  Its in the documentation...and the
same as C.

Brian Wheeler
bdwheele@indiana.edu


> --
> Regards,
> Lance j.
> 
> 


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

Date: Wed, 22 Apr 1998 14:25:32 -0700
From: Andy Cantrell <cantrela@agcs.com>
Subject: Re: Q: How do I ring the terminal bell
Message-Id: <353E604C.29D26FEA@agcs.com>

Lance wrote:
> 
> I know
>      echo -n '^G'
> , or
>      echo '\007\c'
> do the work in Unix shell script.
> But what about in Perl?
> Is there anything other than
>      system "echo '\007\c'

$bond = "\007" ;
print "$bond" worked for me on a unix box.

-- 
Andy Cantrell
AG Communication Systems
E-Mail:  cantrela@agcs.com
Ph. (602)582-7495  Rm. X18


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

Date: Wed, 22 Apr 1998 09:13:42 -0500
From: Holly Sommer <hsommer@micro.ti.com>
Subject: Re: Q: Simple RegExp match help required...
Message-Id: <353DFB16.E138300D@micro.ti.com>

jules wrote:

: if ( $line = /^From \?\?\?\@\?\?\? */ ) {

Assuming that $line has had $_ assigned to it...

First, you need to do:
$line =~
Reason? The "=" is an assignment operator.

Second, that last asterisk with a space before it is
telling you to look for the pattern of:
From<space>???@???<zero or more spaces>
When a more precise regex would be
/^From \?\?\?\@\?\?\? .*/

Or, if you want to make it a little more legible,
and don't mind using something equating a const, you
can try this:

$from = "From ???@??? ";
if ( $line =~ /^$from .*/ ) {
   ...
}

Hope this helps.

-Holly


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

Date: 22 Apr 1998 13:18:36 -0700
From: Terrence Brannon <brannon@lnc.usc.edu>
Subject: QUESTION: foreach $scalar can this be foreach $hash{ref}
Message-Id: <lbyawxbof7.fsf@seal.usc.edu>

As you can see, below I had to use a scalar as the argument for my
foreach loops because apparently perl cant assign to the keys of a
hash within the foreach stmt.

I dont see what would be wrong with allowing such assignments.

===File /home/newport/freeway/brannon/rs/ns-98/dep.generator===

    foreach $v_factor_40 (@factor) {
	foreach $v_factor_51 (@factor) {
	    foreach $v_factor_32 (@factor) {
		foreach $v_factor_25 (@factor) {
		    $v{factor_40}=$v_factor_40;
		    $v{factor_51}=$v_factor_51;
		    $v{factor_32}=$v_factor_32;
		    $v{factor_25}=$v_factor_25;

		    run_jobs_{$branch}'br';
		    }
	    }
	}
    }

-- 
Terrence Brannon * brannon@lnc.usc.edu * http://lnc.usc.edu/~brannon
USC, HNB, 3614 Watt Way, Los Angeles, CA 90089-2520 * (213) 740-3397
Great Milk Debate...  http://www.milk.com vs. http://www.notmilk.com


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

Date: Wed, 22 Apr 1998 16:31:47 -0700
From: Yeu-Perng Nieh <ynieh@fhcrc.org>
Subject: Re: recursive file renaming
Message-Id: <353E7DE3.41C6@fhcrc.org>

Edwin Shin wrote:
> 
> can anyone offer a quick and easy way to make the following script
> recursively plow through a directory tree?
> 
> i would like, for instance, to rename all *.shtml files to *.html in a
> given directory tree.
> 
> tia,
> 
> -eddie
> 
> #!/usr/bin/perl
> 
> print "Enter the file extension you wish to replace (e.g. \"shtml\"): ";
> chomp ($oldSuffix = <STDIN>);
> print "\nEnter the replacement extension (e.g. \"html\"): ";
> chomp ($newSuffix = <STDIN>);
> 
> foreach $_ (<*.$oldSuffix>) {
>         /$oldSuffix/;
>         rename("$_","$`$newSuffix");
> }
> 
> --
> 
> Edwin Shin
> 
> School of Law
> University of California at Berkeley

I have a similar script to so the same thing.

#!/usr/bin/perl 
#change file names script!!
opendir(DIR,".");
@file=readdir(DIR);
print("Enter the filename string to be changed:\n");
$string1=<STDIN>;
chop($string1);
print("Change to:\n");
$string2=<STDIN>;
chop($string2);
PRI: print("Match from the beginning(a),from the end(b) or any
position(c):");
$input=<STDIN>;
chop($input);
if ($input eq "a") {
  foreach $indi (@file) {
    if ($indi =~ /^$string1/) {
      $object=$indi;
      $object=~s/$string1/$string2/;
      rename("$indi","$object");
      print("$indi has been changed to $object .\n");
    }
  }
}
elsif ($input eq "b") {
  foreach $indi (@file) {
    if ($indi =~ /$string1$/) {
      $object=$indi;
      $object=~s/$string1/$string2/;
      rename("$indi","$object");
      print("$indi has been changed to $object .\n");
    }
  }
}
elsif ($input eq "c") {
  foreach $indi (@file) {
    if ($indi =~ /$string1/) {
      $object=$indi;
      $object=~s/$string1/$string2/;
      rename("$indi","$object");
      print("$indi has been changed to $object .\n");
    }
  }
}
else {
goto PRI;
}


-- 
Yeu-Perng Nieh
ynieh@fhcrc.org


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

Date: Wed, 22 Apr 1998 21:48:51 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Yeu-Perng Nieh <ynieh@fhcrc.org>
Subject: Re: recursive file renaming
Message-Id: <Pine.GSO.3.96.980422144234.6132t-100000@user2.teleport.com>

On Wed, 22 Apr 1998, Yeu-Perng Nieh wrote:

>     if ($indi =~ /^$string1/) {

Are you familiar with what happens if $string1 has metacharacters? For
example, if someone has entered *.c as the file name to look for? Also, do
you know about the /o option?

>       rename("$indi","$object");

You may want to check the return value from rename. Also, those quote
marks aren't doing anything useful.

> goto PRI;

Perl is a structured programming language. Please use it properly. Thanks!
:-)

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 22 Apr 1998 16:02:47 -0400
From: William York <william@mathworks.com>
To: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: regexp to return list of matches from string
Message-Id: <Pine.LNX.3.96.980422160208.19911i-100000@york.mathworks.com>

I've look at the POD for HTML::Parser, but still don't know how to use
it.

Could somebody point me to an example?

Bill

William York
william@mathworks.com


On Wed, 22 Apr 1998, Tom Phoenix wrote:

> On 22 Apr 1998, William York wrote:
> 
> > Perhaps I'm dreaming but I'd like to make a piece of regexp do
> > something like this:
> > 
> > # for this string:
> > $line = "<table border><tr><td><table><tr><td>HI</td></tr></table></td></tr>";
> 
> Don't try to parse HTML with a simple regular expression. There are too
> many special cases, such as comments and quoting. Use a module like
> HTML::Parser instead. Hope this helps!
> 
> -- 
> Tom Phoenix       Perl Training and Hacking       Esperanto
> Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/
> 



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

Date: Wed, 22 Apr 1998 20:18:11 GMT
From: jgloudon@hyssop.bbn.com.bbn.com (Jason Gloudon)
Subject: Re: Removing spaces from a variable, how?
Message-Id: <slrn6jsk3s.1u5.jgloudon@hyssop.bbn.com>

Jonathan Feinberg <jdf@pobox.com> wrote:
 .
>Speed.
 .

Odd how often the speed of s/// over tr/// for this purpose is discussed
and how often it gets benchmarked.

--
Jason Gloudon


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

Date: Wed, 22 Apr 1998 18:55:46 +0100
From: "bjf" <ben@wallroyds.demon.co.uk>
Subject: Re: Removing spaces from a variable, how?
Message-Id: <893267759.28680.0.nnrp-08.c2de5b4a@news.demon.co.uk>

Yes, I tried to find the answer I wanted ... (Netshell Perl)

I knew about $var =~ s/(whatever)//g;

But - I didn't know how to instruct it 'space' ... I thought I can't use
space, itself .....

I'm sorry if the question I asked upsetted you.

BJF.


Abigail wrote in message <6hl5un$d6r$1@client3.news.psi.net>...
>bjf (ben@wallroyds.demon.co.uk) wrote on MDCXCV September MCMXCIII in
><URL: news:893222683.6503.0.nnrp-06.c2de5b4a@news.demon.co.uk>:
>++
>++ How do you remove all spaces ... ie ... " " .... from a variable using
>++ pattern-matching?
>
>
>You read the manual.
>
>
>
>Abigail
>--
>perl -e '$a = q 94a75737420616e6f74686572205065726c204861636b65720a9 and
>         ${qq$\x5F$} = q 97265646f9 and s g..g;
>         qq e\x63\x68\x72\x20\x30\x78$&eggee;
>         {eval if $a =~ s e..eqq qprint chr 0x$& and
\x71\x20\x71\x71qeexcess}'




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

Date: Wed, 22 Apr 1998 11:01:27 -0400
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: Removing spaces from a variable, how?
Message-Id: <1d7vsdr.1w8whjgqpabk0N@slip166-72-108-2.ny.us.ibm.net>

bjf <ben@wallroyds.demon.co.uk> wrote:

> Hiya!
> 
> How do you remove all spaces ... ie ... " " .... from a variable using
> pattern-matching?

Translation is faster.

$var =~ tr/ //d;

-- 
  Kevin Reid.      |         Macintosh.
   "I'm me."       |      Think different.


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

Date: Wed, 22 Apr 1998 13:33:54 GMT
From: fritz.knack@nospam.POPULUS.net (Fritz Knack)
Subject: Re: Sending a text file via perl
Message-Id: <3541efca.7589599@cnews.newsguy.com>

On Wed, 22 Apr 1998 00:55:23 GMT, Glenn Schworak
<Glenn.J.Schworak@state.or.us> wrote:

>I have this chunk of perl code that works great under Netscape but
>InterNet Explorer 4.0 loses its mind when it starts to download.

This tells you it's not a Perl-specific problem. Try one of the
web-server groups.

>---------------> Actual Code <----------------
>
>    while (@line = <DOWNLOAD_FILE>) { print $line }

 ...and I may be missing something, but I wouldn't have thought that
this is what you mean. (At least within the code you provided, $line
is undefined.) You might try

while (<DOWNLOAD_FILE>) { print }

	or even

@line = <DOWNLOAD_FILE>;
for $line (@line) {
   print $line;
}

Fritz

-------------------------
Sorry 'bout the nospam in the From field. You know how those 'bots are.


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

Date: Wed, 22 Apr 1998 07:41:39 -0500
From: "InterRed" <grupo@nevado.cui.edu.co>
Subject: Re: Sendmail Attach
Message-Id: <6hjl7s$6in2@ibague.cetcol.net.co>

Unix : System Operating
how work the mime?
for send an email with attach !





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

Date: Wed, 22 Apr 1998 15:25:17 +0300
From: Fain <mindmore@mindless.com>
Subject: Re: spoiled noobie
Message-Id: <353DE1AD.68F1C3D3@mindless.com>

Kevin Reid wrote:

> Lloyd Zusman <ljz@asfast.com> wrote:
>
> > kpreid@ibm.net (Kevin Reid) writes:
> > > $var =~ s/^\s*([^ ]*)\s*$/$1/;
> > >
> > > That's about as elegant as it gets.
> >
> > I'm sorry to interject here, but the above regexp will not work to
> > remove leading and trailing white space from the following string, or
> > any string which contains embedded white space:
> >
> >    $var = "   abc  def   ";
>
> exclaim($ARGH);
>
> $me{intelligence} = 0;
>
> $mistakes++;
>
> --
>   Kevin Reid.      |         Macintosh.
>    "I'm me."       |      Think different.

exclaim($ARGH);

$me{intelligence} = Macintosh;
$me{intelligence} = 0; # this line is not necessary because
                       # they are one in the same
$mistakes++;

--
  Nathan Fain      |         Macintosh.
 Kevin is 'me'.    |        Don't Think.

Kevin... sorry... I'm just picking on you (I don't normally do this).




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

Date: Wed, 22 Apr 1998 15:38:51 +0300
From: Fain <mindmore@mindless.com>
Subject: Re: Testing
Message-Id: <353DE4DB.AE0663D9@mindless.com>

Charlene Yanke wrote:

> This is only a test.

Your test worked.
Is this something you do often or is it spontaneous (like you wake up in
the morning having the urge to run to your computer and test your
USENET program to make sure that it is working OK (you would do this for
the same reason the rest of us do it; because USENET is the worlds most
valuable resource))?

- Nathan Fain
mindmore@mindless.com



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

Date: Wed, 22 Apr 1998 09:28:07 +0100
From: fergus@twig.demon.co.uk (Fergus McMenemie)
Subject: Re: using unpack to generate checksums.
Message-Id: <1d7vp2d.11c5v7rxme0cuN@twig.demon.co.uk>

Jason Gloudon <jgloudon@hyssop.bbn.com.bbn.com> wrote:

> From my NetBSD sum(1) manpage, the sum that the unpack command generates
> is equivalent to the SYSV 'sum -r' but plain 'sum' uses a different algorithm
> which is the same as on BSD.

Yes I noticed that; however:-
        using the example in the book   29840
                      /usr/bin/sum -r   33950
                         /usr/bin/sum   62606
                         /usr/ucb/sum   33950

I am using perl 5.004 on a Sun Ultra running solaris 5.5.1.

I am using the following, all of which produce an answer of 29840:-
#! /usr/local/bin/perl

# my original code.
$f="index.html";
open(IN,$f) || die("Opening $f $!");
while(<IN>) {
  $buf.=$_;
  }
close(IN);
$chksum=unpack("%32C*",$buf) % 32767;
print "$chksum $f\n";



#from the macperl manual pages
$chksum=0;
open(IN,$f) || die("Opening $f $!");
while (<IN>) {
   $chksum += unpack("%16C*", $_);
   }
close(IN);
$chksum %= 65536;
print "$chksum $f\n";



#from the O'Reilly books
open(IN,$f) || die("Opening $f $!");
undef $/;
$chksum=unpack("%32C*",<IN>) % 32767;
close(IN);
print "$chksum $f\n";


-- 
======================================================================
Fergus McMenemie                      Email: fergus@twig.demon.co.uk
Technical Basis
======================================================================


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

Date: Wed, 22 Apr 1998 13:18:24 GMT
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: where's the faq?
Message-Id: <6hkqmu$hq5@flatland.dimensional.com>

Jay Eckles <eckje@rhodes.edu> writes:

> Where do I find the faq (and archive if there is one) for this newsgroup?

You can find links to information about Perl from:

    http://www.perl.com/

You can find newsgroup archives for this and just about every other
newsgroup at Deja News:

    http://www.dejanews.com/

-- 
Michael Fuhr
http://www.dimensional.com/~mfuhr/


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

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

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