[13956] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1366 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 13 03:12:33 1999

Date: Sat, 13 Nov 1999 00:05:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <942480310-v9-i1366@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 13 Nov 1999     Volume: 9 Number: 1366

Today's topics:
        arrays of arrays confusion... <debtman@my-deja.com>
    Re: arrays of arrays confusion... <slanning@bu.edu>
    Re: arrays of arrays confusion... <moseley@best.com>
    Re: cgi page instead of html (www.www2.internetpros.com)
    Re: CGI.pm and Netscape 4.x (www.www2.internetpros.com)
        Date Of Birth from TODAY <webmaster@beautiful-ladies.com>
    Re: Debugging CGI under NT... (Martin Vorlaender)
    Re: funny behaviour of Perl (Abigail)
    Re: Generating pi <steve@corp.airmedia.com>
    Re: Help needed fast please (Tad McClellan)
        Help needed please, simple hash slice question! (Max)
    Re: Help needed please, simple hash slice question! <moseley@best.com>
        How can I vist a number of websites and email addys tony_123@my-deja.com
    Re: How can I vist a number of websites and email addys <moseley@best.com>
    Re: How can I vist a number of websites and email addys tony_123@my-deja.com
    Re: How can I vist a number of websites and email addys tony_123@my-deja.com
        How to call a xs sub with a hash (Gustav Kristoffer Ek)
    Re: how to create a random id? (Abigail)
    Re: How to retrieve substrings at fixed position in a s <bowman@montana.com>
    Re: How to retrieve substrings at fixed position in a s (Martien Verbruggen)
    Re: How to retrieve substrings at fixed position in a s <lr@hpl.hp.com>
    Re: IO-Tty binary package for W95? (Bbirthisel)
        looking for a developer . . .  <vibrant@iinet.net.au>
    Re: Need help understanding directory structure (NEWBIE <votemand@earthlink.net>
    Re: output a binary file to browser from perl script (David Efflandt)
    Re: printing a number with 3 digits (Simon Cozens)
    Re: Serious memory leak in MacPERL? (Henry Penninkilampi)
    Re: Weekday in perl (J. Moreno)
    Re: Writing data to file on another server. <cans1@hotmail.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sat, 13 Nov 1999 03:40:05 GMT
From: debtman <debtman@my-deja.com>
Subject: arrays of arrays confusion...
Message-Id: <80imil$r5l$1@nnrp1.deja.com>



I need to generate a tree structure from a database. Basically the
database has a record_id and a parent_id, and I need to make an array
with the parent id as the key which contains an array of id's. What I
figure I need to do is have the first array $array[$parent_id] reference
an array which I can then push values onto. But I'm not sure what the
most efficient way to do this is. Do I need to check and make sure
$array[$parent_id] already exists, how do I reference each element in the
array to another array? I understand how to create arrays of arrays where
you have all the data, but I need to loop through and add to it, and
dynamically grow both of the arrays... Very confusing :)


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 12 Nov 1999 23:47:35 -0500
From: Scott Lanning <slanning@bu.edu>
Subject: Re: arrays of arrays confusion...
Message-Id: <kusu2mrf15k.fsf@strange.bu.edu>

debtman <debtman@my-deja.com> writes:
[snip]

LOL!

List of lists, BTW, not laughing out loud.
RTFM: perldoc perllol

HTH. HAND.

-- 
"If lightning is the anger of the gods, the gods are concerned mostly
with trees." --Lao Tse


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

Date: Fri, 12 Nov 1999 20:49:41 -0800
From: Bill Moseley <moseley@best.com>
Subject: Re: arrays of arrays confusion...
Message-Id: <MPG.12968dbd2e89ed6e98986a@nntp1.ba.best.com>

debtman (debtman@my-deja.com) seems to say...
> I need to generate a tree structure from a database. Basically the
> database has a record_id and a parent_id, and I need to make an array
> with the parent id as the key which contains an array of id's. What I
> figure I need to do is have the first array $array[$parent_id] reference
> an array which I can then push values onto. But I'm not sure what the
> most efficient way to do this is. Do I need to check and make sure
> $array[$parent_id] already exists, how do I reference each element in the
> array to another array? I understand how to create arrays of arrays where
> you have all the data, but I need to loop through and add to it, and
> dynamically grow both of the arrays... Very confusing :)

