Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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 exploiting the Monastery: (3)
As of 2014-09-22 23:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (208 votes), past polls