Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with splitting array item into several <option> tags

Status
Not open for further replies.

perlescent

Technical User
Apr 7, 2005
23
GB
in my text file, the line brought into the variable $doubleRoomNumber is like this:

001,002,010,015,026 etc. I want to list each of these within <option></option> tags.

I am having trouble splitting the $doubleRoomNumber to do this. The number of rooms may be 200 or it could be 5 so I don;t think this is the way:
my ($firstRoomNumber, $secondRoomNumber) = split /\,/ , $doubleRoomNumber;

Code:
while ( my $Line = <DAT> ) {
		last if ( index($Line, ':') == -1 );
		chomp $Line;
		my ( $Keyword, $Value ) = split /:/, $Line, 2; #splits the line at the first : ignoring any others
            chomp $Value;
            
		if ($Keyword eq "DoubleRoomNumbers") {
			 my $doubleRoomNumber = $Value;
                   @doubleRoomNumber = $doubleRoomNumber;
print "drn = @doubleRoomNumber<br />";
@doubleRoomNumber = split /\,/, @doubleRoomNumber;  
foreach my $var (sort @doubleRoomNumber) {
print "var=$var<br />";
}

Your help would be greatly appreciated.

bazz
 
Aha :) got it. I'll post the result whenever I finish this bit of scipt.

bazz
 
perlescent

Assume you discovered
Code:
my @doubles = split(/\,/, $doubleRoomNumber);

print join("<br>", sort @doubles);
or something similar...
 
your problem lies here:

Code:
@doubleRoomNumber = $doubleRoomNumber; [b]#<- this makes no sense[b]
print "drn = @doubleRoomNumber<br />";
@doubleRoomNumber = split /\,/, [b]@doubleRoomNumber[/b];

split will not work on arrays like it does on strings, it should be:

Code:
print "drn = $doubleRoomNumber<br />";
@doubleRoomNumber = split /\,/, [b]$doubleRoomNumber[/b];
 
sorry stevexff, your post was not there when I posted. Credit to stevexff please.
 
Right on. Although to be fair, your post had more typing, so probably took longer...[smile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top