I need to write the image files in one file and (the xml and html) in another file from a common file. I am trying to compare the extensions,like if it is .jpg or .bmp it will be written to the image file and if it is .html or .xml it will be written to the app file.But I am not able to do so.My code is given below
[code=perl]
open (MyFileHandle," <C\:\\home\\com monfilelist.txt ");
open (MyWebFileHandl e,">$imagefile" ) or die("File Open Error");
open (MyAppFileHandl e,">$Appfile" ) or die("File Open Error");
# Read till end of file.
until((eof(MyFi leHandle)) && (seek(MyFileHan dle,0,0) != eof(MyFileHandl e)))
{
# Check if data exists. If empty exit with appropriate error.
$Text = readline(MyFile Handle);
if(defined($Tex t))
{
#@ArrayTemp = split("/",$Text);
#$Ch = substr($ArrayTe mp[0],0);
$result=rindex( $Text,".");
$pattern=substr ($Text,$result) ;
if($pattern eq (("jpg")||("bmp ")))
{
print MyWebFileHandle $Text;
print MyWebFileHandle "\n";
}
elsif ($pattern eq (("xml")||("htm l")))
{
print MyAppFileHandle $Text;
print MyAppFileHandle "\n";
}
else
{
print "Not an image and Html.\n";
}
}
}[/CODE]
[code=perl]
open (MyFileHandle," <C\:\\home\\com monfilelist.txt ");
open (MyWebFileHandl e,">$imagefile" ) or die("File Open Error");
open (MyAppFileHandl e,">$Appfile" ) or die("File Open Error");
# Read till end of file.
until((eof(MyFi leHandle)) && (seek(MyFileHan dle,0,0) != eof(MyFileHandl e)))
{
# Check if data exists. If empty exit with appropriate error.
$Text = readline(MyFile Handle);
if(defined($Tex t))
{
#@ArrayTemp = split("/",$Text);
#$Ch = substr($ArrayTe mp[0],0);
$result=rindex( $Text,".");
$pattern=substr ($Text,$result) ;
if($pattern eq (("jpg")||("bmp ")))
{
print MyWebFileHandle $Text;
print MyWebFileHandle "\n";
}
elsif ($pattern eq (("xml")||("htm l")))
{
print MyAppFileHandle $Text;
print MyAppFileHandle "\n";
}
else
{
print "Not an image and Html.\n";
}
}
}[/CODE]
Comment