[25200] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7446 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 25 11:05:44 2004

Date: Thu, 25 Nov 2004 08:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 25 Nov 2004     Volume: 10 Number: 7446

Today's topics:
        (Perl) FILE/IO and grep causes 100% CPU mark@gowans.org
    Re: (Perl) FILE/IO and grep causes 100% CPU (Anno Siegel)
    Re: CGI.PM not setting HTTP header <amead@comcast.net>
        escape whitespace in qw/ / (chris)
        FAQ 3.17: How can I make my Perl program take less memo <comdog@panix.com>
    Re: for Richard Gration <richard@zync.co.uk>
    Re: Help: separate difference length of spaces between  <karlUNDERSCOREkramsch@yahooPERIODcom.invalid>
        Is assigning to $#ar most efficient? <dzluk8fsxsw0001@sneakemail.com>
    Re: Is assigning to $#ar most efficient? <toreau@gmail.com>
    Re: Is assigning to $#ar most efficient? <rev_1318@hotmail.com>
    Re: Need some problemsolving-cgi/xml <gnari@simnet.is>
    Re: Newbie with stat(_) problem (Ian Pellew)
    Re: no acceptable C compiler (Marcus)
    Re: no acceptable C compiler burlo_sumproot@yahoo.se
        perl/c++ calculation (Cab Colino)
    Re: perl/c++ calculation <do-not-use@invalid.net>
        Reading last N lines from large file <ccn@panix.com>
    Re: Reading last N lines from large file (Peter Corlett)
    Re: Reading last N lines from large file <toreau@gmail.com>
        source filters at runtime <fxn@hashref.com>
    Re: source filters at runtime <fxn@hashref.com>
        What is 1; (Ian Pellew)
    Re: What is 1; <amead@comcast.net>
    Re: What is 1; <do-not-use@invalid.net>
    Re: What is 1; <josef.moellers@fujitsu-siemens.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 25 Nov 2004 03:27:31 -0800
From: mark@gowans.org
Subject: (Perl) FILE/IO and grep causes 100% CPU
Message-Id: <1101382051.588878.7620@f14g2000cwb.googlegroups.com>

Hi There..

I've a perl script which amongst other things searches for text strings
in a large number of files. The problem I've got is, while the script
is running - idle cpu% drops to 0. (A mix of user and kernel usage).
The code is:

#!/usr/bin/perl
use strict;
my @files = `ls -lart /app/EV4/data/db/u* | awk '{print \$NF}'`;
foreach my $file (@files) {
chomp ($file);
(my $date) = $file =~ m/.*\.(.*)/;
my @result = `grep anicol $file`;
}


@files contains around 7800 entries. I've tried using alternatives to
grep (by opening each file and using pattern matching) but to no avail.


Sticking a 'sleep 1' in the foreach solves the problem.. but I dont
really want to wait 2 hours for the script to run.

Can anyone suggest a better way of doing the above or am I asking the
impossible?

Many thanks in advance - much appreciated,

Cheers,

Mark



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

Date: 25 Nov 2004 13:51:59 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: (Perl) FILE/IO and grep causes 100% CPU
Message-Id: <co4o1v$5ae$1@mamenchi.zrz.TU-Berlin.DE>

 <mark@gowans.org> wrote in comp.lang.perl.misc:
> Hi There..
> 
> I've a perl script which amongst other things searches for text strings
> in a large number of files. The problem I've got is, while the script
> is running - idle cpu% drops to 0. (A mix of user and kernel usage).

What's wrong with that?  It's a busy program, you want to give it
all the CPU it can get.  If that's a problem, read "man nice".  But
that's Unix, not Perl.

> The code is:
> 
> #!/usr/bin/perl
> use strict;
> my @files = `ls -lart /app/EV4/data/db/u* | awk '{print \$NF}'`;

Why do you "ls -l" and then use awk to get the file name?

> foreach my $file (@files) {
> chomp ($file);
> (my $date) = $file =~ m/.*\.(.*)/;
> my @result = `grep anicol $file`;
> }

