[24967] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7217 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 7 09:07:03 2004

Date: Thu, 7 Oct 2004 06:05:14 -0700 (PDT)
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, 7 Oct 2004     Volume: 10 Number: 7217

Today's topics:
    Re: -d file test using Active State PERL under Windows <tadmc@augustmail.com>
    Re: -d file test using Active State PERL under Windows <usenet739_yahoo_com_au>
    Re: Can perl SHA1 module be applied to files? <kuujinbo@hotmail.com>
        directory script tweak <moarif1@gmail.com>
    Re: directory script tweak <usa1@llenroc.ude.invalid>
    Re: directory script tweak <toreau@gmail.com>
    Re: directory script tweak <someone@example.com>
    Re: Error.pm and DBI.pm problem (Peter Scott)
    Re: finding the last element in a referenced array (Anno Siegel)
    Re: Help with Sending Multiple Emails! chris-usenet@roaima.co.uk
    Re: Help with Sending Multiple Emails! <iss025@bangor.ac.uk>
    Re: How to prevent the removal of \ from pairs of \\? (Bad Ynfo)
    Re: How to prevent the removal of \ from pairs of \\? <eam@7ka.mipt.ru>
    Re: How to prevent the removal of \ from pairs of \\? (Bad Ynfo)
    Re: How to prevent the removal of \ from pairs of \\? <bernie@fantasyfarm.com>
    Re: Is PHP still slower than Perl? <tony@NOSPAM.demon.co.uk>
        localtime - user input - output in same format (Dan Vesma)
    Re: localtime - user input - output in same format <me@thomasnagel.com>
    Re: localtime - user input - output in same format <simon@unisolve.com.au>
    Re: localtime - user input - output in same format <no@email.com>
        log_file output <no@no.no>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 6 Oct 2004 20:37:38 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: -d file test using Active State PERL under Windows
Message-Id: <slrncm97f2.8j0.tadmc@magna.augustmail.com>

Scott <> wrote:

> I have this test script:
> 
> my $dir = "C:/WINNT";
> opendir(DIR,$dir) || die("Cannot open directory $dir");
> my @files = readdir DIR;
> closedir(DIR);
> 
> foreach (@files) {
>    print "$_\n" if -d;  # -d -f -t -T -B
> }


> I've cycled thru the tests as per the comment line above.


How many minutes have you spent troubleshooting this problem so far?

10 minutes perhaps?


> For -d, I would have expected it to list all the directories (only) under 
          ^^^^^^^^^^^^^^^^^^^^^
> C:\WINNT.


What info did you base that expectation on?

Did you try reading the documentation for the functions you are using?

They warn you away from the very problem you are having.


> Any idea what I might be doing wrong?  


Not reading the documentation for the functions you are using.


> Are my assumptions incorrect?


   perldoc -f readdir

(the second paragraph:)

      If you're planning to filetest the return values out of a
      "readdir", you'd better prepend the directory in question.
      Otherwise, because we didn't "chdir" there, it would have been
      testing the wrong file.


How many minutes would it have taken to read 2 short paragraphs?

Less than one perhaps?


Work smart, use the docs Luke.





[ snip long version output ]

We almost never need that info as the bug is most often in the
programmer's program than a bug in perl itself.

We almost always need Real Perl Code to help solve the problem though,
so please include Perl code when you have another question. 

Have you seen the Posting Guidelines that are posted here frequently?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 7 Oct 2004 11:42:52 +1000
From: "Scott" <usenet739_yahoo_com_au>
Subject: Re: -d file test using Active State PERL under Windows
Message-Id: <41649f97$0$1264$5a62ac22@per-qv1-newsreader-01.iinet.net.au>

Duh, don't I feel like an idiot!  Yes, the full path to the file test would 
be useful!

Thanks Rhesa, much appreciated!

"Rhesa Rozendaal" <perl&nntp@rhesa.com> wrote in message 
news:41648dcf$0$78738$e4fe514c@news.xs4all.nl...
> Scott wrote:
>> Hi,
>>
>> I have this test script:
>>
>> my $dir = "C:/WINNT";
>> opendir(DIR,$dir) || die("Cannot open directory $dir");
>> my @files = readdir DIR;
>> closedir(DIR);
>>
>> foreach (@files) {
>>    print "$_\n" if -d;  # -d -f -t -T -B
>> }
>>
>
>> C:\Perl\my.scripts>test2  (-d)
>
> [snip]
>
>> Any idea what I might be doing wrong?  Are my assumptions incorrect?
>
> Yes, your assumption about the current working directory.
> Next time, try
>
> print $_,$/ if -d "$dir/$_";
>
>
> HTH,
>
> Rhesa 




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

