[19277] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1472 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 9 06:05:35 2001

Date: Thu, 9 Aug 2001 03:05:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <997351514-v10-i1472@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 9 Aug 2001     Volume: 10 Number: 1472

Today's topics:
        2-Dimensional array math (Moran Goldstein)
    Re: 2-Dimensional array math <james@zephyr.org.uk>
    Re: 2-Dimensional array math (Chris Fedde)
    Re: 2-Dimensional array math (Martien Verbruggen)
    Re: Command line parameters under mod_perl <tom.melly@ccl.com>
    Re: Easy array question ? <pne-news-20010809@newton.digitalspace.net>
        export from dbf to csv/text format (derelixir)
        FAQ: How do I print out or copy a recursive data struct <faq@denver.pm.org>
    Re: getting the name of a sub from a sub ref (Anno Siegel)
        help with hash <ryan@bong.net>
    Re: help with hash (E.Chang)
    Re: help with hash <bcaligari@fireforged.com>
    Re: help with hash <Tassilo.Parseval@post.rwth-aachen.de>
        how to get perlscript  <lbell@essex.ac.uk>
    Re: IF $FileArray[$index] CONTAINS..... <paul@net366.com>
        Limit the number of child process <cosmos@NOSPAMnetvillageasia.com>
    Re: Line counting in a file (Anno Siegel)
    Re: Line counting in a file (Yves Orton)
    Re: Line counting in a file (Yves Orton)
    Re: Perl editor for win32 needed (Yves Orton)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 8 Aug 2001 22:28:53 -0700
From: moran-gy@actcom.co.il (Moran Goldstein)
Subject: 2-Dimensional array math
Message-Id: <223f9ce4.0108082128.47d33580@posting.google.com>

Hi,
I'm working on an script that adds the values of one 2D array to the
values of another 2D array, at a specific location. It's essentially
basic matrix math. The main problem I'm having is code efficiency,
since the way I do it now takes eons, and for whatever reason,
sometimes crashes mid-way...

To illustrate, say the base matrix is:

0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
1 1 1 1 1


And the overlay matrix is:

1 2 1
2 3 2
1 2 1


And I need to add the second matrix to the first one at X3/Y2, the
outcome would be:

0 0 0 0 0
0 0 1 2 1
0 0 2 3 2
1 1 2 3 2


Usually, the base array is around 500x500, and the overlayed arrays
(there can be several different arrays implemented on the same base
one) range from 10x10 to 150x150. One cycle can overlay 1000's of
arrays at a time, so you can imagine that speed and stability are a
problem.


Here's how I do it now (I entered some pseudo checks instead of the
real ones, which can be a bit long):


  for ($cyclerY=0;$cyclerY<=$Base_Array_Height;$cyclerY++){
    for ($cyclerX=0;$cyclerX<=$Base_Array_Width;$cyclerX++){
    
    $Value_Hold = &Checking_Something_About_This_Location($cyclerX,
$cyclerY);
	
	if($Value_Hold == $Some_Check){
	  for ($cyclerYB=0;$cyclerYB<=$Overlay_Array_Height;$cyclerYB++){
	    for ($cyclerXB=0;$cyclerXB<=$Overlay_Array_Width;$cyclerXB++){
		
		my $PowerP = $Value_Hold/$Some_Multiplier;
		my $pinpointX = $cyclerX+$cyclerXB;
		my $pinpointY = $cyclerY+$cyclerYB;
		$Base_Array[$pinpointY][$pinpointX] +=
$PowerP*$Overlay_Array[$cyclerYB][$cyclerXB];
		
	    }
	  }
	}

    }
  }




There are a lot of other operations in the script, but this specific
part takes the longest to process.

Mainly, my 2 questions are:
A) Could anyone suggest a faster/better way of going about this?
B) Should I just take that part and compile it in C? (I really would
rather not, because I have to make frequent changes, but I understand
that it's much faster at executing long loops of basic math)

Thanks in advance.
-Moran Goldstein


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

Date: Thu, 9 Aug 2001 07:24:25 +0100
From: James Coupe <james@zephyr.org.uk>
Subject: Re: 2-Dimensional array math
Message-Id: <nPSJejDZyic7EwQi@gratiano.zephyr.org.uk>

In message <223f9ce4.0108082128.47d33580@posting.google.com>, Moran
Goldstein <moran-gy@actcom.co.il> writes
>A) Could anyone suggest a faster/better way of going about this?

use Math::Matrix; # ?

