473,324 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

what is the function of "FH" in this program?why we use it in our script?

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use Tk;
  4.  
  5. my $window = MainWindow->new;
  6. $window->title("Host Access Report");
  7. ($lab = $window->Label(-text => "Results go here"))->pack;
  8. $window->Entry(-textvariable => \$nnn )->pack;
  9. $window->Button(-text => "Go", -command => \&but )->pack;
  10. $window->Button(-text => "This is the quit button ", -command => \&finito )->pack;
  11. MainLoop;
  12.  
  13. ################################################## #######
  14.  
  15. sub but {
  16. open (FH,"access_log");
  17. $xxx = grep(/^$nnn /,<FH>);
  18. $lab -> configure(-text => "$nnn called in $xxx times");
  19. $nnn = "";
  20. close FH;
  21. }
  22.  
  23. sub finito{
  24. exit;
  25. }
  26.  
Mar 22 '11 #1
2 1602
miller
1,089 Expert 1GB
FH is a file handle. It's openning the access log and determining how many lines begin with the string in $nnn. You probably want to escape that string in the regex with \Q, but otherwise it appears your code should work fine.

Here's how I'd change it slightly to bring it up to date with modern perl coding practices

Expand|Select|Wrap|Line Numbers
  1. sub but {
  2.     my $file = "access_log";
  3.     open my $fh, $file or die "$file, $!";
  4.     my $count = grep /^\Q$nnn\E /, <$fh>;
  5.     $lab->configure(-text => "$nnn called in $count times");
  6.     $nnn = "";
  7.     close $fh;
  8. }
  9.  
Mar 22 '11 #2
numberwhun
3,509 Expert Mod 2GB
In addition, you may want to read a tutorial on working with files in Perl.

Regards,

Jeff
Mar 22 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Wayne Folta | last post by:
Two observations about PEP-315: 1. It's clever, addresses a definite "wart", and is syntactically similar to try/except. But it's syntax seems like an acquired taste to me. 2. It is a very...
6
by: Juho Saarikko | last post by:
The program attached to this message makes the Python interpreter segfault randomly. I have tried both Python 2.2 which came with Debian Stable, and self-compiled Python 2.3.3 (newest I could find...
34
by: Ross Reyes | last post by:
HI - Sorry for maybe a too simple a question but I googled and also checked my reference O'Reilly Learning Python book and I did not find a satisfactory answer. When I use readlines, what...
1
by: ye juan | last post by:
Hi, all I have some questions to ask: 1. How can I add a standard module named "datetime" in Jython when the error happens :"Traceback (innermost last): File "C:\python\test.py", line 3, in...
0
by: tgkprog | last post by:
hi i'm trying to use Win32::IEAutomation to automate clickbank.com navigation and page saving i can login and go to the https://www.clickbank.com/account/showTransactions.htm page but cannot...
0
by: Kris Kennaway | last post by:
If I do the following: def mmap_search(f, string): fh = file(f) mm = mmap.mmap(fh.fileno(), 0, mmap.MAP_SHARED, mmap.PROT_READ) return mm.find(string) def mmap_is_in(f, string): fh =...
2
by: miller.paul.w | last post by:
On Jun 2, 2:08 am, "kalakouentin" <kalakouen...@yahoo.comwrote: If your files will fit in memory, you can just do text = file.readlines() and Python will read the entire file into a list...
0
by: Gabriel Genellina | last post by:
En Thu, 29 May 2008 19:17:05 -0300, Kris Kennaway <kris@FreeBSD.org> escribió: Looks like you should define the sq_contains member in mmap_as_sequence, and the type should have the...
5
by: Max Ivanov | last post by:
Hi all! When and where I should use try-except-finally statement? What is the difference between: -------- try: A... except: B.... finally: C...
1
by: chungku | last post by:
my frogram for it #!usr/local/bin/perl #program practice $file='input.txt'; open(FH, $file); @line=<FH>; open(OUT, ">>output.txt"); foreach $file(@line) {
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.