Re: Problem with scope in CGI script

2007-11-06 Thread Gunnar Hjalmarsson

John W . Krahn wrote:

On Sunday 04 November 2007 18:06, Mike Martin wrote:


sub run_cmd { return print


print() returns either true or false.  Why are you returning this value 
from your sub?



span( { -class = 'place_cmd' }, submit( -name = 'action',
-value = shift ) ), p };

...

run_cmd('entry');


The run_cmd() sub does not take any arguments.


Yes it does.

  -value = shift

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

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: regexp with capture of multiple lines matching a line pattern

2007-11-06 Thread Frank Bergemann
In case s.o. else will have the same problem.
Here's, how i solved it my way:

[...]
# storage for APN data (multiple lines)
my %APNdata;
my @APNarray;
[...]
APNID   PDPADDEQOSID  VPAA  PDPCHPDPTY  PDPID
(?:[ ]+(\\d+)(?{\$APNdata{'APNID'} = \$^N;})[ ]+(\\d+)(?{\
$APNdata{'EQOSID'} = \$^N;})[ ]+(NO|YES|MAYBE)(?{\$APNdata{'VPAA'} = \
$^N;})[ ]+(IPV4)(?{\$APNdata{'PDPTY'} = \$^N;})[ ]+(\\d+)(?{\
$APNdata{'PDPID'} = \$^N; push [EMAIL PROTECTED], {\%APNdata};})\\n)*
[...]

rgds!

Frank


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Get the byte position of previous line from last line in file

2007-11-06 Thread Gunnar Hjalmarsson

sivasakthi wrote:

I have the text file  as following,

this first line
this is the second line
this the third line
this is the fourth line
this is the sixth line
this is the seventh line

while opening and reading that text file, is it possible to get the byte
position of this is the sixth line ??


Jeff answered your question.

Assuming that your goal is to insert the missing fifth line, you may 
want to use this approach:


use Tie::File;
tie my @file, 'Tie::File', 'myfile' or die $!;
splice(@file, 4, 0, 'this is the fifth line');
untie @file;

perldoc Tie::File
perldoc -f splice

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

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Issue while calling the subroutine dynamically

2007-11-06 Thread Ab
I have a package with the following contents.
---
package abhinav::test;

use strict;
use warnings;

sub test1
{
return \nHello World;
}

sub test2
{
my ($include) = @_;
foreach my $row (@$include)
{
push (@$row, @$row[0] + 10);
}
return $include;
}

1;
---



Now, The thing I am trying to achieve is to call abhinav::test::test2
on the runtime.
ie, I am passing the value 'abhinav::test::test2' in a variable, and
trying to exec in the code below, and this place I am failing.
Can someone help me as to how to achieve this in runtime.
Thanks
---
use strict;
use abhinav::test;

my @arr = (['1','2'], ['3','4'], ['5','6'], ['7','8']);

print(\n --- ORIGINAL ARRAY ---\n);
foreach my $row (@arr) {
print(@$row);
print \n;
}

print(\n --- THIS IS A STATIC CALL ---\n);
my $arr = abhinav::test::test2([EMAIL PROTECTED]);
foreach my $row (@$arr) {
print(@$row);
print \n;
}


print(\n --- THIS IS A DYNAMIC CALL ---\n);
my $dyna_sub = 'abhinav::test::test2';
my @arr = (['1','2'], ['3','4'], ['5','6'], ['7','8']);
my $sub_str = $dyna_sub . '(' . [EMAIL PROTECTED] . ')';
my $arr = eval $sub_str;
print (\n -- ERRR -- $@ --\n);

foreach my $row (@$arr) {
print(@$row);
print \n;
}

---

-
Output of the above is as:
 --- ORIGINAL ARRAY ---
12
34
56
78

 --- THIS IS A STATIC CALL ---
1211
3413
5615
7817

 --- THIS IS A DYNAMIC CALL ---

 -- ERRR -- Undefined subroutine main::ARRAY called at (eval 1) line
1.
 --
-


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




How to get teh line before a last from file

2007-11-06 Thread sivasakthi
Hi All,

How to get the line before a last line from file?? 



Thanks,
Siva


Referencing a hash to be dereferenced...

2007-11-06 Thread Beach Cruise
I have an interesting issue that I am not able to seem to get around.

I have a function in a lib that we use that has two referenced
hashes.



my $zone   = $self-{'zone'};
my $params = $self-{'report-params'};
my %zone_list = ();

