[25693] in Perl-Users-Digest
Perl-Users Digest, Issue: 7934 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 2 00:05:51 2005
Date: Fri, 1 Apr 2005 21:05:08 -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 Fri, 1 Apr 2005 Volume: 10 Number: 7934
Today's topics:
Re: $line = <FH> returns incomplete lines <nobull@mail.com>
Re: $line = <FH> returns incomplete lines <nobull@mail.com>
Re: $line = <FH> returns incomplete lines axel@white-eagle.invalid.uk
Re: $line = <FH> returns incomplete lines <nobull@mail.com>
Re: accessing arrays in a different sub-routine <ewitkop90@hotmail.com>
Re: accessing arrays in a different sub-routine <1usa@llenroc.ude.invalid>
Re: Database -> Excel <see.sig@rochester.rr.com>
Re: launching a Perl script .... <wdflannery@aol.com>
Re: perl hangs after receiving signal <jeremy.slade@intel.com>
Re: perl script at godaddy <noreply@gunnar.cc>
Re: Perl script hangs (Anno Siegel)
script to update Perl's HTML doc tree from pod files <dave@nospam.com>
Re: Unable to connect to remote host <nobull@mail.com>
Re: Using a for() statement to create a variable?? <someone@example.com>
Re: using Perl to insert footer into PDF files? <segraves_f13@mindspring.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 01 Apr 2005 19:14:44 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: $line = <FH> returns incomplete lines
Message-Id: <d2k687$k4l$1@sun3.bham.ac.uk>
robic0@yahoo.com wrote:
> -rfc
OK
> if ($line =~ /[\n]+/) {
That condition is more simply written
if ($line =~ /\n/) {
------------------------------
Date: Fri, 01 Apr 2005 19:19:35 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: $line = <FH> returns incomplete lines
Message-Id: <d2k6h9$k4l$2@sun3.bham.ac.uk>
robic0@yahoo.com wrote:
> $line = '';
> while(1) {
> while ( ($line .= <MYLOG> ) )
> {
> if ($line =~ /[\n]+/) {
> print ("GOT THIS: ",$line);
> $line = '';
> }
> }
> seek (MYLOG,0, 1);
> sleep (1);
> }
That code will hang busy if a partial line is read.
It is worse than the OP's solution.
------------------------------
Date: Fri, 01 Apr 2005 17:33:00 -0600
From: axel@white-eagle.invalid.uk
Subject: Re: $line = <FH> returns incomplete lines
Message-Id: <84KdnQzt8tuxR9DfRVn-oA@adelphia.com>
Brian McCauley <nobull@mail.com> wrote:
> robic0@yahoo.com wrote:
>> $line = '';
>> while(1) {
>> while ( ($line .= <MYLOG> ) )
>> {
>> if ($line =~ /[\n]+/) {
>> print ("GOT THIS: ",$line);
>> $line = '';
>> }
>> }
>> seek (MYLOG,0, 1);
>> sleep (1);
>> }
> That code will hang busy if a partial line is read.
The following seems to work.
#!/usr/bin/perl
open (MYLOG, "/tmp/mylog") or die "Cannot open file: $!";
$|++;
print "GOT THIS: ";
while ( 1 ) {
while (<MYLOG>) {
print;
print ("GOT THIS: ") if /\n/;
}
sleep (1);
}
__END__
Axel
------------------------------
Date: Sat, 02 Apr 2005 04:02:45 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: $line = <FH> returns incomplete lines
Message-Id: <d2l568$4kg$1@sun3.bham.ac.uk>
axel@white-eagle.invalid.uk wrote:
> The following seems to work.
>
> #!/usr/bin/perl
>
> open (MYLOG, "/tmp/mylog") or die "Cannot open file: $!";
> $|++;
>
> print "GOT THIS: ";
> while ( 1 ) {
> while (<MYLOG>) {
> print;
> print ("GOT THIS: ") if /\n/;
> }
> sleep (1);
> }
> __END__
That is missing the seek() that is needed to reset the EOF flag on MYLOG.
If you insert the seek() it will work, sort of, but only because you are
simply printing the output. If you wanted to do someting else - like
selectively print lines by pattern match (as per OP) then it wouldn't work.
------------------------------
Date: 1 Apr 2005 17:08:44 -0800
From: "erik" <ewitkop90@hotmail.com>
Subject: Re: accessing arrays in a different sub-routine
Message-Id: <1112404124.313308.95980@g14g2000cwa.googlegroups.com>
No I haven't read the guidelines. I just looked and did not see them.
Would you mind posting the link and I will be glad to play nice in the
sandbox.
------------------------------
Date: Sat, 02 Apr 2005 01:29:07 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: accessing arrays in a different sub-routine
Message-Id: <Xns962BD0623A699asu1cornelledu@127.0.0.1>
"erik" <ewitkop90@hotmail.com> wrote in news:1112404124.313308.95980
@g14g2000cwa.googlegroups.com:
> No I haven't read the guidelines. I just looked and did not see them.
They are posted here regularly. In fact, a fresh copy was posted today.
> Would you mind posting the link and I will be glad to play nice in the
> sandbox.
Would you mind typing
comp.lang.perl.misc posting guidelines
in that Google search box?
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Sat, 02 Apr 2005 03:11:44 GMT
From: Bob Walton <see.sig@rochester.rr.com>
Subject: Re: Database -> Excel
Message-Id: <Q3o3e.522$uw2.354@twister.nyroc.rr.com>
Robert wrote:
> I see a whole passle of Excel modules on CPAN. I am querying an Oracle
> database and I want to save that query into an Excel file. What module
> would you suggest that I use?
>
> Robert
Well, Excel can be accessed as a database. Since you're already
doing database stuff (with DBI, I hope), you could access a named
region in Excel as a table. Steps:
1. make an Excel spreadsheet with a named region containing your
data, starting with a row of column headings.
2. set up a system or user DSN (start..settings..control
panel..administrative tools..data sources (odbc)
Run code something like:
use warnings;
use strict;
use DBI;
my $db=DBI->connect('dbi:ODBC:junk');
die "couldn't open" unless $db;
my $sth=$db->prepare('select * from junk');
die "couldn't prepare" unless $sth;
my $rv=$sth->execute;
die "couldn't execute" unless $rv;
my $arr_ref=$sth->fetchall_arrayref;
use Data::Dumper;
print Dumper($arr_ref);
$db->disconnect;
Here's the Excel region named 'junk' (highlight, then
insert..name..define, enter 'junk':
blah foo bar baz barf gorp
1 3 5 7 9 11
2 5 8 11 14 17
3 4 5 6 7 8
4 7 10 13 16 19
5 6 7 8 9 10
6 9 12 15 18 21
7 8 9 10 11 12
8 3 -2 -7 -12 -17
9 6 3 0 -3 -6
10 8 6 4 2 0
and here's the output:
D:\junk>perl junk525.pl
$VAR1 = [
[
'1.0',
'3.0',
'5.0',
'7.0',
'9.0',
'11.0'
],
[
'2.0',
'5.0',
'8.0',
'11.0',
'14.0',
'17.0'
],
[
'3.0',
'4.0',
'5.0',
'6.0',
'7.0',
'8.0'
],
[
'4.0',
'7.0',
'10.0',
'13.0',
'16.0',
'19.0'
],
[
'5.0',
'6.0',
'7.0',
'8.0',
'9.0',
'10.0'
],
[
'6.0',
'9.0',
'12.0',
'15.0',
'18.0',
'21.0'
],
[
'7.0',
'8.0',
'9.0',
'10.0',
'11.0',
'12.0'
],
[
'8.0',
'3.0',
'-2.0',
'-7.0',
'-12.0',
'-17.0'
],
[
'9.0',
'6.0',
'3.0',
'0.0',
'-3.0',
'-6.0'
],
[
'10.0',
'8.0',
'6.0',
'4.0',
'2.0',
'0.0'
]
];
D:\junk>
You can, of course, use the SQL 'insert into' etc.
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: 1 Apr 2005 18:58:09 -0800
From: "joesplink" <wdflannery@aol.com>
Subject: Re: launching a Perl script ....
Message-Id: <1112410689.952561.29840@g14g2000cwa.googlegroups.com>
Thanks, I tried it using LWP::Simple ... didn't work (for reasons
unknown ... and now I've got an alternate design that doesn't depend on
it), but it's good to know its there.
------------------------------
Date: Fri, 01 Apr 2005 13:24:28 -0700
From: Jeremy Slade <jeremy.slade@intel.com>
Subject: Re: perl hangs after receiving signal
Message-Id: <d2kals$86s$1@news01.intel.com>
Ah, thanks for the info. Yet one more reason I need to move to 5.8.
Anno Siegel wrote:
> Jeremy Slade <jeremy.slade@intel.com> wrote in comp.lang.perl.misc:
>
>>I have a script running in perl 5.6.1 on a debian sarge system (kernel
>
> ^^^^^
>
>>2.6.8).
>
>
> Perl signal handling was unsafe before 5.8.0. In particular, if a program
> was interrupted during a memory allocation, and the signal handler started
> off another memory allocation (can easily happen in inconspicuous code),
> that usually meant a segfault.
------------------------------
Date: Fri, 01 Apr 2005 23:17:05 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: perl script at godaddy
Message-Id: <3b5s52F6aad3bU1@individual.net>
cgidatabase@yahoo.com wrote:
> Gunnar Hjalmarsson wrote:
>> It does sound plausible that the outdated cgi-lib.pl isn't available in
>> @INC. You *could* solve that by installing cgi-lib.pl in the same
>> directory as your script, but a better solution is to replace the line
>> with what's suggested in the "COMPATIBILITY WITH CGI-LIB.PL" section in
>> the POD for CGI.pm.
>
> yes the cgi-lib.pl is in my cgi directory.
Okay. How about start using CGI.pm instead by changing two lines in your
script? (See above.)
> there is also a gdform.cgi file that came with the cgi directory.
> it has a parse_form_data routine but the require doesn't work for that
> either. the chmod on gdform.cgi was set at 711.
> on my other server all scripts are set at 744.
The most commonly used permission settings for CGI scripts is 755.
For some general advice on CGI scripts, you may find this URL useful:
http://my.execpc.com/~keithp/bdlogcgi.htm
> i have other routines saved in cgi-lib.pl that i would like to use.
> does anyone have the particulars for a cgi bin at godaddy?
> like what is the chmods. not to mention sendmail.
This is not the place for such questions. Consult the docs or ask the
support.
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 1 Apr 2005 19:14:44 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl script hangs
Message-Id: <d2k6j4$5hr$2@mamenchi.zrz.TU-Berlin.DE>
Brian McCauley <nobull@mail.com> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
>
> > Brian McCauley <nobull@mail.com> wrote in comp.lang.perl.misc:
> >
> >>
> >>So long as some_condition() will eventually become true for any value of
> >>$counter there is no infinite loop.
> >
> > But $counter won't change anymore once some_statement() evaluates to
> > false, so it's stuck.
>
> It's amazing how you can tell just form the name that the result of
> some_statement() will not change if $counter does not change.
>
> Me, I'd need to look at the definition of some_statement().
Sure, it could depend on the phase of the moon. I was going on the
assumption that the pseudo-code showed all relevant actions. Otherwise,
why show one incrementation of the loop index and not indicate others?
Anno
------------------------------
Date: Fri, 01 Apr 2005 21:25:26 -0500
From: Dave <dave@nospam.com>
Subject: script to update Perl's HTML doc tree from pod files
Message-Id: <-o6dndRA4e44n9PfRVn-vQ@rcn.net>
Would someone be so kind as to post a URL link or the contents of a
simple script that is written to accomplish the purpose included in the
'subject' header? I realize that it's a fairly trivial task, but I'd
rather avoid writing such a script from scratch if unnecessary. The
only scripts of this kind that I was able to locate on the Internet were
specifically written for ActiveState's Perl distribution, but I just
compile Perl from the normal (stable) distribution on NT5.x (i.e., w2k,
xp). If you know of such a script, or have written one yourself that
you wouldn't mind sharing, I would very much appreciate it.
Dave
------------------------------
Date: Fri, 01 Apr 2005 19:02:07 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Unable to connect to remote host
Message-Id: <d2k5gj$jr5$1@sun3.bham.ac.uk>
sri wrote:
> Thanks for the response Brian.
Please quote some context when replying as I did.
> The error is araising at this line
>
> my $t = Net::Telnet->new(%options);
No it is not, that's just where Net::Telnet has chosen to report it.
perldoc Carp
> You want me to add :
>
> $^E my $t = Net::Telnet->new(%options); $!
No, I want you do do what I said.
Find the line in Net::Telnet that is carp()ing with the message you are
seeing. You'll probably find it's already including $!, you should
insert $^E alongside.
> What does these charcters do... ?
They are two of Perl's special variables, the ones that report the most
recent low-level OS error. For details:
perldoc perlvar
------------------------------
Date: Fri, 01 Apr 2005 20:38:14 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Using a for() statement to create a variable??
Message-Id: <Wii3e.155373$fc4.98215@edtnps89>
Brian McCauley wrote:
>
> A. Sinan Unur wrote:
>
> [ of "robic0@yahoo.com" ]
>
>> Your ignorance is amusing.
>
> No, I think it has long ceased to be. robic0 is now rapidly[1]
> decomming the heir apparent to the thrown of she whose name we shall not
> utter.
>
> We are all Frank.
>
> [1] Fredian slip - I initially typed "rabidly".
And yet you didn't correct "decomming"?
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 02 Apr 2005 00:39:44 GMT
From: "Bill Segraves" <segraves_f13@mindspring.com>
Subject: Re: using Perl to insert footer into PDF files?
Message-Id: <kRl3e.2075$44.297@newsread1.news.atl.earthlink.net>
<codingalex@yahoo.com> wrote in message
news:1112136082.166127.110350@z14g2000cwz.googlegroups.com...
> I'm a little new at PDF manipulation in Perl and I'm not completely
> convinced that what I want to do is even possible. Basically what i
> want to do is take a multi-page PDF file and insert a footer onto the
> bottom of every page along with sequential page numbers.
<snip>
> Can someone point me in
> the right direction on this?
>
There's no one "right" direction to do this. Here is one way that may work
for you.
Pdftk, available free from www.accesspdf.com, can be used to do what you're
seeking. Pdftk is a command line program which can easily be run in a Perl
environment, e.g., on this Win32 system, the following is known to work
satisfactorily (both examples tested):
#!perl
use strict;
use warnings;
use CGI qw(param);
my $in1pdf = param('in1pdf');
my $bkgndpdf = param('bkgndpdf');
my $outpdf = param('outpdf');
my $inpdf = param('inpdf');
my $infdf = param('infdf');
#Example 2 - add a background to a PDF
#system('pdftk.exe', $in1pdf, 'background', $bkgndpdf, 'output', $outpdf);
#Example 4 - fill a PDF with the data in an FDF file
#system('pdftk.exe', $inpdf, 'fill_form', $infdf, 'output', $outpdf);
#Uncomment the one of the examples you wish to try. Note: Path to perl
deleted from the two examples below.
# usage (Example 2) - perl pdftk.pl in1pdf=sample.pdf bkgndpdf=hdr_ftr.pdf
outpdf=sam_hdrftr.pdf
# usage (Example 4) - perl pdftk_v2a.pl inpdf=sam_hdrftr.pdf
infdf=sample_was_data.fdf outpdf=sam_hdrftr_filled.pdf
Using the above examples to show you the way, you should be able to write a
Perl script that will do what you're seeking, as follows:
1. Create a PDF that has a form field for the desired footer, using Acrobat
(not free) or Scribus (free), or some other program capable of generating a
PDF with a fillable form field. This PDF will be used to generate multiple
instances of background PDFs containing the page numbers.
2. Write a script to generate an FDF file containing the data (page number)
you wish to show in the footer.
3. Using Pdftk (see Example 4), merge the FDF with the background PDF from 1
above.
4. Using Pdftk (see Example 2), add the background PDF to the PDF that needs
the background.
5. Repeat the above steps for all of the pages of the PDF that need footers
with sequential page numbers.
6. Wrap all of the above up in a Perl script to automate the process.
Enjoy!
--
Bill Segraves
------------------------------
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 7934
***************************************