-- 
James Coupe                                                PGP Key: 0x5D623D5D
                                                                 EBD690ECD7A1F
You scumbag, you maggot, you cheap lousy faggot                  B457CA213D7E6
Happy Christmas your arse, I pray God it's our last             68C3695D623D5D


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

Date: Thu, 09 Aug 2001 06:57:58 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: 2-Dimensional array math
Message-Id: <Wvqc7.16$B2j.171005952@news.frii.net>

In article <223f9ce4.0108082128.47d33580@posting.google.com>,
Moran Goldstein <moran-gy@actcom.co.il> wrote:
>Hi,
>I'm working on an script that adds the values of one 2D array to the
>values of another 2D array, at a specific location. It's essentially
>basic matrix math. The main problem I'm having is code efficiency,
>since the way I do it now takes eons, and for whatever reason,
>sometimes crashes mid-way...
>

You might want to consider using PDL:

use strict;
use PDL;
 
my $x = pdl [
    [qw(0 0 0 0 0)],
    [qw(0 0 0 0 0)],
    [qw(0 0 0 0 0)],
    [qw(1 1 1 1 1)],
];
 
my $y = pdl [
    [qw(0 0 0 0 0)],
    [qw(0 0 1 2 1)],
    [qw(0 0 2 3 2)],
    [qw(0 0 1 2 1)],
];

my $z = $x + $y;

print $z;

-- 
    This space intentionally left blank


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

Date: Thu, 9 Aug 2001 17:15:28 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: 2-Dimensional array math
Message-Id: <slrn9n4e4g.cq.mgjv@martien.heliotrope.home>

On 8 Aug 2001 22:28:53 -0700,
	Moran Goldstein <moran-gy@actcom.co.il> wrote:
> Hi,
> I'm working on an script that adds the values of one 2D array to the
> values of another 2D array, at a specific location. It's essentially
> basic matrix math. The main problem I'm having is code efficiency,
> since the way I do it now takes eons, and for whatever reason,
> sometimes crashes mid-way...

> A) Could anyone suggest a faster/better way of going about this?

Have a look at the PDL modules. They've been written specifically for
matrix manipulations in Perl, and they do it fast. You really don't want
to code this stuff in pure Perl, if you want it to be fast.

> B) Should I just take that part and compile it in C? (I really would
> rather not, because I have to make frequent changes, but I understand
> that it's much faster at executing long loops of basic math)

You don't need to. Either use PDL, or get a good matrix library in C,
and write a bit of glue in XS (or use Inline::C).

There really is no reason to code any of this basic matrix manipulation
stuff yourself.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | The gene pool could use a little
Commercial Dynamics Pty. Ltd.   | chlorine.
NSW, Australia                  | 


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

Date: Thu, 9 Aug 2001 09:48:00 +0100
From: "Tom Melly" <tom.melly@ccl.com>
Subject: Re: Command line parameters under mod_perl
Message-Id: <3b724e40$0$8507$ed9e5944@reading.news.pipex.net>

"Stefan Tillich" <stefan.tillich@siemens.at> wrote in message
news:3B715535.7E26E88C@siemens.at...

> > Well, assuming your problem isn't that you're REALLY trying to read from
> > @ARVG...
>
> Actually I am trying to read the Parameters this way, because my parameters
dont
> come from a webform but are arbitrary parameters without a definite name.

Fair enough - I still think trying to read from @ARVG is a mistake.... under ANY
circumstances ;)




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

Date: Thu, 09 Aug 2001 09:30:17 +0200
From: Philip Newton <pne-news-20010809@newton.digitalspace.net>
Subject: Re: Easy array question ?
Message-Id: <agd4nt0kfbhkpnvui3p80pdo6gso564lbh@4ax.com>

On Wed, 08 Aug 2001 10:57:58 +0200, Philippe PERRIN
<philippe.perrin@sxb.bsf.alcatel.fr> wrote:

> This is certainly easy for some of you, but I can't figure out how to
> remove the FIRST element of an array (in the same way as pop() removes
> the LAST)...

People already pointed out 'shift' to you, but I'd like to point out
another resource: near the beginning of `perldoc perlfunc`, there's an
item called "Perl Functions by Category". One of the categories is
"Functions for real @ARRAYs" and includes only

     `pop', `push', `shift', `splice', `unshift'

Now, if you'd read the documentation for those five functions (which
takes a lot less time than reading perlfunc from beginning to end
looking for the right thing), you would probably have found shift
yourself.

So a reminder -- if you think there ought to be a function that does
<foo> but don't know its name, have a look in the categories at the top
of `perldoc perlfunc`.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: 9 Aug 2001 01:49:32 -0700
From: derelixir@my-deja.com (derelixir)
Subject: export from dbf to csv/text format
Message-Id: <fd50a1dc.0108090049.3f8cbfb7@posting.google.com>

Hello...

I got a file in .dbf format that contains several fields
e.g. name, address, age, id

Is there a way I could automatically convert this dbf file to csv/text format?
Sample of codes is much appreciated.

Thank you & regards.


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

Date: Thu, 09 Aug 2001 06:17:01 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How do I print out or copy a recursive data structure?
Message-Id: <xVpc7.14$B2j.171260928@news.frii.net>

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 every Standard Distribution of
Perl.

+
  How do I print out or copy a recursive data structure?

    The Data::Dumper module on CPAN (or the 5.005 release of Perl) is great
    for printing out data structures. The Storable module, found on CPAN,
    provides a function called "dclone" that recursively copies its
    argument.

        use Storable qw(dclone); 
        $r2 = dclone($r1);

    Where $r1 can be a reference to any kind of data structure you'd like.
    It will be deeply copied. Because "dclone" takes and returns references,
    you'd have to add extra punctuation if you had a hash of arrays that you
    wanted to copy.

        %newhash = %{ dclone(\%oldhash) };

- 

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.

Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to

    news:news.answers

or to the many thousands of other useful Usenet news groups.

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-1999 Tom Christiansen and Nathan
    Torkington.  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.

                                                           04.71
-- 
    This space intentionally left blank


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

Date: 9 Aug 2001 09:13:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: getting the name of a sub from a sub ref
Message-Id: <9ktk8j$1ii$1@mamenchi.zrz.TU-Berlin.DE>

According to Abigail <abigail@foad.org>:
> Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDCCCXCIX
> September MCMXCIII in <URL:news:9krf09$b6j$1@mamenchi.zrz.TU-Berlin.DE>:
> :: According to John Imrie  <john.imrie@pa.press.net>:
> :: > is it possible to extract the name of the subrouteen pointed to by
> a sub ref
> :: 
> :: In general, no.  It may not have one (an anonymous sub) or it may have
> :: more than one (exported subroutines frequently do).  You could probably
> :: do an exhaustive search of all symbol tables and see what you come up
> :: with, but that's hardly worth the effort.
> :: 
> :: If the subroutine is currently running, caller(0) gives you the name it
> :: was called as, if there is one.
> 
> 
> Hmmpf. Two days ago I really, really hoped that was the case. But, alas,
> it doesn't.

Ugh.  Time to admit that I made a claim without double-checking.  My
apologies.
 
>     #!/opt/perl/bin/perl 
> 
>     use strict;
>     use warnings 'all';
> 
>     sub calvin {print +(caller (0)) [3], "\n"}
> 
>     *hobbes = *calvin;
> 
>     calvin ();
>     hobbes ();
> 
>     __END__
>     main::calvin
>     main::calvin

This doesn't make much sense, does it?   Apparently, Perl keeps info
about the environment some code was compiled in with that code and
pulls that up for caller.  A sub even stays anonymous when it was
compiled anonymously and later given a name through glob assignment:

    package SomePack;
    my $some = sub { print +(caller (0)) [3], "\n"};
    package main;
    *other = $some;
    other();

That prints "SomePack::__ANON__".  I doubt that this is actually
intentional.

Anno


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

Date: Thu, 09 Aug 2001 04:33:18 GMT
From: "Ryan Gralinski" <ryan@bong.net>
Subject: help with hash
Message-Id: <iooc7.1547$5d2.4587@news1.wwck1.ri.home.com>

can someone help me out,
i have a list of files downloaded off my web site

i read in the file, and store it like this..
while($filename=<thelist>)
{
     chomp $filename;
       $file{$filename}++;
}
close thelist;



now how can i find out what the largest one is, as in which file was
downloaded most, the biggest of all the $file s

i cannot figure out how to do this i'm sure someone out there can..

Thanks,

RYan





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

Date: Thu, 09 Aug 2001 05:17:11 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: help with hash
Message-Id: <Xns90F8DA783568echangnetstormnet@207.106.93.86>

"Ryan Gralinski" <ryan@bong.net> wrote in 
<iooc7.1547$5d2.4587@news1.wwck1.ri.home.com>:

> can someone help me out,
> i have a list of files downloaded off my web site
> 
> i read in the file, and store it like this..
> while($filename=<thelist>)
> {
>      chomp $filename;
>        $file{$filename}++;
> }
> close thelist;
> 
> 
> 
> now how can i find out what the largest one is, as in which file was
> downloaded most, the biggest of all the $file s

Just go through the hash keeping track of the largest number you have 
found.  When you find a larger one, replace it.

my $lgst_so_far, $lgst_file;
foreach (keys %file) {
   if ($file{$_} > $lgst_so_far){
      $lgst_so_far = $file{$_};
      $lgst_file = $_;
   }
}

print "Most downloads $lgst_so_far for file $lgst_file";

-- 
EBC


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

Date: Thu, 9 Aug 2001 07:25:01 -0000
From: "B. Caligari" <bcaligari@fireforged.com>
Subject: Re: help with hash
Message-Id: <9kt6hc01hg5@enews1.newsguy.com>


"Ryan Gralinski" <ryan@bong.net> wrote in message
news:iooc7.1547$5d2.4587@news1.wwck1.ri.home.com...
> can someone help me out,
> i have a list of files downloaded off my web site
>
> i read in the file, and store it like this..
> while($filename=<thelist>)
> {
>      chomp $filename;
>        $file{$filename}++;
> }
> close thelist;
>
>
>
> now how can i find out what the largest one is, as in which file was
> downloaded most, the biggest of all the $file s
>
> i cannot figure out how to do this i'm sure someone out there can..


How have you tried to do it?  What happens if there were more than
one file that were downloaded the highest number of times?


my ($largest, $count) = ('', 0);
while ((my ($key, $value)) = each %file) {
 ($largest, $count) = ($key, $value) if ($count < $value);
}
print "largest was '$largest' with $count\n";

B

PS: comp.lang.perl does not exist





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

Date: Thu, 09 Aug 2001 09:01:09 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: help with hash
Message-Id: <3B723535.60409@post.rwth-aachen.de>

Ryan Gralinski wrote:
> can someone help me out,
> i have a list of files downloaded off my web site
> 
> i read in the file, and store it like this..
> while($filename=<thelist>)
> {
>      chomp $filename;
>        $file{$filename}++;
> }
> close thelist;
> 
> 
> 
> now how can i find out what the largest one is, as in which file was
> downloaded most, the biggest of all the $file s
> 
> i cannot figure out how to do this i'm sure someone out there can..

Simply sort by values:

ethan@ethan:~$ perl
use warnings;
use strict;
my %hash = ( key1 => 1, key2 => 3, key3 => 2);
my @sorted = sort { $hash{$b} <=> $hash{$a} } keys %hash; # reverse
print @sorted;
^D
key2key3key1ethan@ethan:~$

See perldoc -f sort. You'll find a lot of useful examples in there.


Tassilo

-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



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

Date: Thu, 9 Aug 2001 09:28:16 +0100 
From: "Bell, Leslie" <lbell@essex.ac.uk>
Subject: how to get perlscript 
Message-Id: <C402F529148ED411A7FF00A0C9DD67E10DCC7AEB@sernt14.essex.ac.uk>

I have perl installed on an NT server running IIS, which tells me that
perlscript is not available (for .asp pages). I don't want to install
ActiveState perl because you can't choose the directory, and I want it
to stay in C:\winnt\local\perl\bin. Do you have to use ActiveState to
get perlscript, or is there another way? And what is that other way, if
there is one?

Les :>)



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

Date: Thu, 9 Aug 2001 09:00:25 +0100
From: "Paul Fortescue" <paul@net366.com>
Subject: Re: IF $FileArray[$index] CONTAINS.....
Message-Id: <997343948.7141.0.nnrp-08.d4f094e4@news.demon.co.uk>


"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:9krhv7$fv3$1@mamenchi.zrz.TU-Berlin.DE...
> According to Paul Fortescue <paul@net366.com>:
> > Nice one Mike.
> >
> > I am VERY new to Perl, I only learnt it last weekend :) with a LOT of
help
> > from Ilya Martynov who is great.
> >
> > I hope my answers, naive as they are, will help other newbies because
that
> > is where I'm coming from. I am trying to put something back into the
> > newsgroup which helped me.
> >
> > Let me know if I should hide until I am much better!
>
> Nah, that's fine.  As long as you don't post misleading code, or
> baseless conjecture, you're welcome.  Test your code, or say so
> if you don't for some reason.
>
> But if you want to play, please trim the quoted material and place
> your replies after the text you are referring to.  The top-posting
> style you have practiced is frowned upon in large parts of Usenet.
>
> The grep-solution you posted to the OPs request isn't at all bad.
>
> You wrote:
>
> > $x[0]="fred";
> > $x[1]="bert";
> > $x[2]="freddie";
>
> In Perl you rarely need to refer to array elements through their
> indexes.  Just
>
>   @x = qw( fred bert freddie);
>
> would have done.
>
> > @y=grep(m/fred/, @x);
>
> That's the spirit.  Deal with an array as one unit wherever possible.
>
> > print "@y\r\n";
>
> Why do you explicitly print the "\r\n" combo?  "\n" usually prints
> the kind of linefeed your system requires.
>
> Anno

