[7764] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1389 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 29 14:17:36 1997

Date: Sat, 29 Nov 97 11:00:29 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 29 Nov 1997     Volume: 8 Number: 1389

Today's topics:
     Re: Environmental variable <ckpwong@undergrad.math.uwaterloo.ca>
     Re: failed substitution <friedman@uci.edu>
     FREE Pagers!! Or just give them away for profit. <FREE@any.where.com>
     Re: Help please !!! <thidinh@erols.com>
     Re: Help! unexpected token (Ryuji Yokoyama)
     Re: last element in an array? , snailgem@aol.com
     Re: LWP, and HTTP_REFERER <merlyn@stonehenge.com>
     Re: posting to a newsgroup (I R A Aggie)
     Re: posting to a newsgroup <rra@stanford.edu>
     Q: alternative to Perl? <xah@best.com>
     Re: Q: Learning perl with no progr. experience (Amy Williams)
     Re: Q: Learning perl with no progr. experience <ckpwong@undergrad.math.uwaterloo.ca>
     Re: Q: Learning perl with no progr. experience (I R A Aggie)
     Re: Q: Learning perl with no progr. experience <merlyn@stonehenge.com>
     Re: read from end of file (by line) (Patrick)
     READING the last few lines of a HUGE FILE. <gdoucet@ait.acl.ca>
     Re: READING the last few lines of a HUGE FILE. <friedman@uci.edu>
     Re: READING the last few lines of a HUGE FILE. (Andrew M. Langmead)
     Re: Resource Kit Anomaly (Clay Irving)
     Re: Resource Kit Anomaly (Jeremy D. Zawodny)
     Re: Resource Kit Anomaly <rra@stanford.edu>
     Re: truncating a string (Bart Lateur)
     Re: truncating a string <Matthew.Rice@ftlsol.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Sat, 29 Nov 1997 15:57:52 GMT
From: Cindy Wong <ckpwong@undergrad.math.uwaterloo.ca>
To: venkat5@hotmail.com
Subject: Re: Environmental variable
Message-Id: <Pine.SUN.3.95q.971129105303.17988B-100000@napier.uwaterloo.ca>

> Hello,
>    I am unable to get the QUERY_STRING variable in %ENV. can anyone please
> mail me the reason for this?
> I am working on Perl5.001 under WindowsNT4
> Regards.
> venkat.

You have to run it as a cgi script or somehow set the QUERY_STRING
environment variable (maybe add a "$ENV{'QUERY_STRING'} = 'foo=bar';" line
if you want to test a cgi script as a normal perl script?) before trying
to access the data in $ENV{'QUERY_STRING'}.  Trying a line like
  $ENV{'QUERY_STRING'} || print "no QUERY_STRING!!  Arhhh!!!\n";
to see if you actually have any query string.

Hope this helps,
Cindy

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS/IT/M/O dx s-:- a--- C+++>$ U++>++++$ P+++>++++$ L++>++++ 
E>++ W++ N++ o? K? w-->--- O? M V? PS PE+ Y+ PGP?>++ !t !5 X 
R+ tv b++ DI++++ !D G>+++ e+>++ h! r++ x? 
------END GEEK CODE BLOCK------




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

Date: 29 Nov 1997 17:37:50 GMT
From: "Eric D. Friedman" <friedman@uci.edu>
Subject: Re: failed substitution
Message-Id: <65pjte$6gf@news.service.uci.edu>

In article <65p8sm$s0t$1@daily.bbnplanet.com>,
Jason Gloudon <jgloudon@bbn.remove.com> wrote:
<
<: @myfile =~ s/$find_pat/$replace_pat/g;
<
<Yes. You can't use s/// on an array. You need to do this in a loop.
<I would advise against reading the entire file into memory
<if the operations you needed to perform could be done independently for each 
<line.

Good advice, although for a quick hack many folks would disregard it.
So, just in case the original poster wants to evaluate the one-line
slurp option as well:

$/ = undef;  # consider localizing this if it's in a function
my $file = <FILE>;
$/ = "\n";
$file =~ s/$find/$replace/gs; # need the /s if \n characters should be 
                              # included in `.'



