spssig.spss.com!news.oc.com!eff!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!caen!usenet.cis.ufl.edu!usenet.ufl.edu!darwin.sura.net!uvaarpa!murdoch!usenet Fri Mar 26 08:59:50 CST 1993 Article: 1830 of comp.lang.perl Xref: feenix.metronet.com comp.lang.perl:1830 Newsgroups: comp.lang.perl Path: feenix.metronet.com!spssig.spss.com!news.oc.com!eff!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!caen!usenet.cis.ufl.edu!usenet.ufl.edu!darwin.sura.net!uvaarpa!murdoch!usenet From: jpw@sansfoy.lib.Virginia.EDU (John Price-Wilkin) #Subject: help assessing efficiency of perl script, and testing file content size Message-ID: Sender: usenet@murdoch.acc.Virginia.EDU Organization: University of Virginia Date: Fri, 26 Mar 1993 03:20:31 GMT Lines: 55 Special thanks to Hal R. Pomeranz and Michael J. Corrigan for the pieces that helped me get this together. This is a filter that is piped to by mail (MH) and resulting files get put into the appropriate gopher directory along with a .cap file. I understand what I've done, but only barely. I wonder if someone can tell me if this is an efficient way to approach this problem. I'd also like to take this a step further. An ideal next step would have the $contents being tested, and in the case that it exceeds a set number of bytes, the contents would be set off in yet another area for large files. Can someone give me a clue about a way to approach that? John Price-Wilkin jpw@virginia.edu @header_lines=('^Name:','^Title:','^Size:'); $headers_done = 0; while(<>) { if ( $headers_done == 0) { foreach $header_line ( @header_lines ) { if (/^Name: (.*)/) { $fname = $1; $fname =~ s/^\s*//; shift @header_lines; if ( $#header_lines < 0 ) { $headers_done = 1; } } if (/^Title: (.*)/) { $capname = $1; $capname =~ s/^\s*//; ($subdir = (split(//, $capname))[0]); if (!(-e $subdir)) { mkdir($subdir, 0755) && mkdir("$subdir/.cap", 0755); } shift @header_lines; if ( $#header_lines < 0 ) { $headers_done = 1; } last; } } } else { if (/^$/..eof) { $contents .= $_; $contents =~ s/^Z//g; $contents =~ s/\f/\n\n/g; } open (FILE, ">$subdir/$fname"); print FILE $contents; close FILE; } system "echo 'Name=$capname' >$subdir/.cap/$fname";