[19692] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1887 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 7 18:05:45 2001

Date: Sun, 7 Oct 2001 15:05:06 -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: <1002492306-v10-i1887@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 7 Oct 2001     Volume: 10 Number: 1887

Today's topics:
    Re: "chdir" argument as a variable... <pne-news-20011007@newton.digitalspace.net>
        [Q]: Mail::Box manager hangs before anything interestin <karp@math.wisc.edu>
    Re: Am I asking too much ??? (Tana)
        ANNOUNCE: "Compiler" <aotto@t-online.de>
    Re: ANNOUNCE: "Compiler" <pne-news-20011007@newton.digitalspace.net>
    Re: ANNOUNCE: "Compiler" <aotto@t-online.de>
    Re: Apply Regex In Place <LindaTuner@hotmail.com>
    Re: Apply Regex In Place <Laocoon@eudoramail.com>
        Grafikeinbettung <AndreasWielke@gmx.de>
    Re: Grafikeinbettung <jurgenex@hotmail.com>
    Re: I was all about to enjoy jive in perl except I don' <pilsl_@goldfisch.at>
        join two hashrefs <jens@irs-net.com>
    Re: join two hashrefs <ilya@martynov.org>
    Re: Perl 5.6.0 chmod bug? (Abigail)
    Re: Problems to expect using Perl scripts with Win9x wh (Garry Williams)
    Re: question about MAP function, please help. (Clinton A. Pierce)
        thanks (rolf deenen)
    Re: time transformation <dtweed@acm.org>
    Re: time transformation (Tim Hammerquist)
    Re: time transformation (Logan Shaw)
        unix comm perl style <vbrammer@home.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 07 Oct 2001 17:53:18 +0200
From: Philip Newton <pne-news-20011007@newton.digitalspace.net>
Subject: Re: "chdir" argument as a variable...
Message-Id: <iiu0stcpplhg3bkijuk8eiscbuo1dliudp@4ax.com>

On Sat, 06 Oct 2001 01:01:49 -0400, Benjamin Goldberg
<goldbb2@earthlink.net> wrote:

> By the way, if I were doing it, I would leave out the chdir()s entirely,
> and create the files by doing:
> 
> open( OUT, ">", "$i/command$i" )
>     or die "Couldn't open $i/command$i: $!";

Or if you want to be pedantically portable, File::Spec->catfile or
something like that.

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: 07 Oct 2001 12:14:24 -0500
From: Anatoly Karp <karp@math.wisc.edu>
Subject: [Q]: Mail::Box manager hangs before anything interesting happens
Message-Id: <2shetb1ifj.fsf@erdos.math.wisc.edu>

Hello all,

Eager to harness the power of Perl modules, I started
writing a little mail forwarding program. 


# <------------ code starts here  --------------  >

#!/usr/local/bin/perl -w 

use strict;
use Mail::Box::Manager;

my $mgr    = Mail::Box::Manager->new;
my $folder = $mgr->open(folder => $ENV{MAIL}) or die "Could not open\
                                                      mailbox!\n";
# <------------- code ends here ------------------->



This is almost straight from the perldoc page
(I just added the die bit), and when I run it 
it hangs, hangs miserably. (it does get past the new call)

Any thoughts on what might be wrong here?..

I am running Perl 5.6.1 on Freebsd-4.4 STABLE if this is
of any use.

Thanks,

-- 
Anatoly Karp                        e-mail: karp@math.wisc.edu
Department of Mathematics           


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

Date: 7 Oct 2001 09:27:08 -0700
From: tana@acedsl.com (Tana)
Subject: Re: Am I asking too much ???
Message-Id: <4294f74d.0110070827.d0102c0@posting.google.com>