-- 
Eric D. Friedman
friedman@uci.edu


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

Date: 29 Nov 1997 18:34:06 GMT
From: Money to be made<FREE@any.where.com>
Subject: FREE Pagers!! Or just give them away for profit.
Message-Id: <65pn6u$h7v@nntp1.erinet.com>

http://surf.to/pagers

http://surf.to/freepagers

The sites above will give you all the info you need to start making money just by giving away free pagers.
Is that not the american dream or what?  Something for nothing. GOD BLESS AMERICA.
Thanks for your time.
Tim


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

Date: Sat, 29 Nov 1997 10:09:57 -0500
From: "PH" <thidinh@erols.com>
Subject: Re: Help please !!!
Message-Id: <65pbbn$18f$1@winter.news.erols.com>

Hi Avram,

Thx for your information.  I tried to load this file in IExplorer by :
http://dinh/cgi-bin/scripts/test.pl  and I got the error message above.

I tried to run your script but I got the same error.  I also tried to remove
the line contains  $ENV but it didn't work.  Do you think I missed something
like perl modules ?  But I don't know how to setup them !  I get stuck at
this begining point so I cannot go futher !!!

Hope I have some more advices from you or anyones.

Dinh

=====================================================================
Avram Grumer wrote in message ...
>In article <65o4dq$2go$1@winter.news.erols.com>, "PH" <thidinh@erols.com>
wrote:
>
>> I just begin to test a .pl file on my NT Workstation with PWS4.0 beta.  I
>> always get this error message: "The specified module could not be found.
"
>
>Does the error message specify which line the error was found in?  I just
>tried running it with the "-w" switch on, and it ran, giving only the
>error "Use of uninitialized value. File 'Untitled'; Line 12", line 12
>being the one with "$ENV{REMOTE_ADDR}" in it.  ("Untitled" was the name of
>the window in which I had pasted the script; I'm running MacPerl
>5.1.5r4.)
>
>I've had trouble in the past with interpolated quotes containing <FOO>.  I
>think they get mistaken for filehandles.
>
>Try replacing the double quotes with single quotes, like this:
>
>print '<HTML>' . "\n";
>
>Or another way:
>
>$foo = q|
>HTTP/1.0 200 OK
>Content-Type: text/html
>
><HTML>
><HEAD>
><TITLE>Hello World</TITLE>
></HEAD>
><BODY>
><H4>Hello World</H4>
><P>
>Your IP Address is ==IP_ADDRESS==.
><P>
><H5>Have a nice day</H5>
></BODY>
></HTML>
>|;
>
>$foo =~ s/==IP_ADDRESS==/$ENV{REMOTE_ADDR}/;
>print $foo;
>
>> print "HTTP/1.0 200 OK\n";
>> print "Content-Type: text/html\n\n";
>> print "<HTML>\n";
>> print "<HEAD>\n";
>> print "<TITLE>Hello World</TITLE>\n";
>> print "</HEAD>\n";
>> print "<BODY>\n";
>> print "<H4>Hello World</H4>\n";
>> print "<P>\n";
>> print "Your IP Address is $ENV{REMOTE_ADDR}.\n";
>> print "<P>"; print "<H5>Have a nice day</H5>\n";
>> print "</BODY>\n";
>> print "</HTML>\n";
>
>--
>Avram Grumer       avram@interport.net
>http://www.users.interport.net/~avram/
>Give a man a fish, and you feed him for a day.
>Teach him how to fish, and you can sell him equipment.




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

Date: Sat, 29 Nov 1997 15:35:25 GMT
From: rqy1319@is4.nyu.edu (Ryuji Yokoyama)
Subject: Re: Help! unexpected token
Message-Id: <348034cb.2064653@netnews.nyu.edu>

Thanks for replying.  First of all,  I thought missing semicolon, but
it was OK.   Also, before the declaration of the array, I only put
"#!/use/bin/perl" and some comments(decription of the program).



On 28 Nov 1997 17:13:15 -0800, hermit@cats.ucsc.edu (William R. Ward)
wrote:

