Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

from python to perl

justin8justin8 Posts: 4Member
Hello,

For a couple of years I am a Python programmer now, but now I have to switch to Perl. Changing to a new programming language is always in the beginning difficult, and I wonder if anybody knows a good tutorial for learning Perl, specially for people coming from Python. Until know I only find the switch from Perl to Python.

Comments

  • JonathanJonathan Posts: 2,914Member
    Hi,

    : For a couple of years I am a Python programmer now, but now I have
    : to switch to Perl. Changing to a new programming language is always
    : in the beginning difficult, and I wonder if anybody knows a good
    : tutorial for learning Perl, specially for people coming from Python.
    : Until know I only find the switch from Perl to Python.
    Welcome to Perl, and I hope you'll like the language. Like Python, Perl is dynamically typed etc so they do have a few things in common that way.

    As for tutorials, here's a place to start:-
    http://www.perldoc.com/perl5.8.0/pod/perlintro.html
    Which gives you a quick rundown of the language. If you're up for getting a book, then O'Reilly's Programming Perl is probably the best one out there, though it's aimed at people who have programmed before (so you should be fine having had a couple of years at it).

    From what little I know of Python, the main things you'll find different are:-
    - Variables have sigils
    - OOP is done differently
    - Whitespace is of much less significance (but still write your programs neatly!)
    - We use curly braces for blocks where Python would use indentation

    If you have any questions, feel free to ask. :-)

    Have fun,

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • justin8justin8 Posts: 4Member
    Hi,

    Thanks for the help. Are you also familiar with Perl and MySQL?
    I am able to the connect to MySQL database, do a query, but the way of retrieving the data out of the query, using Perl is not what I am used to in Python, and seems to me difficult. What I just want is to store the query results into what (at least) in Python is called a list. This list can then be used to access the results and combine for instance these results with another query result, also stored in a list....



    : Hi,
    :
    : : For a couple of years I am a Python programmer now, but now I have
    : : to switch to Perl. Changing to a new programming language is always
    : : in the beginning difficult, and I wonder if anybody knows a good
    : : tutorial for learning Perl, specially for people coming from Python.
    : : Until know I only find the switch from Perl to Python.
    : Welcome to Perl, and I hope you'll like the language. Like Python, Perl is dynamically typed etc so they do have a few things in common that way.
    :
    : As for tutorials, here's a place to start:-
    : http://www.perldoc.com/perl5.8.0/pod/perlintro.html
    : Which gives you a quick rundown of the language. If you're up for getting a book, then O'Reilly's Programming Perl is probably the best one out there, though it's aimed at people who have programmed before (so you should be fine having had a couple of years at it).
    :
    : From what little I know of Python, the main things you'll find different are:-
    : - Variables have sigils
    : - OOP is done differently
    : - Whitespace is of much less significance (but still write your programs neatly!)
    : - We use curly braces for blocks where Python would use indentation
    :
    : If you have any questions, feel free to ask. :-)
    :
    : Have fun,
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :

  • WeirdofreakWeirdofreak Posts: 439Member
    [b][red]This message was edited by Weirdofreak at 2004-1-9 8:8:21[/red][/b][hr]
    You want an array. You define them with an @ instead of a $, and you get to the values (both for reading and writing) with $name[index]. Note that you use a $ instead of @ when referring to individual elements, because it's a scalar value stored in them - you use the sign of what you want to get, not what you get it from.

    There are also books online at http://learn.perl.org/library/ if you don't want to buy one, and I personally prefer Beginning Perl to Programming Perl as a tutorial, but Programming for reference.
  • JonathanJonathan Posts: 2,914Member
    A few additional thoughts...

    : You want an array. You define them with an @ instead of a $, and you
    : get to the values (both for reading and writing) with $name[index].
    : Note that you use a $ instead of @ when referring to individual
    : elements, because it's a scalar value stored in them - you use the
    : sign of what you want to get, not what you get it from.
    If you want an array of results you use the fetchrow_array method on a statement handle. E.G.

    @results = $sth->fetchrow_array();

    You access them by numerical index as was said, and they are ordered as the field list in the SELECT query. Note that you can also do things like:-
    ($name, $email) = $sth->fetchrow_array();
    e.g. assign the results of the query directly to variables.

    I think this is the most common way to get results, but it's by no means the only one. You can get an array reference with fetchrow_arrayref, though I'm not sure how useful that'd be. fetchrow_hashref allows you to get the data in a hash (associative array). The key would be the field name. There are also fetchall variations which fetch an array of arrayrefs or hashrefs for all the rows returned, which again can sometimes be useful.

    For the full scoop, see:-
    http://search.cpan.org/~timb/DBI-1.40/DBI.pm#DBI_STATEMENT_HANDLE_OBJECTS

    : There are also books online at http://learn.perl.org/library/ if you
    : don't want to buy one, and I personally prefer Beginning Perl to
    : Programming Perl as a tutorial, but Programming for reference.
    Good point. I guess the best way to work out which is for you is to go to a bookshop and flick through them both. Then buy your chosen one online where it's cheaper. ;-) I'd already learnt a lot of Perl when I picked up Programming Perl, but I can say it made me a much better Perl programmer/hacker.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Sign In or Register to comment.