|
|
Up |
|
|
  |
Author: markparkmarkpark
Date: Oct 14, 2006 23:02
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;
|
| Show full article (2.05Kb) |
|
| |
4 Comments |
|
  |
Author: Mumia W. (reading news)Mumia W. (reading news)
Date: Oct 14, 2006 18:54
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 () {
> 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 (){
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"...
|
| Show full article (2.14Kb) |
|
| |
1 Comment |
|
  |
Author: Mumia W. (reading news)Mumia W. (reading news)
Date: Oct 14, 2006 18:54
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 ...
|
| Show full article (2.94Kb) |
|
9 Comments |
|
  |
Author: Tad McClellanTad McClellan
Date: Oct 14, 2006 18:25
Dean Of St. Louis Blues 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.
|
| Show full article (2.56Kb) |
|
no comments
|
|
  |
Author: PerlFAQ ServerPerlFAQ Server
Date: Oct 14, 2006 18:03
This is an excerpt from the latest version perlfaq4.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
4.47: How do I handle circular lists?
Circular lists could be handled in the traditional fashion with linked
lists, or you could just do something like this with an array:
unshift(@array, pop(@array)); # the last shall be first
push(@array, shift(@array)); # and vice versa
You can also use "Tie::Cycle":
use Tie::Cycle;
tie my $cycle, 'Tie::Cycle', [ qw( FFFFFF 000000 FFFF00 ) ];
print $cycle; # FFFFFF
print $cycle; # 000000
print $cycle; # FFFF00
--------------------------------------------------------------------
|
| Show full article (1.60Kb) |
|
no comments
|
|
  |
Author: PerlFAQ ServerPerlFAQ Server
Date: Oct 14, 2006 12:03
This is an excerpt from the latest version perlfaq4.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
4.14: How can I compare two dates and find the difference?
(contributed by brian d foy)
You could just store all your dates as a number and then subtract. Life
isn't always that simple though. If you want to work with formatted
dates, the "Date::Manip", "Date::Calc", or "DateTime" modules can help
you.
--------------------------------------------------------------------
|
| Show full article (1.37Kb) |
|
no comments
|
|
  |
Author: bwooster47bwooster47
Date: Oct 14, 2006 11:32
Here's some snippet of alarm usage - but if I do a alarm() for over
2000 seconds, it always gets called much earlier - 100s of seconds
early. Is alarm() not the way to get timers kicking for long duration?
use Time::HiRes qw ( time alarm );
...
$SIG{'ALRM'} = sub { $timerExpired = 1; };
...
$seconds = 6600;
alarm($seconds);
$t1 = time();
while (1) {
.... do stuff.... file read and write, no sleep() or timer calls
here....
last if ($timerexpired);
}
$t2 = time();
print "Time taken (Seconds): ", $t2-$t1;
And the time taken is much lower - more like 2000 seconds instead of
6600 seconds.
|
| Show full article (0.85Kb) |
|
20 Comments |
|
  |
Author: scsc
Date: Oct 14, 2006 06:42
I'm now reading "Network Programming w/ Perl". And I modified an
example, but can not get the same result.
The example is as following, excepted from "Network Programming w/
Perl":
#!/usr/bin/perl
# file: redirect.pl
print "Redirecting STDOUT\n";
open (SAVEOUT,">&STDOUT");
open (STDOUT,">test.txt") or die "Can't open test.txt: $!";
print "STDOUT is redirected\n";
system "date";
open (STDOUT,">&SAVEOUT");
print "STDOUT restored\n";
After running, the contents of test.txt are:
STDOUT is redirected
Sat Oct 14 21:17:30 CST 2006
Then I try to use local to get the same result, but failed. Here's my
program:
#!/usr/bin/perl
|
| Show full article (1.10Kb) |
|
2 Comments |
|
  |
Author: PerlFAQ ServerPerlFAQ Server
Date: Oct 14, 2006 06:03
This is an excerpt from the latest version perlfaq4.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
4.75: How do I verify a credit card checksum?
Get the "Business::CreditCard" module from CPAN.
--------------------------------------------------------------------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
|
| Show full article (1.14Kb) |
|
no comments
|
|
  |
|
|
  |
Author: gavinogavino
Date: Oct 14, 2006 03:40
What is the best perl application server?
Or is it simply an issue of pushing what most app servers do down into
the database.
And keeping web code for querying the db and as little else as possible?
|
| |
|
2 Comments |
|
|
|
|
|
|