>Sometimes this kind of error message means that the previous line
>might be missing a semicolon or something like that... sometimes the
>Perl parser doesn't notice something's wrong until it hits the next
>line of code.
>
>Another thing to try is to add "use diagnostics;" to the code, which
>will give more detailed error messages.  Also use the -w switch to
>perl.
>
>Or you could give us some more context for your code....
>
>HTH.
>
>--Bill.
>[posted and mailed]
>
>rqy1319@is4.nyu.edu (Ryuji Yokoyama) writes:
>> I have encountered really strange thing.  I declared the same array in
>> two different program, which is following.
>[...]
>> It works nicely in one program;however, I got an error message at the
>> other program.
>> 
>> ./search2.pl:syntax error near unexpected token 'qw('
>> .search2.pl:./search2.pl:line 4 @files = qw('
>> 
>> I totally don't understand why I got this error message even it works
>> another program.  I wrote both program the same enviroment(Emacs for
>> linux).  Please somebody tell me the reason why this thing happen.



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

Date: Sat, 29 Nov 1997 13:34:52 -0500
From: , snailgem@aol.com
Subject: Re: last element in an array?
Message-Id: <34806049.7ED0@aol.com>

> I hope you don't take offense, but these seem to be very elementary
> questions a person would learn when studying from any tutorial book on
> perl. You might do youself a big favor by picking up a copy of
> "Learning Perl".

Thanks for the response. No offense taken.

> For the array @matches, the last element of the array can be refered
> to as $#matches.
But I did my research before posting. Maybe I have the wrong book (Teach
yourself PERL in 21 days).The only reference to $# in it is as a number
output variable. I couldn't find anything on referencing the last
element of an array. That's when I posted.

 You can also find out the number of elements in the
> array by referring to the array name in a scalar context. (and from
> the number of elements, you can get the index of the last element.)
> See the perldata man page for details.

That's what I was trying (apparently wrongheadedly) to do with:
$matches[$nu_matches] (where $nu_matches=@matches).
> 
> But what you probably really want to be doing is using the push()
> function to append elements to an array. See the entry for push() in
> the perlfunc man page.
> 
I intentionally didn't want to use push. I eventually want to change the
file I'm reading in appending  something to the end of @matches. This
array can be pretty big, and by using push I would have to substitute
the whole old @matches with @matches plus the element I just pushed in.
Instead I  just wanted to find the last element of matches
($last_match)  and substitute it with $last_match . $tackedon_stuff. But
maybe I'm wrong about this too (I'm wrong a lot these days).
> -- 
> Andrew Langmead


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

Date: 29 Nov 1997 11:42:38 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: webadmin <webadmin@prestel.net>
Subject: Re: LWP, and HTTP_REFERER
Message-Id: <8cwwhr8rtt.fsf@gadget.cscaper.com>

>>>>> "webadmin" == webadmin  <webadmin@prestel.net> writes:

webadmin> I am trying to use LWP module to grab a html page, but the
webadmin> problem is that I think they test where the query comes
webadmin> from, because I have built the identical copy, on my server,
webadmin> but it throws up a standard error.

webadmin> Is there anyway i can send through some environment
webadmin> variables such as HTTP_REFERER

Well, forgetting for a moment that this question probably should
have been asked in the web groups instead of here...

Stolen partially from "man lwpcook"...

    use LWP::UserAgent;
    my $ua = new LWP::UserAgent;
    $ua->agent("Mozilla/5.0 Sony Playstation"); # scare them :-)
    my $req = new HTTP::Request 'GET' => "http://www.stonehenge.com/";
    $req->referer("http://www.perl.com/you_can_put/anything_you_want/right_here");
    my $res = $ua->request($req);
    if ($res->is_success) {
      print $res->content;
    } else {
      print "Error: " . $res->code . " " . $res->message;
    }

Similarly, if you need to "POST" to get to some page, it's just a slight
modification of the above.

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 275 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
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@ora.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: Sat, 29 Nov 1997 12:52:04 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: posting to a newsgroup
Message-Id: <-2911971252050001@aggie.coaps.fsu.edu>

In article <3480BE8F.76A4@usa.net>, ctt@usa.net wrote:

+ anybody know how to post message to a newsgroup using perl scripts?

