[23776] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5980 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 25 14:05:41 2003

Date: Thu, 25 Dec 2003 11:05:06 -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 Dec 2003     Volume: 10 Number: 5980

Today's topics:
    Re: Accounting, Database Problem (Tim Shoppa)
    Re: installing mod manually <jwillmore@remove.adelphia.net>
    Re: invoking C-shell command through Perl script (Micha Ophir)
    Re: newbie: Terminating while($line=<stdin>) on Windows <mgjv@tradingpost.com.au>
    Re: newbie: Terminating while($line=<stdin>) on Windows (Tad McClellan)
    Re: Please critique this short script that scans a log  <perl@my-header.org>
    Re: Please critique this short script that scans a log  <perl@my-header.org>
    Re: Please critique this short script that scans a log  <uri@stemsystems.com>
    Re: Please critique this short script that scans a log  (Tad McClellan)
    Re: Problem with executing UNIX command in perl script <me@privacy.net>
    Re: search interval <noreply@gunnar.cc>
    Re: search interval <gnari@simnet.is>
    Re: SOLVED:: HTML::Form->Parse (Perl) not working under <jwillmore@remove.adelphia.net>
    Re: Why chop fails? (Jay Tilton)
    Re: Why does Perl use more resource than Php? <perl@my-header.org>
    Re: why this code shots up memory usage <a_madhur@vsnl.net>
    Re: why this code shots up memory usage <sbryce@singlepoint.net>
    Re: why this code shots up memory usage <a_madhur@vsnl.net>
    Re: why this code shots up memory usage (Jay Tilton)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 25 Dec 2003 04:59:05 -0800
From: shoppa@trailing-edge.com (Tim Shoppa)
Subject: Re: Accounting, Database Problem
Message-Id: <bec993c8.0312250459.6ae35825@posting.google.com>

"Matt" <nospam.hciss@yahoo.com> wrote in message news:<vuk0vt12bki0fc@corp.supernews.com>...
>  But after
> further thought I may run into a locking issue.  The primary script will be
> the ONLY one to write to the file.

Wait until two of the "primary scripts" - the ones that are writing - are
running at once, due to some oddball race condition that you never thought
of.  Changing the system time in a bad way can easily cause cron to fire
up two jobs that were supposed to be an hour apart to start just seconds
from each other.

>  I will have other scripts that read data
> basically to get all the stats out but the will not change anything.  The
> thing I wonder about now is the scripts that read will also likely use
> tieing.  Even though they do not write will that create a problem if its
> updated right from under it?  I do not care if the reading script gets data
> a little old.

If this is accounting information, meaning that money is at stake,
you want to do some sort of locking.

> After thinking if over using hash of arrays and tieing it to a file seems
> the best way to do this.  I just cannot find many examples of hashes of
> arrays.  My guides are: "Learning Perl" and "Perl Cookbook".  Both quite
> good I think.

It's not that hard, but unless you need to access two different user's
accounts simultaneously you don't need both "in scope" at the same time.

Just because you have all those data files at once doesn't mean you
have to maintain them all and their lockfiles simultaneously.  Unless
there's some constraint you didn't tell us about, you would probably
prefer to do them sequentially:  looping over each user, locking
their file, adding the new value and removing the old one, and unlocking.
Then move to the next user.  Do it with tieing or without, as you wish.

Tim.


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

Date: Thu, 25 Dec 2003 06:13:10 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: installing mod manually
Message-Id: <20031225011310.40ad6201.jwillmore@remove.adelphia.net>

On Wed, 24 Dec 2003 11:26:47 -0500
lucas <aolblowz@yahoo.com> wrote:

> Thanks ;)
> I thought about using the 'prefix' paramater, but didn't turns out
> it worked fine.  I didn't find anything in the readme or install
> files about problems with ftp.  So, if anybody wants to know what I
> did to get around the ftp requiring PASV to work properly, here you
> go: Download the package (Math-Pari-2.010500.tar.gz)
> unpack
> edit ./Math-Pari-2.010500/utils/Math/PariBuild.pm
> and modify: $ftp = Net::FTP->new($host) or die "Cannot create FTP
> object: $!";
> to: $ftp = Net::FTP->new($host, Passive => 1) or die "Cannot create
> FTP object: $!";
> 
> Save file, run ./Math-Pari-2.010500/Makefile.pl
> prefix=/usr/local/lib/perl5 or wherever your perl directory is
> the Makefile will download another gzip file and compile the C code
> (some of it is in C), and install to your perl directory.
> 
> Thanks again Jim