$count = $zone-generate_zone_list(\%zone_list,\%params);


--

sub generate_zone_list {
my ($self,$results_hash,$params) = @_;

my $sched_id = %{$params}-scheduleId();
my $filekey  = $filekey.$sched_id;
my $temp_file = /tmp/.bw3-temp-${filekey}.tmp;

return $temp_file;
}

This is what I would expect this to work. If I don't pass params as a
reference it works with the following line:
my $sched_id = $params-scheduleId();

Anyone have an idea what might be going on here?


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Problem with scope in CGI script

2007-11-06 Thread John W . Krahn
On Tuesday 06 November 2007 00:24, Gunnar Hjalmarsson wrote:
 John W . Krahn wrote:
  On Sunday 04 November 2007 18:06, Mike Martin wrote:
  sub run_cmd { return print
 
  print() returns either true or false.  Why are you returning this
  value from your sub?
 
  span( { -class = 'place_cmd' }, submit( -name = 'action',
  -value = shift ) ), p };
 
  ...
 
  run_cmd('entry');
 
  The run_cmd() sub does not take any arguments.

 Yes it does.

-value = shift

Oops!   Thanks Gunnar.


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: How to get teh line before a last from file

2007-11-06 Thread Paul Lalli
On Nov 6, 5:28 am, [EMAIL PROTECTED] (Sivasakthi) wrote:
 How to get the line before a last line from file??

Here's a few off the top of my head.  I'm sure there's more.

#1
open my $fh, '', $file or die $!;
my $before_last = ($fh)[-2];

#2
open my $fh, '', $file or die $!;
my ($last, $before_last);
while ($fh) {
   $before_last = $last;
   $last = $_;
}

#3
use File::ReadBackwards;
my $bw = File::ReadBackwards-new($file) or die $!
$bw-readline();
my $before_last = $bw-readline();


Paul Lalli


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Issue while calling the subroutine dynamically

2007-11-06 Thread John W . Krahn
On Tuesday 06 November 2007 00:40, Ab wrote:
 I have a package with the following contents.
 ---
 package abhinav::test;

 use strict;
 use warnings;

 sub test1
 {
   return \nHello World;
 }

 sub test2
 {
   my ($include) = @_;
   foreach my $row (@$include)
   {
   push (@$row, @$row[0] + 10);
 

That is properly written as:

push (@$row, $row-[0] + 10);


   }
   return $include;
 }

 1;
 ---



 Now, The thing I am trying to achieve is to call abhinav::test::test2
 on the runtime.
 ie, I am passing the value 'abhinav::test::test2' in a variable, and
 trying to exec in the code below, and this place I am failing.
 Can someone help me as to how to achieve this in runtime.
 Thanks
 ---
 use strict;
 use abhinav::test;

 my @arr = (['1','2'], ['3','4'], ['5','6'], ['7','8']);

 print(\n --- ORIGINAL ARRAY ---\n);
 foreach my $row (@arr) {
   print(@$row);
   print \n;
 }

 print(\n --- THIS IS A STATIC CALL ---\n);
 my $arr = abhinav::test::test2([EMAIL PROTECTED]);
 foreach my $row (@$arr) {
   print(@$row);
   print \n;
 }


 print(\n --- THIS IS A DYNAMIC CALL ---\n);
 my $dyna_sub = 'abhinav::test::test2';
 my @arr = (['1','2'], ['3','4'], ['5','6'], ['7','8']);
 my $sub_str = $dyna_sub . '(' . [EMAIL PROTECTED] . ')';

You are turning the reference to @arr into a string and it can't be 
turned back into a reference.


 my $arr = eval $sub_str;
 print (\n -- ERRR -- $@ --\n);

 foreach my $row (@$arr) {
   print(@$row);
   print \n;
 }

The proper way to do what you want is:

print \n --- THIS IS A DYNAMIC CALL ---\n;
my $dyna_sub = \abhinav::test::test2;
my @arr = ( [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], [ 7, 8 ] );
my $arr = $dyna_sub-( [EMAIL PROTECTED] );

foreach my $row ( @$arr ) {
print @$row, \n;
}



The way you want to do it should be:

print \n --- THIS IS A DYNAMIC CALL ---\n;
my $dyna_sub = 'abhinav::test::test2';
my @arr = ( [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], [ 7, 8 ] );

my $sub_str = $dyna_sub . '( [EMAIL PROTECTED] )';
# Or
# my $sub_str = $dyna_sub( [EMAIL PROTECTED] );

