Naming subroutines WAS: special method name start with _
What is considered to be the proper way of naming internal subroutines? Example: my_special_subroutine or mySpecialSubroutine -Original Message- From: Uri Guttman [mailto:u...@stemsystems.com] Sent: Thursday, April 28, 2011 12:50 AM To: Shawn H Corey Cc: beginners@perl.org Subject: Re: special method name start with _ Importance: High SHC == Shawn H Corey shawnhco...@ncf.ca writes: SHC On 11-04-28 12:20 AM, Uri Guttman wrote: methods starting with _ are conventionally private methods. SHC Actually, I think they are protected methods. Those methods that SHC should not be access by other objects but can be by their child SHC classes. A truly private method can be written as a sub reference: SHC my $private_method = sub { SHC # good stuff goes here SHC }; SHC Since $private_method can not be access outside of the file, it is SHC completely private. and that isn't a method since it isn't in the symbol table. what you have there is a private sub. methods must be visible to be found at runtime. that sub isn't visible to anything except code in that block or file. the _ prefix is the only common way to mark a private OR protected method as perl doesn't directly provide any support for it. moose and other OO systems may support this. uri -- Uri Guttman -- u...@stemsystems.com http://www.sysarch.com -- - Perl Code Review , Architecture, Development, Training, Support -- - Gourmet Hot Cocoa Mix http://bestfriendscocoa.com - -- 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: Naming subroutines WAS: special method name start with _
2011/4/28 Tim Lewis twle...@sc.rr.com: What is considered to be the proper way of naming internal subroutines? Example: my_special_subroutine or mySpecialSubroutine neither. But it could be: _my_special_subroutine -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
regular expression
hi, i have following code. $target = abc,xyz; print $target\n; $target =~ s/,/\s/g; print $target\n; i need to replace comma with whitespace for string abc,xyz the output shud be abc xyz the above regular expression does not do that . please suggest --irfan
Re: regular expression
Irfan Sayed wrote: hi, Hello, i have following code. $target = abc,xyz; print $target\n; $target =~ s/,/\s/g; print $target\n; i need to replace comma with whitespace for string abc,xyz Whitespace is something that applies only to regular expressions but the second part of the substitution operator is just a string, not a regular expression. And which of the five whitespace characters should this string interpolate \s as: , \r, n, t or \f? the output shud be abc xyz the above regular expression does not do that . please suggest $target =~ tr/,/ /; 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: regular expression
John W. Krahn wrote: Irfan Sayed wrote: i have following code. $target = abc,xyz; print $target\n; $target =~ s/,/\s/g; print $target\n; i need to replace comma with whitespace for string abc,xyz Whitespace is something that applies only to regular expressions but the second part of the substitution operator is just a string, not a regular expression. And which of the five whitespace characters should this string interpolate \s as: , \r, n, t or \f? Should be: , \r, \n, \t or \f 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: regular expression
On 11-04-28 10:05 AM, Irfan Sayed wrote: hi, i have following code. $target = abc,xyz; print $target\n; $target =~ s/,/\s/g; print $target\n; i need to replace comma with whitespace for string abc,xyz the output shud be abc xyz the above regular expression does not do that . please suggest --irfan The white space meta-character does not work on the replace side of a substitution. Use a space character: $target =~ s/\,/ /g; Some people prefer to use the hexadecimal format because in some fonts, it's hard to distinguish between // and / /. Having something visible makes the meaning clear. Like this: $target =~ s/\,/\x20/g; -- 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. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: regular expression
my logic was to just put the space character in place of comma and keep rest as it is but unfortunately that does not work thanks john for your trick it is working now From: John W. Krahn jwkr...@shaw.ca To: Perl Beginners beginners@perl.org Sent: Thursday, April 28, 2011 7:47 PM Subject: Re: regular expression Irfan Sayed wrote: hi, Hello, i have following code. $target = abc,xyz; print $target\n; $target =~ s/,/\s/g; print $target\n; i need to replace comma with whitespace for string abc,xyz Whitespace is something that applies only to regular expressions but the second part of the substitution operator is just a string, not a regular expression. And which of the five whitespace characters should this string interpolate \s as: , \r, n, t or \f? the output shud be abc xyz the above regular expression does not do that . please suggest $target =~ tr/,/ /; 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: regular expression
thanks all From: Shawn H Corey shawnhco...@ncf.ca To: beginners@perl.org Sent: Thursday, April 28, 2011 7:55 PM Subject: Re: regular expression On 11-04-28 10:05 AM, Irfan Sayed wrote: hi, i have following code. $target = abc,xyz; print $target\n; $target =~ s/,/\s/g; print $target\n; i need to replace comma with whitespace for string abc,xyz the output shud be abc xyz the above regular expression does not do that . please suggest --irfan The white space meta-character does not work on the replace side of a substitution. Use a space character: $target =~ s/\,/ /g; Some people prefer to use the hexadecimal format because in some fonts, it's hard to distinguish between // and / /. Having something visible makes the meaning clear. Like this: $target =~ s/\,/\x20/g; -- 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. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: special method name start with _
On Thu, 28 Apr 2011 13:21:56 +0800, Jeff Pang wrote: I may think Perl OO (not moose) doesn't have private or protected methods as other languages like Java/Ruby. _method can be accessed from anywhere. In your example, yes. But Moose *is* Perl's O-O, it's just a wrapper around it. Perl provides enough flexibility to do all kinds of things. See http://search.cpan.org/perldoc?MooseX::Privacy. (That's Moose-X, not Moo-Sex.) Class::Std can do this too. -- Peter Scott http://www.perlmedic.com/ http://www.perldebugged.com/ http://www.informit.com/store/product.aspx?isbn=0137001274 http://www.oreillyschool.com/courses/perl3/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Naming subroutines WAS: special method name start with _
TL == Tim Lewis twle...@sc.rr.com writes: TL What is considered to be the proper way of naming internal subroutines? TL Example: TL my_special_subroutine or mySpecialSubroutine again it is a convention but perl names (other than class names) are best done with _ as in my_special_subroutine. and if it is internal, prefix it with _ as well. uri -- Uri Guttman -- u...@stemsystems.com http://www.sysarch.com -- - Perl Code Review , Architecture, Development, Training, Support -- - Gourmet Hot Cocoa Mix http://bestfriendscocoa.com - -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: regular expression
- Original Message - From: Irfan Sayed irfan_sayed2...@yahoo.com To: John W. Krahn jwkr...@shaw.ca; Perl Beginners beginners@perl.org Sent: Thursday, April 28, 2011 9:28 AM Subject: Re: regular expression my logic was to just put the space character in place of comma and keep rest as it is but unfortunately that does not work Well, to be precise, your conceptual logic was fine; the implementation was flawed. As several have pointed out, you weren't replacing the comma with a _space_ *character*, but with the RegExp _whitespace_ *character class*. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: regular expression
KK == Karl Kaufman krk...@comcast.net writes: KK Well, to be precise, your conceptual logic was fine; the KK implementation was flawed. As several have pointed out, you KK weren't replacing the comma with a _space_ *character*, but with KK the RegExp _whitespace_ *character class*. to be really precise, there was no character class in that code. he was replacing the comma with the letter s. the right side of s/// is normally just a double quoted string and \s becomes just an s. this shows it: perl -le '$x = a,b ; $x =~ s/,/\s/; print $x' asb -- Uri Guttman -- u...@stemsystems.com http://www.sysarch.com -- - Perl Code Review , Architecture, Development, Training, Support -- - Gourmet Hot Cocoa Mix http://bestfriendscocoa.com - -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Net::SCP is saving a file name with a wild card
Hi, I need to pull a file or files down every day that contain a specific string. Here's my code. #!/usr/bin/perl use strict; use Net::SCP; my $scp=' '; open (LOG, /home/wesaysopost/logs/retrieve-wesayso-results.log) or die Can't open logfile; LOG- autoflush(1); print LOG Starting Retrieval Process; $scp = Net::SCP-new ( theserver.wesayso.com, mylogin); $scp-cwd(postingscript) or die Can't change directories; $scp-get (acme_posting*) or die Can't retrieve results; close LOG; exit; The file I'm retrieving is acme_posting20110415.txt (date changes every day) The file is found, but it's being saved as acme_posting* I'm not specifying a local file name when I get the file, why is SCP saving it under a different name? Thanks in Advance! Dave
Re: How to Generate An Expression to A LOL?
Hi, I've finished it using recursion. #!/usr/bin/perl -w use strict; use Data::Dumper; #不检查输入算式是否正确 print 输入自然数算式(只允许加法、乘法、括号)\n; print 输入完成按回车确认,退出请输入0\n\n; while (1) { print Enter the expression : ; chomp($_ = STDIN); last if not $_; my @tree = grow($_); print Dumper(\@tree); my $result = calculate(\@tree); print \nresult\=$result\n\n; my $answer = eval $_; print Still have bug,the correct answer is $answer\n if ($answer != $result); sub grow { my $expr = $_[0]; my ($part, @part, $node); if ($expr =~ /\(/){ @part = ($expr =~ / \( (?:(?[^()]+) | (?R))* \) /xg); #提取括号中内容 foreach $part (@part) { $part =~ s/^\(|\)$//g; my @temp = grow($part); #递归调用 $part = \@temp; } $expr =~ s/\( ((?[^()]+) | (?R))* \)/tag/xg; #原式中括号内容暂时用字符“tag”替代 } my @node= ($expr =~ /\d+|tag/g); #从算式中提取数字 my $i = 0; foreach $node (@node) { if ($node eq tag){ #tag内容还原成生成的树 $node = $part[$i]; $i++; } } my @op=($expr =~ /[+*()]/g); #从算式中提取算符 return basic (\@node, \@op); } sub basic { #将不含括号的算式转成树 my($a, $b, $i); ($a, $b) = @_; my @node = @$a; my @op = @$b; for($i = 0; $i @op; $i++){ #转换乘法 if ($op[$i] eq *){ my $end = $i+1; while (defined($op[$end])($op[$end] eq *)){ $end++ if $end @op; } my $t = $end - $i; my @new = @node[$i..$end]; unshift (@new, *); splice(@node, $i, $t+1, \@new); splice(@op, $i, $t,); } } if (@op){ unshift (@node, +); }else{ @node=@{$node[0]}; } return @node; } sub calculate{ my $a = $_[0]; return $a if ref($a) ne ARRAY; my @tree = @$a; my $tree; my $result = 0; if ($tree[0] eq +){ shift @tree; foreach $tree(@tree){ $result = $result + calculate($tree); } } elsif ($tree[0] eq *){ $result = 1; shift @tree; foreach $tree(@tree){ $result = $result * calculate($tree); } } return $result; } } 1; 08300720014-07.pl Description: Binary data -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: How to Generate An Expression to A LOL?
zs == z sway zzway...@gmail.com writes: zs Hi, I've finished it using recursion. zs #!/usr/bin/perl -w use warnings is better zs use strict; zs use Data::Dumper; zs while (1) { zs print Enter the expression : ; zs chomp($_ = STDIN); zs last if not $_; zs my @tree = grow($_); it is better to use a named variable than $_. $_ can cause issues as it is a global (recent perl's can make it lexical but still a name is better). zs print Dumper(\@tree); zs my $result = calculate(\@tree); zs print \nresult\=$result\n\n; = does not need escaping in strings. zs my $answer = eval $_; that is very dangerous, allowing user input to be evaled. do you need to do that? zs sub grow { zs my $expr = $_[0]; this is better: my ( $expr ) = @_ ; zs my ($part, @part, $node); don't declare vars until they are first used. zs if ($expr =~ /\(/){ you need to indent your code. it is very hard to read without it. zs @part = ($expr =~ / \( (?:(?[^()]+) | (?R))* \) /xg); #提取括号中 my @part = ... zs foreach $part (@part) { zs $part =~ s/^\(|\)$//g; zs my @temp = grow($part); #递归调用 zs $part = \@temp; no need for the @temp array. in fact if you name something temp, you likely don't need it at all. $part = [ grow($part) ] ; zs my $a = $_[0]; don't use $a (or $b) for your own variables. they are reserved for use by the sort function. also they are bad names in general as they don't tell the reader what they are for. uri -- Uri Guttman -- u...@stemsystems.com http://www.sysarch.com -- - Perl Code Review , Architecture, Development, Training, Support -- - Gourmet Hot Cocoa Mix http://bestfriendscocoa.com - -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
[OFF] OSS Perl Shopping Carts
Are there any current open source Perl shopping carts out there? The only carts I've been able to find are either ancient or are written in PHP. I know about Interchange, but it appears that you have to run an installer(?), which my ISP won't allow me to do (I can't switch ISP's just yet). Thanks, Marc -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Net::SCP is saving a file name with a wild card
On Apr 28, 9:31 am, dthack...@gmail.com (Dave Thacker) wrote: Hi, I need to pull a file or files down every day that contain a specific string. Here's my code. #!/usr/bin/perl use strict; use Net::SCP; my $scp=' '; open (LOG, /home/wesaysopost/logs/retrieve-wesayso-results.log) or die Can't open logfile; LOG- autoflush(1); print LOG Starting Retrieval Process; $scp = Net::SCP-new ( theserver.wesayso.com, mylogin); $scp-cwd(postingscript) or die Can't change directories; $scp-get (acme_posting*) or die Can't retrieve results; close LOG; exit; The file I'm retrieving is acme_posting20110415.txt (date changes every day) The file is found, but it's being saved as acme_posting* I'm not specifying a local file name when I get the file, why is SCP saving it under a different name? Because perl doesn't know what the actual wildcarded transfer will return before the call returns. If fact, several files might be returned. How would perl know which one was the target... So, the basename of the remote file is used to generate the local file name. In this case basename('acme_posting*') just becomes the identical name acme_posting* Any reason you can't just specify an exact filename each day.. for instance: ($day, $mon, $yr ) = (localtime time())[3,4,5]; $file = sprintf( acme_posting%d%02d%02d, $yr+1900, $mon, $day ); -- Charles DeRykus -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: :SCP is saving a file name with a wild card
Dave, in looking at the documentation for Net::SCP, it does not appear that it can accept a wildcard. It looks like it has to be the exact name of the file that you wish to retrieve. It might be creating a file with nothing in it. When it retrieves that file, is it really the file, or just a zero byte file? Tim -Original Message- From: Dave Thacker [mailto:dthack...@gmail.com] Sent: Thursday, April 28, 2011 12:31 PM To: beginners@perl.org Subject: Net::SCP is saving a file name with a wild card Hi, I need to pull a file or files down every day that contain a specific string. Here's my code. #!/usr/bin/perl use strict; use Net::SCP; my $scp=' '; open (LOG, /home/wesaysopost/logs/retrieve-wesayso-results.log) or die Can't open logfile; LOG- autoflush(1); print LOG Starting Retrieval Process; $scp = Net::SCP-new ( theserver.wesayso.com, mylogin); $scp-cwd(postingscript) or die Can't change directories; $scp-get (acme_posting*) or die Can't retrieve results; close LOG; exit; The file I'm retrieving is acme_posting20110415.txt (date changes every day) The file is found, but it's being saved as acme_posting* I'm not specifying a local file name when I get the file, why is SCP saving it under a different name? Thanks in Advance! Dave -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: [OFF] OSS Perl Shopping Carts
2011/4/29 sono...@fannullone.us: Are there any current open source Perl shopping carts out there? The only carts I've been able to find are either ancient or are written in PHP. I don't know there is such one. You may post to mod_perl and Perl CGI mailing lists to get more info. Regards. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/