i am tring to read a long string and then want to filter it with regex for formated value. my formated value is basically name and label which i want to use in a selcet box.
here is my code and any help will be appreciated.
#!/usr/bin/perl
use strict;
my $value = ("TST-----AKAROA, N.Z.\nTRN-----Aborg, mark\n381-----Atic Circle\nLIM-----Call/Lim, Man\nCT2-----San Moon Earth, Soler\n");
print("$value");
#####################################################################
##TST-----AKAROA, N.Z.
##TRN-----Aborg, mark
##381-----Atic Circle
##LIM-----Call/Lim, Man
##CT2-----San Moon Earth, Soler
##################################################################
my
@options = parse_value($value);
if (!
@options){
error_message( 'No available selection options were found.' ); #### line 18
exit 1;
}
print_ui(
@options );
sub parse_value {
my ($filename) =
@_;
my
@options;
if (open( FILE, $filename ))
{
while (<FILE>)
{
my $line = $_;
if ($line =~ /^([^-]*)(-----)(.*)$/)
{
my %hash = ( 'value' => $1, 'label' => $3 );
push(
@options, \%hash );
}
}
}
close FILE;
return
@options;
}
sub print_ui {
my (
@options) =
@_;
foreach my $hash (
@options) {
my $value = $hash->{'value'};
my $label = $hash->{'label'};
if ($label eq '')
{
$label = $value;
}
print qq|<OPTION VALUE=$value>$label</OPTION>\n|;
}
}
************************************************************************************
TST-----AKAROA, N.Z.
TRN-----Aborg, mark
381-----Atic Circle
LIM-----Call/Lim, Man
CT2-----San Moon Earth, Soler
Undefined subroutine &main::error_message called at a.pl line 18.