[25688] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7929 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 31 18:05:47 2005

Date: Thu, 31 Mar 2005 15:05:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 31 Mar 2005     Volume: 10 Number: 7929

Today's topics:
    Re: A hash or array of regexp's? <joe@inwap.com>
    Re: A hash or array of regexp's? (Anno Siegel)
        CGI::UploadEasy - request for comments <noreply@gunnar.cc>
        Cisco Perl Module & Cisco Connectivity <sally.bridges@gmail.com>
    Re: Cisco Perl Module & Cisco Connectivity <1usa@llenroc.ude.invalid>
    Re: Class instances with 'use overload' in a tied hash (Anno Siegel)
    Re: Information transfer over the internet <spam_box@gmx.co.uk>
    Re: Information transfer over the internet <nobull@mail.com>
    Re: launching a Perl script .... <joe@inwap.com>
    Re: Log files in a Date / Time Stamped Directory <manzoorul.hassan@gmail.com>
    Re: Log files in a Date / Time Stamped Directory <mritty@gmail.com>
    Re: Log files in a Date / Time Stamped Directory <tzz@lifelogs.com>
        Looking for a PERL version of "filetime" phynkel@yahoo.com
    Re: Looking for a PERL version of "filetime" <darkon.tdo@gmail.com>
    Re: Looking for a PERL version of "filetime" <do-not-use@invalid.net>
    Re: Looking for a PERL version of "filetime" <jurgenex@hotmail.com>
    Re: Looking for a PERL version of "filetime" <zawrotny@sb.fsu.edu>
    Re: perl script at godaddy <joe@inwap.com>
    Re: Perl script hangs <joe@inwap.com>
    Re: Perl script hangs <phaylon@dunkelheit.at>
    Re: Progressing to OOP & modules for web apps <ra.jones@dpw.clara.co.invalid>
        Redirect on the NO pushing button <nospam@nospam.tv>
    Re: Redirect on the NO pushing button <nospam@nospam.tv>
    Re: Redirect on the NO pushing button <noreply@gunnar.cc>
    Re: Redirect on the NO pushing button <sbryce@scottbryce.com>
    Re: Redirect on the NO pushing button <spamtrap@dot-app.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 31 Mar 2005 03:32:08 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: A hash or array of regexp's?
Message-Id: <t7SdnblbTIsqQtbfRVn-3Q@comcast.com>

Tim Shoppa wrote:
> And to answer the
> other reply, the approach taken ("first match") works fine for my
> purposes.

Be careful when iterating over all hash keys without sorting them.
The order in which keys are returned varies from one run to the next.

If there are several possible matches, and they are not applied
in a specific order, then which one of them is "first" becomes
nondeterministic.

	-Joe


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

Date: 31 Mar 2005 11:36:42 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: A hash or array of regexp's?
Message-Id: <d2gnca$q9r$1@mamenchi.zrz.TU-Berlin.DE>

Tim Shoppa <shoppa@trailing-edge.com> wrote in comp.lang.perl.misc:
> Fabian Pikowski wrote:
> > The Modul Tie::HashRef is moving around the problem
> 
> Thanks for the tip, it's not only a tied hash but also a useful
> object-oriented approach to looking for matches.  It takes "qr//" forms
> directly as the key, no need stringify/destringify.  And to answer the
> other reply, the approach taken ("first match") works fine for my
> purposes.
> 
> I know it's not really a hash (with all the efficiencies that would be
> implied if it was) but I like to think in terms of a hash, and
> Tie::HashRef works wonderfully for this.

As an alternative, you can embed the various actions inside a regex
using the (?{ CODE }) construct.  Example:

    my $re = qr/
        aaa (?{ print "first case\n" }) |
        bbb (?{ print "second case\n" })
    /x;

    /$re/ for qw( gaga-aaa-gugu nothing-here baba-bbb-bubu);

I'm not really recommending this unless special circumstances make it
attractive.  For one, the (?{ CODE }) construct is experimental and
has actual (scoping) issues.  Also, it is an invitation to build one
big-ass regex for all alternatives.  Good coding practice is to
split large regexes, not to combine them.

Anno


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

Date: Thu, 31 Mar 2005 21:16:25 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: CGI::UploadEasy - request for comments
Message-Id: <3b30ieF6bhe7rU1@individual.net>

