[18664] in Perl-Users-Digest
Perl-Users Digest, Issue: 832 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 4 06:05:56 2001
Date: Fri, 4 May 2001 03:05:09 -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: <988970709-v10-i832@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 4 May 2001 Volume: 10 Number: 832
Today's topics:
Allocating people like in a cinema <Tim.Lauterborn@gmx.de>
Re: Alorithm ? addendum <dkoleary@mediaone.net>
Re: Alorithm ? addendum <skilchen@swissonline.ch>
Re: Alorithm ? addendum <bart.lateur@skynet.be>
Re: cookie expiry (Rafael Garcia-Suarez)
DNS Lookups <mmyers1@home.com>
Re: DNS Lookups <gtoomey@usa.net>
Re: Does 'exec' never fail? (Villy Kruse)
Re: Downloading images with HTTP/LWP libraries <bwalton@rochester.rr.com>
Re: Downloading images with HTTP/LWP libraries <godzilla@stomp.stomp.tokyo>
Re: Downloading images with HTTP/LWP libraries <rhughes@fas.harvard.edu>
Re: Downloading images with HTTP/LWP libraries (Rafael Garcia-Suarez)
evil eval in BEGIN <daniel.heiserer@bmw.de>
Re: evil eval in BEGIN <horst_fickenscher@sepp.de>
Re: evil eval in BEGIN (Rudolf Polzer)
Re: evil eval in BEGIN nobull@mail.com
Re: fork (Rafael Garcia-Suarez)
general Perl question <yuriyt@ix.netcom.com>
Re: general Perl question <tward10@jaguar.com>
Re: help with parsing files (Rafael Garcia-Suarez)
Re: hexadecimal convert to binary <bwalton@rochester.rr.com>
Re: How do I find the OS? <pne-news-20010504@newton.digitalspace.net>
Re: Multi dimensional array dimensions <jpnolan@bolt.sonic.net>
One-liner matching woes... <admin@salvador.venice.ca.us>
Re: One-liner matching woes... (Rafael Garcia-Suarez)
Re: One-liner matching woes... <peb@bms.umist.ac.uk>
Re: Own module: how to export constants/subroutines of (EED)
Re: Parsing (Barry Allwood)
Re: PERL Code Generator <tom.beer@btfinancialgroup.spamfilter.com>
Re: PERL Code Generator <hermann@vonabiszet.de>
Re: prevent empty message being sent? <pne-news-20010504@newton.digitalspace.net>
RE: Problems loading a hive file saved with Win32::TieR <perl@programacionweb.com>
Re: Test for integer? (Rudolf Polzer)
untaint help <castaway-helpme@home.com>
using Apache::SSI offline <alun.moon@unn.ac.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 4 May 2001 11:46:58 +0200
From: "Tim Lauterborn" <Tim.Lauterborn@gmx.de>
Subject: Allocating people like in a cinema
Message-Id: <9cttvf$pnd$1@nets3.rz.RWTH-Aachen.DE>
Hi,
I have a list of people in groups (1 to 3 people in one group). I want to
allocate these people to a set of chairs like in a cinema making sure that
groups are not broken in two 'subgroups' at the end of a row.
Does someone know a module or a freeware program which can handle this
problem?
Greetings,
Tim
------------------------------
Date: Thu, 3 May 2001 23:21:41 -0700
From: Doug O'Leary <dkoleary@mediaone.net>
Subject: Re: Alorithm ? addendum
Message-Id: <MPG.155bea4e523b94af989792@news.randori.com>
In article <3AF21B88.B19F8A7C@rochester.rr.com>, bwalton@rochester.rr.com
says...
Would the following from perldoc -f fork be of help in explaining what
happened?:
Actually, no... At least not as far as I can see. I actually tried to
take advantage of that in one iteration of the program with abysmal
results.
The file handle is only accessed once per loop - in the parent process.
The children simply print out the contents of $line and exit.
...
Unless, when the children exit, they close the file handle? But, if
that's the case, why does it read past the first child dying? There's a
quirk there, but I still don't understand it completely.
Thanks for the response.
Doug
--
-------------------
Douglas K. O'Leary
Senior System Administrator
dkoleary@mediaone.net
------------------------------
Date: Fri, 4 May 2001 07:19:54 +0200
From: "Samuel Kilchenmann" <skilchen@swissonline.ch>
Subject: Re: Alorithm ? addendum
Message-Id: <9cteic$f4kv9$1@ID-13368.news.dfncis.de>
"Doug O'Leary" <dkoleary@ro05-24-29-232-217.ce.mediaone.net> schrieb im
Newsbeitrag news:9ejI6.411$qPc.47775888@news.randori.com...
> 30: elsif (defined $pid) ### Child
> 31: {
> 32: # close (In);
> 33: printf ("%-16s %5s %5s %s\n",$node, $gw, $type, $comm);
> 34: exit 0; # Normal exit
> 35: }
>
> This works; I was originally reading each line within the loop
> as shown on line 19. Doing that, however, my output was
> completely mucked - lines munged together and other lines in the
> file were duplicated several times.
>
The problem with the output has nothing to do with how you read the input.
In the child processes you are concurrently writing to a shared output
channel. Thats the problem. As soon as you run your script with a
redirection of STDOUT to a file, you will have the same completely mucked
output in this file. You need to serialize concurrent writes, either by
flocking an open output filehandle in the child processes, or by using
autoflush or syswrite if you write to a handle opened in append mode.
> Once I read the file into an array (#12/13), then iterated through the
> array, it worked perfectly.
>
You were simply lucky. But that has nothing to do with the change in the
way you read the input.
------------------------------
Date: Fri, 04 May 2001 09:07:48 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Alorithm ? addendum
Message-Id: <4ds4ftcf6vo00fq2bkijb9kvufijdkug9g@4ax.com>
Doug O'Leary wrote:
>The file handle is only accessed once per loop - in the parent process.
>The children simply print out the contents of $line and exit.
Er... "print", does that not involve a filehandle?
--
Bart.
------------------------------
Date: 4 May 2001 07:59:31 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: cookie expiry
Message-Id: <slrn9f4ocr.n77.rgarciasuarez@rafael.kazibao.net>
Troy Boy wrote in comp.lang.perl.misc:
} Hi there,
} I have troubles resetting cookie expiry time in IE and some
} versions of Netscape on Linux.
}
} The code i use is as follows
}
} $the_cookie = cookie(-name=>'sid',
} -value=>$session_id,
} -expires=>'+2m',
} -domain=>'.vicnet.net.au',
} -path=>'/');
}
} print header(-cookie=>$the_cookie);
}
} Time passes..........The user hits on a log out button and the same code is
} called..but the expires variable gets reset to '1s' .My problem is...that it
} doesn't take this into account..and keeps the cookie active till the 2
} minutes have passed.
To remove a cookie, the usual method is to set a negative expiration
time. Does it help? If I understand correctly, your code works with some
browsers. This indicates a browser problem.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/perl/biscuit.html
------------------------------
Date: Fri, 04 May 2001 04:19:44 GMT
From: Mike Myers <mmyers1@home.com>
Subject: DNS Lookups
Message-Id: <3AF22E9D.3A55E1D6@home.com>
Hi,
I have been using the following to perform DNS queries on large files:
$name = gethostbyaddr(inet_aton("$nodes[$count]"), AF_INET) || "no DNS
found";
where @nodes is a list of IPs.
This works well for most queries, but not when the server fails to
respond. If the server fails, it takes approx 17s for gethostbyaddr to
timeout and move to the next entry.
Is there a method to implement a simple timeout feature to improve
efficiency without resorting to NET::DNS?
Thanks,
Mike.
------------------------------
Date: Fri, 4 May 2001 14:54:50 +1000
From: "Gregory Toomey" <gtoomey@usa.net>
Subject: Re: DNS Lookups
Message-Id: <UoqI6.17583$482.88997@newsfeeds.bigpond.com>
"Mike Myers" <mmyers1@home.com> wrote in message
news:3AF22E9D.3A55E1D6@home.com...
> Hi,
>
> I have been using the following to perform DNS queries on large files:
>
> $name = gethostbyaddr(inet_aton("$nodes[$count]"), AF_INET) || "no DNS
> found";
>
> where @nodes is a list of IPs.
>
> This works well for most queries, but not when the server fails to
> respond. If the server fails, it takes approx 17s for gethostbyaddr to
> timeout and move to the next entry.
>
> Is there a method to implement a simple timeout feature to improve
> efficiency without resorting to NET::DNS?
>
> Thanks,
> Mike.
You may want to consider forking processes to do a number of gethostbyaddr
this in parallel.
This may lead to different sorts of problems but is one way to speed things
up.
gtoomey
------------------------------
Date: 4 May 2001 07:37:54 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: Does 'exec' never fail?
Message-Id: <slrn9f4n2h.der.vek@pharmnl.ohout.pharmapartners.nl>
On 3 May 2001 21:15:33 -0500, Logan Shaw <logan@cs.utexas.edu> wrote:
>In article <9csv0k$ldi$1@slb1.atl.mindspring.net>,
>James Richardson <time4tea@monmouth.com> wrote:
>>However, PATH is a convenience for people typing at the keyboard, I can
>>think of no reason to ever rely on it from within a program.
>
>I can think of a great reason: you don't want your program to have to
>be changed to include the full path of the program when it can
>just find it through $PATH already.
>
>This is especially true if people share a home directory (or whatever
>directory the program is installed in) across machines. The desired
>executable may be in different places on different hosts.
>
>However, it is true that using the PATH means that you are relying on
>the user having things set up correctly to work with your program.
>And that's not always a safe assumption.
>
For secure programs (such as suid root programs) it is mandatory to
set the PATH from within the program if you ever rely on that. A
few other environment variable must be explicitely set from within
the program as well. suidperl insists on that.
perldoc perlsec for more information.
Villy
------------------------------
Date: Fri, 04 May 2001 04:37:41 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Downloading images with HTTP/LWP libraries
Message-Id: <3AF23254.628CEF8D@rochester.rr.com>
Robert Hughes wrote:
>
> I'm trying to figure out how to download an embedded image
> in a web page using the HTTP/LWP libraries. Right now,
> I'm resorting to submitting a request with the image's URL.
> This creates two problems:
> 1) The image I get when I save $request->content to a
> file is very distorted.
> 2) In response to a request like http://www.foo.com/bar.jpg
> some websites give an html page with bar.jpg embedded.
> In this case, all I get in $request->content is the HTML code.
<code deleted>
> Any suggestions on how to do this better?
...
> -Rob
Your image is probably distored because (I'm guessing here) you are
using a brain-dead OS that requires the use of binmode to correctly
write binary files, like image files. perldoc -f binmode.
Also, test your open's for success by adding or die "Oops, $!" to them.
You'll be glad you did. As far as that goes, test the results of
fetching the web page to see if the fetch worked before attempting to
use the returned results.
As for getting HTML back when fetching an image file, that sounds like a
mis-configured web server to me. Does the web page which references
these images work OK in your browser? If so, is the web page actually
pointing to those image files, or perhaps to other image files
somewhere? Maybe the web server is trying to be too smart by paying
attention to what kind of brower you say you are when giving the
request. If so, you could pretend to be whatever brower it is that
works with the web server (by using $ua->agent('whatever');). Who knows
what the server thinks you are if you don't say? Maybe it assumes
text-only?
--
Bob Walton
------------------------------
Date: Thu, 03 May 2001 22:52:28 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Downloading images with HTTP/LWP libraries
Message-Id: <3AF2439C.4BA73AB9@stomp.stomp.tokyo>
Robert Hughes wrote:
> I'm trying to figure out how to download an embedded image
> in a web page using the HTTP/LWP libraries. Right now,
> I'm resorting to submitting a request with the image's URL.
> This creates two problems:
> 1) The image I get when I save $request->content to a
> file is very distorted.
> 2) In response to a request like http://www.foo.com/bar.jpg
> some websites give an html page with bar.jpg embedded.
> In this case, all I get in $request->content is the HTML code.
> Here's the code I'm using now:
(snipped)
You are investing a lot of code effort for something
very simple. You have the needed URL addresses for
these images. Download them via a browser and save
them to your local system. This is quite logical.
Should you elect to do this in a less than logical
manner, binary mode your Standard Output. Cross
your fingers, this might help.
use LWP::Simple;
$image = get ("url/path/to/image.jpg");
binmode STDOUT;
open (FILEHANDLE, ">image.jpg");
print FILEHANDLE $image;
close (FILEHANDLE);
You should know Win32 systems will not correctly
store a binary image file using this method. You
may also encounter other operating systems which
exhibit problems storing binary images. Use of
binmode may or may not correct this problem.
On images embedded in an html page, you may have
to add a referral variable appropriate for a site.
Some sites do not allow offsite links to an image.
With little effort, you can extract image URLs
from an html page. There is really no need to
write such elaborate code for this task. You
will discover LWP Simple works well.
Best approach is to simply download these images
via a browser and save them to a local diskdrive.
Godzilla!
------------------------------
Date: Fri, 4 May 2001 02:32:50 -0400
From: "Robert Hughes" <rhughes@fas.harvard.edu>
Subject: Re: Downloading images with HTTP/LWP libraries
Message-Id: <9ctibb$9ba$1@news.fas.harvard.edu>
"Bob Walton" <bwalton@rochester.rr.com> wrote in message
news:3AF23254.628CEF8D@rochester.rr.com...
> Your image is probably distored because (I'm guessing here) you are
> using a brain-dead OS that requires the use of binmode to correctly
> write binary files, like image files. perldoc -f binmode.
This works. Thanks.
> As for getting HTML back when fetching an image file, that sounds like a
> mis-configured web server to me. Does the web page which references
> these images work OK in your browser? If so, is the web page actually
> pointing to those image files, or perhaps to other image files
> somewhere?
When I enter the image's URL in Internet Explorer, I get a web page with
a banner ad and a back button, along with the image. The relative
pathname of the embedded image (/dir2/bar.jpg) is the end of the URL
of the page (http://www.foo.com/dir1/dir2/bar.jpg).
> Maybe the web server is trying to be too smart by paying
> attention to what kind of brower you say you are when giving the
> request. If so, you could pretend to be whatever brower it is that
> works with the web server (by using $ua->agent('whatever');).
If I identify myself as 'Mozilla/5.0' I get different html (no banner ad)
than
if I identify myself as 'IE/5.0' or if I don't identify myself. (No banner
ad with Mozilla.) It's still html in any case.
Is it possible to retrieve an html file and the embedded images with a
single HTTP
request?
Thanks for your help.
-Rob
------------------------------
Date: 4 May 2001 07:02:48 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Downloading images with HTTP/LWP libraries
Message-Id: <slrn9f4l2k.mvk.rgarciasuarez@rafael.kazibao.net>
Bob Walton wrote in comp.lang.perl.misc:
}
} As for getting HTML back when fetching an image file, that sounds like a
} mis-configured web server to me. Does the web page which references
} these images work OK in your browser? If so, is the web page actually
} pointing to those image files, or perhaps to other image files
} somewhere? Maybe the web server is trying to be too smart by paying
} attention to what kind of brower you say you are when giving the
} request. If so, you could pretend to be whatever brower it is that
} works with the web server (by using $ua->agent('whatever');). Who knows
} what the server thinks you are if you don't say? Maybe it assumes
} text-only?
Another guess : the web server issues a redirect from the JPEG file to
an HTML file when some header is not present (probably User-Agent or
Referer). Try to use $ua->simple_request instead of $ua->request to
avoid being redirected and investigate the status code of the response :
is it 200 ? Try to add headers to the original request.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/perl/biscuit.html
------------------------------
Date: Fri, 04 May 2001 09:11:22 +0200
From: Daniel Heiserer <daniel.heiserer@bmw.de>
Subject: evil eval in BEGIN
Message-Id: <3AF2561A.91717E1E@bmw.de>
Hi,
I have to use an operation on $0 in the
BEGIN evironment and the only line I have is the push(@INC,,,) is there
a way?
1) my script is always called with the full pathname (leading "/")
2) my script is generated with a macro from a template file
3) I have to substitute the directory .../bin/... in $0 with /moduls
and push that to @INC.
There is almost no easy way around that.
When I use:
BEGIN {
push(@INC, ($path=$0)=~s,/bin/.*,/moduls,);
}
The INC contains 1 instead of "...../moduls".
When I use
BEGIN {
push(@INC, eval($0=~s,/bin/.*,/moduls,));
}
the result is also 1 instead of my new pathname.
Also desperate attempts like sub{$0=~s,/bin/.*,/moduls,;return $0}
didn't work out.
Any ideas?
Pleas remember the only way i can do something is
BEGIN {
push(@INC, HERE);
}
thanks daniel
--
Mit freundlichen Gruessen
Daniel Heiserer
--------------------------------------------------------------
Dipl.-Phys. Daniel Heiserer, BMW AG, Knorrstrasse 147, 80788 Muenchen
Abteilung EK-212
Tel.: 089-382-21187, Fax.: 089-382-42820
mailto:daniel.heiserer@bmw.de
Lageplan Standort FIZ:
http://www.stadtplandienst.de/query?ORT=M&STR=Knorrstr.&HNR=147
------------------------------
Date: Fri, 04 May 2001 10:05:48 +0200
From: Horst Fickenscher <horst_fickenscher@sepp.de>
Subject: Re: evil eval in BEGIN
Message-Id: <3AF262DC.64293CDA@sepp.de>
Daniel Heiserer wrote:
> When I use:
>
> BEGIN {
> push(@INC, ($path=$0)=~s,/bin/.*,/moduls,);
> }
>
> The INC contains 1 instead of "...../moduls".
Well, this is the value of the =~ s expression (1 substitution).
You better should substitute in $path, and then push $path
on @INC.
--
Horst
------------------------------
Date: Fri, 4 May 2001 13:37:20 +0200
From: eins@durchnull.de (Rudolf Polzer)
Subject: Re: evil eval in BEGIN
Message-Id: <slrn9f553g.8eq.eins@www42.t-offline.de>
Daniel Heiserer <daniel.heiserer@bmw.de> wrote:
> Hi,
>
> I have to use an operation on $0 in the
> BEGIN evironment and the only line I have is the push(@INC,,,) is there
> a way?
>
> 1) my script is always called with the full pathname (leading "/")
> 2) my script is generated with a macro from a template file
> 3) I have to substitute the directory .../bin/... in $0 with /moduls
> and push that to @INC.
> There is almost no easy way around that.
>
> When I use:
>
> BEGIN {
> push(@INC, ($path=$0)=~s,/bin/.*,/moduls,);
> }
>
> The INC contains 1 instead of "...../moduls".
> When I use
> BEGIN {
>
> push(@INC, eval($0=~s,/bin/.*,/moduls,));
> }
>
> the result is also 1 instead of my new pathname.
>
> Also desperate attempts like sub{$0=~s,/bin/.*,/moduls,;return $0}
> didn't work out.
Why not? What happens?
AFAIK this should do:
BEGIN {
my $a = $0;
$a =~ s,/bin/(.*)/,/moduls/$1,;
push @INC, $a;
}
You probably want to use unshift instead of push. And why are you trying
to change $0? This causes weird output on ps -ax.
--
#!/usr/bin/perl -w -- sequences
$0=++$|;for(;;){print-length$0;$0=~s/(.)\1*/$1.length$&/ge;}print"\n";
------------------------------
Date: 04 May 2001 08:44:49 +0100
From: nobull@mail.com
Subject: Re: evil eval in BEGIN
Message-Id: <u91yq5tq4f.fsf@wcl-l.bham.ac.uk>
Daniel Heiserer <daniel.heiserer@bmw.de> writes:
> Subject: evil eval in BEGIN
Your problem has nothing to do with eval() or BEGIN {}. "eval" was
part of your attempted solution, not part of the problem. The fact
that the code is inside a BEGIN{} block is not part of the problem.
Trying to accurately describe your problem is the first step in
soliving it.
> BEGIN {
> push(@INC, ($path=$0)=~s,/bin/.*,/moduls,);
> }
Please refer to "perldoc perlop" for the return value of s///
You meant:
BEGIN {
push(@INC, do { (my $path=$0)=~s,/bin/.*,/moduls,; $path });
}
If you think this is ugly, you are not the only one. See the recent
thread "Idiom: the expression of a copied & substituted string"
You may want to condsider 'use lib' for neatness.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 4 May 2001 06:48:41 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: fork
Message-Id: <slrn9f4k85.mvk.rgarciasuarez@rafael.kazibao.net>
Reiner Dassing wrote in comp.lang.perl.misc:
}
} A simple start would be:
}
} my $pid = fork();
} if ( $pid < 0 ) {
} print STDERR "No Fork possible!\n";
} exit;
} }
fork() returns undef on failure, not a negative integer. (Perl is not
C). And undef is not < 0. You should write :
defined $pid or die "Can't fork : $!\n";
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
package another; sub AUTOLOAD { $AUTOLOAD =~ /::(.*)/;"$1 @_"; }
package hacker; sub AUTOLOAD { $AUTOLOAD =~ /::(.*)/;"$1 @_,\n"; }
print Just another Perl hacker;
------------------------------
Date: Thu, 03 May 2001 21:56:21 -0700
From: Yuriy Tenenbaum <yuriyt@ix.netcom.com>
Subject: general Perl question
Message-Id: <3AF23675.D4C9113D@ix.netcom.com>
Hi. I am working on a Perl-CGI-HTML system where a lot of text files
are being modified through web user's input. I heard from many people
that developing such a system in Perl/CGI is not a good idea... that it
has to be done in JavaScript. If this is true, can anyone tell me the
exact reasons why? And what are the downfalls of that kind of system
developed through Perl/CGI?
thanks,
sergey
------------------------------
Date: Fri, 4 May 2001 07:48:19 +0100
From: "Trevor Ward" <tward10@jaguar.com>
Subject: Re: general Perl question
Message-Id: <9ctjbk$jkr1@eccws12.dearborn.ford.com>
Hum well seeing you cannot edit text files in JavaScript or update, read
delete them.
Don't think your info is quite correct.
Personally I think perl is a good tool for any web development however there
are others like PHP, ASP. even Java.
So use Perl its quick to develop and run and works on any platform. So where
is the pitfalls.
unless of course somebody knows different.
Hope this helps.
Yuriy Tenenbaum <yuriyt@ix.netcom.com> wrote in message
news:3AF23675.D4C9113D@ix.netcom.com...
> Hi. I am working on a Perl-CGI-HTML system where a lot of text files
> are being modified through web user's input. I heard from many people
> that developing such a system in Perl/CGI is not a good idea... that it
> has to be done in JavaScript. If this is true, can anyone tell me the
> exact reasons why? And what are the downfalls of that kind of system
> developed through Perl/CGI?
>
> thanks,
>
> sergey
>
------------------------------
Date: 4 May 2001 07:09:07 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: help with parsing files
Message-Id: <slrn9f4leg.mvk.rgarciasuarez@rafael.kazibao.net>
Patrick Joyce wrote in comp.lang.perl.misc:
} I want to create a perl program that will search through a bunch of html
} files
} outside of my root directory, find logo_small.gif and add the following
} after that line.
} <div align="right"><a href="http://207.244.72.79"><img
} src="../pix/checkout.gif" width="120" height="20" alt="Go to Checkout"
} border="0"></a></div>
} This is what i have so far but it still doesnt
} seem to be working.
[...code snipped...]
Test the return value of all your system calls (open, opendir, rename,
unlink). Include $! in the error message to be reported in case of
failure. This will help you to debug.
Use -w and use strict.
Don't use local() to declare local variables in your subroutines : use
my() instead. local() is for other things.
If your script still doesn't work after this cleanup, and if you still
can't figure out why, ask again.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Fri, 04 May 2001 04:39:31 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: hexadecimal convert to binary
Message-Id: <3AF232C2.2BB91989@rochester.rr.com>
Per- Fredrik Pollnow wrote:
...
> I need some help with a perl script I have triad to script. I'm using sun
> Solaris and snoop, what I want to do is to take out the data hexadecimal and
> convert it to binary format.
>
> I have a program that does binary to hexadecimal:
>
<code deleted>
> But I want it to do the same thing but hexadecimal to binary.
>
> The snoop dump looks like this:
>
> 0: 00d0 d335 b41c 0800 20a9 8a94 0800 4500 ...5.... .....E.
> 16: 0088 9764 4000 ff06 37b1 88e1 7067 88e1 ...d@...7...pg..
...
Check out the %b specifier for printf. perldoc -f sprintf.
--
Bob Walton
------------------------------
Date: Fri, 04 May 2001 09:30:38 +0200
From: Philip Newton <pne-news-20010504@newton.digitalspace.net>
Subject: Re: How do I find the OS?
Message-Id: <kim4ftovl4luj81f5bg4jpkegmdnqvi41b@4ax.com>
On Thu, 3 May 2001 14:39:21 EDT, Arek@nospam.tv (Arek P) wrote:
> perl -e 'print "I am runinng under $^O \n";'
More like "I was built under $^O", as perlvar will tell you. (Though I
have no first-hand experience with things such as Linux binaries being
run under emulation on Solaris, or something like that that.)
Note also that on Win32, $^O will not tell you whether you have WinNT
or 9x or Me or XP or ....
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Fri, 04 May 2001 05:40:24 GMT
From: John Nolan <jpnolan@bolt.sonic.net>
Subject: Re: Multi dimensional array dimensions
Message-Id: <chrI6.926$po.26152@typhoon.sonic.net>
Ilmari Karonen <iltzu@sci.invalid> wrote:
: The following code is intended to demonstrate that when we say scalar
: context propagates until a scalar is supplied, we really do mean it.
: sub foo { $_[0] .. $_[1] }
: print scalar foo(0, 5), "\t toggle off\n";
: print foo(0, 5), "\t print '012345'\n";
: print scalar foo(0, 0), "\t still turned off\n";
: print scalar foo(5, 0), "\t toggle on\n";
: print foo(0, 5), "\t print '012345'\n";
: print scalar foo(0, 0), "\t still turned on\n";
What part of the source code should I look at, in order
to learn what is really going on here?
If you repeat that last line over and over again,
it just prints out an incrementing stream of numbers.
I'm wondering where this is coming from.
Anyway, thanks for posting this. Very interesting.
--
#-------------------------
# John Nolan
# jpnolan sonic net
#-------------------------
------------------------------
Date: Fri, 4 May 2001 00:11:08 -0700
From: Salvador Peralta <admin@salvador.venice.ca.us>
Subject: One-liner matching woes...
Message-Id: <9ctjvs$phb$1@persian.noc.ucla.edu>
A few questions...
I was fooling around with perl one liners tonight, and I ran into a
few problems that i couldn't get my head around. First, I wanted to
have a one-liner read in a redmond FUD page from my GET http utility
and print out the number of times .NET was mentioned in the article
versus OSS, Open Source and GPL, so I wrote this script:
[salvador@localhost salvador]$ GET
http://www.microsoft.com/presspass/exec/craig/05-03sharedsource.asp |
perl -ne 'if ($_ =~ /\.NET/){$x++;} elsif ($_ =~ /GPL|OSS|Open
Source/i){$y++;}print "MS: $x\n OS: $y\n";
The count that this returns for the GPL|OSS|Open Source regex is not
valid.
MS: 3
OS: 9
GPL alone is mentioned 11 times in the article. I'm wondering what I
may have done to cause the error. My first thought was that if the
script encounters .NET on a line, it never gets to the second
condition so I changed elsif in the second part of that script to if
with no change in result. My second though is that I may be using
the $_ variable incorrectly.
Can anyone help me troubleshoot this or recommend a better way.
Second, I have looked through perlop and don't see how I can print a
result at the end of the one-liner if I use the -n option. Since I
am using the -n my current program gives me a line by line MS: OS:
result when what I really want is to count up the instances of each
and print the result. Again, can someone recommend a solution or
point me to a resource other than perlop?
Thanks
------------------------------
Date: 4 May 2001 08:16:09 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: One-liner matching woes...
Message-Id: <slrn9f4pc5.n77.rgarciasuarez@rafael.kazibao.net>
Salvador Peralta wrote in comp.lang.perl.misc:
} A few questions...
}
} I was fooling around with perl one liners tonight, and I ran into a
} few problems that i couldn't get my head around. First, I wanted to
} have a one-liner read in a redmond FUD page from my GET http utility
} and print out the number of times .NET was mentioned in the article
} versus OSS, Open Source and GPL, so I wrote this script:
}
} [salvador@localhost salvador]$ GET
} http://www.microsoft.com/presspass/exec/craig/05-03sharedsource.asp |
} perl -ne 'if ($_ =~ /\.NET/){$x++;} elsif ($_ =~ /GPL|OSS|Open
} Source/i){$y++;}print "MS: $x\n OS: $y\n";
You won't write good (short) one-liners if they're full of redundant
code, such as "$_ =~ ". And why did you put an elsif?
} The count that this returns for the GPL|OSS|Open Source regex is not
} valid.
}
} MS: 3
} OS: 9
}
} GPL alone is mentioned 11 times in the article.
I found 10 mentions of the GPL.
Note that your regexp matches also words like 'possible' or 'loss'.
} I'm wondering what I
} may have done to cause the error. My first thought was that if the
} script encounters .NET on a line, it never gets to the second
} condition so I changed elsif in the second part of that script to if
} with no change in result. My second though is that I may be using
} the $_ variable incorrectly.
If a word appears several times on a line, the corresponding variable is
incremented only once. That's your problem. Investigate the /g modifier.
} Second, I have looked through perlop and don't see how I can print a
} result at the end of the one-liner if I use the -n option. Since I
} am using the -n my current program gives me a line by line MS: OS:
} result when what I really want is to count up the instances of each
} and print the result. Again, can someone recommend a solution or
} point me to a resource other than perlop?
Look for '-n' in perlrun. It suggests a solution.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
GET http://www.microsoft.com/presspass/exec/craig/05-03sharedsource.asp |
perl -nle
'END{print"MS:$x\nOS:$y"}$x++while/\.NET/g;$y++while/\b(GPL|Oss|Open Source)\b/ig'
------------------------------
Date: Fri, 04 May 2001 10:09:48 +0100
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: One-liner matching woes...
Message-Id: <3AF271DC.A0140788@bms.umist.ac.uk>
Salvador Peralta wrote:
> [salvador@localhost salvador]$ GET
> http://www.microsoft.com/presspass/exec/craig/05-03sharedsource.asp |
> perl -ne 'if ($_ =~ /\.NET/){$x++;} elsif ($_ =~ /GPL|OSS|Open
> Source/i){$y++;}print "MS: $x\n OS: $y\n";
>
> The count that this returns for the GPL|OSS|Open Source regex is not
> valid.
>
> MS: 3
> OS: 9
>
> GPL alone is mentioned 11 times in the article. I'm wondering what I
> may have done to cause the error. My first thought was that if the
> script encounters .NET on a line, it never gets to the second
> condition so I changed elsif in the second part of that script to if
> with no change in result. My second though is that I may be using
> the $_ variable incorrectly.
You can simplify the one-liner by using $_ implicitly. e.g. $x++ if
/\.NET/;$y++ if /GPL|OSS|Open Source/i;
> Second, I have looked through perlop and don't see how I can print a
> result at the end of the one-liner if I use the -n option. Since I
> am using the -n my current program gives me a line by line MS: OS:
> result when what I really want is to count up the instances of each
> and print the result. Again, can someone recommend a solution or
> point me to a resource other than perlop?
You can enclose the code that you want to be executed in an END block.
This is only run on termination of the script (I apologise if my
terminology is a bit off, but the gist is there).
so your script becomes perl -ne '$x++ if /\.NET/;$y++ if /GPL|OSS|Open
Source/i;END{print "MS: $x\n OS: $y\n"}'
to do multiple matches on a single line you could try using a while
m//g;
e.g. perl -ne '$x++ while m/\.NET/g;$y++ while m/GPL|OSS|Open
Source/gi;END{print "MS: $x\n OS: $y\n"}'
HTH
Paul
------------------------------
Date: Fri, 04 May 2001 11:55:04 +0200
From: "Alexander Farber (EED)" <eedalf@eed.ericsson.se>
Subject: Re: Own module: how to export constants/subroutines of other modules
Message-Id: <3AF27C78.901838F3@eed.ericsson.se>
nobull@mail.com wrote:
> "Alexander Farber (EED)" <eedalf@eed.ericsson.se> writes:
>
> > I have grouped the variables and subroutines shared by
> > several scripts into my own module. I wonder however,
> > how to make avalailable some constants from other
> > modules
>
> The easiest thing to do is just do it. Import the symbols into your
> module's symbol table exactly as you normally would and then export
> them from your module exactly as you normally would.
>
> For a less simple approach see perldoc Exporter/"Exporting without
> using Export's import method".
Thanks, it has worked. I didn't realize, that I could
add these constants to my @EXPORT_OK as well.
------------------------------
Date: 04 May 2001 07:04:42 GMT
From: barryallwood@aol.com (Barry Allwood)
Subject: Re: Parsing
Message-Id: <20010504030442.24039.00001611@ng-mb1.aol.com>
Thanks for your Help with the parsing!
Im going to find a Module for this now
Barry
------------------------------
Date: Fri, 4 May 2001 14:59:27 +1000
From: "Tom Beer" <tom.beer@btfinancialgroup.spamfilter.com>
Subject: Re: PERL Code Generator
Message-Id: <9ctcvn$2j6$1@merki.connect.com.au>
What about me? Going to kill-file me for replying to your post?
Sheesh! Lighten up a bit!
"Randal L. Schwartz" <merlyn@stonehenge.com> wrote in message
news:m1vgnmdh7c.fsf@halfdome.holdit.com...
> >>>>> "Todd" == Todd Smith <todd@designsouth.net> writes:
>
> Todd> why would you blame a company for something they didn't do, and
probably
> Todd> don't know about?
>
> Strike 1 - top posting
> Strike 2 - stealth-CC-ing me
> Strike 3 - defending spammers and spam associates
>
> *plonk*
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
0095
> <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
> See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
training!
------------------------------
Date: Fri, 04 May 2001 10:23:46 +0200
From: Hermann Fass <hermann@vonabiszet.de>
Subject: Re: PERL Code Generator
Message-Id: <3AF26712.7F923DD4@vonabiszet.de>
Michael Wenzelmaier wrote:
> "CodeCharge is a powerful code generator that helps web developers and
> non-programmers create database-driven web applications in a matter of
> hours.
[snip]
My work as a web-developer began to become a nightmare when "professional"
agencies were involved to decrease my workload. They employ professional
"developers", which means:
1. The have started reading a book (HTML in 7 days by Laura Lemay) but went
for Frontpage at the end of the day.
2. They have motivated one of those techie-guys to install a wonderfull
"Code"-Generators for non-programmers.
3. They send spam to newsgroups.
Hermann
------------------------------
Date: Fri, 04 May 2001 09:33:14 +0200
From: Philip Newton <pne-news-20010504@newton.digitalspace.net>
Subject: Re: prevent empty message being sent?
Message-Id: <bpm4ft8h5hmib5lu9fgg95nl73q237afis@4ax.com>
On Thu, 03 May 2001 14:25:09 -0500, Bing Du <bing-du@tamu.edu> wrote:
> Part of my $message is dynamically generated and formatted. The rest is
> static. Now I need to figure out how to put them all in one variable.
.= may be able to help you.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Fri, 4 May 2001 11:13:55 +0200
From: "Perl Programación Web" <perl@programacionweb.com>
Subject: RE: Problems loading a hive file saved with Win32::TieRegistry
Message-Id: <9ctrmr$ha9$1@talia.mad.ttd.net>
I've found the solution. First of all, sorry for my English.
I assume that my last message was no clear, and maybe, this message could
not be clear too.
Thanks to Jenda Krynicky I've found the error.
It was on the UnLoad.
If any of you are interested in UnLoad "tricks", read the message
http://www.activestate.com/ASPN/Mail/msg/perl-win32-admin:476021
from the list perl-win32-admin
This is the code that save keys on a hive file, and then retrieve them.
(I've tested it on a
NT4 machine with ActivePerl Build 518)
Thanks you,
sub Salvar
{
my $separador_anterior= $Registry->Delimiter("/");
$diskKey= $Registry->{"LMachine/Software/Fermin/"} or die "Can't read
LMachine/Fermin key: $^E\n";
$diskKey->AllowSave( 1 );
print $diskKey;
$diskKey->RegSaveKey( "k:/registro.reg", [] );
}
sub Cargar
{
$pound= $Registry->Delimiter("/");
$exito = $Registry->AllowLoad( 1 );
$diskKey = $Registry->{"LMachine/"}->Load( "k:/registro.reg",
"NewSubKeyName" );
$Registry->{"LMachine/Software/Fermin/"}=$diskKey;
undef $diskKey;
}
Fermín
Perl Programación Web <perl@programacionweb.com> escribió en el mensaje de
noticias 9cpf8n$1me$1@talia.mad.ttd.net...
> Hello:
>
> I've saved part of my Win32 registry in a hive file at
> d:\programas\win32registry\registro with this code:
>
> my $separador_anterior= $Registry->Delimiter("/");
> $diskKey= $Registry->{"LMachine/Software/Fermin/"} or die "Can't read
> LMachine/Software/Fermin key: $^E\n";
> $diskKey->AllowSave( 1 );
> $diskKey->RegSaveKey( "registro", [] ); #No poner aquí letras, porque no
> funcionaría.
>
> Now, I want to retrieve this information whith Load, but I don't know how.
>
> I've tried and tried, without a Result.
> I've read the Win32::TieRegistry documentation, but the example shown,
seems
> no work.
>
> $newKey= $Registry->Load( "d:/programas/win32registry/registro" );
>
> Could you help me?
> Do you have an example which works?
>
> Thanks a lot
>
> Fermín
>
>
>
>
>
------------------------------
Date: Fri, 4 May 2001 13:28:22 +0200
From: eins@durchnull.de (Rudolf Polzer)
Subject: Re: Test for integer?
Message-Id: <slrn9f54im.8eq.eins@www42.t-offline.de>
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> According to <nobull@mail.com>:
> > "Dodger" <dodger@necrosoft.net> writes:
> >
> > > "Rob" <"relaxedrob@optushome.com.au"> wrote in message
> > > news:2t6I6.1899$76.7930@news1.rdc1.nsw.optushome.com.au...
> > > > Hi all!
> > > >
> > > > Is there a way for me to test if a scalar holds an integer value (positive
> > > > or negative)?
> > > >
> > > > Thanks!
> > >
> > > Saw a lot of replies, some very elabourate. However, it seems to me that:
> > > ($val == int $val)
> > > should do the trick fine...
> >
> > So "banana" is an integer in your book?
>
> No, but the question "Is a scalar an integer" has been treated a bit
> one-sided as "does it contain the decimal representation of an integer".
If you consider 1.0 a float (like eg Pascal does) you can do
($val eq int $val).
--
To view the lower part of this signature, apply ROT13 to the whole message.
Gb ivrj gur hccre cneg bs guvf fvtangher, nccyl EBG13 gb gur jubyr zrffntr.
------------------------------
Date: Fri, 04 May 2001 08:16:11 GMT
From: "Paul" <castaway-helpme@home.com>
Subject: untaint help
Message-Id: <fztI6.23204$kh.11669340@news1.rsm1.occa.home.com>
Hi,
I am having a problem with untainting. The error message I get is the
following:
Insecure dependency in open while running with -T switch at
/usr/local/lib/perl5/5.6.0/Net/FTP.pm line 445.
which comes from the following lines of code:
foreach $temp_file (@output_arr) {
# $temp_file = &untaint($temp_file);
$ftp->get("$temp_file","$RESTORE_DIR/$y.$temp_file") or die "Can't fetch
$temp_file: $!\n";
$y++;
}
I am running the perl script with -Tw option and perl gets upset when I do
ftp->get. Please note the commented line where I do the untaint of temp
file. I guess I need to untaint the file I am writing to at local host. But
I am not sure how to do that. Any help would be appreciated.
Thanks in advance.
Paul
------------------------------
Date: 04 May 2001 10:39:10 +0100
From: Alun Moon <alun.moon@unn.ac.uk>
Subject: using Apache::SSI offline
Message-Id: <uwv7x5u81.fsf@unn.ac.uk>
Reading through the documentation on CPAN for Apache::SSI, it allows
me to create extra SSI directives, which is one thing I'm looking for.
What I'd like to be able to do is run the SSI processor offline from a
perl script.
I'm wanting to aquire/write a set of tools to preprocess my HTML
(create tables of contents, navbars from <link> tags, etc).
I was thinking of extending the SSI directives anyway, so the
Apache:SSI module is fine. But as the pages will go onto two
different servers (one has basic SSI the other none), I need to do all
the processing offline before loading them to the server.
Is there a wrapper somewhere (in perl) that calls the functions in
this module. I thought mod_perl is the thing, but that appears to be
the bridge from apache to perl.
Many thanks
Alun
------------------------------
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.
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 832
**************************************