You're welcome.  And, have you emailed the author so this modification
is available to all?

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
"Pascal is Pascal is Pascal is dog meat."   -- M. Devine and P.
Larson, Computer Science 340 


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

Date: 25 Dec 2003 04:44:46 -0800
From: micha.ofir@zoran.com (Micha Ophir)
Subject: Re: invoking C-shell command through Perl script
Message-Id: <cec9398b.0312250444.72407633@posting.google.com>

genericax@hotmail.com (Sara) wrote in message news:<776e0325.0312221306.6d27dc57@posting.google.com>...
> micha.ofir@zoran.com (Micha Ophir) wrote in message news:<cec9398b.0312220740.26bd2796@posting.google.com>...
> > Hi,
> > 
> > I was looking for an answer in several places incloding the FAQ in
> > perl.com .
> > 
> > I invoked C-shel through perl like this :
> > `ls *.v`;
> > or like this :
> > system ("ls *.v");
> > 
> > Here are the questions :
> > 1. How can I cause the C-Shell / perl to output the standart output 
> >    to the screen. ( usually I don't see it ).
> > 2. How can I set environment variables in C-Shell through the perl.
> >    When I set the variables in the perl code, and then invoke the C-shell 
> >    command the variables are not set.
> >    Example :
> > $ENV{PATH_TO_FILE} = "all_you_need_is_love";  ## set the variable 
> > `echo $PATH_TO_FILE` ;  ## doesn't know the variable
> > 
> > Thanks in advance.
> > 
> > Ophir Micha
> 
> its not a particularly good idea to turn control over to OS commands
> for a number of reasons, portability being one good one. Error control
> being another.
> 
> I'd advise you to look at opendir / readdir to accomplish what you're
> trying to do. If you insist on using the OS command, perhaps you can
> capture the result in a scalar and print it:
> 
> #!/usr/bin/perl -wd
>  my $cat = `ls *`;
>  print $cat;
> 
> As for ENV Vars- again portabiity might be a concern. Do you want the
> var to persist after the script exits? If so, an OS command might be a
> viable alternative. If you're trying to set the var to do some sort of
> inter-process communication, you might consider portable alternatives.
> Perl has a nice library of file sharing methods for locking, testing
> status, changing permissions, etc on files. Store results in a file
> and have the other script open and read it?
> 
> If you don't need it to persist, just add it to %ENV as you did:
> 
>     $ENV{MyFavoriteHobbit} = 'Bilbo';
> 
> realzing of course that the scope of this definition is only the scope
> of %ENV, which of course cannot exist outside of the script itself
> (wll unless you tie it, but even then it won't affect the ssytem ENV
> VAR tables).
> 
> 
> Happy Holidays,
> G

Hi,


First I would like to thank you and the others who sent answers 
for your time and help.

I can print now messages from Perl, but the environment problem still
exists.
The reason I try to invoke the C-shell commnads through Perl is that 
they are special commnads that invoke specific tools for UNIX like 
ncsim ( verilog simulator by Cadence ), so there are no Perl commnads
that can replace them.
I need the environment variables in the above example to set the version
of the SW invoked.
That is the reason I want the environment variable to exist in C-shell 
after I set it through Perl.
Do you know of a way to do it ?

Thanks,
Micha


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

Date: Thu, 25 Dec 2003 20:49:43 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: newbie: Terminating while($line=<stdin>) on Windows
Message-Id: <slrnbulcln.qbf.mgjv@martien.heliotrope.home>

On 24 Dec 2003 09:03:59 -0800,
	John Deuf <google@spongers.com> wrote:
> Martien Verbruggen <mgjv@tradingpost.com.au> wrote in message news:<slrnbui7tm.qbf.mgjv@martien.heliotrope.home>...

[snip of a lot of material about the <> construct in while loops, and
the treatment of end-of-line in Perl]

>> Martien
> 
>   Hi Martien :)
> 
> Thank you to answer my answer. 
> 
> Did you at least read the initial question from the initial message :)
> And tried to interpret it and answer it... Seemingly the initial user
> is not a pro at Perl and needed to get a solution ready to use.