Hi all,

Judging from questions to these groups and other similar forums, one
area where beginners often encounter difficulties is file uploads. The
just uploaded CPAN module CGI::UploadEasy is an attempt to help prevent
possible hazzle with upload scripts.

<Quoted from README>
CGI::UploadEasy is a wrapper around, and relies heavily on, CGI.pm.
Its purpose is to provide a simple interface to the upload
functionality of CGI.pm.

At creation of the CGI::UploadEasy object, the module saves one or
more files from a file upload request in the upload directory, and
information about uploaded files is made available via the fileinfo()
method. CGI::UploadEasy performs a number of tests, which limit the
risk that you encounter difficulties when developing a file upload
application.
</Quoted from README>

Actually, with CGI::UploadEasy, Perl code for handling file uploads is
as easy to write as the code for ordinary CGI parsing using CGI.pm. :)

Any kind of comments on the module would be much appreciated.

CGI::UploadEasy is available at CPAN:
http://search.cpan.org/CPAN/authors/id/G/GU/GUNNAR/CGI-UploadEasy-0.10.tar.gz
(but not yet via "perl -MCPAN -e shell") and to make it easy to acquaint
oneself with it, I wrote this script:
http://www.gunnar.cc/programs/upload.pl.txt

The whole UploadEasy.pm file follows below. ( Yes, I know, 300
additional lines, but it's with the aim of facilitating comments on
details in the code or POD... ;-) )

Thanks in advance!


+++++++++++++++++++++++++++++++++++++++++++++++++++++

package CGI::UploadEasy;

use 5.006;
use strict;
use warnings;
use CGI 2.76;
use File::Spec;

our $VERSION = '0.10';
# $Id: UploadEasy.pm,v 1.1.1.1 2005/03/31 15:21:01 gunnarh Exp $

=head1 NAME

CGI::UploadEasy - Facilitate file uploads

=head1 SYNOPSIS

     use CGI::UploadEasy;
     my $ue = CGI::UploadEasy->new(-uploaddir => '/path/to/upload/dir');
     my $cgi = $ue->cgiobject;
     my $info = $ue->fileinfo;

=head1 DESCRIPTION

C<CGI::UploadEasy> is a wrapper around, and relies heavily on,
L<CGI.pm|CGI>. Its purpose is to provide a simple interface to the
upload functionality of C<CGI.pm>.

At creation of the C<CGI::UploadEasy> object, the module saves one or
more files from a file upload request in the upload directory, and
information about uploaded files is made available via the B<fileinfo()>
method. C<CGI::UploadEasy> performs a number of tests, which limit the
risk that you encounter difficulties when developing a file upload
application.

=head2 Methods

=cut

sub new {
     my $class = shift;
     my $self = {
         maxsize => 1000,
         _argscheck( \@_ ),
     };

     $CGI::POST_MAX = $self->{maxsize} * 1024;
     $CGI::DISABLE_UPLOADS = 0;
     $CGITempFile::TMPDIRECTORY = $self->{tempdir} if $self->{tempdir};
     $self->{cgi} = CGI->new;
     if ( my $status = $self->{cgi}->cgi_error ) {
         _error($self, $status, "Post too large: "
          . "Maxsize $self->{maxsize} KiB exceeded.");
     }

     if ( $ENV{REQUEST_METHOD} eq 'POST' and
       $ENV{CONTENT_TYPE} !~ /^multipart\/form-data\b/i ) {
         _error($self, '400 Bad Request', 'The content-type at file '
          . "uploads shall be 'multipart/form-data'.<br />\nMake "
          . "sure that the 'FORM' tag includes the "
          . 'attribute: enctype=&quot;multipart/form-data&quot;');
     }

     $self->{files} = _upload($self);

     bless $self, $class;
}

=over 4

=item B<my $ue = CGI::UploadEasy-E<gt>new( -uploaddir =E<gt> $dir [ ,
-maxsize =E<gt> $kibibytes, ... ] )>

The B<new()> constructor takes hash style arguments. The following
arguments are recognized:

=over 4

=item B<-uploaddir>

Specifying the upload directory is mandatory.

=item B<-tempdir>

To control which directory will be used for temporary files, set the
-tempdir argument.

=item B<-maxsize>

