a0=2
a1=a0
a0=4
puts"display value : a1 = #{a1} , a0 = #{a0}"
=> display value : a1 = 4 , a0 = 4
I understand that's normal result but on perl we don't have same thing. I don't use Moose, Mouse or Moo...
]]>>> ruby -v ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]
>> ruby a0=2 a1=a0 a0=4 puts"display value : a1 = #{a1}, a0 = #{a0}" ^D
display value : a1 = 2, a0 = 4
Also, I don't see any discrepancy between Perl and Ruby.
>> perl -v This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi
>> perl $a0 = 2; $a1 = $a0; $a0 = 4; print "display value : a1 = $a1, a0 = $a0\n"; ^D>/pre>]]>display value : a1 = 2, a0 = 4
In Ruby, \h and \H mean \p{Hex} and \P{Hex}, respectively; In Perl they mean \p{VertSpace} and \P{VertSpace} instead.
\p{Age=6.0} is \p{Present_In: 6.0} in Perl -- \p{Age=6.0} will match for characters introduced in Unicode 6.0, -and nothing else-.
[[:space:]] does not match \x{85}.
You can't do character class subtraction and intersection.
\d and friends match much more than ASCII.
There is no \s escape meaning "space" in double quoted strings.
While qw() is the same as %w(), there is no such thing as %W(). Which is a damn shame.
You can't use
Comments embedded in regexs can't have the delimiter in them; Both /\A(?#:foo\)bar)\z/ and
m/
. #This is a comment /
/x
will result in compilation errors.
Perl's support for variable length lookbehind's is a bit worse than Ruby's, sorta. Neither supports (?
(I might have the next bit wrong -- I recall this biting me in my old work, but not the exact details)
Variables are function-scoped in Ruby. So
def whatever
if 1
a = 10
end
puts a
end
Will output 10 -- Whereas the same block in Perl
sub whatever {
if ( 1 ) {
my $a = 10;
}
say $a;
}
Will either die horribly under strict, or output whatever is in the package-scoped variable $a when the function executes.
$x =~ s/// will modify $x in place, like x.sub!would; The equivalent of x.sub is using the /r flag, like $x =~ s///r
Given an array a = [ 1, 2, 3, 4, 5 ], a[1..3] and a[1,3] mean the same thing, and will both return a 3-element array. The equivalent code in Perl, @a[1..3] and @a[1,3], will return a 3 and 2 element list, respectively.
(I could be at this all night... :P)
]]>FWIW, according to Ghostery, blogs.perl.org doesn't include any of the usual ad/tracking junk, so you'd have to get their server logs to get your "analytics."
]]>In my Learning Perl classes, I teach people to reach list things from the end toward the beginning (which is what the autobox does by ordering operations). If you don't figure that out, reading the unparenthesized form is difficult for newbies merely because they don't know where to start to break things into the different operations. It doesn't matter how I feel about that, either. My opinion is completely irrelevant. I know that some newbies have trouble with the lack of parentheses.
People make a big deal out of the ease of writing. That's hardly ever my problem. I certainly don't write code by starting with the first character and typing the next character until I get to the end. I make a big mess, usually coding inside out, and make it look pretty as I debug and refine it. I usually don't end up with whatever I started with. Ease of writing has never been high on my list. Working code that other people can read is much more important to me. The problem, though, is who those other people are. Things that I can easily read aren't necessarily things that other people can easily read, no matter how easily I wrote it.
]]>say
and print
as functions instead of methods to put emphasis on the IO operation as opposed to simply munging a string.
say $string->split(' ')->reverse->join(' ');
or even better in Perl 6:
say $string.words.reverse.join(' ');
Note that words
in Perl 6 splits on any amount of whitespace characters, which would probably be more desirable in this case anyway.
I'm really not familiar with perl6 but split ' ' in perl5 also splits on any amount of whitespace characters (and strips preceeding/trailing whitespace as well), so I think those two are probably equivalent?
]]>words
in Perl 6 is equivalent to split ' '
in Perl 5. In Perl 6, ' '
is not a special pattern for split
. In general, the language is much more predictable than it's predecessor, except for certain elements of the language like the ~~
(smartmatch) operator and the *
(whatever) term. When you see those, expect some magic!
Completely different say
and print
methods are provided for IO
objects, which I think is a much better use of them than the ones on Str
objects. For example:
$filehandle->say($string);
Too often we (and I say "we" because I include myself) belittle instead of helping someone learn.
I sympathise with what JT is saying, and hopefully I'll be able to personally make that distinction even more in the future.
]]>