[12875] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 285 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 28 14:07:27 1999

Date: Wed, 28 Jul 1999 11:05:12 -0700 (PDT)
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, 28 Jul 1999     Volume: 9 Number: 285

Today's topics:
        Any Suggestions? <steven_crazyman@worldnet.att.net>
    Re: ASCII to ANSI conversion -- HELP <flavell@mail.cern.ch>
    Re: Beginner needs help with a function <jimrie@guideguide.com>
    Re: Beginner needs help with a function <uri@sysarch.com>
    Re: ebcdic packed numbers <uri@sysarch.com>
    Re: ebcdic packed numbers <bivey@teamdev.com>
    Re: ebcdic packed numbers <uri@sysarch.com>
    Re: eval <gt7202e@prism.gatech.edu>
    Re: eval (Larry Rosler)
    Re: eval (Greg Bacon)
        File maintenance algorithm required (Roger Musson)
    Re: File maintenance algorithm required (Greg Bacon)
        Filehandler... Can you email attachments??? <probichaud@nonlinear.ca>
        help w/command line argument sn0brdr@yahoo.com
    Re: help w/command line argument (Greg Bacon)
    Re: HELP! tied DB_RECNO ->put() fails with R_IAFTER (Anno Siegel)
        Help!! ---Database access in perl andrewfase@my-deja.com
    Re: help: push array refs into hash, sort by refs in ha (Michel Dalle)
    Re: Korn Shell or Perl? (Michael Wang)
    Re: Korn Shell or Perl? <uri@sysarch.com>
    Re: Newbie sort and references question. (Michel Dalle)
    Re: Passing an Array into a HIDDEN FIELD (Michel Dalle)
        perl timeouts <grossman@bbn.com>
    Re: Perl, FTP, and Win32 with IIS (ouch) vcuya@mindspring.com
    Re: Premature end of script headers??? <jimrie@guideguide.com>
        Reading the binary files in Perl bidyut@yahoo.com
    Re: Selecting files by permisions <uri@sysarch.com>
    Re: Server NT et Perl <nick.sanders@lineone.net>
    Re: splitting an array - well not really but ... (Tad McClellan)
    Re: Using perl CGI under NT <gt7202e@prism.gatech.edu>
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: Wed, 28 Jul 1999 12:59:46 -0500
From: "Steve Wagner" <steven_crazyman@worldnet.att.net>
Subject: Any Suggestions?
Message-Id: <7nngoh$77p$1@bgtnsc01.worldnet.att.net>

I am new to perl/cgi and have written the following code. Do you have any
suggestions on how to restructure the code? It works great but It doesnt
seem to me that I should be using the same arrays for all these different
functions especially since I have a ton left to do.
                            Any suggestions would be appreciated.

#!/usr/bin/perl

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

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $FORM{$name} = $value;
}

$mailprog = '/usr/sbin/sendmail';


$recipient = 'crazyman@cgi101.com';

