in reply to Re^2: Tutoring for beginner?
in thread Tutoring for beginner?

Brilliant, that worked - thanks a lot! I can't wrap my head around how that made a difference, though.

Replies are listed 'Best First'.
Re^4: Tutoring for beginner?
by AppleFritter (Vicar) on Mar 07, 2015 at 17:41 UTC

    It makes a difference because with the added quotes, you're splitting on a literal string rather than a regular expression.

    If you want to split along tab characters, then the following are equivalent:

    @data{@speciesList} = split /\t/, $_, scalar @speciesList; @data{@speciesList} = split "\t", $_, scalar @speciesList;

    But the following is not:

    @data{@speciesList} = split "/\t/", $_, scalar @speciesList;

    as that splits on a slash followed by a tab followed by another slash, rather than just a slash. Here's a quick demonstration that may be instructive:

    #!/usr/bin/perl use strict; use warnings; use feature qw/say/; use English; $LIST_SEPARATOR = ","; while(<DATA>) { chomp; my @a = split /\t/; my @b = split "\t"; my @c = split "/\t/"; say "@a"; say "@b"; say "@c"; } __DATA__ foo bar foo/ /bar

    This outputs:

    $ perl 1119187.pl foo,bar foo,bar foo bar foo/,/bar foo/,/bar foo,bar $

    EDIT: posting the above script converted tab characters to spaces in the __DATA__ section, so you'll have to change those back before running the script to get the correct output.

Re^4: Tutoring for beginner?
by Discipulus (Canon) on Mar 07, 2015 at 18:18 UTC
    As you are very new I suggest you to read good Perl: i very suggest you a copy of Perl Cookbook. Is somehow old and sometimes outdated, but is perfectly valid Perl and you'll have a good panorama view of many Perl's possibilities.

    PS I was very newbie too and with no scientific background too: now I approach my problem with Perl with easy with the help of PerlMonks.

    welcome!
    L*
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.