Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > String generation

Reply
Thread Tools

String generation

 
 
petrucci
Guest
Posts: n/a
 
      09-21-2005
Hi everyone..

i want generate all the string starting a root

For ex.:

root = c

result =
ca
cb
cc
cd
..
..
cz
caa
cab
..
..
caz
cba
..
..
cbz
..
..
czz

and go on even a predefined length
Thank u

 
Reply With Quote
 
 
 
 
John W. Krahn
Guest
Posts: n/a
 
      09-21-2005
petrucci wrote:
>
> i want generate all the string starting a root
>
> For ex.:
>
> root = c
>
> result =
> ca
> cb
> cc
> cd
> .
> .
> cz
> caa
> cab
> .
> .
> caz
> cba
> .
> .
> cbz
> .
> .
> czz


my $root = 'c';

print "$root$_\n" for 'a' .. 'zz';



John
--
use Perl;
program
fulfillment
 
Reply With Quote
 
 
 
 
Tassilo v. Parseval
Guest
Posts: n/a
 
      09-21-2005
Also sprach petrucci:

> i want generate all the string starting a root
>
> For ex.:
>
> root = c
>
> result =
> ca
> cb
> cc
> cd
> .
> .
> cz
> caa
> cab
> .
> .
> caz
> cba
> .
> .
> cbz
> .
> .
> czz
>
> and go on even a predefined length


This is quite easy with Perl's string-increment:

use constant LENGTH => 3;

my ($root, $tail) = qw/c a/;

print $root . $tail++, "\n" while length("$root$tail") <= LENGTH;

Tassilo
--
use bigint;
$n=71423350343770280161397026330337371139054411854 220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($ m+=<=200);
 
Reply With Quote
 
petrucci
Guest
Posts: n/a
 
      09-21-2005
great!! and if i want to include simbols?

 
Reply With Quote
 
Tassilo v. Parseval
Guest
Posts: n/a
 
      09-21-2005
Also sprach petrucci:
> great!! and if i want to include simbols?


Then you have to work harder as Perl's string increment doesn't handle
symbols.

Other than that, please use a proper quoting style when composing
follow-up messages. You're supposed to quote context and to put your
material below those quotes. For this and other essentials please read

<http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html>

first.

Tassilo
--
use bigint;
$n=71423350343770280161397026330337371139054411854 220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($ m+=<=200);
 
Reply With Quote
 
petrucci
Guest
Posts: n/a
 
      09-21-2005
> my ($root, $tail) = qw/c a/;

what does it mean?

 
Reply With Quote
 
Tassilo v. Parseval
Guest
Posts: n/a
 
      09-21-2005
Also sprach petrucci:

>> my ($root, $tail) = qw/c a/;

>
> what does it mean?


qw// is a list constructor. Items of such a list are
whitespace-delimited and so the above is equivalent to

my ($root, $tail) = ('c', 'a');

qw is handy for lists where items never contain whitespace because you
don't have to use tedious quotes around the items in case they are
strings. See the entry on "qw/STRING/" under "Regexp Quote-Like
Operators" in `perldoc perlop`.

There are similar constructs for strings (q// and qq//), regexes (qr//)
and backticks (qx//).

Tassilo
--
use bigint;
$n=71423350343770280161397026330337371139054411854 220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($ m+=<=200);
 
Reply With Quote
 
William James
Guest
Posts: n/a
 
      09-21-2005

petrucci wrote:
> Hi everyone..
>
> i want generate all the string starting a root
>
> For ex.:
>
> root = c
>
> result =
> ca
> cb
> cc
> cd
> .
> .
> cz
> caa
> cab
> .
> .
> caz
> cba
> .
> .
> cbz
> .
> .
> czz
>
> and go on even a predefined length
> Thank u


You may prefer to use Ruby:

root = "c"
puts ("a".."zz").map{|s|root+s}

 
Reply With Quote
 
Matija Papec
Guest
Posts: n/a
 
      09-21-2005
On 21 Sep 2005 01:35:50 -0700, "William James" <>
wrote:

>> and go on even a predefined length
>> Thank u

>
>You may prefer to use Ruby:
>
>root = "c"
>puts ("a".."zz").map{|s|root+s}


Can you also offer perl equivalent so you wouldn't be completely
offtopic?


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
String Generation using Mask Parsing James Arnold C Programming 3 09-21-2008 03:47 PM
string generation Ken Human C Programming 27 05-27-2005 06:09 PM
Fast random string generation Derek Fountain Perl Misc 16 10-28-2004 06:45 AM
Re: String.replaceAll(String regex, String replacement) question Mladen Adamovic Java 0 12-04-2003 04:40 PM
HTML Generation (Next Generation CGI) John W. Long Ruby 4 11-24-2003 04:24 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57