Yes. Take a look at the News::NNTPClient module.

James

-- 
Consulting Minister for Consultants, DNRC
Support the anti-Spam amendment <url:http://www.cauce.org/>
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/perl/faq/idiots-guide.html>


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

Date: 29 Nov 1997 10:29:55 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: posting to a newsgroup
Message-Id: <m37m9r1rks.fsf@windlord.Stanford.EDU>

I R A Aggie <fl_aggie@thepentagon.com> writes:
> ctt@usa.net wrote:

>> anybody know how to post message to a newsgroup using perl scripts?

> Yes. Take a look at the News::NNTPClient module.

I generally prefer using Net::NNTP, if for no other reason than libnet is
commonly installed at most reasonably well-maintained Perl installations.
It also uses the common syntax of the other Net::* modules, while I
believe News::NNTPClient rolls its own.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Sat, 29 Nov 1997 10:47:36 -0800
From: "Xah" <xah@best.com>
Subject: Q: alternative to Perl?
Message-Id: <65pnoi$6vu$1@nntp2.ba.best.com>

Are there alternative languages comparable to Perl with respect to text
manipulation?

I'm wondering because I'm not too thrilled by Perl's grammar, but need
Perl's text manipulation power.

Thanks.

 Xah, xah@best.com
 http://www.best.com/~xah/SpecialPlaneCurves_dir/specialPlaneCurves.html
 Mountain View, CA, USA


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

Date: Sat, 29 Nov 1997 14:55:41 GMT
From: epic@aros.net (Amy Williams)
Subject: Re: Q: Learning perl with no progr. experience
Message-Id: <34802bef.1190116@news.aros.net>

On Sat, 29 Nov 1997 12:31:24 +0100, av3@xs4all.nl wrote:
>Hi,
>
>i wanna start learning perl. The thing is: i have no programming
>experience whatsoever (yeah, writing print "" statements). I'm looking
>for a place on the web to start, and if non excistent, a book.

Learning to program with little or no experience is difficult, but I
think there might be a book or two out there that do actually live up
to their words.  Llama (Learning Perl by Randal L. Schwartz & Tom
Christiansen from O'Reilly & Associates) is a fairly simple book but
does not really cover CGI scripting.  I haven't read Matt's book, but
other's might have and they can give you a recommendation...

--
Amy Williams
epic@aros.net
http://www.aros.net/~epic/
Finger for PGP public key.


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

Date: Sat, 29 Nov 1997 16:10:50 GMT
From: Cindy Wong <ckpwong@undergrad.math.uwaterloo.ca>
To: av3@xs4all.nl
Subject: Re: Q: Learning perl with no progr. experience
Message-Id: <Pine.SUN.3.95q.971129105815.17988C-100000@napier.uwaterloo.ca>

> i wanna start learning perl. The thing is: i have no programming
> experience whatsoever (yeah, writing print "" statements). I'm looking
> for a place on the web to start, and if non excistent, a book.

If you learn better by reading printed materials like I am, and would like
to read a book that has the fewest mistakes (if any), I would say you
should go ahead with "Learning Perl", 2nd ed., by Randal Schwartz and Tom
Christiansen, O'Reilly & Associates, Inc. (aka the blue llama book).
Another good book for people who are more comfortable with programming and
serve as a reference for most if not all perl programmers is "Programming
Perl", 2nd ed., by Larry Wall, Randal Schwartz and Tom Christiansen, also
from O'Reilly.  (Can any one correct me wit the authors please?  I left
the book in my office.)  This one is often referred to as the blue camel
book.  If you use perl on NT/95, get "Learning Perl on Win32 Systems", aka
the gecko book.

Speaking of books, does anyone know what's the "Advanced Perl Programming"
book called?  leopard? ;)

Cindy
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS/IT/M/O dx s-:- a--- C+++>$ U++>++++$ P+++>++++$ L++>++++ 
E>++ W++ N++ o? K? w-->--- O? M V? PS PE+ Y+ PGP?>++ !t !5 X 
R+ tv b++ DI++++ !D G>+++ e+>++ h! r++ x? 
------END GEEK CODE BLOCK------




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

Date: Sat, 29 Nov 1997 12:51:00 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Q: Learning perl with no progr. experience
Message-Id: <-2911971251010001@aggie.coaps.fsu.edu>

In article
<Pine.SUN.3.95q.971129105815.17988C-100000@napier.uwaterloo.ca>, Cindy
Wong <ckpwong@undergrad.math.uwaterloo.ca> wrote:

+ Speaking of books, does anyone know what's the "Advanced Perl Programming"
+ book called?  leopard? ;)

Yes. I suppose it could be called the 'black and blue leopard'... :)

James

-- 
Consulting Minister for Consultants, DNRC
Support the anti-Spam amendment <url:http://www.cauce.org/>
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/perl/faq/idiots-guide.html>


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

Date: 29 Nov 1997 11:28:24 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: epic@aros.net (Amy Williams)
Subject: Re: Q: Learning perl with no progr. experience
Message-Id: <8c1zzza71z.fsf@gadget.cscaper.com>

>>>>> "Amy" == Amy Williams <epic@aros.net> writes:

Amy> On Sat, 29 Nov 1997 12:31:24 +0100, av3@xs4all.nl wrote:
>> i wanna start learning perl. The thing is: i have no programming
>> experience whatsoever (yeah, writing print "" statements). I'm looking
>> for a place on the web to start, and if non excistent, a book.

Amy> Learning to program with little or no experience is difficult, but I
Amy> think there might be a book or two out there that do actually live up
Amy> to their words.  Llama (Learning Perl by Randal L. Schwartz & Tom
Amy> Christiansen from O'Reilly & Associates)

While I'd love for everyone in the world to have three copies of my
Llama book (one at home, one at the office/school, and one to carry
with them), I really didn't write the book with non-programmers in
mind.  So there's quite a few things that I say "this is like an array
in other languages" without explaining the why and how of manipulating
an array... just how to do it in Perl.

Unfortunately, I have yet to read a "from zero programming to workable
Perl knowledge" book that I'd recommend.  Most of the books that
dummies can read are books that only dummies would want to read. :-)

Amy>  is a fairly simple book but
Amy> does not really cover CGI scripting.

Well, it wasn't meant to cover CGI scripting.  It was meant to be a
basic tutorial for Perl, and most of Perl usage is *not* about the web
(since Perl has been around for 10/4's as long as the web :-).

However, you'll find the blue llama includes a brief chapter on using
CGI.pm, but mostly enough for you to want to learn more. :-)

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 275 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
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@ora.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: Sat, 29 Nov 1997 17:58:25 GMT
From: patrickq@hotmail.com (Patrick)
Subject: Re: read from end of file (by line)
Message-Id: <348355ee.1035926930@news.autobahn.mb.ca>


>On 25 Nov 1997, Scott Anthony Hamilton wrote:
>
>> I'm in the process of writing a small module for reading from
>> the end of the file line by line to the beginning. Much like
>> $scalar = <FH> but in reverse.
>> 
>> Before I go on, is there a perl trick which can accomplish this
>> task with ease?

vi trick:

:g/^/m0

reverses the file


Patrick
__________


"It's better to have loved and lost than to never have seen Lost in Space"  
    -- Kelly Bundy quoting Chinese philosopher Unconcious


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

Date: Sat, 29 Nov 1997 16:26:40 GMT
From: Guy Doucet <gdoucet@ait.acl.ca>
Subject: READING the last few lines of a HUGE FILE.
Message-Id: <348041EF.5823A063@ait.acl.ca>

This is how I normally read a file:

   open(FILE,"$basedir/a_data.dat") || &err_nodat;
   @file = <FILE>;
   close(FILE);

But what if I want to read only the last few lines of an enourmously
large log file. I'm talking a few MBytes or maybe 10MBytes. I don't want
to write to it, only read it. The lines in the file are all different
lengths.

There must be a better way than to read a few MBytes of info into a
variable.

Thanks for all info, Guy Doucet




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

Date: 29 Nov 1997 17:50:04 GMT
From: "Eric D. Friedman" <friedman@uci.edu>
Subject: Re: READING the last few lines of a HUGE FILE.
Message-Id: <65pkkc$6rj@news.service.uci.edu>