And? Your point is?

> - <STDIN> being empty or false : actually it is finally evaluated to
> false
> Does playing with words really help the newbie :) 

Accuracy does help. Programmers have to be accurate, because computers
are generally not very forgiving towards inaccurate programs.

> - Regarding the 2 chars on a PC coming from Unix - ok you program Perl
> since the early nineties ... - but you should know my friend that on
> some implementations and depending on the way it has been installed
> the "chomp" removes only the \012 (LF) not the \015 (CR) ...

And on those platforms, end-of-line is \012 or \015. Perl's chomp
removes whatever $/ is set to, and that, by default, is set to whatever
the end-of-line on the current platform is. 

If you want to remove more than the end-of-line characters, then do so.
However, when you are working with _regular_ text files, you should
never ever worry about end-of-line sequences that might come from other
plartforms. never.

You just finished telling me that you thought the OP was "not a pro at
Perl", yet you decide that it would be a good idea to worry the OP with
this sort of stuff? And apart from that, you didn't just give him
inaccurate information in this resect, but wrong information. i
corrected that. This is Usenet, get used to it.

> - STDIN : this is funny :) I'm sure you are not answering threads to
> show off, since your time is so valuable, but my friend, as you say,
> "read the doc" :)) All the global special filehandles are given in
> uppercase (Perl in a nutshell for instance p.55). You're lucky,
> "stdin" works in lowercase. But try with ARGV !!

Te OP used stdin, you started using STDIN. It is by (mis)design that
both work in Perl, but not always. stdin is only synonmous for STDIN in
main::. You switched from one to the other without explaining why you
did that.

The OP should have used STDIN, probably. You didn't explain why.

I do not, and have never advocated the use of stdin above STDIN when
people mean to use the standard input stream. What I remarked was that
the OP used stdin, and you switched to STDIN, which is _not_ the same
thing, in general.

You just finished telling me that you thought the OP was "not a pro at
Perl", yet you decide that it would be a good idea to worry the OP with
the case-insensitivity of STDIN, STDOUT and STDERR, without explaining
that this only is the case in certain circumstances. You should have
sticked with stdin, if you are genuinely worried about the OP not being
"a pro at Perl", or you should have explained why it is better to use
STDIN.

> - Regarding $_, yes, you got the point, and, for once, you answered
> the user. Good. However I think it is better to forget the C
> programming and tend to use $_ instead of other variables (needing
> allocation etc...). Moreover it is so convenient to use this default
> variable...

That is such nonsense that I don't even know where to start. You are
obviously an idiot. The use of named variables has absolutely nothing
whatsoever to do with C, and everything with good programming practices.

>   while (<STDIN>)
>   {
>     chomp;
>     s/\015//; # in case your implementation needs it and (for our
> friend)if
>               # you don't want to spend ages to find out where the PC
> specific
>               # config is missing

In my implementation, this garbage would never appear.

Also, you foget that I responded directly to some piece of code you
submitted:

   while (<STDIN>)          # get line in $_
   {
        chomp;              # removes the unix LF char
        s/\015//;           # removes the PC CR char
        $line = $_;         # if you really want the $line var...
  
           ....  your process ....
   }


I responded specifically to the line "$line = $_;", with the remark that
if you are going to use a named variable, that you should do so at the
start, instead of switching from one to the other in the middle. If you
want to use $_, fine, use it, but if you don't then don't. Don't be
wishy-washy about it, and do both, a little bit.

And you're right, my time is valuable. Too valuable to deal with
trolling idiots like you.

*plonk*

Martien
-- 
                        | 
Martien Verbruggen      | That's funny, that plane's dustin' crops
                        | where there ain't no crops.
                        | 


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

Date: Thu, 25 Dec 2003 11:15:28 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: newbie: Terminating while($line=<stdin>) on Windows
Message-Id: <slrnbum6pg.auk.tadmc@magna.augustmail.com>

John Deuf <google@spongers.com> wrote:
> Martien Verbruggen <mgjv@tradingpost.com.au> wrote in message news:<slrnbui7tm.qbf.mgjv@martien.heliotrope.home>...


> Seemingly the initial user
> is not a pro at Perl 


And neither are you.

Martien is.


> Does playing with words really help the newbie :) 


Does using technically precise terminology help when discussing
technical topics?


> but you should know my friend 

> but my friend, as you say,
> "read the doc"

> - Regarding $_, yes, you got the point, and, for once, you answered
> the user.


You correcting Martien is a ludicrous endeavor.

So long fool.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 25 Dec 2003 13:50:45 +0100
From: Matija Papec <perl@my-header.org>
Subject: Re: Please critique this short script that scans a log file
Message-Id: <6tkluvkdioa3bh43amrsp3ti37odpoameg@4ax.com>

X-Ftn-To: Tad McClellan 

tadmc@augustmail.com (Tad McClellan) wrote:
>Matija Papec <perl@my-header.org> wrote:
>> Uri Guttman <uri@stemsystems.com> wrote:
>
>>>		next ;
>
>
>> On the other hand you can't use "next" outside of loops, 
>
>
>But a "naked block" counts as a loop, so you _can_ use them outside
>of (actual) loops:
>
>   {
>      ...
>      last if something();
>      ...
>   }

Good point, technically it isn't a loop but you still have block/braces.


-- 
Matija


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

Date: Thu, 25 Dec 2003 13:50:43 +0100
From: Matija Papec <perl@my-header.org>
Subject: Re: Please critique this short script that scans a log file
Message-Id: <6blluvod8q8s62c9l99t4736ccmcaajb9v@4ax.com>

X-Ftn-To: Uri Guttman 

Uri Guttman <uri@stemsystems.com> wrote:
>  > else {
>  >   ..
>  > }
>
>but you are missing the real win there. use statement modifiers when you
>can. elsif can't be used like that.
>
>next if /blah/ ;

No they can't, but I think you'll have problem when you need something more
complex then,

$flag=1, next if /blah/;

I've tried that and the only result was long and unreadable oneliners. :)

>(and else/elsif if needed) but i try to use that style of flow control
>with statement modifiers as much as possible. it is amazing how much
>code can be shrunk using them and you don't lose any clarity if done
>correctly. i have restructured loops/subs and such just to make the work
>better this way and the code is markedly better then. but as i said,
>don't go overboard and force this on all flow statements, use it only for
>the short and clear ones. but coding so that your conditionals are short
>and clear is another skill in itself.

I think this is strongly related to good taste and longer practice history.

>  > I did some reading on it, can it be used for automating tasks on remote
>  > computers?(sorry if you already covered this in the docs)
>
>yep. all sorts of remote and local operations can be automated. stem
>doesn't do that directly but it is a framework which makes it much
>easier to do that. you need much less code and get a more flexible
>system when you use it. message passing is a universal API in stem and
>it can be looked at as a super glue application :).

Nice, I hope I'll have time to study stem API as I first want look at POE.

>one key thing is that you can prototype an application in one stem
>process on one box and without any new code (just configuration changes)
>expand it to work on multiple processes on multiple boxes. the same
>message passing API works locally or remotely.

Cool.

>also .11 (due out SOON i hope) has a great way to handle flow control of
>sync AND async methods on an object. that is a very tricky problem with
>most complex local/remote control designs and it is much easier in stem.

Don't know much about such design problems, do you have some rtfm?


-- 
Matija


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

Date: Thu, 25 Dec 2003 16:39:01 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Please critique this short script that scans a log file
Message-Id: <x7d6acg8d7.fsf@mail.sysarch.com>

>>>>> "MP" == Matija Papec <perl@my-header.org> writes:

  > X-Ftn-To: Uri Guttman 
  > Uri Guttman <uri@stemsystems.com> wrote:
  >> > else {
  >> >   ..
  >> > }
  >> 
  >> but you are missing the real win there. use statement modifiers when you
  >> can. elsif can't be used like that.
  >> 
  >> next if /blah/ ;

  > No they can't, but I think you'll have problem when you need something more
  > complex then,

  > $flag=1, next if /blah/;

  > I've tried that and the only result was long and unreadable oneliners. :)

i did say when you can, not in all situations. on #perl on irc.perl.org,
i also said that multiple statements use , or 'and' with a statement
modifier is a bad choice.

  >> yep. all sorts of remote and local operations can be automated. stem
  >> doesn't do that directly but it is a framework which makes it much
  >> easier to do that. you need much less code and get a more flexible
  >> system when you use it. message passing is a universal API in stem and
  >> it can be looked at as a super glue application :).

  > Nice, I hope I'll have time to study stem API as I first want look at POE.

