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

Re^3: split function

by Marshall (Abbot)
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; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://949849]
[Happy-the-monk]: Discipulus: please, what are the labels for CTRL+SHIFT+TAB on an Eatalian keyboards?
[Discipulus]: yes but ireally do not understand anonymous's reply about cpan r command: found no bug with that number and points to mjd.. doh?!
[Discipulus]: Happy-the-monk CTRL is the same. SHIFT is a big fat arrow pointing up. TAB are two opposite arrows on each other pointing left/rigth
[choroba]: Discipulus Read the source of Acme::MJD

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2017-11-21 10:02 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (297 votes). Check out past polls.