[9276] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2871 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jun 14 17:07:39 1998

Date: Sun, 14 Jun 98 14:00:30 -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, 14 Jun 1998     Volume: 8 Number: 2871

Today's topics:
        AIX & GDBM jcamp@plexi.com
    Re: Apache and Perl (John D Groenveld)
        CGI file upload perl script on NT4 running IIS4 temp fi (freekgeek)
        editing middle of file (Todd C. Ames)
    Re: Had a small AHA on objects <quednauf@nortel.co.uk>
    Re: Have we got a good free Perl manual? (Todd Lehman)
    Re: Have we got a good free Perl manual? (Todd Lehman)
    Re: New module/pragma "enum.pm" (was "fields.pm") (Brendan O'Dea)
    Re: new to this - simple if statement question (Shaun Sides)
        Newbie trying to capture(control) output from pipe <tkent@pdq.net>
        NEWBIE: CPAN module install location (nobi)
    Re: Perl and Files shawnporter@my-dejanews.com
    Re: Perl and Files <jhodges@datasync.com>
    Re: prob compil perl5.004_04 under SCO unix with cc OH  <bill@TechServSys.com>
    Re: Puzzle challenge (clarified) <bowlin@sirius.com>
    Re: Read the last record in a file <danboo@negia.net>
    Re: Read the last record in a file (Andre L.)
    Re: Read the last record in a file (Andre L.)
    Re: Read the last record in a file info@insyte.com
    Re: Read the last record in a file info@insyte.com
    Re: REVIEW: Perl CGI Programming - No Experience Requir (Craig Berry)
        Why $foo? Why not $fool? <quednauf@nortel.co.uk>
    Re: Why $foo? Why not $fool? (Michael Fuhr)
    Re: Why $foo? Why not $fool? (Bob Trieger)
    Re: Why $foo? Why not $fool? (Florian Kuehnert)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Sun, 14 Jun 1998 20:37:22 GMT
From: jcamp@plexi.com
Subject: AIX & GDBM
Message-Id: <6m1ca2$13r$1@nnrp1.dejanews.com>

Ok, I'm developing on a Rehat linux machine, and GDBM works fine.  But the
production is on an IBM AIX machine.  When a GDBM database gets 5 or 6 20k
records, it returns the following error:

[14/Jun/1998:14:50:27] failure: for host nywa140950.btco.com trying to POST
/cgi-bin/euro/faq/admin.cgi, cgi-parse-ou
tput reports: the CGI program /www/wwwdev/ns-cgi-bin/euro/faq/admin.cgi did
not produce a valid header (name without
value: got line "lseek error at /www/wwwdev/ns-cgi-bin/euro/faq/admin.cgi
line 363.")

But this works fine on Redhat linux.  Below is the script, if anyone can help
me out then it would be very appreciated, any suggestions you can make are
grateful, we're completely stumped.

#!/usr/bin/perl

use POSIX;
use GDBM_File;

   tie (%test,GDBM_File,"test", O_RDWR | O_CREAT, 0666);

   open(TEST_FILE,"test.txt");  # Gets 20k file and stufs into variable $temp
   while(<TEST_FILE>) {
      $temp = $temp . $_;
   }
   close TEST_FILE;

   $x = 1;
   while($x < 30) {          # Stuffs the 20k var into dbase 30 times
      $test{$x} = "$temp";   # Store in database
      $x = $x + 1;
   }

   untie %test;

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


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

Date: 14 Jun 1998 14:01:23 -0400
From: groenvel@cse.psu.edu (John D Groenveld)
Subject: Re: Apache and Perl
Message-Id: <6m135j$o37$1@tholian.cse.psu.edu>
Keywords: perl apache modperl

In article <6lvf9p$1e5k@r02n01.cac.psu.edu>,
Patrick Lanphier <p-lanphier@psu.edu> wrote:
>What are the settings for the srm file for Apache so the when the file
>extension pl or plx is used it will automatically fire the Perl interpreter?
>Better yet has anybody compiled the modperl for NT for version 1.3b7 of
>Apache?
http://www.cpan.org/doc/FAQs/win32/Perl_for_Win32_FAQ_4.html#4_10
http://www.apache.org/docs/misc/FAQ.html#CGIoutsideScriptAlias

The better solution is to build Apache with mod_perl. Then run your CGI
scripts under Apache::Registry. 
John
groenveld@acm.org


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

Date: 14 Jun 1998 16:28:11 EDT
From: freekgeek@NOSPAM.hotmail.com (freekgeek)
Subject: CGI file upload perl script on NT4 running IIS4 temp file creation question
Message-Id: <6m1bor$po7@examiner.concentric.net>

BACKGROUND:
I borrowed/developed code for a file upload CGI script in Perl for
NT4 also making use of the CGI.pm module. The script works just fine - it 
uploads both text and binary files, except when it uploads a binary file it 
(presumably perl) creates a duplicate of the file with a name like 
CGItemp210001 in a temp folder on the current volume (if no temp folder is 
available it creates it in the cgi-bin folder where the script was executed 
from).

SCRIPT:
open(OUTFILE,">$saveUploadedFileHere");
binmode(OUTFILE);
while ($bytesread = read($uploadedFile,$buffer,1024)) {
    print OUTFILE $buffer;
}
close(OUTFILE);

QUESTION: I have surmised that the problem Perl but since
viewers here might develop for both NT and unix platforms, I was hoping
someone else might have experienced this problem and might know of a way to
circumvent the creation of the temp file when executing a similar script.
Any help/hints would be greatly appreciated.

--
Charles Ragan, ragan@idetix.com




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

Date: Sun, 14 Jun 1998 18:43:58 GMT
From: ames0009@tc.umn.edu (Todd C. Ames)
Subject: editing middle of file
Message-Id: <3584156a.1235096@news.tc.umn.edu>

Yes, I've read the FAQ on this issue--here is my idea:

You have an html file that is a series of tables.  You want to be able
to edit a table's contents from a script (which is in the middle of
the file).

Suppose you added comments with "key words" for each table within the
html file (manually).  You could then dump the entire file into an
array, call split /keyword/ to remove the particular table you wished
to remove.

For instance:
<!----------keyword---->

<table >
 .....stuff
</table>

<!----------keyword---->

You would do this for each table (using a different keyword).  Ok,
you've gotten rid of the old table.  The trick is adding the
replacement in the same position within the file.    I am thinking you
could use splice to replace the old variables (the "keywords" would be
the boundaries of an array slice).

I would just like some feedback on this idea, mainly to see if I am
overlooking anything (conceptually).

Thanks,

T. Ames

>>>>>>>>>>>>>>>>>>>
Todd C. Ames
ames0009@tc.umn.edu
University of Minnesota


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

Date: Sun, 14 Jun 1998 19:27:03 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: Had a small AHA on objects
Message-Id: <358415F7.EA7FC79D@nortel.co.uk>

Mark-Jason Dominus wrote:

> 
> `bless' defaults to using the current package, whether or not the
> current package is `main'...

(and more explanatory comments)

Thanks very much. I had this other flash during Saturday night (after a medieval
banquet; the brain works in strange ways...) on how to pass the arguments, but
your reply clarifies things quite a bit. Hmmm, sometimes I see too much magic in
the things. Maybe Perl is too good :) 


____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: Sun, 14 Jun 1998 20:08:30 GMT
From: lehman@visi.com (Todd Lehman)
Subject: Re: Have we got a good free Perl manual?
Message-Id: <25Wg1.135$8W3.571178@ptah.visi.com>

David Kastrup <dak@mailhost.neuroinformatik.ruhr-uni-bochum.de> writes:
> Please come up with an actual quote to underline your wild
> accusations.

Gee, David, you managed to snip my second paragraph, where I wrote, "I may
be guilty of reading between the lines too much in RMS's post (which started
this thread).  But even after 5 readings, I still sensed snide and arrogant
undertones..."

I don't want to make any accusations, but to state opinions and observations,
and I was hoping that RMS himself might be able to clarify a couple points.

Be that as it may, here are the specific RMS passages which seemed dis-
respectful (IMHO)...  Feel free to point out any specific misinterpreta-
tions I may have had.

RMS> Once upon a time, I thought I would learn Perl.  I got a copy of a
RMS> free manual, but I found it simply unreadable, and gave up.  Perl
RMS> users told me that there were better manuals, but they were not free.
RMS> Why was this?  Their authors had sold the manuals to O'Reilly, instead
RMS> of contributing them to the free software community.  It wasn't the
RMS> first time and (to our community's great loss) it was far from the
RMS> last.

My reaction:  My god, I had no idea that RMS was so antagonistic.


RMS> O'Reilly and other publishers have enticed a great many authors
RMS> to withhold their manuals since then.

My reaction:  But so what.  It's their decision.  It's arguably unfortunate
for some, but everyone makes personal choices.


RMS> Partly as a result of this,
RMS> partly because writing good English is a skill which most good
RMS> programmers have not studied, a lack of documentation is one of the
RMS> worst deficiencies of free operating systems today.

My reaction:  That's irrelevant to the discussion and sounds like a guised
jab at both O'Reilly and the Perl authors.  What is he really trying to say?


RMS> Perl is an important piece of free software, and it ought to have a
RMS> *good* free manual.  So I added this item to the GNU task list, hoping
RMS> this would encourage someone to write one.

My reaction:  A good step.


RMS> That was a few years ago.  If there is now a good free manual, that's
RMS> great.  I'm always glad to remove an item from the task list because
RMS> the job has been done.

My reaction:  "That's great" sounds sarcastic.  Negative undertones really
starting to build now.


RMS> I might even buy a copy of this manual, if
RMS> someone is selling them--especially if it is O'Reilly.

My reaction:  WTF?  What is the point in telling us this?  Is he used to
people following him like sheep?


RMS> (If we buy O'Reilly manuals only when they are free, we can encourage
RMS> O'Reilly to publish and sell more free manuals.)

My reaction:  Good logic.  It's too bad he didn't focus more on constructive
arguments like this one.


RMS> But before I start celebrating,

My reaction:  Would he be celebrating the existence of a Perl manual which he
may or may not even buy, or would he be celebrating the fact that someone had
allowed him to remove an item from the task list?  Or some other thing?


RMS> [5 paragrphs of good points]
RMS>
RMS> To be sure, many users find non-free manuals "useful".  And they can
RMS> indeed be useful, in a purely materialistic sense, just as non-free
RMS> software can.  What they can't be is part of the free software
RMS> community.

My reaction:  Wow, what snobbery.  And since when is there a correlation
between useful and free?  The above paragraph was a cheap jab.  No wonder
he's hated by so many people.


RMS> I expect that I'll soon know whether Perl now has a good free manual.

My reaction:  Why didn't he look on www.perl.com first to find out the
answer?  Or why didn't he write Larry Wall or Randal Schwartz or Tom
Christiansen?  It may have taken much less time than writing a 750-word
essay and posting it for all the world to read and check for him.  Is he
lazy or does he have some other hidden agenda?  I suspect he already knew
and just wanted to make a fuss about it.


RMS> I hope that the answer will be yes, and that I'll be able to delete
RMS> that item from the GNU task list.

My reaction:  What is the point of this sentence, other than to make himself
feel more important?


RMS> If not, I hope that someone will
RMS> change the distribution terms on an existing good manual,

My reaction:  Why state this publicly?  If he hasn't yet written the authors
directly to ask for this, then he is a coward.  If he has, then he's wasting
his breath asking again.  If he wants to encourage the rest of the world to
encourage said transformation, then he is going about it in an in inept way.
The above sentence seemed to me to be nothing more than pissing and moaning.
Of course, I could be wrong.


RMS> or write a new one.

My reaction:  I hear an echo in here.


RMS> O'Reilly is just beginning to contribute to our community;
RMS> most of what they do is still non-free, and thus no contribution.  If
RMS> O'Reilly's Perl manual is still non-free, making it free would be a
RMS> fine way to take the next step in actually contributing to free
RMS> software.

My reaction:  This statement sounds true enough (in RMS's definitions of
free, community, and contributing) but is nonetheless sadly misdirected.

[End of RMS passages, and now back to Mr. Kastrup's post.]


> RMS does not talk about people doing something wrong or
> looking down or whatever else you wildly assume.  He just says that
> non-free books don't fit his demands and are inappropriate as
> documentation for free software.

OK.  I'll have to take your word on that.  But how come he doesn't address
any of the points people bring up here?  It's been like 2 weeks already?


> As it can make the difference
> between free software being useful for a Person in Third-World States,
> China, former Soviet union etc. I think this not as awfully arrogant,
> evil, derogatory and whatever else people want to call it.

Is it RMS's place/business at all to tell Perl folks what to do when he
hasn't even taken the time to learn the language?  No wonder he hasn't
succeeded in motivating anyone to write a free book for Perl -- no fire
in his belly w.r.t. Perl.  He would rather frump than put some actual
effort into it.

--Todd


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

Date: Sun, 14 Jun 1998 20:11:45 GMT
From: lehman@visi.com (Todd Lehman)
Subject: Re: Have we got a good free Perl manual?
Message-Id: <58Wg1.137$8W3.572756@ptah.visi.com>

Barry Margolin <barmar@bbnplanet.com> writes:
> Well, the words he often chooses are easily misinterpreted.  For instance,
> his references to the existing Perl documentation said, "but they were no
> good because they weren't free."  By "no good" he meant "not acceptable" or
> "not appropriate", but it's easy to understand why people would interpret
> it as "not good" == "bad".

Is that sort of thing intentional or is he just a crummy writer?  Or does
he expect all readers to speak his dialect of English?  Curious,

--Todd


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

Date: 15 Jun 1998 04:43:17 +1000
From: bod@compusol.com.au (Brendan O'Dea)
Subject: Re: New module/pragma "enum.pm" (was "fields.pm")
Message-Id: <6m15k5$n9q$1@duende.compusol.com.au>

In article <897698370.910313@thrush.omix.com>,
Zenin  <zenin@bawdycaste.org> wrote:
>Brendan O'Dea <bod@compusol.com.au> wrote:
>: The prefix and `..' ideas are pretty cool.
>
>	Actually, I still would like to see a single RealWorld use of the
>	.. syntax, but it was in the spec I used.

Perhaps something like this:

    use enum qw(
	Title FirstName Surname
	Addr1..Addr4 PostCode
    );

although on reflection such uses would be rare.

>: I would prefer to be able to do this at times:
>:     use enum Foo => 1, Bar => 2;
>
>	Hmm, I question your use of enum.  Are you trying to get a shorter
>	use constant syntax?  This is not what enum is intended for, either
>	in C or here.

Really?  K&R says:

  ``Enumerations provide a convenient way to associate constant values
    with names, an alternative to #define ...''

and provides examples including:

    enum escapes { BELL = '\a', BACKSPACE = '\b', TAB = '\t',
	NEWLINE = '\n', VTAB = '\v', RETURN = '\r' };

This is also a common idiom in C++ (these examples are taken from
include files in the standard library):

    enum {ALIGN = 8};
    enum {MAX_BYTES = 128};
    enum {NFREELISTS = MAX_BYTES/ALIGN};

    enum {
	skipws   = 01,
	left     = 02,
	right    = 04,
	/* ... */
    };

>	Blagh...  This is /not/ a "multi"-constant module.  Personally
>	I think the constant (or manybe 'constants' (with an 's')?) module
>	should allow for multiple assignments in one block.  A enum module
>	however, is not the place for this.

The constant module requires separate imports so that constant arrays
may be defined.

Regards,
-- 
Brendan O'Dea                                        bod@compusol.com.au
Compusol Pty. Limited                  (NSW, Australia)  +61 2 9809 0133


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

Date: 14 Jun 1998 19:15:19 GMT
From: arch@abts.net (Shaun Sides)
Subject: Re: new to this - simple if statement question
Message-Id: <slrn6o7iou.5v3.arch@abts.net>

Original message by: Kerrie Etter <kerrie@home.com>
Date: Fri, 12 Jun 1998 23:50:12 GMT
Subject: new to this - simple if statement question


> sorry this is probably a horribly simple question but.....
> 
> (drop down to choose a state....)
> 
> the following script sends me to California (or whoever I have listed
> first) no matter which state I select....anyone? (again, sorry I'm
> really, really new to this, thanks...k)
> 
> if ($state == California) {
>   print "Location:/newpublic/investors/ca.html\n\n";
> 		}  
> if ($state == Arizona) {
>   print "Location:/newpublic/investors/az.html\n\n";
> 		} 

I see a couple of things you need to improve.  You're using the numeric
comparison operator (==) when you need to be using the one for strings
(eq).  You also are leaving off the quotes around your string literal.

-- 
==============================================================================
	   Shaun L. Sides	    | Hey!  CyberGold |     arch@abts.net
Free Randal Schwartz and Ric Flair! | wastes yer time | arch@sara.mmlc.nwu.edu
==============================================================================
	   The time for desperation is upon us.  Let's play.
		  First Wizard Zeddicus Zu'l Zorander
==============================================================================	


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

Date: Sun, 14 Jun 1998 14:14:45 -0500
From: Tom Kent <tkent@pdq.net>
Subject: Newbie trying to capture(control) output from pipe
Message-Id: <35842125.6120@pdq.net>

I need help!..First let me apologize for the probable ugliness of my
code as I
am just starting out with perl....I am trying to assign this result to
a   
variable to put the output in a place of my liking. So far, I have been
unable
to do this, so my result just prints out in a fairly random place.
I am using this on a Unix system....Any ideas?  Thanks very much in
advance.




open(ON, "|sort|uniq|wc -l");
  foreach $line (@array) {
       ($Fld1) = split(' ',$line);
        print ON "($Fld1)\n";
    }

close (ON);


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

Date: 14 Jun 1998 19:07:02 GMT
From: nobi@clearlight.com (nobi)
Subject: NEWBIE: CPAN module install location
Message-Id: <6m170m$jm4$1@malgudi.oar.net>

Hello there,

I'm searching for a way to install the CPAN module to
my home directory. I don't have root access to install
CPAN module to system. Any help would be mostly appreciated.

Thanks for the help
Nobi


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

Date: Sun, 14 Jun 1998 18:23:43 GMT
From: shawnporter@my-dejanews.com
Subject: Re: Perl and Files
Message-Id: <6m14ff$lqs$1@nnrp1.dejanews.com>

Jay,

If you're having difficulty writing to a file from a CGI script written in
Perl (or any language for that matter) you should make sure that the user
running the CGI script has permission to write to that directory.

For more info, check:
comp.infosystems.www.servers.*
comp.infosystems.www.authoring.cgi

--
Shawn Porter
http://www.rit.edu/~sjp6683

--
In article <6lvg0f$mio$1@chile.it.earthlink.net>,
  "Brent Verner" <REPLY_TO_damonbrent@earthlink.net> wrote:
>
>
> Jay Hodges wrote in message <6lvdsn$mml$1@osh2.datasync.com>...
> >I know this question will be answered easily, but here it goes.  When
> >writing a Perl cgi, how do I open a non-existent file for output?
>
> huh???
>
> output???
>
> if you open a file to write [ open (FILE, ">$filename"); ]  the file will be
> created automatically.
>
> i'm not sure what would happen if you opened a file to read  [ open (FILE,
> "<$filename"); ] that did not exist.  { what could you possibly need to read
> from a nonexistent file? }
>
> brent
>
> (remove 'REPLY_TO_' from address to email)

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


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

Date: Sun, 14 Jun 1998 15:38:14 -0500
From: "Jay Hodges" <jhodges@datasync.com>
Subject: Re: Perl and Files
Message-Id: <6m1cb0$gl$1@osh2.datasync.com>

Thanx e larson.  The permissions thing was it.  I needed to chmod the dir
where the file was being created to give the permissions needed.  Thanx
again, I appreciate your tact, consideration and help.

To anyone who reads this response:

If you are gonna reply to my newsgroup postings with acid and mockery -
DON'T REPLY AT ALL!!!!!  I would rather be ignored than be made fun of.





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

Date: Sun, 14 Jun 1998 14:54:41 -0400
From: -bill- <bill@TechServSys.com>
Subject: Re: prob compil perl5.004_04 under SCO unix with cc OH HELP #2
Message-Id: <35841C71.446B@TechServSys.com>

I still could use some help.  Anyone have an idea of what went wrong ?
-- 

-bill-

Technical Service Systems - bill@TechServSys.com


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

Date: Sun, 14 Jun 1998 13:17:01 -0700
From: Jim Bowlin <bowlin@sirius.com>
To: Tim Bunce Tim Bunce <Tim.Bunce@ig.co.uk>
Subject: Re: Puzzle challenge (clarified)
Message-Id: <35842FBD.A4E7E519@sirius.com>

Tim Bunce wrote:
>  
> A list of names in a specific order is given to a set of messengers
> in a remote land.
> 
> The messengers travel independently to a destination where they
> give the names to you.
> 
> The problem is that the messengers tend to be forgetful:
>         They _often_ miss out one or more names (but not all).
>         They _occasionally_ get the order wrong.
>
> [snip]

Here is a heuristic solution.  It is pretty fast (compared to the exact
solution).  Words that only appear in scrambled messages are lost.
You could insert these randomly in the guessed answer if you want.
Likewise, messages containing just one word are pretty useless.
I suggest tossing these.  If they contain unique words, again feel
free to insert these words at random in the guess.

--- Jim Bowlin

use strict;

my @Msg = 
(
 [qw/foo bar boo     /],
 [qw/foo bar boo     /],
 [qw/bar boo baz     /],
 [qw/foo bar baz boo /],
 [qw/boo foo bar baz /],
 [qw/foo bar baz     /],
 [qw/foo baz boo     /],
);

my (@Hash, @Agree1); 

for my $i (0..$#Msg) {
    $Hash[$i] = { map {$_, 1} @{$Msg[$i]} };
}

for my $i (0..$#Msg) {
    for my $j (0..$#Msg) {
	$Agree1[$i] += agree($i, $j);
    }
}

my @Order = sort {$Agree1[$b] <=> $Agree1[$a]} 0..$#Msg;

my (@Best, $Next_W, $Prev_W, $Follows, $Precedes);
ORDER: foreach my $try (@Order) {
    my @msg = @{$Msg[$try]};
    check_msg(@msg) or next;
    order_msg(@msg);
    push @Best, $try;
}

print_msg('Consistent Messages:', @Best);

my (@Guess, %Guess);
my $word = '_start';
while( $word ) {
    $Guess{$word}++;
    $word = next_word($word) or last;
    $Guess{$word} and last;            # not needed?
    push @Guess, $word;
}

print_msg('Best Guess:');
print "@Guess\n";

#=== Subroutines ===============================================

sub agree {
    my ($i, $j) = @_;
    $i == $j and return 0;
    my @a = grep $Hash[$j]{$_}, @{$Msg[$i]};
    my @b = grep $Hash[$i]{$_}, @{$Msg[$j]};
    return (@a == @b and join('', @a) eq join('',@b)) ? scalar @a : 0;
}

sub order_msg {
    my @msg = @_;
    my $last = '_start';
    while ( @msg and my $word = shift @msg ) {
	my @precedes = (keys(%{$$Precedes{$word}}), $word);
	my %follow;
	foreach my $follow (map({keys %{$$Follows{$_}}} @msg), @msg) {
	    $follow{$follow}++ and next;
	    foreach (@precedes) {
		$$Follows{$_}{$follow}++;
		$$Precedes{$follow}{$_}++;
	    }
	}
	$$Next_W{$last}{$word}++; 
	$$Prev_W{$word}{$last}++;
	$last = $word;
    }
}

sub check_msg {
    my @msg = @_;
    while ( @msg and my $word = shift @msg ) {
	return 0 if grep {$$Follows{$_}{$word}}  @msg;
    }
    return 1;
}

sub next_word {
    my $word = shift;
    my @trys =  keys %{$$Next_W{$word}} or return undef;
    #print "TRY1: @trys\n";
    return $trys[0] if @trys == 1;

    my @trys2;
    foreach my $try (@trys) {
	push (@trys2, $try) unless
	    grep {! defined $Guess{$_}} keys %{$$Prev_W{$try}};
    }
    #print "TRY2: @trys2\n";
    return $trys2[0] if @trys2 == 1;
    @trys = @trys2 if @trys2;

    my @trys3;
    foreach my $word (@trys) {
	push (@trys3, $word) unless grep {$$Follows{$_}{$word}} @trys;
    }
    #print "TRY3: @trys3\n";
    return $trys3[0] if @trys3 == 1;
    @trys = @trys3 if @trys3;

    print STDERR qq/ambiguous words after "$word": @trys\n/;
    my ($first, @rest) = @trys;
    foreach (@rest) {                # could be dangerous!
	$$Next_W{$first}{$_}++; 
	$$Prev_W{$_}{$first}++;
	$$Follows{$first}{$_}++;
    }
    return $first;
}

sub print_msg {
    my $prompt = shift;
    print "\n$prompt\n", '^' x length($prompt), "\n";
    foreach (@_) { 
	printf "%3d [%2d]  ", $Agree1[$_], $_;
	print "@{$Msg[$_]}\n";
    }
}

__END__

Sample output:

Consistent Messages:
^^^^^^^^^^^^^^^^^^^^
 14 [ 5]  foo bar baz
 12 [ 1]  foo bar boo
 12 [ 3]  foo bar baz boo
 12 [ 0]  foo bar boo
  9 [ 6]  foo baz boo

Best Guess:
^^^^^^^^^^^
foo bar baz boo


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

Date: Sun, 14 Jun 1998 14:08:59 -0400
From: Dan Boorstein <danboo@negia.net>
Subject: Re: Read the last record in a file
Message-Id: <358411BB.9599BA89@negia.net>

Bob Trieger wrote:
> 
> "Brent Verner" <REPLY_TO_damonbrent@earthlink.net> wrote:
> 
> -> $array_name[$#array_name];  ## yields last line of @array_name
> ->
> -> $array_name[$#array_name -1];  ## yields next to last line of @array_name
> 
> This is a rather sloppy way of writing:
> 
> pop @arrayname;
> 
> perldoc -f pop

really?

@foo = ('a'..'z');

$bar = $foo[$#foo];
print scalar @foo, "\n";

$bar = pop @foo;
print scalar @foo, "\n";

yes, $bar gets the same value in either case, but the effects on @foo
are different and potentially of great significance.

cheers,

-- 
Dan Boorstein   home: danboo@negia.net  work: danboo@y-dna.com

 "THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER."
                         - Cosmic AC


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

Date: Sun, 14 Jun 1998 14:33:24 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: Read the last record in a file
Message-Id: <alecler-1406981433240001@dialup-723.hip.cam.org>

Four replies so far, and none of them manages to give a simple answer to a
simple question...

   # Always check the return value of open()
   open FILE, $filename
      or die "Error on open, file $filename: $!\n";

   while (!eof FILE) { $last_record = <FILE> }

   close FILE;

There you go. 
The file must end with one newline, and only one, for this to work.

A.L.

=============================================

In article <6lv4n2$mu3$1@nnrp1.dejanews.com>, info@insyte.com wrote:

> Neophyte question.
> 
> There must be an easy way to do this and I haven't found it yet. I have a flat
> file consisting of a number of variable length, CSV, records terminating in
> "\n". I have used the following sequence:
> 
>    open (FILE, <"filename");
>    seek (FILE, 0, 2);
> 
> to get to the EOF. But because I don't know the length of any individual
> record I can't simply position it using "seek (FILE, -rec_lenght, 2). Thus
> far the only way I have come up with is to loop backward one character at a
> time until I find the "\n" at the end of the penultimate record and then read
> the data forward from there.
> 
> Isn't there a simple way to "back up" one record?
> 
> John  Steele
> jsteele AT insyte DOT com
> 
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Sun, 14 Jun 1998 14:52:15 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: Read the last record in a file
Message-Id: <alecler-1406981452150001@dialup-723.hip.cam.org>

In article <alecler-1406981433240001@dialup-723.hip.cam.org>,
alecler@cam.org (Andre L.) wrote:

>    # Always check the return value of open()
>    open FILE, $filename
>       or die "Error on open, file $filename: $!\n";
> 
>    while (!eof FILE) { $last_record = <FILE> }
> 
>    close FILE;


Correction: this is about 30% faster than the above example.

open FILE, $filename
   or die "Error on open, file $filename: $!\n";

while (<FILE>) { $last_record = $_ if eof }

close FILE;

HTH,
A.L.


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

Date: Sun, 14 Jun 1998 19:52:53 GMT
From: info@insyte.com
Subject: Re: Read the last record in a file
Message-Id: <6m19ml$tia$1@nnrp1.dejanews.com>

Thanks. Yes, that will work, but I was trying to avoid reading the whole ting
into an array just to get the last element...

In article <6lvaeb$hjq$1@argentina.it.earthlink.net>,
  "Brent Verner" <REPLY_TO_damonbrent@earthlink.net> wrote:
>
>
> info@insyte.com wrote in message <6lv4n2$mu3$1@nnrp1.dejanews.com>...
> >Neophyte question.
> >
> >There must be an easy way to do this and I haven't found it yet. I have a
> flat
> >file consisting of a number of variable length, CSV, records terminating in
> >"\n". I have used the following sequence:
> >
> >   open (FILE, <"filename");
> >   seek (FILE, 0, 2);
> >
> >to get to the EOF. But because I don't know the length of any individual
> >record I can't simply position it using "seek (FILE, -rec_lenght, 2). Thus
> >far the only way I have come up with is to loop backward one character at a
> >time until I find the "\n" at the end of the penultimate record and then
> read
> >the data forward from there.
> >
> >Isn't there a simple way to "back up" one record?
>
> I'm not sure i understand your FILE, but ...
>
>  open (FILE, "<$filename");
>   @array_name = <FILE>;
>  close (FILE);
>
> $array_name[$#array_name];  ## yields last line of @array_name
>
> $array_name[$#array_name -1];  ## yields next to last line of @array_name
>
> basically,  $#array_name  is the number of lines in  @array_name.
> you access an individual line of @ by using  $array_name[n]  where n is the
> position of the line you want.
>
> {I'm relatively new at Perl, so my advice may be all wrong.}
>
> perhaps the best set of references available::
> http://agora.leeds.ac.uk/Perl/start.html   -   very basic Perl
> http://www-cgi.cs.cmu.edu/cgi-bin/perl-man   -   in depth Perl 4
> http://www.perl.com/CPAN-local/doc/manual/html/pod/index.html   -   in depth
> Perl 5
>
> >
> >John  Steele
> >jsteele AT insyte DOT com
> >
> >-----== Posted via Deja News, The Leader in Internet Discussion ==-----
> >http://www.dejanews.com/   Now offering spam-free web-based newsreading
>
>


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


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

Date: Sun, 14 Jun 1998 19:54:47 GMT
From: info@insyte.com
Subject: Re: Read the last record in a file
Message-Id: <6m19q7$tiq$1@nnrp1.dejanews.com>

Thanks, I'll look there for a clue.

In article <Pine.GSO.3.96.980613181006.27055C-100000@user2.teleport.com>,
  Tom Phoenix <rootbeer@teleport.com> wrote:
>
> On Sun, 14 Jun 1998 info@insyte.com wrote:
>
> > I have a flat file consisting of a number of variable length, CSV,
> > records terminating in "\n". I have used the following sequence:
> >
> >    open (FILE, <"filename");
>
> Even when your script is "just an example" (and perhaps especially in that
> case!) you should _always_ check the return value after opening a file.
>
> >    seek (FILE, 0, 2);
> >
> > to get to the EOF. But because I don't know the length of any individual
> > record I can't simply position it using "seek (FILE, -rec_lenght, 2).
>
> > Isn't there a simple way to "back up" one record?
>
> Search through section five of the FAQ for the part which begins, "If you
> need to seek to an arbitrary line of a file" to find some information on
> working with a line-oriented file. Hope this helps!
>
> --
> Tom Phoenix       Perl Training and Hacking       Esperanto
> Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/
>
>


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


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

Date: 14 Jun 1998 18:38:32 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: REVIEW: Perl CGI Programming - No Experience Required
Message-Id: <6m15b8$t0u$1@marina.cinenet.net>

Stefaan A Eeckels (Stefaan.Eeckels@ecc.lu) wrote:
: The awful^H^H^H^H^Hflexible syntax doesn't help either;
: Perl can be more arcane than LISP and C++ combined ;-) 

Yeah, that's one of my favorite things about it...

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: Sun, 14 Jun 1998 19:45:59 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Why $foo? Why not $fool?
Message-Id: <35841A67.5973587A@nortel.co.uk>

A question on the lighter side. It might be because I am not American and I am
missing some obvious cultural thingie, but:

Why is the traditional name of an example variable in Perl $foo, or for that
matter $bar ??? 
I cannot find the answer to that question being documented anywhere!
Clarification would be greatly appreciated!!

-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: Sun, 14 Jun 1998 19:45:11 GMT
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: Why $foo? Why not $fool?
Message-Id: <6m197v$3ko@flatland.dimensional.com>

"F.Quednau" <quednauf@nortel.co.uk> writes:

> A question on the lighter side. It might be because I am not American and I am
> missing some obvious cultural thingie, but:
>
> Why is the traditional name of an example variable in Perl $foo, or for that
> matter $bar ??? 
> I cannot find the answer to that question being documented anywhere!
> Clarification would be greatly appreciated!!

Take a look at the Jargon File.  Among other places, you can find it at:

    http://sagan.earthspace.net/jargon/

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


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

Date: Sun, 14 Jun 1998 20:02:11 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: Why $foo? Why not $fool?
Message-Id: <6m1abc$ip2$1@ligarius.ultra.net>

[ posted and mailed ]

"F.Quednau" <quednauf@nortel.co.uk> wrote:
-> A question on the lighter side. It might be because I am not American and I
->  am
-> missing some obvious cultural thingie, but:
-> 
-> Why is the traditional name of an example variable in Perl $foo, or for that
-> matter $bar ??? 
-> I cannot find the answer to that question being documented anywhere!
-> Clarification would be greatly appreciated!!

they are syllables of the word "fubar". Look up fubar in any online dictionary 
and you should be able to find the definition.


Bob Trieger
sowmaster@juicepigs.com
" Cost a spammer some cash: Call 1-800-239-0341
    and hang up when the recording starts. "


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

Date: 14 Jun 1998 19:47:54 GMT
From: sutok@gmx.de (Florian Kuehnert)
Subject: Re: Why $foo? Why not $fool?
Message-Id: <slrn6o8a7a.for.sutok@babelon.in-brb.de>

F.Quednau schrieb/wrote/icrivait/ha scritto:
>Why is the traditional name of an example variable in Perl $foo, or for that
>matter $bar ??? 

The Jargon File tells us:

:foo: /foo/  1. /interj./ Term of disgust.  2. Used very
   generally as a sample name for absolutely anything, esp. programs
   and files (esp. scratch files).  3. First on the standard list of
   {metasyntactic variable}s used in syntax examples.  See also
   {bar}, {baz}, {qux}, {quux}, {corge}, {grault},
   {garply}, {waldo}, {fred}, {plugh}, {xyzzy},
   {thud}.

   The etymology of hackish `foo' is obscure.  When used in
   connection with `bar' it is generally traced to the WWII-era Army
   slang acronym FUBAR (`Fucked Up Beyond All Repair'), later
   bowdlerized to {foobar}.  (See also {FUBAR}.)

   However, the use of the word `foo' itself has more complicated
   antecedents, including a long history in comic strips and cartoons.
   The old "Smokey Stover" comic strips by Bill Holman often
   included the word `FOO', in particular on license plates of cars;
   allegedly, `FOO' and `BAR' also occurred in Walt Kelly's
   "Pogo" strips.  In the 1938 cartoon "The Daffy Doc", a very
   early version of Daffy Duck holds up a sign saying "SILENCE IS
   FOO!"; oddly, this seems to refer to some approving or positive
   affirmative use of foo.  It has been suggested that this might be
   related to the Chinese word `fu' (sometimes transliterated
   `foo'), which can mean "happiness" when spoken with the proper
   tone (the lion-dog guardians flanking the steps of many Chinese
   restaurants are properly called "fu dogs").

   Paul Dickson's excellent book "Words" (Dell, 1982, ISBN
   0-440-52260-7) traces "Foo" to an unspecified British naval
   magazine in 1946, quoting as follows: "Mr. Foo is a mysterious
   Second World War product, gifted with bitter omniscience and
   sarcasm."

   Other sources confirm that `FOO' was a semi-legendary subject of
   WWII British-army graffiti more-or-less equivalent to the American
   Kilroy.  Where British troops went, the graffito "FOO was here"
   or something similar showed up.  Several slang dictionaries aver
   that FOO probably came from Forward Observation Officer.  In this
   connection, the later American military slang `foo fighters' is
   interesting; at least as far back as the 1950s, radar operators
   used it for the kind of mysterious or spurious trace that would
   later be called a UFO (the older term resurfaced in popular
   American usage in 1995 via the name of one of the better
   grunge-rock bands).

   Earlier versions of this entry suggested the possibility that
   hacker usage actually sprang from "FOO, Lampoons and Parody",
   the title of a comic book first issued in September 1958, a joint
   project of Charles and Robert Crumb.  Though Robert Crumb (then in
   his mid-teens) later became one of the most important and
   influential artists in underground comics, this venture was hardly
   a success; indeed, the brothers later burned most of the existing
   copies in disgust.  The title FOO was featured in large letters on
   the front cover.  However, very few copies of this comic actually
   circulated, and students of Crumb's `oeuvre' have established
   that this title was a reference to the earlier Smokey Stover
   comics.

   An old-time member reports that in the 1959 "Dictionary of the
   TMRC Language", compiled at {TMRC}, there was an entry that went
   something like this:

     FOO: The first syllable of the sacred chant phrase "FOO MANE
     PADME HUM."  Our first obligation is to keep the foo counters
     turning.

   For more about the legendary foo counters, see {TMRC}.  Almost
   the entire staff of what later became the MIT AI Lab was involved
   with TMRC, and probably picked the word up there.

   Very probably, hackish `foo' had no single origin and derives
   through all these channels from Yiddish `feh' and/or English
   `fooey'.



The rest (expanations to bar, qux etc.) is easily to find in the web, go
searching for "Jargon File" on yahoo and you'll get it quickly.

HTH
  Florian
-- 
"Warum kostet Linux nichts?
 Warum gibt es kein einheitliches Frontend?"
        -- aus "Wie starte ich einen Endlos-Thread?", Teil 1327
           (Holger Schauer in dcolm)


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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

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

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

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


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

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