[12087] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5687 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun May 16 14:07:23 1999

Date: Sun, 16 May 99 11: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           Sun, 16 May 1999     Volume: 8 Number: 5687

Today's topics:
        Baffled... uninitialized value at (eval 2) line 1. (Charles R. Thompson)
        Can someone tell me why this 'require' wont work <mike-carter@email.msn.com>
    Re: Count number of html files and print it a html file <juex@my-dejanews.com>
    Re: counting lines in another file <juex@my-dejanews.com>
    Re: counting lines in another file (Tad McClellan)
    Re: counting lines in another file (Larry Rosler)
    Re: email attachment <joe@laffeycomputer.com>
    Re: Hash arrays (Tad McClellan)
    Re: Help with tie hash to file <joe@laffeycomputer.com>
    Re: man pages and FAQs: why posted? (Larry Rosler)
    Re: man pages and FAQs: why posted? <rick.delaney@home.com>
    Re: need elegant way to deal hand of cards in Perl <gt7202e@prism.gatech.edu>
    Re: open, read,then print a file armchair@my-dejanews.com
    Re: open, read,then print a file <swarren@www.wwwdotorg.org>
    Re: Perl "constructors" (Larry Rosler)
    Re: Perl "constructors" (Randal L. Schwartz)
    Re: Perl "constructors" (Randal L. Schwartz)
    Re: Perl "constructors" (Larry Rosler)
    Re: Perl "constructors" armchair@my-dejanews.com
        perl 2 c/c++ compiler <finkelg@cpm.elex.co.il>
    Re: perltootc - OO Tutorial for Class Data in Perl <swarren@www.wwwdotorg.org>
        Please help! <h0p2468@acs.tamu.edu>
    Re: problem w/perl cgi script & background image <webmaster@ihatewindows98.com>
    Re: TROLL ALERT (Re: Perl "constructors") (Arved Sandstrom)
        Where can i download a complete perl reference? <mike-carter@email.msn.com>
    Re: writing binary data to a file armchair@my-dejanews.com
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Sun, 16 May 1999 17:58:07 GMT
From: design@raincloud-studios.com (Charles R. Thompson)
Subject: Baffled... uninitialized value at (eval 2) line 1.
Message-Id: <MPG.11a8d2947e3b1c4b9896cc@news>

I've never encountered this error before and it's confusing me because it 
doesn't seem to point me to anything helpful... I'm using -w and strict, 
the first line in my script is the path to perl. I've gone through my 
script over and over.. I cannot find a variable that I haven't declared 
with or initialized without a 0 or ''. This is the *only* error generated 
in my script.

What exactly does this error mean, and where should I begin looking to 
understand what is generating it?

Use of uninitialized value at (eval 2) line 1.

-- 
CT


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

Date: Sun, 16 May 1999 13:29:40 -0400
From: "Mike" <mike-carter@email.msn.com>
Subject: Can someone tell me why this 'require' wont work
Message-Id: <e61wgH8n#GA.52@cpmsnbbsa05>


New code that does not work

$url_path = $ENV{SERVER_NAME};   #get the url
$url_path =~ s/ //;   #remove any spaces, probably not necessary
$url_path = "'/disk02/$url_path/htdocs/cgi-bin/shop.cfg'";  #create the
require string
require $url_path;


old code that did work

require '/disk02/zenmuzik.com/htdocs/cgi-bin/shop.cfg';

I am tryng to eliminate the need to type the url in each instance of this
script on different domains.

Thanks




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

Date: Sun, 16 May 1999 09:25:25 -0700
From: "J|rgen Exner" <juex@my-dejanews.com>
Subject: Re: Count number of html files and print it a html file ?
Message-Id: <7hmrdh$r5i@news.dns.microsoft.com>

