[24154] in Perl-Users-Digest
Perl-Users Digest, Issue: 6348 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 31 18:10:43 2004
Date: Wed, 31 Mar 2004 15:10:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 31 Mar 2004 Volume: 10 Number: 6348
Today's topics:
read a paragraph via scrit? (NNTP)
Re: read a paragraph via scrit? <postmaster@castleamber.com>
Re: read a paragraph via scrit? joe@invalid.address
Re: read a paragraph via scrit? <ittyspam@yahoo.com>
Simple File Parse (nick)
Re: Simple File Parse <postmaster@castleamber.com>
Re: trapping errors <bmb@ginger.libs.uga.edu>
Very new to perl <auntie_biotic@tbandu.co.uk>
Re: Very new to perl <auntie_biotic@tbandu.co.uk>
Re: Very new to perl <postmaster@castleamber.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 31 Mar 2004 11:15:27 -0800
From: news8080@yahoo.com (NNTP)
Subject: read a paragraph via scrit?
Message-Id: <110fc16.0403311115.130de45b@posting.google.com>
I'd lile to read the following file and output everything from
'NetBIOS Name Table for Host 192.168.5.10' to the first occurance of
"----------------------------------------"
can perl do that? here is the file (long file but only the portion of
it is shown here)
----------------------------------------
data
data
----------------------------------------
NetBIOS Name Table for Host 192.168.5.11
lines1
line2
Adapter address: 00-00-00-00-00-00
----------------------------------------
NetBIOS Name Table for Host 192.168.5.10
Adapter address: 00-a8-34-35-c3-aa
----------------------------------------
more data
more data
----------------------------------------
------------------------------
Date: Wed, 31 Mar 2004 13:19:56 -0600
From: John Bokma <postmaster@castleamber.com>
Subject: Re: read a paragraph via scrit?
Message-Id: <406b1a47$0$24358$58c7af7e@news.kabelfoon.nl>
NNTP wrote:
> I'd lile to read the following file and output everything from
> 'NetBIOS Name Table for Host 192.168.5.10' to the first occurance of
> "----------------------------------------"
>
> can perl do that?
sure, but can you do it?
> here is the file (long file but only the portion of
> it is shown here)
Read about perl slurp mode, and multi line matching.
You can also read the file line by line, setting a $state variabele to
zero before you start to read, and when you "see" the NetBIOS (see:
perldoc -f index), set $state to 1, and print the line, and every line
after if $state == 1, except when you "see" the ---- stuff. Then you set
the state back to 0.
--
John personal page: http://johnbokma.com/
Freelance Perl / Java developer available - http://castleamber.com/
------------------------------
Date: Wed, 31 Mar 2004 19:31:34 GMT
From: joe@invalid.address
Subject: Re: read a paragraph via scrit?
Message-Id: <m3hdw4byp9.fsf@invalid.address>
news8080@yahoo.com (NNTP) writes:
> I'd lile to read the following file and output everything from
> 'NetBIOS Name Table for Host 192.168.5.10' to the first occurance of
> "----------------------------------------"
>
> can perl do that? here is the file (long file but only the portion of
> it is shown here)
Sure, but awk is probably easier, and awk is more likely to be on any
given machine.
awk '/^NetBIOS Name Table/,/^----------------------------------------/' data
Joe
--
If people don't want to come out to the ballpark, nobody's going
to stop them.
- Yogi Berra
------------------------------
Date: Wed, 31 Mar 2004 14:41:32 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: read a paragraph via scrit?
Message-Id: <20040331144033.D19862@dishwasher.cs.rpi.edu>
On Wed, 31 Mar 2004, NNTP wrote:
> I'd lile to read the following file and output everything from
> 'NetBIOS Name Table for Host 192.168.5.10' to the first occurance of
> "----------------------------------------"
>
> can perl do that? here is the file (long file but only the portion of
> it is shown here)
>
Presuming that line of dashes is constant-width, just change what Perl
considers to be the end of a line, by using the $/ variable. Read about
it in
perldoc perlvar
Paul Lalli
>
>
>
> ----------------------------------------
> data
> data
> ----------------------------------------
> NetBIOS Name Table for Host 192.168.5.11
> lines1
> line2
>
> Adapter address: 00-00-00-00-00-00
> ----------------------------------------
>
> NetBIOS Name Table for Host 192.168.5.10
>
> Adapter address: 00-a8-34-35-c3-aa
> ----------------------------------------
> more data
> more data
> ----------------------------------------
>
------------------------------
Date: 31 Mar 2004 13:19:52 -0800
From: nfemal@findorff.com (nick)
Subject: Simple File Parse
Message-Id: <d7b63544.0403311319.be0377b@posting.google.com>
I recently downloaded Doug Knox's vb script which defrags all drives
in windows xp. This script creates ‘defragreport.txt' on the first
drive it finds. My question is how can I pull information from this
‘defragreport.txt', which will reside on 50-60 pc's, and create a
single file (.xls or .csv) which will be checked to make sure
everything ran properly? In the file I would like to have the name of
the computer from which the ‘defragreport.txt' came and the necessary
information from the .txt file.
The ‘defragreport.txt' looks as follows:
3/25/2004
10:06:11 AM
Drive C: Defrag completed successfully
Drive D: Defrag completed successfully
Drive E: Defrag completed successfully
Any help would be greatly appreciated.
------------------------------
Date: Wed, 31 Mar 2004 16:40:42 -0600
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Simple File Parse
Message-Id: <406b493b$0$24342$58c7af7e@news.kabelfoon.nl>
nick wrote:
> I recently downloaded Doug Knox's vb script which defrags all drives
> in windows xp.
Is this really needed with NTFS? And why on earth VB script? :-D
> This script creates ‘defragreport.txt' on the first
> drive it finds. My question is how can I pull information from this
> ‘defragreport.txt', which will reside on 50-60 pc's, and create a
> single file (.xls or .csv) which will be checked to make sure
> everything ran properly? In the file I would like to have the name of
> the computer from which the ‘defragreport.txt' came and the necessary
> information from the .txt file.
>
> The ‘defragreport.txt' looks as follows:
>
> 3/25/2004
>
> 10:06:11 AM
>
> Drive C: Defrag completed successfully
>
> Drive D: Defrag completed successfully
>
> Drive E: Defrag completed successfully
>
> Any help would be greatly appreciated.
First there must be a way that each report gets on one machine. You
could decide to share each drive as read only.. but... that sounds a bit
unsecure to me. Maybe let each computer upload the report to a central
computer? The hostname can be used to identify which report belongs to
which computer. No need to merge all in one file if checking is all you
want. You just have to look at each file for a not completed
successfully message. If you decide for the "each computer uploads his
report", you can maybe let each computer check its report, and reports
only if an error occured, to a central computer. Maybe using a webserver
on the central computer, and POSTing the problem?
Anyway, the main problem is not the glueing together, but how to get the
reports on one computer :-D
--
John personal page: http://johnbokma.com/
Freelance Perl / Java developer available - http://castleamber.com/
------------------------------
Date: Wed, 31 Mar 2004 14:49:23 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: trapping errors
Message-Id: <Pine.A41.4.58.0403311430170.13714@ginger.libs.uga.edu>
On Wed, 31 Mar 2004, Simon wrote:
> How can I trap an error and let the program continue without aborting e.g
>
> I know the die can abort on errors but not sure how to trap the error it
> generates and let the program continue.
>
> e.g the following program opens four dirs and read the contents and returns
> dir count.
You can use eval to trap errors in your programs, but in this case, I
don't think you have to do that. You're already testing for the error by
checking the return value from opendir. See below.
>
> #!/perl/bin/perl -w
>
> use strict;
> my($dir1, $dir2, $dir3, $dir4, @file_count, $count, @hold_paths, $num,
> @hold_all, $directory_numbers,
>
> $value, $len);
BTW, it's generally better to declare your variables just before they're
used rather than in a bunch at the top.
>
> # These are the directory tree paths,
> $dir1 = '/tools';
> $dir2 = '/test';
> $dir3 = '/develop';
> $dir4 = '/utils';
>
> @hold_paths = ($dir1,$dir2,$dir3,$dir4);
Why not the following, and drop the $dir...'s:
@hold_paths = qw(
/tools
/test
/develop
/utils
);
>
>
> $num = 0;
> for(@hold_paths) { # iterate over each path, open the dir read num of files,
> put into array @hold_all
>
>
> opendir(DIR, $hold_paths[$num]) || die "can't opendir
> $hold_paths[$num]: $!";
> @file_count = readdir(DIR);
> $hold_all[$num] = $hold_paths[$num] ." ". scalar(@file_count) ."\n";
> closedir DIR || die "can't opendir $hold_paths[$num]: $!";
> $num++;
> }
>
Okay, here's where you test your opendir. Rather than "|| die", try this:
if( opendir(DIR, $hold_paths[$num]) ) {
@file_count = readdir(DIR);
$hold_all[$num] = $hold_paths[$num] ." ". scalar(@file_count) ."\n";
closedir DIR || die "can't opendir $hold_paths[$num]: $!";
$num++;
}
But our loop is a bit confused; you don't need $num. Compare to this:
for( @hold_paths ) {
if( opendir(DIR, $_) ) {
my $file_count = readdir(DIR);
push @hold_all, "$_ $file_count\n";
closedir DIR || die "can't closedir $_: $!";
}
}
And you do know that the file '.' is included in your file count?
>
>
> $directory_numbers = 'dir.txt'; # will write to current directory, unless
> #you put a 'path'
> # this is the file your
> writing you data #to
> # This is where you actually write to the file
> # Will 'overwrite' file each time
> open(FILE, ">$directory_numbers") || die "can't open $hold_paths[$num]:
> $!";
> print FILE @hold_all;
> close FILE || die "can't close $hold_paths[$num]: $!";
-----------------------------------^^^^^^^^^^^^^^^^^
Recheck your copy/pastes.
Regards,
Brad
------------------------------
Date: Wed, 31 Mar 2004 23:52:39 +0100
From: "auntie_biotic" <auntie_biotic@tbandu.co.uk>
Subject: Very new to perl
Message-Id: <c4fi3r$jea$1@news7.svr.pol.co.uk>
First of all sorry if this is the wrong place to post this question.
I have a message board on my site at present, but it contains adverts which
I would rather not have and am trying to build my own
I had never heard of perl before yesterday. However, I managed to adjust
the pl.file for my guestbook which appears to work ok.
For the life of my I cannot tell what I have done wrong in my message board
pl.file. I have placed my perl files in cgi-bin.
When I click on my message board
http://www.tbandu.co.uk/wwwboard/wwwboard.html
everything appears ok. After trying to post a message I receive the
following message.
"Internal Server Error
The server encountered an internal error or misconfiguration and was unable
to complete your request.
Please contact the server administrator, webmaster@tbandu.co.uk and inform
them of the time the error occurred, and anything you might have done that
may have caused the error.
More information about this error may be available in the server error log."
I think I have messed up one of three lines of code. Could you please tell
me I have correctly adapted them
1. <form method=POST action="http://your.host.xxx/cgi-bin/wwwboard.pl">
I changed this to
<form method=POST
action="http://www.tbandu.co.uk/cgi-bin/wwwboard.pl">
2. $baseurl = http://your.host.xxx/wwwboard;
I changed this to
$baseurl = http://www.tbandu.co.uk/wwwboard;
3. $cgi_url = http://your.host.xxx/cgi-bin/wwwboard.pl;
I changed this to
$cgi_url = http://your.host.xxx/cgi-bin/wwwboard.pl;
I hope someone will be able to help.
Thanks in advance
--
auntie_biotic
http://www.tbandu.co.uk
------------------------------
Date: Wed, 31 Mar 2004 23:57:40 +0100
From: "auntie_biotic" <auntie_biotic@tbandu.co.uk>
Subject: Re: Very new to perl
Message-Id: <c4fid7$6j6$1@newsg1.svr.pol.co.uk>
PS my third line of confusing perl is
3. $cgi_url = http://your.host.xxx/cgi-bin/wwwboard.pl;
I changed this to
$cgi_url = http://www.tbandu.co.uk/cgi-bin/wwwboard.pl;
rather than stated in previous mail
sorry!!!!!
"auntie_biotic" <auntie_biotic@tbandu.co.uk> wrote in message
news:c4fi3r$jea$1@news7.svr.pol.co.uk...
> First of all sorry if this is the wrong place to post this question.
>
> I have a message board on my site at present, but it contains adverts
which
> I would rather not have and am trying to build my own
> I had never heard of perl before yesterday. However, I managed to adjust
> the pl.file for my guestbook which appears to work ok.
> For the life of my I cannot tell what I have done wrong in my message
board
> pl.file. I have placed my perl files in cgi-bin.
>
> When I click on my message board
> http://www.tbandu.co.uk/wwwboard/wwwboard.html
> everything appears ok. After trying to post a message I receive the
> following message.
>
> "Internal Server Error
> The server encountered an internal error or misconfiguration and was
unable
> to complete your request.
> Please contact the server administrator, webmaster@tbandu.co.uk and inform
> them of the time the error occurred, and anything you might have done that
> may have caused the error.
> More information about this error may be available in the server error
log."
>
>
> I think I have messed up one of three lines of code. Could you please
tell
> me I have correctly adapted them
>
> 1. <form method=POST action="http://your.host.xxx/cgi-bin/wwwboard.pl">
> I changed this to
> <form method=POST
> action="http://www.tbandu.co.uk/cgi-bin/wwwboard.pl">
>
> 2. $baseurl = http://your.host.xxx/wwwboard;
> I changed this to
> $baseurl = http://www.tbandu.co.uk/wwwboard;
>
>
> 3. $cgi_url = http://your.host.xxx/cgi-bin/wwwboard.pl;
> I changed this to
> $cgi_url = http://your.host.xxx/cgi-bin/wwwboard.pl;
>
> I hope someone will be able to help.
> Thanks in advance
> --
> auntie_biotic
> http://www.tbandu.co.uk
>
>
>
------------------------------
Date: Wed, 31 Mar 2004 17:02:25 -0600
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Very new to perl
Message-Id: <406b4e60$0$24352$58c7af7e@news.kabelfoon.nl>
auntie_biotic wrote:
> First of all sorry if this is the wrong place to post this question.
If in doubt, make sure before you post.
> "Internal Server Error
> The server encountered an internal error or misconfiguration and was unable
> to complete your request.
> Please contact the server administrator, webmaster@tbandu.co.uk and inform
> them of the time the error occurred, and anything you might have done that
> may have caused the error.
> More information about this error may be available in the server error log."
Did you read that last line of useful advice, or just ignored it? If you
did check the error_log, as you should have done, why did you not
include the message?
Did you check the script from the shell? (Using for example PuTTY to
connect to the server secure?) Where did you get this script?
Also note that many CGI scripts are crap & unsecure. Are you able to
understand the risks and able to see if your script falls in the c & u
category?
> 2. $baseurl = http://your.host.xxx/wwwboard;
> I changed this to
> $baseurl = http://www.tbandu.co.uk/wwwboard;
>
> 3. $cgi_url = http://your.host.xxx/cgi-bin/wwwboard.pl;
> I changed this to
> $cgi_url = http://your.host.xxx/cgi-bin/wwwboard.pl;
Both lines are wrong. Read on Perl scalars and strings for more
information. Also, copy lines in your posting, don´t type what you think
was there, I see no change in 3. (except 2 more spaces).
And yes, I think this is a c and maybe even a c & u script :-D.
--
John personal page: http://johnbokma.com/
Freelance Perl / Java developer available - http://castleamber.com/
------------------------------
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 6348
***************************************