Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

I can't believe this string is that weird

by girarde (Friar)
on Sep 19, 2008 at 19:58 UTC ( #712602=perlquestion: print w/ replies, xml ) Need Help??
girarde has asked for the wisdom of the Perl Monks concerning the following question:

I am chopping up a collection of xml records into separate files, and everything is tickety-poo EXCEPT that the field for the registration date gets skipped. I am running ActivePerl 5.8.8 build 822. The code looks like this:
open (BOX, "<", "U:/documents/mpcrequeststack.txt"); my $can = ''; my $case = ''; while ($can = <BOX>) { $can = <BOX>; $case .= $can; if ($can =~ /^<\/ACCESS_REQUEST>/) { my (@stamp) = gettimeofday(); my $stamp = join '.', @stamp; open CLIP, ">", "\\\\server\\share\\dbgroom\\$stamp.xml" or di +e $!; print "$case\n"; close CLIP; $case = ''; } }
The source file has one field per line. The <REGISTRATION_DATE> fields look like ' Thursday, April 13, 2006 at 16:11:53 (CDT) '. It is not missing from any of the records. What am I missing? UPDATE: Removed some lines of commented out code.

Comment on I can't believe this string is that weird
Select or Download Code
Re: I can't believe this string is that weird
by FunkyMonk (Canon) on Sep 19, 2008 at 20:03 UTC
    while ($can = <BOX>) { $can = <BOX>;
    This is reading two lines from <BOX> into $can, and discarding the first. Just delete the second $can = <BOX>
      Yes, FunkyMonk and ikegami are both right. I'm still puzzled, because of the times I seem to remember having to do it this way, but I'm not going to argue with results.
Re: I can't believe this string is that weird
by ikegami (Pope) on Sep 19, 2008 at 20:04 UTC
    while ($can = <BOX>) { <- reads one line $can = <BOX>; <- reads another

    Is that really what you wanted to do? I think the second line should be deleted.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://712602]
Approved by McDarren
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2015-07-07 13:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls