Trying to read two files using a sub to get the data, but 2nd read on the 2nd file goes to EOF

------_=_NextPart_001_01C73F21.48FF8233
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

	Here is a snippet of the code:
    my $MyFileHand;   =20
    my $MyFileHand1;   =20
   =20
    open($MyFileHand,"<$MyFileIn")   || diet (3, $MyFileIn, $!);
    open($MyFileHand1,"<$MyFileIn1") || diet (3, $MyFileIn1, $!);
   =20
	............
   =20
    proc_getrcd( $MyFileHand , $MyEOFProd, $MyWorkp, $MyInp ,
$GlblInfo{compcnt}, $MyUnpackSw );
    proc_getrcd( $MyFileHand1, $MyEOFTest, $MyWorkt, $MyInt ,
$GlblInfo{compcnt}, $MyUnpackSw );
=20

Subroutine being called:
sub proc_getrcd {
    #    0              1       2         3     4              5
    my ( $MyFileHand, $MyEOF, $MyWork, $MyIn, $MyRunningCnt, $MyUnpack )
=3D @_;
   =20
    return if ( $MyEOF );
   =20
    my $MyData =3D <$MyFileHand>;
    if ( ! defined $MyData ) {
        $_[1] =3D 1;
        printf "EOF hit on read: %7d\n",
                                $MyIn;
        return;
     }
    =20
    $_[3]++;
    $_[4]++;
   =20
    chomp($MyData);
   =20
    $MyData =3D~ s/[[:cntrl:]]/ /g if ( $MyData =3D~ /[[:cntrl:]]/ );

    if ( $MyUnpack ) {
        @{$MyWork} =3D unpack($GlblInfo{unpackv},$MyData);
     }
     else {
        $MyWork->[0] =3D substr($MyData,10,16);
        $MyWork->[1] =3D substr($MyData,1126,10);
        $MyWork->[0] =3D~ s/\s+//g;
     }

 }  # end of proc_getrcd
=20
	I have three main subs that I am using to print and then compare
the data:

	sub 1		reads the first 10 rcds of the Test file and
prints out the data
	sub 2		reads the first 10 rcds of the Prod file and
prints out the data
	  Now these subs use the the same above sub, but is doing the
unpack into the passed array. I have checked the output in the different
elements and they are different in value and the key for each record is
there so I know it has gottent the next rcd.

	sub 4 	is the compare and reading of both files, but always
ends up only doing the read

	Know I am mssing something very basic, but escapes me.

     Thanks.

  Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449           FAX
http://fedex.com/us=20


**********************************************************************
This message contains information that is confidential and proprietary to F=
edEx Freight or its affiliates.  It is intended only for the recipient name=
d and for the express  purpose(s) described therein.  Any other use is proh=
ibited.
**********************************************************************


------_=_NextPart_001_01C73F21.48FF8233--
0
David
1/23/2007 7:04:19 PM
perl.beginners 29384 articles. 4 followers. Follow

5 Replies
824 Views

Similar Articles

[PageSpeed] 16

On 1/23/07, Wagner, David --- Senior Programmer Analyst --- WGO
<David.Wagner@freight.fedex.com> wrote:

>     $MyData =~ s/[[:cntrl:]]/ /g if ( $MyData =~ /[[:cntrl:]]/ );

Why the if clause?

I'm not sure I understand your difficulty. But it sounds as if you're
not using seek() (or something similar) to get back to the correct
data position in your file, when you call your subroutine the second
time. If that's not it, can you identify which line of code isn't
doing what you think it should?

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training
0
tom
1/23/2007 7:51:11 PM
	I am just trying to read text files which are delimited by a
regular end of line. I usually only read one file at a time, but thought
it should not be that big a thing to have two file handles open and pass
the filehandle to the sub.

	Can I not ready two different text files at the same time using
two different filehandles?


          If you have any problems or questions, please let me know.

     Thanks.

  Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449           FAX
http://fedex.com/us=20

-----Original Message-----
From: tom.phoenix@gmail.com [mailto:tom.phoenix@gmail.com] On Behalf Of
Tom Phoenix
Sent: Tuesday, January 23, 2007 11:51
To: Wagner, David --- Senior Programmer Analyst --- WGO
Cc: Beginner Perl
Subject: Re: Trying to read two files using a sub to get the data, but
2nd read on the 2nd file goes to EOF

On 1/23/07, Wagner, David --- Senior Programmer Analyst --- WGO
<David.Wagner@freight.fedex.com> wrote:

>     $MyData =3D~ s/[[:cntrl:]]/ /g if ( $MyData =3D~ /[[:cntrl:]]/ );

Why the if clause?

I'm not sure I understand your difficulty. But it sounds as if you're
not using seek() (or something similar) to get back to the correct
data position in your file, when you call your subroutine the second
time. If that's not it, can you identify which line of code isn't
doing what you think it should?

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

**********************************************************************
This message contains information that is confidential and proprietary to F=
edEx Freight or its affiliates.  It is intended only for the recipient name=
d and for the express  purpose(s) described therein.  Any other use is proh=
ibited.
**********************************************************************

0
David
1/23/2007 7:54:39 PM
On 1/23/07, Wagner, David --- Senior Programmer Analyst --- WGO
<David.Wagner@freight.fedex.com> wrote:

>         I am just trying to read text files which are delimited by a
> regular end of line. I usually only read one file at a time, but thought
> it should not be that big a thing to have two file handles open and pass
> the filehandle to the sub.
>
>         Can I not ready two different text files at the same time using
> two different filehandles?

What you describe should be possible.

How are you relocating the file position to the correct place in the
file, when you wish to re-read the data after the first time? Does the
subroutine use seek(), or is it the caller's responsibility?

--Tom Phoenix
Stonehenge Perl Training
0
tom
1/23/2007 8:03:19 PM
	It is two different files. Sub1 and sub2 read from 1 file for 10
rcds and then closes the files and goes on to the next sub? If I have
two different filehandles pointing at two different files, why would I
have to do a seek? I am just trying to read two text files at the same
time and determine if key fields are equal or not. If not, then
determine the lower of the two, add the numeric field, read the next rcd
from this file and go back to top of the loop again and start the
compare process over.


          If you have any problems or questions, please let me know.

     Thanks.

  Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449           FAX
http://fedex.com/us=20

-----Original Message-----
From: tom.phoenix@gmail.com [mailto:tom.phoenix@gmail.com] On Behalf Of
Tom Phoenix
Sent: Tuesday, January 23, 2007 12:03
To: Wagner, David --- Senior Programmer Analyst --- WGO
Cc: Beginner Perl
Subject: Re: Trying to read two files using a sub to get the data, but
2nd read on the 2nd file goes to EOF

On 1/23/07, Wagner, David --- Senior Programmer Analyst --- WGO
<David.Wagner@freight.fedex.com> wrote:

>         I am just trying to read text files which are delimited by a
> regular end of line. I usually only read one file at a time, but
thought
> it should not be that big a thing to have two file handles open and
pass
> the filehandle to the sub.
>
>         Can I not ready two different text files at the same time
using
> two different filehandles?

What you describe should be possible.

How are you relocating the file position to the correct place in the
file, when you wish to re-read the data after the first time? Does the
subroutine use seek(), or is it the caller's responsibility?

--Tom Phoenix
Stonehenge Perl Training

**********************************************************************
This message contains information that is confidential and proprietary to F=
edEx Freight or its affiliates.  It is intended only for the recipient name=
d and for the express  purpose(s) described therein.  Any other use is proh=
ibited.
**********************************************************************

0
David
1/23/2007 8:13:01 PM
 	Sorry, but it was a logic problem and onthing else.

	I apologize for missing it, but I did.

          If you have any problems or questions, please let me know.

     Thanks.

  Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449           FAX
http://fedex.com/us=20

-----Original Message-----
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:David.Wagner@freight.fedex.com]=20
Sent: Tuesday, January 23, 2007 12:13
To: Tom Phoenix
Cc: Beginner Perl
Subject: RE: Trying to read two files using a sub to get the data, but
2nd read on the 2nd file goes to EOF

	It is two different files. Sub1 and sub2 read from 1 file for 10
rcds and then closes the files and goes on to the next sub? If I have
two different filehandles pointing at two different files, why would I
have to do a seek? I am just trying to read two text files at the same
time and determine if key fields are equal or not. If not, then
determine the lower of the two, add the numeric field, read the next rcd
from this file and go back to top of the loop again and start the
compare process over.


          If you have any problems or questions, please let me know.

     Thanks.

  Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449           FAX
http://fedex.com/us=20

-----Original Message-----
From: tom.phoenix@gmail.com [mailto:tom.phoenix@gmail.com] On Behalf Of
Tom Phoenix
Sent: Tuesday, January 23, 2007 12:03
To: Wagner, David --- Senior Programmer Analyst --- WGO
Cc: Beginner Perl
Subject: Re: Trying to read two files using a sub to get the data, but
2nd read on the 2nd file goes to EOF

On 1/23/07, Wagner, David --- Senior Programmer Analyst --- WGO
<David.Wagner@freight.fedex.com> wrote:

>         I am just trying to read text files which are delimited by a
> regular end of line. I usually only read one file at a time, but
thought
> it should not be that big a thing to have two file handles open and
pass
> the filehandle to the sub.
>
>         Can I not ready two different text files at the same time
using
> two different filehandles?

What you describe should be possible.

How are you relocating the file position to the correct place in the
file, when you wish to re-read the data after the first time? Does the
subroutine use seek(), or is it the caller's responsibility?

--Tom Phoenix
Stonehenge Perl Training

**********************************************************************
This message contains information that is confidential and proprietary
to FedEx Freight or its affiliates.  It is intended only for the
recipient named and for the express  purpose(s) described therein.  Any
other use is prohibited.
**********************************************************************


--=20
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/


0
David
1/23/2007 9:00:13 PM
Reply:

Similar Artilces:

