Re: trouble
Hi Mike, The email header tells me this was sent a week ago :-) Has this been resolved? Andrew On Thu, Jul 4, 2019 at 3:21 AM Mike Flannigan wrote: > > I am having trouble posting to the Beginners > Perl list. Is there a problem? > > > I understand that to upload a module to CPAN is need > to obtain a PAUSE account. I have tried twice to get > that, but I don't receive an e-mail with a password. > > http://www.mflan.com/temp/pause.jpg > > If anybody can notify the PAUSE people that the PAUSE > program appears to be broke, please do. > > > > Mike > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > > -- Andrew Solomon Director P: +44 7931 946 062 E: and...@geekuni.com
trouble
I am having trouble posting to the Beginners Perl list. Is there a problem? I understand that to upload a module to CPAN is need to obtain a PAUSE account. I have tried twice to get that, but I don't receive an e-mail with a password. http://www.mflan.com/temp/pause.jpg If anybody can notify the PAUSE people that the PAUSE program appears to be broke, please do. Mike -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: having trouble understanding the built-in Perl sort with regards to mixed numbers and strings
On Fri, 17 Jun 2016 14:33:12 -0700 Kenneth Wolcott <kennethwolc...@gmail.com> wrote: > Hi; > > I'm having trouble understanding the built-in Perl sort with regards > to mixed numbers and strings > > I'm looking at http://perldoc.perl.org/functions/sort.html > > I have an array that I want to have sorted numerically and > descending. [...] > What I did as a workaround was to implement my own extremely > brute-force sort routine, which works, but is very ugly. [...] > I'd rather that my code be correct, intuitive and elegant (and > efficient). Personally, I'd skip Perl's built-in sort for this and look at using Sort::Naturally - it handles just this case cleanly and simply, and will leave your code readable. e.g.: my @strings = ( '999 zzz', '111 zzz', '111 aaa', '999 aaa', ); print join "\n", Sort::Naturally::nsort @strings; ... would get you the output I think you want, i.e.: 111 aaa 111 zzz 999 aaa 999 zzz -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: having trouble understanding the built-in Perl sort with regards to mixed numbers and strings
On Mon, Jun 20, 2016 at 10:40 AM, Shlomi Fishwrote: > Hi Chris, > > On Mon, 20 Jun 2016 11:28:57 -0600 > Chris Fedde wrote: > >> Kenneth, >> >> Below the cut is my example implementation as I understand your >> requirements. >> Note that the "compare" routine uses $a and $b which are "special" to perl >> sort routines. >> Also the compare routine is written for obviousness rather than for brevity >> or elegance. >> >> The return from compare illustrates Shalomi Fish's point about using the >> "||" operator to compose sort fields. >> Descending numeric order is done by reversing the comparison on that sub >> field. >> > > Thanks for the illustrative example! I was too lazy to write one. > > Regards, > > Shlomi Fish > > >> chris >> >> - cut - >> #!/usr/env/bin perl >> >> use strict; >> use warnings; >> >> my @x = ; >> >> sub compare { >> my @a = split(/\t/, $a); >> my @b = split(/\t/, $b); >> return $b[0] <=> $a[0] || $a[1] cmp $b[1] >> } >> >> print for (sort {compare} @x); >> >> __DATA__ >> 9500 ohzaew >> 5300 dohpha >> 0700 liemah >> 1700 phuhei >> 0200 phuowo >> 1300 ojaeng >> 3900 aebaat >> 4200 dohgha >> 4200 aiyiej >> 6300 ojaeng >> 1600 haequa >> 3100 hupiez >> 3200 ahrieb >> 3600 ohzaew >> 5300 queebe >> 2000 oeyael >> 0200 hahwoo >> 9900 shahye >> 9300 johhir >> 6400 shahye >> 4500 ohfici >> 5500 ahngoh >> 7300 aibove >> 8200 ahrieb >> 9100 ohzaew >> 3100 ohzaew >> 2800 gahnoh >> 0800 aedeng >> 8400 oowaih >> 0300 vouroh >> 1400 shahye >> 0500 ciejee >> 0500 uanahp >> 2100 ophuum >> 1500 aideev >> 6900 aegeuw >> 6300 haequa >> 9300 queebe >> 5400 reogai >> 5000 ophuum >> 1700 aebaat >> 1600 eshida >> 3700 beidae >> 5200 quieki >> 6800 eashoo >> 6800 ohweba >> 2300 apahqu >> 8100 ahghee >> 6700 jooxoj >> 3500 yeiboo >> 2800 chuema Thank you so much! Now I've got to study this and experiment until it becomes natural. Meanwhile, I studied what was on line 43 of the perldoc sort page and decided to try to use that and modify it. I took out the equals sign and then I took out the second stanza. It seems to work: @sorted_summary_detail = sort {($b =~ /(\d+)/)[0] <=> ($a =~ /(\d+)/)[0]} @summary_detail; Again, thank you; I have to study this. Ken Wolcott -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: having trouble understanding the built-in Perl sort with regards to mixed numbers and strings
Hi Chris, On Mon, 20 Jun 2016 11:28:57 -0600 Chris Fedde <ch...@fedde.us> wrote: > Kenneth, > > Below the cut is my example implementation as I understand your > requirements. > Note that the "compare" routine uses $a and $b which are "special" to perl > sort routines. > Also the compare routine is written for obviousness rather than for brevity > or elegance. > > The return from compare illustrates Shalomi Fish's point about using the > "||" operator to compose sort fields. > Descending numeric order is done by reversing the comparison on that sub > field. > Thanks for the illustrative example! I was too lazy to write one. Regards, Shlomi Fish > chris > > - cut - > #!/usr/env/bin perl > > use strict; > use warnings; > > my @x = ; > > sub compare { > my @a = split(/\t/, $a); > my @b = split(/\t/, $b); > return $b[0] <=> $a[0] || $a[1] cmp $b[1] > } > > print for (sort {compare} @x); > > __DATA__ > 9500 ohzaew > 5300 dohpha > 0700 liemah > 1700 phuhei > 0200 phuowo > 1300 ojaeng > 3900 aebaat > 4200 dohgha > 4200 aiyiej > 6300 ojaeng > 1600 haequa > 3100 hupiez > 3200 ahrieb > 3600 ohzaew > 5300 queebe > 2000 oeyael > 0200 hahwoo > 9900 shahye > 9300 johhir > 6400 shahye > 4500 ohfici > 5500 ahngoh > 7300 aibove > 8200 ahrieb > 9100 ohzaew > 3100 ohzaew > 2800 gahnoh > 0800 aedeng > 8400 oowaih > 0300 vouroh > 1400 shahye > 0500 ciejee > 0500 uanahp > 2100 ophuum > 1500 aideev > 6900 aegeuw > 6300 haequa > 9300 queebe > 5400 reogai > 5000 ophuum > 1700 aebaat > 1600 eshida > 3700 beidae > 5200 quieki > 6800 eashoo > 6800 ohweba > 2300 apahqu > 8100 ahghee > 6700 jooxoj > 3500 yeiboo > 2800 chuema > > > On Fri, Jun 17, 2016 at 3:41 PM, Kenneth Wolcott <kennethwolc...@gmail.com> > wrote: > > > On Fri, Jun 17, 2016 at 2:33 PM, Kenneth Wolcott > > <kennethwolc...@gmail.com> wrote: > > > Hi; > > > > > > I'm having trouble understanding the built-in Perl sort with regards > > > to mixed numbers and strings > > > > > > I'm looking at http://perldoc.perl.org/functions/sort.html > > > > > > I have an array that I want to have sorted numerically and descending. > > > > > > The array is composed of elements that look like the following regex: > > > > > > ^\d+\t\[a-zA-Z0-9]+$ > > > > > > I always have "use strict" at the top of my Perl scripts. > > > > > > If I try: > > > > > > my @articles = sort {$b <=> $a} @files; > > > > > > I get error(s)/warning(s) that the data is not numeric. > > > > > > if I try: > > > > > > my @articles = sort {$b cmp $a} @files; > > > > > > I will get numbers sorted as letters, not numerically. > > > > > > I tried to understand the sort perldoc page further down, but did > > > not grok it at all. > > > > > > What I did as a workaround was to implement my own extremely > > > brute-force sort routine, which works, but is very ugly. > > > > > > Since I have very few elements (perhaps as many as a couple dozen), > > > the inefficiency is immaterial. > > > > > > I'd rather that my code be correct, intuitive and elegant (and > > efficient). > > > > > > Thanks, > > > Ken Wolcott > > > > Addendum: > > > > It appears that when the sequence of digits is the same length in all > > instances that the data will be sorted correctly, but when the length > > of the sequence of the digits is not the same in the entire data set, > > that is when the sort results will be incorrect. > > > > My most current data with this reverse character sort mechanism works > > correctly, but I'd like it to work in all cases. > > > > -- > > 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: having trouble understanding the built-in Perl sort with regards to mixed numbers and strings
Kenneth, Below the cut is my example implementation as I understand your requirements. Note that the "compare" routine uses $a and $b which are "special" to perl sort routines. Also the compare routine is written for obviousness rather than for brevity or elegance. The return from compare illustrates Shalomi Fish's point about using the "||" operator to compose sort fields. Descending numeric order is done by reversing the comparison on that sub field. chris - cut - #!/usr/env/bin perl use strict; use warnings; my @x = ; sub compare { my @a = split(/\t/, $a); my @b = split(/\t/, $b); return $b[0] <=> $a[0] || $a[1] cmp $b[1] } print for (sort {compare} @x); __DATA__ 9500 ohzaew 5300 dohpha 0700 liemah 1700 phuhei 0200 phuowo 1300 ojaeng 3900 aebaat 4200 dohgha 4200 aiyiej 6300 ojaeng 1600 haequa 3100 hupiez 3200 ahrieb 3600 ohzaew 5300 queebe 2000 oeyael 0200 hahwoo 9900 shahye 9300 johhir 6400 shahye 4500 ohfici 5500 ahngoh 7300 aibove 8200 ahrieb 9100 ohzaew 3100 ohzaew 2800 gahnoh 0800 aedeng 8400 oowaih 0300 vouroh 1400 shahye 0500 ciejee 0500 uanahp 2100 ophuum 1500 aideev 6900 aegeuw 6300 haequa 9300 queebe 5400 reogai 5000 ophuum 1700 aebaat 1600 eshida 3700 beidae 5200 quieki 6800 eashoo 6800 ohweba 2300 apahqu 8100 ahghee 6700 jooxoj 3500 yeiboo 2800 chuema On Fri, Jun 17, 2016 at 3:41 PM, Kenneth Wolcott <kennethwolc...@gmail.com> wrote: > On Fri, Jun 17, 2016 at 2:33 PM, Kenneth Wolcott > <kennethwolc...@gmail.com> wrote: > > Hi; > > > > I'm having trouble understanding the built-in Perl sort with regards > > to mixed numbers and strings > > > > I'm looking at http://perldoc.perl.org/functions/sort.html > > > > I have an array that I want to have sorted numerically and descending. > > > > The array is composed of elements that look like the following regex: > > > > ^\d+\t\[a-zA-Z0-9]+$ > > > > I always have "use strict" at the top of my Perl scripts. > > > > If I try: > > > > my @articles = sort {$b <=> $a} @files; > > > > I get error(s)/warning(s) that the data is not numeric. > > > > if I try: > > > > my @articles = sort {$b cmp $a} @files; > > > > I will get numbers sorted as letters, not numerically. > > > > I tried to understand the sort perldoc page further down, but did > > not grok it at all. > > > > What I did as a workaround was to implement my own extremely > > brute-force sort routine, which works, but is very ugly. > > > > Since I have very few elements (perhaps as many as a couple dozen), > > the inefficiency is immaterial. > > > > I'd rather that my code be correct, intuitive and elegant (and > efficient). > > > > Thanks, > > Ken Wolcott > > Addendum: > > It appears that when the sequence of digits is the same length in all > instances that the data will be sorted correctly, but when the length > of the sequence of the digits is not the same in the entire data set, > that is when the sort results will be incorrect. > > My most current data with this reverse character sort mechanism works > correctly, but I'd like it to work in all cases. > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > >
Re: having trouble understanding the built-in Perl sort with regards to mixed numbers and strings
Hi Kenneth, On Fri, 17 Jun 2016 14:41:41 -0700 Kenneth Wolcott <kennethwolc...@gmail.com> wrote: > On Fri, Jun 17, 2016 at 2:33 PM, Kenneth Wolcott > <kennethwolc...@gmail.com> wrote: > > Hi; > > > > I'm having trouble understanding the built-in Perl sort with regards > > to mixed numbers and strings > > > > I'm looking at http://perldoc.perl.org/functions/sort.html > > > > I have an array that I want to have sorted numerically and descending. > > > > The array is composed of elements that look like the following regex: > > > > ^\d+\t\[a-zA-Z0-9]+$ > > > > I always have "use strict" at the top of my Perl scripts. > > > > If I try: > > > > my @articles = sort {$b <=> $a} @files; > > > > I get error(s)/warning(s) that the data is not numeric. > > > > if I try: > > > > my @articles = sort {$b cmp $a} @files; You can chain several comparator clauses using the "||" or "or" operators. See: http://perl-begin.org/tutorials/perl-for-newbies/part4/#page--and_or--DIR Perhaps use the Schwartzian transform in this case and then do that: https://en.wikipedia.org/wiki/Schwartzian_transform Regards, Shlomi Fish -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: having trouble understanding the built-in Perl sort with regards to mixed numbers and strings
In this very particular case you should consider turning off the warning, maybe limiting it to the block. On Jun 17, 2016 5:42 PM, "Kenneth Wolcott" <kennethwolc...@gmail.com> wrote: > On Fri, Jun 17, 2016 at 2:33 PM, Kenneth Wolcott > <kennethwolc...@gmail.com> wrote: > > Hi; > > > > I'm having trouble understanding the built-in Perl sort with regards > > to mixed numbers and strings > > > > I'm looking at http://perldoc.perl.org/functions/sort.html > > > > I have an array that I want to have sorted numerically and descending. > > > > The array is composed of elements that look like the following regex: > > > > ^\d+\t\[a-zA-Z0-9]+$ > > > > I always have "use strict" at the top of my Perl scripts. > > > > If I try: > > > > my @articles = sort {$b <=> $a} @files; > > > > I get error(s)/warning(s) that the data is not numeric. > > > > if I try: > > > > my @articles = sort {$b cmp $a} @files; > > > > I will get numbers sorted as letters, not numerically. > > > > I tried to understand the sort perldoc page further down, but did > > not grok it at all. > > > > What I did as a workaround was to implement my own extremely > > brute-force sort routine, which works, but is very ugly. > > > > Since I have very few elements (perhaps as many as a couple dozen), > > the inefficiency is immaterial. > > > > I'd rather that my code be correct, intuitive and elegant (and > efficient). > > > > Thanks, > > Ken Wolcott > > Addendum: > > It appears that when the sequence of digits is the same length in all > instances that the data will be sorted correctly, but when the length > of the sequence of the digits is not the same in the entire data set, > that is when the sort results will be incorrect. > > My most current data with this reverse character sort mechanism works > correctly, but I'd like it to work in all cases. > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > >
Re: having trouble understanding the built-in Perl sort with regards to mixed numbers and strings
If you want to sort your data numerically, then the data must look like a number. Your data is mixed numerical and alpha data, hence the error message. You first need to extract the numerical parts of your data records and compare just those parts. The first step would be to write a sort routine that extracts the numerical parts of the two key variables $a and $b, e.g., $anum and $bnum, and returns the value of the expression $anum <=> $bnum ( or $bnum <=> $anum if you want to reverse the order). That is not the most efficient way to solve this problem, as you are extracting the numerical parts more often than necessary, but it is a start. Try that and let us know if you want more help. Once you get that working, you can write a Schwartzian transform that will extract the numerical values only once for each record. > On Jun 17, 2016, at 2:41 PM, Kenneth Wolcott <kennethwolc...@gmail.com> wrote: > > On Fri, Jun 17, 2016 at 2:33 PM, Kenneth Wolcott > <kennethwolc...@gmail.com> wrote: >> Hi; >> >> I'm having trouble understanding the built-in Perl sort with regards >> to mixed numbers and strings >> >> I'm looking at http://perldoc.perl.org/functions/sort.html >> >> I have an array that I want to have sorted numerically and descending. >> >> The array is composed of elements that look like the following regex: >> >> ^\d+\t\[a-zA-Z0-9]+$ >> >> I always have "use strict" at the top of my Perl scripts. >> >> If I try: >> >>my @articles = sort {$b <=> $a} @files; >> >> I get error(s)/warning(s) that the data is not numeric. >> >> if I try: >> >> my @articles = sort {$b cmp $a} @files; >> >> I will get numbers sorted as letters, not numerically. >> >> I tried to understand the sort perldoc page further down, but did >> not grok it at all. >> >> What I did as a workaround was to implement my own extremely >> brute-force sort routine, which works, but is very ugly. >> >> Since I have very few elements (perhaps as many as a couple dozen), >> the inefficiency is immaterial. >> >> I'd rather that my code be correct, intuitive and elegant (and efficient). >> >> Thanks, >> Ken Wolcott > > Addendum: > > It appears that when the sequence of digits is the same length in all > instances that the data will be sorted correctly, but when the length > of the sequence of the digits is not the same in the entire data set, > that is when the sort results will be incorrect. > > My most current data with this reverse character sort mechanism works > correctly, but I'd like it to work in all cases. > > -- > 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: having trouble understanding the built-in Perl sort with regards to mixed numbers and strings
On Fri, Jun 17, 2016 at 2:33 PM, Kenneth Wolcott <kennethwolc...@gmail.com> wrote: > Hi; > > I'm having trouble understanding the built-in Perl sort with regards > to mixed numbers and strings > > I'm looking at http://perldoc.perl.org/functions/sort.html > > I have an array that I want to have sorted numerically and descending. > > The array is composed of elements that look like the following regex: > > ^\d+\t\[a-zA-Z0-9]+$ > > I always have "use strict" at the top of my Perl scripts. > > If I try: > > my @articles = sort {$b <=> $a} @files; > > I get error(s)/warning(s) that the data is not numeric. > > if I try: > > my @articles = sort {$b cmp $a} @files; > > I will get numbers sorted as letters, not numerically. > > I tried to understand the sort perldoc page further down, but did > not grok it at all. > > What I did as a workaround was to implement my own extremely > brute-force sort routine, which works, but is very ugly. > > Since I have very few elements (perhaps as many as a couple dozen), > the inefficiency is immaterial. > > I'd rather that my code be correct, intuitive and elegant (and efficient). > > Thanks, > Ken Wolcott Addendum: It appears that when the sequence of digits is the same length in all instances that the data will be sorted correctly, but when the length of the sequence of the digits is not the same in the entire data set, that is when the sort results will be incorrect. My most current data with this reverse character sort mechanism works correctly, but I'd like it to work in all cases. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
having trouble understanding the built-in Perl sort with regards to mixed numbers and strings
Hi; I'm having trouble understanding the built-in Perl sort with regards to mixed numbers and strings I'm looking at http://perldoc.perl.org/functions/sort.html I have an array that I want to have sorted numerically and descending. The array is composed of elements that look like the following regex: ^\d+\t\[a-zA-Z0-9]+$ I always have "use strict" at the top of my Perl scripts. If I try: my @articles = sort {$b <=> $a} @files; I get error(s)/warning(s) that the data is not numeric. if I try: my @articles = sort {$b cmp $a} @files; I will get numbers sorted as letters, not numerically. I tried to understand the sort perldoc page further down, but did not grok it at all. What I did as a workaround was to implement my own extremely brute-force sort routine, which works, but is very ugly. Since I have very few elements (perhaps as many as a couple dozen), the inefficiency is immaterial. I'd rather that my code be correct, intuitive and elegant (and efficient). Thanks, Ken Wolcott -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Search and replace trouble with a variable
Hello List: I am trying to go through a folder of php scripts to add a database prefix to lines that have a select statement. Since the database prefix will differ, I am simply trying to add: .$database_prefix. to those lines. For example, instead of the line looking like: $sql = SELECT * FROM bs_services; I need to have it look like: $sql = SELECT * FROM .$database_prefix._bs_services; I have tried a variety of Perl examples including the the code below, but it gives an error. $_ =~ s/bs_/.$database_prefix._bs/g; Can anyone give me some help on this? Maybe it's due to looking at php code all day but I would really like to get this done before going to bed. It's already 3:40 AM here but oh well... Any help is appreciated! --
Re: Search and replace trouble with a variable
What error? (Sent from iPhone, so please accept my apologies in advance for any spelling or grammatical errors.) On Feb 1, 2014, at 2:40 AM, Omega -1911 1911...@gmail.com wrote: Hello List: I am trying to go through a folder of php scripts to add a database prefix to lines that have a select statement. Since the database prefix will differ, I am simply trying to add: .$database_prefix. to those lines. For example, instead of the line looking like: $sql = SELECT * FROM bs_services; I need to have it look like: $sql = SELECT * FROM .$database_prefix._bs_services; I have tried a variety of Perl examples including the the code below, but it gives an error. $_ =~ s/bs_/.$database_prefix._bs/g; Can anyone give me some help on this? Maybe it's due to looking at php code all day but I would really like to get this done before going to bed. It's already 3:40 AM here but oh well... Any help is appreciated! -- -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Search and replace trouble with a variable
Hi Omega, On Sat, 1 Feb 2014 03:40:01 -0500 Omega -1911 1911...@gmail.com wrote: Hello List: I am trying to go through a folder of php scripts to add a database prefix to lines that have a select statement. Since the database prefix will differ, I am simply trying to add: .$database_prefix. to those lines. For example, instead of the line looking like: $sql = SELECT * FROM bs_services; I need to have it look like: $sql = SELECT * FROM .$database_prefix._bs_services; I have tried a variety of Perl examples including the the code below, but it gives an error. $_ =~ s/bs_/.$database_prefix._bs/g; It appears that the right hand side of the s/// operation will try to interpolate «$database_prefix» as a variable. What you need is to escape the «$» using «\$»: [SHELL] shlomif@telaviv1:~$ cat Test.pl #!/usr/bin/perl use strict; use warnings; while() { $_ =~ s/bs_/.\$database_prefix._bs/g; print $_; } shlomif@telaviv1:~$ perl Test.pl $sql = SELECT * FROM bs_services; $sql = SELECT * FROM .$database_prefix._bsservices; shlomif@telaviv1:~$ [/END OF SHELL] A few notes: 1. It's not a good idea to overuse $_: http://perl-begin.org/tutorials/bad-elements/#overuse_dollar_underscore 2. «$_ =~ s///;» can simply be written as «s///» with the implicit $_ variable. Regards, Shlomi Fish Can anyone give me some help on this? Maybe it's due to looking at php code all day but I would really like to get this done before going to bed. It's already 3:40 AM here but oh well... Any help is appreciated! -- -- - Shlomi Fish http://www.shlomifish.org/ Selina Mandrake - The Slayer (Buffy parody) - http://shlom.in/selina Only dead fish go with the flow. — via Nadav Har’El 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/
Re: Search and replace trouble with a variable
On Sat, Feb 1, 2014 at 4:57 AM, Shlomi Fish shlo...@shlomifish.org wrote: Hi Omega, On Sat, 1 Feb 2014 03:40:01 -0500 Omega -1911 1911...@gmail.com wrote: Hello List: I am trying to go through a folder of php scripts to add a database prefix to lines that have a select statement. Since the database prefix will differ, I am simply trying to add: .$database_prefix. to those lines. For example, instead of the line looking like: $sql = SELECT * FROM bs_services; I need to have it look like: $sql = SELECT * FROM .$database_prefix._bs_services; I have tried a variety of Perl examples including the the code below, but it gives an error. $_ =~ s/bs_/.$database_prefix._bs/g; It appears that the right hand side of the s/// operation will try to interpolate «$database_prefix» as a variable. What you need is to escape the «$» using «\$»: [SHELL] shlomif@telaviv1:~$ cat Test.pl #!/usr/bin/perl use strict; use warnings; while() { $_ =~ s/bs_/.\$database_prefix._bs/g; print $_; } shlomif@telaviv1:~$ perl Test.pl $sql = SELECT * FROM bs_services; $sql = SELECT * FROM .$database_prefix._bsservices; shlomif@telaviv1:~$ [/END OF SHELL] A few notes: 1. It's not a good idea to overuse $_: http://perl-begin.org/tutorials/bad-elements/#overuse_dollar_underscore 2. «$_ =~ s///;» can simply be written as «s///» with the implicit $_ variable. Regards, Shlomi Fish -- Good advice Shlomi. Thank you again. I should have caught that with fresh eyes!
Re: Search and replace trouble with a variable
Hi Omega, On Sat, 1 Feb 2014 11:36:20 -0500 Omega -1911 1911...@gmail.com wrote: Good advice Shlomi. Thank you again. I should have caught that with fresh eyes! You're welcome! ☺ Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ First stop for Perl beginners - http://perl-begin.org/ Jessica on the phone: Sel, you’re getting strange lately, but you are becoming more amusing in the process. — http://www.shlomifish.org/humour/Selina-Mandrake/ 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/
Re: ASCII/binary endline character trouble
Thanks everyone. I came up with a nifty solution. It occurred to me that Perl doesn't need endline characters. Those semicolons do the trick. Here I am trying to put in those silly rectangles (ASCII character number 10) when I didn't even need them. Actually I need one, after the first line #!/usr/bin/perl as that has no semicolon. There I just cut and paste a 'silly rectangle' from a working script. (I knew I could have cut and pasted all along, but it's far too tedious to do for every line, and if I should mess up just one instance...) Fred --- On Tue, 3/27/12, Rob Dixon rob.di...@gmx.com wrote: From: Rob Dixon rob.di...@gmx.com Subject: Re: ASCII/binary endline character trouble To: beginners@perl.org Cc: hOURS h_o...@yahoo.com Date: Tuesday, March 27, 2012, 3:51 AM On 25/03/2012 23:45, hOURS wrote: I write CGI scripts for my website in PERL. When I used to upload them with my FTP program I made sure to do so in ASCII mode rather than binary. My host made me switch to sFTP however. I use FIlezilla, and can't for the life of me find out how to choose the mode on that. Unfortunately, binary is the default mode. I don't like programming when the file displays ASCII endline characters. I'd rather see clear, distinct lines rather than one long line broken up with those vertical rectangles. When I download a script from my site for editing it looks terrible. So I wrote a little program to fix that: open (NEW, 'niceviewscript.pl') or die Couldn't open file for writing; open (FILE, 'script.pl') or die Couldn't open file for reading; while (FILE) { $line = $_; chomp($line); print NEW $line\n; } close (FILE); close (NEW); It works great. How do I get it to go in reverse though so it will work when I upload it? I figured out that the ASCII number for those vertical rectangles that represent line breaks was 10. So I tried: $sillyrectangle = chr(10); open (NEW, 'workingscript.pl') or die Couldn't open file for writing; open (FILE, 'niceviewscript.pl') or die Couldn't open file; while (FILE) { $line = $_; chomp($line); $withnewend = $line . $sillyrectangle; print NEW $withnewend; } close (FILE); close (NEW); Why doesn't this work? The newly created file looks just like the old one. Now, if anyone can tell me how to upload in ASCII mode (assuming that's even possible) that will solve my problem even better of course. But now I'm curious as to why my program for switching back doesn't work. The problem is that the Unix standard is to terminate lines with a linefeed (LF) character. This is the chr(10) that you are seeing. Meanwhile Windows terminates lines with the /two/ characters carriage-return linefeed (CRLF) which would be chr(13).chr(10). The terminators in a file must be changed when it is moved from one type of system to another, and FTP's ASCII mode did this automatically for you. A quick Google tells me that SFTP supports only binary mode, but an ASCII mode like FTP's is planned for the future. So you have to do the conversion separately if you are using SFTP. Perl's PerlIO layers (http://perldoc.perl.org/PerlIO.html) will allow you to specify the format of the file when you open it so you can write a Perl program to do the conversion. Historically the programs to do this have been ux2dos and dos2ux. Below is ux2dos.pl which you can use as ux2dos.pl unix.txt dos.txt and the corresponding dos2ux.pl should be obvious. I hope this helps. Please come back if you have any questions. Rob use strict; use warnings; open my $fh, ':unix', $ARGV[0] or die $!; binmode STDOUT, ':crlf'; print while $fh;
Re: ASCII/binary endline character trouble
Hi Fred, On Mon, Mar 26, 2012 at 11:50 PM, hOURS h_o...@yahoo.com wrote: Thanks. I do see the Transfer Type option under the Transfer menu, but it's grayed out and I can't use it. I don't know the version of FileZilla you have, but I believe you could download a new one for use. I use version 3.5.1, I think the recent one is 3.5.3. Please google it. I also tried modifying the first line of my code. Instead of using the ASCII value and the chr function, I cut and pasted the vertical rectangle. So the line became: $sillyrectangle = ; (with said rectangle between the quotemarks - it won't show up in this e-mail) Needless to say, that didn't work either. Please, allow me to think aloud, since we couldn't get how this vertical rectangle character looks like (or your input file) maybe you could use both ord and chr functions in Perl to *pick* each word or character (as the case maybe) in your while loop used for reading the original file you downloaded from your site. This could give you the numeric value, you can use for your $sillyrectangle using chr function. However, you must note that ord function will only return the numeric value of first *character* of your EXP, in case you try using word on the function. lastly, I don't know if it works perfectly for you. You could also look into unpack and pack functions, using B* Template for conversion; like: while(){ print unpack B*,$_; ## output in binary files and pack reverses } I hope any of this suggestions helps. But really if you ask me I will say, download and do a fresh installation of FileZilla. Fred --- On Sun, 3/25/12, timothy adigun 2teezp...@gmail.com wrote: From: timothy adigun 2teezp...@gmail.com Subject: Re: ASCII/binary endline character trouble To: hOURS h_o...@yahoo.com Cc: Perl Beginners beginners@perl.org, perl-begin...@yahoogroups.com Date: Sunday, March 25, 2012, 9:35 PM Hi Fred, Please, check my comments and possible solution within your mail. On Sun, Mar 25, 2012 at 11:45 PM, hOURS h_o...@yahoo.com wrote: Hello all, I write CGI scripts for my website in PERL. When I used to upload them with my FTP The programming language is Perl not PERL. program I made sure to do so in ASCII mode rather than binary. My host made me switch to sFTP however. I use FIlezilla, and can't for the life of me find out how to choose the mode on that. Unfortunately, binary is the default mode. I don't like programming when the file displays ASCII endline characters. I'd rather see clear, distinct lines rather than one long line broken up with those vertical rectangles. When I download a script from my site for editing it looks terrible. So I wrote a little program to fix that: open (NEW, 'niceviewscript.pl') or die Couldn't open file for writing; I think is better to use open() three arguments like: open(my $fh,,'niceviewscript.pl') or die Couldn't open file for writing: $!; open (FILE, 'script.pl') or die Couldn't open file for reading; ## same thing here too while (FILE) { $line = $_; chomp($line); print NEW $line\n; } close (FILE); ## close($fh) or die can't close file:$!; close (NEW); It works great. How do I get it to go in reverse though so it will work when I upload it? I figured out that the ASCII number for those vertical rectangles that represent line breaks was 10. So I tried: $sillyrectangle = chr(10); open (NEW, 'workingscript.pl') or die Couldn't open file for writing; ## same as above open (FILE, 'niceviewscript.pl') or die Couldn't open file; ## same thing here while (FILE) { $line = $_; chomp($line); $withnewend = $line . $sillyrectangle; print NEW $withnewend; } close (FILE); close (NEW); Why doesn't this work? The newly created file looks just like the old one. Now, if anyone can tell me how to upload in ASCII mode (assuming that's even possible) that Possible Solution: Launch your FileZilla Program, click on the menu bar Transfer menu, then check your sub-menu bar Transfer type, you should be able to change, your mode. I preferred to leave mine as Auto! will solve my problem even better of course. But now I'm curious as to why my program for switching back doesn't work. Thank you! Fred -- Tim -- Tim
Re: ASCII/binary endline character trouble
On 25/03/2012 23:45, hOURS wrote: I write CGI scripts for my website in PERL. When I used to upload them with my FTP program I made sure to do so in ASCII mode rather than binary. My host made me switch to sFTP however. I use FIlezilla, and can't for the life of me find out how to choose the mode on that. Unfortunately, binary is the default mode. I don't like programming when the file displays ASCII endline characters. I'd rather see clear, distinct lines rather than one long line broken up with those vertical rectangles. When I download a script from my site for editing it looks terrible. So I wrote a little program to fix that: open (NEW, 'niceviewscript.pl') or die Couldn't open file for writing; open (FILE, 'script.pl') or die Couldn't open file for reading; while (FILE) { $line = $_; chomp($line); print NEW $line\n; } close (FILE); close (NEW); It works great. How do I get it to go in reverse though so it will work when I upload it? I figured out that the ASCII number for those vertical rectangles that represent line breaks was 10. So I tried: $sillyrectangle = chr(10); open (NEW, 'workingscript.pl') or die Couldn't open file for writing; open (FILE, 'niceviewscript.pl') or die Couldn't open file; while (FILE) { $line = $_; chomp($line); $withnewend = $line . $sillyrectangle; print NEW $withnewend; } close (FILE); close (NEW); Why doesn't this work? The newly created file looks just like the old one. Now, if anyone can tell me how to upload in ASCII mode (assuming that's even possible) that will solve my problem even better of course. But now I'm curious as to why my program for switching back doesn't work. The problem is that the Unix standard is to terminate lines with a linefeed (LF) character. This is the chr(10) that you are seeing. Meanwhile Windows terminates lines with the /two/ characters carriage-return linefeed (CRLF) which would be chr(13).chr(10). The terminators in a file must be changed when it is moved from one type of system to another, and FTP's ASCII mode did this automatically for you. A quick Google tells me that SFTP supports only binary mode, but an ASCII mode like FTP's is planned for the future. So you have to do the conversion separately if you are using SFTP. Perl's PerlIO layers (http://perldoc.perl.org/PerlIO.html) will allow you to specify the format of the file when you open it so you can write a Perl program to do the conversion. Historically the programs to do this have been ux2dos and dos2ux. Below is ux2dos.pl which you can use as ux2dos.pl unix.txt dos.txt and the corresponding dos2ux.pl should be obvious. I hope this helps. Please come back if you have any questions. Rob use strict; use warnings; open my $fh, ':unix', $ARGV[0] or die $!; binmode STDOUT, ':crlf'; print while $fh; -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: ASCII/binary endline character trouble
Date sent: Sun, 25 Mar 2012 15:45:11 -0700 (PDT) I write CGI scripts for my website in PERL. When I used to upload them with my FTP program I made sure to do so in ASCII mode rather than binary. My host made me switch to sFTP however. I use FIlezilla, and can't for the life of me find out how to choose the mode on that. Unfortunately, binary is the default mode. I don't like programming when the file displays ASCII endline characters. I'd rather see clear, distinct lines rather than one long line broken up with those vertical rectangles. When I download a script from my site for editing it looks terrible. Any even remotely decent editor handles unix line edings just fine. What are you using to edit/view the files??? Notepad? If you want something small and generic try http://www.scintilla.org/SciTE.html if you want something bigger and with more features try http://padre.perlide.org/ Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: ASCII/binary endline character trouble
Thanks. I do see the Transfer Type option under the Transfer menu, but it's grayed out and I can't use it. I also tried modifying the first line of my code. Instead of using the ASCII value and the chr function, I cut and pasted the vertical rectangle. So the line became: $sillyrectangle = ; (with said rectangle between the quotemarks - it won't show up in this e-mail) Needless to say, that didn't work either. Fred --- On Sun, 3/25/12, timothy adigun 2teezp...@gmail.com wrote: From: timothy adigun 2teezp...@gmail.com Subject: Re: ASCII/binary endline character trouble To: hOURS h_o...@yahoo.com Cc: Perl Beginners beginners@perl.org, perl-begin...@yahoogroups.com Date: Sunday, March 25, 2012, 9:35 PM Hi Fred, Please, check my comments and possible solution within your mail. On Sun, Mar 25, 2012 at 11:45 PM, hOURS h_o...@yahoo.com wrote: Hello all, I write CGI scripts for my website in PERL. When I used to upload them with my FTP The programming language is Perl not PERL. program I made sure to do so in ASCII mode rather than binary. My host made me switch to sFTP however. I use FIlezilla, and can't for the life of me find out how to choose the mode on that. Unfortunately, binary is the default mode. I don't like programming when the file displays ASCII endline characters. I'd rather see clear, distinct lines rather than one long line broken up with those vertical rectangles. When I download a script from my site for editing it looks terrible. So I wrote a little program to fix that: open (NEW, 'niceviewscript.pl') or die Couldn't open file for writing; I think is better to use open() three arguments like: open(my $fh,,'niceviewscript.pl') or die Couldn't open file for writing: $!; open (FILE, 'script.pl') or die Couldn't open file for reading; ## same thing here too while (FILE) { $line = $_; chomp($line); print NEW $line\n; } close (FILE); ## close($fh) or die can't close file:$!; close (NEW); It works great. How do I get it to go in reverse though so it will work when I upload it? I figured out that the ASCII number for those vertical rectangles that represent line breaks was 10. So I tried: $sillyrectangle = chr(10); open (NEW, 'workingscript.pl') or die Couldn't open file for writing; ## same as above open (FILE, 'niceviewscript.pl') or die Couldn't open file; ## same thing here while (FILE) { $line = $_; chomp($line); $withnewend = $line . $sillyrectangle; print NEW $withnewend; } close (FILE); close (NEW); Why doesn't this work? The newly created file looks just like the old one. Now, if anyone can tell me how to upload in ASCII mode (assuming that's even possible) that Possible Solution: Launch your FileZilla Program, click on the menu bar Transfer menu, then check your sub-menu bar Transfer type, you should be able to change, your mode. I preferred to leave mine as Auto! will solve my problem even better of course. But now I'm curious as to why my program for switching back doesn't work. Thank you! Fred -- Tim
ASCII/binary endline character trouble
Hello all, I write CGI scripts for my website in PERL. When I used to upload them with my FTP program I made sure to do so in ASCII mode rather than binary. My host made me switch to sFTP however. I use FIlezilla, and can't for the life of me find out how to choose the mode on that. Unfortunately, binary is the default mode. I don't like programming when the file displays ASCII endline characters. I'd rather see clear, distinct lines rather than one long line broken up with those vertical rectangles. When I download a script from my site for editing it looks terrible. So I wrote a little program to fix that: open (NEW, 'niceviewscript.pl') or die Couldn't open file for writing; open (FILE, 'script.pl') or die Couldn't open file for reading; while (FILE) { $line = $_; chomp($line); print NEW $line\n; } close (FILE); close (NEW); It works great. How do I get it to go in reverse though so it will work when I upload it? I figured out that the ASCII number for those vertical rectangles that represent line breaks was 10. So I tried: $sillyrectangle = chr(10); open (NEW, 'workingscript.pl') or die Couldn't open file for writing; open (FILE, 'niceviewscript.pl') or die Couldn't open file; while (FILE) { $line = $_; chomp($line); $withnewend = $line . $sillyrectangle; print NEW $withnewend; } close (FILE); close (NEW); Why doesn't this work? The newly created file looks just like the old one. Now, if anyone can tell me how to upload in ASCII mode (assuming that's even possible) that will solve my problem even better of course. But now I'm curious as to why my program for switching back doesn't work. Thank you! Fred
Re: ASCII/binary endline character trouble
Hi Fred, Please, check my comments and possible solution within your mail. On Sun, Mar 25, 2012 at 11:45 PM, hOURS h_o...@yahoo.com wrote: Hello all, I write CGI scripts for my website in PERL. When I used to upload them with my FTP The programming language is Perl not PERL. program I made sure to do so in ASCII mode rather than binary. My host made me switch to sFTP however. I use FIlezilla, and can't for the life of me find out how to choose the mode on that. Unfortunately, binary is the default mode. I don't like programming when the file displays ASCII endline characters. I'd rather see clear, distinct lines rather than one long line broken up with those vertical rectangles. When I download a script from my site for editing it looks terrible. So I wrote a little program to fix that: open (NEW, 'niceviewscript.pl') or die Couldn't open file for writing; I think is better to use open() three arguments like: open(my $fh,,'niceviewscript.pl') or die Couldn't open file for writing: $!; open (FILE, 'script.pl') or die Couldn't open file for reading; ## same thing here too while (FILE) { $line = $_; chomp($line); print NEW $line\n; } close (FILE); ## close($fh) or die can't close file:$!; close (NEW); It works great. How do I get it to go in reverse though so it will work when I upload it? I figured out that the ASCII number for those vertical rectangles that represent line breaks was 10. So I tried: $sillyrectangle = chr(10); open (NEW, 'workingscript.pl') or die Couldn't open file for writing; ## same as above open (FILE, 'niceviewscript.pl') or die Couldn't open file; ## same thing here while (FILE) { $line = $_; chomp($line); $withnewend = $line . $sillyrectangle; print NEW $withnewend; } close (FILE); close (NEW); Why doesn't this work? The newly created file looks just like the old one. Now, if anyone can tell me how to upload in ASCII mode (assuming that's even possible) that Possible Solution: Launch your FileZilla Program, click on the menu bar Transfer menu, then check your sub-menu bar Transfer type, you should be able to change, your mode. I preferred to leave mine as Auto! will solve my problem even better of course. But now I'm curious as to why my program for switching back doesn't work. Thank you! Fred -- Tim
trouble derefencing
hi, I need to add a cli option to my script to push multiple values in a hash. I have verified that using Getopt::Long this is possible, but cannot get my head around dereferencing it. This is a sample code: == use strict; use warnings; use Getopt::Long; Getopt::Long::Configure( no_ignore_case, bundling ); my ($checknow, $help, $revision, %excl_ref ); GetOptions( 'c|checknow' = \$checknow, 'h|help|?'= \$help, 'V|version' = \$revision, 'e|exclude=s%' = sub { push( @{$excl_ref{$_[1]}}, $_[2] ) }, ); use Data::Dumper; print Dumper %excl_ref; = when I run this I get: ./kk.pl -e test=1 -e test=2 -e test=3 $VAR1 = 'test'; $VAR2 = [ '1', '2', '3' ]; But I do not see how I can retrieve these values. I understand that in Getopt::Long when we use a sub, the first argument $_[0] is the name of the option, $_[1] in this case is the key and $_[2] is the value, but I do not understand how I can dereference it, I am afraid. Any help appreciated. TIA. -- Groeten, natxo -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: trouble derefencing
On Sat, Oct 8, 2011 at 14:37, Natxo Asenjo natxo.ase...@gmail.com wrote: hi, I need to add a cli option to my script to push multiple values in a hash. I have verified that using Getopt::Long this is possible, but cannot get my head around dereferencing it. [ snip ] when I run this I get: ./kk.pl -e test=1 -e test=2 -e test=3 $VAR1 = 'test'; $VAR2 = [ '1', '2', '3' ]; %excl_ref is a hash where the keys are on the left hand side of the '=' and the values are arrayrefs of the things on the right hand side of the '='. This will be more clear if you pass Data::Dumper a reference; that will get you output that looks like this: $ ~/try.pl -e test=1 -e test=2 -e test=3 $VAR1 = { 'test' = [ '1', '2', '3' ] }; You could access those -- depending on what you're trying to do -- like so: foreach my $key ( keys %excl_ref ) { foreach my $value ( @{ $excl_ref{$key} ) { print $key = $value\n; } } Hope this helps. chrs, john. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: trouble derefencing
On 11-10-08 02:37 PM, Natxo Asenjo wrote: hi, I need to add a cli option to my script to push multiple values in a hash. I have verified that using Getopt::Long this is possible, but cannot get my head around dereferencing it. This is a sample code: == use strict; use warnings; use Getopt::Long; Getopt::Long::Configure( no_ignore_case, bundling ); my ($checknow, $help, $revision, %excl_ref ); GetOptions( 'c|checknow' = \$checknow, 'h|help|?'= \$help, 'V|version' = \$revision, 'e|exclude=s%' = sub { push( @{$excl_ref{$_[1]}}, $_[2] ) }, ); use Data::Dumper; print Dumper %excl_ref; print Dumper \%excl_ref; = when I run this I get: ./kk.pl -e test=1 -e test=2 -e test=3 $VAR1 = 'test'; $VAR2 = [ '1', '2', '3' ]; %excl_ref has only one key 'test' and its value is an anonymous hash [ '1', '2', '3' ] When you don't send the reference to Dumper(), it expands the hash to a list and dumps each item in the list. -- Just my 0.0002 million dollars worth, Shawn Confusion is the first step of understanding. Programming is as much about organization and communication as it is about coding. The secret to great software: Fail early often. Eliminate software piracy: use only FLOSS. Make something worthwhile. -- Dear Hunter -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Trouble building File::BSDGlob.pm
Dear Shlomi Fish, Thank you for the answer. I tried to use File::Glob's bsd_glob. I replaced line use File::BSDGlob ':glob'; with use File::Glob ':glob'; @list = bsd_glob('*.[ch]'); Now I receive the following error: Global symbol @list requires explicit package name at /big1/robi/ Experiment//AT/ExperimentHarness.pm line 40. BEGIN not safe after errors--compilation aborted at /big1/robi/ Experiment//AT/ExperimentHarness.pm line 41. This time I tried on Debian 2.6.32-34squeeze1. Does anyone have any idea? Robi -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Trouble building File::BSDGlob.pm
2 -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Trouble building File::BSDGlob.pm
Hi Robi, On Tuesday 31 May 2011 13:08:27 Robi wrote: I'm not a perl guy but I need to make something run that relies on the BSDGlob.pm module. I downloaded xzvf File-BSDGlob-0.94.tar.gz from CPAN and generated the Makefile. The make dies with bash-3.2$ perl Makefile.PL Checking if your kit is complete... Looks good Writing Makefile for File::BSDGlob bash-3.2$ make cp BSDGlob.pm blib/lib/File/BSDGlob.pm AutoSplitting blib/lib/File/BSDGlob.pm (blib/lib/auto/File/BSDGlob) gcc -c -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe - Wdeclaration-after-statement -I/usr/local/include -D_LARGEFILE_SOURCE - D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm -O2 -g -pipe -Wall -Wp,- D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer- size=4 -m64 -mtune=generic -DVERSION=\0.94\ -DXS_VERSION=\0.94\ - fPIC -I/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE bsd_glob.c bsd_glob.c: In function ‘globtilde’: bsd_glob.c:369: error: ‘my_perl’ undeclared (first use in this function) This Google search may prove of help: http://www.google.com/search?q=%20error%3A%20%E2%80%98my_perl%E2%80%99%20undeclared A few notes: 1. I was able to successfully run perl Makefile.PL ; make ; make test on x86-32 Mandriva Cooker here. 2. Since you're on CentOS, you may need to install some packages to get Perl modules to build. Moreover, the last release of CentOS still has perl-5.8.8 which has been end-of-lifed. You may wish to use http://search.cpan.org/dist/App-perlbrew/ to install a more recent perl there. 3. The last release of http://search.cpan.org/dist/File-BSDGlob/ was from 1999. Maybe you should replace the functionality that it provides for your code with File::Glob's bsd_glob. Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ UNIX Fortune Cookies - http://www.shlomifish.org/humour/fortunes/ I also have versions of this code in COBOL.NET, Intercal, PDP-10 Assembly, J, APL, Windows NT 4.0 Batch script and Autocad Lisp - I'm sure you can handle all of them because none of them is Perl. ;-). 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/
Trouble building File::BSDGlob.pm
I'm not a perl guy but I need to make something run that relies on the BSDGlob.pm module. I downloaded xzvf File-BSDGlob-0.94.tar.gz from CPAN and generated the Makefile. The make dies with bash-3.2$ perl Makefile.PL Checking if your kit is complete... Looks good Writing Makefile for File::BSDGlob bash-3.2$ make cp BSDGlob.pm blib/lib/File/BSDGlob.pm AutoSplitting blib/lib/File/BSDGlob.pm (blib/lib/auto/File/BSDGlob) gcc -c -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe - Wdeclaration-after-statement -I/usr/local/include -D_LARGEFILE_SOURCE - D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm -O2 -g -pipe -Wall -Wp,- D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer- size=4 -m64 -mtune=generic -DVERSION=\0.94\ -DXS_VERSION=\0.94\ - fPIC -I/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE bsd_glob.c bsd_glob.c: In function ‘globtilde’: bsd_glob.c:369: error: ‘my_perl’ undeclared (first use in this function) bsd_glob.c:369: error: (Each undeclared identifier is reported only once bsd_glob.c:369: error: for each function it appears in.) bsd_glob.c:685:8: warning: extra tokens at end of #endif directive make: *** [bsd_glob.o] Error Interestingly, there is NO reference to my_perl anywhere in bsd_glob.c, only in the included perl.h. Linux kubo.phy.bme.hu 2.6.18-238.9.1.el5.centos.plus #1 SMP Tue Apr 12 20:34:33 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux Help greatly appreciated, Robi -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: trouble matching words with parentheses using grep
On Apr 9, 1:04 pm, alanhag...@alanhaggai.org (Alan Haggai Alavi) wrote: ... #!usr/bin/perl For increased portability, use the shebang #!/usr/bin/env perl Hm, portable only in limited situations, risky, and always slower. From: http://www.webmasterkb.com/Uwe/Forum.aspx/perl/3968/env-perl-or-simply-perl Randal Schwartz's response from above thread: ... Seconded on the reduced portability. The shebang path has to be accurate. Throwing env into the mix means that env has to exist at a known location. Some systems don't have it, some system have it at /bin/env, and some systems have it at /usr/bin/env... so you're only portable within a subset of machines. Also, you're then also doing a double-launch. First, the kernel launches env, then env has to wake up and figure out where Perl is, and then launch that. And, if that wasn't enough, you risk that your script will be run by a privately installed Perl when someone else runs it... which might not have the right version or the right installed modules. An explicit #! path never depends on PATH, so that's not an issue. So, in general, avoid this strategy when you can. -- Charles DeRykus -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
trouble matching words with parentheses using grep
Hello everyone, Here's what I need to do: I need to take each of the words in one List1, search for their presence (or not) in a second List2 and make a new list with all the words in both. These are lists of gene names, which can often include numbers and symbols in addition to letters. The very newbie code that I wrote performs well, but it's missing the words that have parentheses in them (for instance Su(var)2-5). Below are examples of the lists that I'm working with, the code that I'm using, and the output. I realize that there may be a number of ways to do what I need to do (most of them better, I bet), and I'd love to learn about them. But now I'm mostly curious about why grep// cannot see words with parentheses in either (or both lists). I suspect the trick may be somehow escaping the (), but I tried a number of ways of doing that to no avail. Any help will be greatly appreciated! And as usual, if you ever have questions about molecular biology and genetics, fire away - I'd love to pay the favor back. Thanks in advance, Mariano Example of List 1 numb Dl cad99C ham esg Stat92E Hh l(2)Lg neur CG32150 sox15N Su(var)2-5 E(spl)-m4 ci brd vvl Example of List 2 Src42A cad99C ham Hh l(2)Lg neur sox15N numb ubx Su(var)2-5 esg E(spl)-m4 ci ttk egfr brd ocho vvl CG32150 ## SCRIPT BEGINS #!usr/bin/perl use warnings; print \nEnter path to List 1\n\n; $path1 = STDIN; chomp $path1; print \nEnter path to List 2\n\n; $path2 = STDIN; chomp $path2; open (INPUT1, $path1); open (INPUT2, $path2); open (INPUT3, $path3); @array1 = INPUT1; @array2 = INPUT2; my ($array1,$array2,$in1and2); my $ctr1 = 0; while ($ctr1 @array1){ if(grep(/^$array1[$ctr1]$/,@array2)){ push (@in1and2,$array1[$ctr1]); } $ctr1 +=1; } print in 1= .@array1.\nin 2= .@array2.in 1 and 2= .@in1and2.\n\nDone!; exit; ## The output is... in 1= 16 in 2= 19 in 1 and 2= 11 Done! ...when it should have been... in 1= 16 in 2= 19 in 1 and 2= 14 but it's not seeing l(2)Lg, Su(var)2-5, E(spl)-m4 in both lists... (I know this based on troubleshooting) -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: trouble matching words with parentheses using grep
Hello Mariano, I realize that there may be a number of ways to do what I need to do (most of them better, I bet), and I'd love to learn about them. But now I'm mostly curious about why grep// cannot see words with parentheses in either (or both lists). I suspect the trick may be somehow escaping the (), but I tried a number of ways of doing that to no avail. Characters having specific meanings in regular expressions have to be escaped. You could either use the quotemeta function or enclose the regular expression within \Q and \E: grep /^ \Q $array1[$ctr1] \E $/x, @array2; Some comments about the code: #!usr/bin/perl For increased portability, use the shebang #!/usr/bin/env perl use warnings; Also use strict;. $path1 =STDIN; chomp $path1; Declare variables before they are used. open (INPUT1, $path1); open (INPUT2, $path2); open (INPUT3, $path3); Try to use the 3-argument version of open. my ($array1,$array2,$in1and2); Avoid naming scalars and arrays (or hashes) the same. An alternative solution: =pod code #!/usr/bin/env perl use strict; use warnings; use File::Slurp qw( slurp ); use List::MoreUtils qw( any each_array ); my %path; print Enter path to list 1: ; chomp( $path{'list_1'} = STDIN ); print Enter path to list 2: ; chomp( $path{'list_2'} = STDIN ); chomp( my @list_1 = slurp( $path{'list_1'} ) ); chomp( my @list_2 = slurp( $path{'list_2'} ) ); my @common_list; for my $word (@list_1) { any { $_ eq $word } @list_2 and push @common_list, $_; } printf in 1 = %d in 2 = %d in 1 and 2 = %d\n, scalar @list_1, scalar @list_2, scalar @common_list; =cut Any help will be greatly appreciated! And as usual, if you ever have questions about molecular biology and genetics, fire away - I'd love to pay the favor back. Thank you. Hope this message helps. :-) Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: trouble matching words with parentheses using grep
Hello Mariano, use List::MoreUtils qw( any each_array ); I was experimenting and forgot to take off `each_array` from the import list. `each_array` is not used in the alternative solution and is hence not required. Regards, Alan Haggai Alavi. -- The difference makes the difference -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: trouble matching words with parentheses using grep
Mariano Loza Coll wrote: Hello everyone, Hello, Here's what I need to do: I need to take each of the words in one List1, search for their presence (or not) in a second List2 and make a new list with all the words in both. These are lists of gene names, which can often include numbers and symbols in addition to letters. The very newbie code that I wrote performs well, but it's missing the words that have parentheses in them (for instance Su(var)2-5). Below are examples of the lists that I'm working with, the code that I'm using, and the output. I realize that there may be a number of ways to do what I need to do (most of them better, I bet), and I'd love to learn about them. But now I'm mostly curious about why grep// cannot see words with parentheses in either (or both lists). I suspect the trick may be somehow escaping the (), but I tried a number of ways of doing that to no avail. Any help will be greatly appreciated! And as usual, if you ever have questions about molecular biology and genetics, fire away - I'd love to pay the favor back. Thanks in advance, Mariano Example of List 1 numb Dl cad99C ham esg Stat92E Hh l(2)Lg neur CG32150 sox15N Su(var)2-5 E(spl)-m4 ci brd vvl Example of List 2 Src42A cad99C ham Hh l(2)Lg neur sox15N numb ubx Su(var)2-5 esg E(spl)-m4 ci ttk egfr brd ocho vvl CG32150 ## SCRIPT BEGINS #!usr/bin/perl use warnings; use strict; print \nEnter path to List 1\n\n; $path1 =STDIN; chomp $path1; print \nEnter path to List 2\n\n; $path2 =STDIN; chomp $path2; open (INPUT1, $path1); open (INPUT2, $path2); open (INPUT3, $path3); You should *always* verify that a file opened correctly: open INPUT1, '', $path1 or die Cannot open '$path1' because: $!; open INPUT2, '', $path2 or die Cannot open '$path2' because: $!; open INPUT3, '', $path3 or die Cannot open '$path3' because: $!; @array1 =INPUT1; @array2 =INPUT2; my ($array1,$array2,$in1and2); You never use those variables anywhere. my $ctr1 = 0; while ($ctr1 @array1){ if(grep(/^$array1[$ctr1]$/,@array2)){ Change that line to this to get your program to work correclty: if ( grep $_ eq $array1[ $ctr1 ], @array2 ) { push (@in1and2,$array1[$ctr1]); } $ctr1 +=1; } print in 1= .@array1.\nin 2= .@array2.in 1 and 2= .@in1and2.\n\nDone!; exit; ## The output is... in 1= 16 in 2= 19 in 1 and 2= 11 Done! ...when it should have been... in 1= 16 in 2= 19 in 1 and 2= 14 but it's not seeing l(2)Lg, Su(var)2-5, E(spl)-m4 in both lists... (I know this based on troubleshooting) 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: File::Find with chmod trouble debugging
Telemachus telemac...@arpinum.org writes: On Mon Jul 06 2009 @ 3:31, Harry Putnam wrote: Thanks to all ... Now I'm curious about something else: Is the mode in a stat(file) readout something still different than octal or decimal? As John answered, there's more there than just the permissions. If you check perldoc -f stat, there's a recipe for how to get what most people usually want out of that field: Because the mode contains both the file type and its permissions, you should mask off the file type portion and (s)printf using a %o if you want to see the real permissions. $mode = (stat($filename))[2]; printf Permissions are %04o\n, $mode 0; Hope this helps, T Yes, thanks... not sure I understand it that well but it does what I wanted. Seems things are ALWAYS way more complicated than I expect them to be... -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
File::Find with chmod trouble debugging
The script below is my first usage of perls `chmod', but it appears to be in keeping with the info at perldoc -f chmod. But somehow in the print of $mode it turns into 493... even though it is set to 755. Its just the print though... the actual chmod appears to be working as expected. Can anyone tell me how printing of $mode = 0755 turns into 493? #!/usr/local/bin/perl use strict; use warnings; use File::Find; my $myscript; ($myscript = $0) =~ s/^.*\///; ## chmod mode my $mode = 0755; if(!...@argv || $ARGV[0] eq help){ print Usage tripped at . __LINE__ . \n; usage(); print \`$myscript DIR' (needs 1 cmdline argument)\n; exit; } my @dir = shift; if(@ARGV){ print Usage tripped at . __LINE__ . \n; usage(); print Too many cmdline arguments\n; exit; } find(\wanted,@dir); sub wanted { if (-f $_){ print hpdb Opening $_ \n; open(FILE, $_) or die Can't open $_ : $!; my $fname = $_; while(FILE){ if ($. == 1 /^\#\!/){ print hpdb chmod $mode $fname\n; chmod $mode, $fname or die could not chmod '$mode $fname': $!; last; } if ($. == 2){ last; } } close(FILE); } } sub usage { print Purpose: bla Unfinished Usage: ; } A few lines of out put: [...] hpdb Opening form.cgi hpdb chmod 493 form.cgi hpdb Opening index.html hpdb Opening link.cgi hpdb chmod 493 link.cgi [...] -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
AW: File::Find with chmod trouble debugging
Harry Putnam asked: The script below is my first usage of perls `chmod', but it appears to be in keeping with the info at perldoc -f chmod. But somehow in the print of $mode it turns into 493... even though it is set to 755. Its just the print though... the actual chmod appears to be working as expected. Can anyone tell me how printing of $mode = 0755 turns into 493? See perldoc -q octal. HTH, Thomas -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: File::Find with chmod trouble debugging
On Mon, Jul 6, 2009 at 08:00, Harry Putnamrea...@newsguy.com wrote: snip Can anyone tell me how printing of $mode = 0755 turns into 493? snip my $mode = 0755; snip print hpdb chmod $mode $fname\n; snip 0755 is 493. More specifically they are two representations of the same number: the first is in octal (base 8) and the second is in decimal (base 10). If you wish to print the number as octal you must use [printf][1] or [sprintf][2]: printf hpdb chmod 0%o %s\n, $mode, $fname; [1] : http://perldoc.perl.org/functions/printf.html [2] : http://perldoc.perl.org/functions/sprintf.html -- 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: File::Find with chmod trouble debugging
On Mon Jul 06 2009 @ 7:00, Harry Putnam wrote: Can anyone tell me how printing of $mode = 0755 turns into 493? Yup: what's in $mode is an octal number. Its decimal equivalent is 493. What you really want to print out is the string '0755', but the string and the octal number are not the same thing. The good news is that your problem is a lot less bad than the more common one: chmod (755, foobar). (755 is 1363 in octal, an odd choice for permissions.) Try using printf and %o, which should give you 755 for $mode. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: File::Find with chmod trouble debugging
Thanks to all ... Now I'm curious about something else: Is the mode in a stat(file) readout something still different than octal or decimal? I see `33261' show up in the `mode' slot on a file with 755 permissions (from perldoc -f stat: [...] ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat($filename); [...] ls -l file -rwxr-xr-x 1 reader staff 510 2009-07-06 15:25 file My homemade script `mystat' prints out the various values: ./mystat file file: dev = 47776050 ino = 88208 mode= 33261 nlink = 1 uid = 1000 gid = 10 rdev= 4294967295 size= 510 atime = 1246912030 mtime = 1246911903 ctime = 1246911903 blksize = 512 blocks = 2 -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: File::Find with chmod trouble debugging
Harry Putnam wrote: Thanks to all ... Now I'm curious about something else: Is the mode in a stat(file) readout something still different than octal or decimal? I see `33261' show up in the `mode' slot on a file with 755 permissions (from perldoc -f stat: [...] ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat($filename); [...] ls -l file -rwxr-xr-x 1 reader staff 510 2009-07-06 15:25 file My homemade script `mystat' prints out the various values: ./mystat file file: dev = 47776050 ino = 88208 mode= 33261 nlink = 1 uid = 1000 gid = 10 rdev= 4294967295 size= 510 atime = 1246912030 mtime = 1246911903 ctime = 1246911903 blksize = 512 blocks = 2 The mode field contains more information than just the read/write/execute permissions: man 2 stat [ SNIP ] The following flags are defined for the st_mode field: S_IFMT 017 bit mask for the file type bit fields S_IFSOCK 014 socket S_IFLNK012 symbolic link S_IFREG010 regular file S_IFBLK006 block device S_IFDIR004 directory S_IFCHR002 character device S_IFIFO001 FIFO S_ISUID0004000 set UID bit S_ISGID0002000 set-group-ID bit (see below) S_ISVTX0001000 sticky bit (see below) S_IRWXU00700 mask for file owner permissions S_IRUSR00400 owner has read permission S_IWUSR00200 owner has write permission S_IXUSR00100 owner has execute permission S_IRWXG00070 mask for group permissions S_IRGRP00040 group has read permission S_IWGRP00020 group has write permission S_IXGRP00010 group has execute permission S_IRWXO7 mask for permissions for others (not in group) S_IROTH4 others have read permission S_IWOTH2 others have write permission S_IXOTH1 others have execute permission 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: File::Find with chmod trouble debugging
On Mon Jul 06 2009 @ 3:31, Harry Putnam wrote: Thanks to all ... Now I'm curious about something else: Is the mode in a stat(file) readout something still different than octal or decimal? As John answered, there's more there than just the permissions. If you check perldoc -f stat, there's a recipe for how to get what most people usually want out of that field: Because the mode contains both the file type and its permissions, you should mask off the file type portion and (s)printf using a %o if you want to see the real permissions. $mode = (stat($filename))[2]; printf Permissions are %04o\n, $mode 0; Hope this helps, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
trouble with nested forks() (keep spawning twin process)
Hi, I have this code: die Could not fork command1! unless defined (my $command1_pid = fork); if ($command1_pid == 0){ open EXTERNAL_PROG1, external_prog1 | or die Can't run external_prog1; while (EXTERNAL_PROG1){ if (/pattern/){ die Could not fork command2 unless defined (my $command2_pid = fork); die Could not fork command3 unless defined (my $command3_pid = fork); if ($command2_pid == 0){ `external_prog2` } } waitpid($command2_pid,0); if ($command3_pid == 0){ `external_prog3`; } waitpid($command3_pid, 0); } } That is, run external_prog1 and watch the output.. as soon as it sees a particular pattern, run two other external commands at the same time. However, with the above code, I keep getting duplicated external_prog2 process everytime i run the script. I need to track both PIDs of external_prog2 and 3 as I need to kill them later in the code. However, i'm having trouble running them at the same time. if I will put a kill 15, $command3_pid right after the first waitpid, i will surely kill one of those two command 2 process. I tried several places to put die lines and waitpids but I couldn't get it right. It's either they don't run at the same time or they will run but command 2 has a twin brother. Any idea how to solve this chicken and egg problem? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: trouble with nested forks() (keep spawning twin process)
On Thu, Apr 16, 2009 at 8:32 AM, Michael Alipio daem0n...@yahoo.com wrote: Hi, I have this code: die Could not fork command1! unless defined (my $command1_pid = fork); if ($command1_pid == 0){ open EXTERNAL_PROG1, external_prog1 | or die Can't run external_prog1; while (EXTERNAL_PROG1){ if (/pattern/){ die Could not fork command2 unless defined (my $command2_pid = fork); die Could not fork command3 unless defined (my $command3_pid = fork); if ($command2_pid == 0){ `external_prog2` } } waitpid($command2_pid,0); if ($command3_pid == 0){ `external_prog3`; } waitpid($command3_pid, 0); } } That is, run external_prog1 and watch the output.. as soon as it sees a particular pattern, run two other external commands at the same time. However, with the above code, I keep getting duplicated external_prog2 process everytime i run the script. I need to track both PIDs of external_prog2 and 3 as I need to kill them later in the code. However, i'm having trouble running them at the same time. if I will put a kill 15, $command3_pid right after the first waitpid, i will surely kill one of those two command 2 process. I tried several places to put die lines and waitpids but I couldn't get it right. It's either they don't run at the same time or they will run but command 2 has a twin brother. Any idea how to solve this chicken and egg problem? You have problems with scope. At the top of your program, add use warnings; use strict; The messages that are printed should solve your problem. HTH, -- j -- 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! -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: trouble with nested forks() (keep spawning twin process)
On Thu, Apr 16, 2009 at 08:32, Michael Alipio daem0n...@yahoo.com wrote: snip die Could not fork command1! unless defined (my $command1_pid = fork); I am going to number the processes here. 1 will be the first child, 1.1 will be the first child's child. if ($command1_pid == 0){ Only the child will have this be true, so right now these lines of code will be executed by 1 open EXTERNAL_PROG1, external_prog1 | or die Can't run external_prog1; while (EXTERNAL_PROG1){ if (/pattern/){ die Could not fork command2 unless defined (my $command2_pid = fork); You fork again, so the next few lines will be executed by 1 and 1.1 die Could not fork command3 unless defined (my $command3_pid = fork); 1 forks and now has two children 1.1 and 1.2 1.1 forks and has a child 1.1.1 if ($command2_pid == 0){ `external_prog2` } That condition is true for 1 } waitpid($command2_pid,0); if ($command3_pid == 0){ `external_prog3`; } This condition is true for 1.2 and 1.1.1 waitpid($command3_pid, 0); } } snip Any idea how to solve this chicken and egg problem? snip After every fork you must should check the pid and route the parent and child on different tracks in the code. Other things I noticed while looking at your code, * backticks should be used to capture the STDOUT of an external program, not just run it, use system instead. If you want to prevent the program from printing to the screen say system $command /dev/null 21; * old bareword style filehandles are bad, use lexical file handles instead * the two argument version of open is dangerous, use the three argument version instead: open my $lexical_fh, -|, external_prog1 or die etc; -- 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/
bot trouble
hi i am trying to write a bot that passes messages to OSC from and IRC i'm having a bit of problem formating my output the messages i get in my OSC client look like this: /irc/11811/$VAR1 = rob;/$VAR1 = testing 1 2 3 when i would like them to look like this: /irc/11811/rob/testing 1 2 3 any hints to what i am doing wrong? also it complains about Odd number of elements in anonymous hash for this line: $client-send([/irc/11811/$nick/$str]) many thanks, rob code below: package OSCBot; use base qw(Bot::BasicBot); use Net::OpenSoundControl::Client; use Data::Dumper; use warnings; use strict; my $client = Net::OpenSoundControl::Client-new( Host = localhost, Port = ) or die Could not start client: $...@\n; sub said { my ($self, $message) = @_; if ($message-{body} =~ /\b^osc \b/) { my $nick = Dumper($message-{who}); $nick =~ s/'//g; chomp($nick); my $str = Dumper($message-{body}); $str =~ s/'//g; $str =~ s/osc//g; return { $client-send([/irc/11811/$nick/$str]) } } } OSCBot-new( server = irc.goto10.org, channels = #bottest, nick = 'x11811', ignore_list = [qw(3340)], )-run(); -- r...@goto10.org rob.goto10.org -- signature.asc Description: Digital signature
Re: bot trouble
r...@goto10.org wrote: hi i am trying to write a bot that passes messages to OSC from and IRC i'm having a bit of problem formating my output the messages i get in my OSC client look like this: /irc/11811/$VAR1 = rob;/$VAR1 = testing 1 2 3 when i would like them to look like this: /irc/11811/rob/testing 1 2 3 any hints to what i am doing wrong? I know nothing about the module you are using, but out from your description it seems like there is a hash ref looking something like: my $message = { who = 'rob', body = 'osc testing 1 2 3', }; and you are using Data::Dumper to extract values from it when you'd better just say: my $nick = $message-{who}; my $str = $message-{body}; Hopefully that hint helps you move forward. -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
trouble with 'tr' command
Hello, Trying to do the following and the variable $field_term does not transiterate. The $foo becomes name$age$grade$school$semester. #!/usr/bin/perl my $field_term = '|'; my $foo = name,age,grade,school,semester; $foo =~ tr/,/$field_term/; __END__ Please advise.
Re: trouble with 'tr' command
Tony Esposito wrote: Hello, Hello, Trying to do the following and the variable $field_term does not transiterate. The $foo becomes name$age$grade$school$semester. #!/usr/bin/perl my $field_term = '|'; my $foo = name,age,grade,school,semester; $foo =~ tr/,/$field_term/; __END__ Please advise. tr/// does not interpolate so you have to do either: eval \$foo =~ tr/,/$field_term/; Or: $foo =~ s/,/$field_term/g; 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: trouble with 'tr' command
I tried $foo =~ s/,/$field_term/g; and it worked fine ... thx. From: John W. Krahn jwkr...@shaw.ca To: Perl Beginners beginners@perl.org Sent: Tuesday, 6 January, 2009 13:19:20 Subject: Re: trouble with 'tr' command Tony Esposito wrote: Hello, Hello, Trying to do the following and the variable $field_term does not transiterate. The $foo becomes name$age$grade$school$semester. #!/usr/bin/perl my $field_term = '|'; my $foo = name,age,grade,school,semester; $foo =~ tr/,/$field_term/; __END__ Please advise. tr/// does not interpolate so you have to do either: eval \$foo =~ tr/,/$field_term/; Or: $foo =~ s/,/$field_term/g; 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/
Text::vCard trouble
I want to use Text::vCard to import Address Book data and put that data into a CGI.pm object. So far I can break out the name and address from a vCard but I can't seem to access the phone number data. Below is the script I'm building for this. Can anyone spot what I'm doing wrong? Kindest Regards, -- Bill Stephenson code #!/usr/local/bin/perl use strict; use Text::vCard; use Text::vCard::Addressbook; my $address_book = Text::vCard::Addressbook-new({ 'source_file' = '/Library/WebServer/CGI-Executables/test/vCard/GroupvCards.vcf', }); foreach my $vcard ($address_book-vcards()) { print $vcard-fullname() .\n; my $addresses = $vcard-get({ 'node_type' = 'addresses' }); my $address = $addresses-[0]; print $address-street() .\n; print $address-city() . ; print $address-post_code() .\n; print $address-country() .\n\n; print $vcard-email() .\n; # these do not work. # print $vcard-tel() .\n; # print $vcard-tel-home() .\n; # print $vcard-phones-home() .\n; #this should get all the home and work phone numbers my @types = qw(work home); my $nodes = $vcard-get({ 'node_type' = 'tel', 'types' = \...@types, }); # trying print them all out here foreach my $node (@$nodes) { # I have tried variations on this but # cannot get it to print the phone numbers. # I get no errors. Nothing. print $node-value(); print $node-home(); print $node-tel-home(); } print \n==\n\n; } /code Sample vCard used GroupvCards.vcf BEGIN:VCARD VERSION:3.0 N:Galik;Frankie;;; FN:Frankie Galik ORG:Cork Massage; EMAIL;type=INTERNET;type=HOME;type=pref:t...@test.com EMAIL;type=INTERNET;type=WORK:te...@test.com TEL;type=HOME;type=pref:021000 TEL;type=CELL:085000 TEL;type=WORK:021001 item1.ADR;type=HOME;type=pref:;;Test Street;Cork;Cork;;Ireland item1.X-ABADR:ie item2.ADR;type=WORK:;;2 Test Street\, Lee Road;Cork;;;Ireland item2.X-ABADR:ie CATEGORIES:Ezinvoice Vcard Test X-ABUID:E8069363-962C-4F44-A1A2-B678C8597D92\:ABPerson END:VCARD BEGIN:VCARD VERSION:3.0 N:Johnston;John;;; FN:John Johnston ORG:Apple; EMAIL;type=INTERNET;type=HOME;type=pref:j...@mac.com TEL;type=HOME:+3532100 TEL;type=CELL;type=pref:+35387666 TEL;type=WORK:+3532100 item1.ADR;type=HOME;type=pref:;;17 The Mews\nRiver Towers\, Lee Road;Cork;Cork;; item1.X-ABADR:ie CATEGORIES:Ezinvoice Vcard Test X-ABUID:DFBEC94D-55DC-44C6-978E-3AE5CF63EE79\:ABPerson END:VCARD -- To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org For additional commands, e-mail: beginners-cgi-h...@perl.org http://learn.perl.org/
trouble with a regular expresion
Below is snipit of code that is intended to read in the station_id from the header of each example file. In each case the reg expression is supposed to find the 6 digit number within the parentheses. Both files contain 6 lines in the header. For some reason the reg expression will not catch the station_id in the 2nd example. Oddly however, if I paste the data portion of the first file, into the 2nd file, then the the reg expression catches the station id in the 2nd example. Any ideas? my $station_id = ''; while ( ) { #Part 1. Loop through the header lines to identify the station id. #The station ID has the format of: #STATION: (SOME_STATION_ABVR) SOME_STATION_NAME_AP (Station ID: ##) if ( 1 .. 6 ) { $station_id = $1 if /\(Station ID:\s*(\S+)\)/; next; } #At eof close the input filehandle to reset $. if ( eof || !/\S/) { close ARGV; next; } print $station_id; } == EXAMPLE 1 == STATION: WIND_POINT, WI (Station ID: 479983) Precip- Snow SnowObser- itationLow High Fall Depth Mean vation Data Year Mo Dy (in)(F)(F) (in) (in)(F) Time Source 2003 01 01 M M M M M M - - 2003 01 02 M M M M M M - - 2003 01 03 M M M M M M - - 2003 01 04 M M M M M M - - 2003 01 05 M M M M M M - - === EXAMPLE 2 === Station: (APN) ALPENA_WSO_AP (Station ID: 24) mmdd Air WetB DewP Min Max Wind Wind SeaLev SolarPot Temp Temp Temp RelH RelH Speed Direc Press Radiat Evap (F) (F) (F) (per) (per) (mph) (deg) (mb) (MJ/sq m) (in) 199001020m0m0m0m0m0m0m 0m 0m 0m 199001030m0m0m0m0m0m0m 0m 0m 0m 199001040m0m0m0m0m0m0m 0m 0m 0m 199001050m0m0m0m0m0m0m 0m 0m 0m 199001060m0m0m0m0m0m0m 0m 0m 0m -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: trouble with a regular expresion
Kirk Wythers wrote: Below is snipit of code that is intended to read in the station_id from the header of each example file. In each case the reg expression is supposed to find the 6 digit number within the parentheses. Both files contain 6 lines in the header. For some reason the reg expression will not catch the station_id in the 2nd example. Oddly however, if I paste the data portion of the first file, into the 2nd file, then the the reg expression catches the station id in the 2nd example. Any ideas? I tried your example as posted and it does print out the station_id from each file. John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order.-- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: trouble with a regular expresion
Kirk Wythers wrote: On Oct 23, 2008, at 11:09 PM, John W. Krahn wrote: Kirk Wythers wrote: Below is snipit of code that is intended to read in the station_id from the header of each example file. In each case the reg expression is supposed to find the 6 digit number within the parentheses. Both files contain 6 lines in the header. For some reason the reg expression will not catch the station_id in the 2nd example. Oddly however, if I paste the data portion of the first file, into the 2nd file, then the the reg expression catches the station id in the 2nd example. Any ideas? I tried your example as posted and it does print out the station_id from each file. Thanks for the reply John. I also tried pasting the code into new files and the code worked. Could there be any kind of oddities in the original text files that would interfere? I am using emacs to view and edit, so I assume that weird windows carriage returns would show up. Any other ideas? It looks like you are posting from an Apple machine? Are you running the code on the same machine that you edited it on? Is the data generated on the same machine that the code is running on? It *could* be related to the end-of-line character(s) but it is hard to diagnose from this distance. :-) John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order.-- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Having trouble with cpan
Hi All, I am having trouble with CPAN to update my perl packages. Here is the error: [EMAIL PROTECTED] ~]# cpan cpan shell -- CPAN exploration and modules installation (v1.7602) ReadLine support enabled cpan install String::scanf CPAN: Storable loaded ok Going to read /home/barryb/.cpan/Metadata Database was generated on Thu, 12 Jun 2008 12:06:48 GMT Going to read /home/barryb/.cpan/sources/authors/01mailrc.txt.gz CPAN: Compress::Zlib loaded ok Can't call method value on an undefined value at /usr/lib/perl5/vendor_perl/5.8.8/IO/Uncompress/RawInflate.pm line 64. cpan Has anyone seen this or have an idea for how to solve it. Barry
Re: Having trouble with cpan
On Tue, Jul 22, 2008 at 10:53 AM, Barry Benowitz [EMAIL PROTECTED] wrote: cpan install String::scanf Shouldn't that be String::Scanf? Capitalization can be important; if not here, certainly when you use the module. Can't call method value on an undefined value at /usr/lib/perl5/vendor_perl/5.8.8/IO/Uncompress/RawInflate.pm line 64. That seems quite odd. If you repeatedly get that error, I'm guessing that maybe something (the CPAN authors file?) didn't download correctly. I recommend you discard the contents of your CPAN sources directory, since that's just a download cache, and try again. The sources directory is found within your CPAN home directory, which is often named .cpan in your home directory. Of course, if you can't install that module in the automated way, you can try installing without the CPAN shell like us old timers used to do. Somebody around here probably still remembers how to run a Makefile.PL from the command line Or you can type perldoc perlmodinstall at the command line and read about it. Good luck with it! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
trouble with cgi::session- redirects and getting params
I'm trying to set up a simple web page with login and registration system before I try more complicated stuff. I'm running into a problem where I redirect to a script, try to pull a parameter off of the url and do something with it ( in this case, a session id that needs to be removed from the database ). When I redirect to the script, I print out the parameters and get they are all empty, even though the url in the browser has them attached! If I click on the address bar and press enter and reload the script, it works fine. The page I am redirecting from also takes in parameters, and it works fine! Any suggestions? Thanks for the help! Here's the code of interest: # redirecting to this ( logout.pl ) my $cgi = new CGI; my $sid = $cgi-param(sid); my $username = $cgi-param(uid); # check if session exists and then delete it my $dbh = $ProjCfg::dbh; my $dbName = $ProjCfg::dbname; my $sessionTable = $ProjCfg::sessionTable; my $sqlStmt = DELETE FROM $dbName.$sessionTable WHERE id='$sid'; $dbh-do($sqlStmt); print $sqlStmt; # redirecting from $cgi = new CGI; $sid = $cgi-param(sid); $username = $cgi-param(uid); print html head titleLogin Page/title /head body h1 Welcome $username with id number $sid/h1 form action='/cgi-bin/session/logout.pl?sid=$sid' method='post' input type='submit' value='Logout' name='submit' /form /body/html; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Trouble with CPAN login
Hi folks, I'm trying to access a local CPAN mirror over FTP and am unable to connect. cpan reload index CPAN: Storable loaded ok Going to read /.cpan/Metadata Database was generated on Tue, 26 Feb 2008 05:31:07 GMT CPAN: LWP::UserAgent loaded ok Fetching with LWP: ftp://cpan.arrow.com/CPAN/authors/01mailrc.txt.gz LWP failed with code[401] message[Login incorrect.] Fetching with Net::FTP: ftp://cpan.arrow.com/CPAN/authors/01mailrc.txt.gz Couldn't login on cpan.arrow.com at /usr/local/lib/perl5/5.8.0/CPAN.pm line 2178. Fetching with LWP: http://cpan.arrow.com/CPAN/authors/01mailrc.txt.gz ^CCaught SIGINT The http call fails because we don't have port 80 open (I might be able to fix that later), but ftp works fine from a command line. It looks to me like it's trying to login as anonymous even though I have configured username and password through the CPAN shell. Does anyone know if there's a way around this other than hacking CPAN.pm which I wouldn't be crazy about doing? TIA richf
Re: Trouble with CPAN login
looks like local user error are you sure the credentials your supplying are correct? On Thu, Mar 6, 2008 at 4:13 PM, RICHARD FERNANDEZ [EMAIL PROTECTED] wrote: Hi folks, I'm trying to access a local CPAN mirror over FTP and am unable to connect. cpan reload index CPAN: Storable loaded ok Going to read /.cpan/Metadata Database was generated on Tue, 26 Feb 2008 05:31:07 GMT CPAN: LWP::UserAgent loaded ok Fetching with LWP: ftp://cpan.arrow.com/CPAN/authors/01mailrc.txt.gz LWP failed with code[401] message[Login incorrect.] Fetching with Net::FTP: ftp://cpan.arrow.com/CPAN/authors/01mailrc.txt.gz Couldn't login on cpan.arrow.com at /usr/local/lib/perl5/5.8.0/CPAN.pm line 2178. Fetching with LWP: http://cpan.arrow.com/CPAN/authors/01mailrc.txt.gz ^CCaught SIGINT The http call fails because we don't have port 80 open (I might be able to fix that later), but ftp works fine from a command line. It looks to me like it's trying to login as anonymous even though I have configured username and password through the CPAN shell. Does anyone know if there's a way around this other than hacking CPAN.pm which I wouldn't be crazy about doing? TIA richf -- Rodrick R. Brown http://www.rodrickbrown.com http://www.linkedin.com/in/rodrickbrown -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
RE: Trouble with CPAN login
-Original Message- From: Rodrick Brown [mailto:[EMAIL PROTECTED] looks like local user error are you sure the credentials your supplying are correct? Hi Rodrick, The credentials I've configured in CPAN match the ones in my .netrc file which allows me to login successfully from a command line. In addition I took a look at CPAN.pm (the line referenced in the error was 2178): 2177unless ( $ftp-login(anonymous,$Config::Config{'cf_email'}) ){ 2178 warn Couldn't login on $host; 2179 return; 2180} Looks to me like anonymous is hard coded in there...unless I'm missing something? Is anyone else successfully using a username/password to log into cpan? Thanks. richf -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Trouble with Email::MIME modules
On Tue, 27 Nov 2007 22:21:06 +0100 Filip Sneppe [EMAIL PROTECTED] wrote: I am calling this code like this: my $parser = new MIME::Parser; $entity = $parser-parse_data($lines); $convertedstring = convert_mime_to_8bit($log_fh, $loglevel, $entity, ); where $lines is a reference to an array (of lines containing the original mail). While the code itself does convert parts of the mail to 8bit, here are two problems with it: - for some reason, for every attachment in the email, it creates files on the local filesystem. I don't want to have to clean these up manually. From the MIME::Parser docs: Examples of output control ### Keep parsed message bodies in core (default outputs to disk): $parser-output_to_core(1); ### Output each message body to a one-per-message directory: $parser-output_under(/tmp); ### Output each message body to the same directory: $parser-output_dir(/tmp); ### Change how nameless message-component files are named: $parser-output_prefix(msg); And see the section Specifying output destination for the precise specification. Celejar -- mailmin.sourceforge.net - remote access via secure (OpenPGP) email ssuds.sourceforge.net - A Simple Sudoku Solver and Generator -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Trouble with Email::MIME modules
On 11/27/07, Filip Sneppe [EMAIL PROTECTED] wrote: - for some reason, for every attachment in the email, it creates files on the local filesystem. I don't want to have to clean these up manually. The module should provide some way to clean these up, if it creates them. - more importantly, the email that I am puzzling back together, is not a valid email: another application (in php) is reading it, and is simply complaining that the email format is wrong. If you're trying to parse invalid files, things get much tougher. You may need to seek the advice of MIME experts to get things working the way you want. I couldn't see any big bugs in the code you posted, and it seems that nobody else did either. If you step through it with the debugger, you may be able to see where it's going wrong. Good luck with it! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Trouble Installing Carp-Clan 5.9.x
And if you reply to someone you should trim down the message ... there is no reason to include the unsubscribe notice three times. - Because then it's all backwards. - Why is that? - Please, don't top post! From: Gerald Wheeler [EMAIL PROTECTED] Correction, I did get to the end of one branch.. no further prerequisites. However, I got this error at the top of the next branch - Bit::Vector *--- ls Artistic.txt CHANGES.txt GNU_GPL.txt lib MANIFEST t Vector.pm BitVector.c CREDITS.txt GNU_LGPL.txt Makefile patchlevel.h ToolBox.h Vector.pod BitVector.h examples INSTALL.txt Makefile.PL README.txttypemap Vector.xs # perl Makefile.PL Writing Makefile for Bit::Vector Writing patchlevel.h for perl (5.008004) # /usr/ccs/bin/make cp lib/Bit/Vector/Overload.pm blib/lib/Bit/Vector/Overload.pm cp Vector.pm blib/lib/Bit/Vector.pm cp Vector.pod blib/lib/Bit/Vector.pod cp lib/Bit/Vector/String.pod blib/lib/Bit/Vector/String.pod cp lib/Bit/Vector/Overload.pod blib/lib/Bit/Vector/Overload.pod cp lib/Bit/Vector/String.pm blib/lib/Bit/Vector/String.pm cc -c-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -xarch=v8 -D_TS_ERRNO -xO3 -xspace -xildoff-DVERSION=\6.4\ -DXS_VERSION=\6.4\ -KPIC -I/usr/perl5/5.8.4/lib/sun4-solaris-64int/CORE BitVector.c sh: cc: not found *** Error code 1 make: Fatal error: Command failed for target `BitVector.o' *--- If I was a betting man I would say it's looking for a C/C++ Compiler which I do not have Thanks J. Gerald Wheeler [EMAIL PROTECTED] 11/26/2007 2:11 PM It appears that there is no end to the prerequisites for any given module.. Are they all really necessary for a build?? test??? Thanks J. Tom Phoenix [EMAIL PROTECTED] 11/26/2007 2:03 PM On 11/26/07, Gerald Wheeler [EMAIL PROTECTED] wrote: t/10basic..Can't locate Test/Exception.pm in @INC (@INC It looks as if the test failed when it couldn't find a module named Test::Exception. Is that module installed on your system? It may be needed for the tests, even if it's not listed as a prerequisite for the module itself. :-P Cheers! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Trouble Installing Carp-Clan 5.9.x
Sorry about the top posting.. Is there a way to resolve the make problem for Bit::Vector J. Jenda Krynicky [EMAIL PROTECTED] 11/27/2007 5:57:13 AM And if you reply to someone you should trim down the message ... there is no reason to include the unsubscribe notice three times. - Because then it's all backwards. - Why is that? - Please, don't top post! From: Gerald Wheeler [EMAIL PROTECTED] Correction, I did get to the end of one branch.. no further prerequisites. However, I got this error at the top of the next branch - Bit::Vector *--- ls Artistic.txt CHANGES.txt GNU_GPL.txt lib MANIFEST t Vector.pm BitVector.c CREDITS.txt GNU_LGPL.txt Makefile patchlevel.h ToolBox.h Vector.pod BitVector.h examples INSTALL.txt Makefile.PL README.txt typemap Vector.xs # perl Makefile.PL Writing Makefile for Bit::Vector Writing patchlevel.h for perl (5.008004) # /usr/ccs/bin/make cp lib/Bit/Vector/Overload.pm blib/lib/Bit/Vector/Overload.pm cp Vector.pm blib/lib/Bit/Vector.pm cp Vector.pod blib/lib/Bit/Vector.pod cp lib/Bit/Vector/String.pod blib/lib/Bit/Vector/String.pod cp lib/Bit/Vector/Overload.pod blib/lib/Bit/Vector/Overload.pod cp lib/Bit/Vector/String.pm blib/lib/Bit/Vector/String.pm cc -c-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -xarch=v8 -D_TS_ERRNO -xO3 -xspace -xildoff-DVERSION=\6.4\ -DXS_VERSION=\6.4\ -KPIC -I/usr/perl5/5.8.4/lib/sun4-solaris-64int/CORE BitVector.c sh: cc: not found *** Error code 1 make: Fatal error: Command failed for target `BitVector.o' *--- If I was a betting man I would say it's looking for a C/C++ Compiler which I do not have Thanks J. Sorry about the top posting.. Is there a way to resolve the make problem for Bit::Vector This of course is my attempt to install the Date::Calc module Bit::Vector is just one of many prerequisite modules Thanks J. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Trouble with Email::MIME modules
Hi, I am trying to do the following: I have (an) email that is fetched from an IMAP server What I want to do is go over this mail and do two things: - change all Content-Transfer-Encoding: quoted-printable or 7bit to 8bit - drop all MIME parts that are Content-Type: text/html and then save the resulting email to a text file. I want to save the email as 8bit, since that makes parsing things a lot easier for other scripts I have. Over the past two weeks I have spent several hours reading up on various MIME modules and testing things out. But I am simply not able to come up with something that does what I want. Quite a frustrating experience altogether, as I expected this to be a quick 20-lines script. At this point I am getting so frustrated that I would simply like to look at working code of what I need to achieve and then learn where I went wrong. I've already looked at various MIME and mail related Perl modules. I think I need Email::MIME and Email::MIME::Modifier but I can't come up with a working script. Is there anyone who wants to help me out with this ? Thanks in advance. Best regards, Filip -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Trouble with Email::MIME modules
On 11/27/07, Filip Sneppe [EMAIL PROTECTED] wrote: At this point I am getting so frustrated that I would simply like to look at working code of what I need to achieve and then learn where I went wrong. Well, the first part of what you'd like would seem to imply that somebody else should write your program for you. But maybe you don't mean that, you just want code that shows how to use the module? Any good module should include examples (in the documentation, or elsewhere) to show how it should be used in working code. Often these examples are simple to adapt for many typical tasks, perhaps even yours. So, on to the second part. If you're ready to see where you went wrong, post your code. Someone here will surely help you to bring it closer to what you need. Cheers! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Trouble with Email::MIME modules
On Nov 27, 2007 7:20 PM, Tom Phoenix [EMAIL PROTECTED] wrote: Well, the first part of what you'd like would seem to imply that somebody else should write your program for you. But maybe you don't mean that, you just want code that shows how to use the module? Any good module should include examples (in the documentation, or elsewhere) to show how it should be used in working code. Often these examples are simple to adapt for many typical tasks, perhaps even yours. So, on to the second part. If you're ready to see where you went wrong, post your code. Someone here will surely help you to bring it closer to what you need. Ok, thank you for your quick response. The closest I got was by using code based on th mimedump example here: http://www.iaeste.or.at/doc/libmime-perl/examples/ sub convert_mime_to_8bit { my ($log_fh, $loglevel, $entity, $nextpart) = @_; my @parts; my $IO; my $tempstring; my $returnstring; if (!($nextpart) ($entity-head-original_text =~ /boundary=\(.*)\$/m)) { $nextpart = $1; }; $returnstring = --$nextpart\n.$entity-head-original_text; $returnstring =~ s/^Content-Transfer-Encoding: quoted-printable/Content-Transfer-Encoding: 8bit/m; $returnstring .= \n; @parts = $entity-parts; if (@parts) { foreach my $i (0 .. $#parts) { log_it (2, $log_fh, |convert_mime_to_8bit(): part $i: $parts[$i] - $nextpart\n); $returnstring .= convert_mime_to_8bit($log_fh, $loglevel, $parts[$i], $nextpart); }; } else { my ($type, $subtype) = split('/', $entity-head-mime_type); my $body = $entity-bodyhandle; if ($type =~ /^(text|message)$/) { if ($IO = $body-open(r)) { log_it (2, $log_fh, |convert_mime_to_8bit(): converting $type part\n); $returnstring .= $_ while (defined($_ = $IO-getline)); $returnstring .= \n; $IO-close; }; } else { if ($IO = $body-open(r)) { log_it (2, $log_fh, |convert_mime_to_8bit(): base64-encoding $type part\n); $tempstring .= $_ while (defined($_ = $IO-getline)); $IO-close; $returnstring .= encode_base64($tempstring); }; }; }; return $returnstring; } I am calling this code like this: my $parser = new MIME::Parser; $entity = $parser-parse_data($lines); $convertedstring = convert_mime_to_8bit($log_fh, $loglevel, $entity, ); where $lines is a reference to an array (of lines containing the original mail). While the code itself does convert parts of the mail to 8bit, here are two problems with it: - for some reason, for every attachment in the email, it creates files on the local filesystem. I don't want to have to clean these up manually. - more importantly, the email that I am puzzling back together, is not a valid email: another application (in php) is reading it, and is simply complaining that the email format is wrong. So basically, the subroutine is screwing up spaces or MIME metadata somewhere. At this point I am thinking: there's got to be better ways to do this, without my code having to puzzle back together the email etc. So I'm digging around, reading up on all the MIME modules Perl has. There is Email::MIME::Modifier which talks about this method: encoding_set However, I am unable to find any example code. As you can see, the Email::MIME and Email::MIME::Modifier don't have that much example code, especially for a non-MIME expert. Best regards, Filip -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Trouble Installing Carp-Clan 5.9.x
Trying to install Carp-Clan (prerequisite to Date Module) Downloaded file from CPAN unzipped file cd to directory Carp-Clan-5.9 perl Makefile.PL make /usr/ccs/bin/make test (This failes with the following error(s): Anybody know what I'm doing wrong.. # /usr/ccs/bin/make test PERL_DL_NONLAZY=1 /usr/bin/perl -MExtUtils::Command::MM -e test_harness(0, 'blib/lib', 'blib/arch') t/*.t t/01podskipped all skipped: Skipping author tests t/03yaml...skipped all skipped: Skipping author tests t/04boilerplateskipped all skipped: Skipping author tests t/10basic..Can't locate Test/Exception.pm in @INC (@INC contains: /export/home/abc/perls/Carp-Clan-5.9/blib/lib /export/home/abc/perls/Carp-Clan-5.9/blib/arch /usr/perl5/5.8.4/lib/sun4-solaris-64int /usr/perl5/5.8.4/lib/sun4-solaris-64int /usr/perl5/5.8.4/lib /usr/perl5/site_perl/5.8.4/sun4-solaris-64int /usr/perl5/site_perl/5.8.4/sun4-solaris-64int /usr/perl5/site_perl/5.8.4 /usr/perl5/site_perl/5.8.4/sun4-solaris-64int /usr/perl5/site_perl/5.8.4 /usr/perl5/site_perl /usr/perl5/vendor_perl/5.8.4/sun4-solaris-64int /usr/perl5/vendor_perl/5.8.4/sun4-solaris-64int /usr/perl5/vendor_perl/5.8.4 /usr/perl5/vendor_perl/5.8.4/sun4-solaris-64int /usr/perl5/vendor_perl/5.8.4 /usr/perl5/vendor_perl . /usr/perl5/5.8.4/lib/sun4-solaris-64int /usr/perl5/5.8.4/lib /usr/perl5/site_perl/5.8.4/sun4-solaris-64int /usr/perl5/site_perl/5.8.4 /usr/perl5/site_perl /usr/perl5/vendor_perl/5.8.4/sun4-solaris-64int /usr/perl5/vendor_perl/5.8.4 /usr/perl5/vendor_perl .) at t/10basic.t line 5. BEGIN failed--compilation aborted at t/10basic.t line 5. # Looks like your test died before it could output anything. t/10basic..dubious Test returned status 2 (wstat 512, 0x200) DIED. FAILED tests 1-2 Failed 2/2 tests, 0.00% okay t/11basic..ok 1/55 skipped: Object::Deadly not installed Failed Test Stat Wstat Total Fail Failed List of Failed --- t/10basic.t2 512 24 200.00% 1-2 3 tests and 1 subtest skipped. Failed 1/5 test scripts, 80.00% okay. 2/57 subtests failed, 96.49% okay. *** Error code 29 make: Fatal error: Command failed for target `test_dynamic' # -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Trouble Installing Carp-Clan 5.9.x
On 11/26/07, Gerald Wheeler [EMAIL PROTECTED] wrote: t/10basic..Can't locate Test/Exception.pm in @INC (@INC It looks as if the test failed when it couldn't find a module named Test::Exception. Is that module installed on your system? It may be needed for the tests, even if it's not listed as a prerequisite for the module itself. :-P Cheers! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Trouble Installing Carp-Clan 5.9.x
It appears that there is no end to the prerequisites for any given module.. Are they all really necessary for a build?? test??? Thanks J. Tom Phoenix [EMAIL PROTECTED] 11/26/2007 2:03 PM On 11/26/07, Gerald Wheeler [EMAIL PROTECTED] wrote: t/10basic..Can't locate Test/Exception.pm in @INC (@INC It looks as if the test failed when it couldn't find a module named Test::Exception. Is that module installed on your system? It may be needed for the tests, even if it's not listed as a prerequisite for the module itself. :-P Cheers! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Trouble Installing Carp-Clan 5.9.x
Correction, I did get to the end of one branch.. no further prerequisites. However, I got this error at the top of the next branch - Bit::Vector *--- ls Artistic.txt CHANGES.txt GNU_GPL.txt lib MANIFEST t Vector.pm BitVector.c CREDITS.txt GNU_LGPL.txt Makefile patchlevel.h ToolBox.h Vector.pod BitVector.h examples INSTALL.txt Makefile.PL README.txttypemap Vector.xs # perl Makefile.PL Writing Makefile for Bit::Vector Writing patchlevel.h for perl (5.008004) # /usr/ccs/bin/make cp lib/Bit/Vector/Overload.pm blib/lib/Bit/Vector/Overload.pm cp Vector.pm blib/lib/Bit/Vector.pm cp Vector.pod blib/lib/Bit/Vector.pod cp lib/Bit/Vector/String.pod blib/lib/Bit/Vector/String.pod cp lib/Bit/Vector/Overload.pod blib/lib/Bit/Vector/Overload.pod cp lib/Bit/Vector/String.pm blib/lib/Bit/Vector/String.pm cc -c-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -xarch=v8 -D_TS_ERRNO -xO3 -xspace -xildoff-DVERSION=\6.4\ -DXS_VERSION=\6.4\ -KPIC -I/usr/perl5/5.8.4/lib/sun4-solaris-64int/CORE BitVector.c sh: cc: not found *** Error code 1 make: Fatal error: Command failed for target `BitVector.o' *--- If I was a betting man I would say it's looking for a C/C++ Compiler which I do not have Thanks J. Gerald Wheeler [EMAIL PROTECTED] 11/26/2007 2:11 PM It appears that there is no end to the prerequisites for any given module.. Are they all really necessary for a build?? test??? Thanks J. Tom Phoenix [EMAIL PROTECTED] 11/26/2007 2:03 PM On 11/26/07, Gerald Wheeler [EMAIL PROTECTED] wrote: t/10basic..Can't locate Test/Exception.pm in @INC (@INC It looks as if the test failed when it couldn't find a module named Test::Exception. Is that module installed on your system? It may be needed for the tests, even if it's not listed as a prerequisite for the module itself. :-P Cheers! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Trouble with Perl Standalone Executable
Hi all, I was interested in compiling my Perl code. I came across the following site that shows how to do it: http://www.expertsrt.com/tutorials/Matt/perlPAR.html I followed the instructions (I am using PAR and PAR-Packer version 0.976). It works fine on my Mac, but If I take an executable to an XP machine I get the following error message: Program too big to fit in memory even though it's just a simple hello world! program that's 3MB on disk. Anyone know what could be causing this? __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Re: Trouble with Perl Standalone Executable
On 10/26/07, Yoyoyo Yoyoyoyo [EMAIL PROTECTED] wrote: Hi all, I was interested in compiling my Perl code. I came across the following site that shows how to do it: http://www.expertsrt.com/tutorials/Matt/perlPAR.html I followed the instructions (I am using PAR and PAR-Packer version 0.976). It works fine on my Mac, but If I take an executable to an XP machine I get the following error message: Program too big to fit in memory even though it's just a simple hello world! program that's 3MB on disk. Anyone know what could be causing this? Are you trying to run the OS X executable you created with pp on XP? The executables are not portable between operating systems (the par files can be if they don't contain XS based modules). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Trouble with Perl Standalone Executable
Oh, I thought that they might be portable between OSs. My bad. Chas. Owens [EMAIL PROTECTED] wrote: On 10/26/07, Yoyoyo Yoyoyoyo wrote: Hi all, I was interested in compiling my Perl code. I came across the following site that shows how to do it: http://www.expertsrt.com/tutorials/Matt/perlPAR.html I followed the instructions (I am using PAR and PAR-Packer version 0.976). It works fine on my Mac, but If I take an executable to an XP machine I get the following error message: Program too big to fit in memory even though it's just a simple hello world! program that's 3MB on disk. Anyone know what could be causing this? Are you trying to run the OS X executable you created with pp on XP? The executables are not portable between operating systems (the par files can be if they don't contain XS based modules). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Re: Trouble with Perl Standalone Executable
On 10/26/07, Yoyoyo Yoyoyoyo [EMAIL PROTECTED] wrote: Oh, I thought that they might be portable between OSs. My bad. PAR files can be: http://search.cpan.org/~smueller/PAR-0.976/lib/PAR/Tutorial.pod#Cross-platform_Packages But the binaries created by pp can't: http://search.cpan.org/~smueller/PAR-0.976/lib/PAR/FAQ.pod#On_what_platforms_can_I_run_PAR?_On_what_platforms_will_the_resulting_executable_run? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Trouble with activestate perl for windows
Every time I try to use perl 5.8.8 I keep geting the error message Barewood found where operator expected at - line 1, near /perl/bin Missing operator before bin? What am I doing wrong here and how can I fix it. I'm using activestate perl. The command I'm trying is C:/Perl/bin/perl5.8.8.exe perl -v. Any help would be appreciated. TIA Steve -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Trouble with activestate perl for windows
On 8/29/07, Caduceus [EMAIL PROTECTED] wrote: Every time I try to use perl 5.8.8 I keep geting the error message Barewood found where operator expected at - line 1, near /perl/bin Missing operator before bin? What am I doing wrong here and how can I fix it. The message says that you're running a Perl program named '-', and the error was discovered while processing line 1 of that file, where the source text said something like /perl/bin. The file probably isn't named with just a hyphen; that's the name Perl uses when the program didn't come from a true file (for example, when the program is supplied on STDIN, or via the -e run-time switch). I'm using activestate perl. The command I'm trying is C:/Perl/bin/perl5.8.8.exe perl -v. I'm not a Windows user, so I can't check this. But I think that the free word perl in that command line is superfluous, isn't it? Maybe you want this command: C:/Perl/bin/perl5.8.8.exe -v Good luck with it! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Trouble with activestate perl for windows
On 29 Aug, 22:17, [EMAIL PROTECTED] (Caduceus) wrote: Every time I try to use perl 5.8.8 I keep geting the error message Barewood found where operator expected at - line 1, near /perl/bin Missing operator before bin? What am I doing wrong here and how can I fix it. I'm using activestate perl. The command I'm trying is C:/Perl/bin/perl5.8.8.exe perl -v. Any help would be appreciated. TIA Steve If you relay write C:/Perl/bin/perl5.8.8.exe perl -v. this is wrong you are running a exe file that dont exits erl5.8.8.exe with perl as a parameter, and thats is what the errro says. 1. The installation from activestate normal add the path to perl for you so test writing perl -v if not test C:/Perl/bin/perl -v // Anders. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Trouble with activestate perl for windows
On 29 Aug, 22:17, [EMAIL PROTECTED] (Caduceus) wrote: Every time I try to use perl 5.8.8 I keep geting the error message Barewood found where operator expected at - line 1, near /perl/bin Missing operator before bin? What am I doing wrong here and how can I fix it. I'm using activestate perl. The command I'm trying is C:/Perl/bin/perl5.8.8.exe perl -v. Any help would be appreciated. TIA Steve try perl -v or C:/Perl/bin/perl -v -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: $/ variable trouble
On 8/24/07, Yoyoyo Yoyoyoyo [EMAIL PROTECTED] wrote: Hi all, I am using the diamond operator to redirect input to my perl script. I want to copy all of the input on to a single variable using the following subroutine: sub getfile # Copies the file redirected to this perl script to the varialbe $x { my $x; local $/ = undef; $x = ; return $x; } The problem is that when I try to print what the above subroutine returns, the program kindof hangs. That is, it doesn't just print the output and then send me back to the command line, instead I have to press Ctrl-c to break out of it, like it is expecting input from the keyboard. Any help is appreciated, Robert The Perl operator, , reads from STDIN. To pipe a file to STDIN, you need to run the script like so: script.pl file_to_pipe Please note the '' If you do this: script.pl file_to_read the filename gets put onto $ARGV[0]. You can open the file inside Perl like so (untested code): die Please run like: $0 filename\n if (not -f $ARGV[0]); open $filehandle, $ARGV[0]; my $x; local $/ = undef; $x = $filehandle; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
$/ variable trouble
Hi all, I am using the diamond operator to redirect input to my perl script. I want to copy all of the input on to a single variable using the following subroutine: sub getfile # Copies the file redirected to this perl script to the varialbe $x { my $x; local $/ = undef; $x = ; return $x; } The problem is that when I try to print what the above subroutine returns, the program kindof hangs. That is, it doesn't just print the output and then send me back to the command line, instead I have to press Ctrl-c to break out of it, like it is expecting input from the keyboard. Any help is appreciated, Robert - Luggage? GPS? Comic books? Check out fitting gifts for grads at Yahoo! Search.
Re: $/ variable trouble
Yoyoyo Yoyoyoyo wrote: Hi all, I am using the diamond operator to redirect input to my perl script. I want to copy all of the input on to a single variable using the following subroutine: sub getfile # Copies the file redirected to this perl script to the varialbe $x { my $x; local $/ = undef; $x = ; return $x; } The problem is that when I try to print what the above subroutine returns, the program kindof hangs. That is, it doesn't just print the output and then send me back to the command line, instead I have to press Ctrl-c to break out of it, like it is expecting input from the keyboard. If you're reading from STDIN, you have to send an end-of-file marker. In Windows, press control-Z on an empty line. In *NIX, control-D. -- Just my 0.0002 million dollars worth, Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle If you think Terrans are comprehensible, you don't understand them. Great Fang Talphon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: $/ variable trouble
Yoyoyo Yoyoyoyo wrote: Is there anyway to add the End of file marker to the variable before I print it, so I don't have to do ctrl-d? The control-D is part of the shell, not Perl. You didn't say so but from your message I assume that this did the trick. In other words, you are not redirecting the file as you think you are; your program is still trying to read STDIN. -- Just my 0.0002 million dollars worth, Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle If you think Terrans are comprehensible, you don't understand them. Great Fang Talphon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: $/ variable trouble
On Aug 24, 1:12 pm, [EMAIL PROTECTED] (Yoyoyo Yoyoyoyo) wrote: Hi all, I am using the diamond operator to redirect input to my perl script. I want to copy all of the input on to a single variable using the following subroutine: sub getfile # Copies the file redirected to this perl script to the varialbe $x { my $x; local $/ = undef; $x = ; return $x; } The problem is that when I try to print what the above subroutine returns, the program kindof hangs. That is, it doesn't just print the output and then send me back to the command line, instead I have to press Ctrl-c to break out of it, like it is expecting input from the keyboard. I'm willing to bet you're calling your script by doing: $ ./file.pl text.txt when you should be doing: $ ./file.pl text.txt That is, let read from the command line argument, rather than having it read from STDIN and redirecting the process's STDIN to be from this file. Paul Lalli -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
trouble reading subdirectories and files in a directory
Running Perl on WinXP I would like to read the subdirectories and their respective files, that I have on my F: drive. They are arranged hierarchically, with a directory for each year, each of which contains a directory for each month, each of which contains files named for days. Like this: F: 2005 Jan2005 01-01-2005.txt 01-03-2005.txt Feb2005 02-01-2005.txt and so on. F: contains four directories: 2005, 2006, 2007 and Students There are also a few odd files stored directly in F: I am not interested in reading those, or doing anything with them. The problem is, they too get read and listed by my code. Here's what I have so far: -- my $line;# this is for use later, to read the contents of each file my $herenow; # my @linelist # also for use later use Cwd; chdir 'F:/DICTATIONS' or die $!; $herenow = getcwd; # check to see where I am. print $herenow; opendir TOTALHANDLE, . or die Couldn't open the specified directory: $!; while ($yearly = readdir(TOTALHANDLE)) { print $yearly \n; opendir YH, F:/DICTATIONS/$yearly or die Couldn't open the specified directory: $!; while ($monthly = readdir(YH)) { print $monthly \n; } } --- And here's the output of the above code [my comments are in square brackets]: C:\DATA\computer stuff\PerlStuffperl -w ExtractPatients2.pl F:/DICTATIONS. . .. Students 2005 2006 2007 .. [the assortment of odd files listed here] NonTextDictations [a directory inside F:] Students . .. [list of files inside F:\DICTATIONS\Students] 2005 . .. January2005 February2005 March2005 April2005 May2005 June2005 July2005 August2005 September2005 October2005 November2005 December2005 2006 . .. January2006 February2006 March2006 April2006 May2006 June2006 July2006 August2006 September2006 October2006 November2006 December2006 2007 . .. January2007 February2007 March2007 April2007 May2007 June2007 C:\DATA\computer stuff\PerlStuff I want to list only the monthly subdirectories inside each yearly subdirectory inside the directory DICTATIONS on F:. I don't want the assorted loose files that are stored directly on F:, outside of a subdirectory. And I can't understand why they are getting listed here, if my working directory is set properly to F:\DICTATIONS (which I think it is) and not to F:\ Appreciate any advice. Thanks. --Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: trouble reading subdirectories and files in a directory
Thanks. I was vaguely aware of modules that would do this. Doing it by hand at first is a good learning exercise for me. I can indeed check to see if the thing I'm looking at is a directory. But why does it do this? Can you help me understand why when I think I am in one directory, my script reads files one level up? Thanks. --Chris yitzle wrote: 1) There are filesystem modules already out there. 2) You might want to consider using a more generic recursive structure. 3) To answer your question, check its a directory and not a file. while ($yearly = readdir(TOTALHANDLE)) { next unless (-d $yearly); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Trouble installing with CPAN
I tried to install Crypt::Simple using the CPAN shell It failed at downloading the module multiple times from multiple servers. I got: Please check, if the URLs I found in your configuration file (ftp://CPAN.mirror.rafal.ca/pub/CPAN/, ftp://cpan.sunsite.ualberta.ca/pub/CPAN/, ftp://ftp.nrc.ca/pub/CPAN/, ftp://ftp.yi.org/CPAN/, ftp://mirror.arcticnetwork.ca/pub/CPAN, ftp://theoryx5.uwinnipeg.ca/pub/CPAN/) are valid. The urllist can be edited. E.g. with 'o conf urllist push ftp://myurl/' Um... any ideas why this occured? Are the servers down? Or should I try disabling my firewall? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Trouble installing with CPAN
I took down the firewall and got the same results. Could not fetch authors/id/K/KA/KASEI/Crypt-Simple-0.06.tar.gz Giving up on '/home/Admin/.cpan/sources/authors/id/K/KA/KASEI/Crypt-Simple-0.06.tar.gz' Note: Current database in memory was generated on Sat, 05 May 2007 21:09:57 GMT On 6/20/07, yitzle [EMAIL PROTECTED] wrote: I tried to install Crypt::Simple using the CPAN shell It failed at downloading the module multiple times from multiple servers. I got: Please check, if the URLs I found in your configuration file (ftp://CPAN.mirror.rafal.ca/pub/CPAN/, ftp://cpan.sunsite.ualberta.ca/pub/CPAN/, ftp://ftp.nrc.ca/pub/CPAN/, ftp://ftp.yi.org/CPAN/, ftp://mirror.arcticnetwork.ca/pub/CPAN, ftp://theoryx5.uwinnipeg.ca/pub/CPAN/) are valid. The urllist can be edited. E.g. with 'o conf urllist push ftp://myurl/' Um... any ideas why this occured? Are the servers down? Or should I try disabling my firewall? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Trouble installing with CPAN
On 6/20/07, yitzle [EMAIL PROTECTED] wrote: I tried to install Crypt::Simple using the CPAN shell Can you install other modules using the CPAN shell? Can you install this module without the CPAN shell? It seems to be available here: http://search.cpan.org/CPAN/authors/id/K/KA/KASEI/Crypt-Simple-0.06.tar.gz Why do you want this module? There may be better ones for whatever you're doing. Note: Current database in memory was generated on Sat, 05 May 2007 21:09:57 GMT That sounds as if your machine can't connect to CPAN to get a newer database, maybe. 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/
Re: Trouble installing with CPAN
On 06/20/2007 08:40 AM, yitzle wrote: I took down the firewall and got the same results. Could not fetch authors/id/K/KA/KASEI/Crypt-Simple-0.06.tar.gz Giving up on '/home/Admin/.cpan/sources/authors/id/K/KA/KASEI/Crypt-Simple-0.06.tar.gz' Note: Current database in memory was generated on Sat, 05 May 2007 21:09:57 GMT May 5th is too long ago. Those mirrors might not be up-to-date; they might not even be CPAN mirrors anymore. I suggest going through the entire CPAN configuration again: o conf init; you'll get a chance to select a new set of mirrors and other options. Probably the indexes will be re-downloaded after you've finished the configuration, but if they're not, do reload index -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
RE: Having trouble porting an application to MS-Windows
-Original Message- From: Chas Owens [mailto:[EMAIL PROTECTED] Sent: Friday, June 15, 2007 7:43 PM To: Bob McConnell Cc: beginners@perl.org Subject: Re: Having trouble porting an application to MS-Windows On 6/15/07, Bob McConnell [EMAIL PROTECTED] wrote: -Original Message- From: Chas Owens [mailto:[EMAIL PROTECTED] Sent: Friday, June 15, 2007 11:33 AM To: Bob McConnell Cc: beginners@perl.org Subject: Re: Having trouble porting an application to MS-Windows On 6/15/07, Bob McConnell [EMAIL PROTECTED] wrote: snip Or have I found a bug in the ActiveState implementation? snip Are you currently paying for ActiveState support? If so, I would suggest filing a ticket with them. In the mean time, try modifying my code to do a sysread from a socket. No, we are not officially using the ActiveState tools. Only a few of us recognize that anything other than VBScript might actually be useful. I'll have to set up a socket that won't return anything and try that. If that times out as expected, then it looks like a bug report will be needed. Thank you, Bob McConnell Even if it does timeout a bug may still need to be filed. I just want to understand the scope of the problem first and I don't have easy access to an XP machine at the moment. What I can define so far: Win2K Pro SP4 fully patched. Dell Optiplex GX270, 3.0 GHz, 1GB RAM. ActivePerl 5.8.8.820 installed after uninstalling 5.8.0.806. Code snippet was sent earlier in this thread. Attempting to set an alarm for 3 seconds then call sysread() on a serial port within an eval, as per the recommended form. The eval will never return without receiving a character on the port. SIGBRK does get caught and terminates the script. I have not yet tried this on a socket. I don't see anything that matches in the ActiveState bug tracker, but I don't have an ASPN account needed to add bug reports. I am looking at their community support forum. A search there on alarm sysread does not produce any results. It looks like I need to create an account there before I can post a message. Thank you, Bob McConnell If you notice anything funny, record the amount of funny. Milligan's law as reported by Bob Pease. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
RE: Having trouble porting an application to MS-Windows - corrected
-Original Message- From: Chas Owens [mailto:[EMAIL PROTECTED] Sent: Friday, June 15, 2007 7:43 PM To: Bob McConnell Cc: beginners@perl.org Subject: Re: Having trouble porting an application to MS-Windows On 6/15/07, Bob McConnell [EMAIL PROTECTED] wrote: -Original Message- From: Chas Owens [mailto:[EMAIL PROTECTED] Sent: Friday, June 15, 2007 11:33 AM To: Bob McConnell Cc: beginners@perl.org Subject: Re: Having trouble porting an application to MS-Windows On 6/15/07, Bob McConnell [EMAIL PROTECTED] wrote: snip Or have I found a bug in the ActiveState implementation? snip Are you currently paying for ActiveState support? If so, I would suggest filing a ticket with them. In the mean time, try modifying my code to do a sysread from a socket. No, we are not officially using the ActiveState tools. Only a few of us recognize that anything other than VBScript might actually be useful. I'll have to set up a socket that won't return anything and try that. If that times out as expected, then it looks like a bug report will be needed. Thank you, Bob McConnell Even if it does timeout a bug may still need to be filed. I just want to understand the scope of the problem first and I don't have easy access to an XP machine at the moment. What I can define so far: Win2K Pro SP4 fully patched. Dell Optiplex GX270, 3.0 GHz, 1GB RAM. ActivePerl 5.8.8.820 installed after uninstalling 5.8.0.806. Code snippet was sent earlier in this thread. Attempting to set an alarm for 3 seconds then call sysread() on a serial port within an eval, as per the recommended form. The eval will never return without receiving a character on the port. SIGBRK does get caught and terminates the script. I have not yet tried this on a socket. --- Sorry, that should be SIGINT, from CTRL-BREAK! I don't see anything that matches in the ActiveState bug tracker, but I don't have an ASPN account needed to add bug reports. I am looking at their community support forum. A search there on alarm sysread does not produce any results. It looks like I need to create an account there before I can post a message. Thank you, Bob McConnell If you notice anything funny, record the amount of funny. Milligan's law as reported by Bob Pease. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Having trouble porting an application to MS-Windows
On 6/15/07, Bob McConnell [EMAIL PROTECTED] wrote: snip eval { local $SIG{ALRM} = sub { die alarm\n }; # NB: \n required alarm $timeout; $nread = sysread PORT, $line, 1; alarm 0; }; snip This transmits the packet, but never comes out of the eval() if it doesn't receive a character. Is there anything obvious that I missed? snip Hmm, that codes looks right. Do the two scripts I sent earlier work? Even if this does work, can I set simultaneous alarms in multiple threads? Yes, I sent an example that worked for me with ActiveState's latest version on WinXP. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
RE: Having trouble porting an application to MS-Windows
-Original Message- From: Chas Owens [mailto:[EMAIL PROTECTED] Sent: Thursday, June 14, 2007 12:10 PM To: Bob McConnell Cc: beginners@perl.org Subject: Re: Having trouble porting an application to MS-Windows On 6/14/07, Chas Owens [EMAIL PROTECTED] wrote: On 6/14/07, Bob McConnell [EMAIL PROTECTED] wrote: In perlport - Writing portable Perl in the Alphabetic list of Perl Functions: alarm SECONDS alarm Not implemented. (Win32) I couldn't find anything in the ActiveState release notes that contradicted that. snip the latest version of ActiveState Perl on Windows XP works. snip Are you using the latest version of ActiveState Perl? I installed the latest version this morning to test the code I sent and when I run perldoc -T perlport | find /i alarm I get not output. The first three functions listed are -X, atan2, and binmode. In fact, the reference to alarm drops out of perlport in version 5.8.3 (released in 2004). from Perl 5.8.3's Changes file [ 21895] alarm() is now implemented on Win32. I still can't get it to work, even without the fork. I am now running ActivePerl 5.8.8.820 on Win2K SP4. Here are the code snippets after pasting in the recommended alarm handling: --- $port = 'COM4' unless $port; $SIG{'INT'} = 'dokill'; # this allows me to kill it with CTRL-Break sub dokill { kill 9,$child if $child; } sysopen( PORT, $port, O_RDWR ) or die Can't sysopen $port: $!; binmode(PORT); LINE: while (IN) {# Input records from input file. chomp; # loop on NAK or timeout with two retries $done = 0; $tries = 0; do { syswrite PORT, $_, length; $timeout = 3; eval { local $SIG{ALRM} = sub { die alarm\n }; # NB: \n required alarm $timeout; $nread = sysread PORT, $line, 1; alarm 0; }; if ($@) { die unless $@ eq alarm\n; # propagate unexpected errors # timed out print STDOUT t/o; } else { fprint STDOUT sysread returned %d.\n, $nread; if (ord $line == 21) { print STDOUT NAK; } if (ord $line == 6) { print STDOUT ACK; $done = 1; } } } while ($done == 0 ++$tries 3); print STDOUT \n; if ($done == 0) { next LINE; } #send response and wait for ACK/NAK here } --- This transmits the packet, but never comes out of the eval() if it doesn't receive a character. Is there anything obvious that I missed? Even if this does work, can I set simultaneous alarms in multiple threads? Thank you, Bob McConnell -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
RE: Having trouble porting an application to MS-Windows
-Original Message- From: Chas Owens [mailto:[EMAIL PROTECTED] Sent: Friday, June 15, 2007 10:55 AM To: Bob McConnell Cc: beginners@perl.org Subject: Re: Having trouble porting an application to MS-Windows On 6/15/07, Bob McConnell [EMAIL PROTECTED] wrote: snip eval { local $SIG{ALRM} = sub { die alarm\n }; # NB: \n required alarm $timeout; $nread = sysread PORT, $line, 1; alarm 0; }; snip This transmits the packet, but never comes out of the eval() if it doesn't receive a character. Is there anything obvious that I missed? snip Hmm, that codes looks right. Do the two scripts I sent earlier work? Yes, both work with the output below. The difference is that both of yours interrupt an empty while loop, but my code is in a sysread() call. The SIGINT I use to kill the process can interrupt the system call, but will the alarm? Or have I found a bug in the ActiveState implementation? Bob McConnell D:\Perl\eg\SIMscriptperl forka.pl Fri Jun 15 11:16:36 2007 timeout Fri Jun 15 11:16:39 2007 D:\Perl\eg\SIMscriptperl forkb.pl parent Fri Jun 15 11:12:57 2007 parent waiting 10 seconds child Fri Jun 15 11:12:57 2007 child waiting 1 seconds timeout child child Fri Jun 15 11:12:58 2007 timeout parent parent Fri Jun 15 11:13:07 2007 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Having trouble porting an application to MS-Windows
On 6/15/07, Bob McConnell [EMAIL PROTECTED] wrote: snip Or have I found a bug in the ActiveState implementation? snip Are you currently paying for ActiveState support? If so, I would suggest filing a ticket with them. In the mean time, try modifying my code to do a sysread from a socket. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
RE: Having trouble porting an application to MS-Windows
-Original Message- From: Chas Owens [mailto:[EMAIL PROTECTED] Sent: Friday, June 15, 2007 11:33 AM To: Bob McConnell Cc: beginners@perl.org Subject: Re: Having trouble porting an application to MS-Windows On 6/15/07, Bob McConnell [EMAIL PROTECTED] wrote: snip Or have I found a bug in the ActiveState implementation? snip Are you currently paying for ActiveState support? If so, I would suggest filing a ticket with them. In the mean time, try modifying my code to do a sysread from a socket. No, we are not officially using the ActiveState tools. Only a few of us recognize that anything other than VBScript might actually be useful. I'll have to set up a socket that won't return anything and try that. If that times out as expected, then it looks like a bug report will be needed. Thank you, Bob McConnell -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Having trouble porting an application to MS-Windows
On 6/15/07, Bob McConnell [EMAIL PROTECTED] wrote: -Original Message- From: Chas Owens [mailto:[EMAIL PROTECTED] Sent: Friday, June 15, 2007 11:33 AM To: Bob McConnell Cc: beginners@perl.org Subject: Re: Having trouble porting an application to MS-Windows On 6/15/07, Bob McConnell [EMAIL PROTECTED] wrote: snip Or have I found a bug in the ActiveState implementation? snip Are you currently paying for ActiveState support? If so, I would suggest filing a ticket with them. In the mean time, try modifying my code to do a sysread from a socket. No, we are not officially using the ActiveState tools. Only a few of us recognize that anything other than VBScript might actually be useful. I'll have to set up a socket that won't return anything and try that. If that times out as expected, then it looks like a bug report will be needed. Thank you, Bob McConnell Even if it does timeout a bug may still need to be filed. I just want to understand the scope of the problem first and I don't have easy access to an XP machine at the moment. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Having trouble porting an application to MS-Windows
Good morning, The code listed below is part of a link level serial protocol that doesn't port to Win32. A framed message with a checksum is sent and then a single character response (ACK or NAK) is expected in return. On the Win32 platform, this form of select is only implemented for sockets, and alarm() is not implemented at all. How can I set up a sysread() with an adjustable timeout on a device in MS-Windows? $port = 'COM4' unless $port; sysopen( PORT, $port, O_RDWR ) or die Can't sysopen $port: $!; binmode(PORT); # loop on NAK or timeout with two retries $done = 0; $tries = 0; do { syswrite PORT, $_, length; $rin = $win = $ein = ''; vec($rin, fileno(PORT), 1) = 1; vec($win, fileno(PORT), 1) = 1; $ein = $rin | $win; $timeout = 3.0; ($nfound,$timeleft) = select($rout=$rin, $wout=$win, $eout=$ein, $timeout); if ($nfound 0) { $inchar = sysread PORT, $line, 1, 0; if (ord ($line) == 21) { print STDOUT NAK; } if (ord ($line) == 6) { print STDOUT ACK; $done = 1; } } else { print STDOUT t/o; } } while ($done == 0 ++$tries 3); print STDOUT \n; if ($done == 0) { next LINE; } I have ActiveState Perl 5.8.0.806 or Cygwin with Perl 5.6.1 available. Both versions are parts of SDK's which prevent me from upgrading. I tried to install Linux in a VM session, but I don't have a recent enough version of VMWare to do so, and my manager has refused to allow me to update that one either. (He said something about being too near the end of the fiscal year.) NOTA BENE: I don't do objects. After 30 years of procedural code, they don't make any sense to me, on several levels. I have looked at Win32-SerialPort-0.19 but can't make heads nor tails of it. Thank you, Bob McConnell Principal Communications Programmer The CBORD Group, Inc. 61 Brown Road Ithaca NY, 14850 Phone 607 257-2410 FAX 607 257-1902 Email [EMAIL PROTECTED] Web www.cbord.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/