Thanks for encoragement/advice. I don't normally use the newsgroups but in
this case I must! I will post below as you suggest. I am impressed the way
this newsgroup gets answers so quickly and fully.

I use \r\n because I am used to it. I'm using Windows Perl from Active
State. I think I'm getting old! So I ALWAYS test my code.

I didn't know you could set an array like that. Isn't Perl flexible!

Thanks again! Paul







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

Date: Thu, 9 Aug 2001 15:45:44 +0800
From: "Cosmos Tong" <cosmos@NOSPAMnetvillageasia.com>
Subject: Limit the number of child process
Message-Id: <9ktf3b$jem$1@hfc.pacific.net.hk>

Dear all,

I use the following code to create child process (copy from Programming
Perl, 2nd Ed).  How can I know how many child process is running, and how
can I limit them?

Also can anyone help explain the logic of the below code as I am confused.
As the child will sleep 10 seconds, I can see 10 child
processes.  And in the PARENT log I can see a list of 10 lines.  However,
the CHILD log is not written until the 10 seconds is passed.
And once the 10 seconds passed, the code that print the parent PID into
PARENT LOG was run several times.  I am confused.

Thanks very much.

Regards
Cosmos

--

open LOGFILE, ">/home/cosmos/devel/testing/log/rept.fork" ||
  die "Cannot open log file\n";
open CHILD, ">/home/cosmos/devel/testing/log/child"||
  die "Cannot open log file\n";
open PARENT, ">/home/cosmos/devel/testing/log/parent"||
  die "Cannot open log file\n";


sub REAPER {
      $waitedpid=wait;
      $SIG{CHLD} = \&REAPER;

      print LOGFILE "reaped $waitedpid\n";
}

$SIG{CHLD} = \&REAPER;

print PARENT "-----$$-----\n";

while ( $x <= 100 ) {
    FORK: {
        if ($pid=fork) {
             print PARENT "$countp $$ $pid\n";

        }elsif (defined $pid) {
            print CHILD "Child process $$ created\n";
            sleep 10;
            exit;

        }elsif ( $! =~ /No more process/ ){
                sleep 10;
                redo FORK;
        }
     }


     $x++;
}






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

Date: 9 Aug 2001 08:50:17 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Line counting in a file
Message-Id: <9ktis9$g9$1@mamenchi.zrz.TU-Berlin.DE>

According to Yves Orton <demerphq@hotmail.com>:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
> news:<9krj4f$gq6$1@mamenchi.zrz.TU-Berlin.DE>...
> > According to Yves Orton <demerphq@hotmail.com>:
> > > anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
> > > news:<9kqrk4$pth$1@mamenchi.zrz.TU-Berlin.DE>...
> > > > According to Yves Orton <demerphq@hotmail.com>:
> > > > > anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
> > > > > news:<9kos74$fjn$2@mamenchi.zrz.TU-Berlin.DE>...
> > > > > > According to John Imrie  <john.imrie@pa.press.net>:
> 
> SNIP
> 
> > > > > while (<>) {}
> > > > > print $.;
> 
> SNIP
> 
> > > It printed out the correct number of lines.  Is there a point there
> > > anno? :-)
> > 
> > Yes.  It didn't print anything, most likely print failed.  If it could,
> > it would print the total of lines in the files mentioned on the command
> > line, or count lines from STDIN.  Unless FILE happens to be opened to
> > one of these, the count printed has nothing to do with the number of
> > lines in FILE.
> > 
> > Apparently you didn't try the code you posted.
> 
> Ahhh.  Finally the cobwebs clear.  You are in pedantic mode. :-)

No more pedantic than usual.

> should have said
> 
> while (<FILE>) {}

If that is what you meant...

> Oh, and if you do run the second bit of code I provided you will see
> that the point is valid even if the first bit of code was slightly
> inconsistent.

