| |||||||||||
| |||||||||||
Eights and nines Posted by TedH (TedH), 15 June 2005 Hi, 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. Code:
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 2005 If you put a zero in front of a number, it's taken as Octal ![]() Full reply to follow Posted by TedH (TedH), 15 June 2005 So 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 2005 Could try quoting the numbers, perl would then parse these as strings and automagically convert them back to numbers if you numerically compared themCode:
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. http://www.perl.com/doc/manual/html/pod/perlfunc/exists.html Posted by admin (Graham Ellis), 15 June 2005 Here's how I would do it ... shorter but harder to follow ... a list of month names ...!Code:
earth-wind-and-fire:~/jun05 grahamellis$ perl ted Month 01 is Jan Month 08 is Aug Month 12 is Dec earth-wind-and-fire:~/jun05 grahamellis$ Posted by TedH (TedH), 15 June 2005 Great, 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). - Ted This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |