[6992] in Perl-Users-Digest
Perl-Users Digest, Issue: 617 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 16 18:07:22 1997
Date: Mon, 16 Jun 97 15:00:46 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 16 Jun 1997 Volume: 8 Number: 617
Today's topics:
Re: #ifdef in XS ? (Casper H.S. Dik - Network Security Engineer)
[BUG] ExtUtils::MakeMaker fails when / is not readable (Robert Dalgleish)
any major updates to the man program (written in perl) (Daniel Bick)
Any way to link a .o file ? (Art Blair)
Re: Any way to link a .o file ? (Nathan V. Patwardhan)
Re: backing up in a <FILEHANDLE> <rootbeer@teleport.com>
Re: Case Conversion <rootbeer@teleport.com>
CGI scripting in Perl <metalhead@mhv.net>
declaring a list of variables MXD38@vm.cc.purdue.edu
Re: ENVIRONMENTAL VARIABLES...... how do you access the <sibsib@hotmail.com>
errors <webmaster@pageeffects.com>
Re: errors (Tad McClellan)
Re: exec and system calls <mark@sierra-inc.com>
Re: file test operators <bryan@eai.com>
Re: file test operators (Nathan V. Patwardhan)
flock and SCO Matthew Hopkins
Re: FYI: running interactive ftp within perl script <root@192.255.255.255>
getting username and password <ez045864@mailbox.ucdavis.edu>
Help on two-way communication via sockets <pma@sympatico.ca>
Re: help with regexps.... <flg@vhojd.skovde.se>
help with script needed <lcrnkovi@sw.seisy.abb.se>
Help with script needed <lcrnkovi@sw.seisy.abb.se>
Re: help with script needed <flg@vhojd.skovde.se>
Re: Help: SQL Server & perl ( Thomas Lachlan XMS x4206 )
How do i convert a (float) to (integer) ? <labah@algonet.se>
Re: How do i convert a (float) to (integer) ? <cgprice@austin.ibm.com>
Re: How do i convert a (float) to (integer) ? <ajohnson@gpu.srv.ualberta.ca>
How to change code using deprecated features? lvirden@cas.org
Re: How to change code using deprecated features? (Tad McClellan)
Re: justa question... (Faust Gertz)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 13 Jun 1997 14:07:22 GMT
From: Casper.Dik@Holland.Sun.COM (Casper H.S. Dik - Network Security Engineer)
Subject: Re: #ifdef in XS ?
Message-Id: <casper.866211153@uk-usenet.uk.sun.com>
Douglas Seay <seay@absyss.fr> writes:
>To be safest, ensure that the # in the first column and the directive
>comes next, no spaces. Some compilers let you have white space before
>the # or between the # and the directive, but I don't risk it. I give
>up the little bit of readability in exchange for something that I know
>will work. I don't know what ANSI requires, I just know I've been bored
>out of my fixing whitespace in CPP directives (no access to Perl at that
>time).
ANSI allows:
<whitespace>#<whitespace>directive
Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
------------------------------
Date: Fri, 13 Jun 1997 10:39:39 -0600
From: Robert.Dalgleish@mailhost.sk.sympatico.ca (Robert Dalgleish)
Subject: [BUG] ExtUtils::MakeMaker fails when / is not readable
Message-Id: <Robert.Dalgleish-1306971039400001@hssktn257.sk.sympatico.ca>
On the web server that I do some CGI programming on, I attempted to
install the libwww-perl5 package, and ran into a frustrating problem.
1) MakeMaker insists that it cannot find any of the files in the manifest,
even though they are all there, and the directory and files are executable
and readable (respectively).
2) After an hour or so of debugging, I found that File::Find invokes the
routine Cwd::fastcwd(), which breaks when a directory is not readable.
3) Cwd::getcwd() also breaks, but it reports an error when this happens.
4) The root directory on the web server is not readable by others, so the
usual cwd() process is interrupted.
I might suggest a couple of fixes:
o fastcwd() needs to check for a couple of error conditions before doing
its damage. Among other things, it could either return an error
indication, or it could call getcwd() as a backup operation.
o getcwd() could assume that an unreadable directory was at the root (not
a fair assumption, granted) and check that the path built up so far was
the complete path.
--
Bob Dalgleish bob.dalgleish@industrialstrengthsw.sk.ca
------------------------------
Date: 13 Jun 1997 20:14:26 GMT
From: bick@msc.edu (Daniel Bick)
Subject: any major updates to the man program (written in perl)
Message-Id: <5ns9n2$r7k@uc.msc.edu>
Has anyone updated or made significant changes to
the man program written in perl by Tom Christiansen
since around late 1993? There is a RFP from about this
time detailing possible improvements also in the below
directory on CPAN sites.
The URL for this code is ftp://whatever-cpan-site/scripts/
manstuff/*
Thanks for any info you may have.
bick@msc.edu
------------------------------
Date: 14 Jun 1997 00:09:54 GMT
From: blair@sf73.dseg.ti.com (Art Blair)
Subject: Any way to link a .o file ?
Message-Id: <5nsngi$id3@sf18.dseg.ti.com>
Lets say I have a c library of functions, call it libgpib.o, along
with it an include file gpib.h, meant for use with a c compiler.
I dont have the source code to gpib.o. The only way I now
see of using this library is to write a cheesy little c program
that acts as kind of a shell and communicate with it via
STDIN/STDOUT from perl. It's cheesy & slow. Is there any way
to link this library in with perl so I can call the functions
in gpib.o directly in perl ? I can recompile perl if I have to.
Thanx,
Art.
------------------------------
Date: 14 Jun 1997 00:50:08 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Any way to link a .o file ?
Message-Id: <5nsps0$kbd@fridge-nf0.shore.net>
Art Blair (blair@sf73.dseg.ti.com) wrote:
: to link this library in with perl so I can call the functions
: in gpib.o directly in perl ? I can recompile perl if I have to.
Well, you could always check out what XS (perlxs and perlxstut manpages)
has to offer, and take it from there.
--
Nathan V. Patwardhan
nvp@shore.net
------------------------------
Date: Sat, 14 Jun 1997 07:31:53 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Eric Finley <ez041407@boris.ucdavis.edu>
Subject: Re: backing up in a <FILEHANDLE>
Message-Id: <Pine.GSO.3.96.970614073052.4940L-100000@kelly.teleport.com>
On 13 Jun 1997, Eric Finley wrote:
> How do you back up 1 line in a filehandle.
Use seek(). You'll want to remember where the target line started; for
that, use tell(). Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Sat, 14 Jun 1997 08:35:45 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Dean Inada <dmi@deltanet.com>
Subject: Re: Case Conversion
Message-Id: <Pine.GSO.3.96.970614083429.4940V-100000@kelly.teleport.com>
On 14 Jun 1997, Dean Inada wrote:
> >Tom Phoenix typed when the mommy tyrannosaurus found him/her:
> >: On Fri, 6 Jun 1997, Tung-chiang Yang wrote:
> >
> >: > tr/A-Za-z/a-zA-Z/;
> >
> >: That's not going to work on accented characters.
> >
> Since the homework is probably due by now, it should be safe
> to reveal the answer:
>
> $_ ^= lc($_) ^ uc($_);
That's _still_ not going to work on accented characters, tyrannosaurus or
not.
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Thu, 12 Jun 1997 21:57:05 -0700
From: James Esler <metalhead@mhv.net>
Subject: CGI scripting in Perl
Message-Id: <33A0D321.2DCB@mhv.net>
I'm trying to write a CGI script in Perl which will take the information
from an HTML interactive form and feed it to a DBM file. The form is
read and parsed correctly by my CGI library and the associative array
used to reference the DBM gets the info from the form. But for some
reason, it doesn't feed it to the DBM file itself. When I go to the
UNIX command prompt to access the DBM, the file comes up empty. Does
anyone have any idea why this may be occurring?
------------------------------
Date: Fri, 13 Jun 97 23:22:02 EST
From: MXD38@vm.cc.purdue.edu
Subject: declaring a list of variables
Message-Id: <17B8C1489AS86.MXD38@vm.cc.purdue.edu>
Sevearl variables are being inputed to a perl.cgi via a form.
For example: Value1, Value2, Value3, Value4 are submited.
Rather than writing:
$Value1 = $input{'Value1'};
$Value2 = $input{'Value2'};
$Value3 = $input{'Value3'};
$Value4 = $input{'Value4'};
to input the vars, I want to simplify this into a loop of some sort so that I c
an condence it a bit. (There are actually many more vars of high repitition.)
I tried something like the following with minimal luck:
for $i ( 1 .. 4) {
$Value[$i]=$input{'Value$i'};
}
I didn't work. Mostly because Perl is looking for a character input of 'Value$
i'
So, does anyone know how I can pass such a set of vars?
Please advise,
Mark
------------------------------
Date: Thu, 12 Jun 1997 21:04:25 -0400
From: Scott Blanksteen <sibsib@hotmail.com>
Subject: Re: ENVIRONMENTAL VARIABLES...... how do you access them in your program
Message-Id: <33A09C99.356DAA33@hotmail.com>
rthomas wrote:
>
> I'm not sure how to pull the current environmental variables into my perl
> program. I tried the following:
>
> $user=%ENV(REMOTE_USER);
> $host=%ENV(REMOTE_HOST);
>
> also tried,
> $user=$ENV(REMOTE_USER);
> $host=$ENV(REMOTE_HOST);
Almost - try $value = $hash{'key'};
To get one value from a hash, you need to use the '$' character.
You also need to use curly braces, rather than parentheses.
If you want to know what the names and values of the environment
variables are, you could try
foreach (keys %ENV) {
print "$_: $ENV{$_}<br>\n";
}
in your cgi script.
Scott
--
Scott I. Blanksteen
sib (at) worldnet (dot) att (dot) net
------------------------------
Date: Fri, 13 Jun 1997 07:36:30 -0500
From: Lisa Johnson <webmaster@pageeffects.com>
Subject: errors
Message-Id: <33A13ECE.7EC8@pageeffects.com>
Where does "HTTP/1.0 501 Not Supported" come from? I have clients with
order forms that return this error message when you try to place an
order--sometimes!! (sometimes they actually work!) I have not even been
able to find this error documented anywhere...we're using a "submit.plx"
script (returns email), with Perl ISAPI...HELP!!
--
Lisa Johnson
Page Effects
phone: (615)227-0162
On the Web: http://www.pageeffects.com
Visit our website for high-quality web services
that every business can afford!
------------------------------
Date: Fri, 13 Jun 1997 16:27:13 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: errors
Message-Id: <hvdsn5.bu3.ln@localhost>
Lisa Johnson (webmaster@pageeffects.com) wrote:
: Where does "HTTP/1.0 501 Not Supported" come from? I have clients with
^^^^
^^^^
I would guess that it comes from the HyperText Transfer Protocol (HTTP) ;-)
Perl is not the HTTP. So this is not the newsgroup to ask in.
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Fri, 13 Jun 1997 17:21:58 -0400
From: mark <mark@sierra-inc.com>
To: Yanco <jan@virtualf.com>
Subject: Re: exec and system calls
Message-Id: <33A1B9F6.40D0@sierra-inc.com>
Yanco wrote:
>
> I'm having problems with my headers on IIS
>
> I want to set a cookie, then go to a location.
> Unfortunately, I can either set the cookie, or, go to the location, and
> this method:
<snip>
I'm not sure what parameters are passed on @_, but here goes;
Could I possibly suggest using JavaScript? You could set your cookie by
generating a typical HTML document that just happens to jump to a new
page as soon as it's loaded. You could do something similar to the
following:
my $javascript = <<EOT;
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Here is the script:
function jump_to_my_page(){
self.location = "http://page.that.I/want.htm";
}
// -->
</SCRIPT>
</HEAD>
<BODY OnLoad="jump_to_my_page()">
</BODY>
</HTML>
EOT
if (/=/) {
print "Content-type: text/html\n";
print "Set-Cookie: $_;\n";
print $javascript;
}
Hope this helps!
Mark
------------------------------
Date: Fri, 13 Jun 1997 16:50:30 -0500
From: Bryan Hart <bryan@eai.com>
To: williamw@igs.REMOVE.net
Subject: Re: file test operators
Message-Id: <33A1C0A6.41C6@eai.com>
William Wueppelmann wrote:
>
> I was hoping someone could answer a question:
>
> I'm trying to get a list of subdirectories in $path by using
> open(SRC,"$path");
> @list = grep(-d, readdir(SRC));
>
> There are several subdirectories in $path, but @list only contains . and
> ..
>
> Is there something I'm doing wrong? It is just because its Friday and
> I'm missing something really obvious?
>
> Any help would be appreciated
Running your script as listed above I get nothing, but if I use:
opendir(SRC,"$path");
instead of 'open(SRC,"$path");' I get the desired result, including the
. and .. directories.
>
> --
> William Wueppelmann
> ---------------------
> It is pitch black. You are likely to be eaten by a grue.
> >
"Want some rye? 'Course you do!"
--
-------------------------------
| Bryan Hart
| Network Products Engineer
| Engineering Animation Inc.
| Phone: (515) 296-5979
| Fax: (515) 296-7025
| Email: bryan@eai.com
| Web: http://www.eai.com/
-------------------------------
"A conclusion is simply the place where you got tired of thinking"
------------------------------
Date: 13 Jun 1997 18:11:33 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: file test operators
Message-Id: <5ns2gl$8c5@fridge-nf0.shore.net>
William Wueppelmann (williamw@host.igs.net) wrote:
: Is there something I'm doing wrong? It is just because its Friday and
: I'm missing something really obvious?
find2perl /path -type d -print
???
--
Nathan V. Patwardhan
nvp@shore.net
------------------------------
Date: Fri, 13 Jun 1997 12:30:59 GMT
From: Matthew Hopkins
Subject: flock and SCO
Message-Id: <866205059.11243.0.nnrp-2.c1c3590b@news.demon.co.uk>
Greetings to the gods....
I am trying to use flock in my perl script on SCO OS5 to place an
exclusive lock on a file without any success. Is this possible? If not
how else can I do it? (If it is possible then how?).
The error I am getting is:
"The flock() function is unimplemented at blah.pl line 33"
(This is the same error if I try lockf)
Thanks in advance,
Matt Hopkins
------------------------------
Date: Sat, 14 Jun 1997 00:17:16 GMT
From: Jim Buttafuoco <root@192.255.255.255>
Subject: Re: FYI: running interactive ftp within perl script
Message-Id: <5nsnuc$5ke@gateway.buttafuoco.net>
look at Net::FTP module at your nearest CPAN
Eric Cegielski <csec@eiu.edu> wrote:
: I was looking for a way to get around the statement on
: page 162 of 'Programming Perl' that says "You may not
: have an open command that pipes both in and out...".
: I needed some code to run an interactive ftp session from
: within a perl script and I wanted to be able to both read
: from and write to an ftp session. I did not have an example
: of how to "....build one using the pipe and fork commands"
: (the rest of the statement mentioned above). I found the
: ftplib.pl script but our installation does not use perl5 yet,
: so I used the following "trick" (under UNIX):
: open( FTP,"/bin/tail -f $cmd_file | /bin/ftp -vn |")
: I read output from the FTP filehandle and send input to ftp
: by appending to $cmd_file. I am not sure yet how to
: "properly" close everything out but am working on it. I
: suppose one could use this to run other interactive
: commands (telnet, csh?, ...) from within perl. Does anyone
: have an example of how to "....build one using the pipe
: and fork commands"?
: -Eric Cegielski
: csec@eiu.edu
: Technical Support
: Eastern Illinois University
------------------------------
Date: Sat, 14 Jun 1997 03:10:48 -0700
From: Mickey <ez045864@mailbox.ucdavis.edu>
Subject: getting username and password
Message-Id: <Pine.GSO.3.95.970614030520.17409A-100000@boris.ucdavis.edu>
I am trying to read in usernames and passwords from a dummy passwd file.
Using a while loop, I can get each passwd entry into a variable. Is there
some easy way to extract just the username and password.
My code so far:
while($entry = <PASSWD>){
($user,$pass)=split(":", $entry) #This didn't work
<Rest of routine>
Thanks.
------------------------------
Date: Fri, 13 Jun 1997 11:29:46 -0400
From: Paul Ma <pma@sympatico.ca>
Subject: Help on two-way communication via sockets
Message-Id: <33A1676A.2459@sympatico.ca>
Hi, there:
I have a problem to try the two-way communication
between a client and socket. Basically, I want to
the client says "Hello, my server" to the server,
and then waits for the server's response. I saw
that the server did receive the message from the
client. Then, the client was terminated with the following
error message: "modification of a read-only value
attempted at /local/bin/perl5/FileHandle.pm at line 222".
I can not figure out what is wrong with my codes.
I am running on the Solaris.
The following codes are what I am using (just slightly
modified from the 2nd camel book).
Any suggestions are very appreciated!
(1) Client
#!/usr/bin/perl -w
require 5.003;
use strict;
use Socket;
use FileHandle;
my ($remote,$port, $iaddr, $paddr, $proto, $line);
$remote = shift || 'localhost';
$port = shift || 2345; # connect to the perl server
if ($port =~ /\D/) { $port = getservbyname($port, 'tcp') }
die "No port" unless $port;
$iaddr = inet_aton($remote) || die "no host: $remote";
$paddr = sockaddr_in($port, $iaddr);
$proto = getprotobyname('tcp');
socket(SERVER, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
connect(SERVER, $paddr) || die "connect: $!";
# Two-way communication
print SERVER "Hello, my server \n";
SERVER->AUTOFLUSH(1);
while ($line = <SERVER>) {
print $line;
}
close (SERVER) || die "close: $!";
exit;
(2) Server.pl
#!/usr/bin/perl -Tw
require 5.003;
use strict;
BEGIN { $ENV{PATH} = '/usr/ucb:/bin' }
use Socket;
use Carp;
use FileHandle;
sub spawn; # forward declaration
sub logmsg { print "$0 $$: @_ at ", scalar localtime, "\n" }
my $port = shift || 2345;
my $proto = getprotobyname('tcp');
socket(SERVER, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, 1) || die "setsockopt: $!";
bind(SERVER, sockaddr_in($port, INADDR_ANY)) || die "bind: $!";
listen(SERVER,5) || die "listen: $!";
logmsg "server started on port $port";
my $waitedpid = 0;
my $paddr;
sub REAPER {
$SIG{CHLD} = \&REAPER; # loathe sysV
$waitedpid = wait;
logmsg "reaped $waitedpid" . ($? ? " with exit $?" : '');
}
$SIG{CHLD} = \&REAPER;
for ( $waitedpid = 0;
($paddr = accept(CLIENT,SERVER)) || $waitedpid;
$waitedpid = 0, close CLIENT)
{
next if $waitedpid;
my($port,$iaddr) = sockaddr_in($paddr);
my $name = gethostbyaddr($iaddr,AF_INET);
logmsg "connection from $name [",
inet_ntoa($iaddr), "] at port $port";
# Two-way communication
my($in) = <CLIENT>;
print $in;
spawn sub {
print "Hello there, $name, it's now ", scalar localtime, "\n";
#exec '/usr/games/fortune'
# or confess "can't exec fortune: $!";
};
}
sub spawn {
my $coderef = shift;
unless (@_ == 0 && $coderef && ref($coderef) eq 'CODE') {
confess "usage: spawn CODEREF";
}
my $pid;
if (!defined($pid = fork)) {
logmsg "cannot fork: $!";
return;
} elsif ($pid) {
logmsg "begat $pid";
return; # i'm the parent
}
# else i'm the child -- go spawn
open(STDIN, "<&CLIENT") || die "can't dup client to stdin";
open(STDOUT, ">&CLIENT") || die "can't dup client to stdout";
## open(STDERR, ">&STDOUT") || die "can't dup
stdout to stderr";
$| = 1;
exit &$coderef();
}
--
Paul X. Ma
Media Linx Interactive Ltd.
20 Richmond Street, Suite 600,
Toronto, Ontario,
Canada M5C 3B5
Email: pma@sympatico.ca
mab@cs.uwindsor.ca
Tel: (416) 369-6772 (Office)
Fax: (614) 350-1516
Web: www1.sympatico.ca/
www.cs.uwindsor.ca/users/m/mab/
------------------------------
Date: 13 Jun 97 08:11:17 GMT
From: "Fredrik Lindberg" <flg@vhojd.skovde.se>
Subject: Re: help with regexps....
Message-Id: <01bc77d1$5f00f620$e20f10c2@odens.di.vhojd.skovde.se>
Rob Walker <rob@cisco.com> wrote in article
<v00oh9b8ilw.fsf@sj-fte45-sun.cisco.com>...
>
> This works well, except for a few situations. I find that I have some
> lines like:
>
> "Desktop Routers..." MENU
/usr/local/lib/openwin-menus/openwin-menu-celab-dt
> "FTE Routers..." MENU /usr/local/lib/openwin-menus/openwin-menu-celab-fte
> where the separator between MENU and the bit before it are <TAB>s.
>
> My current procedure turns this into:
>
> + "Desktop Routers..."openwin-menu-celab-dt
> + "FTE Routers..."openwin-menu-celab-fte
>
Maybe this could help? I
#!/usr/bin/perl -w
#
# Make a list of items
@str =
(
'"Programs" MENU /lib/openwin-menus/openwin-menu-programs',
'"Text menu" MENU /lib/openwin-menus/openwin-menu',
'" menu again" MENU /lib/openwin-menus/openwin-menu'
);
foreach $str (@str) {
# Notice that you can use any delimiters you want with s//, tr//
and m//
# Here I use | instead of /.
$str =~ s|(\".*?\") # Capture string inside quotes
\s+menu # Match menu directive including
whitespace
\s+.*/ # Match pathname up to last /)
(\S+) # Capture last nonwhitespace item)
|$1 popup $2|xi; # Build new string of the components
print "\$str = + $str\n";
}
__END__
Hope this helps!
/Fredrik
------------------------------
Date: Fri, 13 Jun 1997 08:33:27 +0200
From: Luka Crnkovic <lcrnkovi@sw.seisy.abb.se>
Subject: help with script needed
Message-Id: <33A0E9B7.285@sw.seisy.abb.se>
Hello,
I have a huge directory structure which I
would like to copy to a different location and
in the process add the extension ".frm" to
every file.
How would a perl script look that did it (recursive)?
//Luka
------------------------------
Date: Fri, 13 Jun 1997 08:39:22 +0200
From: Luka Crnkovic <lcrnkovi@sw.seisy.abb.se>
Subject: Help with script needed
Message-Id: <33A0EB1A.1C8A@sw.seisy.abb.se>
Hello,
I have a large directory structure that I wish to
move to another location and add an ".fm" file extension
to every file.
How would such an recursive script look in perl?
Any help appriciated.
//Luka
------------------------------
Date: 13 Jun 97 11:51:30 GMT
From: "Fredrik Lindberg" <flg@vhojd.skovde.se>
Subject: Re: help with script needed
Message-Id: <01bc77f0$22d0d8e0$e20f10c2@odens.di.vhojd.skovde.se>
Luka Crnkovic <lcrnkovi@sw.seisy.abb.se> wrote in article
> I have a huge directory structure which I
> would like to copy to a different location and
> in the process add the extension ".frm" to
> every file.
>
> How would a perl script look that did it (recursive)?
I would use "cp" together with the find2perl tool for this task. For
example
given the command
find2perl . -type f -exec echo {} {}.frm \; > copy
I'll get a script looking like this (slightly edited by me to shorten it a
bit):
#!/usr/bin/perl
eval 'exec perl -S $0 ${1+"$@"}' if $running_under_some_shell;
require "find.pl";
# Traverse desired filesystems
&find('.');
exit;
sub wanted {
(($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
-f _ && &exec(0, 'echo','{}','{}.frm');
}
sub exec {
local($ok, @cmd) = @_;
foreach $word (@cmd) { $word =~ s#{}#$name#g; }
if ($ok) {
local($old) = select(STDOUT); $| = 1;
print "@cmd";
select($old);
return 0 unless <STDIN> =~ /^y/;
}
chdir $cwd; # sigh
system @cmd;
chdir $dir;
return !$?;
}
__END__
As you noticed I first generated a script that simply "echos" the names to
the screen
so I can first test it and make sure it will act as I want. There are lots
of things here
that are not needed so some tweaking wont hurt.
Ok, after some patches and things I came up with this script
#!/usr/bin/perl -w
require "find.pl";
$src = shift; # get arguments
$dst = shift; #
die("Usage: copy src dst\n") if ($dst eq "" or $src eq "");
# Copy with the help of cp. I could have done it myself with the
# wanted() and find() functions, but this is easier.
system("cp -r $src $dst");
# Traverse destination and rename files
&find($dst);
exit;
# function wanted - Called from find
sub wanted {
lstat($_) && -f _ &&
system("mv $cwd/$name $cwd/$name.frm");
}
__END__
Hope this helps!
/Fredrik
------------------------------
Date: 13 Jun 1997 09:51:42 GMT
From: etltsln@etlxd30.ericsson.se ( Thomas Lachlan XMS x4206 )
Subject: Re: Help: SQL Server & perl
Message-Id: <5nr57e$r0c@newstoo.ericsson.se>
Shabbir H. Unwala (shabbir@xilinx.com) wrote:
: Is there any way to connect to a MS SQL Server Database using
: Perl? Is it thru ODBC? If so will I be able to generate SQL
: statements to send and retrieve data?
: thanks,
: shu
Yes there is a way, yes you would use ODBC and yes you can
send sql to the DBMS.
Regds Tam.
------------------------------
Date: Sat, 14 Jun 1997 00:35:10 +0200
From: Jonas Thvrnvall <labah@algonet.se>
Subject: How do i convert a (float) to (integer) ?
Message-Id: <33A1CB1E.5F32@algonet.se>
Hello!
A silly question maybe, but however how do i convert $random, it's a
floating point to an integer?
Jonas T
------------------------------
Date: Fri, 13 Jun 1997 15:47:56 -0500
From: Chris Price <cgprice@austin.ibm.com>
To: "Jonas Thvrnvall" <labah@algonet.se>
Subject: Re: How do i convert a (float) to (integer) ?
Message-Id: <33A1B1FC.167E@austin.ibm.com>
Jonas Thvrnvall wrote:
>
> Hello!
>
> A silly question maybe, but however how do i convert $random, it's a
> floating point to an integer?
>
> Jonas T
There may be a better way, but this will truncate the float, resulting
in an integer rounded DOWN from the original value.
If your original float is called $number:
$decimal = index($number, '.');
$number = substr($number, 0, $decimal);
if you want it to round it according to what the decimal part is, you'll
have to use some if statements.
Unless, of course, there is some built in perl function that I don't
know about.
Hope that helps,
Chris
------------------------------
Date: Thu, 12 Jun 1997 20:46:07 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: How do i convert a (float) to (integer) ?
Message-Id: <33A0A65F.388322B9@gpu.srv.ualberta.ca>
Jonas Thvrnvall wrote:
>
> Hello!
>
> A silly question maybe, but however how do i convert $random, it's a
> floating point to an integer?
some kind of function that turns a float into
an int(eger)? beats me
did you try the FAQ's and copious free documentation like
the perlfunc manpage. If none of that turns
up anything, you are welcome to use the following:
sub my_int ($) {
my $float=shift;
my $integer=0;
if ($float>0) {
$integer++ while --$float>0;
} else {
$integer-- while ++$float<0;
}
return $integer;
}
it may not be extremely robust, but it makes up for it
in sheer lack of speed!
and you might just want to call it int() to save typing
three extra characters everytime you called it...as in:
$new_int_from_a_floating_point_number=int($float);
:-)
regards
andrew
------------------------------
Date: 13 Jun 1997 18:05:18 GMT
From: lvirden@cas.org
Subject: How to change code using deprecated features?
Message-Id: <5ns24u$8vj$1@cas.org>
A program I am using generates the warning message:
Use of $* is deprecated at file.pl line 1317.
Sure enough, at line 1317 I see the line
$* = 1; # Turn on multiline searches
What is the equivalent action to perform under Perl 5.004 for this
capability?
--
Larry W. Virden INET: lvirden@cas.org
<URL:http://www.teraform.com/%7Elvirden/> <*> O- "We are all Kosh."
Unless explicitly stated to the contrary, nothing in this posting should
be construed as representing my employer's opinions.
------------------------------
Date: Fri, 13 Jun 1997 16:35:56 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: How to change code using deprecated features?
Message-Id: <sfesn5.bu3.ln@localhost>
lvirden@cas.org wrote:
: A program I am using generates the warning message:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Perl warning messages are documented in the *perldiag* man page
that comes with the perl distribution.
: Use of $* is deprecated at file.pl line 1317.
: Sure enough, at line 1317 I see the line
: $* = 1; # Turn on multiline searches
: What is the equivalent action to perform under Perl 5.004 for this
: capability?
Sure enough, at line 2160 in the perldiag man page, it tells you
how to do it with modern Perl... ;-)
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Mon, 16 Jun 1997 21:14:17 GMT
From: faust@wwa.com (Faust Gertz)
Subject: Re: justa question...
Message-Id: <33a7a002.4195501@news.wwa.com>
Your subject line isn't very informative and my guess is you have not
read the comp.lang.perl.misc FAQ.
On Mon, 16 Jun 1997 13:46:03 GMT, "NightHawk" <heron@web-access.net>
wrote:
>Will this bit of code utilize "GET" Methods?
Do you know the difference between the POST and GET methods? If not,
you need to read the FAQ for comp.infosystems.www.authoring.cgi and
ask that kind of question there.
>It looks like it could but, when I changed the
>Method on the HTML form to "GET." It didn't work.
This bit of information is not very informative. What didn't work and
what error message was received? What makes you think this a perl
problem and not a lack of understanding of CGI?
>And if this ISN'T the beginning of a "GET" Perl
>program, I would appreciate it if you would show me
>where one might be.
Why not write something which will handle both methods?
The following is pretty close to a textbook example of what you
probably want for getting the input and splitting the name-value
pairs.
if ($ENV{'REQUEST_METHOD'} eq "GET") {
@name_value_pairs = split (/&/, $ENV{'QUERY_STRING'});
} elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
read (STDIN, $query_string, $ENV{'CONTENT_LENGTH'});
@name_value_pairs = split (/&/, $query_string);
} else {
&return_error (500, "Server Error", "Server uses
unsupported method");
}
Of course, you will need a &return_error subroutine or something to
handle the possibility of a method being passed other than GET or
POST.
So I would replace the
># Get the input
>read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>
># Split the name-value pairs
>@pairs = split(/&/, $buffer);
from your code with something like what I provided above.
>foreach $pair (@pairs) {
> ($name, $value) = split(/=/, $pair);
> $value =~ tr/+/ /;
> $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>
> # Stop people from using subshells to execute commands
> $value =~ s/~!/ ~!/g;
Not exactly how I would do it (especially the meta-character
stripping), but it looks like it could work. I have seen scripts
which simply strip the meta-characters, but I would probably alert the
user that certain characters can't be used with something like the
following:
if ($DATA{'Name'}=~ /[;><&\*`\|]/) {
&return_error (500,'CGI Program Alert', "Value supplied for
$DATA{'Name'} contains suspicious meta-characters. Please use your
browsers' <CITE>back</CITE> function to return to the <A
HREF=\"$ENV{'HTTP_REFERER'}\">form</A> and try again.");
where the &return_error subroutine is something like:
sub return_error {
local ($status, $keyword, $message) = @_;
print "Content-type: text/html \n";
print "Status: ", $status, " ", $keyword, "\n\n";
print <<End_of_Error;
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">
<!--Automatically generated CGI Error report-->
<HTML>
<HEAD>
<TITLE>CGI Program - Unexpected Error</TITLE>
<LINK HREF="mailto:heron@web-access.net" REV=made>
<META NAME="Author" CONTENT="heron@web-access.net">
<META NAME="description" CONTENT="Automatically generated CGI
Error report">
</HEAD>
<BODY>
<H1 ALIGN=center><STRONG>$keyword</STRONG></H1>
<HR>
<P ALIGN=left>$message</P>
<HR>
<DIV align=center>Please contact <A
HREF="heron@web-access.net">heron@web-access.net</A> for more
information.</DIV>
</BODY>
</HTML>
End_of_Error
exit(1);
}
> # Uncomment for debugging purposes
> # print "Setting $name to $value<P>";
This is fine if you are running it from the shell, but this will give
you an error if you try it from your browser, unless you put a header
such as
print "Content-type: text/html \n\n";
before your list of values. It was the '<P>' which lead me to suspect
you were planing on running it from the browser.
> $FORM{$name} = $value;
>}
Ya, sure.
I hope this was at least of some assistance.
Streben nach Wahrheit
Faust Gertz
Philosopher at Large
"There are no honorable bargains involving the exchange of qualitative
merchandize like souls for quantitative merchandize like time or
money." - William S. Burroughs, `Words of Advice for Young People'
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 617
*************************************