logan@cs.utexas.edu (Logan Shaw) wrote in message news:<9poi91$ao3$1@charity.cs.utexas.edu>...
> In article <4294f74d.0110061259.67c337a0@posting.google.com>,
> Tana <tana@acedsl.com> wrote:
> >Jon Ericson <Jon.Ericson@jpl.nasa.gov> wrote in message news:<86itducbrg.fsf@jon_ericson.jpl.nasa.gov>...
> >> tana@acedsl.com (Tana) writes:
> >> > Could someone give me the equivalent PHP code for this PERL code above?
> >> > Am I asking too much ???
>  
> >> Frankly, yes.  This is a newsgroup for discussion of *perl*.  Honestly,
> >> you'd be better off finding a group discussing *PHP*.
>  
> >Sorry people, but no reason to be rude.
> >I was just hoping that someone would know both languages.
> >Such a person would be able to give me a straight answer in 5 seconds.
> 
> A good general rule for most technical newsgroups, including this one,
> is that the people who read the group will be glad to answer a question
> someone runs into when trying to solve a problem on their own[1], but
> requests for the readers of the group to do the work of solving the
> problem are considered rude.
> 
> In this newsgroup, that usually works out to mean that questions like
> "can anyone give me code to do X?" are considered rude, while questions
> like "why does the following short piece of code do X when it seems
> like it should do Y?" are generally OK.
> 
> And if you got a rude response, keep in mind that the patience of
> regular readers has probably worn thin because they have seen so many
> "questions" which are really requests for someone to provide free
> programming service.  Sometimes it's even apparent that the person
> asking is receiving money for the solution they deliver to some
> customer, yet they're expecting the solution to come for free from the
> newsgroup.
> 
>   - Logan
> 
> [1]  Provided you've made some effort to figure it out on your own.
>      If the answer is right there in a very obvious place in the
>      documentation, it's best not to ask the question.


Yes, you all have a point there.
But I am not trying to get "free code" or something like that.
I am not a perl programmer, nor php programmer.
I am just trying to use PayPal Instant notification PERL script.
The PERL script provided by PayPal does not work for me, that's all.

thanks anyway
Tana


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

Date: Sun, 7 Oct 2001 16:17:03 +0200
From: Andreas Otto <aotto@t-online.de>
Subject: ANNOUNCE: "Compiler"
Message-Id: <v4opp9.0uj.ln@linux02.otto-net>


Hi,

  never was it so easy to write a native WINDOWS(R) application
  on your LINUX(R) box

  Tcl "Compiler" is NOW a cross compiler

  learn more

    http://www.compiler-factory.com


-- 
================================================================
(C) Compiler-Factory      Phone: ++49-(0)8152-399540
Dipl.-Ing Andreas Otto    mailto:info@compiler-factory.com
Business Solutions        http://www.compiler-factory.com
Ulmenstrasse 3            => "Compiler", FastWeb, OpMenu
D-34289 Zierenberg        => C, C++, Tcl, HTML, database,
=================================================================


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

Date: Sun, 07 Oct 2001 18:15:14 +0200
From: Philip Newton <pne-news-20011007@newton.digitalspace.net>
Subject: Re: ANNOUNCE: "Compiler"
Message-Id: <urv0st893q8q4elp2ojl5pm00hnb9a0vc1@4ax.com>

On Sun, 7 Oct 2001 16:17:03 +0200, Andreas Otto <aotto@t-online.de>
wrote:

>   Tcl "Compiler" is NOW a cross compiler

This has what to do with Perl?

Or HIBT?

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: Sun, 7 Oct 2001 18:17:24 +0200
From: Andreas Otto <aotto@t-online.de>
Subject: Re: ANNOUNCE: "Compiler"
Message-Id: <k6vpp9.b0l.ln@linux02.otto-net>

Philip Newton wrote:

> On Sun, 7 Oct 2001 16:17:03 +0200, Andreas Otto <aotto@t-online.de>
> wrote:
> 
> >   Tcl "Compiler" is NOW a cross compiler
> 
> This has what to do with Perl?
> 
> Or HIBT?


Just for information,

  a little bit competition is sometimes good


(e.g. i hope perl will catch up)

-- 
================================================================
(C) Compiler-Factory      Phone: ++49-(0)8152-399540
Dipl.-Ing Andreas Otto    mailto:info@compiler-factory.com
Business Solutions        http://www.compiler-factory.com
Ulmenstrasse 3            => "Compiler", FastWeb, OpMenu
D-34289 Zierenberg        => C, C++, Tcl, HTML, database,
=================================================================


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