[mailed, posted]

In article <348041EF.5823A063@ait.acl.ca>,
Guy Doucet  <gdoucet@ait.acl.ca> wrote:
<This is how I normally read a file:
<
<   open(FILE,"$basedir/a_data.dat") || &err_nodat;
<   @file = <FILE>;
<   close(FILE);
<
<But what if I want to read only the last few lines of an enourmously
<large log file. I'm talking a few MBytes or maybe 10MBytes. I don't want
<to write to it, only read it. The lines in the file are all different
<lengths.

Two options:

1) use seek() to put the file cursor at the desired position and read from
there. (but see below)

2) do some pattern matching on each line to eliminate early entries.

Assuming logs like this:

1997:10:08:more fields

my $last;
while (<FILE>)
{
  if (/^1997:11/) # first November entry
  {
    $last = $_; # keep the first november entry
    last; # break out of the while loop
  }
}

my @file = $last, <FILE>; # slurp the rest of the file

#2 will slow to a crawl if you can't anchor your patterns.
Option #1 is going to be more efficient, but it's harder to do when
records (lines) are of different lengths.  Option #2 is therefore
more efficient in terms of programmer time, ;-)



<
<There must be a better way than to read a few MBytes of info into a
<variable.
<
<Thanks for all info, Guy Doucet
<
<


-- 
Eric D. Friedman
friedman@uci.edu


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

Date: Sat, 29 Nov 1997 17:59:53 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: READING the last few lines of a HUGE FILE.
Message-Id: <EKF5zt.DBK@world.std.com>

Guy Doucet <gdoucet@ait.acl.ca> writes:

>This is how I normally read a file:

>   open(FILE,"$basedir/a_data.dat") || &err_nodat;
>   @file = <FILE>;
>   close(FILE);

>But what if I want to read only the last few lines of an enourmously
>large log file. I'm talking a few MBytes or maybe 10MBytes. I don't want
>to write to it, only read it. The lines in the file are all different
>lengths.

>There must be a better way than to read a few MBytes of info into a
>variable.

Well, if you are only going to use the last few lines, you might be
better off saying:

use constant MAXLINES => 5;

   open(FILE,"$basedir/a_data.dat") || &err_nodat;
   while(<FILE>) {
     # do something with the line in $_, something like:
     push @lines, $_;
     shift @lines if scalar @lines > MAXLINES;
   }
   close(FILE);

Why store all of the lines in @file if you aren't going to use them.

Also, you could seek() towards the end of the file. The first line
will very likely not be a complete line, (chances are, you will seek
to the middle of a line) but then you will get complete lines from
there.

Or if you are only reading new information, (like since the last run
of the program) could you store the offset (in another file) of the
last line of the log file from the last run?
-- 
Andrew Langmead


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

Date: 29 Nov 1997 11:02:46 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: Resource Kit Anomaly
Message-Id: <65peb6$l4g@panix.com>

In <34801903.48387327@news.magibox.net> pschon@baste.magibox.net (Peter J. Schoenster) writes:

>Is this resource kit worth buying?  I saw it for $112.00 at some
>discount computer store online.

I think so. :)

>Why do they not tell us what is in the book(s)?  

Did you look at: http://perl.oreilly.com/prk_index.html

Lots and lots of examples of programming with Perl modules:

          Programming with Perl Modules, by Nate
          Patwardhan with Clay Irving. A tutorial
          introduction to programming with the
          most important Perl extension modules. 

Most of the pod included with the modules (more than 600 modules):

          Perl Module Reference (two volumes),
          compiled and edited by Ellen Siever and
          David Futato. A comprehensive reference
          of significant Perl modules. 

A description of the software tools included in the kit:

          Perl Utilities Guide, by Brian Jepson.
          Documentation for the professional Perl
          programming utilities contained in the
          Resource Kit. 

>I wonder if O'Reilly has the source code on their website?  

Which source code? The CD-ROM contains:

  - A snapshot of the freeware Perl archives on Comprehensive Perl
    Archive Network (CPAN), with an Install program
  - A Search tool, and a web-aware interface for identifying
    more recent online CPAN tools. 