That's a shell script, shoehorned into a Perl wrapper.

Here is one way to get the files from Perl directly (untested):

    my $d;
    opendir $d, $_ or die "Can't open $_: $!" for '/app/EV4/data/db/';
    while ( $_ = readdir $d ) {
        next unless /^u/;
        my ( $date) = m/.*\.(.*)/;
        # now open the file in $_ and use Perl's grep() to extract
        # the lines
    }

The above is just a partial re-write of your script in Perl.  It
won't be lighter on the CPU, and there is no general reason why it
should.

Anno


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

Date: Thu, 25 Nov 2004 09:26:43 -0600
From: Alan Mead <amead@comcast.net>
Subject: Re: CGI.PM not setting HTTP header
Message-Id: <pan.2004.11.25.15.26.41.796085@comcast.net>

On Wed, 24 Nov 2004 21:12:45 -0800, Mark wrote:

> My Perl CGI script is producing valid HTML (as far as I can tell,)
> but the server is returning a MIME type of 'text/plain'. I have tried
> using the CGI.PM module to set the MIME type in the header,
> but this merely adds a _second_ header to the output stream,
> and this second header ends up displaying as text in the browser
> window! The actual HTTp header is unaffected, still returning the
> 'text/plain' MIME type.

Well, here's a stupid question:  Is the very first thing you print the
CGI.pm function "header"?  If you have a complicated script, you can test
this by printing header near the top.

I've had weird results using IE (and less often Netscape) to browse the
results of web applications.  The browser would think it's an XML
document and then complain that it's broken.  I don't recall what went
wrong, but it was always a bug in my script that I was able to find.

Or if you're saying that even the most basic CGI script always gets
returned as plain text then I guess you're having an apache/iis/whatever
issue, not a Perl issue.

-Alan 


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

Date: 25 Nov 2004 07:41:43 -0800
From: nadsinoz@hotmail.com (chris)
Subject: escape whitespace in qw/ /
Message-Id: <b8996f29.0411250741.66020368@posting.google.com>

I have a whitespace separated list where some of the fields actually
should have a extra whitespace character.  Is there a way I can escape
this space so I can use qw// to create the list:

@list = qw/ 1.0 UK  Y 2.5 /;

where UK is actually 'UK ' (without the quotes).

Is this possible?

Thanks in advance...


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

Date: Thu, 25 Nov 2004 11:03:04 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 3.17: How can I make my Perl program take less memory?
Message-Id: <co4e57$bvu$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

3.17: How can I make my Perl program take less memory?

    When it comes to time-space tradeoffs, Perl nearly always prefers to
    throw memory at a problem. Scalars in Perl use more memory than strings
    in C, arrays take more than that, and hashes use even more. While
    there's still a lot to be done, recent releases have been addressing
    these issues. For example, as of 5.004, duplicate hash keys are shared
    amongst all hashes using them, so require no reallocation.

    In some cases, using substr() or vec() to simulate arrays can be highly
    beneficial. For example, an array of a thousand booleans will take at
    least 20,000 bytes of space, but it can be turned into one 125-byte bit
    vector--a considerable memory savings. The standard Tie::SubstrHash
    module can also help for certain types of data structure. If you're
    working with specialist data structures (matrices, for instance) modules
    that implement these in C may use less memory than equivalent Perl
    modules.

    Another thing to try is learning whether your Perl was compiled with the
    system malloc or with Perl's builtin malloc. Whichever one it is, try
    using the other one and see whether this makes a difference. Information
    about malloc is in the INSTALL file in the source distribution. You can
    find out whether you are using perl's malloc by typing "perl
    -V:usemymalloc".

    Of course, the best way to save memory is to not do anything to waste it
    in the first place. Good programming practices can go a long way toward
    this:

    * Don't slurp!
        Don't read an entire file into memory if you can process it line by
        line. Or more concretely, use a loop like this:

                #
                # Good Idea
                #
                while (<FILE>) {
                   # ...
                }

        instead of this:

                #
                # Bad Idea
                #
                @data = <FILE>;
                foreach (@data) {
                    # ...
                }

        When the files you're processing are small, it doesn't much matter
        which way you do it, but it makes a huge difference when they start
        getting larger.

    * Use map and grep selectively
        Remember that both map and grep expect a LIST argument, so doing
        this:

                @wanted = grep {/pattern/} <FILE>;

        will cause the entire file to be slurped. For large files, it's
        better to loop:

                while (<FILE>) {
                        push(@wanted, $_) if /pattern/;
                }

    * Avoid unnecessary quotes and stringification
        Don't quote large strings unless absolutely necessary:

                my $copy = "$large_string";

        makes 2 copies of $large_string (one for $copy and another for the
        quotes), whereas

                my $copy = $large_string;

        only makes one copy.

        Ditto for stringifying large arrays:

                {
                        local $, = "\n";
                        print @big_array;
                }

        is much more memory-efficient than either

                print join "\n", @big_array;

        or

                {
                        local $" = "\n";
                        print "@big_array";
                }

    * Pass by reference
        Pass arrays and hashes by reference, not by value. For one thing,
        it's the only way to pass multiple lists or hashes (or both) in a
        single call/return. It also avoids creating a copy of all the
        contents. This requires some judgment, however, because any changes
        will be propagated back to the original data. If you really want to
        mangle (er, modify) a copy, you'll have to sacrifice the memory
        needed to make one.

    * Tie large variables to disk.
        For "big" data stores (i.e. ones that exceed available memory)
        consider using one of the DB modules to store it on disk instead of
        in RAM. This will incur a penalty in access time, but that's
        probably better than causing your hard disk to thrash due to massive
        swapping.



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: Thu, 25 Nov 2004 09:58:45 GMT
From: Richard Gration <richard@zync.co.uk>
Subject: Re: for Richard Gration
Message-Id: <pan.2004.11.25.09.58.14.907905@zync.co.uk>

On Wed, 24 Nov 2004 16:30:35 -0500, daniel kaplan wrote:

> richard,
> 
> wanted to thank you for your solution under the topic "redirect question"

You're welcome, glad it helped.

Rich


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

Date: Thu, 25 Nov 2004 11:33:59 +0000 (UTC)
From: KKramsch <karlUNDERSCOREkramsch@yahooPERIODcom.invalid>
Subject: Re: Help: separate difference length of spaces between words
Message-Id: <co4fv7$cbr$1@reader1.panix.com>

In <VCfpd.1668$VL6.630@clgrps13> "John W. Krahn" <someone@example.com> writes:

>Lei wrote:
>> 
>> I have a file "file.txt"which look like this:
>> 
>> aaaaaaa      11111       XXXX
>> bbbbb         222222        YYYYYY
>> ....
>> 
>> 
>> The number of spaces between words are not fixed.
>> 
>> If I want to get     $D = "first column word"  $E = "second column word"
>> and discard the last word of the row.
>> 
>> Then continue get DATA from the second row.
>> 
>> What will be syntax be?
>> 
>> I am confused on how to use split and pattern in this case. Thanks a lot

>Assuming that the current row is in $_ then:

>my ( $D, $E ) = split;

>Which is short for:

>my ( $D, $E ) = split ' ', $_;

Which is short for:

my ( $D, $E ) = split /\s+/, $_;

Both the forms that John gives are *special cases* of split.
Splitting at whitespace is common enough that it warrants the
special treatment.

Also note that in all cases, the LHS of the assignment captures
only the first two split items, and discards the rest.  If instead
of only three words per line you had 1000, but still only wanted
the first 2, then it may be more efficient to write

my ( $D, $E ) = split ' ', $_, 3;

This would split the line into 3 pieces: the first 2 would be the
desired words, and the last one would the rest of the line (after
the second stretch of whitespace).  In contrast, the forms given
earlier would have split the line into 1000 pieces, of which the
last 998 would have been discarded.

Definitely,

  perldoc -f split

	Karl



