[28485] in Perl-Users-Digest
Perl-Users Digest, Issue: 9849 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 15 06:05:50 2006
Date: Sun, 15 Oct 2006 03:05:03 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 15 Oct 2006 Volume: 10 Number: 9849
Today's topics:
Re: alarm() - SIGALRM sent too eariy? <hjp-usenet2@hjp.at>
Re: alarm() - SIGALRM sent too eariy? <bik.mido@tiscalinet.it>
Re: help me pass argument to the subroutine and then re <mgarrish@gmail.com>
new CPAN modules on Sun Oct 15 2006 (Randal Schwartz)
problems appending an entry to a logfile <mark.leeds@morganstanley.com>
Re: problems appending an entry to a logfile <someone@example.com>
Re: trouble merging files using nested loop to read fil <tadmc@augustmail.com>
Re: trouble merging files using nested loop to read fil (reading news)
Re: trouble merging files using nested loop to read fil (reading news)
Re: trouble merging files using nested loop to read fil (reading news)
Re: trouble merging files using nested loop to read fil <theshowmecanuck@no_yahoo_spam.com>
Re: trouble merging files using nested loop to read fil <jurgenex@hotmail.com>
Re: trouble merging files using nested loop to read fil (BillR)
Re: trouble merging files using nested loop to read fil <joe@inwap.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 15 Oct 2006 10:34:02 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: alarm() - SIGALRM sent too eariy?
Message-Id: <slrnej3sjq.la8.hjp-usenet2@yoyo.hjp.at>
On 2006-10-15 00:27, bwooster47@gmail.com <bwooster47@gmail.com> wrote:
> anno4000@radom.zrz.tu-berlin.de wrote:
>> Check the time in the signal handler and restart the alarm if the
>> expected time hasn't been reached. Set the timeout flag only if
>> it has.
>> Anno
>
> But that seems to defeat the purpose of using alarm, have to take of it
> exiting early!
Alarm and sleep don't make any timing guarantees. They may exit early or
late. You should always check how much time has really passed and act
accordingly. At least an early exit is easy to handle - just repeat the
operation for the remaining time.
> I found another script on the web, with people reporting problems:
> http://www.aczoom.com/cms/software/tools/copy-video-for-given-duration
> That page has a script called timed-copy.
>
> I ran it on Fedora system (use -v -v to print debug statements)
> timed-copy -v -v -m 110 < /dev/zero > /dev/null
>
> and it invariably exits in 38.42 minutes (and not 110 minutes) - same
> thing seen, in multiple runs.
110 minutes == 6_600 seconds == 6_600_000_000 µs.
6_600_000_000 % 2^32 == 2_305_032_704 µs == 38.417 minutes.
So my guess is that the time before the alarm is converted to
microseconds before being passed to the OS and that an integer overflow
happens during the conversion.
I can see this on Debian Linux, too: stracing your program (after fixing
the obvious errors and adding some read operations - please post test
programs which are ready to run, not just code snippets) yields:
setitimer(ITIMER_REAL, {it_interval={0, 0}, it_value={0, 2305032704}},
{it_interval={0, 0}, it_value={0, 0}}) = 0
The parameter it_value is wrong. It should be {6600, 0} instead of {0,
2305032704}.
Probably a bug in Time::HiRes. Without use Time::HiRes, alarm(6600) is
called, which is correct.
> I tried another script, removed the sysread/syswrite, and replaced the
> while loop with just:
> while (<>) { }
> and then it seemed to work fine (test is still running, atleast it did
> not alrm in 38.42 minutes).
Did you redirect the input for this script? If its just waiting for
input it may never process the signal. (Safe signals are a pain - maybe
a lesser pain than unsafe signals, but still a pain)
hp
--
_ | Peter J. Holzer | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR | > ist?
| | | hjp@hjp.at | Was sonst wäre der Sinn des Erfindens?
__/ | http://www.hjp.at/ | -- P. Einstein u. V. Gringmuth in desd
------------------------------
Date: 15 Oct 2006 11:36:36 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: alarm() - SIGALRM sent too eariy?
Message-Id: <p604j2po730p0vji3o56498uql4u2e4g48@4ax.com>
On 14 Oct 2006 17:27:29 -0700, bwooster47@gmail.com wrote:
>> > last if ($timerexpired);
>> ^^^^^^^^
>> ... and this one aren't the same.
>
>This was just an example, the code used is correct, was just a typo in
>my posting.
Which is a nice example to explain why people is often recommended not
to retype code, but to paste it. Because we all make typos...
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 14 Oct 2006 18:31:40 -0700
From: "Matt Garrish" <mgarrish@gmail.com>
Subject: Re: help me pass argument to the subroutine and then return the value from that subroutine to another.
Message-Id: <1160875900.403368.168640@m73g2000cwd.googlegroups.com>
Tad McClellan wrote:
> hyper-sensitive <123imemyself@gmail.com> wrote:
>
> > #!\iw-home/iw-perl/bin/iwperl -w
>
>
> What is "iwperl"?
>
The perl executable that comes with Interwoven's clunky Teamsite
content management system (if you can really call it that without
laughing).
Matt
------------------------------
Date: Sun, 15 Oct 2006 04:42:05 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Sun Oct 15 2006
Message-Id: <J75uE5.HMq@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
Archive-StringToZip-1.03
http://search.cpan.org/~robbiebow/Archive-StringToZip-1.03/
Transforms a string to a zip
----
Audio-XMMSClient-0.01
http://search.cpan.org/~flora/Audio-XMMSClient-0.01/
Interface to the xmms2 music player
----
CPAN-1.88_54
http://search.cpan.org/~andk/CPAN-1.88_54/
query, download and build perl modules from CPAN sites
----
CPAN-Test-Dummy-Perl5-Make-CircDepeOne-1.00
http://search.cpan.org/~andk/CPAN-Test-Dummy-Perl5-Make-CircDepeOne-1.00/
CPAN Test Dummy
----
CPAN-Test-Dummy-Perl5-Make-CircDepeThree-1.00
http://search.cpan.org/~andk/CPAN-Test-Dummy-Perl5-Make-CircDepeThree-1.00/
CPAN Test Dummy
----
CPAN-Test-Dummy-Perl5-Make-CircDepeTwo-1.00
http://search.cpan.org/~andk/CPAN-Test-Dummy-Perl5-Make-CircDepeTwo-1.00/
CPAN Test Dummy
----
Continuity-0.8
http://search.cpan.org/~awwaiid/Continuity-0.8/
Abstract away statelessness of HTTP using continuations, for stateful Web applications
----
Digest-SHA-5.44
http://search.cpan.org/~mshelor/Digest-SHA-5.44/
Perl extension for SHA-1/224/256/384/512
----
Digest-SHA-PurePerl-5.44
http://search.cpan.org/~mshelor/Digest-SHA-PurePerl-5.44/
Perl implementation of SHA-1/224/256/384/512
----
EPrints-QueryBuilder-0.01
http://search.cpan.org/~cselt/EPrints-QueryBuilder-0.01/
Perl extension for tokenising search strings and building queries
----
HTML-Links-Localize-0.2.5
http://search.cpan.org/~shlomif/HTML-Links-Localize-0.2.5/
Convert HTML Files to be used on a hard disk
----
HTML-Mason-1.34
http://search.cpan.org/~drolsky/HTML-Mason-1.34/
High-performance, dynamic web site authoring system
----
HTML-Rainbow-0.04
http://search.cpan.org/~dland/HTML-Rainbow-0.04/
Put colour into your HTML
----
Ingres-Utility-IINamu-0.04
http://search.cpan.org/~worm/Ingres-Utility-IINamu-0.04/
API to IINAMU Ingres RDBMS utility
----
Lemonldap-NG-Handler-0.3
http://search.cpan.org/~guimard/Lemonldap-NG-Handler-0.3/
Perl extension for building a Lemonldap compatible handler
----
Lemonldap-NG-Portal-0.11
http://search.cpan.org/~guimard/Lemonldap-NG-Portal-0.11/
Perl extension for building Lemonldap compatible portals
----
Lemonldap-NG-Portal-0.111
http://search.cpan.org/~guimard/Lemonldap-NG-Portal-0.111/
Perl extension for building Lemonldap compatible portals
----
Lingua-TR-Numbers-0.1
http://search.cpan.org/~burak/Lingua-TR-Numbers-0.1/
Converts numbers into Turkish text.
----
MDV-Repsys-0.09
http://search.cpan.org/~nanardon/MDV-Repsys-0.09/
----
MIME-Charset-0.04
http://search.cpan.org/~nezumi/MIME-Charset-0.04/
Charset Informations for MIME
----
MIME-EncWords-0.02
http://search.cpan.org/~nezumi/MIME-EncWords-0.02/
deal with RFC-1522 encoded words (improved)
----
Macro-Micro-0.05
http://search.cpan.org/~rjbs/Macro-Micro-0.05/
really simple templating for really simple templates
----
Net-Appliance-Session-0.08
http://search.cpan.org/~oliver/Net-Appliance-Session-0.08/
Run command-line sessions to network appliances
----
Net-Netmask-1.9014
http://search.cpan.org/~muir/Net-Netmask-1.9014/
parse, manipulate and lookup IP network blocks
----
POE-Filter-FSSocket-0.04
http://search.cpan.org/~ptinsley/POE-Filter-FSSocket-0.04/
a POE filter that parses FreeSWITCH events into hashes
----
Search-QueryBuilder-0.01
http://search.cpan.org/~cselt/Search-QueryBuilder-0.01/
Perl extension for tokenising search strings and building queries
----
Search-Tools-0.05
http://search.cpan.org/~karman/Search-Tools-0.05/
tools for building search applications
----
Thread-Cancel-1.05
http://search.cpan.org/~jdhedden/Thread-Cancel-1.05/
Cancel (i.e., kill) threads
----
Thread-Suspend-1.09
http://search.cpan.org/~jdhedden/Thread-Suspend-1.09/
Suspend and resume operations for threads
----
lib-restrict-0.0.1
http://search.cpan.org/~dmuey/lib-restrict-0.0.1/
Perl extension for restricting what goes into @INC
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: 14 Oct 2006 23:02:06 -0700
From: "markpark" <mark.leeds@morganstanley.com>
Subject: problems appending an entry to a logfile
Message-Id: <1160892126.419880.78310@f16g2000cwb.googlegroups.com>
hi all : i definitely went through all the books ( learning perl, perl
cookbook and programming perl )
and i found discussions of what i want to do but not enough for me to
get it right
( given ym perl ability. i'm not blaming it on the books ).
i just want to append a new line ( with the date, time, entry number
and my login name ) to
a file that already has previous lines ( of the same exact format with
all fields seprated by whitespace ) it and i'm pretty close. the new
line would differ in terms of the entry
number and the date but otherwise it's exactly the same as the previous
lines
that already in the file.
so, i wrote a subroutine , logFileEntry, which would take the
logfilename as input
the code is below.
---------------------------------------------------------------------------------------------------------------------------------------------
sub logFileEntry {
my $logfile = shift;
my $lastone = 0;
open my $LOG_FILE, '<', $logfile or die "could not open $logfile for
reading: !";
while (<$LOG_FILE>) {
chomp;
my @items = split / /;
$lastone = $items[$#items] + 1;
}
close $LOG_FILE;
my $tm = localtime;
my($month,$year,$mday,$hour,$min,$sec) = ($tm->mon, $tm->year,
$tm->mday, $tm->hour, $tm->min, $tm->s
open $LOG_FILE, '>>', $logfile or die "could not open $logfile for
appending !";
print $LOG_FILE " $year $month $mday $hour . "::" . $min . "::" . $sec
$lastone \n";
close $LOG_FILE;
return(1)
}
i would like my logfile to look like
2006 10 14 01:33:06 1 leedsmar
2006 10 14 01:33:06 2 leedsmar
2006 10 14 01:33:06 3 leedsmar
.
.
.
.
but my two problems are
1) how to format my values so the line can look like above
2) somehow use the "whoami" at the prompt to get the login name into a
variable called
say $login_name
again, i've really tried and i found info in different books but i
still can't gt it quite right. thank you
very much to anyone who can help me. i'm sorry to be such a pest to the
list but
i don't know what else to do. I'm really trying.
------------------------------
Date: Sun, 15 Oct 2006 07:37:49 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: problems appending an entry to a logfile
Message-Id: <hzlYg.22564$H7.1865@edtnps82>
markpark wrote:
> hi all : i definitely went through all the books ( learning perl, perl
> cookbook and programming perl )
> and i found discussions of what i want to do but not enough for me to
> get it right
> ( given ym perl ability. i'm not blaming it on the books ).
>
> i just want to append a new line ( with the date, time, entry number
> and my login name ) to
> a file that already has previous lines ( of the same exact format with
> all fields seprated by whitespace ) it and i'm pretty close. the new
> line would differ in terms of the entry
> number and the date but otherwise it's exactly the same as the previous
> lines
> that already in the file.
It looks like you want something like this:
use Fcntl ':seek';
use POSIX 'strftime';
sub logFileEntry {
my $logfile = shift;
open my $LOG_FILE, '+>>', $logfile or die "could not open $logfile: $!";
my $lastone = 1 + ( do {
local $/ = \100; # 100 bytes should be large enough
seek $LOG_FILE, -100, SEEK_END;
<$LOG_FILE>
} =~ /\b\d+\b/g )[ -1 ];
my $date = strftime '%Y %m %d %H:%M:%S', localtime;
my $login_name = getpwuid $<;
print $LOG_FILE "$date $lastone $login_name\n";
return 1;
}
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
------------------------------
Date: Sat, 14 Oct 2006 20:25:57 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: trouble merging files using nested loop to read files
Message-Id: <slrnej33h5.49j.tadmc@magna.augustmail.com>
Dean Of St. Louis Blues <bennie.smith@dean_of_st_louis_blues_guitar.com> wrote:
> I have two sorted files. I open them, I (1) read the first line from the
> first file, then want to (2) loop through the second file and compare
> specific fields (fixed width field format). (3) When I find matching fields
> it extracts data, and writes it as a record to an output file. Then it is
> supposed to (4) break from the inner loop, (5) get the second record from
> the first file, and then ( 6) continue scanning the second file from where
> it left off, until it finds another matching record, and so on.
>
> The problem happens at step (6). It reads the seconf file from the first
> file, but doesn't seem to want to look at the second file any more.
Since you have used a for loop, the input operator is in list context,
so it reads _all_ of the lines right up to the end-of-file.
Then on the 2nd iteration of the outer loop, you are already
at EOF for the billing file (ie. it looks empty).
> open (FILTERED_SORTED_SERVICE_FILE, "$sorted_service_output_filename") or
^ ^
This has nothing to do with your current problem, but you should
lose those quote characters.
perldoc -q vars
What's wrong with always quoting "$vars"?
> for $serviceRecord (<FILTERED_SORTED_SERVICE_FILE>) {
while ( my $serviceRecord = <FILTERED_SORTED_SERVICE_FILE> ) {
> for $billingRecord (<SORTED_BILLING_FILE>){
while ( my $billingRecord = <SORTED_BILLING_FILE> ) {
> $srPayID = substr($service,21,15);
> $brPayID = substr($billing,211,15);
>
> print "billing record count = $bcount,\
> srPayID = $srPayID, brPayID = $brPayID\n"; # for debugging
>
> if ($srPayID eq $brPayID){
> # next line calls the sub which does some work and returns a
> # line to print to file.
> my $op = extractOutputFields($serviceRecord,
> $billingRecord);
> print FINAL_OUTPUT_FILE $op;
> # found corresponding record in billing file, break out, get
> # next service record and continue scanning billing file
> # where it last left off.
seek SORTED_BILLING_FILE, 0, 0; # rewind the file before doing "last"
(or close() and open() SORTED_BILLING_FILE again.)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 15 Oct 2006 01:54:12 GMT
From: "Mumia W. (reading news)" <paduille.4059.mumia.w@earthlink.net>
Subject: Re: trouble merging files using nested loop to read files
Message-Id: <8xgYg.7304$Lv3.5689@newsread1.news.pas.earthlink.net>
On 10/14/2006 05:56 PM, Dean Of St. Louis Blues wrote:
> Hi,
> I am having a problem merging two files. The problem is when reading
> the second file in a nested loop. I have posted the code below.
>
> I have two sorted files. I open them, I (1) read the first line from the
> first file, then want to (2) loop through the second file and compare
> specific fields (fixed width field format). (3) When I find matching fields
> it extracts data, and writes it as a record to an output file. Then it is
> supposed to (4) break from the inner loop, (5) get the second record from
> the first file, and then ( 6) continue scanning the second file from where
> it left off, until it finds another matching record, and so on.
>
> The problem happens at step (6). It reads the seconf file from the first
> file, but doesn't seem to want to look at the second file any more. My
> debugging statements show that it just keeps looping through to the end of
> the first file without ever looking at the second file again.
>
> I am rather new to perl, but have significant programming experience and
> have tried to figure this out on my own. Please help before I finish
> pulling all my hair out.
>
> Thanks.
>
>
> ######## code example ####################
>
> ....
>
> open (FILTERED_SORTED_SERVICE_FILE, "$sorted_service_output_filename") or
> die "$! error opening $sorted_service_output_filename";
> open (SORTED_BILLING_FILE, "$sorted_billing_output_filename") or die "$!
> error opening at $sorted_billing_output_filename";
>
>
> sub mergeFiles{
> #print "merge files\n";
>
> $scount = 1; # for debugging
> $bcount = 1; # for debugging
>
> # go through the service record file one line at a time
>
> for $serviceRecord (<FILTERED_SORTED_SERVICE_FILE>) {
> print "service record count = $scount\n"; # for debugging
>
> # at each service record scan the billing file to find a matching
> # record, do some work and get then break out and get another
> # service record and repeat. Do not start at the top of the
> # billing file again, just continue from before (it is a merge! :-)
>
> for $billingRecord (<SORTED_BILLING_FILE>){
>
This will only work once because, once the file is read, you're at EOF,
so the file will not be read again. It's better for you to store the
data in an array so that you can loop through it again and again:
our @billingRecordArray;
@billingRecordArray = <SORTING_BILLING_FILE> unless @billingRecordArray;
for my $billingRecord (@billingRecordArray) {
> $srPayID = substr($service,21,15);
> $brPayID = substr($billing,211,15);
> [...]
ObStrict: Write your program to run under strictures and warnings; that
will catch 50% of your errors:
use strict;
use warnings;
--
Mumia W.
paduille.4059.mumia.w@earthlink.net
This is a temporary e-mail to help me catch some s-p*á/m.
------------------------------
Date: Sun, 15 Oct 2006 01:54:13 GMT
From: "Mumia W. (reading news)" <paduille.4059.mumia.w@earthlink.net>
Subject: Re: trouble merging files using nested loop to read files
Message-Id: <9xgYg.7305$Lv3.894@newsread1.news.pas.earthlink.net>
On 10/14/2006 05:56 PM, Dean Of St. Louis Blues wrote:
> Hi,
> I am having a problem merging two files. The problem is when reading
> the second file in a nested loop. I have posted the code below.
> [...]
>
> for $serviceRecord (<FILTERED_SORTED_SERVICE_FILE>) {
> print "service record count = $scount\n"; # for debugging
>
> # at each service record scan the billing file to find a matching
> # record, do some work and get then break out and get another
> # service record and repeat. Do not start at the top of the
> # billing file again, just continue from before (it is a merge! :-)
>
> for $billingRecord (<SORTED_BILLING_FILE>){
As I explained in another message, this will only work once because it
will only read the file once--unless you seek back to the beginning of
the file.
>
> $srPayID = substr($service,21,15);
> $brPayID = substr($billing,211,15);
>
> print "billing record count = $bcount,\
> srPayID = $srPayID, brPayID = $brPayID\n"; # for debugging
>
> if ($srPayID eq $brPayID){
> # next line calls the sub which does some work and returns a
> # line to print to file.
> my $op = extractOutputFields($serviceRecord,
> $billingRecord);
> print FINAL_OUTPUT_FILE $op;
> # found corresponding record in billing file, break out, get
> # next service record and continue scanning billing file
> # where it last left off.
> last;
> }
> $bcount = $bcount + 1; # for debugging
>
And here, the end of the for loop for the billing records, is where you
would seek back to the beginning of the file.
use Fcntl qw(:seek);
seek (SORTED_BILLING_FILE, 0, SEEK_SET);
Normally, you would but your "use" statements at the beginning of the
program, but this works.
> }
> $scount = $scount + 1; # for debugging
> [...]
--
Mumia W.
paduille.4059.mumia.w@earthlink.net
This is a temporary e-mail to help me catch some s-p*á/m.
------------------------------
Date: Sun, 15 Oct 2006 03:19:02 GMT
From: "Mumia W. (reading news)" <paduille.4059.mumia.w@earthlink.net>
Subject: Re: trouble merging files using nested loop to read files
Message-Id: <GMhYg.14001$UG4.5097@newsread2.news.pas.earthlink.net>
On 10/14/2006 08:54 PM, Mumia W. (reading news) wrote:
> [...]
> Normally, you would but your "use" statements at the beginning of the
> program, but this works.
> [...]
s/would but/would put/
;-)
------------------------------
Date: Sat, 14 Oct 2006 20:19:33 -0700
From: theshowmecanuck <theshowmecanuck@no_yahoo_spam.com>
Subject: Re: trouble merging files using nested loop to read files
Message-Id: <4531a896$0$5901$9a6e19ea@news.newshosting.com>
Hi, I am the original poster... I just changed over to my Linux box and the
identity on this news reader is different. :-)
I thought this might be what was happening. I am trying to find a way to
read the file one line at a time. The bill file will eventually grow to
about 1.5 Gigabytes, so I don't want to keep going back to the beginning of
the file as will make this file merge way too slow and inefficient. I now
know I can use seek() but would like to find something that will allow me
to move the file pointer ahead one row at a time rather than by byte...
kind of why I was trying Perl... to simplify and speed up development.
Since these are fixed width format files, I can move the file pointer ahead
the width of the row plus the newline. However, I will have figure out the
length of the record dynamically/programmatically as I don't want to have
to recode anything if they add a couple of new fields to the end of the
record.
If you have any more suggestions please fire away and thanks for the quick
answers.
Cheers,
BillR
Mumia W. (reading news) wrote:
>>
>> for $billingRecord (<SORTED_BILLING_FILE>){
>>
>
> This will only work once because, once the file is read, you're at EOF,
> so the file will not be read again. It's better for you to store the
> data in an array so that you can loop through it again and again:
>
> our @billingRecordArray;
> @billingRecordArray = <SORTING_BILLING_FILE> unless @billingRecordArray;
> for my $billingRecord (@billingRecordArray) {
>
>> $srPayID = substr($service,21,15);
>> $brPayID = substr($billing,211,15);
>> [...]
>
> ObStrict: Write your program to run under strictures and warnings; that
> will catch 50% of your errors:
> use strict;
> use warnings;
>
------------------------------
Date: Sun, 15 Oct 2006 03:34:16 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: trouble merging files using nested loop to read files
Message-Id: <Y_hYg.309$cQ5.273@trndny06>
theshowmecanuck wrote:
> I thought this might be what was happening. I am trying to find a
> way to read the file one line at a time.
>>> for $billingRecord (<SORTED_BILLING_FILE>){
Then probably you want to use "while" instead of "for"
jue
------------------------------
Date: Sun, 15 Oct 2006 07:52:52 GMT
From: "theshowmecanuck (BillR)" <theshowmecanuck@no_yahoo_spam.com>
Subject: Re: trouble merging files using nested loop to read files
Message-Id: <4531e8a9$0$5895$9a6e19ea@news.newshosting.com>
Yes, that was it. I used this:
while (my $billingRecord = <SORTED_BILLING_FILE>)
Thanks.
Now I need to find a way to move the file pointer back one record when I
need to. :-)
(I've progressed far enough to find some logic bugs.)
Thanks again.
------------------------------
Date: Sun, 15 Oct 2006 01:33:38 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: trouble merging files using nested loop to read files
Message-Id: <c-CdnbIGsJUDb6zYnZ2dnUVZ_oudnZ2d@comcast.com>
theshowmecanuck (BillR) wrote:
> Now I need to find a way to move the file pointer back one record when I
> need to. :-)
The example at the end of
perldoc -f seek
shows how it is done. Just keep track of what the current position
was before the read that went to far.
Or write a routine to read_a_line() and one to unread_a_line().
Make the latter put a string into a global variable, and the
former return the content of that variable (instead of reading
input) if the variable is set.
-Joe
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 9849
***************************************