Specifies the maximum size in KiB (kibibytes) of a POST request data
set. -maxsize is 1,000 KiB by default. To disable this ceiling for POST
requests, give -maxsize a negative value.

=back

=back

=cut

sub cgiobject {
     my $self = shift;
     $self->{cgi};
}

=over 4

=item B<$ue-E<gt>cgiobject>

Returns a reference to the C<CGI> object that C<CGI::UploadEasy> uses
internally, which gives access to all the L<CGI.pm|CGI> methods.

If you prefer the function-oriented style, you can import a set of
methods instead. Example:

     use CGI qw/:standard/;
     print header;

=back

=cut

sub fileinfo {
     my $self = shift;
     my ($file, $line) = (caller)[1,2];
     if ( @_ ) { die "The 'fileinfo' method does not take arguments ",
       "at $file line $line.\n" }
     $self->{files};
}

=over 4

=item B<$ue-E<gt>fileinfo>

Returns a reference to a 'hash of hashes' with info about uploaded
files. The info may be of use for a result page and/or an email
notification, and it lets you use e.g. MIME type and file size as
criteria for how to further process the files.

=back

=cut

sub otherparam {
     my $self = shift;
     my ($file, $line) = (caller)[1,2];
     if ( @_ ) { die "The 'otherparam' method does not take ",
       "arguments--use CGI.pm's 'param' method to access values at ",
       "$file line $line.\n" }
     my $cgi = $self->{cgi};
     grep { ! ref $cgi->param($_) and $cgi->param($_) } $cgi->param;
}

=over 4

=item B<$ue-E<gt>otherparam>

The B<otherparam()> method returns a list of parameter names
representing POSTed data besides uploaded files. To access the values,
use L<CGI.pm's|CGI> B<param()> method.

=back

=cut

sub _argscheck {
     my $ref = shift;
     my %args;
     my %names = (
         -uploaddir => 'uploaddir',
         -tempdir   => 'tempdir',
         -maxsize   => 'maxsize',
     );
     my $context = sprintf 'at %s line %s', (caller 1)[1,2];

     @$ref % 2 == 0 and @$ref > 0 or die 'One or more name=>argument '
      . 'pairs are expected at the creation of the CGI::UploadEasy '
      . "object $context.\n";

     while ( local $_ = shift @$ref ) {
         my $name = lc;
         $names{$name} or die "Unknown argument: '$_' $context.\n";
         $args{ $names{$name} } = shift @$ref;
     }
     $args{uploaddir} or die "The compulsory argument '-uploaddir' is "
      . "missing $context.\n";

     for my $dir ( @args{ grep exists $args{$_},
       qw/uploaddir tempdir/ } ) {
         -d $dir or die "Can't find any directory '$dir' $context.\n";
         -r $dir and -w _ and -x _ or die 'The user this script runs as '
          . "does not have write access to '$dir' $context.\n";
     }
     $args{maxsize} and $args{maxsize} !~ /^-?\d+$/ and
       die "The '-maxsize' argument shall be an integer $context.\n";

     %args;
}

sub _upload {
     my $self = shift;
     my $cgi = $self->{cgi};
     my %files;

     for my $TEMP ( map $cgi->upload($_), $cgi->param ) {
         ( my $name = $TEMP ) =~ s#.*[\]:\\/]##;
         $name =~ tr/ /_/ unless $^O eq 'MSWin32';
         $name =~ tr/-+@a-zA-Z0-9. /_/cs;
         ($name) = $name =~ /^([-+@\w. ]+)$/;
         my $path = File::Spec->catfile( $self->{uploaddir}, $name );

         # don't overwrite file with same name
         my $i = 2;
         while (1) {
             last unless -e $path;
             $name =~ s/([^.]+?)(?:_\d+)?(\.|$)/$1_$i$2/;
             $path = File::Spec->catfile( $self->{uploaddir}, $name );
             $i++;
         }

         my ($cntrname) =
           $cgi->uploadInfo($TEMP)->{'Content-Disposition'} =~
           /\bname="([^"]+)"/;
         $files{$name} = {
             ctrlname => $cntrname,
             mimetype => $cgi->uploadInfo($TEMP)->{'Content-Type'},
         };

         open my $OUT, '>', $path or die "Couldn't open file: $!";
         if ( $files{$name}{mimetype} =~ /^text\b/ ) {
             binmode $TEMP, ':crlf';
             print $OUT $_ while <$TEMP>;
         } else {
             binmode $OUT, ':raw';
             while ( read $TEMP, my $buffer, 1024 ) {
                 print $OUT $buffer;
             }
         }
         close $TEMP or die $!;  # so the temporary file gets deleted
         close $OUT or die $!;   # so file size can be grabbed below

         $files{$name}{bytes} = -s $path;
     }

     \%files;
}

sub _error {
     my ($self, $status, $msg) = @_;
     my $cgi = $self->{cgi};
     print $cgi->header(-status => $status),
           $cgi->start_html(-title => "Error $status"),
           $cgi->h1('Error'),
           $cgi->tt($msg),
           $cgi->end_html;
     exit 1;
}

1;

__END__

=head1 EXAMPLE

This script handles a file upload request by saving a number of files
in the upload directory and printing the related info:

     #!/usr/bin/perl -T
     use strict;
     use warnings;
     use CGI::UploadEasy;
     use Data::Dumper;
     my $ue = CGI::UploadEasy->new(-uploaddir => '/path/to/upload/dir');
     my $info = $ue->fileinfo;
     my $cgi = $ue->cgiobject;
     print $cgi->header('text/plain');
     print Dumper $info;

=head1 CAVEATS

Since C<CGI::UploadEasy> is meant for file uploads, it requires that the
request data is C<multipart/form-data> encoded. An
C<application/x-www-form-urlencoded> POST request will cause a fatal
error.

No C<CGI> object may be created before the C<CGI::UploadEasy> object has
been created, or else the upload will fail. Likewise, if you import
method names from C<CGI.pm>, be careful not to call any C<CGI> functions
before the creation of the C<CGI::UploadEasy> object.

=head1 AUTHOR, COPYRIGHT AND LICENSE

   Copyright © 2005 Gunnar Hjalmarsson
   http://www.gunnar.cc/cgi-bin/contact.pl

This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=head1 SEE ALSO

L<CGI.pm|CGI>

=cut


-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


-- 
PLEASE NOTE: comp.infosystems.www.authoring.cgi is a
SELF-MODERATED newsgroup. aa.net and boutell.com are
NOT the originators of the articles and are NOT responsible
for their content.

HOW TO POST to comp.infosystems.www.authoring.cgi:
http://www.thinkspot.net/ciwac/howtopost.html


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

Date: 31 Mar 2005 05:06:52 -0800
From: "SallyBridges" <sally.bridges@gmail.com>
Subject: Cisco Perl Module & Cisco Connectivity
Message-Id: <1112274412.016243.37270@f14g2000cwb.googlegroups.com>

Hi,

I have been playing around as I want to be able to display some common
cisco commands as web pages so that we can let people view who is
connected without having to telnet on to the cisco equipment.

I have the following script that works for showing users connected but
i would like to show isdn active.

When i enter this in my box i only get a blank page, i am guessing as
there is a more statment and it may be expecting a response to dump to
screen ( only guessing )

Has any one got any ideas ( yeh it looks messy as cant install perl
modules where i want to either but its working / ish )

#!/usr/bin/perl -w
use lib'/home/httpd/html/test/';
use CGI;
use net::Telnet::Cisco;
$LOGIN = passw1;
$PASSWD = passw2;
$SESSION = Net::Telnet::Cisco->new(Host =>HOSTNAME);
$SESSION->login( $LOGIN, $PASSWD );
print "Content-type: text/plain\n\n";
# This is the command to show active users
$output =print $SESSION->cmd('sh user');
print $output


If you can help then many thanks ;)



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

Date: Thu, 31 Mar 2005 13:47:08 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Cisco Perl Module & Cisco Connectivity
Message-Id: <Xns962A595F23306asu1cornelledu@127.0.0.1>

"SallyBridges" <sally.bridges@gmail.com> wrote in 
news:1112274412.016243.37270@f14g2000cwb.googlegroups.com:

> When i enter this in my box i only get a blank page, i am guessing as
> there is a more statment and it may be expecting a response to dump to
> screen ( only guessing )

Why guess?

> Has any one got any ideas ( yeh it looks messy as cant install perl
> modules where i want to either but its working / ish )
> 
> #!/usr/bin/perl -w

