Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
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 contemplating the Monastery: (18)
As of 2014-08-22 14:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (158 votes), past polls