Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2016-02-09 08:31 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (309 votes), past polls