"parent id as the key"?

Key?  Maybe the wine has gone to my head, but don't you want a hash?  
Seems like you want to be able to look up record_ids by parent_ids?

my %parents;

# Add an id to a parent
push @{ $parents{ $parent_id } } , $record_id;

If you might come across a duplicate record_id then I'd use a hash of 
hashes:

$parents{ $parent_id }{ $record_id }++;

The more I use perl the less often I use array indexes.  That's me being 
lazy and not caring about memory, I guess.

perldoc perllol
perldoc perldsc
perldoc perref

-- 
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.


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

Date: Sat, 13 Nov 1999 02:20:49 GMT
From: mpm@unix2.megsinet.net (www.www2.internetpros.com)
Subject: Re: cgi page instead of html
Message-Id: <slrn82pj0s.1c4.mpm@unix2.megsinet.net>

In article <Pine.HPP.3.95a.991112191307.23951F-100000@hpplus01.cern.ch>, 
Alan J. Flavell wrote:
>On Fri, 12 Nov 1999, Dott Gabriele Gallacci wrote:
>
>>  Can I configure apache to start perl script when .html page are requested?
>
>You evidently already know where to look.  If you couldn't see it
>yourself from the Apache documentation, then good places on usenet to
>ask are comp.infosystems.www.servers.(unix|ms-windows) depending on your
>OS.  For either set of OSes, the answer would be yes.
>
>For the modern way to do it, look at AddHandler.  But the old way using
>magic mime types also works.  Put your directive(s) inside a <Files...>
>or <FilesMatch...> bracket specifying the particular .html files that
>you want treated in this way.  If this is unix, don't forget to make
>them world executable as well as readable (mode 0??5), and of course
>Options +ExecCGI must be in effect for the directory.
>
>I would offer more advice, but this is the wrong place, and I sense
>that the referee's whistle is about to be blown...  if not a red card...
>

A quicker solution (not necessarily better, but works especially well if the
programmer doesn't have administrative access to change httpd.conf) is to use
met tags to redirect the browser to the CGI script.  Like so:

<html><head>
<meta http-equiv="Refresh" content="0; URL=/cgi-bin/script.cgi">
</head>
<body></body>
</html>

You'd need to save this file with the extension .shtml (server-parsed HTML).

--Mike


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

Date: Sat, 13 Nov 1999 02:13:08 GMT
From: mpm@unix2.megsinet.net (www.www2.internetpros.com)
Subject: Re: CGI.pm and Netscape 4.x
Message-Id: <slrn82piie.1c4.mpm@unix2.megsinet.net>

In article <3L%W3.2281$YI2.122079@typ11.nn.bcandid.com>, CS wrote:
>Greetings,
>
>whenever I send output to an MS Internet Explorer browser, things turn out
>fine, but when the same text is sent to a Netscape browser, this is what
>happens:
>
>print $q->header,$q->start_html;
>print $q->h1('Blah');
>print $q->end_html;
>
>And this is what is displayed (in the browser, not the source):
>
><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
><HTML><HEAD><TITLE>Untitled Document</TITLE>
></HEAD><BODY><H1>Blah</H1></BODY></HTML>
>
>Does CGI.pm need to do something different to get it to work?

Odd... the perl snippet you wrote looks fine, and should ostensibly echo output
that Netscape can parse correctly.  Unsure if this is it, but for some reason 
CGI.pm might not be providing the correct Content-Type header.  You could
see what infor the $q->header() method is providing by putting a line like

	print STDERR $q->header,"\n\n";

right before you start echoing HTML back to the client.  You could also try
forcing the $q->header() method to use a particular content-type:

	print $q->header(-type => 'image/gif');

In any case, it sounds like it's a problem on the server's side.

--Mike


>Regards, Chris S.
>
>


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

Date: Sat, 13 Nov 1999 07:17:30 GMT
From: Andrej <webmaster@beautiful-ladies.com>
Subject: Date Of Birth from TODAY
Message-Id: <80j3a9$36f$1@nnrp1.deja.com>



Hello,
Recently I began to use Woda data base(http://itc.fgg.uni-lj.si/woda/ )
Actually I began to study Perl with it, so I not the expert :-)

I have one simple problem, I need to calculate age using today's date
and
date of birth and I would not like to use additional perl modules...

I have many htm files with bio-data of peoples which I gradually, by
hand
add to data base
In these bio-data are specified day, month and year of birth.
 In Woda's *.rec files it is submitted as:

%dayOfBirth: 30
%monthOfBirth: November
%yearOfBirth: 1967


I have received some ideas (see below), but it works if the month are
specified as numbers, Ie. %monthOfBirth: 11

Somebody has any ideas, how it can work if %monthOfBirth is specified
by the
letters, Ie. %monthOfBirth: November
------------------------------------
 It is a code, which works with "numerical %monthOfBirth"

($current_day, $current_month, $current_year) = (localtime)[3..5];
$current_month +=1;
$current_year +=1900;


$Age= $current_year - $rec{yearOfBirth};
$Age-- if ($current_month < $rec{monthOfBirth} or ($current_month ==
$rec{monthOfBirth} and $current_day < $rec{dayOfBirth}));

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

I feel it is necessary establish something eg.
(1,2,3,4,5,6,7,8,9,10,11,12) = (January, February, March, April, May,
June,
July, August, September, October, November, December);

However, I in impasse here...
Please!!! Help!!! And thank you in advance!
Andrej Kartashov
--
><><><><><><><><><><><><><><><><><><><><><>><><><><><><><><><><
>| 1+1 Lonely hearts Marriage agency
>| E-mail forwarding & flower delivery in Bishkek, Kyrgyzstan
>| MAILto:djusha@infotel.kg
>| http://www.beautiful-ladies.com/ -or- http://1-lh.hypermart.net/
><><><><><><><><><><><><><><><><><><><><><>><><><><><><><><><><


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sat, 13 Nov 1999 05:49:51 +0100
From: martin@RADIOGAGA.HARZ.DE (Martin Vorlaender)
Subject: Re: Debugging CGI under NT...
Message-Id: <382cedef.524144494f47414741@radiogaga.harz.de>

I use another approach:

    if (defined $cgi_dbg && $ENV{'CGI_SCRIPT_DEBUG'}) {
        open CGI_DBG, "<$cgi_dbg" or die "Can't open $cgi_dbg: $!";
        $cgi = new CGI(\*CGI_DBG);
        close CGI_DBG;
    } else {
        $cgi = new CGI;
        if (defined $cgi_dbg) {
            open CGI_DBG, ">$cgi_dbg" or die "Can't open $cgi_dbg: $!";
            $cgi->save(\*CGI_DBG);
            close CGI_DBG;
        }
    }

That is, I pass the arguments online via the intended interface, and debug
in a second pass on the command line (where I define the environment variable
CGI_SCRIPT_DEBUG).

When I get the script straight, I set $cgi_dbg to undef.

cu,
  Martin
--
                       |  Martin Vorlaender  |  VMS & WNT programmer
  OpenVMS: When you    |  work: mv@pdv-systeme.de
  KNOW where you want  |        http://www.pdv-systeme.de/users/martinv/
  to go today.         |  home: martin@radiogaga.harz.de


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

Date: 12 Nov 1999 21:00:07 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: funny behaviour of Perl
Message-Id: <slrn82pl8b.lmh.abigail@alexandra.delanet.com>

Bart Lateur (bart.lateur@skynet.be) wrote on MMCCLXIV September MCMXCIII
in <URL:news:382c75e9.1029129@news.skynet.be>:
"" Randal L. Schwartz wrote:
"" 
"" >Well, provided they are named "foobar", which rules out
"" >nearly everything I've written. :)
"" 
"" It then probably needs to be changed to:
"" 
"" 	perl fredbarney


Nah, it's Randal. So, it's:

        perl 'fred&barney'


Abigail
-- 
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
                                      print } sub __PACKAGE__ { &
                                      print (     __PACKAGE__)} &
                                                  __PACKAGE__
                                            (                )


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: Fri, 12 Nov 1999 22:11:00 -0500
From: "Steve Protopapas" <steve@corp.airmedia.com>
Subject: Re: Generating pi
Message-Id: <80ikoi$f8m$1@nnrp03.primenet.com>