The valid point in your post was that $. can be used for line counting.
However, your code didn't demonstrate that, and with the perceived
(but nonexistent) connection to select(), it was more confusing than
clarifying.

> And you _knew_ what I meant anyway.

No.  Too many possibilities.
 
Look, I'm sure I'm not only speaking for myself when I say that I
appreciate your contributions to the group.  It is however a rule
that code you post should be tested (unless there are compelling
reasons not to, which should be mentioned in the text).  If you fail
to do so, that will be noted.

Anno


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

Date: 9 Aug 2001 01:59:44 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Line counting in a file
Message-Id: <74f348f7.0108090059.1d019122@posting.google.com>

Joe Schaefer <joe+usenet@sunstarsys.com> wrote in message news:<m3r8umcpo5.fsf@mumonkan.sunstarsys.com>...
> demerphq@hotmail.com (Yves Orton) writes:
> 
> > anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote...
SNIP
> > As for the select, I somehow thought that to get $. to refer to
> > correct filehandle you had to select().  Upon RTM I realize I was
> > wrong, all you have to do is read() or equiv. Sorry.
>                                ^^^^^^
> 
> Wrong- read() and $. are unrelated.

Indeed?  So the following entry in perlvar is incorrect? perhaps you
should raise a bug report?

input_line_number HANDLE EXPR
$INPUT_LINE_NUMBER
$NR
$.
The current input record number for the last file handle from which
you just read() (or called a seek or tell on). The value may be
different from the actual physical line number in the file, depending
on what notion of ``line'' is in effect--see $/ on how to change that.
An explicit close on a filehandle resets the line number. Because <>
never does an explicit close, line numbers increase across ARGV files
(but see examples in eof in the perlfunc manpage). Consider this
variable read-only: setting it does not reposition the seek pointer;
you'll have to do that on your own. Localizing $. has the effect of
also localizing Perl's notion of ``the last read filehandle''.
(Mnemonic: many programs use ``.'' to mean the current line number.)

Note that the first line specifically mentions read().
 
> > 
> > Anyway try this
> > 
> > my $lines=0;
> > open (IN,$0) || die $!;
> > while (<IN>) {$lines++};
> > print "$.\t$lines\n";
> > 
> > When I run it it prints out the same number twice, so why other with
> > $lines?
> 
> Because $. is poorly documented and more of a nuisance 
> than it is worth.  $. appears in clp.misc with far greater 
> frequency than it does in real perl code. To get some feel for this, 
> try running the following program on a unix box to see how $. is 
> actually used-

Not on a unix box, but when I get some time make the necessary
changes.  But im already slightly concerned that you are doing
assignment to $. when the doc says it should be treated as read-only. 
(I am aware that your usage is not a problem here)
 
Cheers,
Yves


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

Date: 9 Aug 2001 02:10:07 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Line counting in a file
Message-Id: <74f348f7.0108090110.66acc071@posting.google.com>

Ren Maddox <ren@tivoli.com> wrote in message news:<m3zo9acq28.fsf@dhcp9-161.support.tivoli.com>...
> On 8 Aug 2001, demerphq@hotmail.com wrote:
> Actually, that's not what he meant.  Your original code included a
> "select FILE".  While that did not have the desired effect, it did
> change the destination of unqualified prints.  So when you later did a
> "print $.", the output simply vanished.
> 
> That's what Anno meant.

BLUSH.   :-)

Guilty as charged.  I didn't run it with the select statement.

My apologies anno, and thanx ren.

Yves


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

Date: 9 Aug 2001 02:34:46 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Perl editor for win32 needed
Message-Id: <74f348f7.0108090134.53909fa3@posting.google.com>

"Tintin" <somewhere@in.paradise.net> wrote in message news:<wlac7.33$lI2.1172517@news.interact.net.au>...
> <194.203.212.8 [demerphq]> wrote in message
> news:9kp0u407h5@enews2.newsguy.com...
> > > Nikolas Garofil wrote:
> > >
> > > > What is the best editor to write perl scripts in Windows 98
> > > >
> > > >
> > > >
> > > Real perl coders use
> > >
> > > 'cat > myProg.pl'
> > >
> > > ;-)
> >
> > Sorry isnt that (this is dos after all)
> >
> > Real masochistic dos perl coders use
> >
> > 'copy con myProg.pl'
> 
> Wimp!  See http://ars.userfriendly.org/cartoons/?id=19990508

Wuss!

:-)

Yves
Ps Nice Link!


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

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.  

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


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