use warnings;

is preferable because it allows you to turn selected classes of warnings 
on/off;

use strict;

> use lib'/home/httpd/html/test/';
> use CGI;
> use net::Telnet::Cisco;

Case matters.

use Net::Telnet::Cisco;

> $LOGIN = passw1;
> $PASSWD = passw2;
> $SESSION = Net::Telnet::Cisco->new(Host =>HOSTNAME);
> $SESSION->login( $LOGIN, $PASSWD );
> print "Content-type: text/plain\n\n";

Use facilities provided by the CGI module:

print header('text/plain');

> # This is the command to show active users
> $output =print $SESSION->cmd('sh user');

Do you know what print returns?

perldoc -f print

> print $output

Why would you want to output that?

> If you can help then many thanks ;)

I don't have a Cisco router to test this, but the documentation for the 
module you are using is very clear:

In your case, you can probably use (untested):

# !/usr/bin/perl

use strict;
use warnings;
$| = 1;

use lib'/home/httpd/html/test/';
use CGI;
use Net::Telnet::Cisco;

my $session = Net::Telnet::Cisco->new(Host => 'HOSTNAME');

print header('text/plain');

if($session->login('login', 'password')) {
    print $session->cmd('sh user');
} else {
    print "Error\n";
}

Please do read the posting guidelines for this group.

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: 31 Mar 2005 11:13:03 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Class instances with 'use overload' in a tied hash
Message-Id: <d2glvv$pbt$1@mamenchi.zrz.TU-Berlin.DE>

Brian McCauley  <nobull@mail.com> wrote in comp.lang.perl.misc:
> 
> 
> Guy Bolton King wrote:
> >>
> >> I'm relatively new to the OO-features of perl, so I may have made an
> >> obvious mistake in the following code, in which case I apologise for
> >> wasting the group's time.  I have a value-type class (Foo in the
> >> example below) which overloads the comparison operator.  sort() then
> >> successfully uses the comparison operator when sorting a list of
> >> instances obtained from the values() of a hash.  However, if the class
> >> instances are used as the values in a _tied_ hash, the overloaded
> >> operator is no longer called, _unless_ values() is called before
> >> calling the sort() function.
> >>
> >> Have I made a mistake?  Or is this something I shouldn't even attempt
> >> in perl?
> > 
> > 
> > Yes, I've posted code that doesn't work.  Working code attached.
> > 
> > ---snip!---
> 
> Good illustration.
> 
> I was able to reproduce on 5.8.6.
> 
> I'm fairly sure you've found a bug in Perl.

Looks like it.

An alternative workaround is

    sort( map $_, values(%b));

Usually, "map $_, ..." should be a no-op, but here it isn't.

Anno


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

Date: Thu, 31 Mar 2005 10:16:42 -0600
From: Lordy <spam_box@gmx.co.uk>
Subject: Re: Information transfer over the internet
Message-Id: <Xns962AAFF60391lordybigfootcom@216.196.109.145>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in news:d2gg9o$llm$1
@mamenchi.zrz.TU-Berlin.DE:

> If you just want to play with a server/client model in Perl, I recommend
> the module Net::EasyTCP. 

or maybe SOAP::Lite ?

-- 
Lordy


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

Date: Thu, 31 Mar 2005 16:53:41 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Information transfer over the internet
Message-Id: <d2h9jc$73e$1@sun3.bham.ac.uk>



Jonas Nilsson wrote:

>>Jonas Nilsson <dzluk8fsxsw0001@sneakemail.com> wrote in
> 
> comp.lang.perl.misc:
> 
>>>                                           This actually givs some
>>>information to a browser when I type http://127.0.0.1:10000.
> 
> 
> 
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:d2gcsv$iul$1@mamenchi.zrz.TU-Berlin.DE...
> 
>>So you want to write a web server.
> 
> 
> Actually no. I just try to do some learning by playing around... Not very
> successfuly however, since the issue is a bit more complex than I realized.
> 
> Actually I need something very simple that can send strings/binaries over
> the internet between a perl-client and a perl-server. Re-posting the
> quasicode from the initial message might clear up my intentions:
> 
> _QUASICODE_
> 
> server:
> while (1) {
>     if (&new_message) {
>         my $input=&message;
>         my $output=&parse($input);
>         &send_message($output);
>     } else {
>         sleep(5);
>     }
> }
> 
> client:
> my $request="Give me checksum of C:/Tmp/test.txt";
> my $answer=&send_request($request,"mycomp.mynet.com") or "Die no answer!";
> &handle($answer);

I suggest you look at the section that deals with sockets in any Perl 
tutorial.

In the standard Perl documentation there's some socket examples in perlipc.



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

Date: Thu, 31 Mar 2005 03:51:12 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: launching a Perl script ....
Message-Id: <JZCdndxa0squedbfRVn-3A@comcast.com>

joesplink wrote:
> can I launch Perl script A from Perl script B ????

Depends on whether script_A is designed to be called from the
command line as opposed to only running in the CGI environment.

   $result = `perl script_A args=B`;	# If not CGI
   use LWP::Simple;
   $result = get("http://server/cgi-bin/script_A?args=B");

	-Joe


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

Date: 31 Mar 2005 07:01:29 -0800
From: "Manzoorul Hassan" <manzoorul.hassan@gmail.com>
Subject: Re: Log files in a Date / Time Stamped Directory
Message-Id: <1112281289.927888.275750@z14g2000cwz.googlegroups.com>

OK, what I meant was, if I do the following, I get a new file created.

  open(FILE_HANDLE, ">file_name") || die "Could not open file\n";

But when I try the similar for Dir, it doesn't work.

  opendir(DIR_HANDLE, ">dir_name") || die "Could not open file\n";

- manzoor



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

Date: Thu, 31 Mar 2005 15:13:37 GMT
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Log files in a Date / Time Stamped Directory
Message-Id: <BsU2e.56$7b.7@trndny05>

Manzoorul Hassan wrote:
> OK, what I meant was, if I do the following, I get a new file created.
> 
>   open(FILE_HANDLE, ">file_name") || die "Could not open file\n";
> 
> But when I try the similar for Dir, it doesn't work.
> 
>   opendir(DIR_HANDLE, ">dir_name") || die "Could not open file\n";
> 
> - manzoor
> 

Of course it doesn't.  There's no such thing as opening a directory for 
writing.  What you're asking for doesn't make sense.

Paul Lalli


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

Date: Thu, 31 Mar 2005 11:59:27 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Log files in a Date / Time Stamped Directory
Message-Id: <4nll83n440.fsf@lifelogs.com>

On 31 Mar 2005, manzoorul.hassan@gmail.com wrote:

> OK, what I meant was, if I do the following, I get a new file created.
> 
>   open(FILE_HANDLE, ">file_name") || die "Could not open file\n";
> 
> But when I try the similar for Dir, it doesn't work.
> 
>   opendir(DIR_HANDLE, ">dir_name") || die "Could not open file\n";

While this looks appealing, it's not how you use opendir.  Look at
"perldoc -f opendir" for more information.

To make a directory, use mkdir ("perldoc -f mkdir").

Ted

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----


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

Date: 31 Mar 2005 06:21:58 -0800
From: phynkel@yahoo.com
Subject: Looking for a PERL version of "filetime"
Message-Id: <1112278918.452572.160870@z14g2000cwz.googlegroups.com>

We have a compiled program (no source) on our SUN machines called
filetime. If you run it against a file name it returns with the number
of seconds from 1/1/1970. We use it to flag files older than a fixed
date

Looking for same thing in PERL or C for use of Linux

Thanks



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

Date: Thu, 31 Mar 2005 14:37:52 -0000
From: "David K. Wall" <darkon.tdo@gmail.com>
Subject: Re: Looking for a PERL version of "filetime"
Message-Id: <Xns962A621816ABFdkwwashere@216.168.3.30>

 <phynkel@yahoo.com> wrote:

> We have a compiled program (no source) on our SUN machines called
> filetime. If you run it against a file name it returns with the
> number of seconds from 1/1/1970. We use it to flag files older
> than a fixed date
> 
> Looking for same thing in PERL or C for use of Linux

Use the builtin function stat().

perldoc -f stat


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

Date: 31 Mar 2005 16:38:25 +0200
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: Looking for a PERL version of "filetime"
Message-Id: <yzdd5tfrice.fsf@invalid.net>


phynkel@yahoo.com writes:
> We have a compiled program (no source) on our SUN machines called
> filetime. If you run it against a file name it returns with the number
> of seconds from 1/1/1970. We use it to flag files older than a fixed
> date
> 
> Looking for same thing in PERL or C for use of Linux

Suggestion:

        % perl -le '@a = stat(shift); print $a[9]' /etc/passwd
        1112104485

You may want error handling of some kind too. Perhaps there's something
ready-made on CPAN - I haven't looked.

It's semantically very similar in C. See the man page for 'stat'.


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

Date: Thu, 31 Mar 2005 15:11:02 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Looking for a PERL version of "filetime"
Message-Id: <aqU2e.37467$oa6.28647@trnddc07>

phynkel@yahoo.com wrote:
> We have a compiled program (no source) on our SUN machines called
> filetime. If you run it against a file name it returns with the number
> of seconds from 1/1/1970. We use it to flag files older than a fixed
> date

For that I would use -M (details see perldoc -f -M)

> Looking for same thing in PERL or C for use of Linux

If you insist on doing it the hard way: did you check stat() already?

jue 




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

Date: 31 Mar 2005 17:51:32 GMT
From: Michael Zawrotny <zawrotny@sb.fsu.edu>
Subject: Re: Looking for a PERL version of "filetime"
Message-Id: <slrnd4oe6e.ruh.zawrotny@localhost.localdomain>

phynkel@yahoo.com <phynkel@yahoo.com> wrote:
>  We have a compiled program (no source) on our SUN machines called
>  filetime. If you run it against a file name it returns with the number
>  of seconds from 1/1/1970. We use it to flag files older than a fixed
>  date
> 
>  Looking for same thing in PERL or C for use of Linux

It's not a perl solution, but many versions of linux come with a
user-level utility called "stat".  See "man 1 stat" for details,
in particular the %x, %X, %y, %Y, %z, %Z formatting options.


Mike

-- 
Michael Zawrotny
Institute of Molecular Biophysics
Florida State University                | email:  zawrotny@sb.fsu.edu
Tallahassee, FL 32306-4380              | phone:  (850) 644-0069


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

Date: Thu, 31 Mar 2005 03:24:03 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: perl script at godaddy
Message-Id: <ltidnbnj0YJPQNbfRVn-rA@comcast.com>

cgidatabase@yahoo.com wrote:

> This script works on another server ok but doesn't at [new server].
> $afile = "../folder/afile.htm";
> $tempfile = "../folder/temp1.htm";
> open(FILB1,"$afile") || die "tryin FILE\n";
> open(TEMPFILE,">$tempfile") || die "trying tempfile\n";

I see obvious problems with the last two lines.

*) The default directory in which as CGI runs in is not standardized.
    You should explicitly chdir() to the correct directory yourself.

*) File-related die() messages should include the name of the
    file or directory, and should include "$!".

   use CGI::Carp qw(fatalsToBrowser);
   chdir $dir                 or die "Cannot cd to $dir - $!\n";
   open FILB1,$afile          or die "Read $afile - $!\n";
   open TEMPFILE,">$tempfile" or die "Write $tempfile - $!\n";

Things to be aware of: parentheses are usually not necessary, double
quotes with nothing between them but a simple variable are not good,
and 'or' is more appropriate than '||' in cases like these.

	-Joe


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

Date: Thu, 31 Mar 2005 03:42:18 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: Perl script hangs
Message-Id: <TKOdnYbm_b6Lf9bfRVn-jg@comcast.com>

Kurt wrote:

> - "top" shows me a CPU usage of 99.9% for its process-id

In cases like this I use ptrace (Linux) or truss (Solaris)
to see if the process is still executing system calls (such
as open(), opendir(), lstat(), etc.)

If that doesn't work, you could compile a version of perl
with debugging enabled so you can use -D or PERLDB_OPTS.
	-Joe


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

Date: Thu, 31 Mar 2005 14:12:40 +0200
From: phaylon <phaylon@dunkelheit.at>
Subject: Re: Perl script hangs
Message-Id: <pan.2005.03.31.12.12.38.87883@dunkelheit.at>

Joe Smith wrote:

> In cases like this I use ptrace (Linux) or truss (Solaris) to see if the
> process is still executing system calls (such as open(), opendir(),
> lstat(), etc.)

Maybe it is OT, but I have to thank you explicitly for naming ptrace. You
made my life much easier :D

-- 
http://www.dunkelheit.at/
bellum omnium pater.



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

Date: Thu, 31 Mar 2005 21:25:13 +0100
From: RA Jones <ra.jones@dpw.clara.co.invalid>
Subject: Re: Progressing to OOP & modules for web apps
Message-Id: <dRZyOSIpyFTCFw4b@na326073.eclipse.co.uk>

On Mon, 28 Mar 2005, Bart Lateur <bart.lateur@pandora.be> wrote:
>Randal Schwartz, you know the one, created CGI::Prototype for this same
>purpose and is currently in the process of writing better docs and
>examples. I think it's worth checking out.
>
Yes, I think I know the one - doesn't much care for Windows OS. Problem 
is I do all my development on Apache/ActivePerl on WinXP, so will have 
to work around that. But thanks for the pointer - I most certainly will 
take a look. Having great 'fun' with CGI::Application at present.
-- 
To reply by e-mail, change 'invalid' to 'uk':
ra(dot)jones(at)dpw(dot)clara(dot)co(dot)uk


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

Date: Thu, 31 Mar 2005 21:17:39 +0200
From: "PHP2" <nospam@nospam.tv>
Subject: Redirect on the NO pushing button
Message-Id: <d2hicj$3g3$1@ss405.t-com.hr>

I am create edit data form, and it ask visitor: "do you wish edit data?"

All is ok with Yes button, but I don't kniw what with No button :-)

I wish that clicking NO button recirect me on some URL..

Any help




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

Date: Thu, 31 Mar 2005 21:30:53 +0200
From: "PHP2" <nospam@nospam.tv>
Subject: Re: Redirect on the NO pushing button
Message-Id: <d2hj5d$4o1$1@ss405.t-com.hr>

Note: I know that I can solve it with JavaScript.. but I wish Perl way..


"PHP2" <nospam@nospam.tv> wrote in message 
news:d2hicj$3g3$1@ss405.t-com.hr...
>I am create edit data form, and it ask visitor: "do you wish edit data?"
>
> All is ok with Yes button, but I don't kniw what with No button :-)
>
> I wish that clicking NO button recirect me on some URL..
>
> Any help
>
> 




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

Date: Thu, 31 Mar 2005 21:46:16 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Redirect on the NO pushing button
Message-Id: <3b32afF6f6voqU1@individual.net>

PHP2 wrote:
> I am create edit data form, and it ask visitor: "do you wish edit data?"
> All is ok with Yes button, but I don't kniw what with No button :-)
> I wish that clicking NO button recirect me on some URL..
> Any help

Leaving the poorly worded question aside, it should be noted that this 
guy is multi-posting as usual: 
http://www.mail-archive.com/beginners%40perl.org/msg67834.html

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Thu, 31 Mar 2005 12:54:57 -0700
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: Redirect on the NO pushing button
Message-Id: <8--dnXKT4qISyNHfRVn-uw@comcast.com>

Gunnar Hjalmarsson wrote:

> Leaving the poorly worded question aside, it should be noted that this 
> guy is multi-posting

And asking an HTML question on a Perl newsgroup.


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

Date: Thu, 31 Mar 2005 16:27:46 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Redirect on the NO pushing button
Message-Id: <HrKdnenKXtXO9tHfRVn-pQ@adelphia.com>

PHP2 wrote:

> All is ok with Yes button, but I don't kniw what with No button :-)
> 
> I wish that clicking NO button recirect me on some URL..

This is a CGI question, not a Perl question. The answer is the same if you
were writing your CGI in (for example) Python, C, Java, PHP, or whatever.
You're also, as Gunnar pointed out, multi-posting - that's considered rude.

I'll answer your question this time, but please - do us all (including
yourself) a favor, and read the posting guidelines. You'll get more help
and less flames by following them.

So, to answer your (CGI) question: Assign a "name" attribute to both of the
buttons. When one of them is clicked, two params are sent to your CGI. For
example, if the user clicks a button with a "name='foo'" attribute, then
your CGI will receive 'foo.x' and 'foo.y' parameters. The X and Y values
aren't useful for buttons, but you can check for the existence of
parameters with those names to see which button was clicked.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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