comp.lang.perl.misc
  Home FAQ Contact Sign in
comp.lang.perl.misc only
 
Advanced search
December 2006
motuwethfrsasuw
    123 48
45678910 49
11121314151617 50
18192021222324 51
25262728293031 52
2006
 Jan   Feb   Mar   Apr 
 May   Jun   Jul   Aug 
 Sep   Oct   Nov   Dec 
2008 2007 2006  
total
comp.lang.perl.misc Profile…
RELATED GROUPS

POPULAR GROUPS

more...

 Up
  Speeding up an application - general rules         


Author: Petyr David
Date: Dec 21, 2006 19:13

I have a small Perl application that searches through a series of
directories chosen by the user for files containing a pattern or group
of patterns. The file names and matching patterns are returned to the
user sorted by the file's modification time.The user also has the
choice of how far back in time to search and how many lines of output
he wants to see for each file.

With an expected and current increase of files and file sizes, the
application is bogging down a bit. I didn't design it with performance
in mind and I will be reviewing what I've done, but are there general
rules or specific suggestions you could offer to enhance performance?

Basically: the script uses perl's system command to run a long winded
"find" command which is piped to sed to correct patterns that match
HTML markers. The matching lines are then shoved into an array. The
elements of the array are moved into a hash for the purpose of sorting
the file names. Then file names and matching lines are printed.

Q: Can I speed things by eliminating the sed command and letting Perl
filter and modify the matching patterns? If so, how much of a
performance gain?
Show full article (1.48Kb)
8 Comments
  FAQ 3.23 Can I write useful Perl programs on the command line?         


Author: PerlFAQ Server
Date: Dec 21, 2006 18:03

This is an excerpt from the latest version perlfaq3.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

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

3.23: Can I write useful Perl programs on the command line?

Yes. Read perlrun for more information. Some examples follow. (These
assume standard Unix shell quoting rules.)

# sum first and last fields
perl -lane 'print $F[0] + $F[-1]' *

# identify text files
perl -le 'for(@ARGV) {print if -f && -T _}' *

# remove (most) comments from C program
perl -0777 -pe 's{/\*.*?\*/}{}gs' foo.c

# make file a month younger than today, defeating reaper daemons
perl -e '$X=24*60*60; utime(time(),time() + 30 * $X,@ARGV)' *

# find first unused uid
perl -le '$i++ while getpwuid($i); print $i'
Show full article (1.94Kb)
no comments
  Re: How to prevent duplicated entry in array of the hash-Help PLEASE PLEASE         


Author: Tad McClellan
Date: Dec 21, 2006 17:48

Cyrus hotmail.com> wrote:
> Still getting error even after declaring my %%DiskErr;
> any idea..
> Global symbol "$DiskErr" requires explicit package name a

Don't declare %%DiskErr (a hash).

Instead declare $DiskErr (a scalar).

--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
no comments
  Re: how to use rdir in Net Ftp recursive         


Author: Sisyphus
Date: Dec 21, 2006 15:15

"kunlun" wrote in message
news:1166705621.249976.203980@48g2000cwx.googlegroups.com...
You 're right

I managed
my pb was the $wr where i was systematically forgotting to pass it as a
variable (with $) ...

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

You could also code it as:

open(WR, '>', 'rec.txt') or die "Can't open rec.txt for writing: $!";
$ftp->rdir(Filehandle => \*WR);

Cheers,
Rob
no comments
  Re: How to prevent duplicated entry in array of the hash-Help PLEASE PLEASE         


Author: Cyrus
Date: Dec 21, 2006 13:00

> You're declaring it, but not in the same scope in which you're using it.

There was extra ->, it should be like below I fixed it...thanks a lot:
Coorect: $DiskErr{$sys}->{$el->{'id'}} = { status => $el->{'status'}
};
WRONG: $DiskErr->{$sys}->{$el->{'id'}} = { status => $el->{'status'}
};

Cheers & Have Great Holiday...
no comments
  Re: How to prevent duplicated entry in array of the hash-Help PLEASE PLEASE         


Author: Paul Lalli
Date: Dec 21, 2006 12:14

Sherm Pendley wrote:
> "Cyrus" hotmail.com> writes:
>
>> Still getting error even after declaring my %%DiskErr;
>> any idea..
>> Global symbol "$DiskErr" requires explicit package name a
>
> You're declaring it, but not in the same scope in which you're using it.

No, he's not declaring it. He's declaring %%DiskErr, when he's using
$DiskErr. Two completely unrelated variables.

Paul Lalli
1 Comment
  FAQ 4.10 Why aren't my random numbers random?         


Author: PerlFAQ Server
Date: Dec 21, 2006 12:03

This is an excerpt from the latest version perlfaq4.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

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

4.10: Why aren't my random numbers random?

If you're using a version of Perl before 5.004, you must call "srand"
once at the start of your program to seed the random number generator.

BEGIN { srand() if $] < 5.004 }

5.004 and later automatically call "srand" at the beginning. Don't call
"srand" more than once--you make your numbers less random, rather than
more.
Show full article (2.32Kb)
no comments
  Re: id="abcd" in XML         


Author: John Bokma
Date: Dec 21, 2006 10:13

"John" yahoo.com> wrote:
> Hi
>
> Many thanks for those replies. Sorry, if I only put part of the code
> in my query.
> John was right. I am using XML::Simple and I had forgotten to set
> KeyAttr.

:-) The thing is, with insufficient information less people are able to
help you. I often read the documentation of a module I haven't used before
just to see if I can help anyway. You were lucky I have a good memory,
since I used XML::Simple ages ago once or so :-D.

--
John Experienced Perl programmer: http://castleamber.com/

Perl help, tutorials, and examples: http://johnbokma.com/perl/
no comments
  How to compare 2 hashes         


Author: Billy Patton
Date: Dec 21, 2006 10:09

I'm checking the input to functions. The code below is just a snippett
The 'undef' is the problem.
It is being handled as a string.
What would be the simplest method of handling this?

use Data::Dumper;

my %%legal =
(
'extendInto'=> [
{'layer'=>'\S+','comment'=>'\S+','into'=>'\S+','value'=>'\d+','coincidenceOK'=>'[01]'},
];

my %%seed = (
'layer'=>'CONT','comment'=>'xxxx',=>'into'=>undef,'value'=>20,'coincidenceOK'=>1
);

if (isLegal(\@{$legal{extendInto}},\%%seed)){ print "legal\n"; }
else { print "NOT legal\n"; }
Show full article (1.79Kb)
2 Comments
  Re: How to prevent duplicated entry in array of the hash-Help PLEASE PLEASE         


Author: Jürgen Exner
Date: Dec 21, 2006 09:51

Cyrus wrote:
> Got it

Got what?
> thank for verification...something like this one right?

Like what?
Please quote some context when replying or nobody will have a clue what you
are talking about.

jue
no comments
 
1 2 3