Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Ascii characters in a loop

Reply
Thread Tools

Ascii characters in a loop

 
 
Mark Hobley
Guest
Posts: n/a
 
      01-14-2007
Dr.Ruud <(E-Mail Removed)> wrote:

> Better mention what you do want.


I am documenting Perl and at the moment I am documenting loops, so I need to
know any place where choosing a particular value will cause different behaviour
than choosing another value.

I often use alphabetical increments in code, so anywhere that choosing a
particular values for alphabetical ranges requires a change in syntax to
perform across those range needs to be noted.

Regards,

Mark.

--
Mark Hobley
393 Quinton Road West
QUINTON
Birmingham
B32 1QE

Telephone: (0121) 247 1596
International: 0044 121 247 1596

Email: markhobley at hotpop dot donottypethisbit com

http://markhobley.yi.org/

 
Reply With Quote
 
 
 
 
Uri Guttman
Guest
Posts: n/a
 
      01-14-2007
>>>>> "MH" == Mark Hobley <(E-Mail Removed)> writes:


MH> I am documenting Perl and at the moment I am documenting loops, so
MH> I need to know any place where choosing a particular value will
MH> cause different behaviour than choosing another value.

what is this 'documenting perl'? perl IS documented and very well at
that. and there are tons of books about perl. what do you expect to
bring to the table and make it worthy of reading?

MH> I often use alphabetical increments in code, so anywhere that choosing a
MH> particular values for alphabetical ranges requires a change in syntax to
MH> perform across those range needs to be noted.

there is no need to worry about this if you understand the rules of
magic incrementing strings. they are well documented under ++ and .. in
perlop. and in general it makes little sense to code them using c style
for loops. (in fact c style for loops are RARELY needed in perl). use
... for looping over a range of incrementing strings.

uri

--
Uri Guttman ------ http://www.velocityreviews.com/forums/(E-Mail Removed) -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
 
 
 
Uri Guttman
Guest
Posts: n/a
 
      01-14-2007
>>>>> "MH" == Mark Hobley <(E-Mail Removed)> writes:

MH> John Bokma <(E-Mail Removed)> wrote:
>> for ($l = 'a'; $l ne 'aa'; $l++) {
>> print "$l";
>> }


MH> Yeah! I just think that 'a to z' looks far nicer late on a Friday
MH> night when I am trying to debug code.

MH> I need to test reverse loops, capitals, jumping by more than one
MH> letter at a time now to see if there are any more nasty surprises.

what is a reverse loop? perl has no such beast. perldoc perlop covers
magic increment, have you read it?

MH> I often loop through alphabetical sequences in code.

then you must be the odd one. i rarely do and i rarely see it. it is
useful and i use it but often??

uri

--
Uri Guttman ------ (E-Mail Removed) -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
John Bokma
Guest
Posts: n/a
 
      01-14-2007
(E-Mail Removed) (Mark Hobley) wrote:

> This looks like a bug to me, at least in the context of an a to z
> loop.


I am sure most will call it a feature, that 'z'++ goes to 'aa'.

As for loops, the form you use is in my experience very rare. I would have
used:

for my $l ( 'a' .. 'z' ) {

}

Less cluter, and much easier to understand.

--
John Experienced Perl programmer: http://castleamber.com/

Perl help, tutorials, and examples: http://johnbokma.com/perl/
 
Reply With Quote
 
Peter J. Holzer
Guest
Posts: n/a
 
      01-14-2007
On 2007-01-14 10:04, Mark Hobley <(E-Mail Removed)> wrote:
> John Bokma <(E-Mail Removed)> wrote:
>> My guess: because he wants to know why this one "doesn't work" instead of
>> reading: "use this instead".

>
> I am writing Perl documentation. All these points seem to be missed in the
> reference books that I am using, which incidently are extremely big and run
> into several thousand pages each and cost me quite a few quid.
>
> It seems strange that if I increment $l (which equals 'z') then I now have a
> value that is comparitively less than 'z'.


That's because the "le" operator doesn't define "less" and "greater" in
the same sense as "++" increments. The same happens if you use numbers:

for (my $l = 0; $l le 9; $l++) {
print "$l ";
}

prints

0 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89

Because 90 is the first number which is greater than 9 in a string
comparison.

Only with numbers there is a simple solution (use "<=" instead of "le"),
while there is no builtin comparison operator for "alphanumeric
numbers".

hp


--
_ | Peter J. Holzer | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR | > ist?
| | | (E-Mail Removed) | Was sonst wäre der Sinn des Erfindens?
__/ | http://www.hjp.at/ | -- P. Einstein u. V. Gringmuth in desd
 
Reply With Quote
 
Mark Hobley
Guest
Posts: n/a
 
      01-14-2007
Uri Guttman <(E-Mail Removed)> wrote:

> what is a reverse loop?


I meant a decremental loop that goes from a higher value to a lower one.

perl has no such beast. perldoc perlop covers
> magic increment, have you read it?


I have now, but I don't think it is really that clear.

> MH> I often loop through alphabetical sequences in code.
> then you must be the odd one. i rarely do and i rarely see it.


I write educational software, games, data processing and back-end stuff. Maybe
they are more prevalent in these.

Regards,

Mark.

--
Mark Hobley
393 Quinton Road West
QUINTON
Birmingham
B32 1QE

Telephone: (0121) 247 1596
International: 0044 121 247 1596

Email: markhobley at hotpop dot donottypethisbit com

http://markhobley.yi.org/

 
Reply With Quote
 
Mark Hobley
Guest
Posts: n/a
 
      01-14-2007
Uri Guttman <(E-Mail Removed)> wrote:
>
> what is this 'documenting perl'? perl IS documented and very well at
> that. and there are tons of books about perl. what do you expect to
> bring to the table and make it worthy of reading?


Tutorial stuff really. I have read tutorials, but I keep finding quirky
behaviour that the tutorials forgot to mention.

I don't like perldoc. It is difficult to digest, and doesn't give enough
examples, and the reference books that I have spent a small fortune on, don't
mention some of the pitfalls that I am encountering.

Regards,

Mark.

--
Mark Hobley
393 Quinton Road West
QUINTON
Birmingham
B32 1QE

Telephone: (0121) 247 1596
International: 0044 121 247 1596

Email: markhobley at hotpop dot donottypethisbit com

http://markhobley.yi.org/

 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      01-14-2007
>>>>> "MH" == Mark Hobley <(E-Mail Removed)> writes:

MH> Uri Guttman <(E-Mail Removed)> wrote:
>>
>> what is this 'documenting perl'? perl IS documented and very well at
>> that. and there are tons of books about perl. what do you expect to
>> bring to the table and make it worthy of reading?


MH> Tutorial stuff really. I have read tutorials, but I keep finding
MH> quirky behaviour that the tutorials forgot to mention.

almost all perl tutes on the web suck donkey dick. everytime i hear of
one i check it out and see how fast i can find stupid bugs and
comments. i have rarely been disappointed. in my future copious spare
time i will make a page of perl tutes hall of shame.

MH> I don't like perldoc. It is difficult to digest, and doesn't give
MH> enough examples, and the reference books that I have spent a small
MH> fortune on, don't mention some of the pitfalls that I am
MH> encountering.

you don't understand that perldoc is documentation and not tutorial. but
there are a fair number of tutes in there now.

just as a warning to you, writing perl tutes is not easy (witness all
the bad ones out there). if you have trouble reading and comprehending
the existing docs (as with your magic increment issue) bodes poorly for
your proposed tute. i could be wrong but the odds are with me. i know
many perl book authors and how sharp they are and how much perl they
know. to write a tute you need to know more perl than most hackers,
write extremely well, be able to express concepts clearly, concisely and
have plenty of good examples. this is a tough task for anyone.

uri

--
Uri Guttman ------ (E-Mail Removed) -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      01-14-2007
Mark Hobley schreef:


> I don't like perldoc. It is difficult to digest, and doesn't give
> enough examples, and the reference books that I have spent a small
> fortune on, don't mention some of the pitfalls that I am encountering.


Actually a nice title for an article: Perl Pitfalls. Last week (and not
here) we discussed Tropical Perl, a book about how far you can get with
Perl in a don't-worry-be-happy style. Perl Pitfalls can be about things
like using 'le' when you shouldn't and about how to solidly spoil the
value of $_ && about how to be bitten best by binops.

--
Affijn, Ruud

"Gewoon is een tijger."

 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      01-14-2007
>>>>> "MH" == Mark Hobley <(E-Mail Removed)> writes:

MH> perl has no such beast. perldoc perlop covers
>> magic increment, have you read it?


MH> I have now, but I don't think it is really that clear.

clear to me.

The auto-increment operator has a little extra builtin magic
to it. If you increment a variable that is numeric, or that
has ever been used in a numeric context, you get a normal
increment. If, however, the variable has been used in only
string contexts since it was set, and has a value that is
not the empty string and matches the pattern
"/^[a-zA-Z]*[0-9]*\z/", the increment is done as a string,
preserving each character within its range, with carry:

print ++($foo = '99'); # prints '100'
print ++($foo = 'a0'); # prints 'a1'
print ++($foo = 'Az'); # prints 'Ba'
print ++($foo = 'zz'); # prints 'aaa'

what part of that do you find unclear? it shows the rollover case in
numeric and similarly to your example with zz -> aaa.

MH> I often loop through alphabetical sequences in code.
>> then you must be the odd one. i rarely do and i rarely see it.


MH> I write educational software, games, data processing and back-end
MH> stuff. Maybe they are more prevalent in these.

i doubt that. i have coded many different projects and don't see string
increment being needed often. but you could be using the only hammer you
have to work on different nails. i see that all the time.

uri

--
Uri Guttman ------ (E-Mail Removed) -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
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
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
Re: convert unicode characters to visibly similar ascii characters Laszlo Nagy Python 6 07-02-2008 04:42 PM
Re: convert unicode characters to visibly similar ascii characters M.-A. Lemburg Python 0 07-02-2008 08:39 AM
Re: convert unicode characters to visibly similar ascii characters Terry Reedy Python 0 07-01-2008 07:46 PM
[FR/EN] how to convert the characters ASCII(0-255) to ASCII(0-127) Alextophi Perl Misc 8 12-30-2005 10:43 AM



Advertisments