You have a simple syntax error in your call of the built in split function.
use strict; use warnings; my $line = "This is :a line :with colons :in it"; my @items = split /:/, $line; print "$_\n" foreach (@items);
If you are working through Learning Perl, Chapter 9 explains some basic usage of split.
If you are like me and forget syntax easily, try to remember that things like split and print are built in functions of Perl and as such should be treated like any subroutine call where you wrote the subroutine (just no "&" ever necessary, see Chapter 4 of Learning Perl :-)). You can even wrap parenthesis around the list (list implies comma separators) of arguments you are passing them for clarity... e.g.
my @items = split(/:/, $line); print('just ', 'like ', 'this ', ':-)')
EDIT: Also, if you are only looking to extract certain items of your list for each line, and you know their index locations in the array you split them in to, you may want to take a look at array slices which are covered in Chapter 17 of Learning Perl.
In reply to Re: Using Split function
by perldigious
in thread Using Split function
by catfish1116
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |