[10340] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3933 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 9 00:07:59 1998

Date: Thu, 8 Oct 98 21:00:18 -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           Thu, 8 Oct 1998     Volume: 8 Number: 3933

Today's topics:
        "strict subs" choking on method perl file handles <alan@chelz.com>
    Re: *quick q:* how to escape a query string? <aas@sn.no>
    Re: Are there any "perl.newbie" group or forum? (Michael J Gebis)
        Can I FORMAT variables to be a specific length? <gdoucet@ait.acl.ca>
    Re: cgi-lib.pl vs CGI.pm? <ljz@asfast.com>
    Re: Difficulty with HTML & Perl & CGI <mp@mkt2mkt.com>
        Finding location of a match in an RE kenn@owl.co.uk
    Re: Finding location of a match in an RE (Ilya Zakharevich)
        importing a file <jlee@alexia.lis.uiuc.edu>
        list representation <jlee@alexia.lis.uiuc.edu>
        Newbie - using variable for search or substitute option asequeir@my-dejanews.com
    Re: Newbie - using variable for search or substitute op <rick.delaney@shaw.wave.ca>
    Re: Newbie - using variable for search or substitute op (Ronald J Kimball)
    Re: Newbie - using variable for search or substitute op (Ronald J Kimball)
    Re: Newbie - using variable for search or substitute op (Ilya Zakharevich)
    Re: Perl as a dumb terminal - rephrased <tpot@acsys.anu.edu.au>
        Perl Expect question (Username)
    Re: Perl Expect question (Matthew Bafford)
        Please Help - Searching for an NNTP News Script <amani@globaldialog.com>
        Please help with time... <bfb@att.net>
    Re: scope of my using () (R. Ransbottom)
    Re: scope of my using () (Ronald J Kimball)
        Searching for a news Script <amani@globaldialog.com>
    Re: When did you last use AWK (was Re: free book on sh/ <ljz@asfast.com>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Fri, 9 Oct 1998 11:36:39 +1000
From: "Alan Fahrner" <alan@chelz.com>
Subject: "strict subs" choking on method perl file handles
Message-Id: <6vjpdb$s63$1@reader1.reader.news.ozemail.net>

Hi all...

I've recently been creating perl extensions for all the data structures in
my company's records-based "database."

Common functions include read, write, fetch, and store.  As one of the
arguments, I pass the perl file handle to read or write to.  It works fine
until I "use strict."

For instance, in perl this is fine:

strict 'subs';
open(FILEHANDLE,$file);
read(FILEHANDLE,$buffer,$some_number);  # perl's standard read

But, if I:

strict 'subs';
open(FILEHANDLE,$file);
$myobj->read(FILEHANDLE);  # "read" method for $myobj's class

I get the standard bareword error.

I would rather not "no strict subs" or pass the file handle as a glob
reference...which works...

strict 'subs';
open(FILEHANDLE,$file);
$myobj->read(\*FILEHANDLE);

I have looked and looked, even trying to peer into the perl code, but I
can't see a way to declare or write my functions in the ".xs" or ".pm" file
that would cause it to be happy.

I appreciate any suggestions.

Thanks

Alan
alan@chelz.com




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

Date: 08 Oct 1998 23:29:50 +0200
From: Gisle Aas <aas@sn.no>
Subject: Re: *quick q:* how to escape a query string?
Message-Id: <m3emsig2sx.fsf@furu.g.aas.no>

mcafee@waits.facilities.med.umich.edu (Sean McAfee) writes:

> I downloaded RFC 1738 while composing my article (ironic that I should go
> to such trouble and then get the details wrong, eh?), and I could find no
> mention of '+' being an acceptable escape for ' '.  Where is this
> convention documented?

Encoding of ' ' as '+' is just a historical accident.  In the
beginning we had <ISINDEX> for HTML and the user was supposed to
provide some keywords to be searched for.  The individual keywords was
supposed to be separated by '+' when encoded in the query part of the
URL.  NCSA Mosaic let the user enter space separated words as keywords
in its <ISINDEX> text field.  From this some Mosaic developer(s)
concluded (wrongly) that '+' was really just an encoding of the space
character, and this misconception stuck when they moved to <FORM>s and
made <ISINDEX> just be a form <FORM> with a few predefined <INPUT>
elements.

The right way to encode ' ' is to use %20, but it is still a good idea
to allow '+' when decoding in order to cooperate with all those who
don't know better.

-- 
Gisle Aas


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

Date: 9 Oct 1998 00:36:16 GMT
From: gebis@fee.ecn.purdue.edu (Michael J Gebis)
Subject: Re: Are there any "perl.newbie" group or forum?
Message-Id: <6vjlq0$bag@mozo.cc.purdue.edu>

Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com> writes:

}madame philosophe wrote:
}> ...and what pray tell is a troll?

}A troll is someone whom we are not quite sure as to their authenticity
}and whom we suspect is deliberately stirring the group. I was laughing
}at one point. If you aren't a troll we'll make you an honorary one.
}madame 'h. clpm troll' philosophe. :)

Elaine, I checked, and it doesn't appear you have the authority to
bestow honorary troll status.  Would you mind checking your settings?
It looks like the server is ok.

-- 
Mike Gebis  gebis@ecn.purdue.edu  mgebis@eternal.net


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

Date: Fri, 09 Oct 1998 00:49:57 -0300
From: Guy Doucet <gdoucet@ait.acl.ca>
Subject: Can I FORMAT variables to be a specific length?
Message-Id: <361D87E4.74511C6E@ait.acl.ca>

I am receiving data from users. I need to format that data to a certain
length. Is there a quick function. The only thing I know is this:

do {$i=$i . " ";}until length($i) = max ;

Thanks,
Guy Doucet



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

Date: 08 Oct 1998 21:52:05 -400
From: Lloyd Zusman <ljz@asfast.com>
Subject: Re: cgi-lib.pl vs CGI.pm?
Message-Id: <lt67dufqnu.fsf@asfast.com>

fl_aggie@thepentagon.com (I R A Aggie) writes:

> In article <rmRS1.123$P12.538430@news.shore.net>, Scratchie
> <upsetter@ziplink.net> wrote:
> 
> + I'm in the minority around here, but I say if it works, don't "fix" it.
> [ ... ]
> 
> Its not like changing is particularly hard, or even dangerous. Change:
> 
> require "cgi-lib.pl";
> 
> to:
> 
> use CGI qw(:cgi-lib);
> 
> and you get all the functionality of CGI.pm's compatibility mode.

 ... with all the added overhead of the CGI.pm module loaded every time
someone invokes your cgi program, and with this overhead providing
absolutely *zip* in the way of functionality if you're only using the
cgi-lib compatibility mode.

CGI.pm is a very useful module, and I heartily recommend it for many
applications.  However, I see no reason why everyone should always
replace each and every use of cgi-lib.pl with CGI.pm.  There are many
cases where cgi-lib.pl works just fine.

I wholeheartedly agree with Scratchie <upsetter@ziplink.net>: if it
ain't broke, don't fix it.

-- 
 Lloyd Zusman   ljz@asfast.com
 perl -e '$n=170;for($d=2;($d*$d)<=$n;$d+=(1+($d%2))){for($t=0;($n%$d)==0;
 $t++){$n=int($n/$d);}while($t-->0){push(@r,$d);}}if($n>1){push(@r,$n);}
 $x=0;map{$x+=(($_>0)?(1<<log($_-0.5)/log(2.0)+1):1)}@r;print"$x\n"'


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

Date: Thu, 08 Oct 1998 20:56:09 -0800
From: madame philosophe <mp@mkt2mkt.com>
Subject: Re: Difficulty with HTML & Perl & CGI
Message-Id: <361D9730.1FB51D68@mkt2mkt.com>



Craig Berry wrote:

> madame philosophe (mp@mkt2mkt.com) wrote:
> : NOTE: I think if you are creating a new CGI object you want to write:
> :
> : use CGI;
> :
> : rather than
> :
> : use CGI qw( :standard);
>
> Hmm:   > perl -e 'use CGI qw(:standard); new CGI' ''
>        >
>
> Seems to work fine.  Isn't it better to try it rather than making
> inaccurate assertions?

Well I tried my own way: I made a specific trip the the CGI.pm book to look
and see if the new() method was a part of :cgi (which is a part of
:standard) and there was no new() listed.  Ditto for the other parts of
standard.

But after reading your mail I guess new(), being a constructor, may be above
all that.  Unless running from the command line is different with those
funny quotes at the end. :)

Heck.

>
>
> : also you can print out with commas after each html shortcut which means
> : this:
> [snip]
> :
> : print $query->header(), $query->start_html(-title=>'No Title',
> : -bgcolor=>'white'), $query->h4({-align=>'center'}, "Testing 4..."),
> : $query->end_html;
> :
> : is the same as the first entry.
>
> Though I might omit unneeded parens and improve formatting, just to make
> reading and maintaining the code a bit easier:
>
>   print $query->header,
>         $query->start_html(-title   => 'No Title',
>                            -bgcolor => 'white'),
>         $query->h4({-align => 'center'}, 'Testing 4...'),
>         $query->end_html;

I guess I didn't make myself clear.  The point I was making was that it was
one long print stream, rather than separate expressions that would end in a
semicolon.  Of course to be more readable it should be formatted the way I
had it, which you conveniently snipped out:

#!/usr/bin/perl

use CGI;
use CGI::Carp qw(fatalsToBrowser);
$query = new CGI;

print $query->header(),

    $query->start_html(-title=>'No Title', -bgcolor=>'white'),

    $query->h4({-align=>'center'}, "Testing 4..."),

    $query->end_html;

I like spacing my code out, personally.  And yeah sure the () after header
can go, since it defaults to the Content-type: text/html \n\n or some such
header info.

If you wanted to display an nph, or just a text file you would have to place
something in those ()

Something like:

#!/usr/bin/perl

use CGI qw(:standard);

$file = 'path/to/a/file.txt';

open(FILE, $file) || die "can't open $file: $!\n";

print header('text/plain');

while (<FILE>) {

    print;

}

close FILE;


Which leads me to a question actually:

if I were to use the above stub with a default header:

#!/usr/bin/perl

use CGI;

$file = 'path/to/a/file.html';

open(FILE, $file) || die "can't open $file: $!\n";

print header;

while (<FILE>) {

    print ###### See below######;

}

close FILE;

print end_html;

As long as the above isn't a form (in which I would need the start_form and
end_form shortcuts)

would it be possible to have an html file sans header and footer PLUS