nah, bypass poe and go right to stem :)

at the core level they do the same thing. but the higher levels are very
different and that is what counts. also their design philosophy and APIs
are very different as well.

  >> also .11 (due out SOON i hope) has a great way to handle flow
  >> control of sync AND async methods on an object. that is a very
  >> tricky problem with most complex local/remote control designs and
  >> it is much easier in stem.

  > Don't know much about such design problems, do you have some rtfm?

a simple example is a login session. a web login request comes in from
apache and this module need to query a database with DBI which is a
blocking protocol. now in multitasking event systems like this you want
to avoid blocking so you can delegate the dbi request to another process
which can block. but your main process has to track the state of that
session. so the dbi request is an async operation relative to the main
process. when the dbi results come back you will have to crunh them and
that is a sync operation. fetching a web page or communicating to an
external process are other typical async ops. if you mix and match sync
and async ops in a single object, you have a complex state machine
issue. it can be done with each method handling the state and knowing
what next states to enter. but this is a MAJOR pain (having had first
hand experience) when you need to change things and you know you will
always have to change things. so the stem flow module moves the state
login into a higher level layer allowing each method (be it local and
sync or remote and async) to execute and not worry about state. this
makes for cleaner method code, less clutter, easier to handle flow
logic, etc. all the nice things you want in complex software. :)

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 25 Dec 2003 11:02:51 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Please critique this short script that scans a log file
Message-Id: <slrnbum61r.auk.tadmc@magna.augustmail.com>

Matija Papec <perl@my-header.org> wrote:
> tadmc@augustmail.com (Tad McClellan) wrote:
>>Matija Papec <perl@my-header.org> wrote:
>>> Uri Guttman <uri@stemsystems.com> wrote:
>>
>>>>		next ;
>>
>>
>>> On the other hand you can't use "next" outside of loops, 
>>
>>
>>But a "naked block" counts as a loop, so you _can_ use them outside
>>of (actual) loops:
>>
>>   {
>>      ...
>>      last if something();
>>      ...
>>   }
> 
> Good point, technically it isn't a loop but you still have block/braces.


The way you said that makes me wonder if there isn't still some confusion.

It isn't the block/braces that lets you use next/last/redo, otherwise
you'd be able to use them in if-block or sub-block or...

It is the "loopness" that lets you use the loop control operators,
and a naked block _is_ a loop (with special restrictions):


   Note that a block by itself is semantically identical to a loop
   that executes once.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 25 Dec 2003 17:03:44 +1300
From: "Tintin" <me@privacy.net>
Subject: Re: Problem with executing UNIX command in perl script
Message-Id: <bsdnkq$bnknq$1@ID-172104.news.uni-berlin.de>


"sunil" <sunilsreenivas2001@yahoo.com> wrote in message
news:d924fa71.0312241747.6583b441@posting.google.com...
> Hi All,
>        I am trying to execute a complex piped UNIX command in perl
> script as follows:
>
> system("nm @ARGV | awk -F\| '$4 == "OBJT " && $5 == "GLOB "  {print $8
> " " $3}'| grep '^[^$]' | uniq | sort -r  | awk '$1 != prevvar
> {varstr=sprintf("char %s[%d];",$1,$2);print varstr;prevvar = $1}' |
> sort > $ofname");

Why not use Perl to process the output from nm?  Otherwise, you'd be better
off just writing it as a shell/awk script.





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

Date: Thu, 25 Dec 2003 04:20:07 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: search interval
Message-Id: <bsdldk$c0cai$1@ID-184292.news.uni-berlin.de>

Ying Hu wrote:
> My perl script is as the following, but I do know that is not good
> one.

I agree. It's not good at all.

1) It does not compile.

2) You are not using strictures (the script you posted contains errors
which are easily debugged by using strict).

3) It's not a good idea to use the special variables $a and $b outside
the sort() function, especially in a program that uses sort().