if ($FORM{'fname'} eq "" or $FORM{'lname'} eq "" or $FORM{'email'} eq "" or
$FORM{'address'} eq "" or $FORM{'state'} eq "" or $FORM{'city'} eq "" or
$FORM{'zip'} eq "") {
    &dienice("Please fill out the fields for your First Name, Last Name,
E-mail, Adrress, State, City and Zip Code.");
}
else {
 open (MAIL, "|$mailprog -t") or &dienice("Can't access $mailprog!\n");


 print MAIL "To: $recipient\n";


 print MAIL "Reply-to: $FORM{'email'} ($FORM{'name'})\n";


 print MAIL "Subject: Thank You for Registering\n\n";

 foreach $key (keys(%FORM)) {
 print MAIL "$key = $FORM{$key}\n";
 }
 foreach $key (sort(keys %ENV)) {
        print MAIL "$key = $ENV{$key}\n";
 }
}

close(MAIL);

open(OUTF,">>outdata.txt") or &dienice("Couldn't open outdata.txt for
writing. Please notify webmaster\@cgi101.com.");


print OUTF "$FORM{'fname'}|$FORM{'lname'}|$FORM{'email'}\n";



close(OUTF);




mkdir ($FORM{'fname'},0777) or &dienice("Couldn't Make directory. Please
notify webmaster\@cgi101.com.");
chdir($FORM{'fname'});
open(OUTFILE2,">index.html") or &dienice("Couldn't open
($FORM{'fname'}index.html for writing. Please notify
webmaster\@cgi101.com.");
print OUTFILE2 "<html><head><title>TEST</title></head><body>";
print OUTFILE2 "<center>TESTING<center>";
close(OUTFILE2);



print "<html><head><title>Form Output</title></head><body>"; print
"<center><h1>Thank You The Following Info Was
Sent:</h1></center><br><br>\n";

foreach $key (sort(keys(%FORM))) {
   print "<h3><center>$key = $FORM{$key}</h3></center><br>";
}
print "<br><center>Click <A HREF=\"index.html\">Here</A>To Return To Our
Home Page</center>";
print "</body></html>";


sub dienice {
    ($errmsg) = @_;
    print "<h2>Error</h2>\n";
    print "$errmsg<p>\n";
    print "</body></html>\n";
    exit;
}








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

Date: Wed, 28 Jul 1999 19:25:45 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: ASCII to ANSI conversion -- HELP
Message-Id: <Pine.HPP.3.95a.990728190055.1997C-100000@hpplus03.cern.ch>

On Wed, 28 Jul 1999 jeff.fritsche@persoft.com wrote:

> I need to create a script that converts ANSI characters to ASCII
> characters. 

Excuse me?  ASCII is a well-defined 7-bit character code.  ANSI is the
(US) American National Standards Institute or thereabouts.  Microsoft
have a collection of proprietary 8-bit encodings that they tend to call
collectively "ANSI", I guess that's what you have in mind. 

About the only thing one can say about them in this context is that all
the ASCII characters also appear in the same place in all of the
Microsoft-defined 8-bit codes, and all the other characters in those
codes are not in ASCII.  So what is it actually that you hope to achieve
with this "conversion"? 

> Does anybody have any suggestions ???

GNU recode (there's a Perl frontend to it in CPAN). But until we know
what it is that you really hope to achieve, it doesn't seem to be a
welldefined problem. 

 Convert::Recode is a front end to the GNU recode program.  It will
 build a perl tr/// function based on the mapping tables that recode
 knows about.



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

Date: Wed, 28 Jul 1999 18:11:12 +0100
From: John Imrie <jimrie@guideguide.com>
Subject: Re: Beginner needs help with a function
Message-Id: <379F39B0.1965728D@guideguide.com>

>
> I assume "c" is your character you want to strip.
>
> So do a
> $string =~ s/^c+//g;
> to strip the c's at the beginning, and a
> $string =~ s/c+$//g;
> to strip them at the end.
>
> Maybe there is a way to do this with only one command, I would be glad to
> hear about it.

One command method

$string =~ s/^c+(.*)c+$/$1/;

The Pilgrim



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

Date: 28 Jul 1999 13:54:19 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Beginner needs help with a function
Message-Id: <x7zp0gr778.fsf@home.sysarch.com>

>>>>> "JI" == John Imrie <jimrie@guideguide.com> writes:

  >> 
  >> I assume "c" is your character you want to strip.
  >> 
  >> So do a
  >> $string =~ s/^c+//g;
  >> to strip the c's at the beginning, and a
  >> $string =~ s/c+$//g;
  >> to strip them at the end.
  >> 
  >> Maybe there is a way to do this with only one command, I would be glad to
  >> hear about it.

  JI> One command method

  JI> $string =~ s/^c+(.*)c+$/$1/;

see larry rosler's many posts in this thread for why that has
problems. he also posted correct answers to the asked question.

uri


-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.


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

Date: 28 Jul 1999 13:14:48 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: ebcdic packed numbers
Message-Id: <x7aesgsnlj.fsf@home.sysarch.com>

>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:

  AS> [_The Mythical Man Month_]

  >> i read brooks for the philosophy, not the technology. very insightful
  >> and a must read for all software engineer wannabes. but skip his
  >> selection of tools and languages, he is definitely stuck in the 60's.

  AS> Sure.  It's a reprint of the original, plus a few later essays.
  AS> _No Silver Bullet_ and... I forget.

in that essay, (from 1986), he is asking whether ada will be assessed
well. by most opinions it is a failure as it is only used in government
and military stuff as it is required. i doubt he ever has used a unix
box or perl even since then. so his view of tools is still a very
monolithic and handcuffing (even though he says ada is meant for modular
design and objects). the freedom of perl would probably scare all old
blue suiters to death.

but as i said, it is a must read!!

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.


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

Date: 28 Jul 1999 17:33:48 GMT
From: "William" <bivey@teamdev.com>
Subject: Re: ebcdic packed numbers
Message-Id: <01bed91f$7397e2e0$583c08cf@bill.jump.net>


Uri Guttman <uri@sysarch.com> wrote in article
<x7pv1csp0b.fsf@home.sysarch.com>...
> >>>>> "BL" == Bart Lateur <bart.lateur@skynet.be> writes:
[...]
>   BL> Are you sure it will fail? Suppose, as a simple example, that the
upper
>   BL> nibble is 1, the lower nibble is 2 (byte = 18). If you print it out
as a
>   BL> hexadecimal number, you get "12". What's would you want as the
value for
>   BL> the byte? 12.
> 
> you are missing the key point, it is a DECIMAL number!! you encode 1234
> as 0x1234 which is not the value 0x1234. if i add 6 to that value, in
> bcd you want 0x1240 while in hex you get 0x123a. carry occurs at 10,
> like in the arithmetic you learned in grade school. :-)

I believe what he means to do is something like this:

	$value = hex '0x1234';
	print "$value\n";
	$newval = sprintf( "%x\n", $value );
	print "$newval\n";
	$newval += 6;
	print "$newval\n";

You'll notice that it correctly handles the math because by
that time the value is decimal, not packed BCD or hex. I
don't think he meant to imply operating on packed BCD
directly, just using printf to interpret one digit per
nybble and treating it as decimal after that. -Wm


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

Date: 28 Jul 1999 13:52:42 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: ebcdic packed numbers
Message-Id: <x73dy8slud.fsf@home.sysarch.com>

>>>>> "W" == William  <bivey@teamdev.com> writes:

  W> Uri Guttman <uri@sysarch.com> wrote in article
  W> <x7pv1csp0b.fsf@home.sysarch.com>...

  >> you are missing the key point, it is a DECIMAL number!! you encode 1234
  >> as 0x1234 which is not the value 0x1234. if i add 6 to that value, in
  >> bcd you want 0x1240 while in hex you get 0x123a. carry occurs at 10,
  >> like in the arithmetic you learned in grade school. :-)

  W> I believe what he means to do is something like this:

  W> 	$value = hex '0x1234';
  W> 	print "$value\n";
  W> 	$newval = sprintf( "%x\n", $value );
  W> 	print "$newval\n";
  W> 	$newval += 6;
  W> 	print "$newval\n";

  W> You'll notice that it correctly handles the math because by
  W> that time the value is decimal, not packed BCD or hex. I
  W> don't think he meant to imply operating on packed BCD
  W> directly, just using printf to interpret one digit per
  W> nybble and treating it as decimal after that. -Wm

but you are using perl to convert the string '1234' to the binary value
which represents 1234. i said effectively the same thing. you can't
operate on bcd in perl directly nor can you convert it to/from an intger
directly. using sprintf to get the ascii for the decimal number and then
a math operation to get the integer is fine. also that doesn't handle
the sign nibble at all but that is not too hard to code. also try
reversing the operation! you will need pack or vec to put the nibbles
into the string. in fact it would be much better to do it in c like i
had to do all those years ago!

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.


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

Date: Wed, 28 Jul 1999 13:00:13 -0400
From: andy barfoot <gt7202e@prism.gatech.edu>
Subject: Re: eval
Message-Id: <379F371D.DDA2111B@prism.gatech.edu>

renorum@my-deja.com wrote:
> 
> I am trying to use eval to call a certain subroutine depending on the
> value of a given variable:
> 
>           eval($action());
> 
> where $action could be either "add" or "delete" or "edit".  I have
> written the subroutines add(), delete() and edit().

You could say
	sub add {
		...
	}
	sub delete {
		...
	}
	...
	eval "$action()";

Don't forget to ensure $action isn't something evil.

A much cleaner way, imho, would be

	my %dispatch = ();
	$dispatch{add} = sub {
		...
	};
	$dispatch{delete} = sub {
		...
	};
	...

	$dispatch{$action}->(parameters);





-- 
 andy barfoot


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

Date: Wed, 28 Jul 1999 10:12:43 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: eval
Message-Id: <MPG.1208d9e71ff68648989d64@nntp.hpl.hp.com>

[Posted and a courtesy copy sent.]

In article <7nna98$38d$1@nnrp1.deja.com> on Wed, 28 Jul 1999 16:14:38 
GMT, renorum@my-deja.com <renorum@my-deja.com> says...
> I am trying to use eval to call a certain subroutine depending on the
> value of a given variable:
> 
>           eval($action());
> 
> where $action could be either "add" or "delete" or "edit".  I have
> written the subroutines add(), delete() and edit().
> 
> Am I using this correctly? (because it doesn't seem to be working)  Is
> this not what eval is used for?

It could be used for that, but it shouldn't be!

>                                  Is there some better way to effect
> this result (other than the obvious
>           if ($action eq "add") { add(); }
>           elsif ($action eq "delete") { delete(); }     ...etc, etc.)


#!/usr/local/bin/perl -w
use strict;

my %subs = ( add => \&add, delete => \&delete, edit => \&edit );

sub add { 'add' } sub delete { 'delete' } sub edit { 'edit' }

my $action = 'add';

print &{$subs{$action} || die "No sub '$action'\n"};

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


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

Date: 28 Jul 1999 17:35:36 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: eval
Message-Id: <7nnf18$lnq$1@info2.uah.edu>

In article <379F371D.DDA2111B@prism.gatech.edu>,
	andy barfoot <gt7202e@prism.gatech.edu> writes:
: $dispatch{$action}->(parameters);

To emphasize this point, consider this passage from Rob Pike's "Notes
on Programming in C" <URL:http://www.lysator.liu.se/c/pikestyle.html>
(don't forget to s/function pointers/subroutine references/ig):

    Function pointers

    Another result of the tyranny of Pascal is that beginners don't use
    function pointers.  (You can't have function-valued variables in
    Pascal.) Using function pointers to encode complexity has some
    interesting properties. 

    Some of the complexity is passed to the routine pointed to.  The
    routine must obey some standard protocol--it's one of a set of
    routines invoked identically - but beyond that, what it does is its
    business alone.  The complexity is distributed. 

    There is this idea of a protocol, in that all functions used
    similarly must behave similarly.  This makes for easy documentation,
    testing, growth and even making the program run distributed over a
    network - the protocol can be encoded as remote procedure calls. 

    I argue that clear use of function pointers is the heart of
    object-oriented programming.  Given a set of operations you want to
    perform on data, and a set of data types you want to respond to
    those operations, the easiest way to put the program together is
    with a group of function pointers for each type.  This, in a
    nutshell, defines class and method.  The O-O languages give you more
    of course - prettier syntax, derived types and so on - but
    conceptually they provide little extra. 

    Combining data-driven programs with function pointers leads to an
    astonishingly expressive way of working, a way that, in my
    experience, has often led to pleasant surprises. Even without a
    special O-O language, you can get 90% of the benefit for no extra
    work and be more in control of the result.  I cannot recommend an
    implementation style more highly.  All the programs I have organized
    this way have survived comfortably after much development--far
    better than with less disciplined approaches.  Maybe that's it: the
    discipline it forces pays off handsomely in the long run. 

(Rob Pike)++

Greg
-- 
A little poison now and then: that makes for pleasant dreams. And
much poison at the end for a pleasant death.
    -- Nietzsche


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

Date: Wed, 28 Jul 1999 17:26:14 GMT
From: roger@wheelpro.co.uk (Roger Musson)
Subject: File maintenance algorithm required
Message-Id: <379f3b06.3798475@nntp.netcomuk.co.uk>

I need to add a line of data to the front of a file (i.e. not
appending). The file is several thousand lines long and about 5mb file
size.

I am using the following at the moment (psuedo code shown)

create TEMP
print new line to TEMP
while (<DATA>)
    print to TEMP
rename TEMP, DATA

Is there a better, faster method?

Thanks,
Roger Musson


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

Date: 28 Jul 1999 17:37:54 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: File maintenance algorithm required
Message-Id: <7nnf5i$lnq$2@info2.uah.edu>

In article <379f3b06.3798475@nntp.netcomuk.co.uk>,
	roger@wheelpro.co.uk (Roger Musson) writes:
: I need to add a line of data to the front of a file (i.e. not
: appending). The file is several thousand lines long and about 5mb file
: size.

Please read the FAQ.  The FAQ is included with the Perl distribution and
is also available on the web at <URL:http://www.perl.com/perl/faq/>.

Greg
-- 
Fenster: I had a guy's fingers in my asshole tonight.
Hockney: Is it Friday already?


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

Date: Wed, 28 Jul 1999 13:58:12 -0400
From: "Peter Robichaud" <probichaud@nonlinear.ca>
Subject: Filehandler... Can you email attachments???
Message-Id: <rpuh6o$0$37nspbi$n2p@corp.supernews.com>

thanks,

I was wondering if it was possible to send a file attachment out with a form
generated email...

is there a special script or program I need to perform this sort of
operation? or is it not possible at all?

any input would be greatly appreciated,
thanks again,

newbie...




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

Date: Wed, 28 Jul 1999 17:20:56 GMT
From: sn0brdr@yahoo.com
Subject: help w/command line argument
Message-Id: <7nne5g$62q$1@nnrp1.deja.com>

hi,

i'm a (perl) newbie w/a question re: command line argument.

what should i use to do:
   progname   arg(s)

i was able to use Getopt::Std, but i'm trying to make this proggie
easier for the end users so they don't have to memorize the switches.
the ability to see output and error would be great.

what is your suggestion?

tia,
another perl newbie


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: 28 Jul 1999 17:40:00 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: help w/command line argument
Message-Id: <7nnf9g$lnq$3@info2.uah.edu>

In article <7nne5g$62q$1@nnrp1.deja.com>,
	sn0brdr@yahoo.com writes:
: what should i use to do:
:    progname   arg(s)

Use one of the Getopt option parsers or write your own.  It's not that
hard.  We might offer code, but you don't say what you want.

: i was able to use Getopt::Std, but i'm trying to make this proggie
: easier for the end users so they don't have to memorize the switches.

No one has every switch of every utility memorized.  Write a good man
page so people can look up the options if they need to.

: the ability to see output and error would be great.

Maybe you should elaborate on this so we can get a better idea of what
you want.

Greg
-- 
Politicians and diapers have one thing in common. They should both be changed
regularly and for the same reason. 
    -- Gerry Brooks


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

Date: 28 Jul 1999 17:24:51 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: HELP! tied DB_RECNO ->put() fails with R_IAFTER
Message-Id: <7nned3$bcs$1@lublin.zrz.tu-berlin.de>

Sara London <SaraNOS@ixPAMquick.com> wrote in comp.lang.perl.misc:
>Hi! I am trying to manipulate a  file opened via _tie_ with DB_RECNO.

[symptoms snipped]

Just an unqualified shot in the dark:  Which version of Berkeley DB are
you using?  The newish 2.7.5 (available from www.sleepycat.com) has
quite a few bug fixes.

Anno


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

Date: Wed, 28 Jul 1999 16:57:09 GMT
From: andrewfase@my-deja.com
Subject: Help!! ---Database access in perl
Message-Id: <7nncp0$4v3$1@nnrp1.deja.com>

I need some help please!!

I am designing a site for a computer company, and they want a online
database of all there stock

The problem is that the table has 30000+ entries!!

i was going to use Sprite to access it, but i am thinking the database
is just to big for it.

Can anyone tell me what i could use??? and where to find tutorial's to
use it (maybe MySql ???)

One last thing it has to be free!!!!!

Thanks in advance!!!

please email andrew.fase@stud.umist.ac.uk


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Wed, 28 Jul 1999 17:53:14 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: help: push array refs into hash, sort by refs in hash - REPOST
Message-Id: <7nng6j$mn5$3@news.mch.sbs.de>

In article <campbell-lange-2807991759030001@campbell-lange.easynet.co.uk>, campbell-lange@easynet.co.uk (Rory C-L) wrote:
>I have a sets of records some of which belong to the same "issue number"
[snip]

Yes, we've seen your question before. Don't repost the same
question under two different subjects... People might put you
in their kill file (just a hint).


Michel.


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

Date: 28 Jul 1999 17:24:06 GMT
From: mwang@tech.cicg.ml.com (Michael Wang)
Subject: Re: Korn Shell or Perl?
Message-Id: <7nnebm$1he$1@news.ml.com>

brian d foy <brian@pm.org> wrote:
>> what I did and Randal did are different. I would think if
>> keys(%::beeper_byname) or `ypcat -k beeper.byname` are large enough
>> and exceed the system memory, my "awkard" code will survive, and Randal's
>> better code will break. 
>
>why do you think that?  you use both of those constructs in your code,
>so you run out of memory as well.  if you expect that hash to be large,
>you probably want it in a DBM file, but then you need to iterate through
>with something like each() perhaps.
 
Thanks for the comments. My understanding is 
"ypcat -k beeper.byname | while read i" type of construct has no 
"over the memory" problem, since the memory is used in occupy-n-release
fashion. 

People suggested to use
foreach `ypcat -k beeper.byname`
foreach map {}
foreach do {}
type of construct. I do not know how memory gets used. It could be used
in occupy-n-release fashion or it could allocate the whole chunk of memory
for `ypcat -k beeper.byname`. I believe this depends on Perl implementation.
I think the former is efficient use of memory, you indicate that Perl is
not implemented that way, which I do not understand. 

I do use DBM file. If the file is local, I use dbmopen, and something like 
each() as you suggested which has no memory usage problem. However if
the system use "NIS" aka "yp", the file is not local and one has to use
RPC to access the DBM file. That is why "ypcat" comes in. What I am trying
to do is to avoid is to load the whole thing of ypcat in the memory. 
-- 
Michael Wang
http://www.mindspring.com/~mwang


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

Date: 28 Jul 1999 13:43:31 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Korn Shell or Perl?
Message-Id: <x77lnksm9o.fsf@home.sysarch.com>

>>>>> "MW" == Michael Wang <mwang@tech.cicg.ml.com> writes:

  MW> I do use DBM file. If the file is local, I use dbmopen, and
  MW> something like each() as you suggested which has no memory usage
  MW> problem. However if the system use "NIS" aka "yp", the file is not
  MW> local and one has to use RPC to access the DBM file. That is why
  MW> "ypcat" comes in. What I am trying to do is to avoid is to load
  MW> the whole thing of ypcat in the memory.  -- Michael Wang


then loop over reading lines from ypcat which was opened with a pipe:

(untested of course)

open( YP, 'ypcat beepers.byname|' ) || die "beepers suck anyway $!" ;

while( <YP> ) {

	next if /^YP_/ ;

	blah blah
}

no memory used except per line and the pipe buffering.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.


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

Date: Wed, 28 Jul 1999 17:36:47 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: Newbie sort and references question.
Message-Id: <7nnf7o$mn5$1@news.mch.sbs.de>

In article <campbell-lange-2807991505080001@campbell-lange.easynet.co.uk>, campbell-lange@easynet.co.uk (Rory C-L) wrote:
>I have a sets of records some of which belong to the same "issue number"
>
>i.e.
>Issue     Date     Number          Revision
>636/1999     23/2/99  A/LB/10/00/229  D                        
>780/1999     21/4/99  A/LB/10/00/249  C 
>874/1999      1/6/99  A/LB/10/01/003  R                          
>780/1999     14/1/99  A/LB/10/02/028  C                                
>487/1998     4/12/98  A/LB/10/04/021  J 
>
>I'd like to sort the records by number, collected by Issue.

In what order should the issues appear ? By issue, by the lowest
number for that issue, by the first date for that issue, ... ?

>I split the records into issue and @rest.
>Then I want to $hash{$issue} = [@rest], unless $hash{$issue} already exists,
>in which case I'm using $hash{$issue} .= [@rest]. However THEN I have two
>refs appended to each other, rather than an array of refs.
>Should I initialise $hash{$issue} = []; then push subsequent array refs to it?
>I'm a bit confused.

Have you thought of using a simple array, like :

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

chomp(@array = <DATA>);
print map { $_->[0] . "\n" }
        sort { $a->[1] cmp $b->[1] || $a->[3] cmp $b->[3] }
        map { [ $_, split ] } @array;
exit;
__DATA__
636/1999     23/2/99  A/LB/10/00/229  D
780/1999     21/4/99  A/LB/10/00/249  C
874/1999      1/6/99  A/LB/10/01/003  R
780/1999     14/1/99  A/LB/10/02/028  C
487/1998     4/12/98  A/LB/10/04/021  J

This sorts the entries by Issue and then by Number :

487/1998     4/12/98  A/LB/10/04/021  J
636/1999     23/2/99  A/LB/10/00/229  D
780/1999     21/4/99  A/LB/10/00/249  C
780/1999     14/1/99  A/LB/10/02/028  C
874/1999      1/6/99  A/LB/10/01/003  R

>A related sort question:
>
>I have a hash structured like this:
>
>   key   value (ref to anonymous array) 
>    |      |
>    x    (anonymous) array with refs to 1 .. n anonymous arrays
>           |
>         array array array
>           |
>         first element
>         
>         
>I'd like to sort a hash by the 1st element of the 1st array of the array
>referenced by value.
>The structure of the element is a set of numbers followed by a '/' then
>some letters. Its only the numbers I'm interested in.

Something like this might work :

@sortedkeys = map { $_->[0] }
        sort { $a->[1] <=> $b->[1] }
        map { [ $_, split('/',$hash{$_}[0][0]) ] } keys %hash;

Again, you might re-think your data structure before going any further...
Have a look at perldsc, perllol and perlref for some pointers :-)

Have fun,

Michel.

--
aWebVisit - extracts visitor information from WWW logfiles and shows
the top entry, transit, exit and 'hit&run' pages, the links followed
inside your website, the time spent per page, the visit duration etc.
For more details, see http://gallery.uunet.be/Michel.Dalle/awv.html


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

Date: Wed, 28 Jul 1999 17:44:55 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: Passing an Array into a HIDDEN FIELD
Message-Id: <7nnfn1$mn5$2@news.mch.sbs.de>

In article <379FC827.8ABB17B9@altavista.net>, Patrick Lam <p.lam@altavista.net> wrote:
[snip]
>Looking at the CGI page at http://stein.cshl.org/WWW/software/CGI/, I
>tried something like:
>print $cgi->hidden(-name=>'theList' -default=>@theArray),
>where the array contains the elements I wish to store.

Have you tried [@theArray] instead of @theArray ?

Who knows, that might work :-)

Michel.


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

Date: Wed, 28 Jul 1999 17:12:37 GMT
From: Martin Grossman <grossman@bbn.com>
Subject: perl timeouts
Message-Id: <379F3A14.9F4F970C@bbn.com>

A program is timeing out and I don't know if its perl or the program....

Here the part of the perl program that fails....

$error .= "ERROR #1\r\n" unless open ( CMD, "$cmd | " );
while ( <CMD>){
        .
        .
        .
}
close CMD;
if ( $?) {
    $error .= "ERROR #2\r\n";
}

When it fails:
    1) I get "ERROR #2"
    2) Exit code from program $cmd is #14 (Solaris 2.6)
    3) and in system accounting file $cmd ran for exactly 30 minutes (to
the second)
        and produced no output!

SO, I can't figure out if perl killed the program after 30 minutes of
getting no output OR
      somethings wrong with the program $cmd and it ran for exactly 30
minutes and exited
      with errno =14 (EFAULT).

PS I've grepped perl5 source code and can't find anywhere it would time
out a sub-process.
     I've also grepped $cmd src code and do see any timeouts their
either!

PPS only other choice is Solaris ToolTalk!
       $cmd uses tooltalk to send/receive 3 different messages and maybe
tooltalk times out a request
       if no process handles it or sends a reply message.

Please respond via email to grossman@bbn.com or
martin.grossman@cybertrust.gte.com




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

Date: 28 Jul 1999 17:20:26 GMT
From: vcuya@mindspring.com
Subject: Re: Perl, FTP, and Win32 with IIS (ouch)
Message-Id: <7nne4q$l2k$1@nntp9.atl.mindspring.net>

You can also try to use the Win32::Internet extension which uses MS' 
wininet.dll. It gives you more control in a Win32 environment.

Good luck


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

Date: Wed, 28 Jul 1999 18:04:34 +0100
From: John Imrie <jimrie@guideguide.com>
To: nds@instrumental.com
Subject: Re: Premature end of script headers???
Message-Id: <379F3822.E8CA2C19@guideguide.com>

>
> [Wed Jul 28 08:04:37 1999] access to /my/dir/app.cgi failed for
> my.client.com,
> reason: Premature end of script headers

This is a CGI problem not a Perl problem.  Try reading the Apache FAQ at
www.apache.org or posting to comp.infosystems.www.servers.unix



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

Date: Wed, 28 Jul 1999 17:36:37 GMT
From: bidyut@yahoo.com
Subject: Reading the binary files in Perl
Message-Id: <7nnf35$6in$1@nnrp1.deja.com>

Hi there,
I have a problem here. I have to use Perl to read a binary file ( that
is produced by a C program) and parse the data out of it. Also to
mention that I know the length of each record.
So what I do is I read one record and use unpack() to parse the data.
The problem is I am able to get all the string data, but unable to get
any integer or float or short etc.

When i was going through Java FAQ, I found out that  Java reads it
differently than the C program. So i am curious whether is there a
similar case in Perl or what. If so, then how to get around it and if
not, then why am I having problem in reding numeric data types.

I would be happy if somebody can help me out .
Thanks and Regards
Bidyut


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: 28 Jul 1999 13:08:30 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Selecting files by permisions
Message-Id: <x7d7xcsnw1.fsf@home.sysarch.com>

>>>>> "KL" == Keith Lee <leejk@cat.com> writes:

  KL> Thanks, that works fine. I cannot use a chmod * because commands
  KL> like cp, rm, and such cannot handle more than 2000 or so files at
  KL> a time, unless you go in and tweak the kernel parameters a little,
  KL> which is not an option for me. Just one more question; what is the
  KL> meaning of '&'. I can't find it anywhere in my books. I see '&&',
  KL> but this seems different.

as others keep saying, put quoted text BEFORE your reply. that way
readers can see what & you are talking about.

  >> unless (((stat $file) [2] & 07777) == 00644) { ... }

now, think, what could that mean? have you ever heard of masking? or bit
operations? and what books are you reading? & is in the index of the
camel and it refers to the page which describes its operation just fine.

i bet perlop describes it too. try a little harder in your research next
time. it will make your perl life much more enjoyable. if you practice
that, it will be come easier and more productive. 

hey, that's a thought to tell other newbies. researching answers is a
skill in itself that needs practicing. so rtfm and rtfaq is good for
you!

uri


-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.


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

Date: Wed, 28 Jul 1999 17:40:03 +0100
From: Nick Sanders <nick.sanders@lineone.net>
To: MARTIN@RADIOGAGA.HARZ.DE
Subject: Re: Server NT et Perl
Message-Id: <379F3263.EEEE2AEF@lineone.net>

I'm running Netscape Enterprise Server on NT and it runs the script with full
path name so the present working directory is the C drive. Would these % values
help or maybe someone knows how get it to run the script from the cgi-bin so I
when I declare my modules iI don't  have to define the full path name.

Thanks

Nick

Martin Vorlaender wrote:

> Jean-Marc Beaudoin (beaudoin.jean-marc@-NOSPAM-hydro.qc.ca) wrote:
> : Vincent Maugain <V_Maugain@mail.dotcom.fr> a écrit:
> : > I try to work on a server NT and when I start my form, my navigator
> : > puts me the source of my file offre_cgi.pl
> ...
> :
> : You must configure your Web Server (ie.: IIS) for the proper script mapping
> : to .pl or .cgi so it will know what to do with them.
> :
> : Ie.:    Map .pl to c:\perl\bin\perl.exe % %
> :
> : The % % are very important.
>
> It's particularly important to not post wrong information:
> Those % must be %s (perhaps even in "").
>
> And if the server offers the script source for download, it's not the
> mapping that is wrong; the problem is that the server doesn't recognize
> the directory as a script directory.
>
> cu,
>   Martin
> --
>                         | Martin Vorlaender | VMS & WNT programmer
>  VMS is today what      | work: mv@pdv-systeme.de
>  Microsoft wants        |       http://www.pdv-systeme.de/users/martinv/
>  Windows NT 8.0 to be!  | home: martin@radiogaga.harz.de



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

Date: Wed, 28 Jul 1999 08:19:37 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: splitting an array - well not really but ...
Message-Id: <pgsmn7.mmn.ln@magna.metronet.com>

Eric Smith (eric@fruitcom.com) wrote:

: I would like to take an array like say @ARGV and instead of having each
: token (if the arguments) as an array element, I would like to have each
: group of tokens a an element in the top level array.  


   They are put into separate @ARGV elements by the shell,
   before perl is invoked.

   You can, of course, put them back together in your program.


: After that I wish to
: take the group and split that on white space to form an array of arrays
: thusly.

: command.pl john m smi, pete MBchB school, mike west high 

: @first= qw(john m smi) 
: @second= qw(pete MBchB school) 
: @third= qw(mike west high)

: @top=(@first, @second, @third)


   That last part isn't going to work, because the (...) will be
   "flattened" into a single list. You cannot tell where @first
   ends and @second begins...

   It makes a regular old one-dimensional array with all of the
   "name parts" in it.

   You could put 3 _references_ to arrays into @top though:

      @top=(\@first, \@second, \@third);

   But you don't need the temporary intermediate arrays anyway, see below.


: How do I best process the @ARGV to return the above?
: It seems you cannot use `split' on the comma for an array. 


   Of course not.

   split() works on a string, not on an array.

   But you can join() the array elements to form a string,
   then split() _that_:

----------------------------------
#!/usr/bin/perl -w
use strict;

my @top;   # an array of references to arrays (LoL)

my $index=0;  # start at the beginning

# join args with space, then split on comma
foreach my $comma_group ( split /,\s*/, join ' ', @ARGV ) {
   push @{$top[$index++]}, split ' ', $comma_group;
}

foreach my $i ( 0..2 ) {
   print "array $i:\n";
   foreach my $name_part ( @{$top[$i]} ) {
      print "   $name_part\n";
   }
}
----------------------------------


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


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

Date: Wed, 28 Jul 1999 13:13:44 -0400
From: andy barfoot <gt7202e@prism.gatech.edu>
Subject: Re: Using perl CGI under NT
Message-Id: <379F3A48.9C4461DB@prism.gatech.edu>

George Crane wrote:

> where $mail is
> $mail = "j:\sendmail\sendmail.exe";
> or
> $mail = '/usr/lib/sendmail';
> and $pairs{'FHP'} is the emai of the recipiant.
> What am I doing wrong????


$mail = "j:\sendmail\sendmail.exe";
print "Your clue is: $mail\n";



-- 
 andy barfoot


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

Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 1 Jul 99)
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 V9 Issue 285
*************************************


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