[19183] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1378 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 25 18:05:39 2001

Date: Wed, 25 Jul 2001 15:05:13 -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: <996098713-v10-i1378@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 25 Jul 2001     Volume: 10 Number: 1378

Today's topics:
    Re: bitwise operations <kalinabears@hdc.com.au>
    Re: bitwise operations <chris_cobb@hp.com>
    Re: bitwise operations <mjcarman@home.com>
    Re: call a sub defined in a script from the command lin <pne-news-20010725@newton.digitalspace.net>
    Re: Directory Diff <swan@peak2peak.com>
    Re: emacs etags default in cperl mode <badarik@yahoo.com>
    Re: emacs etags default in cperl mode <badarik@yahoo.com>
        FAQ: How can I find the Julian Day? <faq@denver.pm.org>
    Re: FAQ: Why aren't my random numbers random? <krahnj@acm.org>
        File delete <Killiam@hotmail.com>
    Re: File delete <mbudash@sonic.net>
        Help: Perl and PL/SQL, which one is better? u518615722@spawnkill.ip-mobilphone.net
        Incomplete output from crontab email: running shell scr (tenpercenter)
    Re: Incomplete output from crontab email: running shell (John Gordon)
    Re: IO::Socket-Question (Konstantinos Agouros)
    Re: IO::Socket-Question (Konstantinos Agouros)
    Re: IP address incorrect by $ENV{'REMOTE_ADDR'} <pne-news-20010725@newton.digitalspace.net>
        Object Reuse with Net::FTP (Jeff Hill)
        Problem creating file <gsuberri@hotmail.com>
    Re: Problem creating file <cpryce@pryce.net>
        Read Directory  <blnukem@hotmail.com>
    Re: Read Directory  (remove the obvious)
    Re: Read Directory <ilya@martynov.org>
    Re: Read Directory (Craig Berry)
    Re: Read Directory <godzilla@stomp.stomp.tokyo>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 26 Jul 2001 05:31:28 +1000
From: "Sisyphus" <kalinabears@hdc.com.au>
Subject: Re: bitwise operations
Message-Id: <996125862.527398@clover.origin.net.au>


"Swanthog" <lhswartw@ichips.intel.com> wrote in message
news:9jmv30$hmp@news.or.intel.com...
> Greetings all,
>
> I have 4 variables each of which will be set to logic level 1 or 0. I then
> want to use those 4 variables to create a 4 bit vector and compare against
> the 16 possible combinations. I have managed to do this but I don't like
the
> solution.
>
> Is there a better way?
>
> Thanks,
> Larry S.
>
> # The 4 variables as described above. The test pattern is decimal 5.
> $var_0 = 1;
> $var_1 = 0;
> $var_2 = 1;
> $var_3 = 0;
>
> # The sixteen possible combinations to compare against.
> $b_0 = pack("b4", "0000");
> $b_1 = pack("b4", "0001");
> $b_2 = pack("b4", "0010");
> $b_3 = pack("b4", "0011");
> $b_4 = pack("b4", "0100");
> $b_5 = pack("b4", "0101");
> $b_6 = pack("b4", "0110");
> $b_7 = pack("b4", "0111");
> $b_8 = pack("b4", "1000");
> $b_9 = pack("b4", "1001");
> $b_a = pack("b4", "1010");
> $b_b = pack("b4", "1011");
> $b_c = pack("b4", "1100");
> $b_d = pack("b4", "1101");
> $b_e = pack("b4", "1110");
> $b_f = pack("b4", "1111");
>
> # Create a vector of 4 bits using the 4 variables
> vec( $status, 3, 1) = $var_0;
> vec( $status, 2, 1) = $var_1;
> vec( $status, 1, 1) = $var_2;
> vec( $status, 0, 1) = $var_3;
>
> # Do the comparison
> print "Bits in status: ";
> $status = unpack("b4", $status);
> if( $status == unpack("b4", $b_0)) {
>  print "0\n";
> } elsif( $status == unpack("b4", $b_1)) {
>  print "1\n";
> } elsif( $status == unpack("b4", $b_2)) {
>  print "2\n";
> } elsif( $status == unpack("b4", $b_3)) {
>  print "3\n";
> } elsif( $status == unpack("b4", $b_4)) {
>  print "4\n";
> } elsif( $status == unpack("b4", $b_5)) {
>  print "5\n";
> } elsif( $status == unpack("b4", $b_6)) {
>  print "6\n";
> } elsif( $status == unpack("b4", $b_7)) {
>  print "7\n";
> } elsif( $status == unpack("b4", $b_8)) {
>  print "8\n";
> } elsif( $status == unpack("b4", $b_9)) {
>  print "9\n";
> } elsif( $status == unpack("b4", $b_a)) {
>  print "a\n";
> } elsif( $status == unpack("b4", $b_b)) {
>  print "b\n";
> } elsif( $status == unpack("b4", $b_c)) {
>  print "c\n";
> } elsif( $status == unpack("b4", $b_d)) {
>  print "d\n";
> } elsif( $status == unpack("b4", $b_e)) {
>  print "e\n";
> } elsif( $status == unpack("b4", $b_f)) {
>  print "f\n";
> } else {
>  print "Fell through. Status is $status\n";
> }
>
>
>
>

