Re: Help needed with here documents (security?)
Another way of handling is to use one of the availabe Email::* modules on CPAN. This would have the advantages of (beside you don't have to worry about details of string quoting): - better code, as you write down what you intend to do instead of how you do it - better security, as those modules already handles (hopefully) the security breaches - you don't have to think a lot of stuff other have already thought a lot about -- Don't Repeat Yourself or other ones For example [untested]: use Email::Simple; my $email = Email::Simple-create( header = [ From = $sender_addr, To = 'ad...@tristatelogic.com', X-Server-Protocol = $server_protocol, X-Http-User-Agent = $http_user_agent, X-Http-Referer = $http_referer, X-Remote-Addr = $remote_addr, X-Remote-Host = $remote_host, ], body = $message ); print $email-as_string; Greetings, Janek -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with here documents (security?)
On Thu, 24 Oct 2013 13:52:51 +0200 Janek Schleicher janek_schleic...@yahoo.de wrote: use Email::Simple; my $email = Email::Simple-create( header = [ From = $sender_addr, To = 'ad...@tristatelogic.com', X-Server-Protocol = $server_protocol, X-Http-User-Agent = $http_user_agent, X-Http-Referer = $http_referer, X-Remote-Addr = $remote_addr, X-Remote-Host = $remote_host, ], body = $message ); Why are you using an anonymous array for the header? Wouldn't an anonymous hash be better? A hash would insist on an even number of elements. -- Don't stop where the ink does. Shawn -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with here documents (security?)
On Oct 24, 2013, at 6:07 AM, Shawn H Corey wrote: On Thu, 24 Oct 2013 13:52:51 +0200 Janek Schleicher janek_schleic...@yahoo.de wrote: use Email::Simple; my $email = Email::Simple-create( header = [ From = $sender_addr, To = 'ad...@tristatelogic.com', X-Server-Protocol = $server_protocol, X-Http-User-Agent = $http_user_agent, X-Http-Referer = $http_referer, X-Remote-Addr = $remote_addr, X-Remote-Host = $remote_host, ], body = $message ); Why are you using an anonymous array for the header? Wouldn't an anonymous hash be better? A hash would insist on an even number of elements. According to the documentation for Email::Simple, an anonymous array is required for the header parameter of the create method. http://search.cpan.org/~rjbs/Email-Simple-2.202/lib/Email/Simple.pm#create Suggestions for improvement should be directed to the module's author (but you knew that, right?). -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with here documents (security?)
On Thu, 24 Oct 2013 06:30:58 -0700 Jim Gibson jimsgib...@gmail.com wrote: On Oct 24, 2013, at 6:07 AM, Shawn H Corey wrote: On Thu, 24 Oct 2013 13:52:51 +0200 Janek Schleicher janek_schleic...@yahoo.de wrote: use Email::Simple; my $email = Email::Simple-create( header = [ From = $sender_addr, To = 'ad...@tristatelogic.com', X-Server-Protocol = $server_protocol, X-Http-User-Agent = $http_user_agent, X-Http-Referer = $http_referer, X-Remote-Addr = $remote_addr, X-Remote-Host = $remote_host, ], body = $message ); Why are you using an anonymous array for the header? Wouldn't an anonymous hash be better? A hash would insist on an even number of elements. According to the documentation for Email::Simple, an anonymous array is required for the header parameter of the create method. http://search.cpan.org/~rjbs/Email-Simple-2.202/lib/Email/Simple.pm#create Suggestions for improvement should be directed to the module's author (but you knew that, right?). Well, the only reason to do that is to preserve the order. I didn't realize that email was that pernickety. -- Don't stop where the ink does. Shawn -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with here documents (security?)
Am 24.10.2013 15:07, schrieb Shawn H Corey: my $email = Email::Simple-create( header = [ From = $sender_addr, To = 'ad...@tristatelogic.com', X-Server-Protocol = $server_protocol, X-Http-User-Agent = $http_user_agent, X-Http-Referer = $http_referer, X-Remote-Addr = $remote_addr, X-Remote-Host = $remote_host, ], body = $message ); Why are you using an anonymous array for the header? Wouldn't an anonymous hash be better? A hash would insist on an even number of elements. I just followed the synopsis of the documentation of this CPAN-Module as you can find it here: https://metacpan.org/pod/Email::Simple :-) I agree to you, that a ref to a hash like header = { ... } would somehow be more logic, but I didn't wrote this CPAN module. Greetings, Janek -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with here documents (security?)
From: Janek Schleicher janek_schleic...@yahoo.de Am 24.10.2013 15:07, schrieb Shawn H Corey: my $email = Email::Simple-create( header = [ From = $sender_addr, To = 'ad...@tristatelogic.com', X-Server-Protocol = $server_protocol, X-Http-User-Agent = $http_user_agent, X-Http-Referer = $http_referer, X-Remote-Addr = $remote_addr, X-Remote-Host = $remote_host, ], body = $message ); Why are you using an anonymous array for the header? Wouldn't an anonymous hash be better? A hash would insist on an even number of elements. I just followed the synopsis of the documentation of this CPAN-Module as you can find it here: https://metacpan.org/pod/Email::Simple :-) I agree to you, that a ref to a hash like header = { ... } would somehow be more logic, but I didn't wrote this CPAN module. Aren't duplicate headers allowed in email headers? Because if they are allowed, maybe this is the reason an arrayref is used, and not a hashref. Octavian -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with here documents (security?)
In message 7E7181F2497441C88988DD1F16E4A743@octavianf303f0, you wrote: From: Janek Schleicher janek_schleic...@yahoo.de Am 24.10.2013 15:07, schrieb Shawn H Corey: my $email = Email::Simple-create( header = [ From = $sender_addr, To = 'ad...@tristatelogic.com', X-Server-Protocol = $server_protocol, X-Http-User-Agent = $http_user_agent, X-Http-Referer = $http_referer, X-Remote-Addr = $remote_addr, X-Remote-Host = $remote_host, ], body = $message ); Why are you using an anonymous array for the header? Wouldn't an anonymous hash be better? A hash would insist on an even number of elements. I just followed the synopsis of the documentation of this CPAN-Module as you can find it here: https://metacpan.org/pod/Email::Simple :-) I agree to you, that a ref to a hash like header = { ... } would somehow be more logic, but I didn't wrote this CPAN module. Aren't duplicate headers allowed in email headers? Yes. The vast majority of all the e-mail I have in my big piles of e-mails has multiple Received: headers, in particular. And yes, order matters with respect to interpreting those (but also it matters in the case of other headres sometimes too.) But, getting back to my original 2 questions... I want to stress that I did not ask how to formulate and/or send a properly formatted e-mail message. I can handle that part, even if perhaps only in my own clumsey way. What is of more interest to me, again, is the question of how to properly validate (a) a string that's given on a form and which is meant to represent a person's name, an also (b) a string that is given in a form and that is supposed to represent a person's e-mail address. Assume that I want to do both these things *and*, to the maximum extent possible, I want to reject any all strings that are implausible name and/or e-mail address strings. How? What's the code to do each of these things. These certainly should both be well-solved problems by now, but in case they aren't, I'd like to take my own humble wack at developing good solutions for both problems. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with here documents (security?)
On Oct 24, 2013, at 11:59 AM, Ronald F. Guilmette wrote: But, getting back to my original 2 questions... I want to stress that I did not ask how to formulate and/or send a properly formatted e-mail message. I can handle that part, even if perhaps only in my own clumsey way. What is of more interest to me, again, is the question of how to properly validate (a) a string that's given on a form and which is meant to represent a person's name, an also (b) a string that is given in a form and that is supposed to represent a person's e-mail address. Assume that I want to do both these things *and*, to the maximum extent possible, I want to reject any all strings that are implausible name and/or e-mail address strings. How? What's the code to do each of these things. These certainly should both be well-solved problems by now, but in case they aren't, I'd like to take my own humble wack at developing good solutions for both problems. See the advice in Perl FAQ #9 How do I check a valid mail address? The command 'perldoc -q address' will get you that entry. Synopsis: it is difficult to write a regular expression to parse and validate an email address. The modules Email::Valid and RFC::RFC822::Address might help. I usually just check to see if the string contains the '@' character. I might also delete any character that is not in [a-zA-Z0-9.:;_@-] (but see the longer RE in the FAQ). -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with here documents (security?)
Ronald F. Guilmette wrote: In message5268663c.4040...@stemsystems.com, Uri Guttmanu...@stemsystems.comwrote: i think a blank line with . will end input to smtp servers. try that too in the line after the from field. DING DING DING!!! Give that man a cupie doll, because he's the winner of today's perplexing puzzle test! In short, yes, when I first read the above sentence, I said to myself No way! I know that when input is coming in ``over the wire'' to a normal SMTP server *and* when it is already in ``DATA'' (input message collection) SMTP protocol mode, *then* a period alone on a line ends input, *however* in this case Postfix is reading the message from STDIN, and so there is really no need for that period-alone-on-a-line bit of SMTP protocol to apply in this case, because EOF in this case can be signalled by... well... an actual EOF, of course! stdin (and stdout) are part of a stream protocol and as such are not about files and do not signal End-Of-File which is part of why emails use the single period to signal the end of the message. John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with here documents (security?)
On Thu, 24 Oct 2013 14:55:51 -0700 John W. Krahn jwkr...@shaw.ca wrote: stdin (and stdout) are part of a stream protocol and as such are not about files and do not signal End-Of-File which is part of why emails use the single period to signal the end of the message. I thought that was from the old mail(1) program. To indicate to it that you were done typing your message and it could send it, you typed a single period on a line. And all streams have end of file. -- Don't stop where the ink does. Shawn -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with here documents (security?)
In message 52699767.2050...@shaw.ca, you wrote: Ronald F. Guilmette wrote: In message5268663c.4040...@stemsystems.com, Uri Guttmanu...@stemsystems.comwrote: i think a blank line with . will end input to smtp servers. try that too in the line after the from field. DING DING DING!!! Give that man a cupie doll, because he's the winner of today's perplexing puzzle test! In short, yes, when I first read the above sentence, I said to myself No way! I know that when input is coming in ``over the wire'' to a normal SMTP server *and* when it is already in ``DATA'' (input message collection) SMTP protocol mode, *then* a period alone on a line ends input, *however* in this case Postfix is reading the message from STDIN, and so there is really no need for that period-alone-on-a-line bit of SMTP protocol to apply in this case, because EOF in this case can be signalled by... well... an actual EOF, of course! stdin (and stdout) are part of a stream protocol and as such are not about files and do not signal End-Of-File which is part of why emails use the single period to signal the end of the message. I'm not sure that I can even properly parse what you just said, but if I am parsing what you said correctly, then I disagree. C language stdio streams _do_ most definietly signal EOF. See: man 3 feof In the case of *bi-directional* network *sockets* used for SMTP transactions however, it is necessary to use some sort of in-band signaling (i.e. the period alone on a line) to signal the end of the message text, because after that, the socket must remain open so that the client can receive back and then properly interpret and react to whatever following XXX numeric response code the server decides to send back, just after the client has sent the end-of-message indicator. But when Postfix is reading a message from stdin, and when it gets to the end of the message... well, there isn't any more interaction, and in fact their could not be, because this is just uni-directional data flow. The message comes in on Postfix's stdin and then its done and that's it. So in this case, to my way of thinking at least, it is downright nonsensical that in this context Postfix is even looking for (or recognizing) the specialized in-band end-of-message indicator that, of necessity, had to be invented for and used with by-directional SMTP transactions/conversations. Sigh. I'll would wager that Wietse probably feels the same way, but that, as is often the case, he was constrained by the need to implement odd bits of behavior like this in order to be maximally compatible with the pre-existing Sendmail behavior. :-( Anyway, I'll be asking about this.. on the appropriate mailing list, of course. (It just feels wrong to me, and is definitely *not* what I would call ``intutive'' behavior.) Regards, rfg -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with here documents (security?)
In message 20131024183255.3c233104@sage, you wrote: On Thu, 24 Oct 2013 14:55:51 -0700 John W. Krahn jwkr...@shaw.ca wrote: stdin (and stdout) are part of a stream protocol and as such are not about files and do not signal End-Of-File which is part of why emails use the single period to signal the end of the message. I thought that was from the old mail(1) program. To indicate to it that you were done typing your message and it could send it, you typed a single period on a line. And all streams have end of file. Yes. And in my setup, at least, EOF can be signaled from the keyboard with the (traditional?) ^D. Obviously, that could be used, e.g. in cases where somebody wants to interactively type a mail message into some mail client that lacks a front-end editor of any kind. I don't see any need for this in-band period/newline protocol within such contexts. (And as I have now learned, it can cause unnecessary and not entirely pleasant surprises.) Regards, rfg -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with here documents (security?)
From: Ronald F. Guilmette r...@tristatelogic.com In message 7E7181F2497441C88988DD1F16E4A743@octavianf303f0, you wrote: From: Janek Schleicher janek_schleic...@yahoo.de Am 24.10.2013 15:07, schrieb Shawn H Corey: my $email = Email::Simple-create( header = [ From = $sender_addr, To = 'ad...@tristatelogic.com', X-Server-Protocol = $server_protocol, X-Http-User-Agent = $http_user_agent, X-Http-Referer = $http_referer, X-Remote-Addr = $remote_addr, X-Remote-Host = $remote_host, ], body = $message ); Why are you using an anonymous array for the header? Wouldn't an anonymous hash be better? A hash would insist on an even number of elements. I just followed the synopsis of the documentation of this CPAN-Module as you can find it here: https://metacpan.org/pod/Email::Simple :-) I agree to you, that a ref to a hash like header = { ... } would somehow be more logic, but I didn't wrote this CPAN module. Aren't duplicate headers allowed in email headers? Yes. The vast majority of all the e-mail I have in my big piles of e-mails has multiple Received: headers, in particular. And yes, order matters with respect to interpreting those (but also it matters in the case of other headres sometimes too.) But, getting back to my original 2 questions... I want to stress that I did not ask how to formulate and/or send a properly formatted e-mail message. I can handle that part, even if perhaps only in my own clumsey way. What is of more interest to me, again, is the question of how to properly validate (a) a string that's given on a form and which is meant to represent a person's name, an also (b) a string that is given in a form and that is supposed to represent a person's e-mail address. Assume that I want to do both these things *and*, to the maximum extent possible, I want to reject any all strings that are implausible name and/or e-mail address strings. How? What's the code to do each of these things. These certainly should both be well-solved problems by now, but in case they aren't, I'd like to take my own humble wack at developing good solutions for both problems. I think that what you want is not possible. :-) I mean, I don't think it is possible to create a rule that simply filters out all strings which can't be names or all strings that can't be email addresses, without filtering out good names and email addresses, of course. There are many language scripts that can be use to write the names with, and that filter should not filter the names written with chinese/japanese/arabic/kirilic/hebrew and many other exotic scripts used with 8-bit encodings or with Unicode. If you just want to filter the names which are not English-like names, you can deny anything which is not [a-zA-Z0-9\s.'-]. If you want to also allow some Unicode letters and not only A-Za-z, you can use \p{L} or \p{Letter} instead of A-Za-z. But there may be strange chars composed from a letter followed one or more diacritic signs, so the regexp may need to be more complex. Regarding the email addresses... the RFCs allow many types of email addresses which are almost never used now. I don't know if there is a current RFC or standard that defines the rules for an email address which is currently used by most email services. The filter could be based on that rule, but it might filter out some valid exotic email addresses. On the other hand, if the existing rules are used, they may allow strings which look like a valid email address, even if that kind of email address is not used by nobody these days. So these filters could be strict and allow only the most expected name and email formats, but they might disallow some valid emails and names, or they can accept all the possible formats (like Email::Valid does in case of an email address), but then you can get strange formats that your software can't handle. It could be helpful if you'd have the rules for the email formats accepted by your email server. If the email addresses follow that rule it means that they are OK. If they don't follow it, then it doesn't matter that the addresses are valid, because they can't be handled anyway. Octavian -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Help needed with here documents (security?)
I'm not actually/formally a Perl beginner, but this problem is making me feel like one. About a day ago, some schmuck set about to try, hard, to exploit the personally written Perl code I have in place and that processes the input for the contact form on my web site (www.tristatelogic.com). Fortunately, it appears that 99+% of these attempts failed miserably, because I was already well and truly aware of the dangers of processing un-checked input data before I started writing the contact form handler code, several years ago. What worries me is that I have two messages in my inbox that appear to indicate that not all of these exploit attempts failed. It now seems at least possible that two attempts may have breached my security, possibly because of a misunderstnding on my part of here documents and the way they actually work. So I need, desperately, to ask about that now. And I have a *very* specific question. Based on the data I am looking at, it appears that sometimes, or under some (obscure?) circumstances, Perl fails to read all of the way down to the EOF that is supposed to signal the end of a here document. I am trying to understand what conditions might cause that very unexpected behavior on Perl's part. Given the following code snippet, under what conditions, if any, would the resulting generated message (assuming it is immediately piped into Postfix via the command |/usr/sbin/sendmail -bm -f nobody admin) *not* include lines from Subject: on down through X-Remote-Host: = ... print SM EOF; To: Tristatelogic.Com Administrator admin\@tristatelogic.com From: $sender_name $sender_addr Subject: Your message to Tristatelogic.Com X-Server-Protocol: $server_protocol X-Http-User-Agent: $http_user_agent X-Http-Referer: $http_referer X-Remote-Addr: $remote_addr X-Remote-Host: $remote_host $message EOF ... = The puzzle is that I have received (in my admin inbox) two messages that were clearly generated through and via the script that contains the above code, *however* these two e-mail messages in particular, for some reason *do* include the: To: Tristatelogic.Com Administrator admin\@tristatelogic.com header, and each one also includes a From: header, but then after that, all the other headers that I had assumed would *always* be part of such messages are not there... and it is quite apparent, because of the context, that this must be because of the fact that the attacker who was looking for exploits in my web site contact form kept on trying to put various quirky and weird strings into the sender address data field in/on the form. In at least two cases, it appears that he managed to find magic strings that would cause the above snippet of code to not function as expected... and this is *very* worrying to me. So I want desperately to understand here documents better, and in particular, anything that might cause them to not behave in an intutive fashion, particularly when (expanded) variable values are part of the here document. Please note that I perform only *very* minimal pre-filtering on the $sender_name and $sender_addr variable values prior to execution of the above code. Those two are only checked for undef'ness and if they are not defined after: my $cgi = new CGI::Lite; my %form = $cgi-parse_form_data; my $sender_name = $form{sender_name}; my $sender_addr = $form{sender_addr}; my $message = $form{message}; then I just do this to make sure they have at least _some_ value: $sender_name = unless defined $sender_name; $sender_addr = unless defined $sender_addr; Any help, guidance, or explanations of subtle aspects of here documents that maybe I don't understand would be greatly appreciated. Regards, rfg P.S. Don't bother trying to reproduce the exploit by putting weird stuff into the contact form on my web site. I have revamped the contact form handler script and have removed the here document it formerly contained entirely. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with here documents (security?)
In message 39517.1382566...@server1.tristatelogic.com, I wrote: About a day ago, some schmuck set about to try, hard, to exploit the personally written Perl code I have in place and that processes the input for the contact form on my web site... I neglected to mention that this was obviously nothing personal. Many of the messages I did get as a result of these exploit attempts contained the string 3137 LagunaStreet. A google of that exact string, quoted, turns up: 1) A probably entirely unrelated and innocent Real Estate firm in San Francisco, and... 2) ... more than 125K hits having something to do with this same schmuck going around making attempts to exploit other forms on other people's web sites, clearly with evil, if not to say criminal intent. (Some of the hits suggest that this is just a comment spammer, but the messages I did get via my not-actually- exploited contact form on my web site indicate clearly that he was trying hard to lay hands on my /etc/passwd file, and I rather doubt that mere comment spammers do that.) Regards, rfg -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with here documents (security?)
On 10/23/2013 06:18 PM, Ronald F. Guilmette wrote: ... print SM EOF; To: Tristatelogic.Com Administrator admin\@tristatelogic.com From: $sender_name $sender_addr Subject: Your message to Tristatelogic.Com X-Server-Protocol: $server_protocol X-Http-User-Agent: $http_user_agent X-Http-Referer: $http_referer X-Remote-Addr: $remote_addr X-Remote-Host: $remote_host $message EOF ... it isn't a here doc problem. they are just alternate ways of making strings and nothing special about them. also they don't need to use EOF for the token. The puzzle is that I have received (in my admin inbox) two messages that were clearly generated through and via the script that contains the above code, *however* these two e-mail messages in particular, for some reason *do* include the: To: Tristatelogic.Com Administrator admin\@tristatelogic.com header, and each one also includes a From: header, but then after that, all the other headers that I had assumed would *always* be part of such messages are not there... and it is quite apparent, because of the context, that this must be because of the fact that the attacker who was looking for exploits in my web site contact form kept on trying to put various quirky and weird strings into the sender address data field in/on the form. so your email didn't get anything beyond the from: line? that is the big clue. email servers read headers until the first blank line. i bet the from field was filled with a string that had a newline in it (somehow). there may be another cause but it can't be a here doc as the data has no access to your code. something in the data caused the rest of the headers not to be processed by the mailer. P.S. Don't bother trying to reproduce the exploit by putting weird stuff into the contact form on my web site. I have revamped the contact form handler script and have removed the here document it formerly contained entirely. it isn't the here doc but the data. it can't be the here doc. if you changed it to another string style the same exploit is there. uri -- Uri Guttman - The Perl Hunter The Best Perl Jobs, The Best Perl Hackers http://PerlHunter.com -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with here documents (security?)
In message 52684f18.2000...@stemsystems.com, you wrote: On 10/23/2013 06:18 PM, Ronald F. Guilmette wrote: ... print SM EOF; To: Tristatelogic.Com Administrator admin\@tristatelogic.com From: $sender_name $sender_addr Subject: Your message to Tristatelogic.Com X-Server-Protocol: $server_protocol X-Http-User-Agent: $http_user_agent X-Http-Referer: $http_referer X-Remote-Addr: $remote_addr X-Remote-Host: $remote_host $message EOF ... it isn't a here doc problem. they are just alternate ways of making strings and nothing special about them. also they don't need to use EOF for the token. I am aware of that last part. The puzzle is that I have received (in my admin inbox) two messages that were clearly generated through and via the script that contains the above code, *however* these two e-mail messages in particular, for some reason *do* include the: To: Tristatelogic.Com Administrator admin\@tristatelogic.com header, and each one also includes a From: header, but then after that, all the other headers that I had assumed would *always* be part of such messages are not there... and it is quite apparent, because of the context, that this must be because of the fact that the attacker who was looking for exploits in my web site contact form kept on trying to put various quirky and weird strings into the sender address data field in/on the form. so your email didn't get anything beyond the from: line? That is correct. that is the big clue. email servers read headers until the first blank line. I _do_ know more than a little about mail servers, and while you are basically correct, i.e. that Postfix would certainly view anything past the first \n\n encountered as being *message* data (not headers), in the two messages in question, there was *nothing* in the way of body text, other than a single character. Assuming your theory is correct and that the attacker was able to sneak in a newline or two... into the input data constituting the sender name or address fields... then it would still have been the case that within the message body, I would have seen: Subject: Your message to Tristatelogic.Com X-Server-Protocol: bla bla bla and so on. But I didn't! So there is still a deep mystery here. i bet the from field was filled with a string that had a newline in it (somehow). See above. That would not adequantly explain this message: === Return-Path: nob...@tristatelogic.com X-Original-To: admin Delivered-To: ad...@tristatelogic.com Received: by segfault.tristatelogic.com (Postfix, from userid 80) id C15FD3B403; Tue, 22 Oct 2013 04:42:59 -0700 (PDT) To: Monkeys.Com Administrator ad...@monkeys.com From: '@tristatelogic.com, '\)@tristatelogic.com;, |]*{@tristatelogic.com Message-Id: 20131022114259.c15fd3b...@segfault.tristatelogic.com Date: Tue, 22 Oct 2013 04:42:59 -0700 (PDT) === there may be another cause but it can't be a here doc as the data has no access to your code. something in the data caused the rest of the headers not to be processed by the mailer. I believe that you may be on to something here, but it is more than just Postfix seeing a \n\n and believeing that it had encountered the end of the headers. It is possible that something in the input stream I gave it signaled to it the end of *all* input (not just headers) but that is still perplexing. What character or character sequence would do that? I will have to dig into the Postfix docs and research that question. I cannot imagine that it would stop reading stdin on anything other than an actual EOF. P.S. Don't bother trying to reproduce the exploit by putting weird stuff into the contact form on my web site. I have revamped the contact form handler script and have removed the here document it formerly contained entirely. it isn't the here doc but the data. it can't be the here doc. if you changed it to another string style the same exploit is there. Well, I added to the script some rudimentary filtering/validation of the input strings in question also. Regards, rfg -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with here documents (security?)
On Wed, 23 Oct 2013 16:12:12 -0700 Ronald F. Guilmette r...@tristatelogic.com wrote: I believe that you may be on to something here, but it is more than just Postfix seeing a \n\n and believeing that it had encountered the end of the headers. It is possible that something in the input stream I gave it signaled to it the end of *all* input (not just headers) but that is still perplexing. What character or character sequence would do that? Sometimes if the string has a null character, \0, it won't read pass it. This, of course, is a bug but determining what piece of software is doing it will be difficult. -- Don't stop where the ink does. Shawn -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with here documents (security?)
On 2013-10-24 01:12, Ronald F. Guilmette wrote: In message 52684f18.2000...@stemsystems.com, you wrote: On 10/23/2013 06:18 PM, Ronald F. Guilmette wrote: ... print SM EOF; To: Tristatelogic.Com Administrator admin\@tristatelogic.com From: $sender_name $sender_addr Subject: Your message to Tristatelogic.Com X-Server-Protocol: $server_protocol X-Http-User-Agent: $http_user_agent X-Http-Referer: $http_referer X-Remote-Addr: $remote_addr X-Remote-Host: $remote_host $message EOF ... it isn't a here doc problem. they are just alternate ways of making strings and nothing special about them. also they don't need to use EOF for the token. I am aware of that last part. The puzzle is that I have received (in my admin inbox) two messages that were clearly generated through and via the script that contains the above code, *however* these two e-mail messages in particular, for some reason *do* include the: To: Tristatelogic.Com Administrator admin\@tristatelogic.com header, and each one also includes a From: header, but then after that, all the other headers that I had assumed would *always* be part of such messages are not there... and it is quite apparent, because of the context, that this must be because of the fact that the attacker who was looking for exploits in my web site contact form kept on trying to put various quirky and weird strings into the sender address data field in/on the form. so your email didn't get anything beyond the from: line? That is correct. that is the big clue. email servers read headers until the first blank line. I _do_ know more than a little about mail servers, and while you are basically correct, i.e. that Postfix would certainly view anything past the first \n\n encountered as being *message* data (not headers), in the two messages in question, there was *nothing* in the way of body text, other than a single character. Assuming your theory is correct and that the attacker was able to sneak in a newline or two... into the input data constituting the sender name or address fields... then it would still have been the case that within the message body, I would have seen: Subject: Your message to Tristatelogic.Com X-Server-Protocol: bla bla bla and so on. But I didn't! So there is still a deep mystery here. i bet the from field was filled with a string that had a newline in it (somehow). See above. That would not adequantly explain this message: === Return-Path: nob...@tristatelogic.com X-Original-To: admin Delivered-To: ad...@tristatelogic.com Received: by segfault.tristatelogic.com (Postfix, from userid 80) id C15FD3B403; Tue, 22 Oct 2013 04:42:59 -0700 (PDT) To: Monkeys.Com Administrator ad...@monkeys.com From: '@tristatelogic.com, '\)@tristatelogic.com;, |]*{@tristatelogic.com Message-Id: 20131022114259.c15fd3b...@segfault.tristatelogic.com Date: Tue, 22 Oct 2013 04:42:59 -0700 (PDT) === there may be another cause but it can't be a here doc as the data has no access to your code. something in the data caused the rest of the headers not to be processed by the mailer. I believe that you may be on to something here, but it is more than just Postfix seeing a \n\n and believeing that it had encountered the end of the headers. It is possible that something in the input stream I gave it signaled to it the end of *all* input (not just headers) but that is still perplexing. What character or character sequence would do that? I will have to dig into the Postfix docs and research that question. I cannot imagine that it would stop reading stdin on anything other than an actual EOF. P.S. Don't bother trying to reproduce the exploit by putting weird stuff into the contact form on my web site. I have revamped the contact form handler script and have removed the here document it formerly contained entirely. it isn't the here doc but the data. it can't be the here doc. if you changed it to another string style the same exploit is there. Well, I added to the script some rudimentary filtering/validation of the input strings in question also. Also test with strings with embedded 0-bytes. -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with here documents (security?)
On 10/23/2013 07:12 PM, Ronald F. Guilmette wrote: In message 52684f18.2000...@stemsystems.com, you wrote: I _do_ know more than a little about mail servers, and while you are basically correct, i.e. that Postfix would certainly view anything past the first \n\n encountered as being *message* data (not headers), in the two messages in question, there was *nothing* in the way of body text, other than a single character. i think a blank line with . will end input to smtp servers. try that too in the line after the from field. === there may be another cause but it can't be a here doc as the data has no access to your code. something in the data caused the rest of the headers not to be processed by the mailer. I believe that you may be on to something here, but it is more than just Postfix seeing a \n\n and believeing that it had encountered the end of the headers. It is possible that something in the input stream I gave it signaled to it the end of *all* input (not just headers) but that is still perplexing. What character or character sequence would do that? I will have to dig into the Postfix docs and research that question. I cannot imagine that it would stop reading stdin on anything other than an actual EOF. Well, I added to the script some rudimentary filtering/validation of the input strings in question also. you need more than rudimentary filtering. make sure the from field is one string, no newlines or anything but printable text. uri -- Uri Guttman - The Perl Hunter The Best Perl Jobs, The Best Perl Hackers http://PerlHunter.com -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with here documents (security?)
In message 20131023193228.38cf83e2@sage, you wrote: On Wed, 23 Oct 2013 16:12:12 -0700 Ronald F. Guilmette r...@tristatelogic.com wrote: I believe that you may be on to something here, but it is more than just Postfix seeing a \n\n and believeing that it had encountered the end of the headers. It is possible that something in the input stream I gave it signaled to it the end of *all* input (not just headers) but that is still perplexing. What character or character sequence would do that? Sometimes if the string has a null character, \0, it won't read pass it. This, of course, is a bug but determining what piece of software is doing it will be difficult. Actually, I think now that something _other than_ a mere null byte is causing Postfix to get a bit confused, but as regards to what piece of software is losing its way, it is most definitely Postfix, since my Perl script is piping data directly into that. Anyway, just a few moments ago I realized/remembered that Postfix is trying to _parse_ the headers it is given. This is part of its job... so that it can do wonderful and useful things, like as attaching @domain to (local) e-mail addresses that don't already have that. So anyway, I also then realized that yes, Postfix's parsing of the From: header(s) contained within the data I was feeding it probaby failed, utterly, and *not* because there's any actual ``fault'' in Postfix, but rather because the gobbledegook that my attacker was putting into the web contact form didn't add up to anything that actually constituted anything like an even remotely parseable e-mail address, according to current RFC rules. So this is my current/new theory, i.e. that the attacker _didn't_ actually manage to compromise me or execute any code on my system, but that he _did_ manage to pass in some really twisted and sick strings (where there should have been either a person's name or a person's e-mail address) and then Postfix, perhaps not surprisingly, wasn't able to parse that, and as a result it threw up its hands (in disgust?) after one too many parsing errors. Well, it's a theory anyway. I hope it is correct, because it is making me feel better already. (I *was* seriously* worried that I had been compromised, even if only slightly. Even executing only under the rather limited local `www' account/user, an unauthorized outsider could undoubtedly do a lot of mischief that I wouldn't like.) Regards, rfg -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with here documents (security?)
In message 5268663c.4040...@stemsystems.com, Uri Guttman u...@stemsystems.comwrote: i think a blank line with . will end input to smtp servers. try that too in the line after the from field. DING DING DING!!! Give that man a cupie doll, because he's the winner of today's perplexing puzzle test! In short, yes, when I first read the above sentence, I said to myself No way! I know that when input is coming in ``over the wire'' to a normal SMTP server *and* when it is already in ``DATA'' (input message collection) SMTP protocol mode, *then* a period alone on a line ends input, *however* in this case Postfix is reading the message from STDIN, and so there is really no need for that period-alone-on-a-line bit of SMTP protocol to apply in this case, because EOF in this case can be signalled by... well... an actual EOF, of course! But then, just to be sure, I tried it myself, and lo and behold, Postfix *does* apparently treat period-on-a-line-alone as the end of the input message data, *even when* it is reading the message from STDIN (which, to my way of thinking, is _totally_ bizzare, unnecessary, and certainly un- expected). So thanks! This clears up the mystery pretty completely, I think. The attacker no doubt used the HTTP %xx notation to smugle in some newlines, and also stuck a period in there somewhere, and that would completely explain the content of the two exceptionally mysterious messages I saw. (Thankfully, all this means that I was _most probably_ never actually security compromised in any way.) Well, I added to the script some rudimentary filtering/validation of the input strings in question also. you need more than rudimentary filtering. make sure the from field is one string, no newlines or anything but printable text. Um, yes, sorry. I failed to make my meaning plain. When I said rudimentary filtering of the input strings, what I really had intended to say was that I implemented quick and dirty filtering of the strings in question that is grotesquely *over*-restrictive in each case. (The input validation steps for both name and e-mail address *should*, ideally, be much looser than what I have now, but I am too busy just now to deal with it.) For example, if you try *now* to use my contact form and if you try to use any ``funny'' characters at all in either your name or your e-mail address, the current data collection script will basically refuse that data and then tell you to try again. (I hope that nobody from Europe who has umlauts or grave accents in the correct spellings of their names needs to use that form to contact me anytime soon. :-) Regards, rfg -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with here documents (security?)
In message 40504.1382576...@server1.tristatelogic.com, I wrote: Well, I added to the script some rudimentary filtering/validation of the input strings in question also. you need more than rudimentary filtering. make sure the from field is one string, no newlines or anything but printable text. Um, yes, sorry. I failed to make my meaning plain. When I said rudimentary filtering of the input strings, what I really had intended to say was that I implemented quick and dirty filtering of the strings in question that is grotesquely *over*-restrictive in each case. (The input validation steps for both name and e-mail address *should*, ideally, be much looser than what I have now, but I am too busy just now to deal with it.) For example, if you try *now* to use my contact form and if you try to use any ``funny'' characters at all in either your name or your e-mail address, the current data collection script will basically refuse that data and then tell you to try again. (I hope that nobody from Europe who has umlauts or grave accents in the correct spellings of their names needs to use that form to contact me anytime soon. :-) As a hypothetical, assume for the moment that one day I will have time to implement the validation of the input strings ``properly''. Does anyone wnat to pass me a free clue or two as to how I might do this? The contact form is *really* simple: http://www.tristatelogic.com/contact2.html I know that parsing e-mail address _properly_, i.e. according to all current RFC rules can be really rather complex, so I'll start by looking around to see if there is some existing off-the-shelf Perl package that will do this for me. (Anybody know which one I should be looking at on CPAN?) And I also know that if I want to be really persnickety, I'll even check the domain name part to make sure it has either an associated MX or A record in DNS. I may do that too, but I don't need any help for that, because I already know my way around the DNS:: stuff. As regards to the (person's) name data, can anybody suggest a good and proper filter for that? I'd like it to reject any string that contains *any* characters that simply do not ever belong in a person's name... not just newlines and such. For example, I don't know anybody who writes their name with a (US) dollar sign or exclamation point or a asterisk, or most other special characters. But I don't really know poo about international character sets or how to handle them properly, so I really have no idea how to even start working on a ``proper'' filter for the name string. Any helpful tips would be appreciated. Regards, rfg -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Programming Help Needed
I just wanted to give a big Thank you to all who responded to my inquiry! This will help a lot in my search. Thanks again, Angela -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Programming Help Needed
Your post to jobs.perl.org will likely result in some solicitations from recruiters. You also likely to get a some queries about tele-working. At least that has been our experience. I'm not saying that either is good or bad but it's worth making it clear in the description what your after. You may also ask around at your local Perl Mongers group. They may be able to offer some advise also. Good luck, Dermot. On 2 October 2013 01:12, Angela Barone ang...@italian-getaways.com wrote: On Oct 1, 2013, at 2:45 PM, John SJ Anderson wrote: jobs.perl.org is the definitive place to post Perl jobs. good luck in your search. Thank you, John! I mentioned this link and was told that the last time we used it, we got a lot of responses from people who really didn't know there craft. :( If need be, we'll try it again, but hopefully there's a better solution for us. We're not looking for an individual to do some coding. We would like an actual company, or a team of programmers, who can write a modern, large scale e-commerce solution from the ground up. Does anyone know of a Perl shop - an actual company of developers that can handle bigger jobs like this (from Perl to web design)? Thanks again, Angela
Re: Programming Help Needed
Angela, ActiveState offer professional service: http://www.activestate.com/support/open-source-consulting and Cambria.com. I cannot vouch for either but I looked at them awhile ago. Ian On Tue, Oct 1, 2013 at 4:37 PM, Angela Barone ang...@italian-getaways.comwrote: Hello, I don't know if this type of subject is off limits here, so if it is, please let me know where I can post this request. My employer is looking to replace our existing Perl cart with a new, modern version. He has asked me to help in the search for programmers who would be able to write a new cart from scratch. This would not be a simple shopping cart, but a high-end solution for our next 30 years. Any help as to where we can begin looking for someone to help would be greatly appreciated. I have not been able to find a Perl programming shop in my searches. Thank you, Angela P.S. Feel free to write me off-list. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- Ian http://www.cicsworld.com
Programming Help Needed
Hello, I don't know if this type of subject is off limits here, so if it is, please let me know where I can post this request. My employer is looking to replace our existing Perl cart with a new, modern version. He has asked me to help in the search for programmers who would be able to write a new cart from scratch. This would not be a simple shopping cart, but a high-end solution for our next 30 years. Any help as to where we can begin looking for someone to help would be greatly appreciated. I have not been able to find a Perl programming shop in my searches. Thank you, Angela P.S. Feel free to write me off-list. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Programming Help Needed
jobs.perl.org is the definitive place to post Perl jobs. good luck in your search. On Tue, Oct 1, 2013 at 2:37 PM, Angela Barone ang...@italian-getaways.com wrote: Hello, I don't know if this type of subject is off limits here, so if it is, please let me know where I can post this request. My employer is looking to replace our existing Perl cart with a new, modern version. He has asked me to help in the search for programmers who would be able to write a new cart from scratch. This would not be a simple shopping cart, but a high-end solution for our next 30 years. Any help as to where we can begin looking for someone to help would be greatly appreciated. I have not been able to find a Perl programming shop in my searches. Thank you, Angela P.S. Feel free to write me off-list. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Programming Help Needed
On Oct 1, 2013, at 2:45 PM, John SJ Anderson wrote: jobs.perl.org is the definitive place to post Perl jobs. good luck in your search. Thank you, John! I mentioned this link and was told that the last time we used it, we got a lot of responses from people who really didn't know there craft. :( If need be, we'll try it again, but hopefully there's a better solution for us. We're not looking for an individual to do some coding. We would like an actual company, or a team of programmers, who can write a modern, large scale e-commerce solution from the ground up. Does anyone know of a Perl shop - an actual company of developers that can handle bigger jobs like this (from Perl to web design)? Thanks again, Angela
Re: Regex help needed
Punit Jain, This is not the optimized code but you can refactor it. This works for the given scenario, no matter the order of input data. Hope it helps to some extent. [code] my $var = ''; my @args = (); my %hash; while (DATA) { chomp; my ($var,$arg) = split /=/,$_,2; if($var eq '{') { @args = (); #Reset if we encounter '{' } my @arg1 = split /,/,$arg if defined $arg; if(scalar @arg1 scalar @args) { $hash{$var} = $arg unless($var eq '{' || $var eq '}'); @args = @arg1; } } foreach my $k (sort keys %hash) { print $k = $hash{$k}\n; } __DATA__ { test = (test123); test = (test123,abc,xyz); test = (test123,abc); } { test1 = (passfile,pasfile1,user); test1 = (passfile); test1 = (passfile,pasfile1); } { test2 = (temp); test2 = (temp,temp1); test2 = (temp,temp1,username); } { test3 = (betty,betty1,jack); test3 = (betty,betty1); test3 = (betty); } [/code] [output] test = (test123,abc,xyz); test1 = (passfile,pasfile1,user); test2 = (temp,temp1,username); test3 = (betty,betty1,jack); [/output] best, Shaji --- Your talent is God's gift to you. What you do with it is your gift back to God. --- From: punit jain contactpunitj...@gmail.com To: beginners@perl.org beginners@perl.org Sent: Tuesday, 8 January 2013 5:58 PM Subject: Regex help needed Hi , I have a file as below : - { test = (test123); test = (test123,abc); test = (test123,abc,xyz); } { test1 = (passfile); test1 = (passfile,pasfile1); test1 = (passfile,pasfile1,user); } and so on The requirement is to have the file parsing so that final output is :- test = (test123,abc,xyz); test1 = (passfile,pasfile1,user); So basically only pick the lines with maximum number of options for each type. Regards.
Re: Regex help needed
On 2013-01-08 13:28, punit jain wrote: { test = (test123); test = (test123,abc); test = (test123,abc,xyz); } { test1 = (passfile); test1 = (passfile,pasfile1); test1 = (passfile,pasfile1,user); } and so on The requirement is to have the file parsing so that final output is :- test = (test123,abc,xyz); test1 = (passfile,pasfile1,user); So basically only pick the lines with maximum number of options for each type. Or just print the last long line: echo '{ test = (test123); test = (test123,abc); test = (test123,abc,xyz); } { test1 = (passfile); test1 = (passfile,pasfile1); test1 = (passfile,pasfile1,user); } ' |perl -wne'$o=$n||0;$p=$_,next if($n=length)$o;$n=3;print$p' test = (test123,abc,xyz); test1 = (passfile,pasfile1,user); Which preserves order too. :) -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Regex help needed
Hi , I have a file as below : - { test = (test123); test = (test123,abc); test = (test123,abc,xyz); } { test1 = (passfile); test1 = (passfile,pasfile1); test1 = (passfile,pasfile1,user); } and so on The requirement is to have the file parsing so that final output is :- test = (test123,abc,xyz); test1 = (passfile,pasfile1,user); So basically only pick the lines with maximum number of options for each type. Regards.
Re: Regex help needed
On Jan 8, 2013, at 4:28 AM, punit jain wrote: Hi , I have a file as below : - { test = (test123); test = (test123,abc); test = (test123,abc,xyz); } { test1 = (passfile); test1 = (passfile,pasfile1); test1 = (passfile,pasfile1,user); } and so on The requirement is to have the file parsing so that final output is :- test = (test123,abc,xyz); test1 = (passfile,pasfile1,user); So basically only pick the lines with maximum number of options for each type. The easiest solution I can think of would be to extract the first token on each line, use that token as a hash key, count the number of commas in each line, and save the line in the hash with the largest number of commas for each key. This will not work if your strings have commas. In that case, you might want to consider using a parsing module, such as Text::CSV, that will correctly handle your input data. You can use Text::CSV to split your input lines into fields and count the number of fields. However, you will first have to extract the quoted strings from the surrounding parentheses. You can use the Text::Balanced module to do that. Both Text::CSV and Text::Balanced are available at CPAN (http;//search.cpan.org). The best way for you to learn programming will be to attempt writing a program to accomplish your task, then post your program if you have trouble getting it to do what you want. Good luck. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Regex help needed
Hi punit jain, Please check my comments below. On Tue, Jan 8, 2013 at 1:28 PM, punit jain contactpunitj...@gmail.comwrote: Hi , I have a file as below : - { test = (test123); test = (test123,abc); test = (test123,abc,xyz); } { test1 = (passfile); test1 = (passfile,pasfile1); test1 = (passfile,pasfile1,user); } and so on The requirement is to have the file parsing so that final output is :- test = (test123,abc,xyz); test1 = (passfile,pasfile1,user); So basically only pick the lines with maximum number of options for each type. Regards. I basically agreed with Jim on this: Jim to learn programming will be to attempt writing a program to accomplish your task, Jim then post your program if you have trouble getting it to do what you want. However, if I may suggest using hash, if the lines with the maximum number of options for each type *is the last one in each case*. Since, *hash will only permit only one key*. So, splitting each line on =, one can take key and value for hash. So, based on the data presented, one can write like so: use warnings; use strict; my %collection_hash; while (DATA) { chomp; if (/=/) { my ( $key, $value ) = split /=/, $_, 2; $collection_hash{$key} = $value; } } print $_, ' = ', $collection_hash{$_}, $/ for sort keys %collection_hash; __DATA__ { test = (test123); test = (test123,abc); test = (test123,abc,xyz); } { test1 = (passfile); test1 = (passfile,pasfile1); test1 = (passfile,pasfile1,user); } *OUTPUT:* test = (test123,abc,xyz); test1 = (passfile,pasfile1,user); Please, *NOTE* that this will only work as you want if the last line in each case has the maximum options, this is what the data you showed here presented. -- Tim
Help needed in pressing Esc key
Hi, Can anyone plz help me by telling how to press Esc key using perl script. In my script, i came across a scenario to press the Esc key.. Plz help me.. I am not able to move forward due to this problem. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed in pressing Esc key
Hi meaculpa, On Friday 13 May 2011 10:44:34 meaculpa wrote: Hi, Can anyone plz help me by telling how to press Esc key using perl script. In my script, i came across a scenario to press the Esc key.. Plz help me.. I am not able to move forward due to this problem. Do you want to press it in a console application? In an X-Windows application? In a Windows application? In a Mac OS X application? What? Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ UNIX Fortune Cookies - http://www.shlomifish.org/humour/fortunes/ Ran Eilam To Shlomi Fish: so what are you working on? Working on a new wiki about unit testing fortunes in freecell? Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
MQSeries ... help needed
hello , My name is ashwin and i am new to perl. I have a requirement where in i need to send messages to MQSeries.. I assume that for the same .. i need to install the MQSeries package in my existing perl.i use a unix environment.The version of perl that i am using is v5.8.2, can you please guide me in installing a module from CPAN on to my unix machine.. this is what i have done so far... i gave cpan MQSeries ... the following is displayed on my screen which i think is an error... Checking if your kit is complete... Looks good Warning: prerequisite Convert::EBCDIC 0.06 not found. Warning: prerequisite Params::Validate 0.89 not found. Warning: prerequisite Test::Pod 1.20 not found. Warning: prerequisite Test::Simple 0.62 not found. We have 0.47. ERROR from evaluation of /home/spokuri/.cpan/build/ MQSeries-1.31/MQClient/Makefile.PL: No such directory '/usr/lpp/mqm' Compilation failed in require at ./Makefile.PL line 14. # Looks like your test died before it could output anything. Running make test Make had some problems, maybe interrupted? Won't test Running make install Make had some problems, maybe interrupted? Won't install Thanks in advance... Regards Ashwin Thayyullathil Surendran #91 988732
Re: MQSeries ... help needed
MQSeries-1.31/MQClient/ *Makefile.PL: No such directory '/usr/lpp/mqm'* I don't know what the MQSeries is, but that message makes me suspect.. Have you actually installed that, prior to attempting to install the module? If you have, try looking where it's installed, and symlink it to the folder that the module requires. Brian.
Re: [PBML] Help needed in recursion with objects in perl !
On Fri, Aug 6, 2010 at 8:09 PM, Randal L. Schwartz mer...@stonehenge.comwrote: Amit == Amit Saxena learn.tech...@gmail.com writes: Amit I am working on a tree implementation (with any number of parent Amit and child nodes) in perl. Every node is defined as a object of a Amit Node class which I have created as a .pm module. Unless this is for a student exercise, you probably just want to look at Graph in the CPAN. Lots and lots and lots of graph traversal things already worked out for you. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/ Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion Thanks Randal for the reply. The purpose of this activity is to model a hierarchical representation of dependent components, each of one will be represented as a service. I had a look at the Graph module ( http://search.cpan.org/~jhi/Graph-0.94/lib/Graph.pod) but I am not sure how it can be used to implement multiple parent and multiple child implementation of a tree. In other words, I would like to have similar methods which are available in the Tree implementations in CPAN. Please suggest. Thanks Regards, Amit Saxena
Re: [PBML] Help needed in recursion with objects in perl !
On Sat, Aug 7, 2010 at 09:36, Amit Saxena learn.tech...@gmail.com wrote: snip The purpose of this activity is to model a hierarchical representation of dependent components, each of one will be represented as a service. I had a look at the Graph module ( http://search.cpan.org/~jhi/Graph-0.94/lib/Graph.pod) but I am not sure how it can be used to implement multiple parent and multiple child implementation of a tree. In other words, I would like to have similar methods which are available in the Tree implementations in CPAN. snip A [tree][0] is a [Graph][1]. Often you will see trees implemented as [Directed Acyclic Graphs][2] (or DAGs) because pointers or references only flow one way. Here is an example using the [Graph][3] module: #!/usr/bin/perl use strict; use warnings; use Graph; #FIXME: naive implementation, there may be a much better way to do this sub run_in_parallel { my $g = shift-copy; while (my @v = $g-vertices) { my @run = grep { $g-is_successorless_vertex($_) } @v; print running , join(, , @run), in parallel\n; for my $compenent (@run) { $g-delete_vertex($compenent); }; } } my $g = Graph-new; my $f = Graph-new; while (DATA) { my ($component, @dependencies) = split; unless ($g-has_vertex($component)) { $g-add_vertex($component); $f-add_vertex($component); } for my $dependency (@dependencies) { unless ($g-has_vertex($dependency)) { $g-add_vertex($dependency); $f-add_vertex($dependency); } $g-add_edge($dependency, $component); $f-add_edge($component, $dependency); } } print everything will work if you run the programs in this order: , join(, , $g-topological_sort), \n; run_in_parallel($f); #component dependency list __DATA__ a b c d b e c f g d e f g [0]: http://en.wikipedia.org/wiki/Tree_(graph_theory) [1]: http://en.wikipedia.org/wiki/Graph_(mathematics) [2]: http://en.wikipedia.org/wiki/Directed_acyclic_graph [3]: http://search.cpan.org/dist/Graph/lib/Graph.pod -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Help needed in recursion with objects in perl !
Hi all, I am working on a tree implementation (with any number of parent and child nodes) in perl. Every node is defined as a object of a Node class which I have created as a .pm module. I have defined a method getParentNodes which returns reference to an array having all the (immediate) parent nodes objects as shown below. my @immediate_parent_node_objects = $node1-getParentNodes (); my $i; foreach $i ( @{$node1-getParentNodes ()} ) { print Parent node for the child node . $node1-getNodeName() . is . $i-getNodeName() \n; } I want to define another method named getParentNodesRecurse which will return either all or upto a level of (ancestor) parent nodes objects instead of immediate parent node objects. I tried to implement something similar to what's shown below but I am unable to achieve it. sub getParentNodesRecurse { my ( $self, $level ) = @_; print \t x $level . node name = [ . $self-getNodeName() . ], level = [$level]\n; #print level = [$level]\n; if ( ! defined $self-getParentNodes() ) { print \t x $level . (No parent nodes for the node [ . $self-getNodeName() . ])\n; return; } my @concatenated_list_of_parent_nodes; my $l; foreach $l ( @{$self-getParentNodes()} ) { @concatenated_list_of_parent_nodes = ( @concatenated_list_of_parent_nodes, getParentNodesRecurse( $l, $level+1 ) ); } print \n; print Returning the concatenation of following two lists : \n; print . @{$self-getParentNodes()} . \n; print [ . @concatenated_list_of_parent_nodes . ]\n; print \n; return ( \( @{$self-getParentNodes()}, @concatenated_list_of_parent_nodes ) ); } Please help and also let me know in case there is a better way to implement. I can even rewrite my implementation using different design. I tried looking for modules on CPAN which supports tree implementation with multiple parents and child but couldn't find it. Note : For some reasons, I don't want to use implementation which requires $_. Thanks Regards, Amit Saxena
Re: [PBML] Help needed in recursion with objects in perl !
Amit == Amit Saxena learn.tech...@gmail.com writes: Amit I am working on a tree implementation (with any number of parent Amit and child nodes) in perl. Every node is defined as a object of a Amit Node class which I have created as a .pm module. Unless this is for a student exercise, you probably just want to look at Graph in the CPAN. Lots and lots and lots of graph traversal things already worked out for you. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/ Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with '-e' operator
On Wed, Jul 8, 2009 at 6:57 PM, John Refiorjref...@gmail.com wrote: On Wed, Jul 8, 2009 at 7:34 AM, Anu P anurao_...@yahoo.com wrote: I am trying to use the '-e' filetest operator and encountered some wired behavior. I have a tar.gz file which is around 2.6 G and this is the code...Tar.gz file is in the same directory where script is executed. unless (-e $file) { print (ERROR: $file does not exist\n); exit(1); } This does not seem to work..I always get File does not exist message. I also tried out with a small tar.gz file which is around 2K and that seems to work. so I am not sure if the usage of '-e' operator has limitation with file size. It's a long shot, but I notice that you say tar.gz in one place, and Tar.gz in another place. Maybe that's intended as a new sentence, and that's why it's capitalized, I'm not sure with the three-dot ellipsis there. The point is: make sure you have the right case. tar.gz is not Tar.gz. Good point. And also notice that the error message that you are getting File does not exist is not the same as what is supposed to print, ERROR: foo.tar.gz does not exist, if $file=foo.tar.gz. Good luck and do let the list know what you discover. Regards, - Robert -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with '-e' operator
Hi Robert, I am sorry for the typos in the mail.. Actually the file is tar.gz only, Tar.gz was a typo, and secondly the error message was still showing as file.tar.gz does not exist but again it was a mistake from my end. Actually your response helped me get the solution. I figured out that we were using an older version 5.004 on sun os, sun4x_55. I tried the same script using perl5.87 (latest version we had) and it worked!! Thanks a lot for your help. Regards, Anu. From: Robert Citek rwci...@alum.calberkeley.org To: Perl Beginners beginners@perl.org Cc: Anu P anurao_...@yahoo.com; John Refior jref...@gmail.com Sent: Thursday, July 9, 2009 7:40:00 AM Subject: Re: Help needed with '-e' operator On Wed, Jul 8, 2009 at 6:57 PM, John Refiorjref...@gmail.com wrote: On Wed, Jul 8, 2009 at 7:34 AM, Anu P anurao_...@yahoo.com wrote: I am trying to use the '-e' filetest operator and encountered some wired behavior. I have a tar.gz file which is around 2.6 G and this is the code...Tar.gz file is in the same directory where script is executed. unless (-e $file) { print (ERROR: $file does not exist\n); exit(1); } This does not seem to work..I always get File does not exist message. I also tried out with a small tar.gz file which is around 2K and that seems to work. so I am not sure if the usage of '-e' operator has limitation with file size. It's a long shot, but I notice that you say tar.gz in one place, and Tar.gz in another place. Maybe that's intended as a new sentence, and that's why it's capitalized, I'm not sure with the three-dot ellipsis there. The point is: make sure you have the right case. tar.gz is not Tar.gz. Good point. And also notice that the error message that you are getting File does not exist is not the same as what is supposed to print, ERROR: foo.tar.gz does not exist, if $file=foo.tar.gz. Good luck and do let the list know what you discover. Regards, - Robert -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Help needed with '-e' operator
Hi, I am trying to use the '-e' filetest operator and encountered some wired behavior. I have a tar.gz file which is around 2.6 G and this is the code...Tar.gz file is in the same directory where script is executed. unless (-e $file) { print (ERROR: $file does not exist\n); exit(1); } This does not seem to work..I always get File does not exist message. I also tried out with a small tar.gz file which is around 2K and that seems to work. so I am not sure if the usage of '-e' operator has limitation with file size. Any help in this is appreciated. Thanks, Anu.
Re: Help needed with '-e' operator
The code you wrote should work as it worked for me when I tested it on a 3 GB sized file: $ ls -sh 3gb-file 3.0G 3gb-file $ perl -le '$file=3gb-file ; unless (-e $file) { print (nope) ; } else { print (yup) ; } ' yup I tested it with files as large as 10 GB and it worked. Could it be that the error is elsewhere in your code? What version of perl are you running (i.e. perl -V)? What operating system are you using? Regards, - Robert On Wed, Jul 8, 2009 at 6:34 AM, Anu Panurao_...@yahoo.com wrote: I am trying to use the '-e' filetest operator and encountered some wired behavior. I have a tar.gz file which is around 2.6 G and this is the code...Tar.gz file is in the same directory where script is executed. unless (-e $file) { print (ERROR: $file does not exist\n); exit(1); } This does not seem to work..I always get File does not exist message. I also tried out with a small tar.gz file which is around 2K and that seems to work. so I am not sure if the usage of '-e' operator has limitation with file size. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with '-e' operator
On Wed, Jul 8, 2009 at 7:34 AM, Anu P anurao_...@yahoo.com wrote: I am trying to use the '-e' filetest operator and encountered some wired behavior. I have a tar.gz file which is around 2.6 G and this is the code...Tar.gz file is in the same directory where script is executed. unless (-e $file) { print (ERROR: $file does not exist\n); exit(1); } This does not seem to work..I always get File does not exist message. I also tried out with a small tar.gz file which is around 2K and that seems to work. so I am not sure if the usage of '-e' operator has limitation with file size. It's a long shot, but I notice that you say tar.gz in one place, and Tar.gz in another place. Maybe that's intended as a new sentence, and that's why it's capitalized, I'm not sure with the three-dot ellipsis there. The point is: make sure you have the right case. tar.gz is not Tar.gz. John
Re: help needed to get over endless loop
Thank you all for your much needed help. The penny has managed to drop. regards Brian -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
help needed to get over endless loop
Hi I had this semi-working, changed something and can't remember where I went right, so would appreciate some help getting back on top. I know 1..10 and 2..10 probably won't work in the following example, I have just changed lines to show what I am trying to get. $mystart = -2; $i = 1; for ($i = 1..10 ) { while ($i = 1 ) { if ($mystart 1 ) {print line 1 no data} if ($mystart 0 ) {print line 1 data} $mystart++ ; $i++; } } while ($i = 2..10 ) { if ($mystart 1 ) {print line 2..10 no data} if ($mystart 0 ) {print line 2..10 with data} $mystart++ ; $i++; } } thanks Brian -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: help needed to get over endless loop
On 4/17/09 Fri Apr 17, 2009 10:02 AM, Brian brian5432...@yahoo.co.uk scribbled: Hi I had this semi-working, changed something and can't remember where I went right, so would appreciate some help getting back on top. I know 1..10 and 2..10 probably won't work in the following example, I have just changed lines to show what I am trying to get. $mystart = -2; $i = 1; for ($i = 1..10 ) { for my $I ( 1..10 ) { while ($i = 1 ) { '=' is assignment, '==' is test for numerical equality. This loop will never end, as $I gets assigned to the value 1 each time through the loop. while( $i == 1 ) { if ($mystart 1 ) {print line 1 no data} if ($mystart 0 ) {print line 1 data} $mystart++ ; $i++; You probably don't want to change $i inside a 'for my $I ( 1 .. 10 )' loop, as the change will be overwritten at the next loop iteration. If you really need to modify the loop iterator, then you should use a C-style for loop: for( my $i = 0; $i =10; $i++ ) { ... } -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: help needed to get over endless loop
-Original Message- From: Brian [mailto:brian5432...@yahoo.co.uk] Sent: Friday, April 17, 2009 11:03 To: Perl Beginners Subject: help needed to get over endless loop Hi I had this semi-working, changed something and can't remember where I went right, so would appreciate some help getting back on top. I know 1..10 and 2..10 probably won't work in the following example, I have just changed lines to show what I am trying to get. You are not running with strict, warnings which would give you a heads up $mystart = -2; $i = 1; for ($i = 1..10 ) { while ($i = 1 ) { You would get warning if warnings were on. You are assigning 1 to $i and not $i == 1. Better to give your code for the list to review. If you have any questions and/or problems, please let me know. Thanks. Wags ;) David R. Wagner Senior Programmer Analyst FedEx Freight 1.719.484.2097 TEL 1.719.484.2419 FAX 1.408.623.5963 Cell http://fedex.com/us if ($mystart 1 ) {print line 1 no data} if ($mystart 0 ) {print line 1 data} $mystart++ ; $i++; } } while ($i = 2..10 ) { if ($mystart 1 ) {print line 2..10 no data} if ($mystart 0 ) {print line 2..10 with data} $mystart++ ; $i++; } } thanks Brian -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: help needed to get over endless loop
Wagner, David --- Senior Programmer Analyst --- CFS wrote: -Original Message- From: Brian [mailto:brian5432...@yahoo.co.uk] Sent: Friday, April 17, 2009 11:03 To: Perl Beginners Subject: help needed to get over endless loop Hi I had this semi-working, changed something and can't remember where I went right, so would appreciate some help getting back on top. I know 1..10 and 2..10 probably won't work in the following example, I have just changed lines to show what I am trying to get. You are not running with strict, warnings which would give you a heads up $mystart = -2; $i = 1; for ($i = 1..10 ) { while ($i = 1 ) { You would get warning if warnings were on. You are assigning 1 to $i and not $i == 1. Better to give your code for the list to review. I pretty much scrapped everything I had and have used the code as posted as a new starting point, therefore that is all I am working with at the moment. if I use strict I get a couple of screenfuls of warnings, mostly Global symbol $xxx requires explicit package name at and a few Bareword warnings, but they seem to be because of strict subs in use If I can answer both you and Jim here... I want to count from 1 to 10, I assigned $i as 1 so as not to need to test $i against negative. However, at the count of 1, I check to see if $mystart is positive or negative. If it is neg, a null value is printed. If it is pos, $mystart is printed in red. From count 2 thru 10... If it is neg, a null value is printed. If it is pos, $mystart is printed in black. I need to retain the value of $i as this block of code will be re-used further into the cgi. regards Brian -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: help needed to get over endless loop
This is what I'm using upto the code that is giving me a headache. I know it's messy, but I have no training in PERL, I am trying to forward-engineer this cgi by back-engineering from html templates I created and which were chosen using $t-src thanks for any help Brian #! c:\perl\bin\perl.exe -T use warnings; #use strict; use CGI qw/:all/; use CGI::Carp qw/fatalsToBrowser/; use HTMLTMPL; my $t = HTMLTMPL-new(); my $q = new CGI; my $val1 = $q-param('language'); my $val2 = $q-param('year'); #my $submit = $q-param('Submit'); chomp($Lang = $val1); chomp($Year_in = $val2); my ( $day, $mon, $year ) = ( localtime )[ 3, 4, 5 ]; my $today = $year + 1900; set default language if ($Lang eq '' ) {$Lang = en;} handle the strings { $string1 = aaabb; $string2 = cccdd; $string3 = eeeff; $string4 = ggghh; if ($Year_in = 0 ) {$Year_in = $today;} $Year_out = $Year_in; while ($Year_out 100) {$Year_out -= 100;} if (($Year_out 00) ($Year_out = 25)) {$string = $string1;} if (($Year_out 25) ($Year_out = 50)) {$Year_out -= 100;$string = $string2;} if (($Year_out 50) ($Year_out = 75)) {$Year_out -= 200;$string = $string3;} if (($Year_out 75) ($Year_out = 100)) {$Year_out -= 300;$string = $string4;} $Calend = substr $string, $Year_out-1, 1; } user selected language if ($Lang eq en) { ($myjan,$myfeb,$mymar,$myapr,$mymay,$myjun,$myjul,$myaug,$mysep,$myoct,$mynov,$mydec) = (January,February,March,April,May,June,July,August,September,October,November,December); } if ($Lang eq en) { ($mysun_day,$mymon_day,$mytue_day,$mywed_day,$mythu_day,$myfri_day,$mysat_day) = ( Sun,Mon,Tue,Wed,Thu,Fri,Sat); } if ($Lang eq fr) { ($myjan,$myfeb,$mymar,$myapr,$mymay,$myjun,$myjul,$myaug,$mysep,$myoct,$mynov,$mydec) = (Janvier,Fevrier,Mars,Avril,Mai,Juin,Juillet,Août,Septembre,Octobre,Novembre,Decembre); } if ($Lang eq fr) { ($mysun_day,$mymon_day,$mytue_day,$mywed_day,$mythu_day,$myfri_day,$mysat_day) = ( Dim,Lun,Mar,Mer,Jeu,Ven,Sam); } if ($Lang eq de) { ($myjan,$myfeb,$mymar,$myapr,$mymay,$myjun,$myjul,$myaug,$mysep,$myoct,$mynov,$mydec) = (Januar,Februar,März,April,Mai,Juni,Juli,August,September,Oktober,November,Dezember); } if ($Lang eq de) { ($mysun_day,$mymon_day,$mytue_day,$mywed_day,$mythu_day,$myfri_day,$mysat_day) = ( S,M,D,M,D,F,S); } if ($Lang eq ee) { ($myjan,$myfeb,$mymar,$myapr,$mymay,$myjun,$myjul,$myaug,$mysep,$myoct,$mynov,$mydec) = (Jaanuar,Veebruar,Märts,Aprill,Mai,Juuni,Juuli,August,September,Oktoober,November,Detsember); } if ($Lang eq ee) { ($mysun_day,$mymon_day,$mytue_day,$mywed_day,$mythu_day,$myfri_day,$mysat_day) = ( P,E,T,K,N,R,L); } whether or not leapyear { ($myleap = 0 ) } if ($Calend eq b ) {$myleap += 1} if ($Calend eq d ) {$myleap += 1} if ($Calend eq f ) {$myleap += 1} if ($Calend eq h ) {$myleap += 1} whether year starts on a Sunday { ($mystart = 0 ) } if ($Calend eq a || $Calend eq b) {$mystart -= 0} if ($Calend eq c || $Calend eq d) {$mystart -= 1} if ($Calend eq e || $Calend eq f) {$mystart -= 2} if ($Calend eq g || $Calend eq h) {$mystart -= 3} ## this prog originally written to choose a template ## hence the following (superfluous) line #$t-src( c:/apache2/htdocs/calendar/$Lang/$Calend.html ); $t-output( CGI::header ); { print !DOCTYPE html PUBLIC \-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN\ \http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd\ html xmlns=\http:\/\/www.w3.org\/1999\/xhtml\ head title$Year_in\/title style type=\text\/css\ !-- #Layer1 { position:absolute; left:39px; top:36px; width:132px; height:167px; z-index:1; } .style1 {color: #00} .style4 {color: #FF3300; } body { background-color: #003399; } .style5 { font-size: 36px; color: #FF; } .style6 {color: #FF} .style7 {color: #FF3300; font-size: 12px; } .style8 {font-size: 12px} .style9 {font-size: 24px} -- \/style \/head body $myjan $Calend $myleap $mystart table width=\10%\ height=\287\ border=\0\ align=\left\ cellpadding=\0\ cellspacing=\0\ tr td align=\left\form action=\http:\/\/localhost\/testing123\/\ method=\get\ enctype=\text\/plain\ name=\year\ id=\year\ p align=\centre\ class=\style1 style6\ label } if
Re: help needed to get over endless loop
Brian wrote: oops, should read.. $Year_out = $Year_in; while ($Year_out 100) {$Year_out -= 100;} if (($Year_out 00) ($Year_out = 25)) {$string = $string1;} if (($Year_out 25) ($Year_out = 50)) {$Year_out -= 25;$string = $string2;} if (($Year_out 50) ($Year_out = 75)) {$Year_out -= 50;$string = $string3;} if (($Year_out 75) ($Year_out = 100)) {$Year_out -= 75;$string = $string4;} -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: help needed to get over endless loop
Brian, Your while loops aren't actually performing any operation on the variable that is being tested as part of their condition. With while loops, if the condition ($i in this case) is true at the start of the loop, and doesn't change, they will loop forever. They aren't like for loops, where you pre-declare the increment operation that's ran every loop. You need to add some kind of code to increment the $i for each iteration of the loop such that the condition eventually becomes false. I'm not sure exactly what logic you would use to do that, as I'm having a hard time figuring out what these loops are supposed to do. That being said, I think you would realize some benefit by stepping back and looking at the overall design of your program, breaking it down into subroutines and thinking about the clearest way to implement it. I think there are several ways to refactor this to make it much easier to write, debug, and maintain. On Fri, Apr 17, 2009 at 3:46 PM, Brian brian5432...@yahoo.co.uk wrote: This is what I'm using upto the code that is giving me a headache. I know it's messy, but I have no training in PERL, I am trying to forward-engineer this cgi by back-engineering from html templates I created and which were chosen using $t-src thanks for any help Brian #! c:\perl\bin\perl.exe -T use warnings; #use strict; use CGI qw/:all/; use CGI::Carp qw/fatalsToBrowser/; use HTMLTMPL; my $t = HTMLTMPL-new(); my $q = new CGI; my $val1 = $q-param('language'); my $val2 = $q-param('year'); #my $submit = $q-param('Submit'); chomp($Lang = $val1); chomp($Year_in = $val2); my ( $day, $mon, $year ) = ( localtime )[ 3, 4, 5 ]; my $today = $year + 1900; set default language if ($Lang eq '' ) {$Lang = en;} handle the strings { $string1 = aaabb; $string2 = cccdd; $string3 = eeeff; $string4 = ggghh; if ($Year_in = 0 ) {$Year_in = $today;} $Year_out = $Year_in; while ($Year_out 100) {$Year_out -= 100;} if (($Year_out 00) ($Year_out = 25)) {$string = $string1;} if (($Year_out 25) ($Year_out = 50)) {$Year_out -= 100;$string = $string2;} if (($Year_out 50) ($Year_out = 75)) {$Year_out -= 200;$string = $string3;} if (($Year_out 75) ($Year_out = 100)) {$Year_out -= 300;$string = $string4;} $Calend = substr $string, $Year_out-1, 1; } user selected language if ($Lang eq en) { ($myjan,$myfeb,$mymar,$myapr,$mymay,$myjun,$myjul,$myaug,$mysep,$myoct,$mynov,$mydec) = (January,February,March,April,May,June,July,August,September,October,November,December); } if ($Lang eq en) { ($mysun_day,$mymon_day,$mytue_day,$mywed_day,$mythu_day,$myfri_day,$mysat_day) = ( Sun,Mon,Tue,Wed,Thu,Fri,Sat); } if ($Lang eq fr) { ($myjan,$myfeb,$mymar,$myapr,$mymay,$myjun,$myjul,$myaug,$mysep,$myoct,$mynov,$mydec) = (Janvier,Fevrier,Mars,Avril,Mai,Juin,Juillet,Août,Septembre,Octobre,Novembre,Decembre); } if ($Lang eq fr) { ($mysun_day,$mymon_day,$mytue_day,$mywed_day,$mythu_day,$myfri_day,$mysat_day) = ( Dim,Lun,Mar,Mer,Jeu,Ven,Sam); } if ($Lang eq de) { ($myjan,$myfeb,$mymar,$myapr,$mymay,$myjun,$myjul,$myaug,$mysep,$myoct,$mynov,$mydec) = (Januar,Februar,März,April,Mai,Juni,Juli,August,September,Oktober,November,Dezember); } if ($Lang eq de) { ($mysun_day,$mymon_day,$mytue_day,$mywed_day,$mythu_day,$myfri_day,$mysat_day) = ( S,M,D,M,D,F,S); } if ($Lang eq ee) { ($myjan,$myfeb,$mymar,$myapr,$mymay,$myjun,$myjul,$myaug,$mysep,$myoct,$mynov,$mydec) = (Jaanuar,Veebruar,Märts,Aprill,Mai,Juuni,Juuli,August,September,Oktoober,November,Detsember); } if ($Lang eq ee) { ($mysun_day,$mymon_day,$mytue_day,$mywed_day,$mythu_day,$myfri_day,$mysat_day) = ( P,E,T,K,N,R,L); } whether or not leapyear { ($myleap = 0 ) } if ($Calend eq b ) {$myleap += 1} if ($Calend eq d ) {$myleap += 1} if ($Calend eq f ) {$myleap += 1} if ($Calend eq h ) {$myleap += 1} whether year starts on a Sunday { ($mystart = 0 ) } if ($Calend eq a || $Calend eq b) {$mystart -= 0} if ($Calend eq c || $Calend eq d) {$mystart -= 1} if ($Calend eq e || $Calend eq f) {$mystart -= 2} if ($Calend eq g || $Calend eq h) {$mystart -= 3} ## this prog originally written to choose a template ## hence the following (superfluous) line #$t-src( c:/apache2/htdocs/calendar/$Lang/$Calend.html ); $t-output( CGI::header );
Re: help needed to get over endless loop
Kevin Ponds wrote: Brian, Your while loops aren't actually performing any operation on the variable I did actually state that the loops wouldn't work. I adjusted them to better show what I want to achieve, not to show how I am trying to achieve it. that is being tested as part of their condition. With while loops, if the condition ($i in this case) is true at the start of the loop, and doesn't change, they will loop forever. They aren't like for loops, where you pre-declare the increment operation that's ran every loop. You need to add some kind of code to increment the $i for each iteration of the loop such that the condition eventually becomes false. I'm not sure exactly what logic you would use to do that, as I'm having a hard time figuring out what these loops are supposed to do. I've tried using while, if and for in different ways, whilst some permutations worked partially, I haven't been able to figure out the correct way of laying the code out to do a couple of basic tests. I'm going back and forth on something that looks to me like it should be so damned simple to figure out. That being said, I think you would realize some benefit by stepping back and looking at the overall design of your program, breaking it down into subroutines and thinking about the clearest way to implement it. I think there are several ways to refactor this to make it much easier to write, debug, and maintain. Yes I agree, but whilst I am at a point where I am having trouble working out one simple step, I really don't think it a good idea to break it into loads of subroutines. I get confused easily, as can be seen by my inability to solve the problem below. On Fri, Apr 17, 2009 at 3:46 PM, Brian brian5432...@yahoo.co.uk wrote: for ( $i =10; $i += 1 ; ) { while ($i == 1 ) { if ($mystart 1 ) { print td width=27 height=27div align=center class=style4/div/td } if ($mystart 0 ) { print td width=27 height=27div align=center class=style4$mystart/div/td } } } while ($i == 2..10 ) { while ($i 1 ) { if ($mystart 1 ) { print td width=27 height=27div align=center/div/td } if ($mystart 0 ) { print td width=27 height=27div align=center$mystart/div/td } } } #} -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: help needed to get over endless loop
On 4/17/09 Fri Apr 17, 2009 1:50 PM, Brian brian5432...@yahoo.co.uk scribbled: Brian wrote: oops, should read.. $Year_out = $Year_in; while ($Year_out 100) {$Year_out -= 100;} if (($Year_out 00) ($Year_out = 25)) {$string = $string1;} if (($Year_out 25) ($Year_out = 50)) {$Year_out -= 25;$string = $string2;} if (($Year_out 50) ($Year_out = 75)) {$Year_out -= 50;$string = $string3;} if (($Year_out 75) ($Year_out = 100)) {$Year_out -= 75;$string = $string4;} You are doing quite a few redundant tests here. Note that after your while loop, $Year_out cannot be greater than 100. Also, if $Year_out is greater than 25, it must be greater than 0. In addition, when you are done, $Year_out will be between 0 and 25. Therefore, you can take the value modulo 25 and rearrange the tests to be a little more efficient (I am assuming that $Year_out is always = zero): while ( $Year_out 100 ) { $Year_out -= 100; } if ( $Year_out 75 ) { $string = $string4; }elsif ( $Year_out 50 { $string = $string3; }elsif ( $Year_out 25 ) { $string = $string2; }elsif ( $Year_out 0 ) { $string = $string1; } $Year_out = $Year_out % 25; -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: help needed to get over endless loop
Jim Gibson wrote: On 4/17/09 Fri Apr 17, 2009 1:50 PM, Brian brian5432...@yahoo.co.uk scribbled: Brian wrote: oops, should read.. $Year_out = $Year_in; while ($Year_out 100) {$Year_out -= 100;} if (($Year_out 00) ($Year_out = 25)) {$string = $string1;} if (($Year_out 25) ($Year_out = 50)) {$Year_out -= 25;$string = $string2;} if (($Year_out 50) ($Year_out = 75)) {$Year_out -= 50;$string = $string3;} if (($Year_out 75) ($Year_out = 100)) {$Year_out -= 75;$string = $string4;} You are doing quite a few redundant tests here. Note that after your while loop, $Year_out cannot be greater than 100. Also, if $Year_out is greater than 25, it must be greater than 0. In addition, when you are done, $Year_out will be between 0 and 25. Therefore, you can take the value modulo 25 and rearrange the tests to be a little more efficient (I am assuming that $Year_out is always = zero): while ( $Year_out 100 ) { $Year_out -= 100; } if ( $Year_out 75 ) { $string = $string4; }elsif ( $Year_out 50 { $string = $string3; }elsif ( $Year_out 25 ) { $string = $string2; }elsif ( $Year_out 0 ) { $string = $string1; } $Year_out = $Year_out % 25; Thanks for that, a better structure, but I don't understand the use of % 25 in this instance. $year is actually always going to be = zero , even if someone enters a negative. I haven't factored for the Julian/Gregorian changeover, so this prog will calc year 1 as it would have been had todays calendar been in use 2000+ years ago. A point I should make here is that I am actually working over 400 year cycles and not 100, so... 100 = 400 75 = 300 50 = 200 25 = 100 but I suppose the results will be this same in your code above. (I changed certain parameters to stop any robots from stealing my code) ;-) -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: help needed to get over endless loop
Brian wrote: This is what I'm using upto the code that is giving me a headache. I know it's messy, but I have no training in PERL, I am trying to forward-engineer this cgi by back-engineering from html templates I created and which were chosen using $t-src thanks for any help Brian #! c:\perl\bin\perl.exe -T use warnings; #use strict; You should not disable strict, it can help you find mistakes. use CGI qw/:all/; use CGI::Carp qw/fatalsToBrowser/; use HTMLTMPL; my $t = HTMLTMPL-new(); my $q = new CGI; my $val1 = $q-param('language'); my $val2 = $q-param('year'); #my $submit = $q-param('Submit'); chomp($Lang = $val1); chomp($Year_in = $val2); chomp() removes the contents of the $/ variable from the end of the string. What makes you think that $val1 and $val2 need to be chomp()ed? my ( $day, $mon, $year ) = ( localtime )[ 3, 4, 5 ]; my $today = $year + 1900; set default language if ($Lang eq '' ) {$Lang = en;} Strings need to be quoted, either 'en' or en. This is a requirement of most, if not all, programming languages. handle the strings { $string1 = aaabb; $string2 = cccdd; $string3 = eeeff; $string4 = ggghh; Again, you must quote your strings. if ($Year_in = 0 ) {$Year_in = $today;} $Year_out = $Year_in; while ($Year_out 100) {$Year_out -= 100;} No need for a loop ( $Year_out %= 100 ) ||= 100; if (($Year_out 00) ($Year_out = 25)) {$string = $string1;} if (($Year_out 25) ($Year_out = 50)) {$Year_out -= 100;$string = $string2;} if (($Year_out 50) ($Year_out = 75)) {$Year_out -= 200;$string = $string3;} if (($Year_out 75) ($Year_out = 100)) {$Year_out -= 300;$string = $string4;} $Calend = substr $string, $Year_out-1, 1; my @strings = ( ( 'a' ) x 11, ( 'b' ) x 14, ( 'c' ) x 11, ( 'd' ) x 14, ( 'e' ) x 11, ( 'f' ) x 14, ( 'g' ) x 11, ( 'h' ) x 14, ); if ( $Year_out 0 $Year_out = 100 ) { $Calend = $strings[ $Year_out - 1 ]; $Year_out -= int( ( $Year_out - 1 ) / 25 ) * 100; } } user selected language if ($Lang eq en) Again, you must quote your strings. { ($myjan,$myfeb,$mymar,$myapr,$mymay,$myjun,$myjul,$myaug,$mysep,$myoct,$mynov,$mydec) = (January,February,March,April,May,June,July,August,September,October,November,December); } [ *SNIP* ] # $i actually required to be greater than a 10 count, but if I can get # the 2 blocks below to work, I will be able to play about with # the code and increase it to the desired level. # for ( $i =10; $i += 1 ; ) { The for loop synax is: for ( STATEMENT; CONDITIONAL; STATEMENT ) { So $i =10 is superfluous and $i += 1 is always true if $i is true so it will loop until $i becomes 0 which can only happen if $i starts out as a negative number. John -- Those people who think they know everything are a great annoyance to those of us who do.-- Isaac Asimov -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: help needed to get over endless loop
Brian wrote: This is what I'm using upto the code that is giving me a headache. I know it's messy, but I have no training in PERL, I am trying to forward-engineer this cgi by back-engineering from html templates I created and which were chosen using $t-src [ *SNIP* ] whether or not leapyear { ($myleap = 0 ) } if ($Calend eq b ) {$myleap += 1} if ($Calend eq d ) {$myleap += 1} if ($Calend eq f ) {$myleap += 1} if ($Calend eq h ) {$myleap += 1} The usual way to calculate a leap year is: sub is_leap_year { my $year = shift; return $year % 4 == 0 $year % 100 != 0 || $year % 400 == 0 } whether year starts on a Sunday { ($mystart = 0 ) } if ($Calend eq a || $Calend eq b) {$mystart -= 0} if ($Calend eq c || $Calend eq d) {$mystart -= 1} if ($Calend eq e || $Calend eq f) {$mystart -= 2} if ($Calend eq g || $Calend eq h) {$mystart -= 3} use Time::Local; sub year_starts_sunday { my $year = shift; return !( gmtime timegm 0, 0, 12, 1, 0, $year - 1900 )[ 6 ] } John -- Those people who think they know everything are a great annoyance to those of us who do.-- Isaac Asimov -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: help needed to get over endless loop
John W. Krahn wrote: Brian wrote: This is what I'm using upto the code that is giving me a headache. I know it's messy, but I have no training in PERL, I am trying to forward-engineer this cgi by back-engineering from html templates I created and which were chosen using $t-src #! c:\perl\bin\perl.exe -T use warnings; #use strict; You should not disable strict, it can help you find mistakes. But it works with strict turned off. chomp($Lang = $val1); chomp($Year_in = $val2); chomp() removes the contents of the $/ variable from the end of the string. What makes you think that $val1 and $val2 need to be chomp()ed? Oops, they are leftovers from when I was using STDIN my ( $day, $mon, $year ) = ( localtime )[ 3, 4, 5 ]; my $today = $year + 1900; set default language if ($Lang eq '' ) {$Lang = en;} Strings need to be quoted, either 'en' or en. This is a requirement of most, if not all, programming languages. handle the strings { $string1 = aaabb; $string2 = cccdd; $string3 = eeeff; $string4 = ggghh; As I wasn't expecting help at this point, I replaced the strings true data. I was of the understanding that PERL could handle a string of any length, when I originally tried to use a string of 400 chars the prog would refuse, so I changed it to 4 strings of 100 chars. I would love to be able to be able to use a single string, but as this method works, I am stuck with it. I still need to use $Calend = substr $string, $Year_out-1, 1; if (($Year_out 00) ($Year_out = 25)) {$string = $string1;} if (($Year_out 25) ($Year_out = 50)) {$Year_out -= 100;$string = $string2;} if (($Year_out 50) ($Year_out = 75)) {$Year_out -= 200;$string = $string3;} if (($Year_out 75) ($Year_out = 100)) {$Year_out -= 300;$string = $string4;} $Calend = substr $string, $Year_out-1, 1; } user selected language if ($Lang eq en) Again, you must quote your strings. { ($myjan,$myfeb,$mymar,$myapr,$mymay,$myjun,$myjul,$myaug,$mysep,$myoct,$mynov,$mydec) = (January,February,March,April,May,June,July,August,September,October,November,December); } [ *SNIP* ] # $i actually required to be greater than a 10 count, but if I can get # the 2 blocks below to work, I will be able to play about with # the code and increase it to the desired level. # for ( $i =10; $i += 1 ; ) { The for loop synax is: for ( STATEMENT; CONDITIONAL; STATEMENT ) { So $i =10 is superfluous and $i += 1 is always true if $i is true so it will loop until $i becomes 0 which can only happen if $i starts out as a negative number. I have 2 books, 1 is the Camel book of PERL, the other is SAMS teach yourself cgi in 24 hours. About £20 each. In SAMS, the only reference to code for counting is as follows $i = 0; while ($i 100) { $i++; } with the following text This loop doesn't actually do anything, it just increments $i every time the loop is executed and exits when $i gets to 99. And the PERL book isn't any more helpful. Teach yourself in 24 hrs? I have spent the last 72 hrs trying to work out how to test to see if $i = 1 and $mystart 1 $i = 1 and $mystart 0 $i = 2..10 and $mystart = 1 Si = 2..10 and $mystart = 0 and print according to the result. and I still can't do it. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: help needed to get over endless loop
Brian wrote: John W. Krahn wrote: Brian wrote: chomp($Lang = $val1); chomp($Year_in = $val2); chomp() removes the contents of the $/ variable from the end of the string. What makes you think that $val1 and $val2 need to be chomp()ed? Oops, they are leftovers from when I was using STDIN Actually, I have just tried to remove the chomps and the program stops working properly. So it looks like they will have to stay put for a while. :-( -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: help needed to get over endless loop
John W. Krahn wrote: Brian wrote: This is what I'm using upto the code that is giving me a headache. I know it's messy, but I have no training in PERL, I am trying to forward-engineer this cgi by back-engineering from html templates I created and which were chosen using $t-src [ *SNIP* ] whether or not leapyear { ($myleap = 0 ) } if ($Calend eq b ) {$myleap += 1} if ($Calend eq d ) {$myleap += 1} if ($Calend eq f ) {$myleap += 1} if ($Calend eq h ) {$myleap += 1} The usual way to calculate a leap year is: sub is_leap_year { my $year = shift; return $year % 4 == 0 $year % 100 != 0 || $year % 400 == 0 } I guess that % means 'wholly divisible by' And presumably starts out as a 4 digit number, gets tested and overwritten by 0 or 1, 1 being true? whether year starts on a Sunday { ($mystart = 0 ) } if ($Calend eq a || $Calend eq b) {$mystart -= 0} if ($Calend eq c || $Calend eq d) {$mystart -= 1} if ($Calend eq e || $Calend eq f) {$mystart -= 2} if ($Calend eq g || $Calend eq h) {$mystart -= 3} use Time::Local; sub year_starts_sunday { my $year = shift; return !( gmtime timegm 0, 0, 12, 1, 0, $year - 1900 )[ 6 ] } Oh oh oh, I think you think I am only working with the current year. This is how my live prog works using cgi loading templates http://www.absey-vine.co.uk/calendar/ and this is how my cgi only runs, it only displays 2006 regardless of the year you input. http://www.absey-vine.co.uk/calendar/testing123/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: help needed to get over endless loop
Brian wrote: John W. Krahn wrote: Brian wrote: This is what I'm using upto the code that is giving me a headache. I know it's messy, but I have no training in PERL, I am trying to forward-engineer this cgi by back-engineering from html templates I created and which were chosen using $t-src [ *SNIP* ] whether or not leapyear { ($myleap = 0 ) } if ($Calend eq b ) {$myleap += 1} if ($Calend eq d ) {$myleap += 1} if ($Calend eq f ) {$myleap += 1} if ($Calend eq h ) {$myleap += 1} The usual way to calculate a leap year is: sub is_leap_year { my $year = shift; return $year % 4 == 0 $year % 100 != 0 || $year % 400 == 0 } I guess that % means 'wholly divisible by' perldoc perlop [ *SNIP* ] Binary % computes the modulus of two numbers. Given integer operands $a and $b: If $b is positive, then $a % $b is $a minus the largest multiple of $b that is not greater than $a. If $b is negative, then $a % $b is $a minus the smallest multiple of $b that is not less than $a (i.e. the result will be less than or equal to zero). Note that when use integer is in scope, % gives you direct access to the modulus operator as implemented by your C compiler. This operator is not as well defined for negative operands, but it will execute faster. And presumably starts out as a 4 digit number, gets tested and overwritten by 0 or 1, 1 being true? What starts out as a 4 digit number? What gets tested? What gets overwritten? You will have to be more specific on what you think is happening for me to either agree with you or correct you. whether year starts on a Sunday { ($mystart = 0 ) } if ($Calend eq a || $Calend eq b) {$mystart -= 0} if ($Calend eq c || $Calend eq d) {$mystart -= 1} if ($Calend eq e || $Calend eq f) {$mystart -= 2} if ($Calend eq g || $Calend eq h) {$mystart -= 3} use Time::Local; sub year_starts_sunday { my $year = shift; return !( gmtime timegm 0, 0, 12, 1, 0, $year - 1900 )[ 6 ] } Oh oh oh, I think you think I am only working with the current year. No, I do not think that. However using timegm() implies a certain upper and lower bound to the range of years that can correctly be calculated. John -- Those people who think they know everything are a great annoyance to those of us who do.-- Isaac Asimov -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: help needed to get over endless loop
John W. Krahn wrote: Brian wrote: John W. Krahn wrote: Brian wrote: This is what I'm using upto the code that is giving me a headache. I know it's messy, but I have no training in PERL, I am trying to forward-engineer this cgi by back-engineering from html templates I created and which were chosen using $t-src [ *SNIP* ] whether or not leapyear { ($myleap = 0 ) } if ($Calend eq b ) {$myleap += 1} if ($Calend eq d ) {$myleap += 1} if ($Calend eq f ) {$myleap += 1} if ($Calend eq h ) {$myleap += 1} The usual way to calculate a leap year is: sub is_leap_year { my $year = shift; return $year % 4 == 0 $year % 100 != 0 || $year % 400 == 0 } I guess that % means 'wholly divisible by' perldoc perlop [ *SNIP* ] Binary % computes the modulus of two numbers. Given integer operands $a and $b: If $b is positive, then $a % $b is $a minus the largest multiple of $b that is not greater than $a. If $b is negative, then $a % $b is $a minus the smallest multiple of $b that is not less than $a (i.e. the result will be less than or equal to zero). Note that when use integer is in scope, % gives you direct access to the modulus operator as implemented by your C compiler. This operator is not as well defined for negative operands, but it will execute faster. LOL, I didn't understand any of that. :-) Apart from the last sentence ;-) And presumably starts out as a 4 digit number, gets tested and overwritten by 0 or 1, 1 being true? What starts out as a 4 digit number? What gets tested? What gets $year overwritten? You will have to be more specific on what you think is happening for me to either agree with you or correct you. I'm tired, it's about 5 hours past my bedtime. I think I had better go hit the sack. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: help needed to get over endless loop
On Fri, Apr 17, 2009 at 21:35, Brian brian5432...@yahoo.co.uk wrote: snip LOL, I didn't understand any of that. :-) Apart from the last sentence ;-) snip Think of a clock, they hands can go around as many times as you like but they can never point to anything higher than 12. Modulus works the same way, the second value acts as a cap: 0 % 4 = 0 1 % 4 = 1 2 % 4 = 2 3 % 4 = 3 4 % 4 = 0 5 % 4 = 1 6 % 4 = 2 7 % 4 = 3 8 % 4 = 0 It is really the remainder of the division: 7/4 = 1 plus a remainder of 3. -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Help needed in understanding some lines of code.
Can anybody explains this piece of code, i have difficulties in understanding it, my $errorlog = /var/log/controler.log; initLanguage($language); launchCbox(); sub launchCbox { $scr = Term::ScreenColor-new; $scr-clrscr(); my ($mode) = @_; my $error = 0; my $cbox_x = $dog_x + 3; my $args; my %box_args = %{$args[3]}; $args .= -d if $box_args{debug}; $args .= -l if $box_args{log}; $args .= -L .$box_args{language} if $box_args{language}; if($mode ne restart) { $scr-at($y_pos,3)-puts($x.. .$txth-getText(5016)); } else { $y_pos = $dog_y_pos+3; $scr-at($dog_y_pos+3,3)-puts($cbox_x.. .$txth-getText(5016. x($status_bar_pos-(length($txth-getText(5016))+7; } if(!$xwindow) { `perl ./cbox.pl 2/var/log/cbox.log $args /dev/tty9`; } else { `perl ./cbox.pl 2/var/log/cbox.log $args /dev/pts/2`; } $error ? printNOK : printOK; } Kindest Regards, Raheel
Re: Help needed in understanding some lines of code.
On Thu, Mar 19, 2009 at 06:11, Raheel Hassan raheel.has...@gmail.com wrote: Can anybody explains this piece of code, i have difficulties in understanding it, my $errorlog = /var/log/controler.log; initLanguage($language); No idea what this does because there is no context for it. launchCbox(); This runs the code below. sub launchCbox { $scr = Term::ScreenColor-new; This creates a new Term::ScreenColor[1] object called $scr. Term::ScreenColor allows you to position text on the screen and control its color. $scr-clrscr(); here we are calling the clrscr method of the $scr object. This causes the screen to be cleared. my ($mode) = @_; This attempts to get the first argument passed to this function, but since you didn't pass any $mode will be undefined. my $error = 0; Sets a variable named $error to zero. my $cbox_x = $dog_x + 3; sets a variable named $cbox_x to the value of $dog_x (which is created and set somewhere else) plus three. If I had to guess, I would say that $dog_x was used to draw a some form of dialog box, and we are trying to position this cbox inside of the dialog box. my $args; This creates a variable named $args. my %box_args = %{$args[3]}; This creates a hash named %box_args out of the fourth item in @args which is set somewhere else. A hash is a set of key/value pairs. You can access a value in the set by saying $box_args{key}. $args .= -d if $box_args{debug}; $args .= -l if $box_args{log}; $args .= -L .$box_args{language} if $box_args{language}; here we are building a string inside of $args. If the value in %box_args associated with key key named debug is true then we add a -d to the string. The same goes for the others. if($mode ne restart) The code inside of {} after this statement will execute if $mode is not the string restart. Since we know that $mode is empty (see above), we know this code will execute. { $scr-at($y_pos,3)-puts($x.. .$txth-getText(5016)); } This prints the value of $x (set somewhere else) concatenated with . concatenated with the value of calling the getText method of $txth (set somewhere else) with the string 5016 at the position on the screen $y_pos (set somewhere else), 3. If I had to guess, I would bet that $txth is an object that holds a bunch of strings that have been translated into a bunch of different languages, and that you are asking for the string associated with 5016. This is a common technique when working with applications that will be run in many countries. else { $y_pos = $dog_y_pos+3; $scr-at($dog_y_pos+3,3)-puts($cbox_x.. .$txth-getText(5016. x($status_bar_pos-(length($txth-getText(5016))+7; } This does something similar to the code above if the value of $mode was restart. if(!$xwindow) Similar to the code above, if the $xwindow variable (set somewhere else is not true, the code in the braces below will execute. If I had to guess, I would bet that this is a flag that tells us if we are running under the X Windowing System or not. { `perl ./cbox.pl 2/var/log/cbox.log $args /dev/tty9`; } This code runs another perl program named cbox.pl in the current directory. The program is passed a command line options that we built above (e.g. -d if debug was set). It is redirecting error messages to a log file and writing its STDOUT to /dev/tty9 (which is a terminal). My bet is that this program draws the rest of the cbox. else { `perl ./cbox.pl 2/var/log/cbox.log $args /dev/pts/2`; } This code executes if the value in $xwindows is true, and it does a similar thing, but writes to /dev/pts/2 (which is a pseudoterminal). This lends support to my theory that $xwindows is a flag that tells us if we are running X. $error ? printNOK : printOK; Unless I am missing something $error is never changed from its original value of 0, so the function printOK will always be called. Given the odd nature of $error (false being good) I am betting that the original intent was to use the system[2] function instead of the qx// operator[3] (the `s above) to execute cbox.pl and the person who wrote this intended to store the return value from system in $error. All in all, that was some horrible code. Bad indenting style, global variables, calling another Perl program instead of writing a module to do common functions, use of negative comparisons in if statements that have else clauses, and Perl 4 style function calls. My bet is that this code was written by someone who knew ANSI/ISO C fairly well and knew very little Perl. The obvious hack of using the qx// operator where a call to the system function would have been more appropriate speaks of someone who knew roughly what he or she wanted to do, but was struggling to find a way to make it work. 1. http://search.cpan.org/dist/Term-ScreenColor/ScreenColor.pm 2. http://perldoc.perl.org/functions/system.html 3.
Re: Help needed in understanding some lines of code.
On Thu, Mar 19, 2009 at 10:41, Chas. Owens chas.ow...@gmail.com wrote: snip initLanguage($language); No idea what this does because there is no context for it. snip x($status_bar_pos-(length($txth-getText(5016))+7; } snip Whoops, I only worked down the code and didn't reread until after I sent the message. After seeing the rest of the code I believe the initLanguage function is setting the language to be used by the $txth object. -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed in understanding some lines of code.
On Thu Mar 19 2009 @ 10:41, Chas. Owens wrote: On Thu, Mar 19, 2009 at 06:11, Raheel Hassan raheel.has...@gmail.com wrote: Can anybody explains this piece of code, i have difficulties in understanding it, snip - long, careful, generous explanation of ugly, ugly code removed You're much nicer than the folks over at Linux Questions. http://tinyurl.com/dhncl4 Then again, he did format the code at least a bit for the email. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Compare, diff to a file with Perl help needed
Hi I have 2 log files, each with a timestamp on the first 2 fields. However, when I do a awk '/ / {print $1,$2}' logs/x.log on a log file, it is complicated by the fact that I also get other non timestamp column, 2008-10-20 15:00:06,113 2008-10-20 15:00:06,113 2008-10-20 14:59:48,828 javax.naming.CommunicationException: Could at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1414) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:594) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587) at javax.naming.InitialContext.lookup(InitialContext.java:351) at com.cm.common.util.jndi.MultiJndiLookup.getRemoteObjectStub(MultiJndiLookup.java: 377) at com.cm.common.util.jndi.MultiJndiLookup.getRemoteObjectRef(MultiJndiLookup.java: 130) at com.cm.common.util.jndi.JndiLookup.getRemoteObjectRef(JndiLookup.java: 88) at com.cm.system.SystemInfoTopicManager.init(SystemInfoTopicManager.java: 91) at com.cm.system.SystemInfoTopicManager.reconnect(SystemInfoTopicManager.java: 181) at com.m.system.SystemInfoTopicManager.onException(SystemInfoTopicManager.java: 216) at org.jboss.mq.Connection $ExceptionListenerRunnable.run(Connection.java:1348) at java.lang.Thread.run(Thread.java:595) Caused by: at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:269) at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1385) ... 11 2008-10-20 14:59:49,800 Unix diff gives extra output like 1,38c1,2 2008-10-20 15:00:09,890 WARN [EMAIL PROTECTED]:***:***:***] [ExceptionListener Connection@ 323[token=ConnectionToken:ID:93/1003454235 rcvstate=STARTED]] com.cm.system.SystemInfoTopicManager - Jms server not reachable..it may be down. Deatils:Could not obtain connection to any of these urls: 172.16.70.1:1100,172.16.70.2:1100,172.16.70.3:1100,172.16.70.4:1 100,172.16.70.5:1100 I like to generate a 3rd file after comparing 2 files with format like the other 2 files but containing only the difference between 1st and 2nd files. ie suppose the file contains file1file2 2008-10-20 15:00:06,113 ... 2008-10-20 15:00:06,113 ... 2008-10-20 15:00:06,113 ... 2008-10-20 15:00:06,113 2008-10-20 14:59:48,828 ... 2008-10-20 14:58:48,900 ... javax.naming.CommunicationException... at org.jnp.interfaces.NamingContext.ch... I'm hoping to get in file3 2008-10-20 14:59:48,828 ...plus rest of line 2008-10-20 14:58:48,900 ...plus rest of line I suppose I also need to read in the 1 field of the timestamp and convert time to unix time to compare and then convert that unix time to this timestamp format. Is there a way to get this done with Perl ? Could someone be kind to show me a close example to what I like to accomplish here ? Any help is appreciated. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Help needed for Read XML from Serial Port
Hi, I'd like some help with the serial port code from my hacked up program below. I have a electricity monitoring device thats hooked up to my pc's serial port. The device outputs XML every six seconds. I want to read some of the values from the XML and put them into a database. The code below does work but it isn't getting the whole XML feed at six second intervils. I've had a look at the documentation for SerialPort but it's going over my head. #! perl -w use strict; use Win32::SerialPort 0.11; use DBI; use DBD::mysql; my $DBstore = DBI-connect( 'dbi:mysql:elec:localhost: 3306','elec','elec'); my $ob = Win32::SerialPort-start (tpj4.cfg) || die; for (my $qwe = 1; $qwe = 1; $qwe--) { sleep 1; my ($count, $result) = $ob-read(900); if ($result =~ m!ch1watts0*(\d+)/watts/ch1.*ch2watts0*(\d +)/watts/ch2.*ch3watts0*(\d+)/watts/ch3.*tmpr([\d.]+)/ tmpr!) { my $wattsx = $1; my $wattsy = $2; my $wattsz = $3; my $temp = $4; my $Total = $wattsx + $wattsy + $wattsy; my $sql = qq{ insert into readings (units,temp) VALUES ($wattsx, $temp) }; $DBstore-do( $sql ); print Temp : $temp Watts Ch1 : $wattsx Watts Ch2 : $wattsy Watts ch3 : $wattsz Watts Total : $Total in KWh \n; } } undef $ob; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: perl-support for vim help needed
don't forget to instal perl-support for vim: http://www.vim.org/scripts/script.php?script_id=556 here is the desc: description - insert various types of comments - insert complete but empty statements (e.g. 'if {} else {}' ) - insert often used code snippets (e.g. declarations, the opening of files, .. ) - insert the names of file tests, character classes, special Perl-variables and POSIX-signals - read, write, maintain your own code snippets in a separate directory - run scripts or run syntax check from within the editor - show compilation erros in a quickfix window; navigate with hotkeys - read perldoc for functions and modules - run perltidy / run the profiler SmallProf On Sat, 2008-05-10 at 23:09 -0400, Richard Lee wrote: Chas. Owens wrote: On Sat, May 10, 2008 at 1:42 AM, Richard Lee [EMAIL PROTECTED] wrote: does anyone use perl-support for vim here? I installed it but having trouble bringing up the menus.. does anyone uses this? and know how to bring up the menu? If the root menu 'Perl' is not visible call it with the item Load Perl Support from the standard Tools-menu. -- where is this standard tools-menu? I believe that they are referring to gvim's menus. yes, gvim.. thanks!! I am exploring them now.. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: perl-support for vim help needed
On Sat, May 10, 2008 at 1:42 AM, Richard Lee [EMAIL PROTECTED] wrote: does anyone use perl-support for vim here? I installed it but having trouble bringing up the menus.. does anyone uses this? and know how to bring up the menu? If the root menu 'Perl' is not visible call it with the item Load Perl Support from the standard Tools-menu. -- where is this standard tools-menu? I believe that they are referring to gvim's menus. -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: perl-support for vim help needed
Chas. Owens wrote: On Sat, May 10, 2008 at 1:42 AM, Richard Lee [EMAIL PROTECTED] wrote: does anyone use perl-support for vim here? I installed it but having trouble bringing up the menus.. does anyone uses this? and know how to bring up the menu? If the root menu 'Perl' is not visible call it with the item Load Perl Support from the standard Tools-menu. -- where is this standard tools-menu? I believe that they are referring to gvim's menus. yes, gvim.. thanks!! I am exploring them now.. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
perl-support for vim help needed
does anyone use perl-support for vim here? I installed it but having trouble bringing up the menus.. does anyone uses this? and know how to bring up the menu? If the root menu 'Perl' is not visible call it with the item Load Perl Support from the standard Tools-menu. -- where is this standard tools-menu? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Help needed with insignificant problem using format and write
Chas Owens wrote: On 8/20/07, Mathew Snyder [EMAIL PROTECTED] wrote: Paul Lalli wrote: On Aug 20, 3:10 pm, [EMAIL PROTECTED] (Mathew Snyder) wrote: I run a script which creates a small report for different users of a system we have here at work. The report is a simple text document formated with, of all things, the format function. It uses a TOP to create a header for each of our customers which a user has worked with. For some reason the first and only the first write of the TOP results in a double write. write TIMESHEET_TOP; snip write TIMESHEET; It gets that double header. Again, everything else gets only the one, expected, header. Anyone have any ideas as to why the first one always prints twice? Because Perl is smarter than you're giving it credit for. :-P $ perldoc -f write write FILEHANDLE write EXPR write Top of form processing is handled automatically: if there is insufficient room on the current page for the formatted record, the page is advanced by writing a form feed, a special top-of-page format is used to format the new page header, and then the record is written. Key phrase there: top of form processing is handled automatically. That is, you don't have to write the header your self. Perl does that for you, on each new page the report is printed to. You just define the format header. Let Perl decide when it needs to be written. Remove the write TIMESHEET_TOP line. Paul Lalli Paul, Thanks for the help. However, doing what you said results in the output having only one header and the list output for each customer going under it. It doesn't create a header for each customer. Mathew Header writes are controlled by $- (aka $FORMAT_LINES_LEFT under the english pragma). When $- is zero a header gets written and $- is set back to the number of lines to print before a header is printed. Or at least that is how I remember it. #!/usr/bin/perl use strict; use warnings; my $customer; my $id = 5000; my $time = 12:30:00; for $customer (qwfoo bar baz) { $id++; write; $- = 0; } format STDOUT_TOP = Customer @ $customer . format STDOUT = @, @ $id, $time . It would appear that for all but the first iteration, this is happening. However, something during the first time through seems to cause the flag to not be what it should. I've tried changing where the TOP is in the script, when it gets written, the value of $- entering the loop... Nothing seems to work. Keep up with me and what I'm up to: http://theillien.blogspot.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Help needed with insignificant problem using format and write
On 8/21/07, Mathew Snyder [EMAIL PROTECTED] wrote: snip It would appear that for all but the first iteration, this is happening. However, something during the first time through seems to cause the flag to not be what it should. I've tried changing where the TOP is in the script, when it gets written, the value of $- entering the loop... Nothing seems to work. snip Did my example code work for you? You need to set $- to zero after you are finished writing records for this page. You should also add the number of records you have written to $= (otherwise you will wind up with headers in the middle of your records if you have more than 60 - your header size). In general you are reaching the edges of what format can do and are starting to put in hacks. This is bad for three reasons: you need global variables to work with format, you are now messing with how format works to make it do what you want, and the whole system is changing in Perl 6, so your code will have to change anyway. I would suggest using Perl6::Form* or switching to printf. * This is an impelentation of Perl 6's version of formats written for Perl 5 http://search.cpan.org/~dconway/Perl6-Form-0.04/Form.pm -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Help needed with insignificant problem using format and write
Chas Owens wrote: On 8/21/07, Mathew Snyder [EMAIL PROTECTED] wrote: snip It would appear that for all but the first iteration, this is happening. However, something during the first time through seems to cause the flag to not be what it should. I've tried changing where the TOP is in the script, when it gets written, the value of $- entering the loop... Nothing seems to work. snip Did my example code work for you? You need to set $- to zero after you are finished writing records for this page. You should also add the number of records you have written to $= (otherwise you will wind up with headers in the middle of your records if you have more than 60 - your header size). In general you are reaching the edges of what format can do and are starting to put in hacks. This is bad for three reasons: you need global variables to work with format, you are now messing with how format works to make it do what you want, and the whole system is changing in Perl 6, so your code will have to change anyway. I would suggest using Perl6::Form* or switching to printf. * This is an impelentation of Perl 6's version of formats written for Perl 5 http://search.cpan.org/~dconway/Perl6-Form-0.04/Form.pm Chas, Yes, the test code worked. I've installed Perl6::Form and will see what I can do with it. As it seems to be more robust, I might even be able to format the output the way I had mentioned in a previous post: Ticket ID SubjectDate hh:mm 12345 Ticket Subject MM/DD/ 1:00 MM/DD/ 2:00 MM/DD/ 3:00 Mathew -- Keep up with me and what I'm up to: http://theillien.blogspot.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Help needed with insignificant problem using format and write
I run a script which creates a small report for different users of a system we have here at work. The report is a simple text document formated with, of all things, the format function. It uses a TOP to create a header for each of our customers which a user has worked with. For some reason the first and only the first write of the TOP results in a double write. The following code sub writeList { my %users = @_; foreach my $user (keys %users) { open TIMESHEET, /work_reports/ticketlists/ticketlists_$endDate/ticketlist_$user . _ . $endDate.txt or die Can't open file: $!; print TIMESHEET List of tickets worked on by $user during week ending $endDate, \n\n; # Print the header for our data using preset formats. They are offset the way they are due to the # requirement that the closing . be in the first column of the script. All lines have subsequently # been aligned similarly so as not to confuse anyone regarding the association. I would have # declared them earlier in the script but due to the use of scoped variables the compilation # will fail if I do. my $envs_hash = $tickets{$user}; foreach my $env (sort keys %$envs_hash){ format TIMESHEET_TOP = @ $env Ticket ID SubjectDate hh:mm --- . write TIMESHEET_TOP; my $ids_hash = $envs_hash-{$env}; foreach my $id (sort keys %$ids_hash) { my $subjects_hash = $ids_hash-{$id}; foreach my $subject (keys %$subjects_hash) { format TIMESHEET = @# ^ @ @ $id, $subject, $rollupDate{$user}{$env}, $$subjects_hash{$subject} ~~ ^ $subject . write TIMESHEET; } } print TIMESHEET \n\n; } close TIMESHEET; } return; } produces the following begin output List of tickets worked on by msnyder during week ending 08-19-2007 customer1 Ticket ID SubjectDate hh:mm --- customer1 Ticket ID SubjectDate hh:mm --- 81106 Ticket Subject 08-13-2007 0:20 end output It gets that double header. Again, everything else gets only the one, expected, header. Anyone have any ideas as to why the first one always prints twice? Mathew -- Keep up with me and what I'm up to: http://theillien.blogspot.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Help needed with insignificant problem using format and write
On Aug 20, 3:10 pm, [EMAIL PROTECTED] (Mathew Snyder) wrote: I run a script which creates a small report for different users of a system we have here at work. The report is a simple text document formated with, of all things, the format function. It uses a TOP to create a header for each of our customers which a user has worked with. For some reason the first and only the first write of the TOP results in a double write. write TIMESHEET_TOP; snip write TIMESHEET; It gets that double header. Again, everything else gets only the one, expected, header. Anyone have any ideas as to why the first one always prints twice? Because Perl is smarter than you're giving it credit for. :-P $ perldoc -f write write FILEHANDLE write EXPR write Top of form processing is handled automatically: if there is insufficient room on the current page for the formatted record, the page is advanced by writing a form feed, a special top-of-page format is used to format the new page header, and then the record is written. Key phrase there: top of form processing is handled automatically. That is, you don't have to write the header your self. Perl does that for you, on each new page the report is printed to. You just define the format header. Let Perl decide when it needs to be written. Remove the write TIMESHEET_TOP line. Paul Lalli -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Help needed with insignificant problem using format and write
Paul Lalli wrote: On Aug 20, 3:10 pm, [EMAIL PROTECTED] (Mathew Snyder) wrote: I run a script which creates a small report for different users of a system we have here at work. The report is a simple text document formated with, of all things, the format function. It uses a TOP to create a header for each of our customers which a user has worked with. For some reason the first and only the first write of the TOP results in a double write. write TIMESHEET_TOP; snip write TIMESHEET; It gets that double header. Again, everything else gets only the one, expected, header. Anyone have any ideas as to why the first one always prints twice? Because Perl is smarter than you're giving it credit for. :-P $ perldoc -f write write FILEHANDLE write EXPR write Top of form processing is handled automatically: if there is insufficient room on the current page for the formatted record, the page is advanced by writing a form feed, a special top-of-page format is used to format the new page header, and then the record is written. Key phrase there: top of form processing is handled automatically. That is, you don't have to write the header your self. Perl does that for you, on each new page the report is printed to. You just define the format header. Let Perl decide when it needs to be written. Remove the write TIMESHEET_TOP line. Paul Lalli Paul, Thanks for the help. However, doing what you said results in the output having only one header and the list output for each customer going under it. It doesn't create a header for each customer. Mathew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Help needed with insignificant problem using format and write
On 8/20/07, Mathew Snyder [EMAIL PROTECTED] wrote: Paul Lalli wrote: On Aug 20, 3:10 pm, [EMAIL PROTECTED] (Mathew Snyder) wrote: I run a script which creates a small report for different users of a system we have here at work. The report is a simple text document formated with, of all things, the format function. It uses a TOP to create a header for each of our customers which a user has worked with. For some reason the first and only the first write of the TOP results in a double write. write TIMESHEET_TOP; snip write TIMESHEET; It gets that double header. Again, everything else gets only the one, expected, header. Anyone have any ideas as to why the first one always prints twice? Because Perl is smarter than you're giving it credit for. :-P $ perldoc -f write write FILEHANDLE write EXPR write Top of form processing is handled automatically: if there is insufficient room on the current page for the formatted record, the page is advanced by writing a form feed, a special top-of-page format is used to format the new page header, and then the record is written. Key phrase there: top of form processing is handled automatically. That is, you don't have to write the header your self. Perl does that for you, on each new page the report is printed to. You just define the format header. Let Perl decide when it needs to be written. Remove the write TIMESHEET_TOP line. Paul Lalli Paul, Thanks for the help. However, doing what you said results in the output having only one header and the list output for each customer going under it. It doesn't create a header for each customer. Mathew Header writes are controlled by $- (aka $FORMAT_LINES_LEFT under the english pragma). When $- is zero a header gets written and $- is set back to the number of lines to print before a header is printed. Or at least that is how I remember it. #!/usr/bin/perl use strict; use warnings; my $customer; my $id = 5000; my $time = 12:30:00; for $customer (qwfoo bar baz) { $id++; write; $- = 0; } format STDOUT_TOP = Customer @ $customer . format STDOUT = @, @ $id, $time . -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Help needed created this data structure
--- D. Bolliger [EMAIL PROTECTED] wrote: klute am Montag, 9. Juli 2007 23:04: --- Chris Charley [EMAIL PROTECTED] wrote: - Original Message - From: klute [EMAIL PROTECTED] Newsgroups: perl.beginners To: beginners@perl.org Sent: Monday, July 09, 2007 4:20 PM Subject: Help needed created this data structure Hi All, I am new to Perl and was hoping to get advice on creating the following data structure: I have an Affiliate Parent Groups, Affiliate Groups, and Affiliates. Each affiliate has affiliateId, affiliateName. I guess what I'd like to have is an array of hashes where the array would contain Affiliate Parent Groups. Each item in the array would contain a hash map with Affiliate Group name as the key and An array of Affiliates (each having AffiliateId and AffiliateName) as the value. How would I go about creating such structure and adding values to it in a loop? Any help will be greatly appreciated! James Its hard to see what structure you want without some sample data. Send some data as it is in the file. Have you tried any coding yet? Chris Hi Chris, I did try coding this but I am afraid to confuse everyone with what I came up with so far. I can paste what I have if you feel that it would help. Here is the sample data: Affiliate Parent Group: Google - Affiliate Group: Google Advertiser -- Affiliate (Aff Id: 1, Aff Name: Frank) -- Affiliate (Aff Id: 2, Aff Name: Mary) - Affiliate Group: Google Publisher -- Affiliate (Aff Id: 3, Aff Name: Lori) -- Affiliate (Aff Id: 4, Aff Name: Mike) Affiliate Parent Group: Yahoo - Affiliate Group: Yahoo Advertiser -- Affiliate (Aff Id: 5, Aff Name: Marlene) -- Affiliate (Aff Id: 6, Aff Name: Larry) - Affiliate Group: Yahoo Publisher -- Affiliate (Aff Id: 7, Aff Name: Alex) -- Affiliate (Aff Id: 8, Aff Name: Glenn) Hello Klute (please don't top post to keep the conversation readable) The following script extracts the information out of your sample data. There are no checks if the data format is correct (nesting order, additional text). It does not result in an array of hashes, but in a single hash. Modify it if needed :-) Dani #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %data; # holds the current first and second level # my ($parent_group, $aff_group); while (DATA) { # a loop block, so we can use next { # skip blank lines /^\s*$/ and next; # record current first level /^A.*?: (.*)/ and $parent_group=$1 and next; # record current second level /^\s+-.*?: (.*)/ and $aff_group=$1 and next; # fill %data, with completed three levels /--.*?: (\d+).*?: (\w+)/ and $data{$parent_group}{$aff_group}{$1}=$2; } } print Data::Dumper::Dumper \%data; __DATA__ Affiliate Parent Group: Google - Affiliate Group: Google Advertiser -- Affiliate (Aff Id: 1, Aff Name: Frank) -- Affiliate (Aff Id: 2, Aff Name: Mary) - Affiliate Group: Google Publisher -- Affiliate (Aff Id: 3, Aff Name: Lori) -- Affiliate (Aff Id: 4, Aff Name: Mike) Affiliate Parent Group: Yahoo - Affiliate Group: Yahoo Advertiser -- Affiliate (Aff Id: 5, Aff Name: Marlene) -- Affiliate (Aff Id: 6, Aff Name: Larry) - Affiliate Group: Yahoo Publisher -- Affiliate (Aff Id: 7, Aff Name: Alex) -- Affiliate (Aff Id: 8, Aff Name: Glenn) Thanks guys for your replies. It works! So what data structure am I dealing with here? $data{$parent_group}{$aff_group}{$1}=$2; Best, James Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, photos more. http://mobile.yahoo.com/go?refer=1GNXIC -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Help needed created this data structure
--- klute [EMAIL PROTECTED] wrote: --- D. Bolliger [EMAIL PROTECTED] wrote: klute am Montag, 9. Juli 2007 23:04: --- Chris Charley [EMAIL PROTECTED] wrote: - Original Message - From: klute [EMAIL PROTECTED] Newsgroups: perl.beginners To: beginners@perl.org Sent: Monday, July 09, 2007 4:20 PM Subject: Help needed created this data structure Hi All, I am new to Perl and was hoping to get advice on creating the following data structure: I have an Affiliate Parent Groups, Affiliate Groups, and Affiliates. Each affiliate has affiliateId, affiliateName. I guess what I'd like to have is an array of hashes where the array would contain Affiliate Parent Groups. Each item in the array would contain a hash map with Affiliate Group name as the key and An array of Affiliates (each having AffiliateId and AffiliateName) as the value. How would I go about creating such structure and adding values to it in a loop? Any help will be greatly appreciated! James Its hard to see what structure you want without some sample data. Send some data as it is in the file. Have you tried any coding yet? Chris Hi Chris, I did try coding this but I am afraid to confuse everyone with what I came up with so far. I can paste what I have if you feel that it would help. Here is the sample data: Affiliate Parent Group: Google - Affiliate Group: Google Advertiser -- Affiliate (Aff Id: 1, Aff Name: Frank) -- Affiliate (Aff Id: 2, Aff Name: Mary) - Affiliate Group: Google Publisher -- Affiliate (Aff Id: 3, Aff Name: Lori) -- Affiliate (Aff Id: 4, Aff Name: Mike) Affiliate Parent Group: Yahoo - Affiliate Group: Yahoo Advertiser -- Affiliate (Aff Id: 5, Aff Name: Marlene) -- Affiliate (Aff Id: 6, Aff Name: Larry) - Affiliate Group: Yahoo Publisher -- Affiliate (Aff Id: 7, Aff Name: Alex) -- Affiliate (Aff Id: 8, Aff Name: Glenn) Hello Klute (please don't top post to keep the conversation readable) The following script extracts the information out of your sample data. There are no checks if the data format is correct (nesting order, additional text). It does not result in an array of hashes, but in a single hash. Modify it if needed :-) Dani #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %data; # holds the current first and second level # my ($parent_group, $aff_group); while (DATA) { # a loop block, so we can use next { # skip blank lines /^\s*$/ and next; # record current first level /^A.*?: (.*)/ and $parent_group=$1 and next; # record current second level /^\s+-.*?: (.*)/ and $aff_group=$1 and next; # fill %data, with completed three levels /--.*?: (\d+).*?: (\w+)/ and $data{$parent_group}{$aff_group}{$1}=$2; } } print Data::Dumper::Dumper \%data; __DATA__ Affiliate Parent Group: Google - Affiliate Group: Google Advertiser -- Affiliate (Aff Id: 1, Aff Name: Frank) -- Affiliate (Aff Id: 2, Aff Name: Mary) - Affiliate Group: Google Publisher -- Affiliate (Aff Id: 3, Aff Name: Lori) -- Affiliate (Aff Id: 4, Aff Name: Mike) Affiliate Parent Group: Yahoo - Affiliate Group: Yahoo Advertiser -- Affiliate (Aff Id: 5, Aff Name: Marlene) -- Affiliate (Aff Id: 6, Aff Name: Larry) - Affiliate Group: Yahoo Publisher -- Affiliate (Aff Id: 7, Aff Name: Alex) -- Affiliate (Aff Id: 8, Aff Name: Glenn) Thanks guys for your replies. It works! So what data structure am I dealing with here? $data{$parent_group}{$aff_group}{$1}=$2; Best, James Also, I am not quite sure how to iterate through this structure and print its contents without using Dumper. Can anyone help? Thanks very much! James Get the free Yahoo! toolbar and rest assured with the added security of spyware protection. http://new.toolbar.yahoo.com/toolbar/features/norton/index.php -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Fw: Help needed created this data structure
- Original Message - From: Chris Charley [EMAIL PROTECTED] To: klute [EMAIL PROTECTED] Sent: Tuesday, July 10, 2007 7:17 PM Subject: Re: Help needed created this data structure - Original Message - From: klute [EMAIL PROTECTED] Newsgroups: perl.beginners To: klute [EMAIL PROTECTED]; beginners@perl.org Sent: Tuesday, July 10, 2007 5:37 PM Subject: Re: Help needed created this data structure --- klute [EMAIL PROTECTED] wrote: --- D. Bolliger [EMAIL PROTECTED] wrote: Hello Klute (please don't top post to keep the conversation readable) The following script extracts the information out of your sample data. There are no checks if the data format is correct (nesting order, additional text). It does not result in an array of hashes, but in a single hash. Modify it if needed :-) Dani #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %data; # holds the current first and second level # my ($parent_group, $aff_group); while (DATA) { # a loop block, so we can use next { # skip blank lines /^\s*$/ and next; # record current first level /^A.*?: (.*)/ and $parent_group=$1 and next; # record current second level /^\s+-.*?: (.*)/ and $aff_group=$1 and next; # fill %data, with completed three levels /--.*?: (\d+).*?: (\w+)/ and $data{$parent_group}{$aff_group}{$1}=$2; } } print Data::Dumper::Dumper \%data; __DATA__ Affiliate Parent Group: Google - Affiliate Group: Google Advertiser -- Affiliate (Aff Id: 1, Aff Name: Frank) -- Affiliate (Aff Id: 2, Aff Name: Mary) - Affiliate Group: Google Publisher -- Affiliate (Aff Id: 3, Aff Name: Lori) -- Affiliate (Aff Id: 4, Aff Name: Mike) Affiliate Parent Group: Yahoo - Affiliate Group: Yahoo Advertiser -- Affiliate (Aff Id: 5, Aff Name: Marlene) -- Affiliate (Aff Id: 6, Aff Name: Larry) - Affiliate Group: Yahoo Publisher -- Affiliate (Aff Id: 7, Aff Name: Alex) -- Affiliate (Aff Id: 8, Aff Name: Glenn) Thanks guys for your replies. It works! So what data structure am I dealing with here? $data{$parent_group}{$aff_group}{$1}=$2; Best, James Also, I am not quite sure how to iterate through this structure and print its contents without using Dumper. Can anyone help? Thanks very much! James Hello James, To understand hash references, read the docs. the perldsc manpage This is a hash of hash of hash. One way to get the info could be: for my $parent (keys %data) { for my $group (keys %{ $data{$parent} }) { my $recs = $data{$parent}{$group}; while (my ($id, $name) = each %$recs) { print $parent - $group - $id - $name\n; } } } Chris Sent to klute by mistake. Here it is for the list. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Help needed created this data structure
Hi Chris, I did try coding this but I am afraid to confuse everyone with what I came up with so far. I can paste what I have if you feel that it would help. Here is the sample data: Affiliate Parent Group: Google - Affiliate Group: Google Advertiser -- Affiliate (Aff Id: 1, Aff Name: Frank) -- Affiliate (Aff Id: 2, Aff Name: Mary) - Affiliate Group: Google Publisher -- Affiliate (Aff Id: 3, Aff Name: Lori) -- Affiliate (Aff Id: 4, Aff Name: Mike) Affiliate Parent Group: Yahoo - Affiliate Group: Yahoo Advertiser -- Affiliate (Aff Id: 5, Aff Name: Marlene) -- Affiliate (Aff Id: 6, Aff Name: Larry) - Affiliate Group: Yahoo Publisher -- Affiliate (Aff Id: 7, Aff Name: Alex) -- Affiliate (Aff Id: 8, Aff Name: Glenn) Thanks again, James --- Chris Charley [EMAIL PROTECTED] wrote: - Original Message - From: klute [EMAIL PROTECTED] Newsgroups: perl.beginners To: beginners@perl.org Sent: Monday, July 09, 2007 4:20 PM Subject: Help needed created this data structure Hi All, I am new to Perl and was hoping to get advice on creating the following data structure: I have an Affiliate Parent Groups, Affiliate Groups, and Affiliates. Each affiliate has affiliateId, affiliateName. I guess what I'd like to have is an array of hashes where the array would contain Affiliate Parent Groups. Each item in the array would contain a hash map with Affiliate Group name as the key and An array of Affiliates (each having AffiliateId and AffiliateName) as the value. How would I go about creating such structure and adding values to it in a loop? Any help will be greatly appreciated! James Its hard to see what structure you want without some sample data. Send some data as it is in the file. Have you tried any coding yet? Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ Pinpoint customers who are looking for what you sell. http://searchmarketing.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Help needed created this data structure
klute am Montag, 9. Juli 2007 23:04: --- Chris Charley [EMAIL PROTECTED] wrote: - Original Message - From: klute [EMAIL PROTECTED] Newsgroups: perl.beginners To: beginners@perl.org Sent: Monday, July 09, 2007 4:20 PM Subject: Help needed created this data structure Hi All, I am new to Perl and was hoping to get advice on creating the following data structure: I have an Affiliate Parent Groups, Affiliate Groups, and Affiliates. Each affiliate has affiliateId, affiliateName. I guess what I'd like to have is an array of hashes where the array would contain Affiliate Parent Groups. Each item in the array would contain a hash map with Affiliate Group name as the key and An array of Affiliates (each having AffiliateId and AffiliateName) as the value. How would I go about creating such structure and adding values to it in a loop? Any help will be greatly appreciated! James Its hard to see what structure you want without some sample data. Send some data as it is in the file. Have you tried any coding yet? Chris Hi Chris, I did try coding this but I am afraid to confuse everyone with what I came up with so far. I can paste what I have if you feel that it would help. Here is the sample data: Affiliate Parent Group: Google - Affiliate Group: Google Advertiser -- Affiliate (Aff Id: 1, Aff Name: Frank) -- Affiliate (Aff Id: 2, Aff Name: Mary) - Affiliate Group: Google Publisher -- Affiliate (Aff Id: 3, Aff Name: Lori) -- Affiliate (Aff Id: 4, Aff Name: Mike) Affiliate Parent Group: Yahoo - Affiliate Group: Yahoo Advertiser -- Affiliate (Aff Id: 5, Aff Name: Marlene) -- Affiliate (Aff Id: 6, Aff Name: Larry) - Affiliate Group: Yahoo Publisher -- Affiliate (Aff Id: 7, Aff Name: Alex) -- Affiliate (Aff Id: 8, Aff Name: Glenn) Hello Klute (please don't top post to keep the conversation readable) The following script extracts the information out of your sample data. There are no checks if the data format is correct (nesting order, additional text). It does not result in an array of hashes, but in a single hash. Modify it if needed :-) Dani #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %data; # holds the current first and second level # my ($parent_group, $aff_group); while (DATA) { # a loop block, so we can use next { # skip blank lines /^\s*$/ and next; # record current first level /^A.*?: (.*)/ and $parent_group=$1 and next; # record current second level /^\s+-.*?: (.*)/ and $aff_group=$1 and next; # fill %data, with completed three levels /--.*?: (\d+).*?: (\w+)/ and $data{$parent_group}{$aff_group}{$1}=$2; } } print Data::Dumper::Dumper \%data; __DATA__ Affiliate Parent Group: Google - Affiliate Group: Google Advertiser -- Affiliate (Aff Id: 1, Aff Name: Frank) -- Affiliate (Aff Id: 2, Aff Name: Mary) - Affiliate Group: Google Publisher -- Affiliate (Aff Id: 3, Aff Name: Lori) -- Affiliate (Aff Id: 4, Aff Name: Mike) Affiliate Parent Group: Yahoo - Affiliate Group: Yahoo Advertiser -- Affiliate (Aff Id: 5, Aff Name: Marlene) -- Affiliate (Aff Id: 6, Aff Name: Larry) - Affiliate Group: Yahoo Publisher -- Affiliate (Aff Id: 7, Aff Name: Alex) -- Affiliate (Aff Id: 8, Aff Name: Glenn) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Help needed created this data structure
On Jul 9, 2:04 pm, [EMAIL PROTECTED] (Klute) wrote: Here is the sample data: That helps us provide a meaningful reply. Something like this will work, though you may want to make the regexp's a little more generalized: #!/usr/bin/perl use strict; my (%affiliate, $parent, $group); while (DATA) { /Affiliate Parent Group: (.*)\n/ and $parent = $1 and next; /Affiliate Group: (.*)\n/and $group = $1 and next; /Affiliate \(Aff Id: (\d+), Aff Name: (.*)\)/ and $affiliate{$parent}{$group}{$1} = $2; } print $affiliate{'Google'}{'Google Publisher'}{'3'}; #prints 'Lori' __DATA__ Affiliate Parent Group: Google - Affiliate Group: Google Advertiser -- Affiliate (Aff Id: 1, Aff Name: Frank) -- Affiliate (Aff Id: 2, Aff Name: Mary) - Affiliate Group: Google Publisher -- Affiliate (Aff Id: 3, Aff Name: Lori) -- Affiliate (Aff Id: 4, Aff Name: Mike) Affiliate Parent Group: Yahoo - Affiliate Group: Yahoo Advertiser -- Affiliate (Aff Id: 5, Aff Name: Marlene) -- Affiliate (Aff Id: 6, Aff Name: Larry) - Affiliate Group: Yahoo Publisher -- Affiliate (Aff Id: 7, Aff Name: Alex) -- Affiliate (Aff Id: 8, Aff Name: Glenn) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
help needed!!
oops sorry for the last mail...i pressed the enter button inadvertently. neways here is the problem... File1:example.txt ProbeNames Exp1Exp2Exp3Exp4Exp5 244901_at 24.346.437.419.559.6 244902_at 36.692.449.542.4 29.6 244903_at 46.419.4- 18.219.8 244904_at 56.229.478.437.8- ok Exp is the experiment name..Probes are under the ProbeNames and the digits are the signal values.. i want to find the average value for each Probe i.e each horizontal line.For ex:Avg value for 244901_at is so and so,avg value for 244902_at is so and so.. so what i did is took out the first line and the first column and used split on the values.My code is as follows: #!/usr/bin/perl -w $file1=mini.txt; $output1=output1.txt; open(FILE,$file1)or die Unable to open file; open(OT1,$output1)or die Unable to open file; $count=0; $totalcount=0; $total=0; while($line=FILE) #reading each line in the file. { chomp($line); if(!$count==0) { $line =~ s///g; #taking out the delimiters(Quotations) my @fields=split(/\t/,$line); #getting a list of values. foreach $fields(@fields) { if ($fields=~ m/_at/){} else { print OT1 $fields\n; } } } $count++; } close(FILE); close(OT1); --- what do i do next?? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: help needed!!
On 7/4/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: File1:example.txt ProbeNames Exp1Exp2Exp3Exp4Exp5 244901_at 24.346.437.419.559.6 244902_at 36.692.449.542.4 29.6 244903_at 46.419.4- 18.219.8 244904_at 56.229.478.437.8- i want to find the average value for each Probe i.e each horizontal line.For ex:Avg value for 244901_at is so and so,avg value for 244902_at is so and so.. It looks as if you're off to a good start; maybe you should use a pattern match to describe your data? # untested code my $datum = qr{[\d\-\.]+}; # or something better for your data my $ident = qr{\w+}; my $pattern = qr{ ^($ident)# $1 is identifier at start of line \s+# whitespace (# $2 is list of data items (?:$datum\s+)* # items before last item $datum# last item ) }x; # later, when you're ready to read from your data file while ($line = FILE) { next unless $line =~ /\S/; # skip blank lines if ($line =~ /$pattern/) { my($ident, $data) = ($1, $2); next if $ident eq 'ProbeNames'; # skip headings my @data = split /\s+/, $data; my $average = my_average(@data); # or whatever print Probe $ident reports average $average\n; # on your own from here } else { warn Unusable data found on line $. of file, continuing...\n; } } Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Help needed on font colour on the terminal.
hi all, i'm trying to display colourful font on the terminal of cmd.exe under Windows. but as i checked the documentation of TERM::ANSICOLOR, it seems to not work with cmd.exe under Windows OS... do you have any idea to make this happen? Thanks in advance. :) regards, remy
Re: Help needed on font colour on the terminal.
Guo Remy wrote: hi all, i'm trying to display colourful font on the terminal of cmd.exe under Windows. but as i checked the documentation of TERM::ANSICOLOR, it seems to not work with cmd.exe under Windows OS... do you have any idea to make this happen? Thanks in advance. :) Hi Remy The command.com 'command prompt' supports ANSI escape sequences if the ansi.sys driver is loaded, but the cmd.exe 'Windows console' doesn't. For this, take a look at Perl module Win32::Console::ANSI. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Help needed on font colour on the terminal.
Great! it's as easy as use ANSI in telnet BBS! :-D many thanks! 2006/9/30, Rob Dixon [EMAIL PROTECTED]: Guo Remy wrote: hi all, i'm trying to display colourful font on the terminal of cmd.exe under Windows. but as i checked the documentation of TERM::ANSICOLOR, it seems to not work with cmd.exe under Windows OS... do you have any idea to make this happen? Thanks in advance. :) Hi Remy The command.com 'command prompt' supports ANSI escape sequences if the ansi.sys driver is loaded, but the cmd.exe 'Windows console' doesn't. For this, take a look at Perl module Win32::Console::ANSI. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Help needed on font colour on the terminal.
Guo Remy wrote: Great! it's as easy as use ANSI in telnet BBS! :-D many thanks! Oh! the great BBS, never had a chance to see it myself. !..! thanks. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: regex help needed
On 9/27/06, Owen [EMAIL PROTECTED] wrote: On Wed, 27 Sep 2006 13:11:17 -0600 Gerald Wheeler [EMAIL PROTECTED] wrote: I am looking for: ab1in line1 and looking for: ab2 in line 2 actually ab1 and ab2 immediately follow the last / (there are numerous / on the line (w/o quotes)) These are not working. can some explain what these say and what they should say (syntax) to return the results I'm looking for: if ab1/ab2 are in the line, return true. /^[^\#]*ab1/,@lines /^[^\#]*ab2/,@lines Is there more to this code somewhere? This says match $_ against a pattern, ignore the result and return @lines. I doubt that's what you want. If you have warnings on, it should give you warnings like useless use of [something or other] and use of uninitialized value in pattern match (m//) at... Did you intend a grep or something similar there? Something like my @hits = grep /^[^\#]*ab1/, @lines might return a useful result. As for the patterns themselves, '^' means start looking at the beginning of the string. '[^\#]*' means look for zero or more characters in the class of all characters that aren't '\' or '#'. And 'ab1' means exactly that. Presumeably you want a match against '/ab1' In which case you might just get by with /\/ab1/ But you may need to provide a few more specifications and example data But that will match any ab1, not just the one after the last '/' If '/ab1' will always be the end of the string, or at least the end of a word, you could go for: /\ab1$/ or /\ab1\s/ That makes assumptions that may not be valid, though. we'd need to see data. Failing test data--or given unpredictable data--I'd go for something like: m{.*/ab1} $' !~ m{/} or m{/ab1[^/]*$} Although I'm sure someone will have a more efficient, or at least more elegant, approach. HTH, -- jay -- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org values of β will give rise to dom!
regex help needed
I am looking for: ab1in line1 and looking for: ab2 in line 2 actually ab1 and ab2 immediately follow the last / (there are numerous / on the line (w/o quotes)) These are not working. can some explain what these say and what they should say (syntax) to return the results I'm looking for: if ab1/ab2 are in the line, return true. /^[^\#]*ab1/,@lines /^[^\#]*ab2/,@lines Thanks -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: regex help needed
On Wed, 27 Sep 2006 13:11:17 -0600 Gerald Wheeler [EMAIL PROTECTED] wrote: I am looking for: ab1in line1 and looking for: ab2 in line 2 actually ab1 and ab2 immediately follow the last / (there are numerous / on the line (w/o quotes)) These are not working. can some explain what these say and what they should say (syntax) to return the results I'm looking for: if ab1/ab2 are in the line, return true. /^[^\#]*ab1/,@lines /^[^\#]*ab2/,@lines Presumeably you want a match against '/ab1' In which case you might just get by with /\/ab1/ But you may need to provide a few more specifications and example data Owen -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Help needed to Execute CGI on a Apache Server?
Hello, This is my first mail to the group. Let me introduce myself. I am Deep, currently working as a Tech Support Engineer in India. I am new to Perl and CGI.I have a few questions regarding the configuration of Apache Server on a Windows 2000 Server? I faced the following issues when I was trying to run a cgi-program on my apache server. 1. First of all, I have configured the Virtual Host as projects.perlpro.com and set the IP address as 10.10.10.1. I have already edited the Hosts file in C:\winnt\system32\drivers\etc. 2. I have also created a folder in D:drive and set the following path: D:/projects/perlpro. I have given full access to everyone to run the script. I have created two folders inside the same folder perlpro and named as cgibin and htdocs. i have kept all my cgi scripts in cgi-bin folder and all the html files in htdocs. However, when I tried to access the webpage, it's displaying the first page, which contains the html document, however it gives me an error message Access denied, http error 500/404. I am the administrator of my PC and I am unable to configure that. Could anyone please send me the configuration file(httpd.conf) to me so that I can configure the same and run my CGI-scripts on my local PC? Waiting for a quick reply. Warm regards, Deep. FREE 2GB Online Storage - Store data online access them anywhere you go! Visit http://www.inbox.com/storage to find out more! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Help Needed
Hello folks I am thinking to built port scanner in perl. for port scanning I am using SYN packet. Can any body suggest some online document or mannuals for this. with regards Rakesh