have a unique text pattern that would function like commenting out and only
print what is between that unique pattern?  Something like comments in
reverse actually. (though perhaps a text file would be better for this use.

Let me explain:

let's say I have a text file that looks something like this:

-------snip--------

Here is the top of my text file.  This is the secret formula


This is page 1

#**##
The first part of the secret formula required newt eyes
##**#


This is a different page 1

#**##
The first part of the secret formula requires a vat of vegetarian chili.
##**#

This is page 2

#**##
The second part of the secret formula requires a tall Texan.
##**#

Here are additional comments about the secret formula.

-----end of text---------

Now if I were to place a conditional that said something like

If there is text delimited by tags #**## (to start) and ##**# (to end)
print that text.

(which implicitly means don't print the text appearing between ##**# and
#**##)

Any comments?

 madame P



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

Date: Fri, 09 Oct 1998 02:19:02 GMT
From: kenn@owl.co.uk
Subject: Finding location of a match in an RE
Message-Id: <6vjrqm$ldc$1@nnrp1.dejanews.com>

Maybe I'm trying to run before I can walk, but given the following lines of
code, where $thismsg is an email message complete with all new lines:

while ($thismsg =~ /=_NextPart_.*?Content\-Type: ([^\n]*?)\n/sg)
{  #what goes here? This is just to debug.
   print "$.: $1\n"
}

What I'd like to do would be to record the length of each MIME section I find.

I tried $., but that just gives me the position of the input pointer.

Is there a variable to query to find out where in an RE the match took place,
or is there a better way of doing this?

Please don't suggest I use a mail/MIME handling package, as I'm wanting to
learn about REs themselves, not packages.

Thanks!

Ken

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


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

Date: 9 Oct 1998 03:34:37 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Finding location of a match in an RE
Message-Id: <6vk08d$5ag$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to 
<kenn@owl.co.uk>],
who wrote in article <6vjrqm$ldc$1@nnrp1.dejanews.com>:
> Maybe I'm trying to run before I can walk, but given the following lines of
> code, where $thismsg is an email message complete with all new lines:
> 
> while ($thismsg =~ /=_NextPart_.*?Content\-Type: ([^\n]*?)\n/sg)
> {  #what goes here? This is just to debug.
>    print "$.: $1\n"
> }
> 
> What I'd like to do would be to record the length of each MIME section I find.
> 
> I tried $., but that just gives me the position of the input pointer.
> 
> Is there a variable to query to find out where in an RE the match took place,
> or is there a better way of doing this?
> 
> Please don't suggest I use a mail/MIME handling package, as I'm wanting to
> learn about REs themselves, not packages.

The bleeding edge Perl has @- and @+ with exactly the info you want
(in $-[1]).

With mass-production Perl you need extra pair of parens, and something
like
	length($`) + length($1)
(your $1 becomes $2).

With after-the-bleeding-edge Perl you would be able to do

  /=_NextPart_.*?Content\-Type: (?{ pos })([^\n]*?)\n/sg

and will get the info in $^R.  Or you will be able to assign it explicitly:

  /=_NextPart_.*?Content\-Type: (?{ $answer = pos })([^\n]*?)\n/sg

Ilya


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

Date: Thu, 8 Oct 1998 21:50:43 -0500
From: Jonghoon Lee <jlee@alexia.lis.uiuc.edu>
Subject: importing a file
Message-Id: <Pine.SGI.3.95.981008215005.26382B-100000@alexia.lis.uiuc.edu>


Is there any way to import another file in a Perl program,
so I can use functions in another file?

Or, should I just include everything in one file?
Thanks in advance.



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

Date: Thu, 8 Oct 1998 21:46:00 -0500
From: Jonghoon Lee <jlee@alexia.lis.uiuc.edu>
Subject: list representation
Message-Id: <Pine.SGI.3.95.981008214414.26382A-100000@alexia.lis.uiuc.edu>


I was just curious about the internal representation of lists.
I've learned that lists can hold various types of values.
But, then, how can they be retrieved although each element has a
different length?
In case of other language like C, because each element has the
same length, it will be very easy to be retrieved by the offset.
How about in Perl?
Do lists actually store the references of the elements, or
do Perl keep a kind of table to keep track of the length of each element?



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

Date: Fri, 09 Oct 1998 00:46:38 GMT
From: asequeir@my-dejanews.com
Subject: Newbie - using variable for search or substitute option
Message-Id: <6vjmde$eb8$1@nnrp1.dejanews.com>

Hi

I am trying to learn Perl and have run into a problem.

The problem is in using a variable for
specifying search or substitute options.
For example

s/$search/$replace/g

works, but

s/$search/$replace/$options

gives compile error.

Thanks in advance
-Antony

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Fri, 09 Oct 1998 02:33:57 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: Newbie - using variable for search or substitute option
Message-Id: <361D779D.21FB9B82@shaw.wave.ca>

[posted & mailed]

asequeir@my-dejanews.com wrote:
> 
> s/$search/$replace/g
> 
> works, but
> 
> s/$search/$replace/$options

perldoc perlre

In particular, look for (?imsx).  So things like

    s/search/replace/i;

are the same as

    s/(?i)search/replace/;

It's not going to work with /g though.

-- 
Rick Delaney
rick.delaney@shaw.wave.ca


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

Date: Thu, 8 Oct 1998 23:07:15 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Newbie - using variable for search or substitute option
Message-Id: <1dgloys.1tglu2z1oy96m8N@bos-ip-1-60.ziplink.net>

<asequeir@my-dejanews.com> wrote:

> The problem is in using a variable for
> specifying search or substitute options.
> For example
> 
> s/$search/$replace/g
> 
> works, but
> 
> s/$search/$replace/$options
> 
> gives compile error.

I'm afraid you can't use a variable to specify options at the end of
s///.  It would probably be a mess for the parser if you could.

There is another way to specify options, however:
s/(?i)Case/Insensitive/;

You can specify multiple options:
s/(?ig)Case Insensitive/Global Matching/;

And you can even use a variable:

$options = 'ig';
s/(?$options)Variable/Options/;


Ta da!

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Thu, 8 Oct 1998 23:33:43 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Newbie - using variable for search or substitute option
Message-Id: <1dglsoo.3gyefo1donqpyN@bos-ip-1-93.ziplink.net>

Rick Delaney <rick.delaney@shaw.wave.ca> wrote:

> In particular, look for (?imsx).  So things like
> 
>     s/search/replace/i;
> 
> are the same as
> 
>     s/(?i)search/replace/;
> 
> It's not going to work with /g though.

Really?  I must have gotten lucky, then.


$_ = 'abc def ghi jkl';

print "list context:\n";
@matches = /(?g)(\w+)/;
$" = "\n";
print "@matches\n\n";

print "scalar context:\n";
$i = 0;
while (/(?g)(\w+)/) {
  print "$1\n";
  ++$i;
}

__END__

list context:
abc
def
ghi
jkl

scalar context:
abc
def
ghi
jkl


Compare:


$_ = 'abc def ghi jkl';

print "list context:\n";
@matches = /(\w+)/;
$" = "\n";
print "@matches\n\n";

print "scalar context:\n";

$i = 0;
while (/(\w+)/) {
  print "$1\n";
  ++$i;
}

__END__

list context:
abc

scalar context:
abc
abc
abc
abc
abc
abc
abc
abc
 .
 .
 .


This is perl5.004.  Oddly, (?g) is not documented with (?ismx).

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: 9 Oct 1998 03:40:03 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Newbie - using variable for search or substitute option
Message-Id: <6vk0ij$5h4$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Ronald J Kimball
<rjk@coos.dartmouth.edu>],
who wrote in article <1dglsoo.3gyefo1donqpyN@bos-ip-1-93.ziplink.net>:
> > It's not going to work with /g though.
> 
> Really?  I must have gotten lucky, then.
> 
> 
> $_ = 'abc def ghi jkl';
> 
> print "list context:\n";
> @matches = /(?g)(\w+)/;
> $" = "\n";
> print "@matches\n\n";
> 
> print "scalar context:\n";
> $i = 0;
> while (/(?g)(\w+)/) {
>   print "$1\n";
>   ++$i;
> }
> 
> __END__

This is a bug indeed.  Thank you for pointing it out.

Do not know when/how it is going to be fixed, though.

Ilya


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

Date: 09 Oct 1998 12:58:21 +1000
From: Tim Potter <tpot@acsys.anu.edu.au>
Subject: Re: Perl as a dumb terminal - rephrased
Message-Id: <6yogrm30he.fsf@acronym.anu.edu.au>

Buxx <buxx@buxx.com> writes:

> > I'm needing to interface a pc thru a serial port to a Meridian phone
> > system to moniter and issue commands. All ascii text and emulating a
> > dumb terminal.
> > 
> > Anyone have any words of wisdom or done such a thing ??
> 
> I need to write a menuing program to replace the command line command
> using Perl using a serial port as STDIN/STDOUT. Perl makes a great text
> parser for this purpose, however I have no experience using the serial
> port as STDIN/STDOUT. The Meridan Phone sys is highly cryptic and
> requires a several volumes of docs to work with it.  Would like to
> simlipfy basic operations using a perl based menu program.

So you are writing a new front end to replace the crappy old front
end?  I've done something like that for a tape storage device we have
at work.  A really neat thing to do is to use the Term::ReadLine
module and install GNU readline.  This will give you command history
using the arrow keys and all the other bells and whistles that you can
do with bash.  With a bit of work you can get completions working
too.


Tim.


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

Date: 9 Oct 1998 00:40:15 GMT
From: username@qualcomm.com (Username)
Subject: Perl Expect question
Message-Id: <6vjm1f$37d$1@thefuture.qualcomm.com>

Hi,

I have read the FAQ and search CPAN web page and found 2 references on Expect 
which was not that helpful. So, here I am.

Has anybody used Expect? If yes, what is the syntax, is it similar to TCL 
expect?  Where can I find some example or more detail document on this.

Any helpful suggestion is greatly appreaciated.

TIA,

Bo.



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

Date: Thu, 8 Oct 1998 21:33:03 -0400
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: Perl Expect question
Message-Id: <MPG.108731d81fc53f119896cc@news.south-carolina.net>

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

In article <6vjm1f$37d$1@thefuture.qualcomm.com> on 9 Oct 1998 
00:40:15 GMT, Username (username@qualcomm.com) pounded in the 
following text:
=> Hi,
=> 
=> I have read the FAQ and search CPAN web page and found 2 references on Expect 
=> which was not that helpful. So, here I am.

Just wondering, did you download Expect?  I just did and found 
the following interesting items in the tar.gz:

Expect_intro.pod Expect.pm README Expect.pod tutorial FAQ

Seems to me that it's purty well documented. :)

=> Has anybody used Expect? If yes, what is the syntax, is it similar to TCL 
=> expect?  Where can I find some example or more detail document on this.

Always check the module files...  More often than not they will 
be filled with helpfull pod.

=> Any helpful suggestion is greatly appreaciated.
=> TIA,

Your Welcome.
HTH

=> 
=> Bo.

--Matthew


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

Date: Thu, 8 Oct 1998 20:15:16 -0700
From: "Amani International News" <amani@globaldialog.com>
Subject: Please Help - Searching for an NNTP News Script
Message-Id: <6vjp6f$lu4$1@news3.alpha.net>

Another newbie at perl.  High all, I'm looking for a script that will fetch
news and display the headline and a short summary of news on my web.  Has
anybody written such a script or know of the existence of one.  I want to be
able to provide free news on my web page.  I have searched on the net but
have not been able to find one.  I'd really appreciate your help.
Basically, what I want the script to do is fetch the news from an NNTP
server, grab the head line and a short summary, display that info. and if a
visitor to my web page click on the headline, the detailed news version is
displayed.

Thanks

Peter






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

Date: 9 Oct 1998 03:54:40 GMT
From: Bernie <bfb@att.net>
Subject: Please help with time...
Message-Id: <361D88B9.D0DD494B@att.net>

I have to add many time values together in
a format like 00:01:23

What's the easiest way to accomplish this?

Thanks
-Bernie



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

Date: 8 Oct 1998 14:12:20 -0400
From: rir@phavl.ultranet.com (R. Ransbottom)
Subject: Re: scope of my using ()
Message-Id: <6viva4$k7q$1@phavl.ethernet>

In article <361BB469.50840A12@email.sps.mot.com>,
Tk Soh  <r28629@email.sps.mot.com> wrote:
>Mark-Jason Dominus wrote:

>The Camel book (2nd Ed.) says 
>   ##
>     You may also check to see whether arrays, hashes or 
>     subroutines exist. Using 'defined' on the predefined
>     variables is not guaranteed to produce intuitive results.
>   ##
>
>But perldod (Perl5.005) says 
>  ## 
>    On the other hand, use  of C<defined()> upon aggregates 
>    (hashes and arrays) is not guaranteed to produce intuitive 
>    results, and should probably be avoided.
>  ##

>Hmm.. I am confused.

It appears to be about memory allocation:
Every print is called:

#!/usr/bin/perl

%hash;
defined %hash || print "undefined after declaration\n";
$hash{hi};
defined %hash || print "undefined after member sought\n";
$hash{hi} = undef;
defined %hash && print "defined after member loaded\n";
delete $hash{hi};
defined %hash && print "defined after members deleted\n";
undef %hash;
defined %hash || print "undefined after undef'd\n";
-- 

rob
rir@phavl.ultranet.com


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

Date: Thu, 8 Oct 1998 23:33:49 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: scope of my using ()
Message-Id: <1dgltbl.8b2hejmbkvraN@bos-ip-1-93.ziplink.net>

R. Ransbottom <rir@phavl.ultranet.com> wrote:

> > [discussion about defined on hashes and arrays]

> It appears to be about memory allocation:


That is as documented in perlfunc.


    Currently, using defined() on an entire array or hash reports
    whether memory for that aggregate has ever been allocated.  So an
    array you set to the empty list appears undefined initially, and one
    that once was full and that you then set to the empty list still
    appears defined. You should instead use a simple test for size:

        if (@an_array) { print "has array elements\n" }
        if (%a_hash)   { print "has hash members\n"   }

    Using undef() on these, however, does clear their memory and then
    report them as not defined anymore, but you shoudln't do that unless
    you don't plan to use them again, because it saves time when you
    load them up again to have memory already ready to be filled.

    This counterintuitive behaviour of defined() on aggregates may be
    changed, fixed, or broken in a future release of Perl.


-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Thu, 8 Oct 1998 20:12:06 -0700
From: "Amani International News" <amani@globaldialog.com>
Subject: Searching for a news Script
Message-Id: <6vjnhk$llj$1@news3.alpha.net>

Another newbie at perl.  High all, I'm looking for a script that will fetch
news and display the headline and a short summary of news on my web.  Has
anybody written such a script or know of the existence of one.  I want to be
able to provide free news on my web page.  I have searched on the net but
have not been able to find one.  I'd really appreciate your help.
Basically, what I want the script to do is fetch the news from an NNTP
server, grab the head line and a short summary, display that info. and if a
visitor to my web page click on the headline, the detailed news version is
displayed.

Thanks

Peter






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

Date: 08 Oct 1998 23:22:25 -400
From: Lloyd Zusman <ljz@asfast.com>
Subject: Re: When did you last use AWK (was Re: free book on sh/sed/awk)
Message-Id: <ltu31ewham.fsf@asfast.com>

jari.aalto@poboxes.com (Jari Aalto+mail.perl) writes:

> mjd@plover.com (Mark-Jason Dominus) writes:
> 
> > 
> > In article <6umbv5$cio$1@gellyfish.btinternet.com>,
> > Jonathan Stowe  <gellyfish@btinternet.com> wrote:
> > >But apart from that I cant think of a possible situation where I might use
> > >AWK nowadays.  But of course others may differ in their opinion.

I use Perl most of the time.  However, there are occasions where I
need a script on a machine where Perl is not installed, and which is
being managed by someone other than me.  In these rare cases, I will
use AWK or some other tool.

A recent example is a text reformatting script that I needed on a
system for which I don't have root access, and which had a limited
amount of disk space.  Rather than spend the days necessary to haggle
with the sysadmins about installing Perl, giving me root access,
adding disk space, etc., I just cranked out an AWK script in an hour
or so and was done with the whole mess.

Another rare occasion where I will use AWK instead of Perl is at sites
where there is no one employed who is familiar with Perl, and where I
need to write scripts which need to be maintained by others.
Sometimes there are AWK users at these sites, in which case that will
be the language the scripts get written in.  Most of my clients do not
pay me to force their programmers to learn a new language just to be
able to maintain my code.

However, in cases where both AWK and Perl are available to me, I will
almost always make use of Perl.

-- 
 Lloyd Zusman   ljz@asfast.com
 perl -e '$n=170;for($d=2;($d*$d)<=$n;$d+=(1+($d%2))){for($t=0;($n%$d)==0;
 $t++){$n=int($n/$d);}while($t-->0){push(@r,$d);}}if($n>1){push(@r,$n);}
 $x=0;map{$x+=(($_>0)?(1<<log($_-0.5)/log(2.0)+1):1)}@r;print"$x\n"'


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

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


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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

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