Yanick Champoux <yanick1@sympatico.ca> wrote in message
news:QX0X3.50774$up3.78461@news21.bellglobal.com...
> In article <80gfho$ou0$1@charm.magnus.acs.ohio-state.edu>,
> ilya@math.ohio-state.edu (Ilya Zakharevich) writes:
> >> Drat! Writing that module would have been fun. Oh well..
> >> Maybe I'll have better luck with 'e'. :)
> >
> > Hmm, e looks harder:
> >
> >   perl -MMath::Pari=:prec=32000,:int -wle "print exp 1"
> >
> > took more than 5 min on my machine.
>
> Double drat! Hmm... The choice of interesting constants is running thin.
>
> I know! I got it! I bet there is no module to compute '1' to
> an arbitrary precision. ;)
>
> Joy,
> Yanick
>
> --
> #! /usr/bin/perl
> ##############  Email: champoux@iro.umontreal.ca
> ##############  Web:   http://www.iro.umontreal.ca/~champoux
> $_ = 'Oxsgnm0qtkdr0nudq0C`fna`g+0ats0nm0S`snhmd0sgd0B`ldk0hr'
> .'0jhmf-';s,(.),!$1?' ':chr(ord($1)+1),eg;print;

Here's an easy one too: e^(pi*i)

P.S. I wonder how long that would take on Ilya's machine? ;)




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

Date: Fri, 12 Nov 1999 16:32:29 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Help needed fast please
Message-Id: <slrn82p1rd.234.tadmc@magna.metronet.com>

On Fri, 12 Nov 1999 15:25:52 -0800, Larry Rosler <lr@hpl.hp.com> wrote:
>In article <x3yogczqzc5.fsf@tigre.matrox.com> on Fri, 12 Nov 1999 
>14:33:47 -0500, Ala Qumsieh <aqumsieh@matrox.com> says...
>> 
>> "Randy Smith" <randys@NOSPAMamigo.net> writes:
>> 
>> > Chris <chris@chrismail.connectfree.co.uk> wrote in message
>> > news:382a87d4.0@news2.cluster1.telinco.net...
>> 
>> > : $ENV{qw(PATH IFS)} = '' x 2;
>> > Did you forget a " in this line?
>> 
>> No he didn't. Those are two single quotes. Not one double quote. You'd
>> better change your newsreader's font to differentiate between the two.
>> 
>> (I had this problem before).
>
>Which is why my response was:
>
>      @ENV{qw(PATH IFS)} = ("") x 2;
>
>Four hen scratches in a row are hard to mistake for two.


   Being of feeble mind, I throw as many reminders at myself
   as possible, so I usually use

      q''

   for the empty string, instead of '' .


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


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

Date: Sat, 13 Nov 1999 02:56:18 GMT
From: mholland@bestweb.net (Max)
Subject: Help needed please, simple hash slice question!
Message-Id: <mholland-1211992156290001@dialin-13.nanuet.bestweb.net>

#Help needed with following script, please!
#Using MacPerl, Learn Perl in 21 days, Chapter 8, Slices
#Why doesn't my slice subset include the keys 'red' and 'green'
#with their corresponding values? All I get are their values.

%hash=('blue',10,'red',20,'green',5);
%hashslice=@hash{'red','green'};

foreach $x (keys %hashslice) {
      print "Key: $x,  Value: $hashslice{$x}\n"; } 

#Result: "Key: 20,  Value: 5"
#What am I doing wrong? Many, many thanks!!! Max


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

Date: Fri, 12 Nov 1999 20:36:00 -0800
From: Bill Moseley <moseley@best.com>
Subject: Re: Help needed please, simple hash slice question!
Message-Id: <MPG.12968a8638df1979989869@nntp1.ba.best.com>

Max (mholland@bestweb.net) seems to say...
> #Help needed with following script, please!
> #Using MacPerl, Learn Perl in 21 days, Chapter 8, Slices
> #Why doesn't my slice subset include the keys 'red' and 'green'
> #with their corresponding values? All I get are their values.
> 
> %hash=('blue',10,'red',20,'green',5);
> %hashslice=@hash{'red','green'};

That '@' says you are getting an array, right?
$hash{red} = 20, right?
$hash{green} = 5, right?

@hash{'red','green'} is (20,5) right?

%hashslice = ( 20, 5 ) is a key of 20 and a value of 5.  Right?


