Eights and nines
Posted by TedH (TedH), 15 June 2005Hi, hmmm...okay, what does Perl have against 08 and 09?
In the scripts I'm putting together a folder is created each month with 'yearmonth' as it's name (January 2005 = 200501).
I can scan for the folders and separate the 2005 and the 01 into a variable each ($aa is the year, $bb is the month).
Now it pleased me no end that I managed to do that without coming to a forum or phoning up somebody. So the next step was doing fine. I could use if and elsif to swap stuff around and have 01 print as Jan etc. Great thought I, so did the rest of the year.
Then Perl decides to kick out 08 and 09 as illegal! I'm not using the date/time function for this as this doesn't actually relate to that function.
and get this response (no matter what I try):
Illegal octal digit '8' at c:\IGO\CGI-BIN\TDA\T1.PL line 14, at end of line
Illegal octal digit '9' at c:\IGO\CGI-BIN\TDA\T1.PL line 15, at end of line
Now I'm sure that Larry Wall had a very good reason for doing this - but it doesn't half make things difficult for the rest of us...
I bet this has to do with binary doesn't it?
I sure come up with some doozies don't I?
What to do - Ted
Posted by admin (Graham Ellis), 15 June 2005If you put a zero in front of a number, it's taken as Octal
Full reply to follow
Posted by TedH (TedH), 15 June 2005So a long winded way would be to assign each number to a variable ($a=01, etc.), then instead of having the numbers in if/else statements, insert the variables.
Tried it and it worked. I suppose then to make the code smaller I could make it work from arrays? Yeah?
Posted by John_Moylan (jfp), 15 June 2005Could try quoting the numbers, perl would then parse these as strings and automagically convert them back to numbers if you numerically compared them
I may be talking rubbish, but it compiled (perl -c) without warnings.
Note: I realise this is test code but it really looks like its screaming out for a hash, then you can use exists() to see if the key is there.
Posted by admin (Graham Ellis), 15 June 2005Here's how I would do it ... shorter but harder to follow ... a list of month names ...!
earth-wind-and-fire:~/jun05 grahamellis$ perl ted
Month 01 is Jan
Month 08 is Aug
Month 12 is Dec
Posted by TedH (TedH), 15 June 2005Great, both work. The shorter version from Graham solves this problem.
JFP, the quotes did do the stuff and can certainly be used on some less complicated stuff that doesn't have as much input.
Thanks once again.
Graham, I couldn't get the images off the camera so am looking for an alternative (anything but Kodak).
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: email@example.com • WEB: http://www.wellho.net • SKYPE: wellho