Date: Sun, 07 Oct 2001 13:43:02 GMT
From: "Linda Turner" <LindaTuner@hotmail.com>
Subject: Re: Apply Regex In Place
Message-Id: <GZYv7.64857$0x.23077575@typhoon.southeast.rr.com>

Thanks for that.  I added a counter to capture the number of times
something was changed, but it doesn't seem to be working.  I am also
getting some messages that I wonder if I should worry about.  Any
thoughts?

C:\uf\sql>perl -W c:\UF\PERL\SIP.PL
Subroutine cwd redefined at C:/Perl/lib/Cwd.pm line 397.
Subroutine getcwd redefined at C:/Perl/lib/Cwd.pm line 398.
Subroutine fastcwd redefined at C:/Perl/lib/Cwd.pm line 399.
Subroutine fastgetcwd redefined at C:/Perl/lib/Cwd.pm line 400.
Subroutine abs_path redefined at C:/Perl/lib/Cwd.pm line 401.
processing C:\UF\SQL/roll.sql : 0
processing C:\UF\SQL/ex.sql : 0
processing C:\UF\SQL/locks.sql : 0
 ...

#!/usr/local/bin/perl -w

use File::Find;
use strict;

$/ = undef;

my $start_dir = 'C:\\UF\\SQL';

File::Find::find( \&each_file, $start_dir );

sub each_file {
  return unless /\.sql$/;
  if ( -T $_ ) {
    print "processing $File::Find::name : ";
    my $match_count = 0;
    if ( open F, "< $_" ) {
      my $s = <F>;
      close F;
      if ( open F, "> $_" ) {
        if ($s =~ s/COLUMN1/COLUMN2/ig) {
           my $match_count++;
        }
        print F $s;
        close F;
        print "$match_count\n";  #only prints 0 !!
      }
      else {
        print "Error opening file for write: $!\n";
      }
    }
    else {
      print "Error opening file for read: $!\n";
    }
  }
}





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

Date: Sun, 7 Oct 2001 16:31:04 +0200
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: Apply Regex In Place
Message-Id: <Xns9133A80DBA52CLaocooneudoramailcom@62.153.159.134>

*snip*
>         if ($s =~ s/COLUMN1/COLUMN2/ig) {
>            my $match_count++;

Change the 'my' to 'our'.

>         }
>         print F $s;
>         close F;
>         print "$match_count\n";  #only prints 0 !!
>       }
*snip*



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

Date: Sun, 07 Oct 2001 16:13:19 +0200
From: AndreasWielke <AndreasWielke@gmx.de>
Subject: Grafikeinbettung
Message-Id: <3BC062FF.496E4EEA@gmx.de>

Hallo

ich will eine html seite erzeugen, auf der ein Bild ist (Barcode)
striche. Ich hab den Eindruck bei Drucken drucken die Browser
abgsehen von Fonts einfach ein Bildschirmphoto was die Auflösung
anbelangt. Wie kann ich den Browser dazu überreden dass er ein
Bild kleiner und dafür mit höherer Auflösung ausdruckt.
Gibt es in GIF/JPG/PNG Format die Möglichkeit die Auflösung
festzulegen mit der das Bild gedruckt werden soll... und an die
sich die Browser (zumindsest IE und Netscape) halten.

Danke

Andi Wielke

P.S.: Ich hoffe ich bin im richtigem Forum dafür!



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

Date: Sun, 7 Oct 2001 08:54:08 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Grafikeinbettung
Message-Id: <3bc07aa2$1@news.microsoft.com>

"AndreasWielke" <AndreasWielke@gmx.de> wrote in message
news:3BC062FF.496E4EEA@gmx.de...
> ich will eine html seite erzeugen, auf der ein Bild ist (Barcode)
> striche. Ich hab den Eindruck bei Drucken drucken die Browser
> abgsehen von Fonts einfach ein Bildschirmphoto was die Auflösung
> anbelangt. Wie kann ich den Browser dazu überreden dass er ein
> Bild kleiner und dafür mit höherer Auflösung ausdruckt.
> Gibt es in GIF/JPG/PNG Format die Möglichkeit die Auflösung
> festzulegen mit der das Bild gedruckt werden soll... und an die
> sich die Browser (zumindsest IE und Netscape) halten.

