Re: shift oo

2011-03-23 Thread Peter Scott
On Tue, 22 Mar 2011 13:41:59 -0700, Randal L. Schwartz wrote:

>> "Peter" == Peter Scott  writes:
> 
>>> my $s = Streamer->new;
>>> my $app = sub {
>>> return sub {
>>> $s->open_fh;
>>> my $writer = shift->(
>>> [ 200, [ "Content-type" => "text/plain" ], $s ] );
>>> };
>>> };
> 
> Peter> As it stands, this doesn't make sense because nothing happens to
> $writer; Peter> so why create it?
> 
> I presume you're objecting to the explicit $writer.  Certainly, the
> value of $writer is also the return value of the inner subroutine, so
> that *is* something that could be noted:

Right, the superfluous naming of $writer leads to a lot of head-
scratching.  Best guess (if this is an accurate post of the code), that 
there was originally some debugging/logging code in there before a 
"return $writer" that got taken out.  Although I supposed that the paste 
was incomplete.  Either way, a giant red herring.

-- 
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl3/

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: foreach loop

2011-03-23 Thread Jim Gibson
On 3/23/11 Wed  Mar 23, 2011  12:49 PM, "Chris Stinemetz"
 scribbled:

> Jim,
> 
> I have another question.
> 
> How do I sort the results so it is from smallest to largest starting with
> $cell,$sect,$carr?

It is difficult to sort a multi-level, nested hash. I would transfer the
values to an array-of-arrays and sort that:

#!/usr/local/bin/perl

use warnings;
use strict;

my %sum;
while (){
next unless /;/;
  chomp;
  my @data = split /;/;
  my($cell,$sect,$chan,$carr,$rlptxat1,$dist,$precis) =
  @data[31,32,38,39,44,261,262];
  $sum{$cell}{$sect}{$chan} += $rlptxat1 || 0;
}

my @data;
for my $cell ( sort keys %sum ) {
  for my $sect ( sort keys %{$sum{$cell}} ) {
for my $chan ( sort keys %{$sum{$cell}{$sect}} ) {
  push( @data, [ $sum{$cell}{$sect}{$chan}, $cell, $sect, $chan ]);
}
  }
}

for my $record ( sort { $a->[0] <=> $b->[0] } @data ) {
my( $val, $cell, $sect, $chan ) = @$record;
print "The value of ($cell,$sect,$chan) is $val\n";
}



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Twisting Text

2011-03-23 Thread John W. Krahn

Emeka wrote:

Hello All,


Hello,


I have a file containing dictionary of words ... I would like to play with
the file in this way.  Say I pick a word "Heaves" . I would like to find
other words that could be derive from
"Heaves"

Have, Haves, eave , eaves, Has, see, eves and so on. I would not want to use
brute force , I have an algorithm to speed things up. Can somebody help me?


$ perl -lne'
BEGIN {
$word = lc "Heaves";
$pattern  = qr/\A[$word]{1,@{[ length $word ]}}\z/;
}

print if lc =~ $pattern;

' /usr/share/dict/words  | cat -n
 1  A
 2  As
 3  Ashe
 4  Av
 5  Ava
 6  Ave
 7  Aves
 8  E
 9  Es
10  Eva
11  Eve
12  H
13  Haas
14  He
15  Hess
16  Hesse
17  S
18  Sasha
19  Se
20  Shea
21  V
22  Va
23  a
24  ah
25  aha
26  ahas
27  as
28  ash
29  ashes
30  ass
31  asses
32  assess
33  e
34  ease
35  eases
36  eave
37  eaves
38  eh
39  es
40  eve
41  eves
42  h
43  ha
44  hah
45  hahs
46  has
47  hash
48  hashes
49  have
50  haves
51  he
52  heave
53  heaves
54  hes
55  s
56  sash
57  sashes
58  sass
59  sasses
60  save
61  saves
62  sea
63  seas
64  see
65  sees
66  sh
67  shah
68  shahs
69  shave
70  shaves
71  she
72  sheave
73  shes
74  v
75  vase
76  vases
77  vs




John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Twisting Text

2011-03-23 Thread Greg J
Emeka,

What you are looking for is a word stemmer.  You might want to take a look
at something like Porter Stemmer.

-Greg


On Wed, Mar 23, 2011 at 5:35 PM, Emeka  wrote:

> Hello All,
>
> I have a file containing dictionary of words ... I would like to play with
> the file in this way.  Say I pick a word "Heaves" . I would like to find
> other words that could be derive from
> "Heaves"
>
> Have, Haves, eave , eaves, Has, see, eves and so on. I would not want to
> use
> brute force , I have an algorithm to speed things up. Can somebody help me?
>
> Regards,
> Emeka
> --
> *Satajanus  Nig. Ltd
>
>
> *
>


Re: Re:must 'x' in g^x be a prime number

2011-03-23 Thread fakessh @
i paste a discussion to openssl-users

how to implement this attack in perl


Le mercredi 23 mars 2011 à 09:13 +0800, Ziyu Liu a écrit :
> 1)The exponent x in DH can be any number.It should be big enough to 
> bear attack.The source in DH told us what exponent  x can be.
> ref:dh_key.c
> if (generate_new_key)
> {
> l = dh->length ? dh->length : BN_num_bits(dh->p)-1; /* secret
> exponent length */
> if (!BN_rand(priv_key, l, 0, 0)) goto err;
> }
> 2)The time of generation depends the length of your DH parameters.The
> longger parameters you created, the more time you need to compute the
> value.
> ref:
> int DH_generate_parameters_ex(DH *dh, int prime_len,int generator,
> BN_GENCB *cb);
> 
> 
> At 2011-03-23 08:12:37,ikuzar  wrote:
> Hello, 
> I 'd like to know  :
> 1) if exponent x in g^x must be a great prime number. In some
> docs I saw, it is said that x must b a GREAT number but no
> information about primality ..
> 2) May generation of 'x' run for hours like related here :
> http://www.openssl.org/docs/crypto/DH_generate_parameters.html
> ( in NOTES)
> Thanks for your help.
> 
> 
> 
-- 
gpg --keyserver pgp.mit.edu --recv-key 092164A7
http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x092164A7


signature.asc
Description: Ceci est une partie de message	numériquement signée


Twisting Text

2011-03-23 Thread Emeka
Hello All,

I have a file containing dictionary of words ... I would like to play with
the file in this way.  Say I pick a word "Heaves" . I would like to find
other words that could be derive from
"Heaves"

Have, Haves, eave , eaves, Has, see, eves and so on. I would not want to use
brute force , I have an algorithm to speed things up. Can somebody help me?

Regards,
Emeka
-- 
*Satajanus  Nig. Ltd


*


Re: shift oo

2011-03-23 Thread Brandon McCaig
On Fri, Mar 18, 2011 at 5:34 PM, shawn wilson  wrote:
> sorry, i don't know how to do any better in gmail (and does it different on
> the gmail app on my android too - sorta messed up). should i color replies
> differently or something?

Quoting is typically done by prefixing each line of the quoted text
with "> ". Most mailers (including Gmail's Web interface) will do this
for you. Since you even suggested sending colored text I'm going to
assume that you are sending G-mail's default, which will probably end
up being whichever format is capable of sending your message (i.e.,
HTML, if necessary). Looking at the original raw message that I'm
responding to (and quoting) it appears that Gmail sent the E-mail as a
multipart/alternative, which is apparently used to send multiple
copies of the same E-mail in different formats. The only format that I
received appears to be text so I don't really understand why it would
do that... In any case, I can only assume that your quoting problems
are related to this. Either that, or you're screwing it up from your
phone. ;)

I personally use Gmail (most of the time) too, but to my knowledge my
E-mails are sent as I expected them to be (with the occasional
unintended wrapping of code if I forget to count my columns). You can
configure Gmail to send plain-text E-mails in its configuration
settings. It actually works out because as it turns out alternative
formats are evil. ;D

-- 
Brandon McCaig  
V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
Castopulence Software  

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: foreach loop

2011-03-23 Thread Chris Stinemetz
Jim,

I have another question.

How do I sort the results so it is from smallest to largest starting with 
$cell,$sect,$carr?

Thanks again for all you help. I am gaining a much better understanding.

This is what I got:

#!/usr/bin/perl

use warnings;
use strict;


#my $filepath = 'C:/temp/PCMD';
#my $filepath = 'C:/cygwin/home/cstinemetz/perl_programs/1.EVDOPCMD';
# my $outfile  = 'output.txt';

#open my $fh, '<', $filepath or die "ERROR opening $filepath: $!";
# open my $out, '>', $outfile or die "ERROR opening $outfile: $!";

my %sum;
#my @records = ();

while (){

next unless /;/;
chomp;
my @data = split /;/;

my($cell,$sect,$chan,$carr,$rlptxat1,$rlptxat2,$rlptxat3,$rlptxat4,$dist,$precis)
 = @data[31,32,38,39,44,45,46,47,261,262];

$carr = 
( $chan == 75 )   ? 2 : 
( $chan == 1025 ) ? 2 : 1 ; #nested ternary operator

$dist = 
( length( $dist ) > 1 ) ? $dist/6.6/8/2*10/10 : 0 ;


$sum{$cell}{$sect}{$carr}{$dist} += $rlptxat1 += $rlptxat2 += $rlptxat3 
+= $rlptxat4 || 0 ; }

for my $cell ( sort keys %sum ) {
for my $sect ( sort keys %{$sum{$cell}} ) {
for my $carr ( sort keys %{$sum{$cell}{$sect}} ) {
for my $dist ( sort keys 
%{$sum{$cell}{$sect}{$carr}} ) {
print "$cell\t $sect\t $carr\t $dist\t" .
$sum{$cell}{$sect}{$carr}{$dist} . "\n";
}
}
}
}

And this is the current output:

10   2   1   0.710227272727273  439
100  1   1   0  469
100  2   1   0  3207
101  3   1   0  96
102  3   1   0  1623
107  1   1   0  48
109  2   1   0  49
11   2   1   0  48
110  3   1   0.681818181818182  49
114  3   1   0  48
121  2   1   2.78409090909091   3628


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: shift oo

2011-03-23 Thread Brandon McCaig
You still seem a bit confused so lets try to start over straight
to the point:

On Fri, Mar 18, 2011 at 4:31 PM, shawn wilson  wrote:
> i ran across a peace of interesting code:
>
> my $writer = shift->(
>  [ 200, [ "Content-type" => "text/plain" ], $s ]
> );

To understand just this piece of code, ignore where it came from
and lets fill in the blanks with something simpler.

bamccaig@castopulence:~$ cat | perl
#!/usr/bin/env perl

use strict;
use warnings;

use Data::Dumper;

sub foo
{
my ($array_ref) = @_;
my ($status, $headers, $blah) = @{$array_ref};

return {
status => $status,
headers => $headers,
blah => $blah
};
}

sub bar
{
# The original code was this (wrapped for readability):
#   my writer = shift->(
#   [200, ['Content-Type' => 'text/plain'], $s]);
#
# Lets create an arbitrary $s (understanding this snippet
# doesn't require knowing what $s actually is).
my $s = 5;

# As seen in previous posts, shift->(...) is shifting @_
# and dereferencing the first argument as a subroutine.
# Let's explicitly shift into a variable for clarity.
my $foo = shift @_;

# The dereferenced subroutine was passed an array reference,
# the array of which contained a number, another array
# reference, and whatever $s is. For clarity, lets assign
# that array reference to a variable too.
my $arg = [200, ['Content-Type', 'text/plain'], $s];

# Now we finally get to see what's happening with all of
# the clutter removed. A subroutine reference, $foo, is
# being called with the argument, $arg.
my $writer = $foo->($arg);

# $sub_ref->() can also be written as &{$sub_ref}(), so this
# is the same as the previous statement (albeit, less
# readable):
my $writer2 = &{$foo}($arg);

# Finally, print what the result is so you can see for
# yourself. It isn't the original array reference passed to
# the dereferenced subroutine, but whatever that subroutine
# decided to return. In my case, I transformed the array
# reference into a hash reference.
print Dumper $writer2;
}

sub bar2
{
# Now that we understand how the code works, let's see it in
# action as it was originally written. Again, we'll replace
# $s with a random scalar since we still don't care what it
# actually is.
my $s = 5;

my $writer = shift->(
[200, ['Content-Type' => 'text/plain'], $s]);

print Dumper $writer;
}

print "bar:\n\n";

# We've seen that bar expects a subroutine reference as the first
# argument, so that's what we're going to give it.
bar \&foo;

print "\nbar2:\n\n";

# Again, we pass in a reference too our subroutine, foo.
bar2 \&foo;

__END__
bar:

$VAR1 = {
  'blah' => 5,
  'headers' => [
 'Content-Type',
 'text/plain'
   ],
  'status' => 200
};

bar2:

$VAR1 = {
  'blah' => 5,
  'headers' => [
 'Content-Type',
 'text/plain'
   ],
  'status' => 200
};
bamccaig@castopulence:~$


HTH.


-- 
Brandon McCaig  
V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
Castopulence Software  

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: foreach loop

2011-03-23 Thread Chris Stinemetz
That worked! Thanks Jim.

Chris

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: foreach loop

2011-03-23 Thread Jim Gibson
On 3/23/11 Wed  Mar 23, 2011  10:02 AM, "Chris Stinemetz"
 scribbled:

In addition to the missing semicolon, the declaration of %sum must appear
before it is used, i.e. before the while() loop. The line adding
values of $rlptxat1 to the sum must appear inside the while loop, not after
it.

Run this program on your data:

#!/usr/local/bin/perl

use warnings;
use strict;

my %sum;
while (){

  next unless /;/;
  chomp;
  my @data = split /;/;
  my($cell,$sect,$chan,$carr,$rlptxat1,$dist,$precis) =
  @data[31,32,38,39,44,261,262];

  $sum{$cell}{$sect}{$chan} += $rlptxat1 || 0;
}

for my $cell ( sort keys %sum ) {
  for my $sect ( sort keys %{$sum{$cell}} ) {
for my $chan ( sort keys %{$sum{$cell}{$sect}} ) {
  print "Value of sum($cell,$sect,$chan) is " .
$sum{$cell}{$sect}{$chan} . "\n";
}
  }
}



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: foreach loop

2011-03-23 Thread Chas. Owens
On Mon, Mar 21, 2011 at 01:46, Mike McClain  wrote:
snip
>> > my @report = map
>> > "$_->{cell}\t$_->{sect}\t$_->{carr}\t$_->{chan}\t$_->{dist}\n" , @sorted;
>> > print @report ;
>>
>> This map will consume a lot of memory, better do it using a foreach loop.
>
> In what way will the use of map here use any more memory than a foreach loop?
snip

The problem is that map returns a list.  That list will exist in
memory as you copy it to @report.  Just before the assignment is
finished, you will be using twice the amount of memory you expect.
Perl doesn't tend to return memory to the system, so, even though no
variable is using it, the memory used to hold the list will still be
held by perl.  Happily, perl will reuse the memory, so, as long as it
isn't huge, it normally isn't a big deal.



-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: foreach loop

2011-03-23 Thread Jim Gibson
On 3/23/11 Wed  Mar 23, 2011  10:02 AM, "Chris Stinemetz"
 scribbled:

> Thanks Jim,
> 
> I am still unable to sum up the field $rlptxat.
> 
> The error I am getting is below:
> 
> Scalar found where operator expected at ./jim.pl line 52, near "$sum"
> (Missing semicolon on previous line?)



> my %sum

The above line needs a semicolon.

Please reduce the size of your posts. Maybe shorten the data by including
fewer rows and columns. The concepts will still be the same. Thanks.



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: foreach loop

2011-03-23 Thread Chris Stinemetz
Thanks Jim,

I am still unable to sum up the field $rlptxat.

The error I am getting is below:

Scalar found where operator expected at ./jim.pl line 52, near "$sum"
(Missing semicolon on previous line?)
"my" variable %sum masks earlier declaration in same scope at ./jim.pl line 54.
"my" variable %sum masks earlier declaration in same statement at ./jim.pl line 
55.
"my" variable $cell masks earlier declaration in same statement at ./jim.pl 
line 55.
"my" variable %sum masks earlier declaration in same scope at ./jim.pl line 56.
"my" variable $cell masks earlier declaration in same scope at ./jim.pl line 56.
"my" variable $sect masks earlier declaration in same scope at ./jim.pl line 56.
"my" variable %sum masks earlier declaration in same scope at ./jim.pl line 58.
"my" variable $cell masks earlier declaration in same scope at ./jim.pl line 58.
"my" variable $sect masks earlier declaration in same scope at ./jim.pl line 58.
"my" variable $chan masks earlier declaration in same scope at ./jim.pl line 58.
syntax error at ./jim.pl line 52, near "$sum"
Global symbol "%sum" requires explicit package name at ./jim.pl line 52.
Global symbol "$cell" requires explicit package name at ./jim.pl line 52.
Global symbol "$sect" requires explicit package name at ./jim.pl line 52.
Global symbol "$chan" requires explicit package name at ./jim.pl line 52.
Global symbol "$rlptxat" requires explicit package name at ./jim.pl line 54.
Execution of ./jim.pl aborted due to compilation errors.