Yeong Mo/Director Hana co. <factory@factory.co.kr> wrote in message
news:7hkdtk$fvj$1@news2.kornet.net...
> [Q] Count number of html files and print it a html file ?
>
> I have many html files under several directories.
>
> Is it possible to check the number of html files,
> and print the numbers at a html file ?
>
> Example;
> ================================
> Directory name  || Number of files
> ================================
> dir-1                      82 html files
> dir-2                      50 html files
> dir-3                      76 html files
> .
> .
> .
> dir-25                    63 html files

    find . -type dir -print -exec ls \{}/*.html | wc -l \;

(you may have to tweak the syntax a bit) will give you a list with all
directories and the number of files ending with .html in each of them.
Add a bit of formatting sugar and you are done.

jue
--
J|rgen Exner





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

Date: Sun, 16 May 1999 09:20:24 -0700
From: "J|rgen Exner" <juex@my-dejanews.com>
Subject: Re: counting lines in another file
Message-Id: <7hmr44$o3r@news.dns.microsoft.com>

Bjorn De Waele <bjorn.de.waele@skynet.be> wrote in message
news:7hmea0$jab$1@news1.skynet.be...
> I've got a textfile called address.txt which contains very much lines with
> e-mailaddresses in.  I need to now automatically how much lines there are
in
> that text-file.  How do I need to do this ?

No need to launch Perl for this rather trivial task, just use wc (word
count):
    wc -l address.txt

jue
--
J|rgen Exner





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

Date: Sun, 16 May 1999 05:36:02 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: counting lines in another file
Message-Id: <2i3mh7.b26.ln@magna.metronet.com>

Bjorn De Waele (bjorn.de.waele@skynet.be) wrote:

: I've got a textfile called address.txt which contains very much lines with
: e-mailaddresses in.  I need to now automatically how much lines there are in
: that text-file.  How do I need to do this ?


   You need to read and count all of the lines in the file.


      while (<>) {}
      print "there are $. lines in the file\n";


   The $. special variable is documented in the perlvar.pod man page.


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


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

Date: Sun, 16 May 1999 10:22:47 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: counting lines in another file
Message-Id: <MPG.11a89ebb5a4a4d4989a79@nntp.hpl.hp.com>

[Posted and a courtesy copy sent.]

In article <7hmea0$jab$1@news1.skynet.be> on Sun, 16 May 1999 14:38:18 
+0200, Bjorn De Waele <bjorn.de.waele@skynet.be> says...
 ...
> I've got a textfile called address.txt which contains very much lines with
> e-mailaddresses in.  I need to now automatically how much lines there are in
> that text-file.  How do I need to do this ?
> 
> I hope someone can help me out.

The FAQ can help you out.

perlfaq5:  "How do I count the number of lines in a file?"

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


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

Date: Sun, 16 May 1999 12:17:44 -0500
From: Joe Laffey <joe@laffeycomputer.com>
Subject: Re: email attachment
Message-Id: <Pine.LNX.4.10.9905161217090.12582-100000@tripe.laffeycomputer.com>

On Mon, 10 May 1999, David Craig wrote:

> Does anyone know how to attach a file to an email from a perl script?

Try the CPAM module MIME::Lite

Joe Laffey
LAFFEY Computer Imaging
St. Louis, MO
http://www.laffeycomputer.com/
 ------------------------------



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

Date: Sun, 16 May 1999 05:50:10 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Hash arrays
Message-Id: <ic4mh7.b26.ln@magna.metronet.com>

armchair@my-dejanews.com wrote:
: In article <slrn7jshro.49a.sholden@pgrad.cs.usyd.edu.au>,
:   sholden@cs.usyd.edu.au wrote:
: > armchair@my-dejanews.com wrote:
: > >
: > >As long as $num_elements = keys(%hash) doesn't create a temporary
: > >intermediate array, I guess I am happy, as that syntax is no more
: > >confusing than $num_elements = @array;
: >
: > So do some research and find out what it does. Or do you need to be
: > spoon fed everything...

: Are you truly contending that every Perl programmer should examine the
: source code of Perl to find out how $scalar = keys %hash; is
: implemented? Then what would you fellows hector people about?


   "research" does not mean "examine the  source code of Perl".

   That is merely one form of research.

   Another form would be to try it out on a small vs. large hash
   and see if it takes longer for the large hash.

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

my %hash;

@hash{0 .. 100} = (1) x 100;
timethese 2_000_000, { 100 => q{$num_elements = keys(%hash)}, };

@hash{0 .. 100000} = (1) x 100000;
timethese 2_000_000, { 100000 => q{$num_elements = keys(%hash)}, };
---------------------

output:

Benchmark: timing 2000000 iterations of 100...
       100:  2 wallclock secs ( 1.77 usr +  0.00 sys =  1.77 CPU)
Benchmark: timing 2000000 iterations of 100000...
    100000:  2 wallclock secs ( 1.76 usr +  0.00 sys =  1.76 CPU)


   Ten minutes of coding, and it is readily apparent that it
   does not create an intermediate array. No source code reading
   needed.


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


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

Date: Sun, 16 May 1999 12:07:28 -0500
From: Joe Laffey <joe@laffeycomputer.com>
Subject: Re: Help with tie hash to file
Message-Id: <Pine.LNX.4.10.9905161206520.12582-100000@tripe.laffeycomputer.com>

On Fri, 7 May 1999, Jason Vardzel wrote:

> I am trying to write a simple cgi that uses the tie() method.  I am also
> very new to perl.  I know that I need a class to tie the hash to, but I
> cannot find a simple class to use.  I looked at DB_File but that seemed a
> bit too much.  If anyone has worked with this and can point me to a simple
> module for use with tie() I would be grateful.

Pick up the Perl Cookbook (O'Riley) and look up using MLDBM, a CPASN
module which is fantastic for dbm files.

Joe Laffey
LAFFEY Computer Imaging
St. Louis, MO
http://www.laffeycomputer.com/
 ------------------------------



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

Date: Sun, 16 May 1999 08:27:57 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: man pages and FAQs: why posted?
Message-Id: <MPG.11a883d93c29d397989a78@nntp.hpl.hp.com>

[Posted and a courtesy copy sent.]

In article <373ed4e2@cs.colorado.edu> on 16 May 1999 08:23:30 -0700, Tom 
Christiansen <tchrist@mox.perl.com> says...
> In comp.lang.perl.misc, lr@hpl.hp.com (Larry Rosler) writes:
> :My main complaint is that they are not being edited on a cycle-to-cycle 
> :basis in response to feedback from the newsgroup. 
> 
> I am trying, you know.

We all know that, and we (most of us :-) appreciate the effort.

But you have seen people recycling comments that first appeared a few 
weeks ago.  That is frustrating to everyone.

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


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

Date: Sun, 16 May 1999 15:59:46 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: man pages and FAQs: why posted?
Message-Id: <373EEB15.ABC3D1B6@home.com>

[posted & mailed]

Tom Christiansen wrote:
> 
>  [courtesy cc of this posting sent to cited author via email]
> 
> In comp.lang.perl.misc, lr@hpl.hp.com (Larry Rosler) writes:
> :My main complaint is that they are not being edited on a 
> :cycle-to-cycle basis in response to feedback from the newsgroup.
> 
> I am trying, you know.

As Larry said, it is appreciated.  Is there something we (the clpm
community) can do to help you out?  

It's very easy for us to post typo corrections and the occasional
content addition but it's still extra work for you (and probably not
your favourite).

Would you like to see pod patches in a certain format like diff or
whatever?  Is there something else we can do?  

Maybe you could create a document on "How to Submit Pod Patches" or
something.  Sure, that's still more work for you, but you might get it
back in maintenance time.  Maybe such a document already exists that I'm
not aware of.

I'd like to thank you for your tireless efforts but I'm sure there are
things we can do to make your life easier, however small.  Please let us
know.

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Sun, 16 May 1999 11:04:21 -0400
From: "andy barfoot" <gt7202e@prism.gatech.edu>
Subject: Re: need elegant way to deal hand of cards in Perl
Message-Id: <7hmmrm$65d$1@news-int.gatech.edu>


Bob Berman wrote in message <373DCB34.E6C27B24@icehouse.com>...
>I'm trying to come up with a Perl routine to distribute data round robin
into an
>arbitrary number of "buckets". Like dealing a hand of cards when people are
>coming and going from the table. I currently create an array of "n" empty
array
>refs and then iterate over that in a while loop and insert into each anon.
array
>in turn. It just seems kind of "brute" force to me. Does any one know of
any
>more Perlish type of way I could do this? This is purely for my own
interest.
>Thanks.


This routine is useful for making tables too.  Sometimes i have a sorted
list that i want to display in multiple columns.. naturally its easier to
read down a column than across!  In this case each row would be one of your
"buckets".  (Isn't it annoying that "dir /w/on" doesn't do this?)

I can't think of a simpler algorithm than the loop with a push.  Can someone
think of a nice _name_ for this sub?


Andy





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

Date: Sun, 16 May 1999 16:15:45 GMT
From: armchair@my-dejanews.com
Subject: Re: open, read,then print a file
Message-Id: <7hmqvg$st5$1@nnrp1.deja.com>

In article <slrn7jtm4f.7jo.sholden@pgrad.cs.usyd.edu.au>,
  sholden@cs.usyd.edu.au wrote:
> On Sun, 16 May 1999 13:12:12 GMT, armchair@my-dejanews.com wrote:
> >In article <7hj78o$atj$2@justice.csc.cuhk.edu.hk>,
> >  austin95002887@yahoo.com (Austin Ming) wrote:
> >>
> >> How to open, read,then print a text.txt file to the browser in
current
> >> dierectory ?
> >>
> >>
> >Have added Larry Rosler's suggestions and corrections:
> >*******************************************************************
> >#!/usr/local/bin/perl -w
> >use strict;
> >
> >print "Content-Type: text/plain\n\n";
> >
> >my $input_file = "test.txt";
> >my $scalar = open(INPUT_FILE,"<$input_file");
> >
> >if ( $scalar )
>
> Why not use :
>
> if (open(INPUT_FILE, "<$input_file")
>
> Even if you don't you could use a better name than $scalar. Of course
> it's probably sample code so it doesn't really matter...
>
> >{
> >  my $file_line = "";
>
> Just my $file_line would do, since you don't use it before setting it.

I could swear I have gotten warnings before for not initializing
variables on the same line I declare them. But I took it out and no
warning. But that was on Perl 5.003 and I just tested on Perl 5.005???


>
> >  while ( $file_line = <INPUT_FILE> )
> >  {
> >     print "--> $file_line";
> >  }
> >  close (INPUT_FILE);
> >}
> >else
> >{
> >  print STDOUT "CGI SCRIPT ERROR:Unable to open file $input_file
!!!\n";
>
> Why STDOUT here, but not in the other two prints?
>
Uh, yeah, it is the default isn't it.
*****************************************************
#!/usr/local/bin/perl -w
use strict;

print "Content-Type: text/plain\n\n";

my $input_file = "test.txt";
if ( open(INPUT_FILE,"<$input_file") )
{
  my $file_line;
  while ( $file_line = <INPUT_FILE> )
  {
     print "--> $file_line";
  }
  close (INPUT_FILE);
}
else
{
  print "CGI SCRIPT ERROR:Unable to open $input_file!!!\n";
}


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


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

Date: Sun, 16 May 1999 17:04:49 GMT
From: "Stephen Warren" <swarren@www.wwwdotorg.org>
Subject: Re: open, read,then print a file
Message-Id: <RUC%2.652$fx5.414@news.rdc1.sfba.home.com>

<armchair@my-dejanews.com> wrote in message
news:7hmqvg$st5$1@nnrp1.deja.com...
> In article <slrn7jtm4f.7jo.sholden@pgrad.cs.usyd.edu.au>,
>   sholden@cs.usyd.edu.au wrote:
> > On Sun, 16 May 1999 13:12:12 GMT, armchair@my-dejanews.com wrote:
> > >In article <7hj78o$atj$2@justice.csc.cuhk.edu.hk>,
> > >  austin95002887@yahoo.com (Austin Ming) wrote:
> > >
> > >> How to open, read,then print a text.txt file to the browser in
> > >> current dierectory ?
> > >
> > >  while ( $file_line = <INPUT_FILE> )
> > >  {
> > >     print "--> $file_line";
> > >  }
> > >  close (INPUT_FILE);
> > >}
> > >else
> > >{
> > >  print STDOUT "CGI SCRIPT ERROR:Unable to open file".
> > >  "$input_file !!!\n";
> >
> > Why STDOUT here, but not in the other two prints?
> >
> Uh, yeah, it is the default isn't it.

Assuming it's the select()ed file-handle!

> *****************************************************
> #!/usr/local/bin/perl -w
> use strict;
>
> print "Content-Type: text/plain\n\n";
>
> my $input_file = "test.txt";
> if ( open(INPUT_FILE,"<$input_file") )
> {
>   <snip>
> }
> else
> {
>   print "CGI SCRIPT ERROR:Unable to open $input_file!!!\n";
> }

One would do well to include the error message in your can't-open-file
error print:

>   print "CGI SCRIPT ERROR:Unable to open $input_file: $1\n";

One might also find the following more clear:

    open( INPUT_FILE, "<$input_file" ) ||
       die "Can't open $input_file for reading: $!" ;

which is more idiomatic and prevents the need to wrap the rest of the
script (which in general can be quite large) in an if. Of course, you'll
need to:

    use cgi qw(fatalsToBrowser) ;

Or, if you're security minded and don't want to give out undue
information, or want to use print directly for some reason, you could
always negate the truth value wrap the if around the open:

    if ( ! open( FH, "<$input_file" ) )
    {
       print "Can't open $input_file for read: $!\n" ;
       exit 0 ;
    }

--
Stephen Warren, Snr Systems Engineer, Technology House, San Francisco
mailto:swarren@techhouse.com                http://www.techhouse.com/
mailto:swarren@wwwdotorg.org                http://www.wwwdotorg.org/
              MIME, S/MIME and HTML mail are acceptable





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

Date: Sun, 16 May 1999 07:53:53 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Perl "constructors"
Message-Id: <MPG.11a87bd9c80c8739989a76@nntp.hpl.hp.com>

In article <7hlu8v$bl9$1@nnrp1.deja.com> on Sun, 16 May 1999 08:05:52 
GMT, armchair@my-dejanews.com <armchair@my-dejanews.com> says...
> In article <926819373.57195@thrush.omix.com>,
>   zenin@bawdycaste.org wrote:
> > armchair@my-dejanews.com wrote:
 ....
> > : Well, hashes are variable in size and you appear to feel they
> involve no
> > : meaningful performance degradation (but you also appear to hold
> bias) but
> > : one does need to depend on the fact that variables have been added,
> or use
> > : exists() which is not necessary with structs.
> >
> > 	It's not necessary in Perl either.
> 
> That statement is meaningless without a code example of a subroutine tha
> t receives a hash and expects a certain key, which isn't present, and
> handles it without exists().

sub foo {
    my %hash = shift;
    my $need_existence  = exists  $hash{bar} ? $hash{bar} : 'default';
    my $need_definition = defined $hash{bar} ? $hash{bar} : 'default';
    my $need_truth      = $hash{bar} || 'default';
 ...

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


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

Date: 16 May 1999 08:04:49 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Perl "constructors"
Message-Id: <m1u2tdukby.fsf@halfdome.holdit.com>

>>>>> "armchair" == armchair  <armchair@my-dejanews.com> writes:

armchair> Again, I was responding to an incredulous query of how I
armchair> could not see that keys() returns a scalar in "scalar context".

You could not see it because your book didn't tell you.

Many perl actions cannot be derived from philosophizing about Perl.
You simply have to read the docs. :) The actions were chosen to make
sense in the mind of one Larry Wall.  Some of us don't think like
Larry, but it's arrogant of us to presume that because a feature
doesn't work like *we* would want it (or guess that it should), it
doesn't work for *anyone* to have it that way.  It works for Larry.

If you can't get into Larry-think, please don't use Perl. :)

If you want a language where chars and ints and doubles and floats and
arrays of chars and pointers all take their own variables, you know
where to find it. :)

Just another guy who thinks a lot like Larry, and does fine with Perl,

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: 16 May 1999 08:07:00 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Perl "constructors"
Message-Id: <m1pv41uk8b.fsf@halfdome.holdit.com>

>>>>> "armchair" == armchair  <armchair@my-dejanews.com> writes:

armchair> And just what is happneing in your "constructor". If we to
armchair> look at the last few lines, what, other than "bless $rSelf,
armchair> $sClass;" would we see?  Again, I will repeat myself - if
armchair> you look at Perl discussions of objects they say a
armchair> "constructor" returns a reference to the object. Are you
armchair> know suggesting that constructors should also return scalar
armchair> number and/or strings in the case of errors?

In Perl, it's traditional for a so-called "constructor" to return a
blessed reference, or undef in the case of failure.  And it's up to
the invoker to verify that, usually aborting if undef is returned.

What's so freaking hard to get about THAT?  <sigh>

If you don't get that, just wait until you get to autovivification. :)

print "Just another Perl hacker,"

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: Sun, 16 May 1999 08:22:42 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Perl "constructors"
Message-Id: <MPG.11a882953134d43c989a77@nntp.hpl.hp.com>

In article <7hm8sm$hre$1@nnrp1.deja.com> on Sun, 16 May 1999 11:07:02 
GMT, armchair@my-dejanews.com <armchair@my-dejanews.com> says...
> In article <yllnep1kdh.fsf@windlord.stanford.edu>,
>   Russ Allbery <rra@stanford.edu> wrote:
 ...
> You didn't follow my spec, which had a specific purpose, which was not:
> "how should I solve this particular problem?", but how would you check
> for a missing hash key without using exists(). The filename is inside of
> a hash that I am passing down as a reference (the hash reference is the
> first parameter passed down.) And I want to know from the return code
> exactly what failed - bad value of a parameter, missing parameter, file
> not readable, file not found. You are only telling me something went
> wrong. And the second parameter passed is a reference to an array where
> I want the first line placed, not returned via return().
> 
> > That will return the first line of the given file, undef on failure to
> > open the file, and the empty string if the file is empty.  You'll find
> > that all of the possible cases are well-defined.  If you want to know
> > why the file couldn't be opened, the reason will be in $!.
> 
> I don't want to grep any reason in $!, because the wording may change or
> be system dependent, or , if you don't like that, because I want it done
> via a return code.

Perl has anticipated your needs, yet again.  Did you look at the 
documentation for $! in perlvar?

$OS_ERROR 
$ERRNO 
$! 
If used in a numeric context, yields the current value of errno, with 
all the usual caveats. (This means that you shouldn't depend on the 
value of $! to be anything in particular unless you've gotten a specific 
error return indicating a system error.) If used in a string context, 
yields the corresponding system error string. You can assign to $! to 
set errno if, for instance, you want "$!" to return the string for error 
n, or you want to set the exit value for the die() operator. (Mnemonic: 
What just went bang?) 

Also see Error Indicators. 

>                       Let me change the spec to say that I want an error
> returned if stat() reveals that the file is less than 800 bytes. And, as
> we have standardized here at our hypothetical programming shop that all
> functions which do not receive parameters that are expected, must return
> the value 10.

  sub first_line {
      my ($hash_ref, $array_ref) = @_;
      my $filename = $hash_ref->{filename} or return 10; # FALSE param
      open FILE, $filename or return -$!;                # -errno
      -s FILE < 800 and return 42;                    # What you will.
      $array_ref->[0] = <FILE>;
      return 0;                                          # Success!!!
   }
   print $array[0] unless first_line('filename') != 0;

 ...

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


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

Date: Sun, 16 May 1999 16:00:51 GMT
From: armchair@my-dejanews.com
Subject: Re: Perl "constructors"
Message-Id: <7hmq3j$s68$1@nnrp1.deja.com>

In article <slrn7jtmtp.7jo.sholden@pgrad.cs.usyd.edu.au>,
  sholden@cs.usyd.edu.au wrote:
> On Sun, 16 May 1999 14:07:10 GMT, armchair@my-dejanews.com wrote:

> Well I'm sick of having you put down my entire country and falsely
quote
> me in a public forum. Have fun with perl.

I certainly have been raking Australia over the coals, haven't I. But
the second part should read "and falsely quoting Elle MacPherson and
Crocodile Dundee in a public forum". Your umbrage seems quite misplaced,
particularly from someone who quite freely uses phrase like "you idiot".

>
> --
> Sam
>
> We prefer English to remain a rich language, quirky, sloppy, and full
> of redundancy. Same for Perl.
> 	--Larry Wall
>


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


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

Date: Sun, 16 May 1999 07:18:01 GMT
From: Gilad Finkelstein <finkelg@cpm.elex.co.il>
Subject: perl 2 c/c++ compiler
Message-Id: <Pine.HPP.3.96.990516101519.3540B-100000@tlprh22>

Is there a compiler that can compile a perl code into a faster c code.
If not is there a way to make perl work  [nearly as] fast as c/c++ code ?

Thanks.
Gilad Finkelstein
		Email: <finkelg@cpm.elex.co.il>



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

Date: Sun, 16 May 1999 16:55:34 GMT
From: "Stephen Warren" <swarren@www.wwwdotorg.org>
Subject: Re: perltootc - OO Tutorial for Class Data in Perl
Message-Id: <aMC%2.632$fx5.576@news.rdc1.sfba.home.com>

Tom Christiansen <tchrist@mox.perl.com> wrote in message
news:373ec2a9@cs.colorado.edu...
> Cursed by Microsoft Outlook Express 5.00.2014.211, "Stephen Warren"
> <swarren@www.wwwdotorg.org> wrote on Sun, 16 May 1999 06:45:44 GMT in
> comp.lang.perl.misc:
>
> >Some comments in the form of a unified diff. I hope people can grok
this,
> >but I figured it would be the most convenient way to merge them into
the
> >original .pod file...
>
> I'm afraid that what you sent wasn't a valid diff: you got
screw-wrapped.
> You are being tortured by the Horror Out of Redmouth.  May the Lord Bill
> have mercy on your pocket book, for it is clear that he has had none
> on anything else in your life.

Ick. Forgot about the automatic wrapping... I guess I really should take
people's advice and change newsreader. Looks like you've worked it out, so
I won't bother re-posting without wrapping, or *horror* as an
attachment:-)

One last change:

> >+XX Stephen Warren comment
> >+XX Depends on implementation... Since this is before the code, it
might
> >+XX help to note that we are using defined() rather than exists() for
the
> >+XX determination of translucency below. Otherwise, one's first though
on
> >+XX reading the above might be that it doesn't work. Of course, on
reading
> >+XX the code, it all became clear.
>
> Here's some added clarification at that point:
>
>     If you have an object with a discrete (read: not translucent)
>     attribute value, but you want to make that object's attribute value
>     translucent again later, what do you do?  Let's design the class so
>     that when invoke an accessor method with C<undef> as its argument,
it
               ^^ we
>     returns to its translucent nature and allows the class meta-object's
>     current value for that attribute to shine through again.

That's it. Clarifications make it much better!

One other thought I had was about using this scheme (the naming scheme for
the eponymous meta-object) for classes in 'nested' packages e.g. A::B,
where you'd get A::B::A::B as the meta-object name. Wouldn't this be a
hash %B in package A::B::A? This might amount to polution of "someone
else's" namespace. To fix this, we could have some re stuff like along the
lines of the following: __PACKAGE__ . ( __PACKAGE =~ s/^.*::// ) ;
Although the side-effects make this particular syntax invalid, you get the
idea. Of course, this all depends on what our() does exactly, but I highly
doubt that:

package A::B ;
our %A::B ;

would make %A::B a symbol inside package A::B?

--
Stephen Warren, Snr Systems Engineer, Technology House, San Francisco
mailto:swarren@techhouse.com                http://www.techhouse.com/
mailto:swarren@wwwdotorg.org                http://www.wwwdotorg.org/
              MIME, S/MIME and HTML mail are acceptable





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

Date: Sun, 16 May 1999 10:55:30 -0500
From: "Mei" <h0p2468@acs.tamu.edu>
Subject: Please help!
Message-Id: <7hmpt6$1ri$1@news.tamu.edu>

Hello,

I have an ASN.1 file that has a format as

     title title 1,
        description description 1,
            comment  ,
.
    title title 2,
        description description 2,
            comment  ,
.

I have another file that is a tab delimited text file.
title 1     comment 1
title 2     comment 2
.

How do I put comment 1 in comment   under title 1, comment 2 under title 2
and so on of the ASN.1 file?  Thank you very much.

Mei









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

Date: Sun, 16 May 1999 15:10:49 GMT
From: hate98 <webmaster@ihatewindows98.com>
Subject: Re: problem w/perl cgi script & background image
Message-Id: <7hmn5p$qcm$1@nnrp1.deja.com>

In article <373eebc1@news1.jps.net>,
  rcastro@nospam.jps.net (rcastro) wrote:
> Hi,
> I'm having problems with one of my Perl CGI scripts.
> I want the script to generate a web page that uses
> a background image (a .gif file).

Make sure the image exists in the same directory since you did not
include it, as the HTML looks fine.


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


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

Date: Sun, 16 May 1999 13:04:07 -0300
From: Arved_37@chebucto.ns.ca (Arved Sandstrom)
Subject: Re: TROLL ALERT (Re: Perl "constructors")
Message-Id: <Arved_37-1605991304080001@dyip-114.chebucto.ns.ca>

In article <7hlneo$6ma$1@nnrp1.deja.com>, armchair@my-dejanews.com wrote:

> In C++ the constructor (member function that creates an object of that
> class) has the exact same name as the class of the object it is
> constructing. Their are no exceptions. They can be "overloaded - an odd
> C++ term" in that you have more than one constructor (all with the same
> name - the name of the class) but each one will take a different input
> parameter list.
> 
> CPlusClass my_instance;          // call to CPlusClass(void)
> CPlusClass my_inst2.(10,23,30);  // call to CPlusClass(int, int, int)
> 
> "new" is a reserved word that is used to dynamically allocate memory.
> In Java "new" is also a reserved word (and it appears to function more
> as documentation than anything else), and is used in the creation of
> objects (not dynamic memory as in C++), but it is not the constructor
> name, the constructor name(s) are exactly as done in C++.
> 
> JavaClass myInstance = new JavaClass(); // new is keyword and
> //JavaClass() is the constructor
> 
I'm aware that new() in Java and C++ is not the constructor. What I was
getting at is more the frequent association of the word 'new' with the
deed (construction). My main point is that in Perl "new" is not a keyword,
but by usage it has acquired an identification with object construction.
I'm suggesting that for many people it isn't clear that you don't have to
use this specific word.

I'd disagree a bit about your contention with respect to new() in Java.
The keyword is also used to dynamically allocate arrays. I.e., dynamic
allocation of memory. So, if it walks like a duck...

Perl "constructors", i.e. the method create() in package My, are
inherently overloadable. You just pass whatever argument list makes sense.
The same method uses its logic to figure out what to do with the argument
list. In point of fact, this is one reason I'm not too fond of C++ or Java
- umpteen constructors to handle every reasonable set of construction
parameters.

Arved


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

Date: Sun, 16 May 1999 11:46:36 -0400
From: "Mike" <mike-carter@email.msn.com>
Subject: Where can i download a complete perl reference?
Message-Id: <unME9N7n#GA.305@cpmsnbbsa05>

I find plent of online references to perl but is there a windos download
reference manual?

Thanks

Mike




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

Date: Sun, 16 May 1999 16:46:03 GMT
From: armchair@my-dejanews.com
Subject: Re: writing binary data to a file
Message-Id: <7hmsob$u1a$1@nnrp1.deja.com>

In article <372D1FB3.E1ED6788@worldnet.att.net>,
  Frank Hale <frankhale@worldnet.att.net> wrote:
> I didn't know this was such a funny subject. Please I am not a perl
guru
> as most of you here.
>
> I'm on RedHat Linux 5.2. The man pages says that binmode has no effect
> on Unix systems since it doesn't distinguish between binary and text
> files.
>
> I tried the following script
>
> #!/usr/bin/perl
>
> $a = 0x01;
> $b = 0x02;
> $c = 0x03;
>
> open (BIN, ">bin.dat");
> print BIN $a,$b,$c;
> close (BIN);
>
> This produces a normal text file with the following data
>
> 123
>
> When in fact I want the data in binary for the numbers 1,2,3.
>
> --
> From:      Frank Hale
> Email:     frankhale@worldnet.att.net
*********************************************************
a Perl program writes:
*********************************************************
#!/usr/local/bin/perl -w
use strict;


my $a = 1;
my $b = 2;
my $c = 3;

open(BIN,">output_file") || die "can't open file";
binmode(BIN);

my $bin_data = pack("i3",$a,$b,$c);

print (BIN $bin_data);
close(BIN);

******************************************************
a C/C++ program reads:
******************************************************
#include <stdio.h>
#include <assert.h>

void main(void)
{
   FILE *fpFile = fopen("output_file","r"); assert(fpFile);

   struct my_ints {
      int a;
      int b;
      int c;
   };
   my_ints data;
   int iRead = fread(&data,sizeof(int),3,fpFile); assert(iRead == 3);
   printf(" my ints from Perl are %d %d %d\n",
              data.a,data.b,data.c);

   fclose(fpFile);
}


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


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

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


Administrivia:

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

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

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 5687
**************************************

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