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!

Intresting split bug

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
Program:

#!/usr/local/bin/perl

$abso_path = "f:/inetpub/clanworld.org/clans/loros/cgi-bin/gamers";

print "content-type: text/html\n\n";
my $in;
if ($ENV{'REQUEST_METHOD'} eq "GET") {
$in = $ENV{'QUERY_STRING'};
} else {
$in = <STDIN>;
}

$in =~ s/\+/ /gi;
$in =~ s/%(..)/pack(&quot;c&quot;,hex($1))/ge;

opendir(DIR,&quot;$abso_path/data&quot;) || die(&quot;failed to open dir: $!&quot;);

while($var = readdir(DIR))
{
print &quot;$var<br>&quot;;
@files = split (/.dat/, $var);
}

closedir(DIR);

for($i =0; $i <= $#files; $i++)
{
print &quot;$files[$i]<br>&quot;;
}

<===== EOF =====>

output:

.
..
adminsecurityfile.dat
banlist.dat
index.dat
lastusr.dat
reguser
reguser

problem:
it doesn't printout the inital read (...adminsecurity.datbanlist.datindex.datlastusr.datreguser)
and it doesn't split out the .dat's from the file names.

can anyone enlighten me as to where i'm going wrong?

thanks
 
Try escaping the dot in &quot;.dat&quot; like this &quot;\.dat&quot; - so your split would look like:

@files = split (/\.dat/, $var);

if you don't escape the dot, the dot means match any character. I'm not sure if this will solve your problem, but it is something that should be corrected.
Hardy Merrill
Mission Critical Linux, Inc.
 
Stupid me :)
it wasn't writing the split of var to the files array (why i don't know) so using a very crude for loop replacement (as i needed the while)
i did this:
$whilelopp = 0;
while($var = readdir(DIR))
{
$var =~ /\.dat//gi;
$files[$whileloop] = $var;
$whileloop++:
}

that solved the problem, and i got the result i wanted.
Siberdude
siberdude@settlers.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top