# You shouldn't use eval()
# see: perldoc -q How can I use a variable as a variable name
my $arr = eval $sub_str;

print \n -- ERRR -- $@ --\n if $@;

foreach my $row ( @$arr ) {
print @$row, \n;
}



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Referencing a hash to be dereferenced...

2007-11-06 Thread Paul Lalli
On Nov 5, 7:45 pm, [EMAIL PROTECTED] (Beach Cruise) wrote:
 I have an interesting issue that I am not able to seem to get around.

 I have a function in a lib that we use that has two referenced
 hashes.

 
 my $zone   = $self-{'zone'};
 my $params = $self-{'report-params'};
 my %zone_list = ();

 $count = $zone-generate_zone_list(\%zone_list,\%params);

Where did %params come from?  There is no such variable above.  Are
you not using strict (which would tell you when you use an undeclared
variable), or are you not showing us a relevant piece of your code?

%params and $params have absolutely nothing to do with each other.  At
all.   If $params is a reference to a hash, and you want to pass a
reference to that hash, just pass the reference you already have:
$count = $zone-generate_zone_list(\%zone_list, $params);

 sub generate_zone_list {
 my ($self,$results_hash,$params) = @_;

 my $sched_id = %{$params}-scheduleId();

This is wrong syntax.  I'm shocked (and disturbed) it works at all.
It should be:
$params-scheduleId();

 my $filekey  = $filekey.$sched_id;

This makes no sense.  You're declaring a variable on the left and
assigning it to be a string that results in part from the
concatenation of that variable on the right.  When the right side of
this is evaluated, $filekey does not exist (and therefore has no
value).  Again, strict would tell you when you make mistakes like
this.

 my $temp_file = /tmp/.bw3-temp-${filekey}.tmp;
 return $temp_file;

I don't understand the point of creating and storing a variable only
to then immediately return it.  Why not just return the value itself?

return /tmp/.bw3-temp-$filekey.tmp;

Paul Lalli


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Referencing a hash to be dereferenced...

2007-11-06 Thread Lawrence Statton
 I have a function in a lib that we use that has two referenced
 hashes.

No, you have a method in a class that has two referenced hashes.
Computers are frustratingly pedantic, and mastering the art requires
the same level of attention do detail at the human leve.

 
 
 
 my $zone   = $self-{'zone'};
 my $params = $self-{'report-params'};
 my %zone_list = ();
 
 $count = $zone-generate_zone_list(\%zone_list,\%params);

You should have gotten a warning here remarkably similar to:
 Global symbol %params requires explicit package name at /tmp/test.pl line 9. 
 

(unless you have some other variable named %params that you are not telling us 
about)

 --
 
 sub generate_zone_list {
   my ($self,$results_hash,$params) = @_;
 
   my $sched_id = %{$params}-scheduleId();
   my $filekey  = $filekey.$sched_id;
   my $temp_file = /tmp/.bw3-temp-${filekey}.tmp;
 
 return $temp_file;
 }
 
 This is what I would expect this to work. If I don't pass params as a
 reference it works with the following line:
 my $sched_id = $params-scheduleId();
 
 Anyone have an idea what might be going on here?
 

One can glean since $params-scheduleId() provides the response that
you want, that $params is an object, and you don't need to pass it by
reference.  (ALL objects in Perl are implemented as blessed references
to SOMETHING)

just call $count = $zone-generate_zone_list(\%zone_list, $params);

In other news $count is a terrible name for a variable that is going
to hold a filename.

--L



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Referencing a hash to be dereferenced...

2007-11-06 Thread Lawrence Statton
 
 No, you have a method in a class that has two referenced hashes.
 Computers are frustratingly pedantic, and mastering the art requires
 the same level of attention do detail at the human leve.
 level.


And exceent prufreeding skils.

-- 
Lawrence Statton - [EMAIL PROTECTED] s/aba/c/g
Computer  software  consists of  only  two  components: ones  and
zeros, in roughly equal proportions.   All that is required is to
place them into the correct order.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Referencing a hash to be dereferenced...

2007-11-06 Thread Paul Lalli
On Nov 6, 9:36 am, [EMAIL PROTECTED] (Lawrence Statton) wrote:
  I have a function in a lib that we use that has two referenced
  hashes.

 No, you have a method in a class that has two referenced hashes.
 Computers are frustratingly pedantic, and mastering the art requires
 the same level of attention do detail at the human leve.

Classes *are* libraries.  Methods *are* functions.

A class is simply a module that contains one or more subroutines which
function as methods.
A method is simply a function that expects either a class name or
blessed reference as its first argument.

What he said was correct.  What you said was simply more specific.

  my $zone   = $self-{'zone'};
  my $params = $self-{'report-params'};
  my %zone_list = ();

  $count = $zone-generate_zone_list(\%zone_list,\%params);

 You should have gotten a warning here remarkably similar to:
  Global symbol %params requires explicit package name at /tmp/test.pl line 
 9.  

1) that's a compilation error, not a warning.  What was it you said
about a pedantic level of detail?
2) That error will only be displayed if the OP is using strictures.
Nothing in his post indicates that he is.

 One can glean since $params-scheduleId() provides the response that
 you want, that $params is an object, and you don't need to pass it by
 reference.

