Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I've done some reading but not that Perl 5 code can be dropped into Perl 6.

Indeed, you can not. But like the Queen's English vs American English, they look very much alike. With subtle differences. -> became ., . became ~, sigils don't vary, and you must put a comma after the block in a map. But by and large, you can write Perl 5-style in Perl 6, just as you can write C-style in Perl 5. Even moreso if you use P5built-ins, which exports a growing number of functions (currently at 100 or so) that exist in Perl 5, with the same semantics as in Perl 5. Think about things like tie, opendir, pack/unpack, but also things that exist in Perl 6 but have magic attached (such as shift shifting from @_ or @ARGV by default).

I thought barewords were bad practice.

Indeed they are, they don't exist in Perl 6. A sigilless variable needs to be defined: it usually indicates an alias. E.g. in a for loop:

for @foo -> \element { say element }

Or as a direct alias to a value in a hash:

my %hash; my \foo = %hash<FOO>; dd %h; # Hash %h = {} foo = 42; dd %h; # Hash %h = {:FOO(42)}

So, no, those are not barewords like Perl 5 has them. Perl 5 will happily accept say BAR as valid syntax, Perl 6 does not (unless you have defined BAR in that scope).

$ perl6 -e 'say BAR' ===SORRY!=== Error while compiling -e Undeclared name: BAR used at line 1

And yes, all of Perl 5 CPAN is available at your fingertips if you have Inline::Perl5 installed. The only thing you need to do, is to add :from<Perl5> to your use statement, so e.g.

use DBI:from<Perl5>; use DBD::mysql:from<Perl5>; my $dbh = DBI.connect(...); # call DBI->connect(...) under the hood

It really can't get much simpler than that, I would say, thanks to all the hard work of Stefan Seifert


In reply to Re^3: Why should any one use/learn Perl 6? by liz
in thread Why should any one use/learn Perl 6? by skooma

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-24 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found