Re: How to pass parameters to a module

2003-09-29 Thread Juris
Hi!

It's easy!
There is one sample:
sub do_somethig {
my @[EMAIL PROTECTED];
if (! ($passed_params[0]))  { print "Not passed parametrs" }
my @lines;
#Do something ...
return @lines;
}
On Thu, 25 Sep 2003 21:59:53 -0700, Rajesh Dorairajan 
<[EMAIL PROTECTED]> wrote:

Can someone explain how does one pass a parameter to a Perl Module? To
illustrate suppose I've My::Module
package My::Module;

BEGIN
{
  $scalar = $input;
}
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = ($scalar);
In the above script is there anyway to pass the $input variable to the
package My::Module from the calling script? Please excuse me if the code 
is
horrible, just trying to simplify what I want ;)

TIA

Rajesh


--
With best regards,
Juris
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Perl - HowTo operating with large file?

2003-09-29 Thread Juris
Hi!

Thanks, your solution is one way how solve this problem! I found other ...

sub remove_ary_dupes{
my @[EMAIL PROTECTED];
#Define hash
undef %saw;
@[EMAIL PROTECTED] = ();
#Hash owerwrite automaticly duplicated values! ;)
my @out = sort keys %saw;  # remove sort if undesired
return @out;
}
sub grep_log_file{
my @[EMAIL PROTECTED];
#if (undef $sparam[0]) {print "No records found with @ARGV\n"; exit 0}
my ($first, $match);
my $block_size=20480;
my ($tmp_block, $pos_corect,@ary_match, @res_ary);
open(F, "$LOG_FILE") or die "Error opening $LOG_FILE: $!";

#Read LOG file block by block
while (read(F,$first,$block_size)) {
$end_pos=rindex($first,"\n");
# $first=~/(.*)\n(.*)$/; #Not used, because so slowly for long lines!
# Compare read line length with default block size!
# If not equal, its last block in cycle
   if (length($first) ne $block_size) {
$match=$first; $match = $tmp_block . $first;
$tmp_block=""; $pos_corect=0;
} else {
$match=substr($first,0, $end_pos); $match=$tmp_block . 
$match ;
$pos_corect=$block_size-$end_pos;  
$tmp_block=substr($first,$end_pos,$block_size-$end_pos);
}
 my @log_lines=split("\n",$match);
 ##Grep all lines
 @log_lines=remove_ary_dupes(@log_lines); #Remove duplicated log 
lines!
 foreach my $j (@sparam) {
 push @ary_match, (grep /$j/, @log_lines);
 }
 #push @res_ary, @ary_match;
}
close (F);
return @ary_match;
}

Try this code, if have similar problem!

On Fri, 26 Sep 2003 20:13:21 +0530, Ramprasad A Padmanabhan 
<[EMAIL PROTECTED]> wrote:

Juris wrote:
I have one small problem!
HowTo read from large text file text in binary mode?
if i want read all file, i use this code:

my (@LOG_FILE);
open (FL, "/var/log/maillog");
@LOG_FILE=;
close (FL);
#After this code execution file contents stored in array @LOG_FILE
@LOG_FILE=grep /$something/, @LOG_FILE
I not want read all file string by struing - it's so slowly, if file is 
large and contains more than 100 records!
I need read each 50 bytes, but how?
Please, help!




When you are opening big files never do
@array = 
This essentially reads the entire file into an array and is very 
expensive on memory.

you could do something like
while(){
push @arr , $_ if(/$something/);
}
But IMHO this still that may not be the best way.

What I would do is

system("grep $something $filename > $tempfile");
# *Nothing* beats gnu grep when you parse large file
open(FILE,$tempfile);
# Now if you really want the lines in an array
@lines = 
Ram
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Perl - HowTo operating with large file?

2003-09-26 Thread Juris
I have one small problem!
HowTo read from large text file text in binary mode?
if i want read all file, i use this code:

my (@LOG_FILE);
open (FL, "/var/log/maillog");
@LOG_FILE=;
close (FL);
#After this code execution file contents stored in array @LOG_FILE
@LOG_FILE=grep /$something/, @LOG_FILE
I not want read all file string by struing - it's so slowly, if file is 
large and contains more than 100 records!
I need read each 50 bytes, but how?
Please, help!

--
With best regards,
Juris
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: How to get the file name from a path

2003-09-25 Thread Juris
On Thu, 25 Sep 2003 12:10:15 +0530, Chetak Sasalu M 
<[EMAIL PROTECTED]> wrote:

Hi,
How can I extract "filename" from /root/dir1/.../filename
$path_name='/root/dir1/.../filename';
my $fname=substr($path, rindex($path,"/")+1,length($path)-rindex($path,"/")- 
1);
Cheers,
Chetak.
--
wbr,
Juris
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]