This is nonsensical.  ALL subroutines in perl are passed by
reference.  I think you meant You do not need to pass a reference to
it, which is remarkably different.  There's that less than pedantic
attention to detail again...

Paul Lalli


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Issue while calling the subroutine dynamically

2007-11-06 Thread Chas. Owens
On 11/6/07, Ab [EMAIL PROTECTED] wrote:
snip
 Now, The thing I am trying to achieve is to call abhinav::test::test2
 on the runtime.
 ie, I am passing the value 'abhinav::test::test2' in a variable, and
 trying to exec in the code below, and this place I am failing.
 Can someone help me as to how to achieve this in runtime.
snip

The String version of eval is the wrong method to choose.   If you
want to execute functions at runtime you want a dispatch table.  These
are commonly implemented in Perl as a hash whose keys are the names of
the subroutines you want to be able to call and the values are
references to the subroutines.  In your case it should look something
like this:

my %dispatch = (
'abhinav::test::test1' = \abhinav::test::test1,
'abhinav::test::test2' = \abhinav::test::test2,
);

my $dyna_sub = 'abhinav::test::test2';
my @arr = ([1, 2], [3, 4], [5, 6], [7, 8]);
die could not find $dyna_sub to dispatch unless $dispatch{$dyna_sub};
my $arr = $dispatch{$dyna_sub}-(@arr);

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Referencing a hash to be dereferenced...

2007-11-06 Thread Paul Lalli
On Nov 6, 12:55 pm, [EMAIL PROTECTED] (Chas. Owens) wrote:
 On 11/6/07, Paul Lalli [EMAIL PROTECTED] wrote:
 snip  my $filekey  = $filekey.$sched_id;

  This makes no sense.  You're declaring a variable on the left and
  assigning it to be a string that results in part from the
  concatenation of that variable on the right.  When the right side of
  this is evaluated, $filekey does not exist (and therefore has no
  value).  Again, strict would tell you when you make mistakes like
  this.

 snip

 Since it looks like he/she is not using strict, that line could make
 sense if there is a global variable named $filekey that has a value.
 It is still a bad idea though.

 #!/usr/bin/perl

 use warnings;

 $foo = Hello;
 my $foo = $foo .  World;
 print foo is $foo main::foo is $main::foo\n;

shudder  I didn't think about that.  Thanks for pointing it out.
And if that's really what's happening ysh.

Paul Lalli


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Referencing a hash to be dereferenced...

2007-11-06 Thread Paul Lalli
On Nov 6, 12:55 pm, [EMAIL PROTECTED] (Chas. Owens) wrote:
 On 11/6/07, Paul Lalli [EMAIL PROTECTED] wrote:
 snip  my $filekey  = $filekey.$sched_id;

  This makes no sense.  You're declaring a variable on the left and
  assigning it to be a string that results in part from the
  concatenation of that variable on the right.  When the right side of
  this is evaluated, $filekey does not exist (and therefore has no
  value).  Again, strict would tell you when you make mistakes like
  this.

 snip

 Since it looks like he/she is not using strict, that line could make
 sense if there is a global variable named $filekey that has a value.
 It is still a bad idea though.

 #!/usr/bin/perl

 use warnings;

 $foo = Hello;
 my $foo = $foo .  World;
 print foo is $foo main::foo is $main::foo\n;

shudder  I didn't think about that.  Thanks for pointing it out.
And if that's really what's happening ysh.

Paul Lalli


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Referencing a hash to be dereferenced...