My code is as follows:

#!/usr/bin/perl

use warnings;
use strict;

my @records = ();

while (){

next unless /;/;
chomp;
my @data = split /;/;
my($cell,$sect,$chan,$carr,$rlptxat1,$dist,$precis) = 
@data[31,32,38,39,44,261,262];

$carr =
( $chan == 75 )   ? 2 :
( $chan == 1025 ) ? 2 : 1 ; #nested ternary operator

$dist =
( length( $dist ) > 1 ) ? $dist/6.6/8/2*10/10 : '' ;

push @records, {
cell=> $cell,
sect=> $sect,
carr=> $carr,
chan=> $chan,
RTD => $dist,
RLP1=> $rlptxat1,
Precis  => $precis,
};
}

my @sorted = sort {
$a->{cell} <=> $b->{cell} ||
$a->{sect} <=> $b->{sect} ||
$a->{carr} <=> $b->{carr}
  } @records ;

my %sum

$sum{$cell}{$sect}{$chan} += $rlptxat

for my $cell ( sort keys %sum ) {
for my $sect ( sort keys %{$sum{$cell}} ) {
for my $chan ( sort keys %{$sum{$cell}{$sect}} ) {
print "Value of sum($cell,$sect,$chan) is " .
$sum{$cell}{$sect}{$chan} . "\n";
}
}
}

__DATA__
PACE | EVDOPCMD | 33.0 | 101218 | 07 |
8;1023240136;1218;0;1;00a01a2bcdc7;0310003147702376;ac016d4a;;;5.6.128.8;0;43234169;43234349;;;1;1;1;;0;;19;5.6.128.22;172.30.151.5;304;3;304;3;15;175;15;175;15;175;1;1798;1251;0;0;2;19;20;1;1;1;0;128;5.6.128.8;;;301;5.6.128.8;;;8;304;31;43244037;;;1;18;43234169;01;;43234416;0;0;304;3;21;19;175;15;405;1;1;1;1;0;125;1||
8;1023240137;1218;0;1;00a01db74ace;;ac0174ca;43243423;1678442111;5.6.128.8;1;0;;43242544;43244207;43243423;43243647;;;1000;1;1;;0;;19;5.6.128.26;;372;2;372;2;;43243012;0;43243562;15;175;15;175;15;175;1;5;48;19;20;49;50;;0;1;2;0;68;5.6.128.8;;;301;5.6.128.8;;;8;372;21;43244207;;;1;18;43243423;01;;43242544;0;0;372;2;21;19;175;15;177;3;1;0;0;0;68;1|43243753;0;0;372;2;21;19;175;15;177;3;1;1;1;0;71;1|
8;1023240138;1218;0;1;00a02017ccdb;0310003147833882;aca344d7;;;5.6.128.13;0;43234160;43234358;;;1;1;1;;0;;19;5.6.128.31;172.30.151.5;320;2;320;2;15;75;15;75;15;75;1;2162;1317;0;0;2;19;20;1;1;1;0;104;5.6.128.13;;;306;5.6.128.13;;;8;320;21;43244164;;;1;18;43234160;01;;43234404;0;0;320;2;21;19;75;15;279;6;1;1;1;0;64;1||
8;1023240139;1218;0;1;00a109237b21;0310003147774000;aca3141e;;;5.6.128.13;0;43235644;43235820;;;9000;1;1;;0;;19;5.6.128.19;172.30.151.5;502;1;502;1;15;175;15;175;15;175;1;48;79;0;0;2;19;20;1;1;1;0;124;5.6.128.13;;;306;5.6.128

Re: Need Help. .Issue with format statement

2011-03-23 Thread Chas. Owens
On Wed, Mar 23, 2011 at 08:47, Sudhir  wrote:
> My work environment recently shifted from perl v5.6 to perl v5.10
>
> I found one issue with perl format statement in latest version v5.10
>
> sample code:
>
> #!/bin/env perl
> use strict;
>
> &genRep();
>
> sub genRep
> {
> format DURATION_TOP =
> @<<<
> "This is TOP"
> ---
> .
> format DURATION =
> @<<<
> "Main Body"
> .
> $~ = 'DURATION';
> write;
> }
>
> Output in perl v5.6:
> This is TOP
> ---
> Main Body
>
> output in perl v5.10
> Main Body
>
>
> What should I do in v5.10 to get the old output?
snip

I don't have 5.6 laying around, but it looks like 5.12 (and I assume
5.10) will do the right thing if the file is open:

#!/usr/bin/perl

use strict;

#create an in memory file to test if the problem is
#the lack of a filehandle
open DURATION, ">", \my $output or die $!;

&genRep();

print $output;


sub genRep
{
format DURATION_TOP =
@<<<
"This is TOP"
---
.
format DURATION =
@<<<
"Main Body"
.
write DURATION;
}

You could also fix it with fewer steps by dup'ing STDOUT to DURATION
if you weren't already opening DURATION:

#!/usr/bin/perl

use strict;

open DURATION, ">&", \*STDOUT or die $!;

&genRep();

sub genRep
{
format DURATION_TOP =
@<<<
"This is TOP"
---
.
format DURATION =
@<<<
"Main Body"
.
write DURATION;
}


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Perl packet tracking module

2011-03-23 Thread Olof Johansson
On 2011-03-23 09:05 -0700, Parag Kalra wrote:
> Hi,
> 
> Does Perl have any packet tracking module equivalent to tcpdump, snoop,
> tshark or tethereal

Check out Net::Pcap...

-- 
- Olof Johansson
-  www:  http://www.stdlib.se/
-  {mail,xmpp}:  o...@ethup.se
-  irc:  zibri on Freenode/OFTC/IRCnet/...
--


signature.asc
Description: Digital signature


Perl packet tracking module

2011-03-23 Thread Parag Kalra
Hi,

Does Perl have any packet tracking module equivalent to tcpdump, snoop,
tshark or tethereal

TIA

~Parag


Need Help. .Issue with format statement

2011-03-23 Thread Sudhir
My work environment recently shifted from perl v5.6 to perl v5.10

I found one issue with perl format statement in latest version v5.10

sample code:

#!/bin/env perl
use strict;

&genRep();

sub genRep
{
format DURATION_TOP =
@<<<
"This is TOP"
---
.
format DURATION =
@<<<
"Main Body"
.
$~ = 'DURATION';
write;
}

Output in perl v5.6:
This is TOP
---
Main Body

output in perl v5.10
Main Body


What should I do in v5.10 to get the old output?


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Better Regrex

2011-03-23 Thread Mike Blezien
- Original Message - 
From: "Chas. Owens" 

To: "Mike Blezien" 
Cc: "Perl List" 
Sent: Wednesday, March 23, 2011 8:42 AM
Subject: Re: Better Regrex


On Wed, Mar 23, 2011 at 09:05, Mike Blezien  wrote:

Hello,

I'm working on a simple regrex issue which I got to work but I think there's a 
better way to do this. This is what I have right now. I need to simply remove 
the string section in red.


my($marker);
my $message = "Why are we here? To bless, inspire and uplift one another. #TRB 
#inspiration #loa";

if($message =~ /\#(.*)/i) { $marker = $1; }
$message =~ s!$mark!!gi;
$message =~ s!\#!!gi;

#Resulting String wanted:
Why are we here? To bless, inspire and uplift one another.

The method I'm using above works and we get the results wanted but I was 
looking at it again and I think there's a better way to do this. Any suggested 
would be appreciated.

snip

Removal can be done with one substitution:

$message =~ s/\s*#\S+\s*//g;

That will remove any whitespace characters followed by a # followed by
one or more non-whitespace characters and the whitespace that follows
it.

If you want to save the markers, you will need to match first, then remove them:

#!/usr/bin/perl

use strict;
use warnings;

my $message = "Why are we here?  To bless, inspire and uplift one
another. #TRB #inspiration #loa";

my @markers = $message =~ /#(\S+)/g;
$message =~ s/\s*#\S+\s*//g;

print "[$message]\nmarkers: ", join(", ", @markers), "\n";

=

Thx's this work very well, allot cleaner.


Mike 



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Better Regrex

2011-03-23 Thread Chas. Owens
On Wed, Mar 23, 2011 at 09:05, Mike Blezien  wrote:
> Hello,
>
> I'm working on a simple regrex issue which I got to work but I think there's 
> a better way to do this. This is what I have right now. I need to simply 
> remove the string section in red.
>
> my($marker);
> my $message = "Why are we here?  To bless, inspire and uplift one another. 
> #TRB #inspiration #loa";
>   if($message =~ /\#(.*)/i) { $marker = $1; }
>   $message =~ s!$mark!!gi;
>   $message =~ s!\#!!gi;
>
> #Resulting String wanted:
>  Why are we here?  To bless, inspire and uplift one another.
>
> The method I'm using above works and we get the results wanted but I was 
> looking at it again and I think there's a better way to do this. Any 
> suggested would be appreciated.
snip

Removal can be done with one substitution:

$message =~ s/\s*#\S+\s*//g;

That will remove any whitespace characters followed by a # followed by
one or more non-whitespace characters and the whitespace that follows
it.

If you want to save the markers, you will need to match first, then remove them:

#!/usr/bin/perl

use strict;
use warnings;

my $message = "Why are we here?  To bless, inspire and uplift one
another. #TRB #inspiration #loa";

my @markers = $message =~ /#(\S+)/g;
$message =~ s/\s*#\S+\s*//g;

print "[$message]\nmarkers: ", join(", ", @markers), "\n";





-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Better Regrex

2011-03-23 Thread Brian Fraser
Regex, or maybe regexp, but not regrex.. That doesn't make any sense : p
I have no idea what you mean with "section in red." However, there's a few
things wrong with your code:

What is $mark? Don't you mean $marker? As it stands, your snipped would die
under strict, and in non-strict $mark would be undefined, which would be
interpreted as an empty string; You'd be replacing all empty strings with
empty strings, effectively achieving nothing at the cost of doing a lot.
Also, that if is pretty worthless if all you using it for is to assign $1
you might as well write my ($marker) = message =~ /regex here/;

But assuming you mean "delete all words that start with a #," then yeah,
there's a much simpler way:

> s/#\w*//g;

Which uses the /g modifier, explained in perlretut[0] and perlop[1].

Meanwhile, if you mean "if a word start with #, delete it from everywhere in
the script", you could do something like

> s/$+{word}//g while s/ \# (? \w+ ) //x;
>
This uses named captures, explained in perlretut and perlre[2]. You could do
without them though.

Brian.

[0] http://perldoc.perl.org/perlretut.html#Using-regular-expressions-in-Perl
[1] http://perldoc.perl.org/perlop.html#Regexp-Quote-Like-Operators
[2] http://perldoc.perl.org/perlre.html

On Wed, Mar 23, 2011 at 10:05 AM, Mike Blezien wrote:

> Hello,
>
> I'm working on a simple regrex issue which I got to work but I think
> there's a better way to do this. This is what I have right now. I need to
> simply remove the string section in red.
>
> my($marker);
> my $message = "Why are we here?  To bless, inspire and uplift one another.
> #TRB #inspiration #loa";
>   if($message =~ /\#(.*)/i) { $marker = $1; }
>   $message =~ s!$mark!!gi;
>   $message =~ s!\#!!gi;
>
> #Resulting String wanted:
>  Why are we here?  To bless, inspire and uplift one another.
>
> The method I'm using above works and we get the results wanted but I was
> looking at it again and I think there's a better way to do this. Any
> suggested would be appreciated.
>
> Thx's
> Mike(mickalo)Blezien
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> Thunder Rain Internet Publishing
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


Better Regrex

2011-03-23 Thread Mike Blezien
Hello,

I'm working on a simple regrex issue which I got to work but I think there's a 
better way to do this. This is what I have right now. I need to simply remove 
the string section in red.

my($marker);
my $message = "Why are we here?  To bless, inspire and uplift one another. #TRB 
#inspiration #loa"; 
   if($message =~ /\#(.*)/i) { $marker = $1; } 
   $message =~ s!$mark!!gi;
   $message =~ s!\#!!gi;

#Resulting String wanted:
  Why are we here?  To bless, inspire and uplift one another.

The method I'm using above works and we get the results wanted but I was 
looking at it again and I think there's a better way to do this. Any suggested 
would be appreciated.

Thx's
Mike(mickalo)Blezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-