-- 
Sent from a spam-bucket account; I check it once in a blue moon.  If
you still want to e-mail me, cut out the extension from my address,
and make the obvious substitutions on what's left.


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

Date: Thu, 25 Nov 2004 12:07:00 +0100
From: "Jonas Nilsson" <dzluk8fsxsw0001@sneakemail.com>
Subject: Is assigning to $#ar most efficient?
Message-Id: <co4ec3$k78$1@news.island.liu.se>

The most efficient way to shorten an array is that to assign to $#ar?
/jN




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

Date: Thu, 25 Nov 2004 14:20:57 +0100
From: Tore Aursand <toreau@gmail.com>
Subject: Re: Is assigning to $#ar most efficient?
Message-Id: <pan.2004.11.25.13.20.55.869923@gmail.com>

On Thu, 25 Nov 2004 12:07:00 +0100, Jonas Nilsson wrote:
> The most efficient way to shorten an array is that to assign to $#ar?

Compared to what?  What does the Benchmark module tell you?


-- 
Tore Aursand <toreau@gmail.com>
"To cease smoking is the easiset thing I ever did. I ought to know,
 I've done it a thousand times." (Mark Twain)


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

Date: Thu, 25 Nov 2004 15:26:16 +0100
From: Polleke <rev_1318@hotmail.com>
Subject: Re: Is assigning to $#ar most efficient?
Message-Id: <co4q2a$256$1@voyager.news.surf.net>

on Thursday 25 November 2004 12:07, Jonas Nilsson wrote:

> The most efficient way to shorten an array is that to assign to $#ar?
> /jN

a small comparison between various options gives:


#!/usr/bin/perl

use strict;
use warnings;
use Benchmark ':all';

