[19734] in Perl-Users-Digest
Perl-Users Digest, Issue: 1929 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 14 21:06:46 2001
Date: Sun, 14 Oct 2001 18:05:08 -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: <1003107907-v10-i1929@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 14 Oct 2001 Volume: 10 Number: 1929
Today's topics:
Change Last Modified for all files in a directory <whataman@home.com>
Check Syntax <gclark@wavetel.com>
Re: filehandle : localized typeglob - local $_ (F. Xavier Noria)
Re: filehandle : localized typeglob - local $_ (Martien Verbruggen)
Re: filehandle : localized typeglob - local $_ <bart.lateur@skynet.be>
Re: FTP mirror script (Martien Verbruggen)
Re: How to make a script put itself into background? <goldbb2@earthlink.net>
Re: Perl and Win32 <tim@vegeta.ath.cx>
Re: PERL freelance programmer availeable <tim@vegeta.ath.cx>
redhat 5.6.1 install <silverrouge@hotmail.com>
Re: Setting cookies <matthew.garrish@sympatico.ca>
Simple Client Server communication! (Michael Herzog)
Re: Specifying a range of values (Logan Shaw)
Re: Stop Transversal of a Directory with Tar and Unzip <goldbb2@earthlink.net>
Using Split <keysd@cs.pdx.edu>
Re: Using Split (Mark Taylor)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 14 Oct 2001 23:50:55 GMT
From: "What A Man !" <whataman@home.com>
Subject: Change Last Modified for all files in a directory
Message-Id: <3BCA24F3.61FCA217@home.com>
My script below does not change the last modified date. The error
message says there is no such file. What am I doing wrong?
# Change last mod date for all files in "test" directory
chdir "test";
opendir THISDIR, "." or die "Can't Open Directory: $!";
@files = grep !/^\.\.?$/, readdir THISDIR;
foreach $file(@files) {
$now=time;
utime $now, $now, @files;
};
die "Cannot change utime: $!";
closedir THISDIR;
Regards,
--Dennis
------------------------------
Date: Sun, 14 Oct 2001 23:05:43 GMT
From: "Geoff Clark" <gclark@wavetel.com>
Subject: Check Syntax
Message-Id: <bToy7.501816$Lw3.30476548@news2.aus1.giganews.com>
Could someone please check my syntax when they get a moment. Thank you,
Geoff Clark
#!'C:\Perl\bin\Perl.exe'
use strict;
use vars qw($session $error $response $host $addr $filename $ip $UnitName
$bestau);
use Net::SNMP;
foreach $host (1 .. 10) {
my $addr = "10.1.66.$host";
($session, $error) = Net::SNMP->session(
-hostname => $addr,
-community => 'public',
-timeout => '2',
-retries => '1'
);
if (!defined($session)) {
printf("ERROR: %s.\n", $error);
next;
}
my $ip = '1.3.6.1.4.1.710.3.3.11.5.0';
my $UnitName = '1.3.6.1.4.1.710.3.3.10.3.0';
my $bestau = '1.3.6.1.4.1.710.3.3.6.23.1.0';
$response = $session->get_request($ip, $UnitName , $bestau);
if (!defined($response)) {
printf("ERROR: %s.\n", $session->error());
$session->close();
next;
}
printf("IP Address = %s, Unit Name = %s, Best AU Support = %s\n",
$response->{$ip},
$response->{$UnitName},
$response->{$bestau}
);
while ($filename = <*.secret>) {
open (WORDLIST, $filename) || die "can't open $filename: $!",
while ($ip = <WORDLIST>);
chomp ($ip);
$UnitName = <WORDLIST>;
chomp ($UnitName);
$bestau = <WORDLIST>;
chomp ($bestau);
write;
}
close (WORDLIST);
$session->close();
}
format STDOUT =
@<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<<<<<<<<<<@<<<<<<<<<<
$ip, $UnitName, $bestau
.
format STDOUT_TOP =
Page @<<
$%
WaveTel Network Operations - Best AU Support
0 = Disabled 1 = Enabled
IP Address Unit Name Best Au Support
============== ======================== ===============
.
exit 0;
------------------------------
Date: 14 Oct 2001 21:54:57 GMT
From: fxn@retemail.es (F. Xavier Noria)
Subject: Re: filehandle : localized typeglob - local $_
Message-Id: <9qd1jh$2gjh66@news2s.iddeo2.es>
On Sun, 14 Oct 2001 22:56:53 +0200, peter pilsl <pilsl_@goldfisch.at> wrote:
: sub rec
: {
: my $name=shift;
: local *FH;
: open(FH,'< $name) or die 'shit';
: while (<FH>)
: {
: ...
: rec($1) if $line=~/^INSERT\((.*)\)$/;
: ...
: }
: close FH;
: }
: perldoc -q filehandle reveals the faq 'How can I make filehandles local to
: a subroutine' and states an example with a line 'local $_' and the comment
: that this is a very important line. Unfortunately there is no further
: explanation why this line is important and in the following examples there
: is no such line ...
:
: Do I need the line and if - why ?
You know that $_ is a global variable. That `local $_' is there
because the programmer of findme() kindly does not want to change the
value of $_ in the code that uses that routine.
Particularly, though a bit further, in your listing, the while loop
modifies $_ no matter how deep in the recursion we are, so if we'd
want to do something with $_ in the execution of rec() after its very
call to rec(), we'd need to protect the value of $_ in each stage
localizing it.
-- fxn
------------------------------
Date: Sun, 14 Oct 2001 23:17:13 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: filehandle : localized typeglob - local $_
Message-Id: <slrn9sk77p.l88.mgjv@verbruggen.comdyn.com.au>
On Sun, 14 Oct 2001 22:56:53 +0200,
peter pilsl <pilsl_@goldfisch.at> wrote:
>
> a recursive subroutine needs to open a file and keep it opened while it
> calls itself again and opens the next file ...
> perldoc -q filehandle reveals the faq 'How can I make filehandles local to
> a subroutine' and states an example with a line 'local $_' and the comment
> that this is a very important line. Unfortunately there is no further
> explanation why this line is important and in the following examples there
> is no such line ...
If you use $_ anywhere in your subroutine, and you do not
want to clobber the global value of $_, then you should make it local.
while(<FH>) loops implicitly use $_, and don't localise it (for loops
do localise it, however). Especially in recursive calls, this can be
important. If you want to use $_ before and after the call that
recurses, and you expect it to be the same, you better use local().
Maybe an example:
#!/usr/local/bin/perl -wl
use strict;
sub recurse
{
my $lvl = shift;
$_ = "recurse: $lvl";
recurse($lvl + 1) if $lvl < 3;
print;
}
sub recurse_local
{
my $lvl = shift;
local $_;
$_ = "recurse_local: $lvl";
recurse_local($lvl + 1) if $lvl < 3;
print;
}
$_ = "start";
recurse(0);
$_ = "start";
recurse_local(0);
OUTPUT:
recurse: 3
recurse: 3
recurse: 3
recurse: 3
recurse_local: 3
recurse_local: 2
recurse_local: 1
recurse_local: 0
> Do I need the line and if - why ?
That depends on what you want to do :). In most cases, I'd say you
need it.
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | Curiouser and curiouser, said Alice.
NSW, Australia |
------------------------------
Date: Mon, 15 Oct 2001 00:58:07 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: filehandle : localized typeglob - local $_
Message-Id: <6uckstchgllk5g2hrptnmegb3i1il36ijq@4ax.com>
peter pilsl wrote:
>perldoc -q filehandle reveals the faq 'How can I make filehandles local to
>a subroutine' and states an example with a line 'local $_' and the comment
>that this is a very important line. Unfortunately there is no further
>explanation why this line is important and in the following examples there
>is no such line ...
>
>Do I need the line and if - why ?
It has nothing to do with localized filehandles. It has to do with the
fact that, in contrast with foreach(), while(<FH>) *clobbers $_*,
without any protection, and while it doesn't even look that way. So if
your outer code doesn't rely on $_ being unaltered, you may discard it.
However, localizing global variables whenever the intention to globally
change their value is not there, is basically a very good idea.
--
Bart.
------------------------------
Date: Sun, 14 Oct 2001 23:48:15 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: FTP mirror script
Message-Id: <slrn9sk91v.l88.mgjv@verbruggen.comdyn.com.au>
On Thu, 11 Oct 2001 23:10:48 +0200,
ANDERS FLODERUS <anders.floderus@swipnet.se> wrote:
> I have not done very much Perl programming and none
> for communication over the net.
> Now I have made a mirror script but before I try it, I wonder
> if somebody can check to see if it ought to work, I am afraid
> to do something that will anger my ISP.
> ( I found a mirror.pl script on the web but it was 91 KB.
> I think that is to much.)
I recently started doing this myself, because I wasn't aware that
mirror.pl could be used to update a remote directory with a local
directory as a source. I spent half a day on it. As soon as I realised
(by reading the documentation a bit more thorougly) that mirror.pl
does indeed work in both directions, I canned my own stuff. mirror.pl
is now in place as part of a production cycle.
What I'm trying to say is that you should probably reconsider using
mirror.pl. While there are things about it I don't like, it has been
thoroughly debugged, and is in very widespread use.
> ( Of course, if somebody is interested, it is all right to use it.)
Thanks. It is always appreciated when someone contributes :)
> ######################################################
> # mirror.pl
> use strict;
> use Net::FTP;
> my $ftp;
>
> ################################################
> ## supply your own parameters
> my $host = 'myHost'; # host
> my $ldir = 'C:\\myLdir'; # local directory
> my $rdir = 'myRdir'; # remote directory
> my $user = 'myUser';# user name
> my $passw = 'myPassw';# password
> ##
> #################################################
I'd consider making all of the above command line parameters. Maybe
the Getopt:Long or Getopt::Std modules can make that easier. I'd also
consider using the .netrc file to get a password, instead of putting
it either in this source file, or accepting it as a command line
parameter. The Net::Netrc module may be of help.
Of course, on Windows systems .netrc may be less useful.
> $ftp = Net::FTP->new( $host ) or
> die "Can not connect: $@\n";
> $ftp->login( $user, $passw ) or
> die 'Can not login: ', $ftp->message;
> $ftp->cwd( $rdir ); # set working directory
You should also check this for errors.
> &update( 'a', '.htm' );
> &update( 'b', '.jpg' );
> &update( 'b', '.gif' );
Don't use the &. It isn't necessary anymore, and it can actually
change the way a subroutine is called. See the perlsub documentation
for more information.
> $ftp->quit;
> exit 0;
The 0 isn't needed.
> sub update( ) {
sub update
{
Done't give update an empty prototype (with the parentheses),
especially since you actually are expecting arguments. The prototype
is too late here anyway, because you've already sone all your calls,
but in Perl, you should only prototype if you have very very good
reasons to do so. The perlsub documentation, again, tells you more
about this.
> if( $_[0] eq 'a' ) { $ftp->ascii; }
> else { $ftp->binary; }
>
> my $dev, my $ino, my $mode, my $nlink, my $uid;
> my $gid, my $rdev, my $size, my $atime, my $ltime;
> my $ctime, my $blksize, my $blocks;
Why do you declare all these things at the top, instead of where they
are needed? And are you sure you really need all of them as variables?
The return of a stat() can easily be kept in an array, without losing
too much meaning. If you like to have the names to refer to individual
elements of the stat structure, look into using the File::Stat module.
> my $file, my @lfiles, my $lfile, my $rtime;
And I would also declare these when used, instead of just at the top
here.
> opendir( DIRHANDLE, $ldir );
> @lfiles = readdir( DIRHANDLE );
> closedir( DIRHANDLE );
It would probably not be a bad idea to localise this directory handle,
with local(*DIRHANDLE).
> foreach $file ( @lfiles ) {
> if( $file !~ m/$_[1]/ ) { next; }
Hmmm.. I would probably not use $_[1] here. I'd assign it to a
parameter at the top of the subroutine...
my $ext = $_[1];
or something like that.
And I'd write the above as
next unless $file =~ /\Q$ext\E$/;
because you probably don't want to process files like
foo.html.is.ugly, or even foohtm.txt. The perlre documentation
explains the \Q\E pair and the $ anchor.
> $lfile = $ldir . '\\' . $file;
Instead of using a backwhack here, you could just use a forward slash.
Windows will accpet that perfectly fine, and it'll make your code more
portable. You could also use the File::Spec module if you want to be
really portable.
> ( $dev, $ino, $mode, $nlink, $uid,
> $gid, $rdev, $size, $atime, $ltime,
> $ctime, $blksize, $blocks ) = stat( $lfile );
Again, I'd just keep it in a list, or use the File::Stat module.
> $rtime = $ftp->mdtm( $file ); # remote modification time
Not all servers do these things 'correctly'. I'm not entirely sure
that this response is guaranteed to return seconds since epoch (since
it doesn't actually appear in RFC 959). This was one of the things I
was having troubles with when I started writing my own stuff. How to
compare local and remote time stamps.
> if( $rtime ) {
> if( $ltime <= $rtime ) { next; }
> $ftp->delete( $file );
> }
> $ftp->put( $lfile, $file );
This is a bit confused. You delete the file if the remote server gave
you a $rtime, and if that $rtime is smaller than $ltime. If the remote
server gave you an $rtime which is larger, you go to the next file. If
there was no remote time, or if you have just deleted the remote file,
you put the local copy.
Why do you delete the remote file before putting it, if it's out of
date? Why not just overwrite it?
I'd probably rewrite that a bit to make the logic a bit easier to
follow. Or I'd at least put some comments in to help the reader
determine what is happening here.
Martien
--
Martien Verbruggen |
Interactive Media Division | Make it idiot proof and someone will
Commercial Dynamics Pty. Ltd. | make a better idiot.
NSW, Australia |
------------------------------
Date: Sun, 14 Oct 2001 18:43:50 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: How to make a script put itself into background?
Message-Id: <3BCA1525.895AAE0F@earthlink.net>
Tassilo von Parseval wrote:
>
> Ilya Martynov wrote:
>
> > And now
> >
> > use POSIX qw/SIGSTOP/;
> > kill SIGSTOP, $$;
>
> Ah, thanks a lot! I knew it would be POSIX if any. Works splendidly.
Just remember that you probably want to restore the terminal settings
just before you suspend yourself, and 'raw' them after you get
unsuspended.
if (ord($k) == KEY_SUB) {
ReadMode 'restore';
kill "SIGSTOP", $$;
ReadMode 'raw';
}
Oh, and you don't need to use POSIX to use SIGSTOP as the first argument
to kill... according to perldoc -f kill, you can pass a string which is
a signal name as the first argument.
--
"Just how stupid are you Kuno?"
"Verily, Tatewaki Kuno knows no limits."
------------------------------
Date: Mon, 15 Oct 2001 00:43:27 GMT
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: Perl and Win32
Message-Id: <slrn9skd4f.8s2.tim@vegeta.ath.cx>
Me parece que Carsten Menke <bootsy52@gmx.net> dijo:
> On Sun, 14 Oct 2001 00:15:03 +0200, Darlene Murphy wrote:
>
> > I am trying to get perl to run under WinME. I have done web sites on
> > unix systems with perl and they work fine.
> >
> > For WinMe I am using WinSite and ActiveState Perl. It dose not
> > recognize #!g:\perl\bin\perl. What should I use? Also how do we put
> > comments in our perl scripts.
> >
> I would say you can give up, I tried this also once, but I have read that
> windows is not able to process a shebang. And the funny thing on this?
>
> Well, this was not possible in Win98 and from your post I see that it is
> not possible until today :-)
It worked fine for me running both Python and perl CGIs on Win98. Did
you get a broken Win98? To clarify:
1. Neither Windows(95/98/NT) nor COMMAND.COM nor CMD.EXE process
the unix shebang line.
2. Apache (for win95/98/NT, BSD, linux, solaris) _does_ process
the shebang line.
3. M$ Personal Web Server did _not_ process the shebang line.
To the OP:
As Mr. Lateur stated in his post, I recommend IndigoPerl (which comes
with a pre-configured Apache web server and web-based maintenance
interface) if you want to get up and running with perl CGIs quick.
#!/sex/booze/drugs/perl
print <<END;
It's 10 o'clock.
Do you know where your perl binary is?
Tim
--
"This is your life...
and it's ending on minute at a time."
-- Jack, "Fight Club"
------------------------------
Date: Mon, 15 Oct 2001 00:18:50 GMT
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: PERL freelance programmer availeable
Message-Id: <slrn9skbme.8s2.tim@vegeta.ath.cx>
Me parece que Philip Newton <pne-news-20011014@newton.digitalspace.net> dijo:
> On 13 Oct 2001 19:03:11 -0700, merlyn@stonehenge.com (Randal L.
> Schwartz) wrote:
>
> > 7) Should I hire someone who has only a hotmail account? What, you
> > can't spring for the $20/month or so to get a real domain and hosting
> > service? How bad *is* your business at the moment.
>
> He's probably done most of his work for clients who keep insisting
> they're only 99 and 44/100 % satisfied and therefore don't need to pay
> him. So he's been doing a lot of work for free.
99.44%? Was the Ivory soap implication diliberate, or am I just
getting old? =)
> (Seriously, that clause just seems to leave WAAY too much wiggle room
> IMO.)
True.
> Cheers,
> Philip
Tim
--
Self Test for Paranoia:
You know you have it when you can't think of anything that's
your own fault.
------------------------------
Date: Sun, 14 Oct 2001 22:05:17 GMT
From: "The Waltons" <silverrouge@hotmail.com>
Subject: redhat 5.6.1 install
Message-Id: <x_ny7.2827$bE1.16622@news1.rdc1.nsw.optushome.com.au>
Hello,
Am no perl guru, am attempting to get rid of Redhats excuse for perl
and setup 5.6.1
Am coming up againt problems with:
Bundle::libnet
because of Net::Telnet
Any pointers?
Jed
------------------------------
Date: Sun, 14 Oct 2001 19:31:31 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Setting cookies
Message-Id: <Hbpy7.967$7Y4.381552@news20.bellglobal.com>
"Jeff Zucker" <jeff@vpservices.com> wrote in message
news:3BC9F70C.14BBBCBF@vpservices.com...
> If they
> bring rocks and want to discuss geology, we tell them there's a
> rock-hounds meeting next door, we're more interested in stuff we can
> sink our teeth into and we don't pay much attention when they protest
> "but I wanted to cook *food* in a stone fireplace so this *is* the right
> meeting to discuss minerals".
>
But what if they were making the fireplace out of rock-candy? Would you
shuffle them off to the mineralists to would then laugh them out of that
group?
This is all so deep... ; )
Matt
------------------------------
Date: 14 Oct 2001 15:07:45 -0700
From: m.herzog@hrsoftware.de (Michael Herzog)
Subject: Simple Client Server communication!
Message-Id: <b87fff5c.0110141407.315d0c87@posting.google.com>
Hi there,
I don't know how to build a bidirektional client! In the "Perl
Cookbook" I've seen how to do but it don't works. I've build a Simple
Client and a Simple Server. For now I wanna know how to change the
Client and Server Script to work as a bidirectional Client! I'm useing
a WindowsBox (Win32). Could anybody help me!
------------Client Script-----------
use IO::Socket;
my $sock = new IO::Socket::INET (
PeerAddr => 'localhost',
PeerPort => '23',
Proto => 'tcp',
Type => 'SOCK_DGRAM',
);
die "Could not create socket: $!\n" unless $sock;
print $sock "1";
my $new_sock = $sock->accept();
while (<$new_sock>) { print $_
}
my $new_sock = $sock->accept();
while (<$new_sock>) {
$interrupt = $_;
if ($interrupt eq '2') {
}
if ($interrupt ne '2') {
}
}
close($sock);
--------------END------------------
------------Server Script----------
use IO::Socket;
$flags = 0;
my $sock = new IO::Socket::INET (
LocalHost => 'localhost',
LocalPort => '23',
Proto => 'tcp',
Type => 'SOCK_DGRAM',
Listen => 1,
Reuse => 1,
);
die "Could not create socket: $! \n" unless $sock;
for ($con = 1; ; $con++) {
print "Waiting for Connection: $con ...\n";
my $new_sock = $sock->accept();
if (($child = fork()) == 0) {
while (<$new_sock>) {
$interrupt = $_;
if ($interrupt eq '1') {
while (<$new_sock>) { print $_
}
print "Client Choise 1";
}
if ($interrupt ne '1') {
print "Client Choise not eq to 1";
}
}
print "Client went away!\n";
close($sock);
exit;
}
}
------------END------------------
feel free to mail me!
THNX
Michael Herzog
------------------------------
Date: 14 Oct 2001 18:49:48 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Specifying a range of values
Message-Id: <9qd8as$61k$1@charity.cs.utexas.edu>
In article <keljstsr87pp64tgm19hom210hi41rv6gj@4ax.com>,
Philip Newton <nospam.newton@gmx.li> wrote:
>which I prefer personally. (Perl6 will let you do the 'maths' thing and
>go straight for
>
> if( $X < $score < $Y) { ... }
>
>.)
Say it ain't so!
How does it deal with the fact that that expression is ambiguous?
Since
$X < $score
is a subexpression with a true/false value and since that can be turned
into a numeric value (zero for false, one for true), then the value of
that subexpression can be compared to $Y.
That's no so bad if $X and $score and $Y are all numeric because you
can then decide based on whether certain kinds of type conversions need
to happen. But what if everything is a boolean value? What am I
supposed to make of the following code?
$a = (1 == 0);
$b = (1 == 1);
$c = (0 == 1);
$d = ($a == $b == $c);
This sets to $a to false, $b to true, and $c to false.
So should $d be true or false? If the two "==" operators combine to a
"test if all three of these numbers are equal" operator, then $d should
be set to false. But if "$a == $b" is evaluated by itself, then it
evaluates to false, and if that value is then compared to $c, the
comparison should have the value true (because false equals false), so
$d should be set to true.
The result is that
$d = ($a == $b == $c);
might have a different value than
$d = (($a == $b) == $c);
And that's just WRONG, in my opinion.
And yeah, you can come up with rules about what happens when (it only
happens if the values are numeric, and not if they're boolean, or it
only happens if you use an ordering operator instead of an equality
operator), but that makes things way too confusing.
- Logan
--
"In order to be prepared to hope in what does not deceive,
we must first lose hope in everything that deceives."
Georges Bernanos
------------------------------
Date: Sun, 14 Oct 2001 18:30:00 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Stop Transversal of a Directory with Tar and Unzip
Message-Id: <3BCA11E8.DBB7A61F@earthlink.net>
What A Man ! wrote:
>
> > Randal L. Schwartz wrote:
> > > {ahem} "correct" being used loosely?
> > > open STDERR, ">&STDOUT" ...
>
> Hmmm. I'm confused. According to perlsec...
> open(FOO, "< $arg"); # OK - read-only file
> open(FOO, "> $arg"); # Not OK - trying to write
> So, which of the above are correct?
Perlsec is talking about it being unsafe to write to a file whose name
is supplied by a user in an unsafe way. The statement I gave [re]opens,
in such a way that it is a copy of STDOUT ... note that STDOUT is *not*
a user supplied filename.
> > Benjamin Goldberg wrote:
>
> > > ### TEST the ZIP File first
> > > `unzip -qt $tmpfile`;
> > > if ($? == 0 ) {
> >
> > Why are you using backticks instead of system()? This should be:
> >
> > system("unzip", "-qt", $tmpfile);
>
> Ummm. Because I didn't know any better. :)
>
> > if( system("unzip", "-qt", $tmpfile) ) {
> > my ($sig, $ret) = ($?&255, $?>>8);
> > die "unzip -t died from signal $sig" if $sig;
> > die "unzip -t exited with code $ret" if $ret;
> > die "system failed: $!";
> }
>
> It works great up to here.
>
> > defined( my $pid = fork ) or die "Couldn't fork: $!";
> > if( $pid == 0 ) {
> > open(STDOUT, ">/dev/null") or close(STDOUT);
> > open(STDERR, ">&STDERR") or close(STDERR);
> > # for neither of the above do we really care if we could open
> > # /dev/null, since the only purpose of us doing so is to discard
> > # our output.
> > exec( "unzip", "-qqjnCL", $tmpfile,
> > "-x", "*.pl *readme* *.ht *.exe",
> > "-d", $tmpdir );
> > die "exec(unzip) failed: $!";
> > }
>
> Why does it only die here if something is wrong with $tmpfile.
It doesn't die *here* if something's wrong with $tmpfile, it dies up
above when we did unzip -qt $tempfile.
> Shouldn't it also die if it can't find $tmpdir, etc?
> For example, I tried a $tmpppdir that didn't exist, and it gave no
> error.
Well, it *did* give an error, but we didn't see it, since we're
redirecting both the output and error streams of unzip to /dev/null.
If you *want* to see the error messages, then don't do that.
In your original code, you'd had:
`unzip -qjnCL $tmpfile ..... -d $tmpdir 2>&1`;
The `` capture the stdout of the program, and the 2>&1 cause the error
stream to be merged with the output stream... and since the `` was in
void context [you weren't doing anything with the returned string] you
were just discarding the output.... so I wrote my code to do the same.
To make the error messages visible, remove the line from my code which
says:
open(STDERR, ">&STDERR") or close(STDERR);
[snip]
> Thanks for this script. Even though I may change to using the Perl
> modules later for unzipping, your examples and corrections have served
> me well in teaching me how to properly execute programs from the shell
> in Perl (and another lesson in proper syntax too). I take it that I
> can utilize the above unzip program example for other programs too,
> such as tar, wget, etc... with a few minor changes.
Yes. But keep in mind that you may want to change, or remove the lines
which (re)open STDERR and STDOUT [and maybe add one to (re)open STDIN].
For example, if, in the shell, you would usually run a program as:
myprog < inputfile.txt > outputfile.txt 2> errorfile.txt
Then your fork/exec part will probably look like:
defined( my $pid = fork ) or die "Couldn't fork: $!";
if( $pid == 0 ) {
open( STDIN , "<inputfile.txt" )
or die "Couldn't open inputfile.txt: $!";
open( STDOUT, ">+outputfile.txt" )
or die "Couldn't open outputfile.txt: $!";
open( STDERR, ">+errorfile.txt" )
or die "Couldn't open errorfile.txt: $!";
exec( "myprog" );
die "exec(myprog) failed: $!";
}
# the waitpid stuff of course would be almost exactly the same.
[snip]
> > > I needed Compress::Zlib and I can't compile on it on my present
> > > server.
> >
> > Can't you get it already compiled for that architecture?
>
> I hadn't thought of that. Is that the same as a binary? In a Google
> search of "Compress::Zlib compiled FreeBSD" I wasn't able to find one,
> but maybe I don't know what I'm looking for.
I would generally start with a search on CPAN, followed by contacting
the author to see if they know of anyone who has compiled it for your
architecture and who could send the compiled stuff to you.
--
"Just how stupid are you Kuno?"
"Verily, Tatewaki Kuno knows no limits."
------------------------------
Date: Sun, 14 Oct 2001 16:55:17 -0700
From: "Dustin Keys" <keysd@cs.pdx.edu>
Subject: Using Split
Message-Id: <tsk91klloqnl02@corp.supernews.com>
I am trying to pul the idle times for al the users currently on a system. I
am using the who -u command to generate this list and I am stuffing it into
a string variable. All I want is to create a list with each element being
one idle time. For example.
prasad pts/15 Oct 14 15:41 0:02 14123
(pdxproxy.jf.intel.com)
prasad pts/16 Oct 14 16:07 0:32 14371
(pdxproxy.jf.intel.com)
keysd pts/13 Oct 14 13:19 . 12283
(sirius.cs.pdx.edu)
prasad pts/4 Oct 14 16:38 . 14571
(pdxproxy.jf.intel.com)
keysd pts/14 Oct 14 14:32 0:20 12989
(dsl-209-162-200-134.easystreet.com)
^^^ This is the
coloum I want stored into a list like,
"0.02", "0.32", ".", ".". "0.20"
I have tried split using many different patters but have yet to make my
desired results. Any ideas?
Dustin Keys
keysd@cs.pdx.edu
------------------------------
Date: 14 Oct 2001 18:59:40 -0500
From: mtaylor@lrim.com (Mark Taylor)
Subject: Re: Using Split
Message-Id: <Xns913AC3D3FAD39maintainersetifaqorg@128.242.171.114>
[posted and mailed]
"Dustin Keys" <keysd@cs.pdx.edu> wrote in
<tsk91klloqnl02@corp.supernews.com>:
>I am trying to pul the idle times for al the users currently on a
>system. I am using the who -u command to generate this list and I am
>stuffing it into a string variable. All I want is to create a list with
>each element being one idle time. For example.
>
>prasad pts/15 Oct 14 15:41 0:02 14123
>(pdxproxy.jf.intel.com)
>prasad pts/16 Oct 14 16:07 0:32 14371
>(pdxproxy.jf.intel.com)
>keysd pts/13 Oct 14 13:19 . 12283
>(sirius.cs.pdx.edu)
>prasad pts/4 Oct 14 16:38 . 14571
>(pdxproxy.jf.intel.com)
>keysd pts/14 Oct 14 14:32 0:20 12989
>(dsl-209-162-200-134.easystreet.com)
> ^^^ This is the
>coloum I want stored into a list like,
>
>"0.02", "0.32", ".", ".". "0.20"
>
>I have tried split using many different patters but have yet to make my
>desired results. Any ideas?
>
>Dustin Keys
>keysd@cs.pdx.edu
>
>
>
Well there is always more than one way to do things in perl. The easiest
for you to start with would probably substitute the spaces with a single
character, |, for instance, then split on the |.
That should get you immediate results, and you can continue to find the
best way to suit yourself.
Mark
______________________________________________________________________________
Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net
------------------------------
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 1929
***************************************