It's good that you posted code this time, but you have obviously not
studied the posting guidelines as suggested in my previous post in
this thread (or you decided to ignore them). Please give it a new try,
complying with the guidelines. It's inconsiderate to expect the people
who you ask for help to start possible efforts to assist you with
correcting typos.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Thu, 25 Dec 2003 03:14:06 -0000
From: "Ragnar Hafstaš" <gnari@simnet.is>
Subject: Re: search interval
Message-Id: <bsdkm5$8j8$1@news.simnet.is>

"Ying Hu" <yhu@mail.nih.gov> wrote in message
news:3FE9CE16.2FAC8D2D@mail.nih.gov...
> My perl script is as the following, but I do know that is not good one.
> The two data sets are in text files and very huge.
>
a bit more info might still help to optimize
how big datasets?
are the A-intervals overlapping?
what are the value ranges? (for example integers 0-1000)

>
> foreach $b (sort {$B_point{a}<=>$B_point{$b} keys %B_point){
you are sorting the dataset B , but nothing in the following requires it
unless the output needs to be sorted. in that case it might be more
efficient to sort
the output if it is a much smaller set than B

>     foreach $a (sort {$A_from{$a} <=> $A_from{$b} keys %A_from){
here you sort unnecessarily A for EACH element of B (bad if B is large)
better to sort it before (if you want to sort it at all)
>         if ($B_point{$b} >= $A_from{$a} and $B_point{$b} <= $A_to){
>             print "A:$a B:$b\n";
>         }
>     }
> }

try to move the sort to before the loops and see if you have improvements.

@Aset=sort {$A_from{$a} <=> $A_from{$b} keys %A_from;
@Bset=sort {$B_point{$a}<=>$B_point{$b} keys %B_point;
foreach $b (@Bset) {
    foreach $a (@Aset) {
        ...

if this improvement is not enough, you might make the innerloop slightly
more complex and make use of the fact that (if A and B are sorted)
for any given $Bset[x] >=$Aset[y],  you do not need to check $Aset[0..y-1]
when processing $Bset[x+1]. in other words, for each element of Bset,
you can start the inner loop at the first @Aset element that passed the
$B_point{$b} >= $A_from{$a} test in the previous B

also if A is sorted, you can exit from the inner loop with last as soon as
$A_from{$a}>$B_point{$b},
as all following intervals will just be more distant from the B point

another problem is memory usage. if set B is huge and much larger than set A
you might want/need to only read A into memory, and process B line by line.
if both are too huge to read into memory, you might need to use another
method altogether

good luck
gnari







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

Date: Thu, 25 Dec 2003 06:00:41 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: SOLVED:: HTML::Form->Parse (Perl) not working under Fedora Core 1
Message-Id: <20031225010040.31deef4c.jwillmore@remove.adelphia.net>

On Wed, 24 Dec 2003 16:36:11 GMT
kosowsky@consult.pretender (Jeffrey J. Kosowsky) wrote:

> James Willmore <jwillmore@remove.adelphia.net> writes:
> > No offense, but I don't bother with RPM's when it comes to Perl
> > modules.  In fact, given your position (a new install of Fedora),
> > the*first* thing I'd do is use the CPAN shell and start updating
> > *all* the modules.  Because the *most* of the Perl modules that
> > come with*most* distros are horribly out of date "out of the box".
> >  And the
> > RPM's are usually not much better.  
> > 
> > I'd get used to using the CPAN shell instead of using the RPM's -
> > but that's just my opinion :-)
> 
> No offense taken... but as a perennial perl newbie, I don't know
> much about the CPAN shell.
> 
> I tend to use RPMS as time-savers so I don't have to worry about
> updating and rebuilding apps.
> 
> What is the CPAN shell? Is it like a perl version of
> up2date/yum/apt?

perldoc CPAN -or- man CPAN

It aids in updating Perl modules - in much the same way as the
utilities you mentioned.

I would ditch the RPM idea - like I stated before.  I foresee many
issues in the future using RPM's, but that been my experience.

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
Is your job running?  You'd better go catch it! 



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

Date: Thu, 25 Dec 2003 14:53:09 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Why chop fails?
Message-Id: <3feaf203.475784998@news.erols.com>

huey_jiang@yahoo.com (Huey) wrote:

: #!perl
: # records in file foo.txt is like "me:123\n"
: open (F, "./foo.txt");
: while (<F>) {
: 	($u, $p) = split(/:/, $_);
:         chop $p;
: 	if ( $p eq "123"  ) {
: 		print "got ya!", "\n";
: 	} 
: }
: close(F);
: 
: I am using cygwin perl. I noticed $p looked correct in command-line
: when printed. The problem is the if () test never go true, it means
: that $p never equals "123", and chop never worked!

chop() might not be doing what you expect, but that doesn't mean it's not
doing what it's supposed to do.

Use of the preferred chomp() function to remove a record separator has
already been covered in this thread.  This is more about determining
whether the fault lies in the function or in the programmer's assumption on
what the function should be doing.

As a strictly temporary measure to convince yourself chop() is really doing
something, you could wrap the function in a subroutine of your own that
emits a message on what's going on:

    use subs 'chop';
    sub chop {
        chop($_) unless @_; # act on $_ if no arguments passed
        my $c;
        printf STDERR
          "chop:length before=%d; removed chr(%vd); length after=%d\n",
          length, $c = CORE::chop, length
          for @_;
        $c;
    }

    my $foo = "me:123\n";
    chop $foo; 
    # prints "chop:length before=7; removed chr(10); length after=6"



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

Date: Thu, 25 Dec 2003 13:50:46 +0100
From: Matija Papec <perl@my-header.org>
Subject: Re: Why does Perl use more resource than Php?
Message-Id: <k4nluv8djtdblirlm4n2idcum7e63o7vbk@4ax.com>

X-Ftn-To: Gunnar Hjalmarsson 

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
>Sam Holden wrote:
>> What that application is written in is irrelevant (if it was they
>> would ban that language and not just the application).
>
>I'm not following you, Sam. A Perl app that means a large number of
>new processes, which I suppose is the case with a bulletin board, may
>well reach the limit as regards how much CPU a web host accepts,
>without the host necessarily having to ban Perl for smaller
>applications. And there may be other languages that require less CPU
>for a similar app, so the language may well be relevant.

You shouldn't say such heretic words.. some other language being better than
Perl.. bah, just wait and see which language you'll use in your afterlife if
you keep on with such heresy (hint, devil likes Sun).

;)


-- 
Matija


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

Date: Thu, 25 Dec 2003 11:00:14 +0530
From: "Madhur" <a_madhur@vsnl.net>
Subject: Re: why this code shots up memory usage
Message-Id: <bsdsia$c3j07$1@ID-81175.news.uni-berlin.de>

Hello
Thanks to you all.
But shouldn't the substitution $input[$i]=~s/^[0-9]+://;
terminate automatically after a newline. I remember there is a
option in
the substitution which lets you operate on multiple lines. Then
What's the use
of that switch?, if its skipping newlines already here.

>It is because the line

  >  $input[$i]=~s/^[0-9]+://;

>keeps adding elements to the array after you have reached the
end of the
>data, so that
[snip]


When the end of data is reached, why the substitution is made, as
I have specified
the ^ operator, which specifies *the substitution should  only
occur if the digit is found at the beginning*.


Or May be, I haven't understood the response.
--
Winners dont do different things, they do things differently.

Madhur Ahuja
India
email : madhur<underscore>ahuja<at>yahoo<dot>com

John W. Krahn <krahnj@acm.org> wrote in message
news:3FEA2147.CC7BDC19@acm.org...
> Madhur wrote:
> >
> > The following code snippet, shots the memory usage to full
and
> > results in Out of Memory error.
> > The substitution seems to be the culprit. But why it happens.
I
> > am running W2K, Perl 5.6.
> >
> > @input=<MYFILE>;
>
> You are reading the entire file into memory.  If it is a large
file then
> this will die with an Out of Memory error.
>
>
> > $i=0;
> > while($i<=@input)
> > {
> >
> >   $input[$i]=~s/^[0-9]+://;
> >  print("$input[$i]");
> >  $i++;
> > }
> > close(MYFILE);
>
> The usual way to write that in perl is:
>
> while ( <MYFILE> ) {
>     s/^\d+://;
>     print;
>     }
> close MYFILE;
>
> Or another way: without the substitution:
>
> while ( <MYFILE> ) {
>     print substr $_, 1 + index $_, ':';
>     }
> close MYFILE;
>
>
>
> John
> --
> use Perl;
> program
> fulfillment




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

Date: Thu, 25 Dec 2003 00:29:18 -0700
From: Scott Bryce <sbryce@singlepoint.net>
Subject: Re: why this code shots up memory usage
Message-Id: <3FEA91CE.3080508@singlepoint.net>

Madhur wrote:

> But shouldn't the substitution $input[$i]=~s/^[0-9]+://;
> terminate automatically after a newline.

The substitution will be made on whatever is in $input[$i]. The data in 
the file was already broken at the newlines by the

@input=<MYFILE>;

line in your code.



> When the end of data is reached, why the substitution is made, as
> I have specified
> the ^ operator, which specifies *the substitution should  only
> occur if the digit is found at the beginning*.
> 
> 
> Or May be, I haven't understood the response.

Yup.

Let's walk through this...

Lets say the file only contains two lines.

@input=<MYFILE>;

reads the data out of the file and creates a 2 element array.

while($i<=@input)

when first encountered compares the value of $i (zero) with the number 
of elements in the array (2). 0 <= 2, so the condition evaluates to true.

$input[$i]=~s/^[0-9]+://;

is evaluated for $input[0];

$i is incremented, and the script returns to the top of the while loop. 
1 is less than the number of elements in the loop (2), so the loop runs 
a second time. This time the substitution is evaluated for $input[1].

$i is incremented again. It now equals 2.

Back to the top of the loop. $i ( now = 2) is  <= 2 (the number of 
elements in the array), so the loop runs a third time.

This time the substitution is evaluated for $input[2], which does not 
already exist. Perl creates $input[2] with an undef value. Now the array 
has 3 elements.

$i is incremented again. It now equals 3.

Back to the top of the loop. $i ( now = 3) is  <= 3 (the number of 
elements in the array), so the loop runs a fourth time.

And it will continue to run indefinitely, because every time

$input[$i]=~s/^[0-9]+://;

is encountered for a value of $input[$1] that does not exist, Perl adds 
another element to the array.



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

Date: Thu, 25 Dec 2003 21:50:50 +0530
From: "Madhur" <a_madhur@vsnl.net>
Subject: Re: why this code shots up memory usage
Message-Id: <bsf3c3$cj6v8$1@ID-81175.news.uni-berlin.de>


> This time the substitution is evaluated for $input[2], which
does not
> already exist. Perl creates $input[2] with an undef value. Now
the array
> has 3 elements.
>
[snip]

Oh! I didn't knew that. Thanks for clearing.
One more thing, Can I have remove the equal sign from the while
loop.

while($i<@input)

Would this be a good solution.


--
Winners dont do different things, they do things differently.

Madhur Ahuja
India
email : madhur<underscore>ahuja<at>yahoo<dot>com





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

Date: Thu, 25 Dec 2003 17:49:27 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: why this code shots up memory usage
Message-Id: <3feb17a4.485419583@news.erols.com>

"Madhur" <a_madhur@vsnl.net> wrote:

: One more thing, Can I have remove the equal sign from the while
: loop.
: 
: while($i<@input)
: 
: Would this be a good solution.

It will plug the hole that is sinking the program, but nobody competent
would call the program "good."

Recapping the original code, including that change:

    @input=<MYFILE>;
    $i=0;
    while($i < @input) {
        $input[$i] =~ s/^[0-9]+://;
        print("$input[$i]");
        $i++;
    }
    close(MYFILE);

The bad things about that:

1. Using global variables $i and @input instead of lexically declaring them
with my().

2. Useless use of quotes in the print() statement.  See "What's wrong with
always quoting ``$vars''? " in perlfaq4.

3. Perl programmers would rather write "while($i < @input){...;$i++}" as
"for my $i (0..$#input){...}" .

4. But they would rather not do even that.  Using the array elements'
indeces to iterate across the elements' values is distinctly anti-Perl.
The program treats all the array's values in the same way.  Why should it
care where each element is located in the array?

5. The worst thing about the program is the array itself.  Slurping an
entire file into memory just to process its records sequentially is amateur
programming.  If you're processing sequentially, then read sequentially.

To see the program distilled into something good, reread the code given by
John W. Krahn in this thread. 

    while ( <MYFILE> ) {
        s/^\d+://;
        print;
    }
    close MYFILE;



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

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


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