[16528] in Perl-Users-Digest
Perl-Users Digest, Issue: 3940 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 7 18:10:51 2000
Date: Mon, 7 Aug 2000 15:10:28 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <965686228-v9-i3940@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 7 Aug 2000 Volume: 9 Number: 3940
Today's topics:
Re: How to open web page from Perl script hla_sa@my-deja.com
Re: How to open web page from Perl script (Colin Keith)
How to parse an odd file format? <smerr612@mailandnews.com>
Re: Hyperlink Patterns (Colin Keith)
install_driver error ? <kaamraanNOkaSPAM@hotmail.com.invalid>
Re: install_driver error ? (NP)
Re: install_driver error ? <kaamraanNOkaSPAM@hotmail.com.invalid>
Re: IP spoofing <dan@tuatha.sidhe.org>
Newbie error: arrays are not returned from subs correct <grinnell@american.edu>
Re: Newbie error: arrays are not returned from subs cor <lr@hpl.hp.com>
newbie question concerning a mail string... <chris@dslbroadband.com>
Re: newbie question concerning a mail string... <tony_curtis32@yahoo.com>
parsing PDF <nlymbo@mindspring.com>
Perl and Ftp question sankarmukh@my-deja.com
Re: Perl Newbie Question <lr@hpl.hp.com>
Perl to excel levo99@my-deja.com
Re: Perl to excel <jeff@vpservices.com>
Re: Perl to excel <amonotod@netscape.net>
Re: Please help me! <mark325@hotmail.com>
Re: Please help me! (Colin Keith)
Problem With AT Command, DBI ODBC on NT4 bayers@my-deja.com
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 07 Aug 2000 18:02:14 GMT
From: hla_sa@my-deja.com
Subject: Re: How to open web page from Perl script
Message-Id: <8mmtj1$d4m$1@nnrp1.deja.com>
Thanks. It would be running a stand alone script on the server.
Shouldn't use lwp::simple;
print get "http:// ... .html";
work ? It's not for me.
In article <87hf8xyo89.fsf@limey.hpcc.uh.edu>,
Tony Curtis <tony_curtis32@yahoo.com> wrote:
> >> On Mon, 07 Aug 2000 17:09:59 GMT,
> >> hla_sa@my-deja.com said:
>
> There's a number of questions in there, all related but
> somewhat different.
>
> > I'm new to Perl and need to know how to open an existing
> > web page from within a Perl script.
>
> with the LWP modules:
>
> perldoc lwpcook
>
> [ I think open() is a bit of a misnomer, "fetch" might be
> better, or maybe it's just me... ]
>
> > After a login verification my Perl script should open a
> > new web page in the browser. The login check is working
>
> If you're talking about the WWW and using the server's
> (basic) protection mehanisms, then it's not "login", but
> "authentication". If not, then you might need to expand
> further on what you're doing.
>
> You can send back a redirection,
>
> perldoc CGI
>
> redirect() method
>
> > p.s. How is another Perl script called from with a
> > running script ?
>
> It depends on what you're trying to do. Do you want to
> import some functionality from a module/library? Run a
> standalone perl program on the server, possibly collecting
> the output for processing and return to the requesting
> client? Or do you want to cause some web server to invoke
> something through CGI, and pass the parameters over like a
> GET/POST request?
>
> hth
> t
> --
> "With $10,000, we'd be millionaires!"
> Homer Simpson
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 07 Aug 2000 18:46:39 GMT
From: newsgroups@ckeith.clara.net (Colin Keith)
Subject: Re: How to open web page from Perl script
Message-Id: <juDj5.94$DT4.2853094@nnrp2.clara.net>
In article <8mmqh2$aaj$1@nnrp1.deja.com>, hla_sa@my-deja.com wrote:
do you think perl6 can have a counterpart for "use strict", "be vague"?
>I'm new to Perl and need to know how to open an existing web page from
>within a Perl script. After a login verification my Perl script should
>open a new web page in the browser. The login check is working but I
>don't know how to redirect the browser to a new webpage
>programmatically. A simple example should suffice. Thanks.
Sooo many people come here assuming that we know what you're thinking. We
don't, please try and think of it that way and provide full information. Do
you mean
a) Another resource (web page or CGI script) that can be reached via a URL?
b) A HTML formatted text file stored on the same computer ?
The two are different but both covered by what you said.
a) Redirect the browser to the other page using Location: / URI: headers.
You can access this from the CGI pm using the function redirect() (read
the documentation for details and examples of use) If your 'login' is done
by a CGI script and not by HTTP-Authentication, then you will either have
to set a cookie (Also supported by CGI) if the page is in the same domain,
or you'll have to return a URL with a query_string embedded into it. I.e.
print $cgi->redirect(-uri=>'http://www.server2.com/cgi-bin/authed?uid=5x');
If you are using HTTP-Authentication, then the agent (browser) making the
request will send the username/password and your server will verify the
user before your script even sees it. You can then use CGI's
remote_user() method (don't bother with user_name() it won't get what
you want)
b) Read the file off the disk. Parse it for dubious data Print it back to
the browser.
>p.s. How is another Perl script called from with a running script ?
Again, it depends what you mean. If you mean a CGI script, that depends. You
could use one of the LWP::* modules to open a connection to that other CGI
script. If you mean how to I execute a local program, then using backticks,
(`), open(), system(), etc. depending on what you want to do. For instance,
if your other perl script might be a running daemon and you have to connect
to a unix socket a network socket, use a named pipe or using IPC. (man
perlipc for details)
This is not designed to confuse you or put you off, but to try and cover a
wide variety of the topics that you have included by not specifying exactly
what you mean. If you need more details, check out the man pages that I've
suggested ( `, open(), system(), exec(), etc are covered in perlfunc), they
usually come with examples. If it doesn't quite fit or you're still not sure
or you get stuck with what you see, come back with the details of what
you're trying to do, your code and the output (copy and paste the code,
don't retype it)
Col.
---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC
------------------------------
Date: Mon, 07 Aug 2000 21:19:53 GMT
From: Steven Merritt <smerr612@mailandnews.com>
Subject: How to parse an odd file format?
Message-Id: <8mn95i$mjt$1@nnrp1.deja.com>
I've got an old logfile that I'm re-writing the interface to.
Specifically I'm needing to get some more search functionality into it.
The difficulty I'm having is getting the data into a data structure so
I can manipulate it.
The basic layout of the input file is like this
(space)\n
+>date timestamp - operator(required) (optional) status:whatever
Who: some guy (optional)
Contact: Guy's number(optional)
What To: where they want something done(optional)
Account: number(optional)
blah blah blah whatever was done, sometimes repeating for a lot
of lines blah blah blah
(space)\n
At the moment I'm doing something like this(pseudocode)
while <filehandle>{
#toss out the first line
if ($. == 1) {
$_ = <filehandle>;
}
#snag date stamp
$datestamp = substr($_, 2, 17)
# snag the rest of the line and split it on the "status" tag
($name, $status) = split /Status: /, (substr ($_, 22, ((length) -
22)));
# onto the next line and parse it
$_ = <filehandle>;
($junk, $who) = split /Who: /, $_;
#second verse same as the first
$_ = <filehandle>;
($junk, $Contact) = split /Contact: /, $_;
$_ = <filehandle>;
($junk, $What) = split /What To: /, $_;
$_ = <filehandle>;
($junk, $Account) = split /Account: /, $_;
# Now we need to get the description
# The beginning of a record is marked by +>
# but all the records are seperated by a space-newline
# on a line by themselves, we'll stop when we see those
# so the next line read by the outer loop will always
# be the beginning of the next record
$_ = <filehandle>;
until (/^\s\n/) {
$description = $description . $_;
$_ = <filehandle>;
}
It can sucessfully grab the date, operator and status(when present,
gives substr out of range when no status, not sure why the (length -
22) isn't working, to my mind it means get the substring starting from
the 22nd byte that is the total length of the string - the first 22
bytes, so that should be the rest of the string) The really confusing
thing is sometimes the splits grab the data properly, sometimes they
don't. It turns input like this
+>20000724 11:06:51 -
Geoff
Application: a4
Environment: T1
Referencing Phone: 976-328-7448
Referencing Party: Duncan McLeod
Ticket: 2
Called Duncan. I closed the EER.
+>20000724 11:01:59 -
nancy
Application: CI/WW/CX
Environment: E3
Referencing Phone:
Referencing Party: production migration
Ticket:
deployed all c0058 and c0193 to production management for header
ci004991.
also, deployed cx for fdp01.
into something like this
20000724 11:06:51
Use of uninitialized value at timestampread.pl line 35, <FH> chunk 36.
(not a problem, it's simply because this entry doesn't have a status,
It's just a problem in the test script because I'm printing this stuff,
in the final result I'll be assigning it to an array of hashes to
search against)
Geoff
Use of uninitialized value at timestampread.pl line 44, <FH> chunk 37.
Use of uninitialized value at timestampread.pl line 48, <FH> chunk 38.
(These are part of the problem. Not sure why, the split works fine in
other parts of the program)
976-328-7448
Duncan McLeod
2
Called Duncan. I closed the EER.
20000724 11:01:59
Use of uninitialized value at timestampread.pl line 35, <FH> chunk 45.
nancy
Use of uninitialized value at timestampread.pl line 44, <FH> chunk 46.
Use of uninitialized value at timestampread.pl line 48, <FH> chunk 47.
production migration
deployed all c0058 and c0193 code to production for
header
ci004991.
also, deployed cx code for fdp01.
There are cases where it aparently gets out of sync even worse and
gives me nothing but errors on all the splits. But the input file is
regular, and I'm not sure what the problem is.
My next step is to try to read in an entire record and then begin
splitting on newlines, if they contain one of the tags, Who: Status:
etc, then I know what each line is and how to deal with it, any without
tags are description by default.
Steven
--
King of Casual Play
The One and Only Defender of Cards That Blow
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 07 Aug 2000 18:50:56 GMT
From: newsgroups@ckeith.clara.net (Colin Keith)
Subject: Re: Hyperlink Patterns
Message-Id: <kyDj5.95$DT4.2853602@nnrp2.clara.net>
In article <06ba2d80.66d12260@usw-ex0104-031.remarq.com>, Samay <samay1NOsaSPAM@hotmail.com.invalid> wrote:
>Hi, I have bunch of hyperlinks, and I am trying to figure out
>the different patterns.
patterns?
>Is there any simple program which exists to do this?
>
>Sample patterns are:
>
>xyz.htm
>xyz.html
>xyz.htm#abc
>xyz.html#abc
>http://www.somesite.com/dir1/dir2/xyz.htm
>http://www.somesite.com/cgi-bin/script.pl?query
Pretty, but meaningless. Some of them are filenames, some are filenames with
named sections - both can be classified as partial URL's - the others are
complete URL's, one requesting a file, the other passing query_string data.
And with the obvious description out of the way, what do you want to do with
this data? Organise it by line length. Organise it by protocol, or the
resource that's being pointed to ..? Please, 'patterns' doesn't mean
anything out of context, followup with a description of what you want to do
and what you've done to try to sort the problem, or how you're thinking
about approaching the problem, using Perl to do the processing and why you
think/don't think it will work.
Col.
---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC
------------------------------
Date: Mon, 07 Aug 2000 11:17:32 -0700
From: kaamraan <kaamraanNOkaSPAM@hotmail.com.invalid>
Subject: install_driver error ?
Message-Id: <08497f3e.1066111e@usw-ex0103-024.remarq.com>
I have a Perl script which does a bunch of SQL stuff on
a Oracle database. The script runs fine on some Unix boxes, but
on one Unix
box I get
install_driver(Oracle) failed: Can't load
'/usr/local/lib/perl5/site_perl/5.005/sun4-solaris/auto/DBD/Oracl
e/Oracle.so' for module DBD::Oracle: ld.so.1:
/usr/local/bin/perl: fatal: libclntsh.so.1.0: open failed: No
such file or directory at
/usr/local/lib/perl5/5.00502/sun4-solaris/DynaLoader.pm line 168.
at (eval 1) line 2
at tst2.pl line 4
kaamraan
-----------------------------------------------------------
Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com
------------------------------
Date: Mon, 07 Aug 2000 18:34:03 GMT
From: nvp@spamnothanks.speakeasy.org (NP)
Subject: Re: install_driver error ?
Message-Id: <viDj5.217665$t91.1964303@news4.giganews.com>
<kaamraanNOkaSPAM@hotmail.com.invalid> wrote:
:
: install_driver(Oracle) failed: Can't load
: '/usr/local/lib/perl5/site_perl/5.005/sun4-solaris/auto/DBD/Oracl
: e/Oracle.so' for module DBD::Oracle: ld.so.1:
: /usr/local/bin/perl: fatal: libclntsh.so.1.0: open failed: No
Is your ORACLE env setup correctly? Did you try modifying your
LD_LIBRARY_PATH? When DBD::Oracle failed to work for me, I found that
one or the other or both of those things wasn't configured correctly.
--
Nate II
------------------------------
Date: Mon, 07 Aug 2000 12:26:48 -0700
From: kaamraan <kaamraanNOkaSPAM@hotmail.com.invalid>
Subject: Re: install_driver error ?
Message-Id: <1cd3eef3.2277c62c@usw-ex0103-024.remarq.com>
Hey Nate II :-)
My LD_LIBRARY_PATH was pointing at Oracle8 directories,
while my database was Oracle7. When I fixed this env
variable, it all worked out !
Thank You
kaamraan
-----------------------------------------------------------
Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com
------------------------------
Date: Mon, 07 Aug 2000 20:17:12 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: IP spoofing
Message-Id: <cPEj5.13202$f_5.66633@news1.rdc1.ct.home.com>
DT <dsa@dassda.com> wrote:
>> Oh, I can see a legitimate reason for doing that. Surely if a search engine
>> has restrictions on what you can submit you should be a good little net
>> puppy and abide by them. You know just being nice since you want to use
>> their service ...
>>
> I want to provide search engine submission service, using a script,
> however, also heared that search engines don't like mass submission even
> if the URLs are from different domains. I need a solution, that's why, I
> think of using 'ip spoofing'.
What, another one? Just what the world needs.
Listen, mass URL sumbission services just don't work. Sumbit a single URL
and the engines don't care where you came from, submit a bunch and they
don't really care that they came from different places.
Besides, perl's rather too high-level to do IP spoofing, and even if you
could do it, it only works in the way you'd need it to for machines on the
same subnet. Guaranteed the engines aren't, and if they were you wouldn't
need to ask.
Dan
------------------------------
Date: Mon, 07 Aug 2000 16:11:18 -0400
From: Michael Grinnell <grinnell@american.edu>
Subject: Newbie error: arrays are not returned from subs correctly
Message-Id: <1u5uoso3urrvejpqsma08laj5budkgaa8q@4ax.com>
The problem I have is as follows:
In some subs, not all, when I return an array, it doesn't get copied
back into main correctly. The subs work properly, Tracing it, the
program works up until the point where it tries to return the array.
I'm baffled. Any help would be greatly appreciated.
I'm using Redhat 6.2, Perl 5.005_03
TIA,
Michael Grinnell
###########################
#!/usr/bin/perl
use Getopt::Long;
use IO::File;
use vars '$DEBUG';
$main::DEBUG = 1;
$main::ENTRIES = 288; # The number of mrtg log entries in a 24 hour
period,
# running at 5 min. intervals
# Constants - indicates which column of the logfile to look at,
# 0 being the first column. Also used for subscripting
%main::sortby = (
'CUR_IN' => '1',
'MAX_IN' => '2',
'CUR_OUT' => '3',
'MAX_OUT' => '4'
);
sub main {
# Get Command line options
%main::options = ();
my ($result);
# Just need to make sure that all perl installations have the GetOpt
module
# Hash for the command-line options
$result = GetOptions(\%options,'results=i','getMAC','html:s',
'files=s', 'sortby=s', 'ignorelist=s', 'filelist=s', 'base_href=s');
# Check to make sure it returns Ok
if($result == 0 )
{
print_usage();
exit 1;
}
# Setup default values
unless (defined $main::options{"results"}) {
$main::options{"results"} = 9; # In reality, 10
(arrays start with 0...)
}
else {
$main::options{"results"}--; # else decrement by
one because arrays start with 0
}
unless (defined $main::options{"files"}) {
$main::options{"files"} = '*.log';
}
for ($main::options{"sortby"}) {
/MAX_IN/ and do {last;};
/CUR_OUT/ and do {last;};
/MAX_OUT/ and do {last;};
do {$_ = 'CUR_IN'; last;};
}
if (defined ($main::options{"html"})) {
if ($main::options{"html"} eq "")
{$main::options{"html"} = 'index.html';}
else {
unless ($main::options{"html"} =~ /\.htm/)
{$main::options{"html"} = 'index.html';}
}
}
unless (defined $main::options{'base_href'}) {
$main::options{'base_href'} = "";
}
# Open filelist if available
if ($main::options{"filelist"}) {
my (@file_list) =
open_file_list($main::options{"filelist"});
goto CONTINUE;
}
##
## For some reason, the _assignment_ below does not work if it's in a
conditional statement
## i.e. an else that follows the above if() statement
## I have no idea why. Using perl -d you can walk through it and the
sub is working correctly,
## but when it returns the array to main, all the info disappears
##
# Get the file list based on a pattern passed at the command line (or
the default one)
my (@file_list) = get_file_list($main::options{"files"});
CONTINUE:
# Open ignorelist if available
my (@ignore_list) =
open_file_list($main::options{"ignorelist"});
## The problem occurs here too, the array returned from
open_file_list() does
## not get copied into the array variable. If I copy the subroutine
code
## into main(), it works because it's no longer copying the array, but
then
## the line below fails. @new_file_list doesn't get the array that is
passed back
## from array_intersect(). Passing array refs doesn't work either.
# If there exists both a file_list and an ignorelist, intersect them
to remove common entries
if (@ignore_list && @file_list) {
my(@new_file_list) = array_intersect(\@ignore_list,
\@file_list);
}
# Create temp file for holding values: Automatically cleaned up
my ($temp_file) = IO::File->new_tmpfile or die "Unable to
create temporary file: $!\n";
$temp_file->autoflush(1);
# Loop for processing each file
my($file);
foreach $file (@new_file_list) {
if ($file =~ /^\s/) {next;} # Just in case, strip out
entries that are blank
my (@log_entries_list) = get_logfile_entries($file);
# Debug Code
# if($main::DEBUG) {
# print_array_of_arrays(@log_entries_list);
# }
my (@prelim_results_list) =
get_average($main::sortby{"$main::options{\"sortby\"}"},
@log_entries_list);
unless (@prelim_results_list) {next;} # Get an empty
list back, go back to the top
write_temp_file($temp_file, $file,
@prelim_results_list);
} # end foreach $file
# Debug Code
if($DEBUG) {print
"########################################################\n";}
my (@top_entries_list) = read_temp_file($temp_file);
# if($main::DEBUG) {
# print_array_of_arrays(@top_entries_list);
# }
my (@final_results) = sort_entries
($main::sortby{"$main::options{\"sortby\"}"},$main::options{"results"},
@top_entries_list);
write_html_output($main::options{"html"},
$main::options{'base_href'}, @final_results);
} # end main()
&main;
exit 0;
########################################
##
## Subroutines
##
########################################
sub array_intersect {
my ($ignore_array_ref, $keep_array_ref) = @_;
my (%union, %isect, $temp);
foreach $temp (@$ignore_array_ref) {$union{$temp} = 1}
foreach $temp (@$keep_array_ref) {unless ($union{$temp})
{$isect{$temp} = 1}}
@isect = keys %isect;
return @isect;
}
sub open_file_list {
my ($file_list) = @_;
my (@array, $line);
open FILE, "<$file_list" or warn "Unable to open $file_list :
$!\n";
while (<FILE>) {
if (/^\#/) {next;}
chomp;
push @array, $_;
}
close FILE or warn "Error closing $file_list : $!\n";
return (@array);
}
sub get_average {
my ($sortby, @array) = @_;
my ($i, $j, @results);
my ($temp) = 0;
unless ($#array > 0) {return;} # Error Checking code. Don't
allow empty arrays (Needed?)
for $i (0 .. $#array) {
$temp += $array[$i][$sortby];
}
if ($temp <= 0) {return;} # Error Checking code. Don't allow
divide by 0
# if ($DEBUG) {
# print "\$temp\t=> $temp\n";
# print "\$\#array\t=> $#array\n";
# }
$temp /= ($#array + 1);
for $i (0 .. 1) {
for $j (0 .. $#{$array[$i]}) {
$results[$i][$j] = $array[$i][$j];
}
$results[$i][$sortby] = $temp;
}
return @results;
}
sub write_html_output {
my ($html_filename, $base_href, @array) = @_;
my (@html_files);
unless ($base_href eq "") {
$base_href = '<BASE HREF = "' . "$base_href" . '">';
print STDERR "\$base_href\t=>$base_href\n";
}
# Open the HTML file
open (HTMLFILE, ">$html_filename") or warn "Error creating
$html_filename: $!\n";
# print the header
print HTMLFILE <<HEADER;
<HTML>
<HEAD>
<TITLE>List of busiest ports sorted by
$main::options{"sortby"}</TITLE>
$base_href
</HEAD>
<BODY>
HEADER
my ($i, $j, $temp);
for $i (0 .. $#array) {
$temp = $array[$i][$#{$array[$i]}];
$temp =~ s/\.log/\.html/;
print HTMLFILE <<BODY;
<H1 ALIGN="CENTER">$1 <a href="$temp"> $temp </a></H1>
BODY
}
print HTMLFILE <<FOOTER;
</BODY>
</HTML>
FOOTER
# Put a loop in here to find the logfile name, change it to an html
file, then write results to a
# formatted html file, default = index.html
# Include How they were sorted, make html files links to mrtg files,
}
sub read_temp_file {
my ($temp_file) = @_;
my (@array, @tmp);
seek ($temp_file, 0, 0) or die "Error rewinding $temp_file :
$!\n";
while(<$temp_file>) {
@tmp = split;
push @array, [@tmp];
} # end while($temp_file)
return @array;
}
sub print_array_of_arrays {
my (@array, $target) = @_;
unless (defined ($target)) {$target = "STDOUT";}
my ($i, $j);
for $i (0 .. $#array) {
for $j (0 .. $#{$array[$i]} ) {
print $target "Element $i, $j\t=>
$array[$i][$j]\n";
}
}
}
sub sort_entries {
my ($criteria, $results, @entries_list) = @_;
# $criteria = $main::sortby{"$criteria"};
my (@sorted_results);
@sorted_results = sort { $b->[$criteria] <=> $a->[$criteria] }
@entries_list;
if ($#sorted_results > $results) {$#sorted_results =
$results;} # Truncate list
# Debug Code
if ($DEBUG) {
print "Array sorted by column $criteria:\n";
print_array_of_arrays(@sorted_results);
}
return @sorted_results;
}
sub write_temp_file {
my ($temp_file, $name, @entry_list) = @_;
my ($i, $j, $k);
unless (defined ($entry_list[0][0])) {return;} # weed out
empty lists
$k = $#{$entry_list[1]}; # use the second entry, because the
first is weird
for $i (0 .. ($#entry_list -1)) {
for $j (0 .. $k) {
print $temp_file "$entry_list[$i][$j] ";
}
print $temp_file "$name\n"; # add the name of the log
file to the array
}
}
sub get_logfile_entries {
my($logfile) = @_;
my($i) = 0;
my(@log_entries, @tmp);
open (LOGFILE, "<$logfile") or warn "Error opening $logfile:
$!\n";
# DEBUG Code
# if ($DEBUG) {print "Log Entries for $logfile :\n";}
# && $i < $main::ENTRIES
while(<LOGFILE>) {
@tmp = split;
unless (defined ($tmp[3])) {next;} # Skip over
incomplete entries in the log file
unless ($tmp[1] && $tmp[3]) {last;} # skip all the
lines at the end with no values
unless ($i < $main::ENTRIES) {last;}
push @log_entries, [@tmp];
$i++;
}
return @log_entries;
} # end sub get_logfile_entries
sub print_usage {
print "Printing Usage...\n";
}
sub get_file_list {
my ($pattern) = @_;
my (@file_list);
open (TMP, "ls -AF $pattern |") or die "Can't open input pipe:
$!\n";
while (<TMP>) {
my ($temp) = $_;
# strip out files that are strange, i.e. directories,
executables, etc.
if ($temp =~ /\Z\//) {next;} # Couldn't get
alternation to work in pattern match
elsif ($temp =~ /\Z\*/) {next;} # i.e.
/\Z(\/|\*|\@|\=|\|)/
elsif ($temp =~ /\Z\|/) {next;}
elsif ($temp =~ /\Z\@/)
{next;}
elsif ($temp =~
/\Z\=/) {next;}
push @file_list, $temp;
}
close (TMP) or die "Can't close input pipe: $!\n";
return (@file_list);
}
__DATA__
------------------------------
Date: Mon, 7 Aug 2000 14:43:07 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Newbie error: arrays are not returned from subs correctly
Message-Id: <MPG.13f8cd4a5dc2694d98ac42@nntp.hpl.hp.com>
[Newbie error #1: putting 'Newbie' in the Subject line, which will
cause some newsreaders to filter out the article.]
In article <1u5uoso3urrvejpqsma08laj5budkgaa8q@4ax.com> on Mon, 07 Aug
2000 16:11:18 -0400, Michael Grinnell <grinnell@american.edu> says...
> The problem I have is as follows:
>
> In some subs, not all, when I return an array, it doesn't get copied
> back into main correctly. The subs work properly, Tracing it, the
> program works up until the point where it tries to return the array.
> I'm baffled. Any help would be greatly appreciated.
> I'm using Redhat 6.2, Perl 5.005_03
> TIA,
> Michael Grinnell
>
>
>
> ###########################
> #!/usr/bin/perl
Newbie errors #2 and #3:
Posting code without the '-w' flag and the 'use strict;' pragma.
Newbie error #4:
Posting a complete program (about 350 lines!). Who can relate your text
description above to the actual code?
Isolate the problem down to at most a screenful of code, including a
test case that shows the problem, and then someone will take a look.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 07 Aug 2000 14:07:52 -0600
From: Chris Hough <chris@dslbroadband.com>
Subject: newbie question concerning a mail string...
Message-Id: <398F1717.63C7E7BC@dslbroadband.com>
I'm going throught the "Learning Peal" book and am having a problem with
a part of the script...
on one of my lines i've got:
open (MAIL, "| MAIL chris@dslbroadband.com");
but it keeps responding with an error requesting a / in front of the
@dslbroadband part...
i've tried it several ways but it keeps giving me an error, saying it
can't compile correctly.
any help?
-chris
------------------------------
Date: 07 Aug 2000 15:20:40 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: newbie question concerning a mail string...
Message-Id: <87vgxcesbr.fsf@limey.hpcc.uh.edu>
>> On Mon, 07 Aug 2000 14:07:52 -0600,
>> Chris Hough <chris@dslbroadband.com> said:
> I'm going throught the "Learning Peal" book and am
That rings a bell. You mean "perl" don't you?
> having a problem with a part of the script...
> on one of my lines i've got:
> open (MAIL, "| MAIL chris@dslbroadband.com");
> but it keeps responding with an error requesting a / in
> front of the @dslbroadband part...
No, it doesn't :-) It's complaining about a \ in front of
the @. @ introduces an array so perl is getting confused
as to what you mean. Write it as name\@....
Do you really mean "MAIL chris..." ? You're referring to
an external mail sending program here, not the handle
inside the perl program.
Note that "perldoc perldiag" explains the \@ thing.
In string, @%s now must be written as \@%s
hth
t
--
"With $10,000, we'd be millionaires!"
Homer Simpson
------------------------------
Date: Mon, 07 Aug 2000 16:09:23 -0400
From: steveFarris <nlymbo@mindspring.com>
Subject: parsing PDF
Message-Id: <398F1773.C2B67889@mindspring.com>
Does anyone know of one...i checked CPAN but all i saw was early
developement modules??
thanks!!
steve farris
--
original guitar music at
http://www.mindspring.com/~nlymbo
------------------------------
Date: Mon, 07 Aug 2000 21:07:21 GMT
From: sankarmukh@my-deja.com
Subject: Perl and Ftp question
Message-Id: <8mn8e3$m3u$1@nnrp1.deja.com>
The following script just have a blinking cursor. I don't know what's
wrong?
********************************************************
#!/usr/local/bin/perl -I /u/ctssmuk/myperllib/lib/site_perl/5.005/Net
use blib;
use Net::FTP;
use Getopt::Long;
##################################################
#Name:ftp_test.pl
###################################################
$ftp= Net::FTP-> new ("hsdfs01") ;
$ftp->login ("prod");
$ftp->pwd;
$ftp->quit;
****************************************************
I am using:
inawk170:/u/ctssmuk> which perl
/usr/local/bin/perl
inawk170:/u/ctssmuk> perl -v
This is perl, version 5.005_03 built for sun4-solaris
Also, I downloaded libnet-1.0703 and that is in myperlib directory.
Any help is appreciated.
Regards,
Sankar
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 7 Aug 2000 11:12:05 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Perl Newbie Question
Message-Id: <MPG.13f89bcf2c0296e298ac3c@nntp.hpl.hp.com>
[Choose a better Subject next time. Your question will have been
filtered out by many newsreaders.]
In article <na3j5.1750$KO2.37087@typhoon.austin.rr.com> on Sun, 06 Aug
2000 01:27:47 GMT, Ken <research@ev1.net> says...
> I have a delimited file with data pertaining to each column. I am needing
> to add dates into every 4th column. I'm not grasping the concept of reg
> exp, but the columns are delimited by |. The layout of the file is as such.
>
> data0|data1|data2|data3|data4|data5|data6|data7|...data29
>
> The first date will need to be placed between data1 and data2, the next date
> is then placed between data5 and data6.
Someone has posted a suggestion based on split, splice, and join. Here
is a potentially faster, regex-based approach. If you want to advance
beyond Perl Newbie, you must 'grasp the concept'. Read a web tutorial
first, then `perldoc perlre`.
#!/usr/bin/perl -wl
use strict;
my @dates = qw( D0 D1 D2 D3 D4 );
$_ = 'd0|d1|d2|d3|d4|d5|d6|d7|d8|d9|d10|d11';
my $i;
s/([^|]+\|[^|]+\|)([^|]+\|[^|]+)/$1$dates[$i++]|$2/g;
print;
Isn't that regex an imposing sequence of line noise? More legibly:
s/
( # Capture what follows in $1.
[^|]+ \| [^|]+\ | # Non-| chars followed by |, twice.
) # End of capture in $1.
( # Capture what follows in $2.
[^|]+ \| [^|]+ # Non-| chars separated by |.
) # End of capture in $2.
/$1$dates[$i++]|$2/gx;
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 07 Aug 2000 19:41:20 GMT
From: levo99@my-deja.com
Subject: Perl to excel
Message-Id: <8mn3cu$hp1$1@nnrp1.deja.com>
I'm trying to display my Perl output in Excel. Anyone know how to do it?
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 07 Aug 2000 13:14:51 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Perl to excel
Message-Id: <398F18BB.4A149C2F@vpservices.com>
levo99@my-deja.com wrote:
>
> I'm trying to display my Perl output in Excel. Anyone know how to do it?
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
Write the output as a CSV (comma separated values, "comma delimited")
file which Excel can read automatically. Or use Spreadsheet::WriteExcel
on CPAN.
--
Jeff
------------------------------
Date: Mon, 07 Aug 2000 20:59:09 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: Perl to excel
Message-Id: <8mn7up$ll1$1@nnrp1.deja.com>
In article <398F18BB.4A149C2F@vpservices.com>,
Jeff Zucker <jeff@vpservices.com> wrote:
> levo99@my-deja.com wrote:
> >
> > I'm trying to display my Perl output in Excel. Anyone know how to do
it?
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
>
> Write the output as a CSV (comma separated values, "comma delimited")
> file which Excel can read automatically. Or use
Spreadsheet::WriteExcel
> on CPAN.
Check out this:
http://www.roth.net/books/extensions/examples.zip
Look at example 5-24.
>
> --
> Jeff
>
amonotod
--
`\|||/ amonotod@
(@@) netscape.net
ooO_(_)_Ooo________________________________
_____|_____|_____|_____|_____|_____|_____|_____|
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 08 Aug 2000 02:23:58 +0800
From: Mark <mark325@hotmail.com>
Subject: Re: Please help me!
Message-Id: <398EFEBE.6962034C@hotmail.com>
> I solved my program problem, thanks for all your helps!
Mark ^_^
------------------------------
Date: Mon, 07 Aug 2000 19:35:04 GMT
From: newsgroups@ckeith.clara.net (Colin Keith)
Subject: Re: Please help me!
Message-Id: <IbEj5.96$DT4.2859189@nnrp2.clara.net>
In article <398ECD46.30A7A4F4@hotmail.com>, Mark <mark325@hotmail.com> wrote:
[ c.l.p.modules removed from newsgroups since its nowt to do with modules ]
>$var1 = 0;
>$i=1;
>
>$test = "\$var" . "$i";
>if i use:
>print "$test";
>the output should be: $var1
No no, you say "The output is:". You say that because you have already tried
this. Haven't you? (Yes, it is this, but please make it sound like you have
tried this already)
maia% perl -w -Mstrict;
my($var1) = 0;
my($i) = 1;
my($test) = "\$var" . "$i";
print "var1 = $var1\ni = $i\ntest = $test\n";
var1 = 0
i = 1
test = $var1
>(it means that the $test should contain the value of $var1)
>does anyone know how to implement it?
Uh huh. You're playing with symbolic references (yes, I sneaked a look at
the man page because I was getting no answer)
maia% perl
local($var1) = 0;
my($i) = 1;
my($test) = "var$i";
print "var = $$test\n";
var = 0
Now you may wonder why I suddenly changed from using my($var1) to
local($var1). Simply because I wasn't getting any output, and it dawned on
me after skim reading the docs that its because this works on package
variables, and of course my() variables are lexical - I.e. $main::test
doesn't exist. You don't see this if you just ploink down $test = 'x';
because it automatically makes it a package variable.
You'll also notice that I've turned off warnings and stopped using strict.
Both bad, but otherwise it generates errors. You cannot do this with strict
checking in force. So you are better off doing this within a block and
turning off strict checking for that block if you have to do this.
Note also that I dropped the $ from the value of $test. That's because if
you don't you're trying to access a variable called "$var1" rather than a
variable called "var1" that is a scalar ($), and that was too much hassle.
man perlref / Symbolic references
Col.
---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC
------------------------------
Date: Mon, 07 Aug 2000 18:02:40 GMT
From: bayers@my-deja.com
Subject: Problem With AT Command, DBI ODBC on NT4
Message-Id: <8mmtjr$d51$1@nnrp1.deja.com>
Here's a curious problem. Logged on as administrator, I can run the
program below from the command prompt, but when I try to run it with
the AT command, it fails with no error messages. For testing, I am
running the scedule service as administrator.
I've read all the FAQ's and am stuck.
====================
use DBI;
$TERM_CODE='004';
open(STDOUT,">>c:\\scripts\\sis.log") or die "Can't append to my log
$!";
open(STDERR,">>c:\\scripts\\sis.log") or die "Can't append to my log
$!";
$db2 = DBI->connect('dbi:ODBC:MSSQL', 'user', 'password', { RaiseError
=> 1});
$db2->do("DROP TABLE SIS");
$db2->do(qq{CREATE TABLE "dbo"."SIS" (
"STUDENT_ID" varchar (9) NOT NULL ,
"NAME" varchar (32) NULL ,
"RESIDENCY" varchar (2) NULL ,
"INFO_RELEASE_FLAG" varchar (2) NULL ,
"TERM_CODE" varchar (3) NULL ,
"GENDER" varchar (1) NULL ,
"FOREIGN_STUDENT_CODE" varchar (1) NULL ,
"DORM" varchar (5) NULL ,
"BIRTH_DT" varchar (8) NULL ,
"CITIZENSHIP" varchar (2) NULL ,
"ETHNIC_ORIGIN" varchar (1) NULL ,
"COLLEGE" varchar (2) NULL ,
"PRIMARY_MAJ1" varchar (4) NULL ,
"PRIMARY_MAJ2" varchar (4) NULL ,
"PRIMARY_MNR1" varchar (4) NULL ,
"CLASS_CODE" varchar (3) NULL ,
"CUMGPA" "float" NOT NULL DEFAULT 0,
CONSTRAINT "PrimaryKey" PRIMARY KEY NONCLUSTERED
(
"STUDENT_ID"
)
)
});
$db2->do("GRANT SELECT, INSERT, UPDATE, DELETE ON SIS to webuser,
staff");
$db1 = DBI->connect('dbi:ODBC:UIS', 'user', 'password', { RaiseError =>
1});
$st1 = $db1->prepare("SELECT ZSIS_AA1.STUDENT_ID, ZSIS_AA1.NAME,
ZSIS_AA1.RESIDENCY, ZSIS_AA1.INFO_RELEASE_FLAG, ZSIS_RT1.TERM_CODE,
ZSIS_AA1.GENDER, ZSIS_AA1.FOREIGN_STUDENT_CODE, ZSIS_AA1.DORM,
ZSIS_AA1.BIRTH_DT, ZSIS_AA1.CITIZENSHIP, ZSIS_AA1.ETHNIC_ORIGIN,
ZSIS_RT1.COLLEGE,ZSIS_RT1.PRIMARY_MAJ1, ZSIS_RT1.PRIMARY_MAJ2,
ZSIS_RT1.PRIMARY_MNR1, ZSIS_RT1.CLASS_CODE, ZSIS_RP3.GPA FROM
ZSIS_AA1,ZSIS_RT1,ZSIS_RP1,ZSIS_RP3 WHERE ZSIS_AA1.STUDENT_ID =
ZSIS_RT1.STUDENT_ID AND ZSIS_AA1.STUDENT_ID = ZSIS_RP1.STUDENT_ID AND
ZSIS_AA1.STUDENT_ID = ZSIS_RP3.STUDENT_ID AND ZSIS_RT1.CAREER =
ZSIS_RP3.CAREER AND ZSIS_RT1.TERM_CODE ='$TERM_CODE' AND
ZSIS_AA1.HONORS_ACTIVE='Y' AND ZSIS_RT1.CAREER='U'");
$st1->execute();
my
($f01,$f02,$f03,$f04,$f05,$f06,$f07,$f08,$f09,$f10,$f11,$f12,$f13,$f14,$
f15,$f16,$f17);
$rv = $st1->bind_columns
(\($f01,$f02,$f03,$f04,$f05,$f06,$f07,$f08,$f09,$f10,$f11,$f12,$f13,$f14
,$f15,$f16,$f17));
my $st2 = $db2->prepare(qq!INSERT INTO SIS (
STUDENT_ID, NAME, RESIDENCY, INFO_RELEASE_FLAG, TERM_CODE, GENDER,
FOREIGN_STUDENT_CODE, DORM, BIRTH_DT, CITIZENSHIP, ETHNIC_ORIGIN,
COLLEGE, PRIMARY_MAJ1, PRIMARY_MAJ2, PRIMARY_MNR1, CLASS_CODE, CUMGPA
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,convert(float,?))!);
while($st1->fetch()) {
print "$f01\n";
$st2->execute
($f01,$f02,$f03,$f04,$f05,$f06,$f07,$f08,$f09,$f10,$f11,$f12,$f13,$f14,$
f15,$f16,$f17);
}
$db1->disconnect;
$db2->disconnect;
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 3940
**************************************