Eof of file , file read and file write ! Problem !
Hello All, I want to do 2 things. I have a big file and I want to read file line by line upto last. and side by side i want to write it to new file with some change I am not getiing , in a read , linemode! how i will get End of file and how i will do all this. can you tell me script. I'm not sure I understand your question. From the PowerBuilder Help file, in linemode! FileRead() will return a 0 when it reaches End of File (EOF) so it should be trivial to code? This is just off the cuff but I would imagine it's something like li_Readfile = FileOpen( ...

Can FireDac be used to read *.dbf files (same files used with ShapeFiles)
Hello all, Just wondering if FireDac can be used to access *.dbf file that usually associate with shapefiles? Also, is available for iOS FireDac support? Regards, Bryan Hello Bryan > Just wondering if FireDac can be used to access *.dbf file that usually > associate with shapefiles? If these "dbf" files are standard DBase DB files, then - yes. For that you should use FireDAC Advantage driver: http://docs.embarcadero.com/products/rad_studio/firedac/Connect_to_Advantage_Database_Server.html Most simple will be to use Advantage local engine, which is free for...

reading data from a file and put in a new file
Hello I need to read some data in a file and add in another file part of the line with some changes input data ../data01;data02;data03;data04;data05;data06;data07; ../data11;data12;data13;data14;data15;data16;data17; ../data21;data22;data23;data24;data25;data26;data27; ../data31;data32;data33;data34;data35;data36;data37; out put data need can be like zis data01;data02;data03;data01_sametexttoall;data04 data11;data12;data03;data11_sametexttoall;data14 data21;data22;data23;data21_sametexttoall;data24 data31;data32;data33;data31_sametexttoall;;data34 out data can be also ...

How to assign an XML file to a data set without reading it from a file. The data set is in a string.
I want to bind some XML data to a data list control on my web form. Here is my problem:   I have a data set that is populated via a call to a sql stored procedure. I need the data set data to be in XML format though. I can convert the data to an XML formatted string using the GetXML() method. But  I don't know how to assign it back to the DataSet. Does anyone know how to do this. Here is some code I have written. It is close but it does not completely do what I want done. 1. DataSet myDataSet = myWebService.GetData(); // Populate the data set via a SQL stored proc ...

superreview granted: [Bug 259708] Trying to save file from data: protocol wipes every file in target directory not marked read-only : [Attachment 160030] Ported patch
Boris Zbarsky <bzbarsky@mit.edu> has granted Boris Zbarsky <bzbarsky@mit.edu>'s request for superreview: Bug 259708: Trying to save file from data: protocol wipes every file in target directory not marked read-only https://bugzilla.mozilla.org/show_bug.cgi?id=259708 Attachment 160030: Ported patch https://bugzilla.mozilla.org/attachment.cgi?id=160030&action=edit ------- Additional Comments from Boris Zbarsky <bzbarsky@mit.edu> r+sr=bzbarsky ...

Reading a CSV file and extracting data to several files
Hello group, I have a CSV file I'm going to read, and parse out full lines that have unique identifiers into a separate file. Example: If line in the CSV file has "XTRP" in it I want to create a new file and add that line of data. "XTRP" is only one of many unknown identifiers in the CSV file, but the identifiers are all in the same location in the file, so it is easy to know when to push data to a different file. I would then save the file as XTRP.csv I can easily read this file and know when a new identifier is found by iterating through a TStringList, but...

How to read eml files : Trying to remove duplicate files.
Here is what I posted to Bugzilla to follow up on an existing entry: Bugzilla Bug 158032 want a remove dup mail feature http://bugzilla.mozilla.org/show_bug.cgi?id=158032 > I want this type of tool, too. > > I had a problem with Mozilla 1.7.2 in that > when I tried to interrupt "Run filter" operation > on a large folder, the "Stop" didn't seem to work well > and left a running thread and when I didn't realize this, > mozilla seemed to have spawned another thread when I hit > "Run Now" again, and as a result, I h...

read xls to a xml file or oledb data base file
I have a xls file, BUt it doesn't have a named range in it. Can i either programatically create the named range,, then process it to a OLEDB file, or can I convert the xls file to a XML. your thoughts and what object can I use to perform this. bevbev I tried XML to XLS and it worked fine but the reverse (XLS->XML) creates a lot of mess in the xml file (for me). But if you like it, go ahead. From Excel work sheet you can choose SaveAs from File menu and choose XML file format and you are done. Be sure to examine the XML file that is created. It could be a mess hiding the in...

Read Data From HTML File using FileUpload
Hello guys! I just want to know if I can read data or strings from a html file that was retrieve using FileUpload? Thanks in advance! // Willy David JrMicrosoft Student PartnersWilly David JrJunior Software Development EngineerGurango Software CorporationProgramming is a Passion, Software Development is an Adventure - willydavidjr Using file upload Control you will get the data in byte formatbyte []arrdata = Fileupload1.Get.. .. .;string str = System.Text.Encoding.Ascii.GetString(arrdata);str will hold your uploaded data SatalajWatch The true story of internet ||Yet another forum |||I&...

read data from xml file using LINQ?
Hi to all, I have a XML file i want to select records from that but i dont know what are the columns is there because while runtime the xml file columns are differ, so how can i write the query for this situation using LINQ? Experts please help me.  If this post is answer of your question then don't forgot to Click Mark As Answer Well an XML document does not have records or columns, instead it has nodes like element nodes, attribute nodes, comment nodes, text nodes. You can read out such nodes and determine the names if you want. Here is an example that recursively processes t...

Reading files from file server
Hi all,I need help reading data from files . I am storing files in the file system and  unable to read the file from the file system. I am stroing doc and PDF files in my file system. Can any one help me in reading the  files back from the file system...  Here is my code  If (uploadPDF.HasFile = False Or uploadWord.HasFile = False) Then                           ' No file uploaded!&nbs...

Read txt file and use each line as regex and output matches to file.
--------------enig6320889D80B32E6F799A5486 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi All! Please help this beginner! More than likely there is an easy way to do this and/or I am doing something stupid but I just don't know how. Sorry if this is a bit long. (Scenario) -Several routers/firewalls log events to a single ($log_file). -I want to be able to seperate the logs based on router/firewall IP addresses ($log_source) and dump all matches to their relevant files for further processing ($date-$ip.log) -Process the (...

How can I read the HTTP file use c#? subject: image file.
The server have internet but the client can't link to internet. I want use the server to read HTTP file and show it to client.Thanks for your help.Weboy B.Wan---------------------------------------MSN: weboy.wan"at"msn.comE-Mail: weboy.wan"at"gmail.com private void Page_Load(object sender, System.EventArgs e) { Response.Buffer = true; System.Net.WebRequest req = System.Net.WebRequest.Create("http://www.microsoft.com/"); System.Net.WebResponse res = req.GetResponse(); System.IO.Stream stream = res.GetResponseStream(); System.IO.StreamReader reader = new System.IO.StreamReader(...

how to change attribute of file from read only to read write using powerbuilder script
I have a paradox file.I am coping this file and reading after that as binary.while copying it ,if this file has read only attribute i am not able to delete it and replace the new file,if it is already present there at destination.I want to do it with powerbuilder script.I searched a kernel32.dll function SetFileAttribute(filnename ,attribute) but i don't know how to apply.please give the solution for this function or any other alternative. Here is how I do it: ls_imagepath = as_imagepath lu_win32.SetFileAttributesA(ls_imagepath, lu_win32.FILE_ATTRIBUTE_NORMAL) -- functio...

Web resources about - Trying to read two files using a sub to get the data, but 2nd read on the 2nd file goes to EOF - perl.beginners

Taylor Swift Upset About Kendall Jenner, Harry Styles Relationship? Not True, One Source Reports
Could this be a true tale about Taylor Swift? Harry Styles and Kendall Jenner were recently seen cozying up in St. Barth’s, and according to ...

Ohio State Buckeyes Blast Past Notre Dame Fighting Irish In BattleFrog Fiesta Bowl Win
Ohio State proved to be too much for Notre Dame as the Buckeyes trounced the Fighting Irish in a 44-28 win at the BattleFrog Fiesta Bowl in Glendale, ...

'Unforgettable' singer Natalie Cole dead at 65
Grammy-winning singer Natalie Cole, whose biggest hit came in a virtual duet with her late father, pop legend Nat King Cole, of his decades-old ...

‘Star Wars Episode IX’: What Does Galaxy Far, Far Away Look Like Beyond New Trilogy
Star Wars Episode IX may not be at the forefront of audiences’ minds just yet, but you can bet that it’s on those of the execs at Disney. The ...

Pusha T – “M.P.A.” (Feat. Kanye West, A$AP Rocky, & The-Dream) Video
Pusha T is back with another video from his ridiculously good Darkest Before Dawn: The Prelude . In contrast to the darkly dramatic clips that ...

Hillary Clinton’s Campaign Exceeds 2015 Fundraising Goal
Hillary Clinton’s presidential campaign announced Friday that it raised $37 million in the last three months , bringing its yearly fundraising ...

Someone wrote 'Trump is disgusting' in the sky above the Rose Parade
The annual Rose Parade in Pasadena, California, got political with a special message for Republican presidential front runner Donald Trump. ...

Using Cubii’s elliptical trainer is one of my New Year’s resolutions
I sit at my desk and write posts all day for my job. My fingers get a lot of exercise, but not the rest of me. That’s why I’m looking forward ...

Wayne Rogers, who played ‘Trapper’ John on ‘M*A*S*H’, dies at 82
Wayne Rogers, who portrayed wisecracking Army surgeon "Trapper John" McIntyre in the first three seasons of TV's "M*A*S*H," died Thursday, his ...

Erdoğan cites Hitler's Germany as example of effective government - World news - The Guardian
Turkey’s president Recep Tayyip Erdoğan is pushing to change his ceremonial role to chief executive as in US and Russia

Resources last updated: 1/2/2016 2:09:29 AM