[23514] in Perl-Users-Digest
Perl-Users Digest, Issue: 5723 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 29 06:05:53 2003
Date: Wed, 29 Oct 2003 03:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 29 Oct 2003 Volume: 10 Number: 5723
Today's topics:
Call Perl Scripts from Other Dir in Linux, Path Messed <no@no.no>
Re: Call Perl Scripts from Other Dir in Linux, Path Mes <josef.moellers@fujitsu-siemens.com>
Re: Call Perl Scripts from Other Dir in Linux, Path Mes <no@no.no>
Re: Call Perl Scripts from Other Dir in Linux, Path Mes <josef.moellers@fujitsu-siemens.com>
Re: Call Perl Scripts from Other Dir in Linux, Path Mes <grazz@pobox.com>
Re: Call Perl Scripts from Other Dir in Linux, Path Mes <usenet@morrow.me.uk>
Re: Call Perl Scripts from Other Dir in Linux, Path Mes <bart.lateur@pandora.be>
Re: Can't do setuid and file permision denied errors (Tad McClellan)
cksum module <zeke03_no_spam@caramail.com>
Re: exec() gives output?? <e02@removethis.toao.net>
Re: exec() gives output?? <jurgenex@hotmail.com>
Re: Finding out if a string has a trailing slash <kaspREMOVE_CAPS@epatra.com>
Re: Guide for dealing with alternate character sets? <ldo@geek-central.gen.new_zealand>
Re: Guide for dealing with alternate character sets? <flavell@ph.gla.ac.uk>
Re: help... this perl is different... null values are c (Tad McClellan)
Re: Interactive sessions on another box from Win32 (Bill)
iteration number <jaddo@yahoo.com.>
Re: iteration number <vilain@spamcop.net>
Re: iteration number <kaspREMOVE_CAPS@epatra.com>
Re: iteration number <bart.lateur@pandora.be>
Re: multiline regular expression, is it possible? (Leif Wessman)
Re: multiline regular expression, is it possible? <usenet@morrow.me.uk>
Re: multiline regular expression, is it possible? <bart.lateur@pandora.be>
opendchub script problem <raidenji@bellsouth.net>
Re: Rounding a float in Perl? <pne-news-20031029@newton.digitalspace.net>
Re: Rounding a float in Perl? (Anno Siegel)
Re: Using 'crypt' command in perl script giving Insecur (Tad McClellan)
Using GnuPG::Interface daemonised <mb@uq.net.au>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 29 Oct 2003 07:18:14 GMT
From: "Public Interest" <no@no.no>
Subject: Call Perl Scripts from Other Dir in Linux, Path Messed Up
Message-Id: <WQJnb.198261$0v4.15415634@bgtnsc04-news.ops.worldnet.att.net>
I put my Perl script in a unix shell now. The filename is abc.pl
If I run "perl abc.pl", it works perfect
but if I run "perl /abs-path/abc.pl", it gave me the error file now found in
abc.pl. I opened several files in abc.pl. I think the perl script abc.pl use
the path veriable on the shell not where abc.pl sites. Because I want my
script to be portable, so I don't wnat to change the relative path within
abc.pl, so how do I tell abc.pl to set default path?
Anoher problem is that I run several scripts at once, and I put them in a
.sh file as
perl 111.pl
perl 222.pl
perl 333.pl
and I made the .sh file chmod 777, but when I type the file name RUN.sh, it
still tells me "command not found". I am not sure it is a shell problem or I
set up something wrong here.
------------------------------
Date: Wed, 29 Oct 2003 08:29:43 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: Call Perl Scripts from Other Dir in Linux, Path Messed Up
Message-Id: <3F9F6C67.235A11B1@fujitsu-siemens.com>
Public Interest wrote:
First of all, try to get a decent name. I sincerely doubt your parents
called you "Public" ("Hey Pubby, it's dinnertime!")
> I put my Perl script in a unix shell now. The filename is abc.pl
That won't work. Perl scripts belong in files not in unix shells.
> If I run "perl abc.pl", it works perfect
> but if I run "perl /abs-path/abc.pl", it gave me the error file now fou=
nd in
> abc.pl. I opened several files in abc.pl. I think the perl script abc.p=
l use
What files is abc.pl looking for and where are they? Although my crystal
ball is broken, somke shards still seem to work ...
I assume that your files reside in /abs-path and your current working
directory is not /abs-path. Then you might want to consult the manual
page of FindBin.
However, the use of this module is not a real solution. You might want
to consider other options like putting the path name(s) of the other
file(s) into an environment variable.
> the path veriable on the shell not where abc.pl sites. Because I want m=
y
> script to be portable, so I don't wnat to change the relative path with=
in
> abc.pl, so how do I tell abc.pl to set default path?
> =
> Anoher problem is that I run several scripts at once, and I put them in=
a
> .sh file as
> perl 111.pl
> perl 222.pl
> perl 333.pl
> and I made the .sh file chmod 777, but when I type the file name RUN.sh=
, it
> still tells me "command not found". I am not sure it is a shell problem=
or I
> set up something wrong here.
Try sh -x RUN.sh and it will tell you more.
Consulting another shard of my broken crystal ball, maybe the path of
perl is not in your PATH?
Josef
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Wed, 29 Oct 2003 07:53:11 GMT
From: "Public Interest" <no@no.no>
Subject: Re: Call Perl Scripts from Other Dir in Linux, Path Messed Up
Message-Id: <HlKnb.198273$0v4.15418978@bgtnsc04-news.ops.worldnet.att.net>
I followed your instruction as
sh -x RUN.sh
but except it prints something extra as
+ perl 111.pl
+ perl 222.pl
, it is the same as sh RUN.sh
I can run perl anywhere, so I think perl is in my path
in my abc.pl file, I "open (INPUT "input.txt")", so if the input file sits
right with the .pl file, and it works perfectly if I call from the same dir.
but not from other dirs
my file system:
/perlfiles/111.pl
/perlfiles/222.pl
/perlfiles/333.pl
/perlfiles/abc.pl
/perlfiles/input.txt
/perlfiles/RUN1.sh
/RUN2.sh
at /perlfiles/
"sh RUN1.sh" OK
"RUN1.sh" bash: RUN1.sh: command not found
at /
"sh /perlfiles/RUN1.sh" file input.txt not found in abc.pl
"sh RUN2.sh" file input.txt not found in abc.pl
What I think I can do is I CD to the path in RUN2.sh and run the script, and
CD back to the default dir. But it seems other better ways to do it.
------------------------------
Date: Wed, 29 Oct 2003 09:03:00 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: Call Perl Scripts from Other Dir in Linux, Path Messed Up
Message-Id: <3F9F7434.4079DAA9@fujitsu-siemens.com>
Public Interest wrote:
> =
> I followed your instruction as
> sh -x RUN.sh
> but except it prints something extra as
> + perl 111.pl
> + perl 222.pl
> , it is the same as sh RUN.sh
> =
> I can run perl anywhere, so I think perl is in my path
> =
> in my abc.pl file, I "open (INPUT "input.txt")", so if the input file s=
its
> right with the .pl file, and it works perfectly if I call from the same=
dir.
> but not from other dirs
That's what the notions of "current working directory" and "relative
path" do.
You either specify an absolute path or your specify a relative path and
the system sort-of prepends the current working directory.
> my file system:
> =
> /perlfiles/111.pl
> /perlfiles/222.pl
> /perlfiles/333.pl
> /perlfiles/abc.pl
> /perlfiles/input.txt
> /perlfiles/RUN1.sh
> /RUN2.sh
> =
> at /perlfiles/
> "sh RUN1.sh" OK
> "RUN1.sh" bash: RUN1.sh: command not found
> at /
> "sh /perlfiles/RUN1.sh" file input.txt not found in abc.pl
> "sh RUN2.sh" file input.txt not found in abc.pl
> =
> What I think I can do is I CD to the path in RUN2.sh and run the script=
, and
> CD back to the default dir. But it seems other better ways to do it.
As for finding executables: add their absolute path(s) to the PATH
environment variable.
As for finding files: either put them into a well-known location (/lib,
/usr/lib, $HOME/lib, ...) or provide the absolute path of their location
into an environment variable (MY_DATAFILE_PATH=3D/perlfiles) or into a
configuration file ($HOME/.myperlconfig) or whatever, but the system is
pretty helpless in guessing where your files are.
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Wed, 29 Oct 2003 08:10:10 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: Call Perl Scripts from Other Dir in Linux, Path Messed Up
Message-Id: <CBKnb.37693$1C5.12925@nwrdny02.gnilink.net>
In comp.lang.perl.misc Public Interest <no@no.no> wrote:
> in my abc.pl file, I "open (INPUT "input.txt")", so if the input
> file sits right with the .pl file, and it works perfectly if I
> call from the same dir. but not from other dirs
Then you need to use absolute paths -- or paths relative to the
location of your script -- with open().
use FindBin qw($Bin);
open INPUT, "$Bin/input.txt" or die "open: $Bin/input.txt: $!";
[ f'ups to clpm ]
--
Steve
------------------------------
Date: Wed, 29 Oct 2003 08:28:14 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Call Perl Scripts from Other Dir in Linux, Path Messed Up
Message-Id: <bnntmu$6an$1@wisteria.csv.warwick.ac.uk>
"Public Interest" <no@no.no> wrote:
> in my abc.pl file, I "open (INPUT "input.txt")", so if the input file sits
> right with the .pl file, and it works perfectly if I call from the same dir.
> but not from other dirs
You want to put
chdir '/perlfiles';
or so at the start of your Perl script.
> my file system:
>
> /perlfiles/111.pl
> /perlfiles/222.pl
> /perlfiles/333.pl
> /perlfiles/abc.pl
> /perlfiles/input.txt
> /perlfiles/RUN1.sh
> /RUN2.sh
>
> at /perlfiles/
> "sh RUN1.sh" OK
> "RUN1.sh" bash: RUN1.sh: command not found
Unlike DOS, Unix shells do not by default (nowadays) have '.' (the
current working directory) in your PATH. This means that to run
RUN1.sh you need to invoke it as './RUN1.sh'. Or you can find what
your PATH is (echo $PATH) and copy RUN1.sh into one of those
directories.
Also, [OT], you don't really want to be stuffing things into / like
that... at least put them under /usr/local. And it is not conventional
under Unix to use 'file extensions' for executable script files.
Ben
--
EAT
KIDS (...er, whoops...)
FOR ben@morrow.me.uk
99p
------------------------------
Date: Wed, 29 Oct 2003 10:53:07 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Call Perl Scripts from Other Dir in Linux, Path Messed Up
Message-Id: <4k2vpv44k511j8cle9bno6l1o2vkov9fd6@4ax.com>
Public Interest wrote:
>I can run perl anywhere, so I think perl is in my path
That's not your problem. your problem is here:
>> I opened several files in abc.pl.
I'm sure you're using relative paths? Then your problem is simply in
your current directory when the script is run.
You could demand that people chdir to the path containing the files,
before calling your script, or you could use the FindBin module to find
out where the script itself is. I'll stay a bit sketchy on that
approach, because FindBin is somewhat broken, it sometimes refuses to
work in mysterious ways.
The approach I'm advocating, is to simply figure out the path, either
absolute or relative, out of $0, the name for the script, since that is
*always* a valid path, at startup. At least, I can't think of any
counter-examples.
So I guess this should work, at least on Unixy systems:
$0 =~ /(.*)\// and chdir $1;
Now your script should be able to find the files.
--
Bart.
------------------------------
Date: Tue, 28 Oct 2003 23:31:57 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Can't do setuid and file permision denied errors
Message-Id: <slrnbpuk6d.gld.tadmc@magna.augustmail.com>
Chris <chrisw@lu.csi.com.ph> wrote:
> I'm a newbie with perl scripts
No problem. Everybody has to start somewhere.
> I'm having
> problem running my copied script to my server.
What server?
Most uses of Perl do not require a server at all, so the least
you could do was tell us what _kind_ of server you are
dealing with: SMTP, NNTP, FTP, HTTP...
> I have a chpass.pl which is being executed by a change password web
> utility page.
Oh. Must be question about using Perl in the CGI environment then?
Have you already seen what the Perl FAQ has to say about CGI programming?
perldoc -q CGI
The easiest programming is single user on the command line.
CGI programming is a bit more advanced, as it adds issues of
multitasking, security and sometimes performance, that would
not normally need to be considered.
Changing passwords is yet more advanced, but in the area of
Operating Systems, rather than Perl.
Changing passwords through a CGI interface scares me to death!
And that is what you want to take on as your very first
Perl program?
Gulp.
1) Learn Perl before learning a new application area, such as CGI.
2) _Why_ do you think you want this?
It is *profoundly* dangerous you know...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 29 Oct 2003 07:22:31 GMT
From: zeke03 <zeke03_no_spam@caramail.com>
Subject: cksum module
Message-Id: <20031029-92231-538323@foorum.com>
Hello,
I have a question concerning the String-CRC-Cksum-0.03 CPAN module.
I have downloaded Cksum.pm and Makefile.PL and put it in c:\perl\lib\cksum (i
work on Windows and i would work on unix and linux after)
I have launched "perl Makefile.PL", then the file Makefile has been create in
c:\perl\lib\cksum folder.
My little perl program, in a folder, i want to do a cksum to each files in the
folder (i am a beginner) doesn't work :
use String::CRC::Cksum;
use String::CRC::Cksum qw(cksum);
use File::Spec;
$reptra='c:\temp\data_integrity';
chdir $reptra or die "Can't go in work folder Because: $! \n";
### Globalisation
my @all_files = glob "*";
print Dumper @all_files;
### Threat
foreach $arg (@all_files)
{
$cksum=cksum($arg);
print "CHECK SUM = $cksum \n\n";
}
=> perl d:\ssh_integre.pl
Can't locate String/CRC/Cksum.pm in @INC (@INC contains: C:/Perl/lib) at
d:\ssh_integre.pl line 1.
BEGIN failed--compilation aborted at d:\ssh_integre.pl line 1.
Can someone help me ?
Thanks
zeke03@caramail.com
--
Ce message a ete poste via la plateforme Web club-Internet.fr
This message has been posted by the Web platform club-Internet.fr
http://forums.club-internet.fr/
------------------------------
Date: Wed, 29 Oct 2003 07:20:49 GMT
From: "Experienced but Undocumented" <e02@removethis.toao.net>
Subject: Re: exec() gives output??
Message-Id: <lTJnb.211862$pl3.87972@pd7tw3no>
"Jürgen Exner" <jurgenex@hotmail.com> wrote
> Did you even bother to read even the first sentence of the documentation
for
> the functions you are using?
Yeah, and it's not doing what it says it should ;-)
------------------------------
Date: Wed, 29 Oct 2003 07:23:49 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: exec() gives output??
Message-Id: <9WJnb.2223$Q9.466@nwrddc02.gnilink.net>
Experienced but Undocumented wrote:
> "Jürgen Exner" <jurgenex@hotmail.com> wrote
>> Did you even bother to read even the first sentence of the
>> documentation for the functions you are using?
>
> Yeah, and it's not doing what it says it should ;-)
???
What does the doc state and what do you observe?
I would be curious to here details.
jue
------------------------------
Date: Wed, 29 Oct 2003 13:03:31 +0530
From: "Kasp" <kaspREMOVE_CAPS@epatra.com>
Subject: Re: Finding out if a string has a trailing slash
Message-Id: <bnnqqq$q1i$1@newsreader.mailgate.org>
> Perhaps $dirname ends with something invisible like a carriage return on
> an OS that does not recognize that as part of newline. See if this works:
Might I add that a chomp would be helpful too?
chomp($dirname); #my two cents
$dirname =~ s/\s*$//;
if ($dirname =~ m|/$|) {
print "trailing slash\n";
}
--
"Accept that some days you are the pigeon and some days the statue."
"A pat on the back is only a few inches from a kick in the butt." - Dilbert.
------------------------------
Date: Wed, 29 Oct 2003 19:22:10 +1300
From: Lawrence D¹Oliveiro <ldo@geek-central.gen.new_zealand>
Subject: Re: Guide for dealing with alternate character sets?
Message-Id: <ldo-74F5DD.19221029102003@news.wave.co.nz>
In article <Pine.LNX.4.53.0310281042580.28979@ppepc56.ph.gla.ac.uk>,
"Alan J. Flavell" <flavell@ph.gla.ac.uk> wrote:
>On Tue, 28 Oct 2003, Lawrence D¹Oliveiro wrote:
>
>> For character manipulation, a fixed-length code like UTF-16
>
>utf-16 is not "fixed length".
Ignore surrogates. I don't know what the hell they're doing there.
------------------------------
Date: Wed, 29 Oct 2003 10:30:45 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Guide for dealing with alternate character sets?
Message-Id: <Pine.LNX.4.53.0310291010560.30368@ppepc56.ph.gla.ac.uk>
On Wed, 29 Oct 2003, Lawrence D¹Oliveiro wrote:
> In article <Pine.LNX.4.53.0310281042580.28979@ppepc56.ph.gla.ac.uk>,
> "Alan J. Flavell" <flavell@ph.gla.ac.uk> wrote:
>
> >On Tue, 28 Oct 2003, Lawrence D¹Oliveiro wrote:
> >
> >> For character manipulation, a fixed-length code like UTF-16
> >
> >utf-16 is not "fixed length".
>
> Ignore surrogates.
No thanks.
> I don't know what the hell they're doing there.
All the more reason not to ignore them, then, until one does know.
Check the meaning of the "utf" initialism ("transformation format"),
as opposed to the true fixed-length representation(s), specifically
iso-10646-ucs-4. AIUI, Unicode don't recommend UCS format for
transmission (interworking) encoding, but if you want a fixed-length
internal representation then ucs-4 *could* be an appropriate choice.
But, as I said, Perl has already made its choice of internal
representation. I'd say "use it". Some complain that it's
inefficient, but don't forget the first three rules of optimisation:
"don't optimise yet".
------------------------------
Date: Tue, 28 Oct 2003 23:37:49 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: help... this perl is different... null values are crashing my script.
Message-Id: <slrnbpukhd.gld.tadmc@magna.augustmail.com>
Eric J. Roode <REMOVEsdnCAPS@comcast.net> wrote:
> Please do not post
> MIME/multipart articles to usenet.
Oh. That explains why I'm seeing followups without having seen the OP.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 28 Oct 2003 22:18:52 -0800
From: wherrera@lynxview.com (Bill)
Subject: Re: Interactive sessions on another box from Win32
Message-Id: <239ce42f.0310282218.7d8b0260@posting.google.com>
"John Call" <jcall@ellijay.com> wrote in message news:<bnmtmb01fb1@enews1.newsguy.com>...
> I need to write some code on a Win32 box that will connect securely to a
> linux box, su (which is interactive), and then run a command line program
> which will prompt me for some input (interactive). I planned to ssh to the
> box and use Expect to handle the interactive issues. I have found that
> Expect is not an option on Win32.
>
> I am only vaguely familiar with Win32 and am not sure what my options are
> for connecting securely to linux box and running interactive programs on the
> linux box. My own research has turned up very little. If anyone has any
> ideas on this I would appreciate it.
>
>
This is a command line login, or a GUI login?
Look at Net::Telnet and the waitfor function. If it needs to be ssh,
there may be a way to run a similar script through that (anybody
know?). Regular telnet will pass passwords in plaintext by default.
In general, it would be something like:
$t = new Net::Telnet (Port => $portnum, Timeout => 20);
$t->open('myserver');
$t->waitfor('/login: $/');
$t->print('administrator');
$t->waitfor('/password: $/');
$t->print('my-passwd');
------------------------------
Date: Wed, 29 Oct 2003 17:41:34 -0800
From: "Jack" <jaddo@yahoo.com.>
Subject: iteration number
Message-Id: <3f9f61bf$1@dnews.tpgi.com.au>
Hello
is there a perl default variable which holds the number of iteration for the
'foreach' statement
foreach my $key ( sort keys %data) {
thanks
------------------------------
Date: Tue, 28 Oct 2003 23:08:35 -0800
From: "Michael Vilain <vilain@spamcop.net>"
Subject: Re: iteration number
Message-Id: <vilain-DA0D0B.23083528102003@comcast.ash.giganews.com>
In article <3f9f61bf$1@dnews.tpgi.com.au>, "Jack" <jaddo@yahoo.com.>
wrote:
> is there a perl default variable which holds the number of iteration for the
> 'foreach' statement
> foreach my $key ( sort keys %data) {
Not that I'm aware of. Because of this, if I need any sort of index, I
use a "for" loop instead.
--
DeeDee, don't press that button! DeeDee! NO! Dee...
------------------------------
Date: Wed, 29 Oct 2003 12:53:03 +0530
From: "Kasp" <kaspREMOVE_CAPS@epatra.com>
Subject: Re: iteration number
Message-Id: <bnnpss$omb$1@newsreader.mailgate.org>
"Jack" <jaddo@yahoo.com.> wrote in message
news:3f9f61bf$1@dnews.tpgi.com.au...
> is there a perl default variable which holds the number of iteration for
the
> 'foreach' statement
> foreach my $key ( sort keys %data) {
Not that I know of. But you could use a variable of your own to accomplish
this
Eg.
my $counter = 0
foreach my $key ( sort keys %data) {
...
$counter++;
}
print $counter;
--
"Accept that some days you are the pigeon and some days the statue."
"A pat on the back is only a few inches from a kick in the butt." - Dilbert.
------------------------------
Date: Wed, 29 Oct 2003 09:37:24 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: iteration number
Message-Id: <tf2vpv8slbgmbr0s1oip3c66jggpn4onu3@4ax.com>
Jack wrote:
>is there a perl default variable which holds the number of iteration for the
>'foreach' statement
>foreach my $key ( sort keys %data) {
No.
It has been proposed as a feature for Perl6, so I'm sure it's not in
perl5.
All you can do is keep track yourself, with an extra variable o your
own.
my $i = 0;
foreach my $key ( sort keys %data) {
...
} continue {
$i++;
}
--
Bart.
------------------------------
Date: 29 Oct 2003 00:41:02 -0800
From: leifwessman@hotmail.com (Leif Wessman)
Subject: Re: multiline regular expression, is it possible?
Message-Id: <64beeaad.0310290041.5c08a04@posting.google.com>
Yes, maby I could. But I have more faith in Perl programmers... And
regexp work almost the same in the two languages...
Leif
"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in message news:<Xns9422BFB87EEB0sdn.comcast@216.196.97.136>...
> leifwessman@hotmail.com (Leif Wessman) wrote in
> news:64beeaad.0310280637.4c49e659@posting.google.com:
>
> > In php I'm doing the following:
> >
> > preg_match_all("/$myregexp/", $results, $matches);
> >
> > But I get an error. Why is this?
>
> Perhaps you could ask in a PHP newsgroup? :-)
------------------------------
Date: Wed, 29 Oct 2003 09:08:18 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: multiline regular expression, is it possible?
Message-Id: <bno022$71s$1@wisteria.csv.warwick.ac.uk>
[please don't top-post]
leifwessman@hotmail.com (Leif Wessman) wrote:
> "Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in message
> news:<Xns9422BFB87EEB0sdn.comcast@216.196.97.136>...
> > leifwessman@hotmail.com (Leif Wessman) wrote in
> > news:64beeaad.0310280637.4c49e659@posting.google.com:
> >
> > > In php I'm doing the following:
> > >
> > > preg_match_all("/$myregexp/", $results, $matches);
> > >
> > > But I get an error. Why is this?
> >
> > Perhaps you could ask in a PHP newsgroup? :-)
>
> Yes, maby I could. But I have more faith in Perl programmers... And
> regexp work almost the same in the two languages...
In that case, let us translate your script into Perl:
#!/usr/bin/perl -l
use warnings;
use strict;
my $myregexp = <<RE;
<tr><td>
id: (\\d{5}[AX])
<\\/td><\\/tr>
RE
my $results = <<RES;
<table>
<tr><td>
id: 45434X
</td></tr>
<tr><td>
id: 95434A
</td></tr>
</table>
RES
print join ", ", $results =~ /$myregexp/g;
__END__
Worksforme.
~% ./php
45434X, 95434A
~%
Now, what was your Perl problem?
Ben
--
"If a book is worth reading when you are six, * ben@morrow.me.uk
it is worth reading when you are sixty." - C.S.Lewis
------------------------------
Date: Wed, 29 Oct 2003 09:33:01 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: multiline regular expression, is it possible?
Message-Id: <vr1vpvcnd7ama2329tk9m58con31n39vbd@4ax.com>
Leif Wessman wrote:
>In php I'm doing the following:
>
>preg_match_all("/$myregexp/", $results, $matches);
>
>But I get an error. Why is this?
Because PHP is stupid.
You may not like that answer, but you have to make sure the interpolated
string looks like a proper regexp, complete with slashes. For this
simple case, this implies that there must be backslashes in front of
every slash in the string.
Even though it's not intended for that purpose -- but PHP is a very
hackish language anyway -- you can try using addslashes() on the regexp
before wrapping slashes around it. It would also escape backslashes,
which is a plus.
Otherwise, you could use alternative delimiters on the regexp, something
not in the string, for example "!":
preg_match_all("!$myregexp!", $results, $matches); # untested
Perl programmers will still be shocked when they realize what is going
on here, but it's the best one can do on such a braindead language,
except for writing a very elaborate library to get the level of
smartness Perl has all by itself.
--
Bart.
------------------------------
Date: Wed, 29 Oct 2003 00:45:25 -0500
From: "Raidenji" <raidenji@bellsouth.net>
Subject: opendchub script problem
Message-Id: <0tInb.78463$W77.8971@bignews6.bellsouth.net>
is there a way to hide user input in a script for opendchub?
the command is just like the me command in IRC.
but i want to be able to only show the output.
here is the code i'm using
} elsif ($command[1] =~ /^[\+-\/]me/i) {
($cmd) = ($command[1] =~ /^[\+-\/]me(.*)$/);
&sendmessage($user,$touser,$type,"<*> $user$cmd $command[-1]");
}
thanks.
Raidenji
------------------------------
Date: Wed, 29 Oct 2003 06:54:15 +0100
From: Philip Newton <pne-news-20031029@newton.digitalspace.net>
Subject: Re: Rounding a float in Perl?
Message-Id: <1elupvsjng0l7k4a96g60onof4gbfpj7e8@4ax.com>
On 27 Oct 2003 11:27:56 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
Siegel) wrote:
> The FAQ answer is "use sprintf()", which is fine in most cases. It
> must be said, however, that sprintf() is a slow function, and if a
> lot of rounding is going on it can easily dominate the calculation.
> Even a pure Perl rounding function, along the lines of
>
> sub round {
> my $x = shift;
> my $y = 0.5 + abs $x;
> my $abs = int $y;
> $abs -= $abs % 2 if $y == $abs;
> ($x <=> 0) * $abs;
> }
>
> is twice as fast, and a compiled rounding function can be ten times
> as fast.
But that doesn't allow you to specify the number of decimal places to
round to, does it?
And I wonder whether, once you add the scaling necessary to support
that, it's still faster than sprintf.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
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: 29 Oct 2003 10:12:58 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Rounding a float in Perl?
Message-Id: <bno3ra$1p7$1@mamenchi.zrz.TU-Berlin.DE>
Philip Newton <nospam.newton@gmx.li> wrote in comp.lang.perl.misc:
> On 27 Oct 2003 11:27:56 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
> Siegel) wrote:
>
> > The FAQ answer is "use sprintf()", which is fine in most cases. It
> > must be said, however, that sprintf() is a slow function, and if a
> > lot of rounding is going on it can easily dominate the calculation.
> > Even a pure Perl rounding function, along the lines of
> >
> > sub round {
> > my $x = shift;
> > my $y = 0.5 + abs $x;
> > my $abs = int $y;
> > $abs -= $abs % 2 if $y == $abs;
> > ($x <=> 0) * $abs;
> > }
> >
> > is twice as fast, and a compiled rounding function can be ten times
> > as fast.
>
> But that doesn't allow you to specify the number of decimal places to
> round to, does it?
No, it doesn't. I don't remember the last time I wanted to round to
anything but the nearest integer, but the objection is valid.
> And I wonder whether, once you add the scaling necessary to support
> that, it's still faster than sprintf.
It (i.e. my implementation on my machine) is still 44% faster than sprintf,
as opposed to 113% for the non-scaling version. Then again, it can also
round 1234 to 1000 for a negative "number of decimal places", something
sprintf doesn't do.
But we're approaching bean-counting territory here...
Anno
------------------------------
Date: Tue, 28 Oct 2003 23:56:04 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Using 'crypt' command in perl script giving Insecure depedency warning and error.
Message-Id: <slrnbpuljk.gld.tadmc@magna.augustmail.com>
Ravi Bhave <rbhave@ford.com> wrote:
> I have a perl script which is used to log on to a server using
> username and encrypted password file and key file. The script runs
> FINE when I execute it on command line
> BUT when my program(C++ program) calls the same script(ftp_get) and
> passes the required parameters it does not work.
It looks like your C++ program is calling perl setgid, while
at the command line it was running as you.
Perl will automatically turn on "taint checking" under those
circumstances. See perlsec.pod.
> It fails at line
> where 'crypt' is used and gives me error: 'Insecure depedency
> in''while running setgid at ftp_get (script shown at the end) at line
> 21, <INF> line 1.
All of the messages that perl might issue are documented in
perldoc perldiag
For your message it says:
Insecure $ENV{%s} while running %s
(F) You can't use system(), exec(), or a piped open in
a setuid or setgid script if any of $ENV{PATH},
$ENV{IFS}, $ENV{CDPATH}, $ENV{ENV} or $ENV{BASH_ENV}
are derived from data supplied (or potentially sup
plied) by the user. The script must set the path to a
known value, using trustworthy data. See perlsec.
> Please help me in fixing this error.
You are trying to do something potentially dangerous, and perl
wants some convincing that that is really what you want to do.
> Any help is greatly apreciated.
perldoc perlsec
and try hard-coding the env vars above in your Perl program.
> # Get the parameters.
> my( $host ) = shift || die $Usage;
> my( $login ) = shift || die $Usage;
> my( $local_file ) = shift || die $Usage;
> my( $remote_file ) = shift || die $Usage;
> my( $SeedFile ) = shift || die $Usage;
> my( $PWC_File ) = shift || die $Usage;
Doesn't have anything to do with your problem, but I'd replace
all of that with:
# untested
die $Usage unless @ARGV == 6;
my($host, $login, $local_file, $remote_file, $Seedfile, $PWC_File) = @ARGV;
> open INF, $SeedFile;
You should always, yes *always*, check the return value from open():
open INF, $SeedFile or die "could not open '$SeedFile' $!";
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 29 Oct 2003 16:07:44 +1000
From: Matthew Braid <mb@uq.net.au>
Subject: Using GnuPG::Interface daemonised
Message-Id: <bnnlff$2i0$1@bunyip.cc.uq.edu.au>
Hi all,
I've run into a problem using GnuPG::Interface. I'm not sure if it's the
package or GPG itself, but its kind of debilitating.
Basically, if my script's STDOUT/STDERR handles are not connected to a
terminal, GnuPG::Interface will return nothing on the stdout/stderr
handles, despite the fact that these are supplied as IO::Handles and
should (as far as I can tell) not be bound to STDOUT/STDERR unless I
explicitly made them so.
The following code is how I tested this. You'll need
gpg/GnuPG::Interface/a keyring/a default key without a password to make
this work:
============= START CODE =====================
use GnuPG::Interface;
#print "OK - CLOSE THE TERMINAL!\n";
#sleep(20);
print "HERE GOES!\n";
my $gpg = GnuPG::Interface->new;
$gpg->options->hash_init(armor => 1);
$gpg->options->meta_interactive(0);
$gpg->call('/usr/local/bin/gpg');
my ($in, $out, $err, $stat) = (IO::Handle->new, IO::Handle->new,
IO::Handle->new, IO::Handle->new);
my $pid = $gpg->sign(handles => GnuPG::Handles->new(stdin => $in,
stdout => $out,
stderr => $err,
status => $stat));
print $in "THIS IS A TEST";
close($in);
my @ciphered = <$out>;
close($out);
close($err);
close($stat);
waitpid($pid, 0);
print "CIPHERED IS: ", @ciphered, "\n";
$pid = $gpg->decrypt(handles => GnuPG::Handles->new(stdin => $in,
stdout => $out,
stderr => $err,
status => $stat));
print $in @ciphered;
close($in);
use IO::File;
my $mout = IO::File->new("|/usr/sbin/sendmail -ti");
print $mout "To: ME\n\n"; # <--- CHANGE THIS!!!
print $mout "DECRYPT STATUS IS: ", <$stat>, "\n\n";
close($stat);
print $mout "DECRYPT ERROR IS: ", <$err>, "\n\n";
close $mout;
close($err);
close($out);
waitpid($pid, 0);
============= END CODE =====================
You need to change the line with CHANGE THIS so it points to an email
address you can get to.
First time, run it from a terminal. All should be OK (as long as you
have GPG set up correctly) - you'll get an email to the address you added
Next, uncomment lines 2 and 3, and run it again.
This time, when "OK - CLOSE THE TERMINAL!" comes up, do as it says (I;m
assuming you're running this from withing a window manager too).
This time I get a message with contents of:
DECRYPT STATUS IS: [GNUPG:] NODATA 2
DECRYPT ERROR IS:
Further digging shows that the filehandles specified by stdout and
stderr (to GnuPG::Handles) are at EOF immediately. Nothing comes out of
there at all. The status handle however spits out data as normal.
Is there a way around this? This has been very disappointing as
GnuPG::Interface is otherwise very clean to use, and now I've had to go
back to juggling temp files.
MB
------------------------------
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 5723
***************************************