Browser, font, photo, resolution, GIF, JPG, PNG, printing in brower, IE,
Netscape .....
Do you see a Perl question anywhere in this list?

> P.S.: Ich hoffe ich bin im richtigem Forum dafür!

Forum? What forum? The Forum Romanum?
This is not a forum, you posted to a Usenet newsgroup and apparently to the
wrong one.

jue




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

Date: Sun, 7 Oct 2001 19:08:08 +0200
From: peter pilsl <pilsl_@goldfisch.at>
Subject: Re: I was all about to enjoy jive in perl except I don't know how to invoke it
Message-Id: <3bc08bf9$1@e-post.inode.at>

Dan Jacobson wrote:

> I'm sorry I've downloaded the perl
> http://www.illuminated.co.uk/mung/filters/jive etc. but don't know how to
> invoke them without appending a 
> while (<>) {&filter($_);} to them.

whats wrong with this ?
I really dont know whats that code is about, but it isnt a script, but a 
sub, so you need something like your code.

merge your above code and the sub in a perlscript called jive.pl and run
$cat source | jive.pl

jive.pl (untested):
#/usr/bin/perl -w
while (<>) {filter($_);} 
sub filter{
$_=shift;
and so on ...
}


or give the name of sourcefile as commandlineoption and open in the script.

peter

-- 
peter pilsl
pilsl_@goldfisch.at
http://www.goldfisch.at



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

Date: Sun, 07 Oct 2001 23:47:32 +0200
From: Jens Luedicke <jens@irs-net.com>
Subject: join two hashrefs
Message-Id: <9pqilj$v18$07$1@news.t-online.com>

hi ...

can I join two hashrefs like:

$one = {};
$two = {};
$one->{'test1'} = "bla1";
$two->{'test2'} = "bla2";

$one .= $two

-- 
Jens Luedicke
jens@irs-net.com


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

Date: 08 Oct 2001 02:03:52 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: join two hashrefs
Message-Id: <87lminxg3b.fsf@abra.ru>

>>>>> On Sun, 07 Oct 2001 23:47:32 +0200, Jens Luedicke <jens@irs-net.com> said:

JL> hi ...
JL> can I join two hashrefs like:

JL> $one = {};
JL> $two = {};
JL> $one->{'test1'} = "bla1";
JL> $two->{'test2'} = "bla2";

JL> $one .= $two

%$one = (%$one, %$two);

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| 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: 7 Oct 2001 13:45:32 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Perl 5.6.0 chmod bug?
Message-Id: <slrn9s0n0r.nh6.abigail@alexandra.xs4all.nl>

Doug (shadowmint@mailcity.com) wrote on MMCMLIX September MCMXCIII in
<URL:news:56a6cb33.0110070310.357ba01b@posting.google.com>:
@@ > Yeah, it's that the it is supposed to function.  But when I say that,
@@ > I'm talking about a different "it" than you are.  Witness this:
@@ > 
@@ >     $ perl -le 'print 0700 + 0'
@@ >     448
@@ >     $ perl -le 'print "0700" + 0'
@@ >     700
@@ >     $ 
@@ 
@@ I see. I'm not sure what it means... but I see. I'm aware that
@@ 448 is 700 in octal... This in fact demonstrates my problem exactly:
@@ 
@@ If I have a string $permissions, and I want a number in octal to 
@@ pass to the chmod function, what do I do?

You write it as an octal number of course. Or, alternatively, you'd
use the oct() function.

@@ clearly: print "0700" + 0; returns 700; HOWEVER, it still treats 
@@ it as a string. This has -not- forced it into a numeric expression;
@@ for instance:

Huh? How do you think Perl adds a string and a number, if 700 is still
a string?