>But I would love to hear what modules etc. are discussed in the book

Alot.

>and what is this thing about the Java/Perl that Larry Wall wrote.

          A Java/Perl interface, written for the Kit by Larry Wall,
          creator of Perl. This new Java/Perl tool allows programmers 
          to write Java classes with Perl implementations. 
          Now Perl programmers can exploit Java's wide availability, 
          while using Perl for the things that it does better than Java 
          (such as string processing). 

Does this answer your questions?

-- 
Clay Irving <clay@panix.com>                   http://www.panix.com/~clay/


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

Date: Sat, 29 Nov 1997 17:19:00 GMT
From: jzawodn@wcnet.org (Jeremy D. Zawodny)
Subject: Re: Resource Kit Anomaly
Message-Id: <34804e0b.666786788@woody.wcnet.org>

[original author automagically cc'd via e-mail]

On Sat, 29 Nov 1997 13:34:16 GMT, pschon@baste.magibox.net (Peter J.
Schoenster) wrote:

>Ijust got an offer in the mail
>that if I buy 10 books... come one who are they kidding?  I will not
>buy 10 O'Reilly books in the next year, no way!  I think that they
>have some new marketing people and I don't like what i feel.

Heh.

I just got that book offer too.

I was tempted to call and say, "Hey. How about if I send you the back
cover of any 10 of my EXISTING O'Reilly books, and you send me the
free one?"

I already own 14 of their books. Not to mention that I went to the
Perl conference.

c'mon guys.

Jeremy
-- 
Jeremy D. Zawodny                 jzawodn@wcnet.org
Web Server Administrator          www@wcnet.org
Wood County Free Net (Ohio)       http://www.wcnet.org/


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

Date: 29 Nov 1997 10:33:18 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Resource Kit Anomaly
Message-Id: <m34t4v1rf5.fsf@windlord.Stanford.EDU>

Jeremy D Zawodny <jzawodn@wcnet.org> writes:

> I was tempted to call and say, "Hey. How about if I send you the back
> cover of any 10 of my EXISTING O'Reilly books, and you send me the free
> one?"

> I already own 14 of their books. Not to mention that I went to the Perl
> conference.

> c'mon guys.

If you went to the Perl conference, they already *gave* you a free book,
so why complain?  :)  Personally, like most of you, I already own a lot of
O'Reilly books, but I won't rule out wanting to buy 10 more over the next
year.  They're good.

This is a really standard sort of offer; I'm not sure why people are
complaining.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Sat, 29 Nov 1997 15:17:38 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: truncating a string
Message-Id: <34802ff7.11419127@news.tornado.be>

Bill Eberle <wile@inficad.com> wrote:

>I have a problem with limiting the size of a string variable.  I want to 
>take the first ten characters and delete the rest.  Does anyone know an 
>easy way to do this, short of reading the first ten characters into an 
>array?  Thanks.

	$truncated = substr($string, 0, 10 );
or
	$truncated = unpack("A10",$string);

As an added bonus, the latter will also remove trailing spaces. If you
don't want that (huh?), use this instead:

	$truncated = unpack("a10",$string);

HTH,
Bart.


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

Date: 29 Nov 1997 10:53:47 -0500
From: Matthew Rice <Matthew.Rice@ftlsol.com>
Subject: Re: truncating a string
Message-Id: <m3wwhr66ic.fsf@hudson.ftlsol.com>

Tom <beans@bedford.net> writes:

> "Ronald G\"oggel" <r.goeggel@atos-group.de> writes: > 
> > Bill Eberle wrote <65i7t1$8c0$1@news.inficad.com>...
> > >I have a problem with limiting the size of a string variable.  I want to
> > >take the first ten characters and delete the rest.  Does anyone know an
> > >easy way to do this, short of reading the first ten characters into an
> > >array?  Thanks.
> > >
>  
> How about:
> 
> $myvar =~ s/(.{0,10}).*/$1/;

or
$myvar = substr($myvar, 0, 10);

-- 
Matthew Rice                             e-mail: matthew.rice@ftlsol.com


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

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

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