in reply to Help Using Split and Arrays

OK, you have lines containing something - comma - something - comma - remainder. Right?

So split on the commas. More specifically, split on the first two commas only so I don't have to worry about any stray commas in the remainder.

use Data::Dump qw(dump); my $s= 'a,b, this is the rest of the string, dude!'; my @results= split(/,/, $s); print dump \@results;
Now, you might find stray whitespace around the commas, so try formulating a fancier pattern to match that.

Replies are listed 'Best First'.
Re^2: Help Using Split and Arrays
by burningredmoon (Novice) on Apr 23, 2011 at 03:13 UTC
    Thank you for replying.

    I'm new to arrays. Can I take the array that's storing the information pulled from the file and split it like you're doing the string you've written into the code?

    Something like this?

    my @newarray= split (/,/,$data);

    It may be easy but for some reason I can't word the questions I have right to get what I need. Maybe that's all I need to do.

      Each item in the array is one string. You need to read this book. I've seen free PDFs for that around the web. You might also try this page. You need to know about scalars and arrays as basic types, how to write loops, and probably everything else. So just start with a beginner book and work through it.

      my @samples= ('a,b,stuff', 'b, c , more stuff'); foreach my $line (@samples) { # work with $line here }
      See Foreach Loops in the Perl documentation.

        Thanks for the reference help. I'll read up and see what I can do!