Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: Is there a way to compare strings without using an array? (say)

by toolic (Bishop)
on Oct 18, 2011 at 19:45 UTC ( [id://932230]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Is there a way to compare strings without using an array?
in thread Is there a way to compare strings without using an array?

Bareword "say" not allowed while "strict subs"
perldoc -f say
use feature 'say';

Replies are listed 'Best First'.
Re^4: Is there a way to compare strings without using an array? (say)
by Jeri (Scribe) on Oct 18, 2011 at 19:51 UTC
    thanks, it's working
Re^4: Is there a way to compare strings without using an array? (say)
by Jeri (Scribe) on Oct 18, 2011 at 20:00 UTC

    Why is it necessary to use 'say'? If I took out..

    use feature 'say';

    and the 'say' in...

     say for $line1 =~ /[$line2]/g;

    Why doesn't it work?

      The reason is because say is not (yet) a built-in function. You have to import the function into your namespace first, hence use feature 'say';

      Alternatively, you can just use print, which does not implicitly add the new line for you like say does.

      print "$_\n" for $line1 =~ /[$line2]/g;
      You can also add the -l (dash elle) modifier to your "shebang" line which essentially makes print behave like say:
      #!/path/to/perl -l ... print for $line1 =~ /[$line2]/g;
      Hope this helps!

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      

        say is a builtin function since 5.010. feature has never exported say. feature tells the parser that say should use the builtin say instead of the sub say.

      use feature qw( say ); or equivalent is required for backwards compatibility reasons. Many scripts and modules already had a sub named say when say was added to Perl, so it's not available by default in order to avoid breaking these scripts and modules.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://932230]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-03-19 10:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found