@@ #!/usr/bin/perl -lw
@@ $val = "0700" + 0;
@@ print $val + 0;
@@ 
@@ Prints out 700; not the 448 that I would expect if $val had been turned
@@ into a numeric expression (and hence the second line being equivalent of
@@ 
@@ perl -le 'print 0700 + 0';
@@ 
@@ As previously.

There is a difference between a numeric *EXPRESSION* and a octal LITERAL.

It's the 0 in the LITERAL that makes it an octal number, just like the
quotes in "time" make it the string time, and not the function time().

If you have:

    $str = "time";
    print $str . "()";

what do you expect will be printed? The string 'time()', or the current
value of time()?

@@ 
@@ > So it's not just chmod() that interprets things differently.  What's
@@ > going on is that Perl treats numeric literals in the program text
@@ > differently than it treats strings that need to be converted into
@@ > numeric values.  (Adding zero forces Perl to make the string into a
@@ > numeric value.)
@@ 
@@ I've read this. Adding a zero forces perl to make the string into a numeric
@@ value. It doesnt in this case. That's the problem. Or rather it does; it
@@ converts 0700 into 700; but then still treats the 700 as a string, rather
@@ than a numeric expression.

What on earth do you mean by this? Apparently, you think that adding a
string (without conversion to a number) to a number is a valid operation
in Perl. How does that work?

@@ 
@@ What I want to do is really very simple;
@@ 
@@ #!/usr/bin/perl -w
@@ $permissions = "0700";
@@ $file = "junk";
@@ chmod $permissions, $file;
@@ 
@@ and get the resulting file (junk) with the correct permissions.

Then you should use correct Perl.

Question: why do you put quotes around 0700? They shouldn't be there.
For exactly the same reason you don't put quotes around time in the 
code below:

    #!/usr/bin/perl -w
    $now = "time";
    $file = "junk";
    utime $now, $now, $file;

The quotes indicate a string literal. Not an octal literal. A string
literal. Rules for octal literals no longer apply.

@@ and get the resulting file (junk) with the correct permissions. Now; that
@@ doesn't work. Neither does adding in a + 0 anywhere. I've tried;
@@ 
@@ $permissions = 0;
@@ $permissions += "0700";

That's not adding a zero. That's adding the string "0700", which Perl
numifies for you, resulting in 700. If you want to add the octal number
0700, either use an octal literal, 0700, or tell Perl to interpret the
number as an octal number using the function oct().

@@ chmod $permissions + 0, $file;
@@ 
@@ chmod "$permissions" + 0, $file;

Again the quotes. What's up with the quotes? 

@@ $new = 1;
@@ $new += $permissions;
@@ chmod "$permissions" + 0, $file;
@@ 
@@ Even that didn't work. It did the equivalent of oct(701) for the permissions.
@@ 
@@ Any suggestions? I probably sound obtuse, and I'm sorry. :) This is really
@@ frustrating me. 

What's really frustrating is that this "problem" is spelled out in the
documentation of chmod(), *including* code showing incorrect and correct
examples.

@@ 
@@ > In fact what may be confusing you is the very fact that chmod() DOESN'T
@@ > behave differently.  In the Unix world, /bin/chmod does behave
@@ > differently than most other programs (it expects octal); in Perl,
@@ > chmod() behaves just like other functions.  That is, Perl doesn't make
@@ > chmod() magical in any way.  (It certainly could -- it could treat
@@ > its first argument as a string and process it specially if it begins
@@ > with zero.  But apparently it doesn't.)
@@ 
@@ I'm not sure I know what you mean. Chmod in this case -is- expecting an octal
@@ value (ie. same as the shell chmod). Perl is simply not turning the string in
@@ a number correctly, so it's getting confused.

Bullocks. Processes, including chmod, never get numbers passed - they are
always, always, always strings. It's up to the chmod command to interpret
the strings as octal numbers. Function in languages like Perl (but it
works the same in C), get values of various types passed. It's the lexer
that sees 0700, and turns that in to a token "INTEGER, value 111000000".
It's not up to chmod() to inspect the program text.

@@ for instance; in (very many) perl tutorials you see:
@@ 
@@ ...
@@ chmod 0755, "helloworld.cgi";
@@ ...


Nothing wrong with that. Do you see the difference with your code?



Abigail
-- 
@;=split//=>"Joel, Preach sartre knuth\n";$;=chr 65;%;=map{$;++=>$_}
0,22,13,16,5,14,21,1,23,11,2,7,12,6,8,15,3,19,24,14,10,20,18,17,4,25
;print@;[@;{A..Z}];


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

Date: Sun, 07 Oct 2001 13:43:56 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Problems to expect using Perl scripts with Win9x who were written with Linux
Message-Id: <slrn9s0n0s.enu.garry@zfw.zvolve.net>

On Sun, 07 Oct 2001 12:45:09 +0200, Rinus Luijmes <digirini@xs4all.nl>
wrote:

> What problems can I expect using this different OS and what
> can I do while writing this script to prevent them?

The manual directly answers this question.  See the perlport manual
page.  

-- 
Garry Williams


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

Date: Sun, 07 Oct 2001 13:54:28 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: question about MAP function, please help.
Message-Id: <o8Zv7.151398$K6.72576193@news2>

[Posted and mailed]

In article <pbUv7.211256$j65.50706539@news4.rdc1.on.home.com>,
	Qiang <home@home.com> writes:
> #1
> 
> @sizes = map { -s $_ } @file_names;
> 
> my understanding is , elements in @file_names gets read one by one and 
> saved into $_ , then the block function evalutes each of them i.e the "-s 
> $_"  and put it into @size array.  am i right ? 

Esentially you are correct.  A list of the sizes of the elements in 
@file_names is created by map and stored in @sizes.

> #2:
> 
> @a = ('a'..'z');
> @b = (0..5);
> $c = map {$a[int rand @a]} @b;
> print "$c \n";
> 
> i got the output as uncertain alphebet combination in length 6. again, my 
> understanding is : @b gets read and store in $_ one by one. but here we did 
> not use $_ , so @b works in the map function just like while loop as .. 

map is used to iterate over one list, returning another list.  Essentially
doing a transformation of the first into the second.  The second list can 
be larger, smaller, related to or have nothing to do with the first list
at all.

In this case the mistake comes in $c.  Rmember: map is normally used to 
return a list.  You're using it in a /scalar/ context and map's scalar 
context return value is the number of elements returned.  (Always 6.)

Try this variation:

	$c=join '', map { $a[ rand @a ] } @b;

This properly takes the list coming out of map, joins them together
into a scalar, which is what I presume you intended.
 
> my another question arises.... under what situation should i use map ? 

Whenever appropriate.  :)

> which way is better ? 

When it fits better.

> does it make really difference between map code with 
> this while one regardless of the length of the code ,  is the 
> time-consuming ?   

Do whatever works best for you.  In terms of efficiency, your time spent
programming is probably more important than how long the program takes to
run.  Get the big picture right, and don't sweat the small stuff too 
much.

-- 
    Clinton A. Pierce            Teach Yourself Perl in 24 Hours  *and*
  clintp@geeksalad.org                Perl Developer's Dictionary
"If you rush a Miracle Man,     for details, see http://geeksalad.org     
	you get rotten Miracles." --Miracle Max, The Princess Bride


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

Date: 7 Oct 2001 12:54:00 -0700
From: rdeenen@mollymail.com (rolf deenen)
Subject: thanks
Message-Id: <5b51a4e6.0110071153.2b2601f4@posting.google.com>

Thanks NoBull,

I really appreciate your comments and suggestions.

Rolf Deenen


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

Date: Sun, 07 Oct 2001 16:22:02 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: time transformation
Message-Id: <3BC07FD4.E8DE8DD8@acm.org>

Logan Shaw wrote:
> Others have posted various solutions.  Here's a string-oriented
> approach:
> 
>     $time =~ s/12:/0:/;                         # special cases
>     $time =~ s/(\d+):(\d+)pm/($1+12).":$2"/e;   # handle pm
>     $time =~ s/am//;                            # handle am
>     $time =~ s/24:/0:/;                         # midnight -> 00
> 
> Hope that helps.

Nope, this one gets noon and midnight backwards.

Also, the last line is superfluous, because all 12: got changed to 0:
in the first line.

Are you people testing this code before you post???

-- Dave Tweed


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

Date: Sun, 07 Oct 2001 19:39:04 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: time transformation
Message-Id: <slrn9s1ckc.hcn.tim@vegeta.ath.cx>

Me parece que Tim Hammerquist <tim@vegeta.ath.cx> dijo:
> Me parece que Zimmen Gnauh <yah00204052@yahoo.com> dijo:
> >     What's the simplest way to tranform 12 hour format time into 24 hour
> > format, i.e.
> >            9:20am   ->9:20
> >          12:30pm   ->12:30
> >            4:30pm  ->16:30
> 
> if ($time =~ /^(1?\d):([0-5]\d)([ap])m$/i) {
>     ($h, $m) = ($1, $2);
>     $h += 12 if $3 eq 'p' and $h < 12;
>     $time = sprintf "%02d:%02d", $h, $m;
> }

I tested this with the times the OP posted originally, but it occurred
to me while driving last night that this would break on if AM/PM were
stated in caps.  Try:

if ($time =~ /^(1?\d):([0-5]\d)([ap])m$/i) {
    ($h, $m) = ($1, $2);
    $h += 12 if lc $3 eq 'p' and $h < 12;
    $time = sprintf "%02d:%02d", $h, $m;
}

[ snip ]

HTH
Tim
-- 
It's astonishing how much trouble one can
get oneself into, if one works at it.
    -- Destruction, The Sandman


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

Date: 7 Oct 2001 16:19:18 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: time transformation
Message-Id: <9pqgsm$eh1$1@charity.cs.utexas.edu>

In article <3BC07FD4.E8DE8DD8@acm.org>, Dave Tweed  <dtweed@acm.org> wrote:
>Logan Shaw wrote:
>> Others have posted various solutions.  Here's a string-oriented
>> approach:
>> 
>>     $time =~ s/12:/0:/;                         # special cases
>>     $time =~ s/(\d+):(\d+)pm/($1+12).":$2"/e;   # handle pm
>>     $time =~ s/am//;                            # handle am
>>     $time =~ s/24:/0:/;                         # midnight -> 00
>> 
>> Hope that helps.
>
>Nope, this one gets noon and midnight backwards.

It converts 12:00am to 0:00 and 12:00pm to 12:00.  In my part of the
world, at least, that's commonly accepted as the right way to do it.
But the fact is that "12:00am" and "12:00pm" are poorly-defined; see
http://www.boulder.nist.gov/timefreq/general/misc.htm#Anchor-57026 .

>Also, the last line is superfluous, because all 12: got changed to 0:
>in the first line.

Yeah, you're right.  I added the first line long after adding the last
line and didn't realize it made the last line unnecessary.  (Actually,
I added the first line to handle the noon and midnight cases.)