my $vector = "0b".$var_0.$var_1.$var_2.$var_3;
my $match = sprintf ("%x", oct($vector));
print $match, "\n";

Cheers,
Rob




------------------------------

Date: Wed, 25 Jul 2001 14:04:05 -0700
From: Chris Cobb <chris_cobb@hp.com>
Subject: Re: bitwise operations
Message-Id: <3B5F3445.78F70603@hp.com>

Sisyphus wrote:
> 
> "Swanthog" <lhswartw@ichips.intel.com> wrote in message
> news:9jmv30$hmp@news.or.intel.com...
> > 
> > Is there a better way?
> >
> 
> my $vector = "0b".$var_0.$var_1.$var_2.$var_3;
> my $match = sprintf ("%x", oct($vector));
> print $match, "\n";
> 

And, for those poor souls who don't yet have Perl 5.6,
here is another approach.

Cheers,
Chris

my $var_0 = 1;
my $var_1 = 0;
my $var_2 = 1;
my $var_3 = 0;

my $hex = {};
map { $hex->{hex($_)} = $_ } ("0".."9","a".."f");

print "Bits in status: ";
print bits($hex,$var_0,$var_1,$var_2,$var_3), "\n";


sub bits {
  my($hex,@vars) = @_;

  my $vec = 0;
  for (0..$#vars) { $vec += $vars[$_] * 2**$_ }

  my $bits = ( defined $hex->{$vec} ? $hex->{$vec}
             : "Fell through (vec is $vec)" );

  return $bits;
}


------------------------------

Date: Wed, 25 Jul 2001 16:19:12 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: bitwise operations
Message-Id: <3B5F37D0.CBC07051@home.com>

Swanthog wrote:
> 
> I have 4 variables each of which will be set to logic level 1 or 0.
> I then want to use those 4 variables to create a 4 bit vector and
> compare against the 16 possible combinations. I have managed to do
> this but I don't like the solution.
> 
> Is there a better way?

It looks like all you're doing is converting four bits into a (hex)
number. If that's true, use bitshifts and bitwise-OR to create a number:

#!/usr/bin/perl -w
use strict;

# Normally I'd put variables named this way into an array, but 
# I'm guessing that in your case they're really four non-related
# things and should be four seperate variables.
my $var_0 = 1;
my $var_1 = 0;
my $var_2 = 1;
my $var_3 = 0;

my $status = 0;
foreach ($var_3, $var_2, $var_1, $var_0) {
    $status = $status << 1 | $_;
}

print unpack('b4', $status), "\n";
printf("status is %x\n", $status);
__END__

1010
status is 5

But perhaps there's something you're not telling us?

-mjc


------------------------------

Date: Wed, 25 Jul 2001 20:48:54 +0200
From: Philip Newton <pne-news-20010725@newton.digitalspace.net>
Subject: Re: call a sub defined in a script from the command line
Message-Id: <ug4ult8dora0jhl9c9cldf78ptnjum586j@4ax.com>

On Wed, 25 Jul 2001 12:42:12 +0100, Paul Johnston
<paul.johnston@dsvr.co.uk> wrote:

> You can take advantage of a useful, but rarely used feature of perl:

[snip example of symbolic references]

One reason why it's rarely used is probably because it makes it easier
for you to shoot yourself in the foot. Use real references instead.

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: Wed, 25 Jul 2001 21:23:05 GMT
From: "Ross" <swan@peak2peak.com>
Subject: Re: Directory Diff
Message-Id: <3b5f410b$1@news.peakpeak.com>

Nice tool.
Everything works ok except that the Differences sub-window is empty for version
1.2 and 1.4, probably since I need to compile filecmp.c but I don't have the necessary
includes.
--Ross



"Matt Christian" <mattc@visi.com> wrote in message news:87puaplx6v.fsf@powerhouse.boogie.cx...
Ross,

> I've done a backup on a UNIX directory
> to a temporary location and I'd like to find
> the files that have been changed from my
> current version of the directory. Has anyone
> written a utility to do this? What makes it a
> little tricky is that the directory has many sub-
> directories.

Yes, Paul Mackerras has written dirdiff which does
exactly what you want, it runs in X and requires TCL/TK.
The subdirectories shouldn't be a problem...

dirdiff CVSWeb (download the current/unstable version):
http://samba.org/cgi-bin/cvsweb/dirdiff/

dirdiff FTP site (download the stable version):
ftp://ftp.samba.org/pub/paulus/

Thanks,

Matt

--
Matt Christian - mattc@visi.com
http://www.visi.com/~mattc/
ftp://ftp.visi.com/users/mattc/
Learn to love and love to learn.




------------------------------

Date: Wed, 25 Jul 2001 13:54:09 -0700
From: Badari Kakumani <badarik@yahoo.com>
Subject: Re: emacs etags default in cperl mode
Message-Id: <3B5F31F1.59C55CF1@yahoo.com>

Ilya Zakharevich wrote:
> 
> [A complimentary Cc of this posting was sent to
> Badari Kakumani
> <badarik@yahoo.com>], who wrote in article <3B5E0259.E3348BC5@yahoo.com>:
> > i use emacs cperl mode for writing the perl code.
> > i am starting to use etags facility. when i search
> > for a tag using M-. (find-tag) command in emacs, the default
> > appears to be the word at which the cursor is
> > located. typical perl function calls we have
> > are of the form <package>::<function> and that is
> > selected as the default. but etags needs only <function>
> > to find the tag. so is there a way to influence
> > etags find-tag routine to ignore the <package>::
> > prefix in the word around cursor and select just <function>
> > as the default value to look for?
> 
> The function to extract the word for etags' default is customizable.
> CPerl has cperl-mode-hook.

but i am not
much of a lisp programmer and hence had trouble
even locating the exact routine that implements this
functionality ( in either etags.el or cperl.el files )
let alone customize it. so i was looking for any
other perl programmer who already customized this :)

thanks for the pointer anyways.

-badari


> 
> Enough said,
> Ilya


------------------------------

Date: Wed, 25 Jul 2001 13:54:57 -0700
From: Badari Kakumani <badarik@yahoo.com>
Subject: Re: emacs etags default in cperl mode
Message-Id: <3B5F3221.B96773F7@yahoo.com>

Ilya Zakharevich wrote:
> 
> [A complimentary Cc of this posting was sent to
> Badari Kakumani
> <badarik@yahoo.com>], who wrote in article <3B5E0259.E3348BC5@yahoo.com>:
> > i use emacs cperl mode for writing the perl code.
> > i am starting to use etags facility. when i search
> > for a tag using M-. (find-tag) command in emacs, the default
> > appears to be the word at which the cursor is
> > located. typical perl function calls we have
> > are of the form <package>::<function> and that is
> > selected as the default. but etags needs only <function>
> > to find the tag. so is there a way to influence
> > etags find-tag routine to ignore the <package>::
> > prefix in the word around cursor and select just <function>
> > as the default value to look for?
> 
> The function to extract the word for etags' default is customizable.
> CPerl has cperl-mode-hook.

but i am not
much of a lisp programmer and hence had trouble
even locating the exact routine that implements this
functionality ( in either etags.el or cperl.el files )
let alone customize it. so i was looking for any
other perl programmer who already customized this :)

thanks for the pointer anyways.

-badari


> 
> Enough said,
> Ilya


------------------------------

Date: Wed, 25 Jul 2001 18:16:52 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How can I find the Julian Day?
Message-Id: <o2E77.53$os9.207698944@news.frii.net>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.

+
  How can I find the Julian Day?

    Use the Time::JulianDay module (part of the Time-modules bundle
    available from CPAN.)

    Before you immerse yourself too deeply in this, be sure to verify that
    it is the *Julian* Day you really want. Are you really just interested
    in a way of getting serial days so that they can do date arithmetic? If
    you are interested in performing date arithmetic, this can be done using
    either Date::Manip or Date::Calc, without converting to Julian Day
    first.

    There is too much confusion on this issue to cover in this FAQ, but the
    term is applied (correctly) to a calendar now supplanted by the
    Gregorian Calendar, with the Julian Calendar failing to adjust properly
    for leap years on centennial years (among other annoyances). The term is
    also used (incorrectly) to mean: [1] days in the Gregorian Calendar; and
    [2] days since a particular starting time or `epoch', usually 1970 in
    the Unix world and 1980 in the MS-DOS/Windows world. If you find that it
    is not the first meaning that you really want, then check out the
    Date::Manip and Date::Calc modules. (Thanks to David Cassell for most of
    this text.)

- 

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to

    news:news.answers

or to the many thousands of other useful Usenet news groups.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-1999 Tom Christiansen and Nathan
    Torkington.  All rights reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.

                                                           04.14
-- 
    This space intentionally left blank


------------------------------

Date: Wed, 25 Jul 2001 20:20:45 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: FAQ: Why aren't my random numbers random?
Message-Id: <3B5F2A55.15C4E934@acm.org>

Andras Malatinszky wrote:
> 
> "Steffen Müller" wrote:
> 
> > "Andras Malatinszky" <andras@mortgagestats.com> schrieb im Newsbeitrag
> > news:3B5E1491.2E8F8051@mortgagestats.com...
> > >
> > >
> > > PerlFAQ Server wrote:
> > >
> > > >Don't call "srand" more than once--you make your numbers less random,
> > rather
> > > than  more.
> > >
> > > Why is that?
> >
> > Read the man pages.
> 
> I did, a couple of weeks ago, and that's when the question first occurred to me
> (and, let me add, your quote didn't answer it). I can see why reseeding rand( )
> would not make my random numbers more random, but why it would make them less
> random is not obvious to me..

Maybe reading this will help (and maybe it won't :-) )

http://random.org/essay.html



John
-- 
use Perl;
program
fulfillment


------------------------------

Date: Wed, 25 Jul 2001 18:11:10 GMT
From: "Killiam" <Killiam@hotmail.com>
Subject: File delete
Message-Id: <2ZD77.143266$qs5.23347438@news02.optonline.net>

Hi Group

Can someone show me how to delete a file by its age say 10 days old?


Thanxs!




------------------------------

Date: Wed, 25 Jul 2001 18:17:54 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: File delete
Message-Id: <mbudash-9589EC.11175625072001@news.sonic.net>

In article <2ZD77.143266$qs5.23347438@news02.optonline.net>, "Killiam" 
<Killiam@hotmail.com> wrote:

> Can someone show me how to delete a file by its age say 10 days old?

if (-M $file >= 10) {
  unlink ($file) || die ("Can't unlink $file: $!");
}

hth-
-- 
Michael Budash ~~~~~~~~~~ mbudash@sonic.net


------------------------------

Date: Wed, 25 Jul 2001 19:33:14 GMT
From: u518615722@spawnkill.ip-mobilphone.net
Subject: Help: Perl and PL/SQL, which one is better?
Message-Id: <l.996089594.1705932617@[198.138.198.252]>

We are running a perl scripts, in which we call several PL/SQL 
procedures.  

My question is, if we get rid of PL/SQL, use completely perl, will we get any performance gain?  In other word, is calling PL/SQL procedure
expensive?

Thanks

 



-- 
Sent by dbadba62 from hotmail in field  com
This is a spam protected message. Please answer with reference header.
Posted via http://www.usenet-replayer.com/cgi/content/new


------------------------------

Date: 25 Jul 2001 13:51:48 -0700
From: tenpercenter54@hotmail.com (tenpercenter)
Subject: Incomplete output from crontab email: running shell scripts from a perl script
Message-Id: <e1849f6b.0107251251.30492dab@posting.google.com>

I am running a perl script from my crontab.  The perl script that I
run executes shell scripts at the command line.  My crontab sends me
the output from this perl script that runs shell scripts.  However, if
I run the shell scripts directly from the crontab itself I get a
different output (the output that I want).

Why would a perl script that runs a shell script give me a different
"cron job" output then the shell script itself?

I don't think it is a perl problem but I am running the shell scripts
from perl with the following command: `$shell_script`.

Any help would be greatly appreciated.


------------------------------

Date: Wed, 25 Jul 2001 20:56:27 GMT
From: gordon@cwww.cso.uiuc.edu (John Gordon)
Subject: Re: Incomplete output from crontab email: running shell scripts from a perl script
Message-Id: <%nG77.803$A3.9457@vixen.cso.uiuc.edu>

tenpercenter54@hotmail.com (tenpercenter) writes:

> I am running a perl script from my crontab.  The perl script that I
> run executes shell scripts at the command line.  My crontab sends me
> the output from this perl script that runs shell scripts.  However, if
> I run the shell scripts directly from the crontab itself I get a
> different output (the output that I want).

> Why would a perl script that runs a shell script give me a different
> "cron job" output then the shell script itself?

jobs executed by cron can have a different environment than the same
job executed in an interactive shell:

  + different $PATH
  + different current working directory
  + different shell (cron executes its jobs with sh.  is sh your shell?)

---
"... What with you being his parents and all, I think that you could
be trusted not to shaft him."  -- Robert Chang, rec.games.board

John Gordon                               gordon@osiris.cso.uiuc.edu


------------------------------

Date: 25 Jul 2001 07:46:57 +0200
From: elwood@news.agouros.de (Konstantinos Agouros)
Subject: Re: IO::Socket-Question
Message-Id: <elwood.996039963@news.agouros.de>

In <f2nrltcs9d9k5e4jep5g88cbpef1ofgogl@4ax.com> Bart Lateur <bart.lateur@skynet.be> writes:

>Konstantinos Agouros wrote:

>>print $sock "commandforserver"

>Shouldn't commands end in a newline, or even CRLF?
Yes in the real program there are some CRLF's since the server I connect
to speaks a kind of HTTP...

Konstantin
-- 
Dipl-Inf. Konstantin Agouros aka Elwood Blues. Internet: elwood@agouros.de
Otkerstr. 28, 81547 Muenchen, Germany. Tel +49 89 69370185
----------------------------------------------------------------------------
"Captain, this ship will not sustain the forming of the cosmos." B'Elana Torres


------------------------------

Date: 25 Jul 2001 07:51:09 +0200
From: elwood@news.agouros.de (Konstantinos Agouros)
Subject: Re: IO::Socket-Question
Message-Id: <elwood.996040060@news.agouros.de>

In <9jkpr1$ju4$07$1@news.t-online.com> Buggs <buggs-clpm@splashground.de> writes:

>Konstantinos Agouros wrote:

>> In <9jk8cq$u6i$06$1@news.t-online.com> Buggs <buggs-clpm@splashground.de>
>> writes:
>> 
>>>Konstantinos Agouros wrote:
>> 
>--chop--
>> IO::Socket sets sockets to autoflush by default

>Modul up to date?
 I guess so.. perl 5.6 and the one shipped with that

>> I hope to avoid syswrite / select

>what's wrong with syswrite?
more parsing if I use sysread also \:) I should go with send anyway since
it's a socket.

>--chop--
>> There isn't much about it:
>> somewhere I do an IO::Socket::Inet new to the server... since the server
>> some- times closes the connection I do something like:

>IO::Socket::INET

>> if(!$sock->connected())
>> { # reconnect
>> }
>> print STDERR "Before\n";
>> print $sock "commandforserver"

>Note Barts post.
>You can import CRLF from IO::Socket.
Like I said the string I send contains some \r\n

>See if telnet(1) also blocks.
THe problem is it is not deterministic when it blocks... If You send one
command all is ok...But in the end I want to send a few 100,000 requests
and it needs some time until it blocks.

>> print STDER "after\n";
>> 
>> 'After' is never reached
>> If the server really has a bug (which I suspect) I would like to be able
>> to catch this. But I guess I will have to vec/select it before I print.
>> Will be interesting though if the select call will claim, that I could
>> write...
>> 
>> Konstantin

>Consider using the ->timeout() method.
I did that... no luck

Konstantin
-- 
Dipl-Inf. Konstantin Agouros aka Elwood Blues. Internet: elwood@agouros.de
Otkerstr. 28, 81547 Muenchen, Germany. Tel +49 89 69370185
----------------------------------------------------------------------------
"Captain, this ship will not sustain the forming of the cosmos." B'Elana Torres


------------------------------

Date: Wed, 25 Jul 2001 20:57:02 +0200
From: Philip Newton <pne-news-20010725@newton.digitalspace.net>
Subject: Re: IP address incorrect by $ENV{'REMOTE_ADDR'}
Message-Id: <rc5ult0mcm3846pbn0dsi1gbfjv0f5oopf@4ax.com>

On Thu, 26 Jul 2001 00:58:53 +0800, "Peter Chan"
<peter.cch@mailexcite.com> wrote:

> I'm using Perl to write CGI, but I encounter some problem on the IP address.
> 
> I'm using the environment variable, $ENV{'REMOTE_ADDR'} to print the
> address, but what i get is 127.0.0.1, which is local PC IP.

Would you get the same results of your CGI script were written in C or
shell? I think so. So it's not a Perl problem, but a CGI problem.

comp.infosystems.www.authoring.cgi is over there --------->

Followups set.

Cheers,
Phi "maybe you have a funny firewall or reverse proxy" lip
-- 
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: 25 Jul 2001 14:30:36 -0700
From: jeffrey.hill1@tycoelectronics.com (Jeff Hill)
Subject: Object Reuse with Net::FTP
Message-Id: <2cd423e6.0107251330.3cb400e9@posting.google.com>

I am writing a batch processing FTP program that needs to log into
multiple servers.  My Perl experience is right at the Journeyman
level, but this is a problem that I can't seem to figure out.  Several
of the scripts take information from a server in the firewall DMZ,
pull it back to a server on the other side of the firewall and push it
to another server on the intranet.

The first part of that works fabulously!  Unfortunately, when I log
off the first server and go into the next server, I am unable to log
into the next server.  I'm trying to use the same variable (I've set
the '$ftp' variable as a global variable and used it in all the subs,
I know it's a bad practice, but I'm still a little unsure about using
objects in Perl).

When I am about to log into the second server, I undef $ftp, then
reinstaniate it with the new method.  (see code snippet below)  What
happens is that it won't allow me to log in a second time (although I
don't get an error).  It's just that all the calls to $ftp fail.  This
is a batch process, so it loops through a file, taking a command line
and processing it.  I've already checked and the passwords and
usernames are correct, and I can manually get to them.

Code:
my $ftp;

sub Logon {
	my ( $Host, $User, $Pass ) = @_;
	#-Note that the $ftp variable is global. I don't like this, but it 
	# fits with the error handling scheme.  I could pass the $ftp object
by
	# reference, but that will be a later version. (JH 7/25/01)
	if (defined $ftp) { 
		$ftp->quit; 
		$ftp = undef;
	}
	$ftp = Net::FTP->new($Host)
		or return "Could not create object $!\n";
	$ftp->login($User,$Pass)
		or return "Unable to log on to $Host as $User. Check .pgf
file.$!\n";
	return undef;
}

Note that I get the "Unable to log on to $Host as $User. Check .pgf
file.$!\n" error in my log file.

Does anyone have any ideas on this?  

Thanks,
Jeff Hill


------------------------------

Date: Wed, 25 Jul 2001 21:25:24 GMT
From: "Gilad Suberri" <gsuberri@hotmail.com>
Subject: Problem creating file
Message-Id: <8PG77.28564$EP6.7088172@news1.rdc2.pa.home.com>

I have a script that creates a text file. It works fine when I run it off
the server directly, but when I call it from a web page, it does not create
the file for some reason. If the file is already there, it will open it, but
it will not create a new one. Any ideas? Thanks in advance

Gilad






------------------------------

Date: Wed, 25 Jul 2001 16:39:37 -0500
From: "cp" <cpryce@pryce.net>
Subject: Re: Problem creating file
Message-Id: <C_G77.26613$B7.4132793@ruti.visi.com>

"Gilad Suberri" <gsuberri@hotmail.com> wrote in message
news:8PG77.28564$EP6.7088172@news1.rdc2.pa.home.com...
> I have a script that creates a text file. It works fine when I run it off
> the server directly, but when I call it from a web page, it does not
create
> the file for some reason. If the file is already there, it will open it,
but
> it will not create a new one. Any ideas? Thanks in advance
>

The appropriate News Group for CGI questions is
comp.infosystems.www.authoring.cgi. Please direct CGI related questions
there. This likely has very little to do with Perl. However, it comes up
often enough that there is an FAQ to cover it. You should read and
understand the frequently asked question: "My CGI script runs from the
command line but not the browser (500 error)."

type: perldoc perlfaq9

from the command line. FAQs and other docs are available online at
http://www.perldoc.com.
You could also review the archive for this news group by visiting
http://groups.google.com/groups?group=comp.lang.perl.*

Likely, the User ID of the Web server (it often runs as a user called
'nobody') does not have appropriate permissions to make new files.

cp




------------------------------

Date: Wed, 25 Jul 2001 19:29:29 GMT
From: "Blnukem" <blnukem@hotmail.com>
Subject: Read Directory 
Message-Id: <t6F77.143721$qs5.23399687@news02.optonline.net>

Hi All

    I'm tying to read all of the files in a directory but with my script I
get a dot "." and a double ".." listed as files. I'm guessing that this is
the directory structure that it is reading is there a way to read just the
file in the directory without the dots.

My Code;

opendir (DOC, "../test");
@files = readdir (DOC);

print "Content-type: text/html\n\n";
foreach $file (@files) {
print $file;
}
exit;




------------------------------

Date: Wed, 25 Jul 2001 21:09:59 GMT
From: "--Rick" <no_trick@my-de(remove the obvious)ja.com>
Subject: Re: Read Directory 
Message-Id: <HAG77.52123$C81.4436474@bgtnsc04-news.ops.worldnet.att.net>


"Blnukem" <blnukem@hotmail.com> wrote in message
news:t6F77.143721$qs5.23399687@news02.optonline.net...
| Hi All
|
|     I'm tying to read all of the files in a directory but with my
script I
| get a dot "." and a double ".." listed as files. I'm guessing that
this is
| the directory structure that it is reading is there a way to read just
the
| file in the directory without the dots.
|
| My Code;
|
| opendir (DOC, "../test");
| @files = readdir (DOC);
|
| print "Content-type: text/html\n\n";
| foreach $file (@files) {
| print $file;
| }
| exit;
|

On pg 143 of _Learning Perl on Win32 Systems_ it says that is normal
behavior when reading from a directory handle, but you can get the
listing without the dots using glob.  Who knows, maybe that will work?
;-)
(the book just happened to be open to that page...)
--
--Rick




------------------------------

Date: 25 Jul 2001 23:48:18 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Read Directory
Message-Id: <87k80wvlh9.fsf@abra.ru>


B> Hi All
B>     I'm tying to read all of the files in a directory but with my script I
B> get a dot "." and a double ".." listed as files. I'm guessing that this is
B> the directory structure that it is reading is there a way to read just the
B> file in the directory without the dots.

Just filter '.' and '..'. See below

B> My Code;

B> opendir (DOC, "../test");
B> @files = readdir (DOC);

@files = grep $_ ne '.' or $_ ne '..', readdir (DOC);

B> print "Content-type: text/html\n\n";
B> foreach $file (@files) {
B> print $file;
B> }
B> exit;



-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


------------------------------

Date: Wed, 25 Jul 2001 20:16:10 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Read Directory
Message-Id: <tlua8absfko82a@corp.supernews.com>

Ilya Martynov (ilya@martynov.org) wrote:
: @files = grep $_ ne '.' or $_ ne '..', readdir (DOC);

That test will be true for both '.' and '..'.  Methinks 'and' might be a
better boolean operator in there, or even

  @files = grep ! /^\.{1,2}$/, readdir DOC;

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Brute force done fast enough looks slick."
   |             - William Purves


------------------------------

Date: Wed, 25 Jul 2001 14:38:39 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Read Directory
Message-Id: <3B5F3C5F.6F839E05@stomp.stomp.tokyo>

Blnukem wrote:

> I'm tying to read all of the files in a directory but with my script I
> get a dot "." and a double ".." listed as files. I'm guessing that this is
> the directory structure that it is reading is there a way to read just the
> file in the directory without the dots.
 
> opendir (DOC, "../test");
> @files = readdir (DOC);
 
> print "Content-type: text/html\n\n";
> foreach $file (@files) {
> print $file;
> }
> exit;


You need to -f file test. Here are some snippets which
perform a variety of functions you may find useful. This
code you actually want, perhaps, is last in line.



$internal_path = "c:/apache/users";
chdir($internal_path);
@Directories = $internal_path;

while (@Directories)
 {
  $directory = shift(@Directories);
  opendir(DIRECTORY, $directory) || next;
  while (defined ($found = readdir(DIRECTORY))) 
   {
    if (-d "$directory/$found" && $found ne "." && $found ne "..")
     { push(@Directories, "$directory/$found"); }
    if (-f "$directory/$found") 
     { push(@Results, "$directory/$found"); }
   }
  closedir(DIRECTORY);
 }


This snippet above will create two arrays. My @Directories
will logically hold directory names. Array @Results will hold
directory path / filename if this is needed. @Directories will
be null at closing of my example.  You may also enclose this
code within an array loop mechanism if you wish to index a number
of directory trees. My $internal_path would be one of a number
of array elements within this loop mechanism.

My $internal_path is a parent directory for a specific tree.
This variable could very well be produced by an input argument
or a form action input variable.


For your needs, you only need $found filenames. However, you
now have a little extra code with which you may play.


This code will pull only files in a very specific directory,
a directory which is the last or bottom most of a directory
tree. Do not use this code if sub-directories are present:

$directory = "c:/apache/users/test";

opendir(DIRECTORY, $directory);
while (defined ($found = readdir(DIRECTORY))) 
 {
  if (-f "$found") 
   { push(@Results, "$found"); }
 }
closedir(DIRECTORY);


You could add error checking for code like this. However,
your best error message is a lack of a print.

Be sure you "closedir" in your code, especially if you
continue on with other processing. It is usually safer
to use a full directory path rather than dot syntax; it
is easy to miss typing a dot or type too many dots.

You should be able to attain your goal by playing around
with these code examples presented, by mixing and matching
code snippets to perform as you want. The -f filetest is
the magic you need.

Godzilla!


------------------------------

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 1378
***************************************


home help back first fref pref prev next nref lref last post