Date: Thu, 07 Oct 2004 21:39:49 +0900
From: ko <kuujinbo@hotmail.com>
Subject: Re: Can perl SHA1 module be applied to files?
Message-Id: <2skrohF1l0r2pU1@uni-berlin.de>

Lee Hibberd wrote:
> Thanks for your reply Keith. I am now seeing the same value generated
> for three different .jpg files I am working with so I guess something
> is still wrong with my code. Could you give me a final nudge in the
> right direction? Here's the modified code:
> 
> #!/usr/local/bin/perl

use strict;
use warnings;

> use Digest::SHA1;
> 
> my $datafile = "c:\testerforanette.jpg";
> my $file_is_binary = ! -T $datafile;
> 
> open ((MYNEWFILE, $datafile) || die ("Can't find file"));

Is this *really* the code you're using? Enable strict and warnings and 
see what happens. Even without strict and warnings, you get a diagnostic 
message informing you that no filehandle is being passed to addfile().

> if ($file_is_binary) {
>     binmode(MYNEWFILE);
> 	print Digest::SHA1->new->addfile(*MYNEWFILE)->hexdigest, "\n";
> 	close (MYNEWFILE);
> }
> 
> I've noticed if I replace addfile(*MYNEWFILE) with addfile(MYNEWFILE).
> I also get the same result. Thanks - Lee

A lexical filehandle as posted previously (need Perl 5.6.0 or
higher) allows you to pass the filehandle directly to addfile() without 
the typeglob. For details:

perldoc perlopentut, the 'Indirect Filehandles' section
perldoc -q "How do I pass filehandles between subroutines?"

Or, if you're running an older version, use IO::File to get the lexical 
filehandle:

use IO::File;
my $datafile = 'YOUR_JPG';
my $fh = new IO::File $datafile;

if (defined $fh) {
   binmode($fh);
   print Digest::SHA1->new->addfile($fh)->hexdigest, " $datafile\n";
   $fh->close;
}

Can't make any other suggestions, since the code as posted doesn't read 
any files.

keith


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

Date: Wed, 06 Oct 2004 21:45:16 -0400
From: "transcript" <moarif1@gmail.com>
Subject: directory script tweak
Message-Id: <d681cb7ae567f0545811f37ec6d930f9@localhost.talkaboutprogramming.com>

I'm using this script below to compare two directories.

#!/usr/bin/perl -w
use File::Find;
use File::Basename;

# Read the contents of the first directory (DOC) into a hash
$input = "/home/oper/testscripts/input/testprocedures";
%docs =();
find (\&firstDir, $input);
sub firstDir {
    /.doc/ or return;
    -f and ($name,$path,$suffix) = fileparse($File::Find::name);
    $docs{$name} = 1;
}

# Now read the contents of the second directory (PDF) into an array
$output = "/home/oper/testscripts/output/testprocedures";
@pdfs=();
find (\&secondDir, $output);
sub secondDir {
    /.pdf/ or return;
    -f and ($name,$path,$suffix) = fileparse($File::Find::name);
    push @pdfs, $name;
}

# Now delete the files in the second dir that aren't in the first dir.
foreach $file (@pdfs) {
    if (!defined($docs{$file})) {
        $fullpath = "${output}/${file}";
        print "unlink $fullpath\n";
        system("unlink $fullpath");
    }
}


In the result, I get a list of pdf files that need to be deleted but I
don't get the complete path to the files.
For example:
I would get "unlink
home/oper/testscripts/output/testprocedures/sample.pdf.

In actuality, The complete path would 
home/oper/testscripts/output/testprocedures/test/sample.pdf.

Therefore, when the unlink command runs, it comes up with
"no file or directory".

How can I tweak the script in order to print the complete path to the .pdf
files. 





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

Date: 7 Oct 2004 02:33:24 GMT
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Re: directory script tweak
Message-Id: <Xns957AE5B48C00asu1cornelledu@132.236.56.8>

"transcript" <moarif1@gmail.com> wrote in
news:d681cb7ae567f0545811f37ec6d930f9@localhost.talkaboutprogramming.com:

> I'm using this script below to compare two directories.
> 
> #!/usr/bin/perl -w

