compact my wordlist generator

2009-10-25 Thread Michael Alipio
Hi,

 I'm trying to write a word list generator which can
 generate all possible combinations of n characters, within n
 set of characters.
 
 
 So far, this is what I have come up. The only input is the
 lenght of the password the user wants.
 
 my @set = qw(a b c d e f g h i j k l m n o p q r s t u v w
 x y z);
 my $len = scalar @set;
 my $char1;
 my $char2;
 my $char3;
 my $char4;
 my $char5;
 my $char6;
 my $char7;
 my $char8;
 
 if ($pwlen == 8){
 
 for ($char1=0;$char1$len;$char1++){
   for ($char2=0;$char2$len;$char2++){
     for ($char3=0;$char3$len;$char3++){
 
     ... upto
 
     for ($char8=0;$char8$len;$char8++){
 
 print
 
$set[$char1]$set[$char2]$set[$char3]$set[$char4]$set[$char5]$set[$char6]set[$char7]$set[$char8]\n;
 
 
 
 } elseif ( $pwlen == 7){
 
 for ($char2=0;$char2$len;$char1++){
   for ($char3=0;$char3$len;$char2++){
     for ($char4=0;$char4$len;$char3++){
 
     ... upto
 
     for ($char8=0;$char8$len;$char8++){
 
 print
 
$set[$char2]$set[$char3]$set[$char4]$set[$char5]$set[$char6]$set[$char7]set[$char8]\n;
 
 }}}
 
 }
 
 
 The problem with the code above is that the length of words
 is hard coded. Only 8 maximum. I'm looking for ways on how
 to make my code flexible (length can be whatever the user
 wants ).
 
 My code is limited to 8 chars maximum length plus if I want
 to increase it, I have to add another set of for loops plus
 another variable to use, e.g., $char9, char10.. and so
 on...
 
 
 Any idea?
 
 
       






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




Re: compact my wordlist generator

2009-10-25 Thread Gabor Szabo
2009/10/25 Michael Alipio daem0n...@yahoo.com:
 Hi,

  I'm trying to write a word list generator which can
  generate all possible combinations of n characters, within n
  set of characters.


  So far, this is what I have come up. The only input is the
  lenght of the password the user wants.

  my @set = qw(a b c d e f g h i j k l m n o p q r s t u v w
  x y z);
  my $len = scalar @set;
  my $char1;
  my $char2;
  my $char3;
  my $char4;
  my $char5;
  my $char6;
  my $char7;
  my $char8;

  if ($pwlen == 8){

  for ($char1=0;$char1$len;$char1++){
    for ($char2=0;$char2$len;$char2++){
      for ($char3=0;$char3$len;$char3++){

      ... upto

      for ($char8=0;$char8$len;$char8++){

  print
  $set[$char1]$set[$char2]$set[$char3]$set[$char4]$set[$char5]$set[$char6]set[$char7]$set[$char8]\n;

  

  } elseif ( $pwlen == 7){

  for ($char2=0;$char2$len;$char1++){
    for ($char3=0;$char3$len;$char2++){
      for ($char4=0;$char4$len;$char3++){

      ... upto

      for ($char8=0;$char8$len;$char8++){

  print
  $set[$char2]$set[$char3]$set[$char4]$set[$char5]$set[$char6]$set[$char7]set[$char8]\n;

  }}}

  }


  The problem with the code above is that the length of words
  is hard coded. Only 8 maximum. I'm looking for ways on how
  to make my code flexible (length can be whatever the user
  wants ).

  My code is limited to 8 chars maximum length plus if I want
  to increase it, I have to add another set of for loops plus
  another variable to use, e.g., $char9, char10.. and so
  on...


  Any idea?

What about keeping the characters in an array @char
so you will have
$char[0], $char[1] etc. a

nd the loops could be replaced by a recursive function call. Something
like this:

do_something_for_char($k)

sub do_something_for_char {
  my ($k) = @_;
  return if $k = $n;
   do_something_for_char($n+1);
}


Gabor

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




Re: compact my wordlist generator

2009-10-25 Thread Michael Alipio
I was thinking about this recursive thing... thanks for the tip.. will try this 
out.. I hope I can accomplish it.

--- On Sun, 10/25/09, Gabor Szabo szab...@gmail.com wrote:

 From: Gabor Szabo szab...@gmail.com
 Subject: Re: compact my wordlist generator
 To: Michael Alipio daem0n...@yahoo.com
 Cc: begginers perl.org beginners@perl.org
 Date: Sunday, October 25, 2009, 5:06 PM
 2009/10/25 Michael Alipio daem0n...@yahoo.com:
  Hi,
 
   I'm trying to write a word list generator which can
   generate all possible combinations of n characters,
 within n
   set of characters.
 
 
   So far, this is what I have come up. The only input
 is the
   lenght of the password the user wants.
 
   my @set = qw(a b c d e f g h i j k l m n o p q r s t
 u v w
   x y z);
   my $len = scalar @set;
   my $char1;
   my $char2;
   my $char3;
   my $char4;
   my $char5;
   my $char6;
   my $char7;
   my $char8;
 
   if ($pwlen == 8){
 
   for ($char1=0;$char1$len;$char1++){
     for ($char2=0;$char2$len;$char2++){
       for ($char3=0;$char3$len;$char3++){
 
       ... upto
 
       for ($char8=0;$char8$len;$char8++){
 
   print
 
  $set[$char1]$set[$char2]$set[$char3]$set[$char4]$set[$char5]$set[$char6]set[$char7]$set[$char8]\n;
 
   
 
   } elseif ( $pwlen == 7){
 
   for ($char2=0;$char2$len;$char1++){
     for ($char3=0;$char3$len;$char2++){
       for ($char4=0;$char4$len;$char3++){
 
       ... upto
 
       for ($char8=0;$char8$len;$char8++){
 
   print
 
  $set[$char2]$set[$char3]$set[$char4]$set[$char5]$set[$char6]$set[$char7]set[$char8]\n;
 
   }}}
 
   }
 
 
   The problem with the code above is that the length
 of words
   is hard coded. Only 8 maximum. I'm looking for ways
 on how
   to make my code flexible (length can be whatever the
 user
   wants ).
 
   My code is limited to 8 chars maximum length plus if
 I want
   to increase it, I have to add another set of for
 loops plus
   another variable to use, e.g., $char9, char10.. and
 so
   on...
 
 
   Any idea?
 
 What about keeping the characters in an array @char
 so you will have
 $char[0], $char[1] etc. a
 
 nd the loops could be replaced by a recursive function
 call. Something
 like this:
 
 do_something_for_char($k)
 
 sub do_something_for_char {
   my ($k) = @_;
   return if $k = $n;
    do_something_for_char($n+1);
 }
 
 
 Gabor
 





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




split n characters into n chunks

2009-10-25 Thread Michael Alipio
Hi,

How do I split a word into n subsets?

my $word = thequickbrown


If I want three subsets I should be able to create:

the
heq
equ

upto

own


Using split function with limit of 3 gives me:

t h equickbrown



Any idea how to do this? I'm thinking maybe I can just split the whole string 
and push each character into array, then loop through the array, getting 3 
elements set in the proces..







  


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




Re: compact my wordlist generator

2009-10-25 Thread Philip Potter
2009/10/25 Michael Alipio daem0n...@yahoo.com:
  I'm trying to write a word list generator which can
  generate all possible combinations of n characters, within n
  set of characters.

Have you looked into the magical autoincrement operator?
http://perldoc.perl.org/perlop.html#Auto-increment-and-Auto-decrement

   1. print ++($foo = '99'); # prints '100'
   2. print ++($foo = 'a0'); # prints 'a1'
   3. print ++($foo = 'Az'); # prints 'Ba'
   4. print ++($foo = 'zz'); # prints 'aaa'

my $x;
my $len = 4;

for ($x = 'a' x $len; $x ne 'a' x ($len+1); $x++) {
 print $x\n;
}

Or you could specify it as a range:

my $len=4;

for ('a'x$len..'z'x$len) {
print $_\n;
}

These won't help with arbitrary character sets, unfortunately.

Gabor wrote:
 nd the loops could be replaced by a recursive function
 call. Something
 like this:

 do_something_for_char($k)

 sub do_something_for_char {
   my ($k) = @_;
   return if $k = $n;
do_something_for_char($n+1);
 }

I would write it differently:

sub print_all_strings_of_length {
my ($len, $prefix) = @_;
$prefix = defined($prefix) ? $prefix : q{}; # or $prefix //= q{};
under recent perls
$len  0 and die qq{print_all_strings_of_length($len) can't be done};
if ($len == 0) {
print $prefix\n;
return;
}
for ('a'..'z') { # or for (@set) for an arbitrary set of characters
print_all_strings_of_length($len-1, $prefix.$_);
}
return;
}

print_all_strings_of_length(3);

For me, the idea of recursion is expressing an idea in terms of a
slightly simpler idea. Here, I express how to print all strings of
length N in terms of an operation which will print all strings of
length N-1 prefixed with $prefix. So I use that operation to print all
strings starting with 'a' followed by N-1 characters, then all strings
starting 'b' followed by N-1 characters, and so on.

Phil

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




Re: newbie question : about the perl sprintf

2009-10-25 Thread Majian
I found these :
perl -e'print 01.234 + 01.234', \n'
perl -e'print 01.234 + 011.234' \n'
perl -e'print 01.234.12 + 01.234', \n'

And the results were :

1235234
1235234
1235.12234



Can someone explain it ?

Thanks~~


On Sat, Oct 24, 2009 at 7:28 PM, Peter Scott pe...@psdt.com wrote:

 On Wed, 21 Oct 2009 20:52:05 +0800, Majian wrote:
  And  I modify it like this sprintf The number in
  scientific
  notation is %e, 01.255;
  The screen now output is  The number in scientific
  notation
  is 1.255000e+03

 Ha, this is an interesting case.  By putting the zero before the 1, it
 turns it into an octal number and now the period becomes the concatenation
 operator instead of a decimal point, yielding a term of 1255.

 Try printf The number in scientific notation is %e, 037.255; and see
 what happens.

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

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





Re: newbie question : about the perl sprintf

2009-10-25 Thread Philip Potter
2009/10/25 Majian jian...@gmail.com:
 I found these :
 perl -e'print 01.234 + 01.234', \n'

print (01).(234+01).234, \n;

this evaluates to '1'.'235'.'234'

 perl -e'print 01.234 + 011.234' \n'

I didn't get 1235234, I got 1243234.
print (01).(234+011).(234),\n
evaluates to
print '1'.(234+9).'234',\n;
evaluates to
print '1'.'243'.'234',\n;

 perl -e'print 01.234.12 + 01.234', \n'

I'll let you work this one out as an exercise. The key point is that
you can't have decimal octal numbers, so the . operator is interpreted
as the string concatenation operator.

Phil

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




Re: split n characters into n chunks

2009-10-25 Thread Shawn H Corey
Michael Alipio wrote:
 Any idea how to do this? I'm thinking maybe I can just
 split the whole string and push each character into array,
 then loop through the array, getting 3 elements set in the
 proces..

Split the string into an array, loop through it and use a slice to join
the elements.


-- 
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

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




Re: split n characters into n chunks

2009-10-25 Thread Shlomi Fish
On Sunday 25 Oct 2009 14:39:32 Shawn H Corey wrote:
 Michael Alipio wrote:
  Any idea how to do this? I'm thinking maybe I can just
  split the whole string and push each character into array,
  then loop through the array, getting 3 elements set in the
  proces..
 
 Split the string into an array, loop through it and use a slice to join
 the elements.
 

Why not use perldoc -f substr ( http://perldoc.perl.org/functions/substr.html 
) in a loop? Alternatively one can use unpack but I'm not sure how well it 
would handle Unicode characters.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
First stop for Perl beginners - http://perl-begin.org/

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: newbie question : about the perl sprintf

2009-10-25 Thread Dr.Ruud

Majian wrote:

I found these :
perl -e'print 01.234 + 01.234', \n'
perl -e'print 01.234 + 011.234' \n'
perl -e'print 01.234.12 + 01.234', \n'

And the results were :

1235234
1235234
1235.12234


For other surprises, try also:

perl -wle 'print length(01.234.12)'
perl -wle 'print 01.234.12'

perl -wle 'print length(1.234.12)'
perl -wle 'print length(0+1.234.12)'

--
Ruud

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




Re: split n characters into n chunks

2009-10-25 Thread Shawn H Corey
Shlomi Fish wrote:
 Why not use perldoc -f substr ( http://perldoc.perl.org/functions/substr.html 
 ) in a loop? Alternatively one can use unpack but I'm not sure how well it 
 would handle Unicode characters.

You're right, substr works best.

#!/usr/bin/env perl

use strict;
use warnings;

use Data::Dumper;

# Make Data::Dumper pretty
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent   = 1;

# Set maximum depth for Data::Dumper, zero means unlimited
$Data::Dumper::Maxdepth = 0;

use Benchmark qw(:all);

my $word = thequickbrown;
my $size = 3;

cmpthese( 50_000, {
  'via_arrays' = \via_arrays,
  'via_substr' = \via_substr,
  'via_unpack' = \via_unpack,
});

# for testing only
# via_arrays();
# via_substr();
# via_unpack();

sub via_arrays {
  my @array = split //, $word;
  my $max = @array - $size;
  my @list = ();
  for my $i ( 0 .. $max ){
push @list, join '', @array[ $i .. $i+$size-1 ];
  }
  # print Dumper \...@list;  #for testing only
}

sub via_substr {
  my $max = length( $word ) - $size;
  my @list = ();
  for my $i ( 0 .. $max ){
push @list, substr( $word, $i, $size );
  }
  # print Dumper \...@list;  #for testing only
}

sub via_unpack {
  my $max = length( $word ) - $size;
  my @list = ();
  for my $i ( 0 .. $max ){
push @list, (unpack( A${i}A$size, $word ))[1];
  }
  # print Dumper \...@list;  #for testing only
}


-- 
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

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




Re: split n characters into n chunks

2009-10-25 Thread Dr.Ruud

Michael Alipio wrote:


my $word = thequickbrown

If I want three subsets I should be able to create:

the
heq
equ
.
upto
.
own


  print substr( $word, $-[0], 3 )
while $word =~ /.(?=..)/g;

--
Ruud

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




Re: split n characters into n chunks

2009-10-25 Thread Shawn H Corey
Dr.Ruud wrote:
   print substr( $word, $-[0], 3 )
 while $word =~ /.(?=..)/g;
 

Doesn't beat substr.

#!/usr/bin/env perl

use strict;
use warnings;

use Data::Dumper;

# Make Data::Dumper pretty
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent   = 1;

# Set maximum depth for Data::Dumper, zero means unlimited
$Data::Dumper::Maxdepth = 0;

use Benchmark qw(:all);

my $word = thequickbrown;
my $size = 3;

cmpthese( 50_000, {
  'via arrays' = \via_arrays,
  'via substr' = \via_substr,
  'via unpack' = \via_unpack,
  'via match'  = \via_match,
});

# for testing only
# via_arrays();
# via_substr();
# via_unpack();
# via_match();

sub via_arrays {
  my @array = split //, $word;
  my $max = @array - $size;
  my @list = ();
  for my $i ( 0 .. $max ){
push @list, join '', @array[ $i .. $i+$size-1 ];
  }
  # print Dumper \...@list;  #for testing only
}

sub via_substr {
  my $max = length( $word ) - $size;
  my @list = ();
  for my $i ( 0 .. $max ){
push @list, substr( $word, $i, $size );
  }
  # print Dumper \...@list;  #for testing only
}

sub via_unpack {
  my $max = length( $word ) - $size;
  my @list = ();
  for my $i ( 0 .. $max ){
push @list, (unpack( A${i}A$size, $word ))[1];
  }
  # print Dumper \...@list;  #for testing only
}

sub via_match {
  my @list = ();
  push @list, substr( $word, $-[0], 3 )
while $word =~ /.(?=..)/g;
  #print Dumper \...@list;  #for testing only
}


-- 
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

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




Re: split n characters into n chunks

2009-10-25 Thread John W. Krahn

Michael Alipio wrote:

Hi,


Hello,


How do I split a word into n subsets?

my $word = thequickbrown


If I want three subsets I should be able to create:

the
heq
equ

upto

own


$ perl -le'
my $word = thequickbrown;
my $subsets = 3;
print for $word =~ /(?=(.{$subsets}))/g;
'
the
heq
equ
qui
uic
ick
ckb
kbr
bro
row
own



John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity.   -- Damian Conway

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




Re: split n characters into n chunks

2009-10-25 Thread Shawn H Corey
John W. Krahn wrote:
 $ perl -le'
 my $word = thequickbrown;
 my $subsets = 3;
 print for $word =~ /(?=(.{$subsets}))/g;

Getting up there but substr is still the fastest.

#!/usr/bin/env perl

use strict;
use warnings;

use Data::Dumper;

# Make Data::Dumper pretty
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent   = 1;

# Set maximum depth for Data::Dumper, zero means unlimited
$Data::Dumper::Maxdepth = 0;

my $Testing = $ARGV[0] || 0;
use Benchmark qw(:all);

my $word = thequickbrown;
my $size = 3;

if( $Testing ){
  via_arrays();
  via_substr();
  via_unpack();
  via_match();
  via_match2();
}else{
  cmpthese( 50_000, {
'via arrays' = \via_arrays,
'via substr' = \via_substr,
'via unpack' = \via_unpack,
'via match'  = \via_match,
'via match2' = \via_match2,
  });
}


sub via_arrays {
  my @array = split //, $word;
  my $max = @array - $size;
  my @list = ();
  for my $i ( 0 .. $max ){
push @list, join '', @array[ $i .. $i+$size-1 ];
  }
  # print Dumper \...@list;  #for testing only
}

sub via_substr {
  my $max = length( $word ) - $size;
  my @list = ();
  for my $i ( 0 .. $max ){
push @list, substr( $word, $i, $size );
  }
  # print Dumper \...@list;  #for testing only
}

sub via_unpack {
  my $max = length( $word ) - $size;
  my @list = ();
  for my $i ( 0 .. $max ){
push @list, (unpack( A${i}A$size, $word ))[1];
  }
  # print Dumper \...@list;  #for testing only
}

sub via_match {
  my @list = ();
  push @list, substr( $word, $-[0], 3 )
while $word =~ /.(?=..)/g;
  # print Dumper \...@list;  #for testing only
}

sub via_match2 {
  my @list = ();
  push @list, $_ for $word =~ /(?=(.{$size}))/g;
  # print Dumper \...@list;  #for testing only
}



-- 
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

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




A Revised Logo for Perl

2009-10-25 Thread M. E8. H.
This is an minor  topic. I feel the Camel logo to represent Perl to be strange, 
illogical and slightly ugly.  I presume I do not get the humor.   However I 
prefer a swiss army knife -liked  tool or a red tool box with tons of tools to 
be a better logo.    Like C, Perl is a programming language that does almost 
everything.  ...  Back to the topic of Perl.  ... 



  

Re: A Revised Logo for Perl

2009-10-25 Thread Erez Schatz
2009/10/25 M. E8. H. cispro...@yahoo.com:
 This is an minor  topic. I feel the Camel logo to represent Perl to be 
 strange, illogical and slightly ugly.  I presume I do not get the humor.   
 However I prefer a swiss army knife -liked  tool or a red tool box with tons 
 of tools to be a better logo.    Like C, Perl is a programming language that 
 does almost everything.  ...  Back to the topic of Perl.  ...

The official logo of the Perl Foundation, and AFAIK, the one promoted
by Larry Wall is the onion, especially the one shown here:
http://www.perlfoundation.org/perl_trademark

-- 
Erez

The government forgets that George Orwell's 1984 was a warning, and
not a blueprint
http://www.nonviolent-conflict.org/ -- http://www.whyweprotest.org/

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




Re: A Revised Logo for Perl

2009-10-25 Thread Shawn H Corey
M. E8. H. wrote:
 This is an minor  topic. I feel the Camel logo to
 represent Perl to be strange, illogical and slightly ugly.
 I presume I do not get the humor.   However I prefer a
 swiss army knife -liked  tool or a red tool box with tons
 of tools to be a better logo.Like C, Perl is a
 programming language that does almost everything.  ...
 Back to the topic of Perl.  ... 

I think you get a better response if you post this on the Perl 5 Porters
mailing list http://www.perlfoundation.org/perl5/index.cgi?perl5_porters

Perl 6 has a different logo, a cute little butterfly, awww...
http://perl6.org/


-- 
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

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




Re: A Revised Logo for Perl

2009-10-25 Thread Shawn H Corey
Erez Schatz wrote:
 The official logo of the Perl Foundation, and AFAIK, the one promoted
 by Larry Wall is the onion, especially the one shown here:
 http://www.perlfoundation.org/perl_trademark
 

That look ore like a garlic bulb to me.  :)


-- 
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

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




Re: split n characters into n chunks

2009-10-25 Thread John W. Krahn

Shawn H Corey wrote:

John W. Krahn wrote:

$ perl -le'
my $word = thequickbrown;
my $subsets = 3;
print for $word =~ /(?=(.{$subsets}))/g;


Getting up there but substr is still the fastest.

#!/usr/bin/env perl

use strict;
use warnings;

use Data::Dumper;

# Make Data::Dumper pretty
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent   = 1;

# Set maximum depth for Data::Dumper, zero means unlimited
$Data::Dumper::Maxdepth = 0;

my $Testing = $ARGV[0] || 0;
use Benchmark qw(:all);

my $word = thequickbrown;
my $size = 3;

if( $Testing ){
  via_arrays();
  via_substr();
  via_unpack();
  via_match();
  via_match2();
}else{
  cmpthese( 50_000, {
'via arrays' = \via_arrays,
'via substr' = \via_substr,
'via unpack' = \via_unpack,
'via match'  = \via_match,
'via match2' = \via_match2,
  });
}


sub via_arrays {
  my @array = split //, $word;
  my $max = @array - $size;
  my @list = ();
  for my $i ( 0 .. $max ){
push @list, join '', @array[ $i .. $i+$size-1 ];
  }
  # print Dumper \...@list;  #for testing only
}

sub via_substr {
  my $max = length( $word ) - $size;
  my @list = ();
  for my $i ( 0 .. $max ){
push @list, substr( $word, $i, $size );
  }
  # print Dumper \...@list;  #for testing only
}

sub via_unpack {
  my $max = length( $word ) - $size;
  my @list = ();
  for my $i ( 0 .. $max ){
push @list, (unpack( A${i}A$size, $word ))[1];
  }
  # print Dumper \...@list;  #for testing only
}

sub via_match {
  my @list = ();
  push @list, substr( $word, $-[0], 3 )
while $word =~ /.(?=..)/g;
  # print Dumper \...@list;  #for testing only
}

sub via_match2 {
  my @list = ();
  push @list, $_ for $word =~ /(?=(.{$size}))/g;


Why the for loop?

  my @list = $word =~ /(?=(.{$size}))/g;



  # print Dumper \...@list;  #for testing only
}




John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity.   -- Damian Conway

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




Re: split n characters into n chunks

2009-10-25 Thread Shawn H Corey
John W. Krahn wrote:
 Why the for loop?
 
   my @list = $word =~ /(?=(.{$size}))/g;
 
 
   # print Dumper \...@list;  #for testing only
 }

Because you sent it with a loop.  It also seems faster.

#!/usr/bin/env perl

use strict;
use warnings;

use Data::Dumper;

# Make Data::Dumper pretty
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent   = 1;

# Set maximum depth for Data::Dumper, zero means unlimited
$Data::Dumper::Maxdepth = 0;

my $Testing = $ARGV[0] || 0;
use Benchmark qw(:all);

my $word = thequickbrown;
my $size = 3;

if( $Testing ){
  via_arrays();
  via_substr();
  via_unpack();
  via_match();
  via_match2();
  via_match3();
}else{
  cmpthese( 50_000, {
'via arrays' = \via_arrays,
'via substr' = \via_substr,
'via unpack' = \via_unpack,
'via match'  = \via_match,
'via match2' = \via_match2,
'via match3' = \via_match3,
  });
}


sub via_arrays {
  my @array = split //, $word;
  my $max = @array - $size;
  my @list = ();
  for my $i ( 0 .. $max ){
push @list, join '', @array[ $i .. $i+$size-1 ];
  }
  # print Dumper \...@list;  #for testing only
}

sub via_substr {
  my $max = length( $word ) - $size;
  my @list = ();
  for my $i ( 0 .. $max ){
push @list, substr( $word, $i, $size );
  }
  # print Dumper \...@list;  #for testing only
}

sub via_unpack {
  my $max = length( $word ) - $size;
  my @list = ();
  for my $i ( 0 .. $max ){
push @list, (unpack( A${i}A$size, $word ))[1];
  }
  # print Dumper \...@list;  #for testing only
}

sub via_match {
  my @list = ();
  push @list, substr( $word, $-[0], 3 )
while $word =~ /.(?=..)/g;
  # print Dumper \...@list;  #for testing only
}

sub via_match2 {
  my @list = ();
  push @list, $_ for $word =~ /(?=(.{$size}))/g;
  # print Dumper \...@list;  #for testing only
}

sub via_match3 {
  my @list = $word =~ /(?=(.{$size}))/g;
  # print Dumper \...@list;  #for testing only
}




-- 
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

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




Re: A Revised Logo for Perl

2009-10-25 Thread netfox

Why it isn't a Pearl? That seems more close.


-Original Message-
From: Erez Schatz moonb...@gmail.com
To: M. E8. H. cispro...@yahoo.com
Cc: beginners@perl.org
Sent: Mon, Oct 26, 2009 4:58 am
Subject: Re: A Revised Logo for Perl










2009/10/25 M. E8. H. cispro...@yahoo.com:
This is an minor  topic. I feel the Camel logo to represent Perl to 

be
strange, illogical and slightly ugly.  I presume I do not get the 
humor.  
However I prefer a swiss army knife -liked  tool or a red tool box with 
tons of
tools to be a better logo.    Like C, Perl is a programming language 
that does

almost everything.  ...  Back to the topic of Perl.  ...

The official logo of the Perl Foundation, and AFAIK, the one promoted
by Larry Wall is the onion, especially the one shown here:
http://www.perlfoundation.org/perl_trademark



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




Re: A Revised Logo for Perl

2009-10-25 Thread Uri Guttman
 n == netfox  net...@royal.net writes:

  n Why it isn't a Pearl? That seems more close.

because the language is perl without the 'a'. it actually was originally
going to be caller 'pearl' (after another name change) but that was
already used for a language so larry dropped the 'a'. making a pearl the
logo would make no sense IMO given that story. as for the logos (camel
and onion) does it really matter to anyone on this list? one is owned by
o'reilly and is restricted for some uses and the other is owned by the
perl foundation and is open to any use. does that affect how you learn
perl from this list or other resources? not really i bet. not to dump on
anyone, but this thread isn't very on topic for the perl beginner's
list.

uri

-- 
Uri Guttman  --  u...@stemsystems.com    http://www.sysarch.com --
-  Perl Code Review , Architecture, Development, Training, Support --
-  Gourmet Hot Cocoa Mix    http://bestfriendscocoa.com -

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




Re: A Revised Logo for Perl

2009-10-25 Thread rkb
Shawn H Corey wrote:
 Erez Schatz wrote:
 The official logo of the Perl Foundation, and AFAIK, the
 one promoted
 by Larry Wall is the onion, especially the one shown
 here:
 http://www.perlfoundation.org/perl_trademark


 That look ore like a garlic bulb to me.  :)

-- 
Either way, add a little olive oil and grill it and every
one will love it. :)

Ron Bergin



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