2007-11-06 Thread Chas. Owens
On 11/6/07, Paul Lalli [EMAIL PROTECTED] wrote:
snip
  my $filekey  = $filekey.$sched_id;

 This makes no sense.  You're declaring a variable on the left and
 assigning it to be a string that results in part from the
 concatenation of that variable on the right.  When the right side of
 this is evaluated, $filekey does not exist (and therefore has no
 value).  Again, strict would tell you when you make mistakes like
 this.
snip

Since it looks like he/she is not using strict, that line could make
sense if there is a global variable named $filekey that has a value.
It is still a bad idea though.

#!/usr/bin/perl

use warnings;

$foo = Hello;
my $foo = $foo .  World;
print foo is $foo main::foo is $main::foo\n;

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




XP UDP broadcast

2007-11-06 Thread kenTk
I am posting this problem and the solution to spread the news a little
about a nasty bug in XP.

PROBLEM
I have a Perl (activestate) 5.8.8 script that uses IO::Socket::INET;
and opens a broadcast UDP socket. The packets are received
successfully by another host running a similar script as long as I run
the sending script on windows2000. They fail to arrive when sent by
the identical script running on an XP host. A packet sniffer shows
that the packets are indeed broadcast but with an incorrect header
checksum and therefore the receiving host rejects them at socket
level.

SOLUTION (Work-around)
The packet header sumcheck corruption only occurs when the payload has
more than the  MTU bytes. Chopping the payload in to chunks that each
are shorter than the MTU and sending them  separately fixes it.

For information the socket is opened in non-blocking mode as follows:

use IO::Socket::INET;
sub openSock
{
 my $remoteIP=255.255.255.255;
 ${$_[0]}=new IO::Socket::INET-new(
   PeerPort=$_[1],
   Proto='udp',
   PeerAddr=$remoteIP,
   Broadcast = 1)

  my $temp = 1;
  ioctl (${$_[0]}, 0x8004667E, \$temp); # set non-blocking on windoze
}


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




simplest of simple web servers

2007-11-06 Thread Willy West
just the simplest webserver one can imagine.

I made a POE web server a long time ago and it was fun.  I've long
since lost that code.

Anyway, I'd like to make a perl webserver as simply as possible so
that I can play with dynamic web pages without configuring apache
everywhere I go..  actually a webserver in a USB key would be fun :)

I figured that I'd come here to see which directions I could go to
start off and where I should avoid going.

  thank you much

-- 
Willy

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: simplest of simple web servers

2007-11-06 Thread Tom Phoenix
On 11/6/07, Willy West [EMAIL PROTECTED] wrote:

 Anyway, I'd like to make a perl webserver as simply as possible so
 that I can play with dynamic web pages without configuring apache
 everywhere I go..  actually a webserver in a USB key would be fun :)

 I figured that I'd come here to see which directions I could go to
 start off and where I should avoid going.

Have you seen what's available on CPAN?

http://search.cpan.org/

Cheers!

--Tom Phoenix
Stonehenge Perl Training

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: simplest of simple web servers

2007-11-06 Thread Jeff Pang
Writting a webserver by yourself is not so easy I have to say.
You must know well about http protocal handling and http connection status.
Lincoln Stein has made a simple web server in his book network programming 
with perl, you may take that as a reference.


-Original Message-
From: Willy West [EMAIL PROTECTED]
Sent: Nov 7, 2007 9:38 AM
To: beginners@perl.org
Subject: simplest of simple web servers

just the simplest webserver one can imagine.

I made a POE web server a long time ago and it was fun.  I've long
since lost that code.

Anyway, I'd like to make a perl webserver as simply as possible so
that I can play with dynamic web pages without configuring apache
everywhere I go..  actually a webserver in a USB key would be fun :)

I figured that I'd come here to see which directions I could go to
start off and where I should avoid going.

  thank you much

-- 
Willy

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Reading the file using tell and seek method

2007-11-06 Thread sivasakthi
Hi All,


I have one requirement, the file content is following, it is a dynamic
file,

1194240905.451105 127.0.4.56 TCP_MISS/200 2853 GET
cache_object://localhost/info - NONE/- text/plain
1194240905.452  0 127.0.0.1 TCP_MISS/200 2853 GET
cache_object://localhost/info - NONE/- text/plain
1194240905.452  0 127.0.0.1 TCP_MISS/200 2853 GET
cache_object://localhost/info - NONE/- text/plain


First time read the full file, then store byte position of the line
before the last line read and last line time stamp(eg: 1194240905.452)
in to one temporary file.

next time first open the temporary file and get the position,time stamp.
open the file and seek the position of last time read and get time stamp
of current line, after comparing that time stamp with already stored
time stamp, if both are equal then doing some calculation..


I have tried as below, but it not works well,

#!/usr/bin/perl
use strict;
use warnings;
use Tie::File;

my($name,$pos,$name1,$no,$tmpp,$tmp);
my $file=/file/path;
open(FH,temp.txt);
while(FH)
{
($pos,$name1)=split;
}
close FH;
tie my @file, 'Tie::File', 'test.txt' or die $!;
my $length=$#file + 1;
untie @file;
open(FH,$file);
seek(FH,$pos,0);
while(FH) {
($Ltimestamp,$Lelapsed,$Lhost,$Ltype,$Lsize,$Lmethod,$Lurl,$Luser,
$Lhierarchy,$Lconttype)=split;
 if(($Ltimestamp eq $name1)
{
   #some calculation
}
if($.== ($length-1))
{
$tmpp=$_;
}
}
my ($na,$num)=split( ,$tmpp);
$pos=tell(FH) if/^$na/;
close FH;
open(FH,temp.txt);
print FH $pos $na;
close FH;




Re: simplest of simple web servers

2007-11-06 Thread Willy West
 http://search.cpan.org/

 Cheers!

 --Tom Phoenix
 Stonehenge Perl Training


Well of course!  *laugh*  funny how staring at a book for hours on end
addles the brain.


http://search.cpan.org/~jesse/HTTP-Server-Simple-0.27/lib/HTTP/Server/Simple.pm

seems to have what I want.  it will take time to play with it, but
that's fine.  This will let me learn/improve my CGI programming
without bothering with Apache or what have you until I am ready to/
want to do so.


Hmmm.  It's been a long time since I've posted here.  I really should
try to be more active.


Thank you, each of you who responded.

-- 
Willy

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Reading the file using tell and seek method

2007-11-06 Thread sivasakthi
Sorry..the actual tried coding is following,

#!/usr/bin/perl
use strict;
use warnings;
use Tie::File;

my ($Ltimestamp,$Lelapsed,$Lhost,$Ltype,$Lsize,$Lmethod,$Lurl,$Luser,
$Lhierarchy,$Lconttype);
my($name,$pos,$name1,$no,$tmp,$Ltimestamp1);
our $tmpp;
my $file=/file/path;
open(FH,tmp.txt) || die can't open the file\n;
while(FH)
{
($pos,$name1)=split;
}
close FH;
print position : $pos\n;
tie my @file, 'Tie::File', 'test.txt' or die $!;
my $length=$#file + 1;
untie @file;
open(FH,$file) || die can't open the file\n;
seek(FH,$pos,0);
while(FH) {
($Ltimestamp,$Lelapsed,$Lhost,$Ltype,$Lsize,$Lmethod,$Lurl,$Luser,
$Lhierarchy,$Lconttype)=split;
 if($Ltimestamp eq $name1)
{
   #do some calculations
}
if($.== ($length-1))
{
$tmpp=$_;
}
}
($Ltimestamp1,$Lelapsed,$Lhost,$Ltype,$Lsize,$Lmethod,$Lurl,$Luser,
$Lhierarchy,$Lconttype)=split( ,$tmpp);
$pos=tell(FH) if/^$$Ltimestamp1/;
close FH;
open(FH,tmp.txt) || die can't open the file\n;
print FH $pos $$Ltimestamp1;
close FH;


On Wed, 2007-11-07 at 10:38 +0530, sivasakthi wrote:

 Hi All,
 
 
 I have one requirement, the file content is following, it is a dynamic
 file,
 
 1194240905.451105 127.0.4.56 TCP_MISS/200 2853 GET
 cache_object://localhost/info - NONE/- text/plain
 1194240905.452  0 127.0.0.1 TCP_MISS/200 2853 GET
 cache_object://localhost/info - NONE/- text/plain
 1194240905.452  0 127.0.0.1 TCP_MISS/200 2853 GET
 cache_object://localhost/info - NONE/- text/plain
 
 
 First time read the full file, then store byte position of the line
 before the last line read and last line time stamp(eg: 1194240905.452)
 in to one temporary file.
 
 next time first open the temporary file and get the position,time
 stamp. open the file and seek the position of last time read and get
 time stamp of current line, after comparing that time stamp with
 already stored time stamp, if both are equal then doing some
 calculation..
 
 
 I have tried as below, but it not works well,