Shawn H Corey wrote:
Dr.Ruud wrote:
push @list, unpack "x${_}a$size", $word for 0 .. $max;
Funnily enough, that is somehow&what faster than
push @list, map unpack( "x${_}a$size", $word ), 0 .. $max;
You don't need the push:
my @list = map unpack( "x${_}a$size", $word ), 0 .. $max;
Hi,
you can use substr $myword, 1,3 function
Thanks,
Mahesh
On Sun, Oct 25, 2009 at 3:13 PM, Michael Alipio wrote:
> 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
>
>
Dr.Ruud wrote:
> Shawn H Corey wrote:
>
>
>> push @list, (unpack( "A${i}A$size", $word ))[1];
>
> Be careful with unpack "A", because it rtrims.
>
>
> Best use "x" to skip, and "a" to capture.
>
> push @list, unpack "x${_}a$size", $word for 0 .. $max;
>
>
> Funnily enough, that is som
Shawn H Corey wrote:
push @list, (unpack( "A${i}A$size", $word ))[1];
Be careful with unpack "A", because it rtrims.
Best use "x" to skip, and "a" to capture.
push @list, unpack "x${_}a$size", $word for 0 .. $max;
Funnily enough, that is somehow&what faster than
push @list, map
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.
I had to set the iterations to 300_000, to get rid of warnings.
$ perl5.8.8 3.pl
Rate
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
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::Du
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 =
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
he
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
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,
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
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 int
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.
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 st
15 matches
Mail list logo