cmpthese(10000, {
    '$#'      => sub { my @array = (1..1000); $#array = 9 },
    'assign'  => sub { my @array = (1..1000); @array  = @array[0..9] },
    'undef'   => sub { my @array = (1..1000); @array[10..10000] = (undef) x
990 },
    'delete'  => sub { my @array = (1..1000); delete @array[10..1000] },
    'splice'  => sub { my @array = (1..1000); splice(@array, 0, 10) },
});

__END__

         Rate  undef     $# delete assign splice
undef   732/s     --   -86%   -88%   -90%   -90%
$#     5076/s   594%     --   -18%   -30%   -31%
delete 6211/s   749%    22%     --   -15%   -16%
assign 7299/s   898%    44%    18%     --    -1%
splice 7407/s   913%    46%    19%     1%     --

So it would seem, that splice is the fastest way, closely followed by
assignment...

Paul



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

Date: Thu, 25 Nov 2004 09:05:26 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Need some problemsolving-cgi/xml
Message-Id: <co473q$6no$1@news.simnet.is>

"lievemario" <lievemario@hotmail.com> wrote in message
news:co3tk9$auq$1@snic.vub.ac.be...

[snip]

 you have many apparent problems:
 you are not using strict
 you are useing CGI.pm but still decoding your params yourself.
 you did not try to simplify your problem. do you expect us
   to install all these modules to debug unrelated things ?
 you seem to use a temp file with hardwired location, with no
   locking. also you use relative filepaths

 gnari






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

Date: 25 Nov 2004 07:13:48 -0800
From: ipellew@pipemedia.co.uk (Ian Pellew)
Subject: Re: Newbie with stat(_) problem
Message-Id: <30875970.0411250713.497129fd@posting.google.com>

Hi all;

>Have you read up about arrays in perldata.pod yet? 
Tried un Tried rtfm.

>You don't really need one, you can just use a "list slice"
>   my $mtime = ( stat($tf) )[9];

Well Jim, if I:-
 . . . . . 
$i = (stat($tf))[9];
$j = (stat($sf))[9];
 . . . .  
as you and manpages suggest I get:-
  From stepping through these with the Debugger:-
main::compile(w:773):       if ( -w ($tf =  $s[0])) {
  DB<2>            src          = "n
main::compile(w:780):          my  $i,  $j;
  DB<2>
main::compile(w:785):          $i = (stat($tf))[9];
  DB<2>
main::compile(w:786):          $j = (stat($sf))[9];
  DB<2>
main::compile(w:787):          if (  $j <  $i ) {
  DB<2>
main::compile(w:793):          if (  $make ==  $true ) {
  DB<2> p $i
-1
  DB<3> p $j

  DB<4> p $sf
c:/Program Files/Apache Group/Apache2/cgi-bin/Pages/Page_hdr.htm
  DB<5> p $tf
c:/Program Files/Apache Group/Apache2/cgi-bin/Pages/Generated/ph_10001.cgi
  DB<6> q
Xp ls -l Pages/Generated/ph_10001.cgi Pages/Page_hdr.htm
-rw-r--r--    1 ipellew  None         1038 Nov 19 18:47 Pages/Generated/ph_10001.cgi
-rw-r--r--    1 ipellew  None          863 Nov 22 08:41 Pages/Page_hdr.htm

Code fragment :-
if ( -w ($tf = $s[0])) {
	my $i, $j;
#	$i = stat($tf);
#	$i = @$i[9];	# Mtime
#	$j = stat($sf);
#	$j = @$j[9];
	$i = (stat($tf))[9];
	$j = (stat($sf))[9];
	if ( $j < $i ) {
		print qq(Target is younger than the source, So nothing to do.\n);
		$make = $false;
	}
}

Xp perl -V
Summary of my perl5 (revision 5 version 8 subversion 4) configuration:
  Platform:osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread

Regards
Ian


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

Date: 25 Nov 2004 02:16:01 -0800
From: mygooglegroupsaccount@yahoo.com (Marcus)
Subject: Re: no acceptable C compiler
Message-Id: <6fc26ca7.0411250216.1e7c436c@posting.google.com>

Im running a Unix server

Tony Curtis <tony_curtis32@yahoo.com> wrote in message news:<87653udbag.fsf@limey.hpcc.uh.edu>...
> >> On 24 Nov 2004 16:24:33 -0800,
> >> mygooglegroupsaccount@yahoo.com (Marcus) said:
>  
> > hi when trying to install image::magick perl module I get
> > the following:
>  
> > error: no acceptable C compiler found in $PATH
>  
> > what c compiler should I install on my server? is there a
> > module?
> 
> You need to ask this question in a group related to your OS.


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

Date: Thu, 25 Nov 2004 10:48:33 GMT
From: burlo_sumproot@yahoo.se
Subject: Re: no acceptable C compiler
Message-Id: <uact6yzjp.fsf@notvalid.se>

mygooglegroupsaccount@yahoo.com (Marcus) writes:

Please dont top post. (text moved below where it belongs)

> Tony Curtis <tony_curtis32@yahoo.com> wrote in message news:<87653udbag.fsf@limey.hpcc.uh.edu>...
> > >> On 24 Nov 2004 16:24:33 -0800,
> > >> mygooglegroupsaccount@yahoo.com (Marcus) said:
> >  
> > > hi when trying to install image::magick perl module I get
> > > the following:
> >  
> > > error: no acceptable C compiler found in $PATH
> >  
> > > what c compiler should I install on my server? is there a
> > > module?
> > 
> > You need to ask this question in a group related to your OS.
>
> Im running a Unix server


Assuming "Unix server" means Solaris go to http://www.sunfreeware.com/ and install gcc.

If not follow Tonys advice.




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

Date: 25 Nov 2004 05:28:49 -0800
From: fidel@mongobaer.de (Cab Colino)
Subject: perl/c++ calculation
Message-Id: <4d9da5e7.0411250528.947f231@posting.google.com>

hi,

i try to implement a calculation that i got in c++
in my perl project.


example:

c++:
unsigned char byte[] = "a";
int crc32 = 0xFFFFFFFF;
crc32 = ((crc32) >> 8) ^ array[(chr[0]) ^ ((crc32) & 0x000000FF)];

crc32 = -397917764

perl:
$crc32 = 0xFFFFFFFF;
$byte = "a";
$byte = unpack("C",$byte);
$crc32 = (($crc32) >> 8) ^ $array[($byte) ^ (($crc32) & 0x000000FF)];

$crc32 = 390611388


if you can see, the problem is that i get different results in the two
callclations. any suggestions why?

i would be graceful for any suggest.

cya

cab


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

Date: 25 Nov 2004 14:53:14 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: perl/c++ calculation
Message-Id: <yzdmzx66nn9.fsf@invalid.net>


fidel@mongobaer.de (Cab Colino) writes:
> i try to implement a calculation that i got in c++
> in my perl project.
> 
> 
> example:
> 
> c++:
> unsigned char byte[] = "a";
> int crc32 = 0xFFFFFFFF;
> crc32 = ((crc32) >> 8) ^ array[(chr[0]) ^ ((crc32) & 0x000000FF)];
> 
> crc32 = -397917764
> 
> perl:
> $crc32 = 0xFFFFFFFF;
> $byte = "a";
> $byte = unpack("C",$byte);
> $crc32 = (($crc32) >> 8) ^ $array[($byte) ^ (($crc32) & 0x000000FF)];
> 
> $crc32 = 390611388
> 
> 
> if you can see, the problem is that i get different results in the two
> callclations. any suggestions why?
> 
> i would be graceful for any suggest.

I think you want to use 'byte' in the C++ code, and not 'chr[0]'. It's
a good habit to only paste code that you actually ran. And the
contents of the two arrays could be interesting too. But the problem
is probably this:

        % perl -e 'printf("%d\n", 0xFFFFFFFF >> 8)'
        16777215

0xffffffff >> 8 in C++, on the other hand, is sign extended, and remains
0xffffffff.


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

Date: Thu, 25 Nov 2004 14:51:19 +0000 (UTC)
From: Chris Nestrud <ccn@panix.com>
Subject: Reading last N lines from large file
Message-Id: <co4rh7$f4g$1@reader1.panix.com>

I need to read a number of lines from the end of a large file. For
example, the file may have 460484 lines and I need the last 500.

The "tail -500 file" command from the shell works, but I'd like a solution
that doesn't involve calling an external program.

Reading the file and keeping an array with the last 500 lines seen
works, but takes a very long time on large files.

I've looked at the seek function, but other than guessing at how far
from EOF to seek backward, I can't figure out how to make sure that I'm
left with enough data to account for the needed number of lines.

Any suggestions or other approaches would be much appreciated.
-- 
Chris Nestrud
Email: ccn@panix.com
http://www.panix.com/~ccn/


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

Date: 25 Nov 2004 14:55:48 GMT
From: abuse@dopiaza.cabal.org.uk (Peter Corlett)
Subject: Re: Reading last N lines from large file
Message-Id: <41a5f274$0$220$5a6aecb4@news.aaisp.net.uk>

Chris Nestrud <ccn@panix.com> wrote:
[...]
> I've looked at the seek function, but other than guessing at how far
> from EOF to seek backward, I can't figure out how to make sure that
> I'm left with enough data to account for the needed number of lines.

I suspect tail merely guesses a seek position, then reads to find out
if it was right, retrying until it gets enough data.


-- 
PGP key ID E85DC776 - finger abuse@mooli.org.uk for full key


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

Date: Thu, 25 Nov 2004 17:01:49 +0100
From: Tore Aursand <toreau@gmail.com>
Subject: Re: Reading last N lines from large file
Message-Id: <pan.2004.11.25.16.01.49.698904@gmail.com>

On Thu, 25 Nov 2004 14:51:19 +0000, Chris Nestrud wrote:
> I need to read a number of lines from the end of a large file. For
> example, the file may have 460484 lines and I need the last 500.

Take a look at the 'File::ReadBackwards' module;

  <http://search.cpan.org/~uri/File-ReadBackwards-1.02/>


-- 
Tore Aursand <toreau@gmail.com>
"A teacher is never a giver of truth - he is a guide, a pointer to the
 truth that each student must find for himself. A good teacher is
 merely a catalyst." (Bruce Lee)


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

Date: 25 Nov 2004 01:31:58 -0800
From: "Xavier Noria" <fxn@hashref.com>
Subject: source filters at runtime
Message-Id: <1101375118.196665.155680@c13g2000cwb.googlegroups.com>

Looks like source filters do not filter at runtime:

In this example the second pass is not seen by perl:

% perl -wle 'pass;
use Acme::Pythonic;
pass
'
Unquoted string "pass" may clash with future reserved word at -e line
1.
Useless use of a constant in void context at -e line 1.

but in this one it is not filtered out:

% perl -wle 'pass;
quote> require Acme::Pythonic;
quote> pass
quote> '
Unquoted string "pass" may clash with future reserved word at -e line
1.
Unquoted string "pass" may clash with future reserved word at -e line
4.
Useless use of a constant in void context at -e line 1.
Useless use of a constant in void context at -e line 3.

Since perlfilter says "require" opens a source stream as well as "use"
and also "A source filter is a special kind of Perl module that
intercepts and modifies a source stream before it reaches the parser."
I guessed source filters would filter if they were required (not that
perlfilter says it). But the experiments prove me wrong.

I imagine that since the compilation was already done nothing remains
to be parsed, but I don't know perl internals so I would like to
confirm the reason that's that way.
Why source filters don't filter with require or eval STRING?

-- fxn



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

Date: 25 Nov 2004 02:47:45 -0800
From: "Xavier Noria" <fxn@hashref.com>
Subject: Re: source filters at runtime
Message-Id: <1101379665.260205.244240@f14g2000cwb.googlegroups.com>

I realize that trial with "pass" could not be relevant because the
warning could be being issued at compile time. Anyway, this might a
simpler example of a filter that does not work if required:

% cat Foo.pm
package Foo;
use Filter::Simple sub { s/foo/bar/ };
1;
% perl -wle '
quote> use Foo;
quote> print "foo"
quote> '
bar
% perl -wle '
require Foo;
print "foo"
'
foo

-- fxn



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

Date: 25 Nov 2004 07:14:51 -0800
From: ipellew@pipemedia.co.uk (Ian Pellew)
Subject: What is 1;
Message-Id: <30875970.0411250714.30fb8502@posting.google.com>

Hi all;

What does the 
1;
line of a perl script do?

Regards
Ian


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

Date: Thu, 25 Nov 2004 09:29:45 -0600
From: Alan Mead <amead@comcast.net>
Subject: Re: What is 1;
Message-Id: <pan.2004.11.25.15.29.45.551235@comcast.net>

On Thu, 25 Nov 2004 07:14:51 -0800, Ian Pellew wrote:

> What does the 
> 1;
> line of a perl script do?

Returns 1 which is a true value.  It's the standard way of ending a
module.  Try '0' or '' or undef... see what you get.

-Alan


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

Date: 25 Nov 2004 16:30:10 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: What is 1;
Message-Id: <yzdis7u6j5p.fsf@invalid.net>


ipellew@pipemedia.co.uk (Ian Pellew) writes:
> 
> What does the 
> 1;
> line of a perl script do?

See perldoc -f require:

"Note that the file will not be included twice under the same specified
name.  The file must return TRUE as the last statement to indicate
successful execution of any initialization code, so it's customary to
end such a file with "C<1;>" unless you're sure it'll return TRUE
otherwise."


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

Date: Thu, 25 Nov 2004 17:03:02 +0100
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: What is 1;
Message-Id: <co4ves$a76$1@nntp.fujitsu-siemens.com>

Ian Pellew wrote:
> Hi all;
>=20
> What does the=20
> 1;
> line of a perl script do?

It signals successfull initialization of this script to the use-ing or=20
require-ing module/program.

--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett



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

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


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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

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

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


------------------------------
End of Perl-Users Digest V10 Issue 7446
***************************************


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