> foreach $x (keys %hashslice) {
>       print "Key: $x,  Value: $hashslice{$x}\n"; } 
> 
> #Result: "Key: 20,  Value: 5"

Yep!



-- 
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.


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

Date: Sat, 13 Nov 1999 02:51:08 GMT
From: tony_123@my-deja.com
Subject: How can I vist a number of websites and email addys
Message-Id: <80ijmr$pem$1@nnrp1.deja.com>

Hi Folks

How can I write a script that given a web site address, will go to that
site and extract all email addresses from that page.  I want to know
what modules would help in doing this,  is there already a script out
there that does this, those sort of things.


Cheers

Tony


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 12 Nov 1999 20:31:29 -0800
From: Bill Moseley <moseley@best.com>
Subject: Re: How can I vist a number of websites and email addys
Message-Id: <MPG.1296897e960ce431989868@nntp1.ba.best.com>

tony_123@my-deja.com (tony_123@my-deja.com) seems to say...
> How can I write a script that given a web site address, will go to that
> site and extract all email addresses from that page.  I want to know
> what modules would help in doing this,  is there already a script out
> there that does this, those sort of things.

Ooooooh!  So THAT explains all that junk mail in my inbox.

Therefore, I can't make it too easy:

perldoc IO::Socket


-- 
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.


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

Date: Sat, 13 Nov 1999 05:56:46 GMT
From: tony_123@my-deja.com
Subject: Re: How can I vist a number of websites and email addys
Message-Id: <80iuit$c0$1@nnrp1.deja.com>

Hi Bill

Thanks for the reply.  You don't know anything which is at a higher
level than sockets for doing this that is already built?

Cheers

Tony

In article <MPG.1296897e960ce431989868@nntp1.ba.best.com>,
  Bill Moseley <moseley@best.com> wrote:
> tony_123@my-deja.com (tony_123@my-deja.com) seems to say...
> > How can I write a script that given a web site address, will go to
that
> > site and extract all email addresses from that page.  I want to know
> > what modules would help in doing this,  is there already a script
out
> > there that does this, those sort of things.
>
> Ooooooh!  So THAT explains all that junk mail in my inbox.
>
> Therefore, I can't make it too easy:
>
> perldoc IO::Socket
>
> --
> Bill Moseley mailto:moseley@best.com
> pls note the one line sig, not counting this one.
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sat, 13 Nov 1999 05:56:55 GMT
From: tony_123@my-deja.com
Subject: Re: How can I vist a number of websites and email addys
Message-Id: <80iuj6$c2$1@nnrp1.deja.com>

Hi Bill

Thanks for the reply.  You don't know anything which is at a higher
level than sockets for doing this that is already built?

Cheers

Tony

In article <MPG.1296897e960ce431989868@nntp1.ba.best.com>,
  Bill Moseley <moseley@best.com> wrote:
> tony_123@my-deja.com (tony_123@my-deja.com) seems to say...
> > How can I write a script that given a web site address, will go to
that
> > site and extract all email addresses from that page.  I want to know
> > what modules would help in doing this,  is there already a script
out
> > there that does this, those sort of things.
>
> Ooooooh!  So THAT explains all that junk mail in my inbox.
>
> Therefore, I can't make it too easy:
>
> perldoc IO::Socket
>
> --
> Bill Moseley mailto:moseley@best.com
> pls note the one line sig, not counting this one.
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sat, 13 Nov 1999 04:12:32 +0100
From: stoffer@netcetera.dk (Gustav Kristoffer Ek)
Subject: How to call a xs sub with a hash
Message-Id: <stoffer-1311990412320001@odin.netcetera.dk>

Hi group, I'm looking for an example of how to call an xs sub with a hash
as argument.

In my script using the module, I write something like:
%my_hash = (key => 'value');
foo(%my_hash)

then the xs sub c-code should alter 'value' to something else and return
the modified hash in the %my_hash variable.

I'm sorry to say, that I can't find any examples of that neither in
perlxstut or perlxs, could you please direct me to some information about
this :)

- gustav


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

Date: 12 Nov 1999 20:52:49 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: how to create a random id?
Message-Id: <slrn82pkql.lmh.abigail@alexandra.delanet.com>

