Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

I can't believe this string is that weird

by girarde (Hermit)
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.

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://712602]
Approved by McDarren
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2017-09-25 01:54 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (275 votes). Check out past polls.