use strict;
use warnings;

> use File::Find;
> use File::Basename;
> 
> # Read the contents of the first directory (DOC) into a hash
> $input = "/home/oper/testscripts/input/testprocedures";

my $input = ...

I recommend using File::Spec->catfile.

> %docs =();

my %docs;

> find (\&firstDir, $input);
> sub firstDir {
>     /.doc/ or return;

The pattern above is probably not want you want. The . character matches 
any character. In addition, since you have not anchored your pattern, it 
will match a whole bunch of things you don't want it to match. E.g.:

perl -e "print qq{matched\n} if q{adoc.pdf} =~ /.doc/"

>     -f and ($name,$path,$suffix) = fileparse($File::Find::name);

perldoc File::Find

BTW, why are you calling fileparse when all you need is the full path to 
the file?

>     $docs{$name} = 1;
> }
> 
> # Now read the contents of the second directory (PDF) into an array
> $output = "/home/oper/testscripts/output/testprocedures";
> @pdfs=();
> find (\&secondDir, $output);
> sub secondDir {
>     /.pdf/ or return;

See above. You should at least read perldoc perlrequick.

>     -f and ($name,$path,$suffix) = fileparse($File::Find::name);
>     push @pdfs, $name;
> }
> 
> # Now delete the files in the second dir that aren't in the first dir.
> foreach $file (@pdfs) {
>     if (!defined($docs{$file})) {

No need for defined here. 

>         $fullpath = "${output}/${file}";
>         print "unlink $fullpath\n";
>         system("unlink $fullpath");
>     }
> }

Why use system here?

> In the result, I get a list of pdf files that need to be deleted but I
> don't get the complete path to the files.
> For example:
> I would get "unlink
> home/oper/testscripts/output/testprocedures/sample.pdf.

perldoc File::Find

> In actuality, The complete path would 
> home/oper/testscripts/output/testprocedures/test/sample.pdf.
> 
> Therefore, when the unlink command runs, it comes up with
> "no file or directory".
> 
> How can I tweak the script in order to print the complete path to the
> .pdf files. 

Oh, I see, this is not your script. Why don't you contact the author of the 
script then?

Sinan.


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

Date: Thu, 07 Oct 2004 10:56:56 +0200
From: Tore Aursand <toreau@gmail.com>
Subject: Re: directory script tweak
Message-Id: <pan.2004.10.07.08.56.54.443409@gmail.com>

On Wed, 06 Oct 2004 21:45:16 -0400, transcript wrote:
> I'm using this script below to compare two directories.
> 
> #!/usr/bin/perl -w

Replace with:

  #!/usr/bin/perl
  #
  use strict;
  use warnings;

> use File::Find;
> use File::Basename;

Consider using File::Find::Rule instead of File::Find, as it is much
easier to work with;

  use File::Find::Rule;
  use File::Basename;

> # Read the contents of the first directory (DOC) into a hash
> $input = "/home/oper/testscripts/input/testprocedures";
> %docs =();
> find (\&firstDir, $input);

  my $input = '/home/oper/testscripts/input/testprocedures';
  my %docs  = map { $_ => 1 } File::Find::Rule->file()->relative()->name( '*.doc' )->in( $input );

> sub firstDir {
>     /.doc/ or return;

First of all, IMO, this is better written as:

  return unless ( /.doc/ );

Secondly, this will match any character followed by 'doc' anywhere in the
filename.  You probably want to match the '.' character followed by 'doc'
at the end of the filename;

  return unless ( /\.doc$/ );

>     -f and ($name,$path,$suffix) = fileparse($File::Find::name);

You should have used the '-f' test together with the first test;

  return unless ( /\.doc$/ && -f );

>     $docs{$name} = 1;

However, with File::Find::Rule, you don't need this subroutine at all. :)

> # Now read the contents of the second directory (PDF) into an array
> $output = "/home/oper/testscripts/output/testprocedures";
> @pdfs=();
> find (\&secondDir, $output);
> sub secondDir {
>     /.pdf/ or return;
>     -f and ($name,$path,$suffix) = fileparse($File::Find::name);
>     push @pdfs, $name;
> }

Change to:

  my $output = '/home/oper/testscripts/output/testprocedures';
  my @pdfs   = File::Find::Rule->file()->relative()->name( '*.doc' )->in( $output );

This should get you going.


-- 
Tore Aursand <toreau@gmail.com>
"Those people who think they know everything are a great annoyance to
 those of us who do." (Isaac Asimov)


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

Date: Thu, 07 Oct 2004 12:52:46 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: directory script tweak
Message-Id: <y_a9d.38796$223.33319@edtnps89>

transcript wrote:
> I'm using this script below to compare two directories.
> 
> #!/usr/bin/perl -w
> use File::Find;
> use File::Basename;
> 
> # Read the contents of the first directory (DOC) into a hash
> $input = "/home/oper/testscripts/input/testprocedures";
> %docs =();
> find (\&firstDir, $input);
> sub firstDir {
>     /.doc/ or return;
>     -f and ($name,$path,$suffix) = fileparse($File::Find::name);
>     $docs{$name} = 1;
> }
> 
> # Now read the contents of the second directory (PDF) into an array
> $output = "/home/oper/testscripts/output/testprocedures";
> @pdfs=();
> find (\&secondDir, $output);
> sub secondDir {
>     /.pdf/ or return;
>     -f and ($name,$path,$suffix) = fileparse($File::Find::name);
>     push @pdfs, $name;
> }
> 
> # Now delete the files in the second dir that aren't in the first dir.
> foreach $file (@pdfs) {
>     if (!defined($docs{$file})) {
>         $fullpath = "${output}/${file}";
>         print "unlink $fullpath\n";
>         system("unlink $fullpath");
>     }
> }
> 
> In the result, I get a list of pdf files that need to be deleted but I
> don't get the complete path to the files.
> For example:
> I would get "unlink
> home/oper/testscripts/output/testprocedures/sample.pdf.
> 
> In actuality, The complete path would 
> home/oper/testscripts/output/testprocedures/test/sample.pdf.
> 
> Therefore, when the unlink command runs, it comes up with
> "no file or directory".
> 
> How can I tweak the script in order to print the complete path to the .pdf
> files. 

You should be able to do it something like this (assuming that all the file 
names are unique):

#!/usr/bin/perl
use warnings;
use strict;

use File::Find;
use File::Basename;

# Read the contents of the first directory (DOC) into an array
my @docs;
find( sub {
     /\.doc$/ and -f and push @docs, basename( $_, '.doc' )
     }, '/home/oper/testscripts/input/testprocedures' );

# Now read the contents of the second directory (PDF) into a hash
my %pdfs;
find( sub {
     /\.pdf$/ and -f and $pdfs{ basename( $_, '.pdf' ) } = $File::Find::name
     }, '/home/oper/testscripts/output/testprocedures' );

# Now delete the files in the second dir that aren't in the first dir.
delete @pdfs{ @docs };
for my $file ( values %pdfs ) {
     unlink $file or warn "Cannot unlink $file: $!";
     }

__END__



John
-- 
use Perl;
program
fulfillment


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

Date: Thu, 07 Oct 2004 13:03:25 GMT
From: peter@PSDT.com (Peter Scott)
Subject: Re: Error.pm and DBI.pm problem
Message-Id: <x8b9d.17813$a41.15681@pd7tw2no>

In article <53867fbe.0410060715.7948a734@posting.google.com>,
 unkwb@web.de (Horst Walter) writes:
>Yes, this is what I have guessed. But I tried many things and was not
>able to do it.
>
>I used
>use Error qw(:try);
>
>as in all the examples for error.pm. I have tried several tings as 
>use Error qw(:try with);
>
>but none of them worked.
>It would be great if somebody had an example on this.

Post the shortest *complete program* you can construct that
demonstrates the problem please.  I have never had problems
with Error.pm and DBI and cannot reproduce your problem.

-- 
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/


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

Date: 7 Oct 2004 09:12:56 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: finding the last element in a referenced array
Message-Id: <ck31ao$ptf$1@mamenchi.zrz.TU-Berlin.DE>

Joe Smith  <Joe.Smith@inwap.com> wrote in comp.lang.perl.misc:
> .rhavin wrote:
> 
> > i think i once again outed myself as a c-styler, thinkin
> > the minus-first element is the element preceding the zeroth in a
> > reference to the middle of an array - i guess now that kind of
> > construction is impossible in perl?
> 
> Correct.  Arrays are first class citizens in the Perl world; not
> merely pointers to memory.

True.

>                            There's really no concept of a
> reference to the middle of an array: Perl gives you a single
> scalar, or an array slice (which has its own set of array
> bounds checking).

Also true, but it sounds like the second statement were a consequence
of the first one, which it isn't.  Perl's strings are also first class
data (not just arrays of characters), but the concept of a string
that is really part of another string does exist, realized by
substr().  Similarly, Perl *could* have "sub-arrays", though it
doesn't.  If we had lvalue functions for arrays, not only scalars,
it should be simple to implement sub-arrays in a class.

Anno


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

Date: Thu, 7 Oct 2004 08:53:24 +0100
From: chris-usenet@roaima.co.uk
Subject: Re: Help with Sending Multiple Emails!
Message-Id: <k89f32-pqf.ln1@moldev.cmagroup.co.uk>

Terry <gobeyondgobeyond@rem0ve.yahoo.com> wrote:
> I am new to Perl.  I ran into this problem while trying to send out 2 
> messages from a script. [..]

> # send the 1st message
> open (M, "| /usr/sbin/sendmail -t");
> print M "To: $address_01\n";
> print M "From: $address_from\n";

These variables aren't from a CGI by any chance, are they? Have you
sanitised $address_01 and $address_from? If not, consider what happens
if either of the variables contains a newline followed by a very long
"Bcc: spam1@address1 spam2@address2..."

Chris


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

Date: Thu, 07 Oct 2004 10:10:36 +0100
From: "P.R.Brady" <iss025@bangor.ac.uk>
Subject: Re: Help with Sending Multiple Emails!
Message-Id: <4165080C.6050909@bangor.ac.uk>

Terry wrote:
> Hi,
> 
> I am new to Perl.  I ran into this problem while trying to send out 2 
> messages from a script.  Nearly half the time, the second message didn't 
> get sent, while the first message always get sent.  Here is what I did:
> 
> # send the 1st message
> open (M, "| /usr/sbin/sendmail -t");
> 
> print M "To: $address_01\n";
> print M "From: $address_from\n";
>  ...
> # content of 1st message
> 
> close (M);
> 
> 
> # send the 2nd message
> open (M, "| /usr/sbin/sendmail -t");
> 
> print M "To: $address_02\n";
> print M "From: $address_from\n";
>  ...
> # content of 2nd message
> 
> close (M);
> 
> 
> I wonder if this is the right way to implement this.  Is there a way to 
> check to see if the messages have been sent successfully?
> 
> Thanks in advance for your help!
> 
> Terry

Terry,
    that's a refreshing back to basics approach!
Alternatively, the module SendMail as described at 
http://www.tneoh.zoneit.com/perl/SendMail/
is easy to use.  Remember to 'reset' after each email.
The site gives a download link but I installed it with PPM.

I hope you are not writing a spam engine!

Regards
Phil



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

Date: 7 Oct 2004 01:39:52 -0700
From: badynfo@yahoo.fr (Bad Ynfo)
Subject: Re: How to prevent the removal of \ from pairs of \\?
Message-Id: <d76524b7.0410070039.872aaea@posting.google.com>

"Paul Lalli" <mritty@gmail.com> wrote in message news:<vwT8d.695$tc.258@trndny02>...
> "Bad Ynfo" <badynfo@yahoo.fr> wrote in message
> news:d76524b7.0410060553.565691c1@posting.google.com...
> > Hi,
> >
> > In perlop, it reads:
> >
> > '', q//
> > The only interpolation is removal of \ from pairs \\.
> >
> > So how can I assign '\\foo\bar' to a scalar without having to say
> > '\\\\foo\bar'? Is it possible?
> 
> About the only way I can think of is to use a single-quoted heredoc:
> 
> $path =<<'PATH';
> \\foo\bar
> PATH
> 
> Note that I don't especially understand why this works.  Why would
> single-quoted heredocs not work the same as 'normal' single-quoted
> strings?
> 
> Paul Lalli

Thanks Paul, that's exactly what I was looking for!


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

Date: Thu, 7 Oct 2004 11:48:35 +0300
From: "Eugene Mikheyev" <eam@7ka.mipt.ru>
Subject: Re: How to prevent the removal of \ from pairs of \\?
Message-Id: <ck2vnt$2dl6$1@news.univ.kiev.ua>

> have you tried that out and printed it?
>
> perl -le '$x = q{\\foo\bar} ; print $x'
> \foo\bar
>
> he wants 2 \'s at the beginning of the string, hence his 4 \'s.
>
> uri
Yes, you're right. I thought he was seeking for a regex without escaping
that slashes. So I did misfire...




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

Date: 7 Oct 2004 01:55:47 -0700
From: badynfo@yahoo.fr (Bad Ynfo)
Subject: Re: How to prevent the removal of \ from pairs of \\?
Message-Id: <d76524b7.0410070055.269d60d1@posting.google.com>

Tad McClellan <tadmc@augustmail.com> wrote in message news:<slrncm845p.79m.tadmc@magna.augustmail.com>...
> Bad Ynfo <badynfo@yahoo.fr> wrote:
> > Hi,
> > 
> > In perlop, it reads:
> > 
> > '', q// 
> > The only interpolation is removal of \ from pairs \\. 
> > 
> > So how can I assign '\\foo\bar' to a scalar without having to say
> > '\\\\foo\bar'? 
> 
> 
> Why do you think you want to assign '\\foo\bar' to a scalar without 
> having to say '\\\\foo\bar'?

Because the assignment is made from a text file where it reads
\\foo\bar!
The "transfer" from the file is made by means of "copy-and-paste".
Sure it's not a good method since we can't process the input file, but
I can't change this step and I wanted a quick solution to handle this
situation.

The single-quoted heredoc should do the trick without having to change
the (bad) mecanism =)

> 
> That is NOT a rhetorical question. This sounds like an XY Problem to me, 
> we could give a much better answer if we knew what the "Y" was...
> 
> 
>    What is it that you are ultimately trying to accomplish?
> 
> 
> If those data are paths, then did you know that '//foo/bar' will
> work in most cases?

I know this possibility but because of the "copy-and-paste", this was
not a solution...

> 
> How are you using these strings?
> 
> If you can switch to sensible slashes, your whole problem goes away
> (which is what makes those silly slashes silly).
> 
> 
> > Is it possible?
> 
> 
> Sure, but the cure is MUCH worse than the disease. 
> 
> What is your objection to backslashing backslashes in literal strings?

copy-and-paste =)

> 
> Here are some examples:
> 
>    $_ = chr(92) . chr(92) . 'foo' . chr(92) . 'bar';  # works for ASCII
> 
>    $_ = "@{[chr(92)]}@{[chr(92)]}foo@{[chr(92)]}bar"; # works for ASCII
> 
>    my $bs = chr(92);        # works for ASCII
>    $_ = "$bs${bs}foo${bs}bar";
> 
>    $_ = '//foo/bar';
>    $_ =~ tr#/#\\#;

Unfortunately these examples are not relevant to my problem.

Thanks for your time and for your detailed answer.

B.Y.


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

Date: Thu, 07 Oct 2004 08:18:44 -0400
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Re: How to prevent the removal of \ from pairs of \\?
Message-Id: <cucam09glmmq6k2cag841hcvuvmap40q9u@library.airnews.net>

Uri Guttman <uri@stemsystems.com> wrote:

} >>>>> "PL" == Paul Lalli <mritty@gmail.com> writes:

}   PL> Note that I don't especially understand why this works.  Why would
}   PL> single-quoted heredocs not work the same as 'normal' single-quoted
}   PL> strings?
} 
} because in single quoted strings \ is needed to escape ' and \. in
} single quoted heredocs there is no need to escape anything as perl just
} scans for the closing token. in normal double quoted heredocs, perl has
} to scan for \ escapes like \n and \t so it must handle \\ and it makes
} that into just \.

Why does that apply if you use 'q' with an explicit terminator?  [which
was, I thought, the original question.  Is there a need to scan for '\' if
I'm doing:  q{stuff} ?

  /Bernie\

-- 
Bernie Cosell                     Fantasy Farm Fibers
bernie@fantasyfarm.com            Pearisburg, VA
    -->  Too many people, too few sheep  <--          


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

Date: Thu, 7 Oct 2004 11:31:42 +0100
From: "Tony Marston" <tony@NOSPAM.demon.co.uk>
Subject: Re: Is PHP still slower than Perl?
Message-Id: <ck35ue$r1k$1$830fa7b3@news.demon.co.uk>


"John Bokma" <postmaster@castleamber.com> wrote in message 
news:Xns957AC495EAC76castleamber@130.133.1.4...
> oracle.shinoda@gmail.com (Brad Shinoda) wrote in
> news:ad3a63b3.0410061342.780a787c@posting.google.com:
>
>> John Bokma <postmaster@castleamber.com> wrote in message
>> news:<Xns9579AAC4C59F6castleamber@130.133.1.4>...
>>> That's mySQL, not PHP.
>>>
>>> I mean something like:
>>>
>>> $query = "INSERT INTO table VALUES(?, ?, ?)";
>>> mysql_bla( $query, $a, $b, $c );
>>>
>>> Hence without the quote_she_bang_garbage
>>
>> I can't believe you can't actually write such a function yourself???
>
> Sure. I can even write my own improved PHP clone. What's the point?
>
>> People should always be writing wrapper functions or classes to handle
>> db connections, to remove such stuff as addslashes()ing. Use
>> func_num_args() to find out the number of arguments passed to a php
>> function and func_get_arg([number]) to get the [number]th argument
>> passed. I've written such a function for myself.
>
> Yes, and everybody has to write wrapper functions. You get the point
> now, or do you want it spelled out?

But different developers will write wrapper functions in different ways. 
Whish one should I choose? Why?

>> Well in fact I use
>> three classes for handling databases - one abstract "Database" class
>> for any database,
>
> Yes, in Perl that is called DBI. You don't have to write it yourself.

Yes, but what happens if I don't like the way it works?

>> one Database specific class (eg mysql_db for mysql
>> databases) and a Query class for handling queries in the manner you
>> suggest. Now I do this:
>>
>> $sql = "SELECT foo, bar
>>   FROM table
>>   WHERE a = ?
>>   AND b = ?";
>> $db->query(new Query($sql, $a, $b), __LINE__, __FILE__);
>>
>> And all query preprocessing is handled by the Query class, and
>> database connection/query processing/error handling is handled by the
>> database-specific class.
>>
>> I use such classes in all my developments. They're written once then
>> forgotten about, and simply reused where needed.
>
> Wonderful. With Perl it's put on CPAN and used (and tested) by many
> people.
>
>> All I'm saying is that it's really pretty easy to implement many
>> things yourself, without moaning that the language hasn't done them
>> for you.
>
> Programming shouldn't be about reinventing wheels, and worse reinventing
> bugs.

But it is about reinventing wheels. A pram wheel is no good for a sports 
car, so you have to invent one that works under those circumstances.

I have stopped using other people's solutions for the following reasons:
(a) There are too many solutions from too many people. The people have 
various skill levels (from pathetic to passable), and the solutions are 
tailored for specific purposes.
(b) It takes too much time to go though all the possible solutions to find 
one that is applicable to the problem in hind. I find it much quicker to use 
my decades of experience in devising my own solution.

Just my personal opinion.

-- 
Tony Marston

http://www.tonymarston.net





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

Date: 7 Oct 2004 00:27:15 -0700
From: daninbrum@hotmail.com (Dan Vesma)
Subject: localtime - user input - output in same format
Message-Id: <14c7b35.0410062327.324645e3@posting.google.com>

Good morning,

I am trying to get to grips with a timesheet app. I am presenting the
user with a form to enter details of an undertaken task, including the
date on which the work was undertaken. I am using

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime
time;

to populate an HTML form with today's day/month/year. The user can
then change this figure if the work was done the previous day, or a
month ago, or whenever.

When that form is returned, I would ideally like to store a single
number to represent the day that the work was undertaken, so that I
can sort tasks by the date undertaken. How do I get from a day, a
month and a year to the number of seconds since 1.1.1970?

Any clues?

Thanks,


Daniel V


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

Date: Thu, 07 Oct 2004 10:04:47 +0200
From: Thomas Nagel <me@thomasnagel.com>
Subject: Re: localtime - user input - output in same format
Message-Id: <ck2tav$d6p$1@sapa.inka.de>

Hi,

> When that form is returned, I would ideally like to store a single
> number to represent the day that the work was undertaken, so that I
> can sort tasks by the date undertaken. How do I get from a day, a
> month and a year to the number of seconds since 1.1.1970?

use Time::Local;
my $seconds = timelocal(0, 0, 0, $day, $month - 1, $yyyy);

$day is in range 1..31 while $month is in (0..11).

Thomas



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

Date: Thu, 07 Oct 2004 18:01:35 +1000
From: Simon Taylor <simon@unisolve.com.au>
Subject: Re: localtime - user input - output in same format
Message-Id: <ck2tfk$13e8$1@otis.netspace.net.au>

Dan Vesma wrote:
> Good morning,
> 
> I am trying to get to grips with a timesheet app. I am presenting the
> user with a form to enter details of an undertaken task, including the
> date on which the work was undertaken. I am using
> 
> ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime
> time;
> 
> to populate an HTML form with today's day/month/year. The user can
> then change this figure if the work was done the previous day, or a
> month ago, or whenever.
> 
> When that form is returned, I would ideally like to store a single
> number to represent the day that the work was undertaken, so that I
> can sort tasks by the date undertaken. How do I get from a day, a
> month and a year to the number of seconds since 1.1.1970?
> 
> Any clues?


See the FAQ entry:

     perldoc -q seconds

and more specifically:

use Date::Calc qw(Date_to_Time);

 ...

my $time = Date_to_Time($year,$month,$day,
            $hour,$min,$sec);

print "time: $time\n";


Regards,

Simon Taylor


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

Date: Thu, 7 Oct 2004 11:08:27 +0100
From: "Brian Wakem" <no@email.com>
Subject: Re: localtime - user input - output in same format
Message-Id: <2skissF1ln81qU1@uni-berlin.de>


"Thomas Nagel" <me@thomasnagel.com> wrote in message
news:ck2tav$d6p$1@sapa.inka.de...
> Hi,
>
> > When that form is returned, I would ideally like to store a single
> > number to represent the day that the work was undertaken, so that I
> > can sort tasks by the date undertaken. How do I get from a day, a
> > month and a year to the number of seconds since 1.1.1970?
>
> use Time::Local;
> my $seconds = timelocal(0, 0, 0, $day, $month - 1, $yyyy);
>
> $day is in range 1..31 while $month is in (0..11).
>

$month must be 1..12 here as you are supplying $month - 1 to the function,
but not actually changing $month.  If $month eq 0 then you'd be passing -1
to the function.

-- 
Brian Wakem




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

Date: Thu, 07 Oct 2004 05:29:37 -0500
From: Mike Rogers <no@no.no>
Subject: log_file output
Message-Id: <Xns957B74FC4F7BEnonono@216.196.97.142>

Hello Folks, 

I am new to perl and I have written a script that ssh's to a server and 
then runs a command. I am trying to have the script send the output of 
the command to a log file but am running into problems.

I have added the whole script to the bottom of the post, at the moment it 
works fine and logs the output of "uname -a\r" to the log file dump.dat 
but its pretty messy, for example the contents look like:-

^M
^M^[[3g^[[24;9H^[H^[[24;17H^[H^[[24;25H^[H^[[24;33H^[H^[[24;41H^[H^
[[24;49H^[H^[[24;57H^[H^[[24;65H^[H^[[24;73H^[H^M^Mtest-server[root]# 
uname -a^M
IPSO test-server 3.7.1-BUILD013 releng 1279  07.21.2004-225500 i386^M
test-server[root]# ^M

Is there a clean way to send the output of "uname -a" to dump.dat without 
using:

$command->log_file("dump.dat");
$command->log_file(undef);

Something like: 

print $command "uname -a\r" >> dump.dat;

I know the above won't work but is there something like this so it just 
appends dump.dat with:

test-server[root]# uname -a
IPSO test-server 3.7.1-BUILD013 releng 1279  07.21.2004-225500 i386

Many Thanks in advance,

Mike.

#!/usr/local/bin/perl

use Expect;

$fwlist= "fwlist";

open (FWLIST, $fwlist) or die ("Cannot open $fwlist - $!");

while ($fwname = <FWLIST>) {

      print ("$fwname\n");

$ip = `getmip $fwname`;

$command = Expect->spawn("s0 ssh1 $ip")
    or die "Couldn't start program: $!\n";

      # prevent the program's output from being shown on the screen
      $command->log_stdout(0);

      # wait 60 seconds for "[vt100]" to appear
        unless ($command->expect(60, '[vt100]')) {
      # timed out
}
      
      # send a carriage return to the program
      print $command "\r";

$command->log_file("dump.dat");

      # wait 10 seconds for "[root]#" to appear
        unless ($command->expect(10, '[root]#')) {
      # timed out
}

      # send a "uname -a" and a carriage return to the program
      print $command "uname -a\r";

      # wait 10 seconds for "[root]#" to appear
        unless ($command->expect(10, '[root]#')) {
      # timed out
}


$command->log_file(undef);


      # send "exit" and a carriage return to the program
      print $command "exit\r";

      print ("\n\n\n");

      print ("Completed\n\n");

}


# close (FWLIST);


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

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


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