Ben Humphreys

  • Archive
  • RSS

Perl variables and apostrophes

This came up recently. I’d been using #2 for a while but never hit #1 which was a surprise.

my $person = "Ben";
print "Check out $person's cat\n"; #1
print "Say hi to '$person'\n"; #2
print "What about $person\'s hat\n"; #3

Output:
Name "person::s" used only once: possible typo at test.pl line 6.
Use of uninitialized value in concatenation (.) or string at test.pl line 6.
Check out  cat
Say hi to 'Ben'
What about Ben's hat
    • #perl
    • #programming
  • 2 years ago
  • Comments
  • Permalink
  • Share
    Tweet

Recent comments

Blog comments powered by Disqus
← Previous • Next →

About

Avatar Computational linguistics researcher at Kyoto University, focussing on machine translation. Also learning Japanese, Korean, French and other badassery.
(日本語版)

Me, Elsewhere

  • @benhumphreys on Twitter
  • benhumphreys on github
  • RSS
  • Random
  • Archive
  • Mobile

Effector Theme by Carlo Franco.

Powered by Tumblr