Tom Briles (sariq@texas.net) wrote on MMCCLXIV September MCMXCIII in
<URL:news:382C2E1C.B84EDEA7@texas.net>:
[] Abigail wrote:
[] > 
[] >     $id = '=' x 17;
[] 
[] If there's one thing I've learned in the time I've been reading
[] Abigail's posts, it's that she's obsessed with the number 17.
[] 
[] Fess up, Abigail!  What's the significance?  IQ / 10?  The age at which
[] you first (fill in the blank)ed?


In this case, I simply counted the number of characters in the example
given. There were 17 characters, unless I miscounted.

However, for those who had math at university level, we all know that
there are only 2 candidates for "a random prime" and "a random odd
number". 17, and 23, with 17 by far the favourite.

If your math professor picks any other number, the number wasn't chosen
at random, but carefully picked to make the numbers come out nicely.



Abigail
-- 
package Z;use overload'""'=>sub{$b++?Hacker:Another};
sub TIESCALAR{bless\my$y=>Z}sub FETCH{$a++?Perl:Just}
$,=$";my$x=tie+my$y=>Z;print$y,$x,$y,$x,"\n";#Abigail


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: Thu, 11 Nov 1999 13:17:42 -0700
From: "bowman" <bowman@montana.com>
Subject: Re: How to retrieve substrings at fixed position in a string?
Message-Id: <RF3X3.305$KU2.1061@newsfeed.slurp.net>

Michael Yuan <juntao@pan.as.utexas.edu> wrote in message
news:Pine.GS4.4.10.9911121927360.12968-100000@pan.as.utexas.edu...
>
> serveal of them. So, my question is, if I read a line into perl, how can I
> get the columns, say 20-25, out as a substring? Thanks a lot.

It may be something you could do with the Perl function, substr






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

Date: 13 Nov 1999 02:13:30 GMT
From: mgjv@wobbie.heliotrope.home (Martien Verbruggen)
Subject: Re: How to retrieve substrings at fixed position in a string?
Message-Id: <slrn82pigk.eri.mgjv@wobbie.heliotrope.home>

On Fri, 12 Nov 1999 19:32:41 -0600,
	Michael Yuan <juntao@pan.as.utexas.edu> wrote:

>                  So, my question is, if I read a line into perl, how can I
> get the columns, say 20-25, out as a substring?

The easiest way is with substr. A slightly more complex way is with
unpack.

Something like:

$_ = 'column 1       column 2        column 3          column 4    ';

# Only want 1 2 and 4
my @c = (
    substr($_, 0, 15),
    substr($_, 15, 16),
    substr($_, 49, 12),
);

And if you want to get rid of the spaces, something like this could do
that:

@c = map { s/ +$//; $_ } @c;

A solution with unpack:

my @c = unpack "A15A16A18A12", $_;

and this automatically remove trailing spaces. To get only column 1 2
and 4:

my @c = unpack "A15A16x18A12", $_;

I happen to like the unpack method for this sort of thing a bit better,
(despite the fact that I have professed a general dislike for
pack/unpack before on this group, which, btw, is diminishing). substr is
easier for just one substring. If you're reading formatted output,
unpack is probably better, because you can document the format in the
pack string.

# perldoc -f substr
# perldoc -f unpack
# perldoc -f pack

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Never hire a poor lawyer. Never buy
Commercial Dynamics Pty. Ltd.   | from a rich salesperson.
NSW, Australia                  | 


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

Date: Fri, 12 Nov 1999 22:12:30 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: How to retrieve substrings at fixed position in a string?
Message-Id: <MPG.1296a1296c7f265d98a1ed@nntp.hpl.hp.com>

In article <slrn82pigk.eri.mgjv@wobbie.heliotrope.home> on 13 Nov 1999 
02:13:30 GMT, Martien Verbruggen <mgjv@wobbie.heliotrope.home> says...

 ...
 
> my @c = unpack "A15A16x18A12", $_;
> 
> I happen to like the unpack method for this sort of thing a bit better,
> (despite the fact that I have professed a general dislike for
> pack/unpack before on this group, which, btw, is diminishing). substr is
> easier for just one substring. If you're reading formatted output,
> unpack is probably better, because you can document the format in the
> pack string.

And you can even make it legible.

  my @c = unpack 'A15 A16 x18 A12', $_;

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


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

Date: 13 Nov 1999 04:13:48 GMT
From: bbirthisel@aol.com (Bbirthisel)
Subject: Re: IO-Tty binary package for W95?
Message-Id: <19991112231348.29863.00000553@ng-co1.aol.com>

Hi Neil:

>>If your stream is coming from a serial device, and you need
>>more than the current subset from Win32::SerialPort, let me
>>know.
>
>The stream is a socket, but thank you. I'll just have to write the
>program a bit differently. I've been spoiled by the Expect package
>under Linux. A few lines of code goes a long way (but then again that
>is what Perl is for :-).

You can probably lift the expect-subset code out of Win32::SerialPort
and adapt it to a socket input without much effort. It is already set up
to read all available bytes and then post-process them looking for
data patterns. At least you'd get a good list of essential variables.

-bill
Making computers work in Manufacturing for over 25 years (inquiries welcome)


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

Date: Sat, 13 Nov 1999 13:58:06 +0800
From: Daniel Barnett <vibrant@iinet.net.au>
Subject: looking for a developer . . . 
Message-Id: <382CFD9F.96B3FC1@iinet.net.au>

Hi,

We have a digital product that we need to sell online.  We are looking
for a programmer that can integrate our credit card providers API's with
somesort of shopping cart / download manager.

Please e-mail for full details.

Regards,

Daniel Barnett.



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

Date: Sat, 13 Nov 1999 05:23:56 GMT
From: Michael Fischer <votemand@earthlink.net>
Subject: Re: Need help understanding directory structure (NEWBIE)
Message-Id: <382CF623.574CE240@earthlink.net>



David Cassell wrote:

> >
> > When I try to do this with        --- open MYFILE,
> > "../files/myfile.data" I get an error.
> 
> A relative path.  Bad in web apps.
> 
> > When I do it with a direct path --- open MYFILE,
> > "c:/server/files/myfile.data"
> >  it works but I dont believe this is the correct way to do it....
> 
> An absolute path.  Good.
> 
> Why, you ask?  Because webservers can start your process in
> any place they want to, which is quite often in some place
> you never thought of.  So an absolute path gets you to your
> file, while the relative path may go nowhere fast [because
> you're not starting in the directory you supposed].

Ah ha!

That answers a bunch of peculiar thingies. Why didn't I 
see this caveat in an FAQ? Or was I just getting bleary?

Thanks.

-Michael


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

Date: 13 Nov 1999 07:01:30 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: Re: output a binary file to browser from perl script
Message-Id: <slrn82q36c.1q2.efflandt@efflandt.xnet.com>

On Fri, 12 Nov 1999 04:16:55 GMT, Kragen Sitaker <kragen@dnaco.net> wrote:
>In article <80fgeu$hjd$1@nnrp1.deja.com>,  <abnerstransky@my-deja.com> wrote:
>>I'm trying to write a script that will send a gzip'd file to the
>>browser via http only when the user has entered a password correctly. I
>>don't want a simple Location:http://etcetc tag, because I don't want
>>the URL to be accessible. So how do I output a 2meg gzip file - that
>>is, read it from the directory and spit it out to the browser?
>
>open() it, read() it in chunks, and print the results.
>-- 
><kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
>The Internet stock bubble didn't burst on 1999-11-08.  Hurrah!
><URL:http://www.pobox.com/~kragen/bubble.html>

Why in chunks?  I have never had any trouble sending image files in
continuous stream, so I don't see why it wouldn't work for any binaries:

if (open(FILE,"$file")) {
    binmode FILE;	# only needed for Win servers
    print <FILE>;	# prints complete file
    close FILE;
} else {
    # print error message including $! and exit
}

-- 
David Efflandt  efflandt@xnet.com  http://www.xnet.com/~efflandt/
http://www.de-srv.com/  http://cgi-help.virtualave.net/
http://thunder.prohosting.com/~cv-elgin/


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

Date: 13 Nov 1999 03:14:58 GMT
From: simon@brecon.co.uk (Simon Cozens)
Subject: Re: printing a number with 3 digits
Message-Id: <slrn82plti.1s1.simon@othersideofthe.earth.li>

Martien Verbruggen (comp.lang.perl.misc):
>> 2 days x 8 hours x US $200/hour / 1 LOC = US $3200/LOC [0]
>No one who has to ask this question will be able to make US $200/hour
>programming.

I regret to inform you that the world is as fair as you seem to think
it is.

-- 
panic: kernel segmentation violation. core dumped		(only kidding)


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

Date: Sat, 13 Nov 1999 15:15:27 +1030
From: spamfree@metropolis.net.au (Henry Penninkilampi)
Subject: Re: Serious memory leak in MacPERL?
Message-Id: <spamfree-1311991515360001@d5.metropolis.net.au>

In article <sheppard-1211991239380001@192.168.0.1>, sheppard@magma.ca (Tom
Sheppard) wrote:

> That all works well, but I need to handle a lot of data from many
> different files. I repeatedly call a function which may build a hash and
> then I explicitly free it before returning by doing an:
> 
>    undef %someHash;
> 
> This seems to help a little but not all the memory is recovered. If I
> repeatedly call the function I eventually run out of memory requiring me
> to quit MacPERL and relaunch it.
> 
> Sometimes I can manage to run one script through to completion, close it,
> and then I try to run another script. But the memory has not all been
> recovered, even though the first script has terminated and been closed,
> such that the next script runs out of memory even though it's not trying
> to do too much.
> 
> Since MacPERL hasn't been updated in a long time I guess I'm looking for a
> more elegant workaround to ensure all memory is properly freed. Is there a
> more memory efficient way to allocate and reliably free hashes?

Rather than deleting the hash in one chomp, you could try to nibble it:

foreach $key (keys %someHash) { push @tempArray, $key; }
while ($tempArray) { delete $someHash{pop @tempArray}; }
  
This is under the assumption that the memory leak comes from using undef,
and is not present in delete or pop.

I've never tested the above code, or used it in any way, so there might be
some flaws with it.  Consider it pseudo-code.  Tweak and repair as
required and see if it works.  Let me/us know if it helps - I'm personally
going to be developing a MacPerl application in the near future which is
likely to be subject to memory leaks, so I'm interested in the outcome.

Henry.


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

Date: Fri, 12 Nov 1999 22:09:53 -0500
From: planb@newsreaders.com (J. Moreno)
Subject: Re: Weekday in perl
Message-Id: <1e16fy5.1hdyayhe0zuhfN%planb@newsreaders.com>

Martien Verbruggen <mgjv@wobbie.heliotrope.home> wrote:

>       Larry Rosler <lr@hpl.hp.com> wrote:
> > GMT, Viscano <kc@disinfo.net> says...
> > + Probably a faster way to do it..but...
> 
> [snip code]
> 
> > + That will give you the current day of the week in three letter form,
> > + ie: Mon, Tue, Wed, etc....
> 
> > But in general, you have a problem with code bloat.  The last four lines
> > of code in your subroutine (from '$date =' on) do nothing more than
> > this:
> > 
> >             substr localtime $epoch_seconds, 0, 3
> 
> And the whole thing really doesn't do much more than
> 
> use POSIX;
> print strftime "%a", localtime;

Sure it does, specifically:

   $epoch_seconds = timelocal(0, 0, 0, $d, $m, $y);

can't be replaced with localtime, since it is supposed to be for a
particular date (possibly adjustable) and not today (at least according
to the original post).

-- 
John Moreno


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

Date: Sat, 13 Nov 1999 05:57:56 GMT
From: "Crawfishy" <cans1@hotmail.com>
Subject: Re: Writing data to file on another server.
Message-Id: <01bf2d94$31d33c00$c534d8c0@default>

OK, I just spent the last 3 hours researching this and I think I have a
handle on it.... But just so I don't beat my head against the wall for a
week, let me just be sure...
If I understand correctly, instead of using OPEN and PRINT to write data to
a file as I am doing now, Instead I would create a routine that utilized
the http::request using the PUT method. Correct?
If this is correct, then will I need to have anything special on the
receiving site to accept this PUT data. Bear in mind that the receiving
site is just going to be running a simple web server program over a static
IP on Win98 not something "web advanced" like Linux.
Thanx
George

> Crawfishy wrote:
> > 
> > OK, that's all fine and dandy but... I would consider myself a novice
perl
> > programmer...
> > I will research your suggestions but I do a lot better when I have
sample
> > code to examine and tear apart. Any suggestions???
> > George
> 
> Start with:
> 
> perldoc LWP
> perldoc lwpcook



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

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

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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.

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


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