Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: split function

by Marshall (Prior)
on Jan 25, 2012 at 08:34 UTC ( #949849=note: print w/ replies, xml ) Need Help??


in reply to Re^2: split function
in thread split function

#!/usr/bin/perl -w use strict; my $data ='1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23 +;24;25;26;27;28;29;30;31;32;33;34;35;36'; my @elements = split (';',$data); my $number =1; foreach my $element (@elements) # or could be: # foreach my $element (split (';',$data)) { print "number=$number\t element=$element\n"; $number++; }
The above works.

I think that there is a "new line" in your data file file.

sub split_the_element { my ($fh_in) = @_; #or: my $fh_in = shift; my @result; while (<$fh_in>) { chomp; foreach my $element (split ';', $_) { push (@result, $element); } } return @result; }


Comment on Re^3: split function
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2015-07-06 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls