You need to close the port I believe. Robby
On Thursday, April 11, 2013, Steve Byan wrote: > Section 3.7.4 "Regexp Matching" of the "Racket Reference" says in part: > > "If the optional output-port is provided as an output port, the part of > input from its beginning (not start-pos) that precedes the match is written > to the port. All of input up to end-pos is written to the port if no match > is found. This functionality is most useful when input is an input port." > > Given this input file: > > multivac:~ smb$ cat > /Users/smb/Library/Mail/V2/Mailboxes/personal.mbox/PMRC.mbox/Info.plist > <?xml version="1.0" encoding="UTF-8"?> > <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" " > http://www.apple.com/DTDs/PropertyList-1.0.dtd"> > <plist version="1.0"> > <dict> > <key>DisplayInThreadedMode</key> > <string>no</string> > <key>MailboxName</key> > <string>PMRC</string> > <key>SearchSortDescending</key> > <string>YES</string> > <key>SearchSortOrder</key> > <string>received-date</string> > <key>SortOrder</key> > <string>received-date</string> > <key>SortedDescending</key> > <string>NO</string> > </dict> > </plist> > > I expect the following racket function to copy the entire input port to > the output port: > > #lang racket > > (define (plist-file-match-sorted-descending plist-path) > (let ([input-port (open-input-file plist-path)] > [output-port (open-output-file (path-replace-suffix plist-path > ".plist~") #:exists 'replace)]) > (if (regexp-match "<key>SortedDescending</key>\n\t<string>YES</string>" > input-port 0 #f output-port) > (displayln "sorted descending") > (displayln "sorted ascending")))) > > (define test-path (string->path > "/Users/smb/Library/Mail/V2/Mailboxes/personal.mbox/PMRC.mbox/Info.plist")) > > I apply the function to the file path: > > Welcome to DrRacket, version 5.3.3 [3m]. > Language: racket; memory limit: 128 MB. > > (plist-file-match-sorted-descending test-path) > sorted ascending > > > > But despite my expectations the resulting Info.plist~ file is empty: > > multivac:~ smb$ ls -l > /Users/smb/Library/Mail/V2/Mailboxes/personal.mbox/PMRC.mbox/Info.plist~ > -rw-r--r-- 1 smb staff 0 Apr 10 17:09 > /Users/smb/Library/Mail/V2/Mailboxes/personal.mbox/PMRC.mbox/Info.plist~ > > > What am I missing? > > Best regards, > -Steve > > -- > Steve Byan <[email protected] <javascript:;>> > Littleton, MA 01460 > > > > > ____________________ > Racket Users list: > http://lists.racket-lang.org/users >
____________________ Racket Users list: http://lists.racket-lang.org/users