And while we're on the subject of improving the code, it wouldn't be a
bad idea to add "i" after the last slash on the second and third
lines.

>Are you people testing this code before you post???

I tested it, and I got this output:

    12:00am -> 0:00
    1:00am -> 1:00
    2:00am -> 2:00
    3:00am -> 3:00
    4:00am -> 4:00
    5:00am -> 5:00
    6:00am -> 6:00
    7:00am -> 7:00
    8:00am -> 8:00
    9:00am -> 9:00
    10:00am -> 10:00
    11:00am -> 11:00
    12:00pm -> 12:00
    1:00pm -> 13:00
    2:00pm -> 14:00
    3:00pm -> 15:00
    4:00pm -> 16:00
    5:00pm -> 17:00
    6:00pm -> 18:00
    7:00pm -> 19:00
    8:00pm -> 20:00
    9:00pm -> 21:00
    10:00pm -> 22:00
    11:00pm -> 23:00

I believe this output to be correct.

  - Logan
-- 
"In order to be prepared to hope in what does not deceive,
 we must first lose hope in everything that deceives."

                                          Georges Bernanos


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

Date: Sun, 07 Oct 2001 20:46:24 GMT
From: "vbrammer" <vbrammer@home.com>
Subject: unix comm perl style
Message-Id: <Aa3w7.129607$Xz1.15829310@news1.rdc1.md.home.com>

hi,

Im trying to do with perl what the unix comm command can do.

    I have 2 files, the second is a subset of the first. I want to know what
the differance between the 2 files is.
each file has duplicate lines in itself, as in lines could be repeated
hundreds of times.

this is what i have, and it works :

 for (@log) {
  foreach $stat (@post) {
   if ($stat eq $_) {
    $true = 1;
   }
  last if ($true eq 1);
  }
  shift @post if ($true eq 1) || push @diff , $_;
  $true = 0;
 }

can this be written simpler? or quicker? if so please show me how.

thx

Vince




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

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


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