Click to See Complete Forum and Search --> : Question regarding the Perl split function...


Mike Burdick
05-16-2007, 03:29 AM
Hi,

I have a question regarding the split function.

As an example, the text string looks like this:

$texstring="data1::data2::::data3::data4::"

The split function looks like this:

@record=split(/::/,$text_string)


My question: What value will be placed in $record[2] ? (between the ::::)

Thanks...

Edit... Darn the forum places a smiley face - but you know what I mean.

Nedals
05-17-2007, 02:07 AM
Nothing in ALL the elements
Your variable names don't match....

use strict;
then test it yourself. :(

Mike Burdick
05-19-2007, 09:27 PM
Nedals,

Thanks for the response!

Okay, okay...goofed :o on my example... $text_string should have been $textstring, or the other way around, but my question still stands: What is the value placed in $record[2] when there is nothing in there -::::? I'm assuming a null but not sure.

Jeff Mott
05-20-2007, 01:07 AM
The simplest way to know is to print the data and see.

use strict;
use warnings FATAL => 'all';

my $textstring = 'data1::data2::::data3::data4::';
my @records = split(/::/, $textstring);

for my $i (0 .. $#records) {
print "\$records[$i] is $records[$i]\n";
}

disgracian
05-30-2007, 05:28 AM
I'm pretty sure it will be a zero-length string. But, as the guy above said, best to test for yourself.

Cheers,
D.