Current location: Hot Scripts Forums » Programming Languages » Perl » alpha-num numbering scheme in perl


alpha-num numbering scheme in perl

Reply
  #1 (permalink)  
Old 06-20-09, 12:24 PM
cpp1ouser cpp1ouser is offline
New Member
 
Join Date: Jan 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
alpha-num numbering scheme in perl

Hi,
Does anyone know how to get the alpha-numeric numbering scheme in perl ?
For example the
numberic => 0,1,2,...9,10,11,12,...99,100,... # $x = 0;$x++;
lower-alpha => a,b,c,...z,aa,ab,ac,...zz,aaa,... # $x = "a";$x++;
upper-alpha => A,B,C,..,Z,AA,AB,AC,...ZZ,AAA,... # $x = "A";$x++;
lower-alpha-num => a,b,c,...z,0,1,2,3,...9,aa,ab,ac,...zz,10,11,12,.. .99,aaa,... # ?
upper-alpha-num => A,B,C,..,Z,0,1,2,3,...9,AA,AB,AC,...ZZ,10,11,12,.. .99,AAA,... # ?

cvv3@yahoo.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 06-29-09, 06:06 PM
Boraan's Avatar
Boraan Boraan is offline
Coding Addict
 
Join Date: Jul 2007
Location: Clayton, NC
Posts: 292
Thanks: 0
Thanked 1 Time in 1 Post
Regular expressions. When I was learning Perl this was drilled into my head. Memorize to be a pro.

Expressions (symbol - match):
. - matches any single character except newline
[a-z0-9] - matches any single character of set
[^a-z0-9] - matches any single character NOT in set
\d - matches a digit (a number 0-9)
\D - matches a non-digit (anything but 0-9)
\w - matches an alphanumeric character (a-zA-Z0-9 and _)
\W - matches a non-alphanumeric character
\s - matches a whitespace character (space, tab, newline)
\S - matches a non-whitespace character
\n - matches a newline
\r - matches a return
\t - matches a tab
\f - matches a formfeed
\b - matches a backspace (inside [ ] brackets only)
\0 - matches a null character
\b - matches a word boundary (outside [ ] brakets only)
\B - matches a non-word boundary

Placement:
^ - anchors match to the beginning of a line or string
$ - anchors match to the end of a line or string

Equations:
x? - matches 0 or 1 x's, where x is any of the above
x* - matches 0 or more x's
x+ - matches 1 or more x's
x{m,n} - matches at least m x's, but no more than n

(pat1|pat2) - matches either pat1 or pat2
(pat) - stores a pattern for backreferencing via $1...$9

and a crucial one for returning matches to print... $&

All other character are self matching, for example a will match a. The special characters that you have to backslash are + ? . * ^ $ @ ( ) [ ] | \. So you when you want to match the @ in an email would be \@

Regualar expression work to match anything you need like so

$var =~ /pattern/ OR $var =~ m/pattern/ (m#pattern#) works well.

regexps can be used to replace patterns as well.
$var =~ s/pattern/replacement/;

so a numeric would be $var =~ [\d]; as it matches 0-9 in that set. same goes for your other sets.
lower case alpha $var =~ [a-z];
upper case alpha $var =~ [A-Z];
lower alphanumeric $var =~ [a-z0-9];
upper alphanumeric $var =~ [A-Z0-9];

Remember that perl is cAsE sEnSiTiVe. matching with \w will match anything a-zA-Z0-9 and _. $var =~ [\w\];
for it to be insensitive you would use i modifier like so.
$var =~ [\w\]/i;

matches can also be global with g. $var =~ [\w\]/g;

A good example would be an email address. To properly match on you would use something like this.
$var =~ /[\w\-]+\@[\w\-]+[\w\-]+/

you should take the time to memorize expressions and how they are used. That's half the perl battle if you can master those.

Cheers!
__________________
Dexter Nelson
Techdex Development & Solutions
========================
Internet Marketing For Programmers | Free Market Research in 15 Minutes or Less
My Software: Hotscripts Softpedia software.techdex.net
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks

Tags
perl


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl upload progress bar with these spec: scott2500uk Script Requests 4 03-16-07 05:04 PM
Perl for a dummy kragnesb414 Perl 1 01-31-06 05:34 AM
Perl FormMail Problem ennanguyen2002 Perl 2 03-09-05 05:47 PM


All times are GMT -5. The time now is 02:46 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.