[21852] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4056 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 1 11:05:52 2002

Date: Fri, 1 Nov 2002 08:05:10 -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           Fri, 1 Nov 2002     Volume: 10 Number: 4056

Today's topics:
        'system' slow on Win9x? <bik.mido@tiscalinet.it>
    Re: 2 different results from while loop... <jurgenex@hotmail.com>
    Re: 2 different results from while loop... <flavell@mail.cern.ch>
    Re: 2 different results from while loop... <vm.mayer@comcast.net>
        Backticks, C++, and stdout <remccart@students.uiuc.edu>
    Re: Backticks, C++, and stdout (Helgi Briem)
    Re: Declaring 2 Dimensional Hashes <pinyaj@rpi.edu>
    Re: File truncating script <bowman@montana.com>
    Re: fill array with equal elements <rev_1318@hotmail.com>
    Re: fill array with equal elements <pilsl_use@goldfisch.at>
        Instal perl modules howto (sjaak538)
    Re: Instal perl modules howto (Helgi Briem)
    Re: Limit output of examine (x) and return (r) in debug (Mark Jason Dominus)
    Re: log files for previous month news@roaima.freeserve.co.uk
        Perl -e "print qq!    Tips and Tricks   !" (zzapper)
    Re: problem with hash content disappearing - unable to  <pjdouillard@videotron.ca>
        qx (or backticks) and Windows' titlebars <bik.mido@tiscalinet.it>
    Re: Search for a string while in PerlDoc? <pilsl_use@goldfisch.at>
    Re: Search for a string while in PerlDoc? <jurgenex@hotmail.com>
    Re: Serial Port <oracle@sympac.com.au>
        two digit date with local time <chris.harris@cwfi.co.fk>
    Re: two digit date with local time <tzz@lifelogs.com>
    Re: two digit date with local time <nospam@nospam.org>
    Re: two digit date with local time (Tad McClellan)
    Re: Why is this an infine loop??? <joe+usenet@sunstarsys.com>
    Re: Why is this an infine loop??? <joe+usenet@sunstarsys.com>
    Re: ~ Perl script output help ~ (Tad McClellan)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 01 Nov 2002 15:02:05 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: 'system' slow on Win9x?
Message-Id: <54v4su842l08ii1eeapad7282veevtokc5@4ax.com>

Still experimenting with perl... is it just my impression or launching
a command with 'system' is considerably slower under Windows (<2000,
Nt, etc.) than under Linux (et similia)? BTW: I've tried different
commands and "to be sure", I've been working only on Win's vfat fs
anyway.


Michele
-- 
Liberta' va cercando, ch'e' si' cara,
Come sa chi per lei vita rifiuta.
           [Dante Alighieri, Purg. I, 71-72]

I am my own country - United States Confederate of Me!
           [Pennywise, "My own country"]


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

Date: Fri, 01 Nov 2002 12:35:29 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: 2 different results from while loop...
Message-Id: <lyuw9.56927$wm6.7462@nwrddc01.gnilink.net>

parv wrote:
> in message <k2nw9.43155$iV1.38768@nwrddc02.gnilink.net>,
> wrote Jürgen Exner ...
>
>> havoc wrote:
>>> Okay, I got a text file that looks like this:
>>>
>>> -----
>>> 1                 #id number
>>> SomeUser          #username
>>> SomeUser's Info   #info on someuser
>>> -----
>>> 2
>>> OtherUser
>>> OtherUsers Info
> ...
>>>
>>> open(FILE,"somefile.txt");
>>> while(<FILE>){
>>>  my $id   = <FILE>;
>>>  my $name = <FILE>;
>>>  my $info = <FILE>;
>>>
>>>  print "Info on $name (ID: $id) - $info";
>>> }
>>> close(FILE);
>>>
>> That is a dirty programming trick:
>> The "while (<FILE>)" reads a line, too. And this happens to be the
>> line containing the dashes.
>>
>> This is not what I call error-tolerant programming and the
>> programmer who did that would not have passed my class.
>
> would using next & seek be any better?  below is pseudocode
>
>  - loop until end of the file
>      - skip current line if it matches "^-{5}$"
>      - else,
>          store current line in $id
>          seek next line; store it in $name
>          seek next line; store it in $info

Well, from a program design point of view you should always test that the
format of your input matches what you expect. The original programmer just
assumed that every fourth line would be the dash separator line. But he
didn't verify it.

So I guess something like a simple test (as the first line inside of the
loop)
    die "Wrong input file format: somefile.txt\n" unless chomp($_) eq
"-----";
should be enough.

jue




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

Date: Fri, 1 Nov 2002 13:59:04 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: 2 different results from while loop...
Message-Id: <Pine.LNX.4.40.0211011351580.6204-100000@lxplus076.cern.ch>


In addition to what's already been posted:

On Oct 31, havoc inscribed on the eternal scroll:

> open(FILE,"somefile.txt");

_Always_ test to find out whether it's succeeded:

  open(FILE,'somefile.txt') or die "unable to open somefile.txt: $!";

(avoid using double-quotes where no interpolation is required).

> while(<FILE>){
>  my $id   = <FILE>;
>  my $name = <FILE>;
>  my $info = <FILE>;

That really _was_ a dirty hack, though.  If I had somehow felt
motivated to write that (let's hope I wouldn't be) then I'd at least
have put a dirty-great comment to explain what was intended.



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

Date: Fri, 01 Nov 2002 08:26:31 -0500
From: Mike Mayer <vm.mayer@comcast.net>
Subject: Re: 2 different results from while loop...
Message-Id: <vm.mayer-813BC1.08263101112002@news-east.giganews.com>

In article <k2nw9.43155$iV1.38768@nwrddc02.gnilink.net>,
 "Jürgen Exner" <jurgenex@hotmail.com> wrote:
> That is a dirty programming trick:
> The "while (<FILE>)" reads a line, too. And this happens to be the line
> containing the dashes.
> 
> This is not what I call error-tolerant programming and the programmer who
> did that would not have passed my class.

And yet their are many times that I've found myself writing  
  quick/dirty, one-time-use, throw-away script that use this (and worse)
  "design patterns."

My point (ok.. pet peeve) I have worked on many occasions with newhires 
  who were unable to throw together quick scripts or apps to get a   
  specific job done.... Specifically because they were taught to NEVER 
  use "sloppy" coding.   

Note that I'm not talking about deliverable code or in-house tools 
supposed to have a long shelf life.  For these, I whole-heartedly agree 
with you that these should be error tolerant and forward looking.

mike


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

Date: Fri, 1 Nov 2002 08:48:09 -0600
From: Ryan E Mcarthy <remccart@students.uiuc.edu>
Subject: Backticks, C++, and stdout
Message-Id: <Pine.GSO.4.31.0211010845200.2972-100000@ux10.cso.uiuc.edu>

I am trying to capture the stdout of a compiled C++ function but am
failing to figure out how.  I was trying to do it in this manner:

$output = 'program options';

However, my $output is always empty.  The output needs to be a string and
the main in C++ can only return an integer (obviously).  So what's a
brother supposed to do?

-- 
R.E.M.C.C.A.R.T: Robotic Electronic Machine Calibrated for Ceaseless
Assassination and Rational Troubleshooting






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

Date: Fri, 01 Nov 2002 15:17:26 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Backticks, C++, and stdout
Message-Id: <3dc2991f.1425518447@news.cis.dfn.de>

On Fri, 1 Nov 2002 08:48:09 -0600, Ryan E Mcarthy
<remccart@students.uiuc.edu> wrote:

>I am trying to capture the stdout of a compiled C++ function but am
>failing to figure out how.  I was trying to do it in this manner:
>
>$output = 'program options';
>
>However, my $output is always empty.  

Use backticks, not single quotes.  Of course, that
will only work for executable programs, not functions.
For actual functions you need XS or Inline::C, I
believe, but that is outside my area of knowledge.

my $output = `program options`;

I actually prefer to use the qx (quote execute) operator
instead of backticks because they catch the eye of the
inexperienced programmer better.

my $output = qx(program options);

>The output needs to be a  string and the main in C++ 
>can only return an integer (obviously).  

I'm afraid that's not obvious to me but then I 
don't know C++.

-- 
Regards, Helgi Briem
helgi AT decode DOT is

                           A: Top posting
                           Q: What is the most irritating thing on Usenet?
                                           - "Gordon" on apihna


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

Date: Fri, 1 Nov 2002 09:27:50 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Hal Vaughan <hal@thresholddigital.com>
Subject: Re: Declaring 2 Dimensional Hashes
Message-Id: <Pine.A41.3.96.1021101092426.61726A-100000@vcmr-104.server.rpi.edu>

[posted & mailed]

On Fri, 1 Nov 2002, Hal Vaughan wrote:

>So it's not a 2 dimensional hash, but a hash of hashes?  I think I see.  
>Thanks.  (I'm self taught -- I've never had any background on data 
>structures and sometimes it can get a bit confusing.)

The big difference between C's multi-dimensional data structures and
Perl's is that in C, an array like

  char foo[10][10];

is allocated all in one block, and when you access foo[i][j], you're
really accessing foo[i*10 + j], because of how pointers work in C.  In
Perl, you're not using pointers, but references.  In Perl, an array of 10
array references looks like:

  @foo = (REF, REF, REF, REF, REF, REF, REF, REF, REF, REF);

where each REF gives the location to look for the underlying array.  A
book like "Effective Perl Programming" (by Hall and Schwartz, pub. by
Addison-Weseley) uses a diagramming method called "PEGS" to visually
explain references.  It does an excellent job, in my opinion.

-- 
Jeff "japhy" Pinyan      RPI Acacia Brother #734      2002 Acacia Senior Dean
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

Date: Fri, 01 Nov 2002 07:44:53 -0700
From: bowman <bowman@montana.com>
Subject: Re: File truncating script
Message-Id: <apu3in$4vf27$1@ID-159066.news.dfncis.de>

Bob wrote:
> 
> The script works, but it seems a bit slow when processing large files.
> Im not sure this can be improved too much, but if someone could tell me
> in what way I can optimize the code or give a general critique that
> would be great.

if you are not concerned with a particular date range, and just want to 
trim to a size, fseek to the position and work with a chunk or chunks 
rather than lines. if you want to be neat, work from the fseek to find a 
newline so you don't truncate a line.

if you have the memory, you could fseek, read in the rest of the file, seek 
to the beginning, write it out, and truncate the file to do it in position.



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

Date: Fri, 01 Nov 2002 13:44:03 +0100
From: Paul van Eldijk <rev_1318@hotmail.com>
Subject: Re: fill array with equal elements
Message-Id: <aptstv$ekg$1@odysseus.uci.kun.nl>

peter pilsl wrote:


> for building a database-test-suite I need to fill mediumsized arrays
> (1000-10000 elements) with equal values very often:
> 
> foreach (1..10000) {push(@array,$value);}
> 
> So this is very slow. I was thinking about alternatives, but all  I
> found are very slow (see my script below). Suprisingly the fastet way
> was to create a string using the 'x'-operator and then split it. So I'm
[snip]

Now why would create a string and then split is again?!
The following should work:

my @array = ($value) x 10000;

Don't know if it's the fastest way though..


HTH,
Paul

-- 
            ''' 
           (0 0) 
+----oOO----(_)----------+ 
|  Paul van Eldijk       | 
|  rev_1318@hotmail.com  | 
+-----------------oOO----+ 
          |__|__| 
           || || 
          ooO Ooo 

RTFM: No just an acronym, it's the LAW!


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

Date: Fri, 1 Nov 2002 13:58:30 +0100
From: peter pilsl <pilsl_use@goldfisch.at>
Subject: Re: fill array with equal elements
Message-Id: <3dc27a92$1@e-post.inode.at>

Paul van Eldijk wrote:
> 
> my @array = ($value) x 10000;
> 

I was sure that there is an easy solution but I didnt dream of such an easy 
and obvious one ..

Its about twice as fast as all the other solutions and I think there is no 
faster one.

thnx,
peter

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



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

Date: 1 Nov 2002 05:40:34 -0800
From: sjaak538@yahoo.com (sjaak538)
Subject: Instal perl modules howto
Message-Id: <dfb0d959.0211010540.3c73cc52@posting.google.com>

Hi

I like to install a module  IC::Radius into perl.
Everything seems to be fine but I get the following message in my http
error_log

Fri Nov  1 15:35:05 2002] [error] [client 212.104.194.3] Premature end
of script headers: /var/www/cgi-bin/radius.cgi
Can't locate IC/Radius.pm in @INC (@INC contains:
/usr/lib/perl5/5.6.0/i386-linux /usr/lib/perl5/5.6.0
/usr/lib/perl5/site_perl/5.6.0/i386-linux
/usr/lib/perl5/site_perl/5.6.0 /usr/lib/perl5/site_perl) at
/var/www/cgi-bin/radius.cgi line 60.
BEGIN failed--compilation aborted at /var/www/cgi-bin/radius.cgi line
60.
[Fri Nov  1 15:35:09 2002] [error] [client 212.104.194.3] Premature
end of script headers: /var/www/cgi-bin/radius.cgi

location of Radius.pm
/usr/lib/perl5/5.6.0/i386-linux/IC/Radius.pm
/usr/lib/perl5/5.6.0/i386-linux/Radius.pm
/usr/lib/perl5/site_perl/5.6.0/i386-linux/Radius.pm
/usr/lib/perl5/site_perl/5.6.0/IC/Radius.pm
/usr/lib/perl5/site_perl/5.6.0/Radius.pm

What can be wrong ?
How and where is the module list ?
What's the @INC file and where is this file 

Thnxs

Sjaak


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

Date: Fri, 01 Nov 2002 13:58:51 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Instal perl modules howto
Message-Id: <3dc286f5.1420868100@news.cis.dfn.de>

On 1 Nov 2002 05:40:34 -0800, sjaak538@yahoo.com (sjaak538)
wrote:

>I like to install a module  IC::Radius into perl.

You can do this three ways:

1) Download from search.cpan.org, untar, then follow 
instructions in readme document.  

2) Use the CPAN module.  That will have to be installed
by hand as above though and configured correctly.
Then you can run
perl -MCPAN -eshell '
[cpan] install IC::Radius

3) If you have the Perl distribution from activestate.com,
that has a program called ppm (Perl Package Manager)
that can simply:
ppm install IC::Radius

If you are not root on the machine, read:
perldoc -q "my own module"

>Everything seems to be fine but I get the following message in my http
>error_log
>
>Fri Nov  1 15:35:05 2002] [error] [client 212.104.194.3] Premature end
>of script headers: /var/www/cgi-bin/radius.cgi
>Can't locate IC/Radius.pm in @INC (@INC contains:
-- 
Regards, Helgi Briem
helgi AT decode DOT is

                           A: Top posting
                           Q: What is the most irritating thing on Usenet?
                                           - "Gordon" on apihna


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

Date: Fri, 1 Nov 2002 15:08:11 +0000 (UTC)
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Limit output of examine (x) and return (r) in debugger.
Message-Id: <apu5cr$tqf$1@plover.com>

In article <s0p1suknk1di5bra5o49upar5pejlr7tcb@4ax.com>,
Teh (tî'pô) <teh@mindless.com> wrote:
>Mark Jason Dominus bravely attempted to attach 23 electrodes of
>knowledge to the nipples of comp.lang.perl.misc by saying:
>
>>However, this is only available in Perl version 5.7.3 and later.
>
>Sadly I'm using an older version.


But you can obtain the perl5db.pl from 5.8.0 and use it instead of the
one you were using, without having to change the version of Perl you
are using.


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

Date: Fri, 1 Nov 2002 15:38:17 +0000
From: news@roaima.freeserve.co.uk
Subject: Re: log files for previous month
Message-Id: <957upa.g19.ln@moldev.cmagroup.co.uk>

Desmond Coughlan <pasdespam_desmond@zeouane.org> wrote:
> A friend of mine uses my webserver for virtual hosting. [...]
> (it's an apache box) 

Not a Perlish answer, but if it's your webserver, you could always get
Apache to put your friend's virtual host accesses in a different log
file. That way you wouldn't have to split them out - Apache would have
already done it for you.

Chris
-- 
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}


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

Date: 1 Nov 2002 08:02:02 -0800
From: david@tvis.co.uk (zzapper)
Subject: Perl -e "print qq!    Tips and Tricks   !"
Message-Id: <f677762.0211010802.2c7952a6@posting.google.com>

Hi

perl -e "print join \" \a\",(map {ucfirst} map {lc} split /@/,reverse
'REKCAH@LREP@REHTONA@TSUJ')"

I'd like to get a tr/// or s/// in above so as to make it even more
tricky, but it never works (either swallows output or fails or counts)

Any tips welcomed

zzapper


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

Date: Fri, 01 Nov 2002 07:28:03 -0500
From: P.J <pjdouillard@videotron.ca>
Subject: Re: problem with hash content disappearing - unable to debug and find why - weird behavior
Message-Id: <eas4su4469rlcd4pusgjnakvbsmnc2b631@4ax.com>

I'm using the debugger with the '-d' option of perl.exe that I d/l
from ActiveState.  

I guess this is not the native perl debugger?  Or is it?

Forgot those, my mistake.  I was washed yesterday because of
this problem that I'm trying so solve since 2 days...

Here they are:

sub fixGroup {
	my ($group) = @_;
	
	# remove first '-' from the end
	$group =~ s/(.*)(-)(.*$)/$1$3/;  
	
	return $group;
}

sub getSuffix {
	my ($dirFile) = @_;
	
	# Generate a suffix according to the $dirFile entry received
	
	if ($dirFile =~ /full-control/i) {
		return "FL";
	}
	if ($dirFile =~ /change/i) {
			return "CH";
	}
	if ($dirFile =~ /read/i) {
			return "RD";
	}
	if ($dirFile =~ /list/i) {
			return "LS";
	}
	if ($dirFile =~ /no-access/i) {
			return "NO";
	}
	if ($dirFile =~ /add/i) {
			return "ad";
	}
	if ($dirFile =~ /add&read/i) {
			return "AR";
	}
	else {
		return "SP";
	}
}

On 01 Nov 2002 05:38:11 GMT, "James E Keenan" <jkeen@concentric.net>
wrote:

>
>"P.J Douillard" <pjdouillard@snclavalin.com> wrote in message
>news:4f351142.0210311935.5dbb66db@posting.google.com...
>> For starters, I'm using the latest ActivePerl, and I'm running it on
>> W2K sp3.  And I'm kind of new to Perl.
>>
>[snip]
>> NOTE: If you notice that I'm not using 'things' correctly, please, let
>> me know.
>>
>
>I couldn't fully test your script because it contains two undefined
>subroutines here:
>
>    $tempLocalGroupName =
>'L01'.&genLocalName($path).'01-'.&getSuffix($dirFile);
>
>My initial impression is that your debugging problem may stem from the
>length of the subroutine.  Consider breaking this down into several
>component subroutines and testing each individually before combining them
>into a larger structure.
>
>Are you using Perl's native debugger or the ActivePerl debugger?
>



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

Date: Fri, 01 Nov 2002 15:02:07 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: qx (or backticks) and Windows' titlebars
Message-Id: <i105su02bge21b0rheljvv2u65a0m6alv0@4ax.com>

Just curious: when I run an external command with qx, the titlebar of
the dos prompt window (well, if I run it in a window) shows the name
of the command rather than 'perl'. Why is it?


Michele
-- 
Liberta' va cercando, ch'e' si' cara,
Come sa chi per lei vita rifiuta.
           [Dante Alighieri, Purg. I, 71-72]

I am my own country - United States Confederate of Me!
           [Pennywise, "My own country"]


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

Date: Fri, 1 Nov 2002 13:33:23 +0100
From: peter pilsl <pilsl_use@goldfisch.at>
Subject: Re: Search for a string while in PerlDoc?
Message-Id: <3dc274b0$1@e-post.inode.at>

Jim Ryan wrote:

> [This followup was posted to comp.lang.perl.misc and a copy was sent to
> [the cited author.]
> 
> How do I do this?  If I'm reading about something lengthy in perldoc and
> want to find a string within it, what do I type at the --more-- prompt?
> 

You use the same like you use in VIM or at the more/less - prompt:

/ ... search forward
? ... search backward
n ... search next

the most important command is 'h' cause it pops up the help-page where you 
find all the other commands.

best
peter

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



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

Date: Fri, 01 Nov 2002 12:40:24 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Search for a string while in PerlDoc?
Message-Id: <YCuw9.56955$wm6.39790@nwrddc01.gnilink.net>

Jim Ryan wrote:
> [This followup was posted to comp.lang.perl.misc and a copy was sent
> to the cited author.]
>
> How do I do this?  If I'm reading about something lengthy in perldoc
> and want to find a string within it, what do I type at the --more--
> prompt?

That depends solely upon which utility you are using as "more". Is it the
original "more"? Is it "less"? Is it GNU "more"? .....
Check the man page for your paginator.

jue




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

Date: Fri, 01 Nov 2002 22:15:47 +1100
From: oracle <oracle@sympac.com.au>
Subject: Re: Serial Port
Message-Id: <aptnmb$9m$1@perki.connect.com.au>

Tan Nguyen wrote:

> 
> "oracle" <oracle@sympac.com.au> wrote in message
> news:api58k$ali$1@perki.connect.com.au...
>> Hi all
>>
>> Am planning a program to talk to a weather station via the serial port on
> an
>> intel box and cannot find out how to talk to the serial port.
>>
>> Its gotta be easy but i can't find it. Any body help ?
>>
>> Just need the setup of the port, and how to send receive data from the
> port.
>>
>> Thanks
>> oracle
> 
> sockets don't work for you? Are transfered data in binary format?

The device I am talking to will be connect via the serial port and I will be 
receiving data in bytes from the unit at specific intervals. The weather 
station device will only send binary data via serial (Typical 8N1 9600 
baud). How does or would sockets fit in ?


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

Date: Fri, 1 Nov 2002 11:58:52 -0300
From: "Chris Harris" <chris.harris@cwfi.co.fk>
Subject: two digit date with local time
Message-Id: <apu4t7$4trc7$1@ID-134007.news.dfncis.de>

Hi,

How do I get the parts of the string returned from the localtime function to
alway be in 2 digit format.

For example I have

my ($day, $hour, $min) = (localtime)[3,2,1];

Then later I use to create a filename

open O ">images/webcam/$day-$hour-$min.jpg";

problem is that I don't get the leading 0 for values 0 - 9.
e.g. today at 9:05 comes out as 1-9-5, what I want is 01-09-05.

All suggestions welcomed

Chris




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

Date: Fri, 01 Nov 2002 10:38:55 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: two digit date with local time
Message-Id: <4ny98djo4w.fsf@benko.bwh.harvard.edu>

On Fri, 1 Nov 2002, chris.harris@cwfi.co.fk wrote:
> How do I get the parts of the string returned from the localtime
> function to alway be in 2 digit format.
> 
> For example I have
> 
> my ($day, $hour, $min) = (localtime)[3,2,1];
> 
> Then later I use to create a filename
> 
> open O ">images/webcam/$day-$hour-$min.jpg";
> 
> problem is that I don't get the leading 0 for values 0 - 9.
> e.g. today at 9:05 comes out as 1-9-5, what I want is 01-09-05.

"perldoc POSIX", look for the strftime() function.  Your system
probably also has a strftime manpage.  What you need for the filename
is probably:

strftime("images/webcam/%d-%H-%M.jpg", localtime);

Ted


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

Date: Fri, 1 Nov 2002 10:38:26 -0500
From: "Christian Caron" <nospam@nospam.org>
Subject: Re: two digit date with local time
Message-Id: <apu75i$mi312@nrn2.NRCan.gc.ca>


"Chris Harris" <chris.harris@cwfi.co.fk> wrote in message
news:apu4t7$4trc7$1@ID-134007.news.dfncis.de...
> Hi,
>
> How do I get the parts of the string returned from the localtime function
to
> alway be in 2 digit format.
>
> problem is that I don't get the leading 0 for values 0 - 9.
> e.g. today at 9:05 comes out as 1-9-5, what I want is 01-09-05.

If on a Unix box, you could use:

chop(my $date = `date +"%Y-%m-%d"`); # returns 2002-11-01

Good luck!




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

Date: Fri, 1 Nov 2002 09:49:59 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: two digit date with local time
Message-Id: <slrnas58l7.3je.tadmc@magna.augustmail.com>

Chris Harris <chris.harris@cwfi.co.fk> wrote:

> my ($day, $hour, $min) = (localtime)[3,2,1];

> problem is that I don't get the leading 0 for values 0 - 9.


   my ($day, $hour, $min) = map sprintf("%02d", $_), (localtime)[3,2,1];


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


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

Date: 01 Nov 2002 07:21:33 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Why is this an infine loop???
Message-Id: <m3znstmqeq.fsf@mumonkan.sunstarsys.com>

Brian McCauley <nobull@mail.com> writes:

[...]

> Since you have found something that appears to be a bug in Perl you
> should try to generate a _minimal_ but _complete_ (strict, warning
> free) script that other people could run and that you have found will
> actually reproduce the symptoms on your system.  Post it _unaltered_
> together with at least some version information.
> 
> For example the following script does _not_ reproduce the problem on
> 5.6.1 or 5.8.0 on Linux.

> #!/usr/bin/perl

And be sure to say whether or not you are using taint checks (-T).
Tainted hash/array entries are known to cause this behavior in pre-5.8
perls.

-- 
Joe Schaefer               "Buy land.  They've stopped making it."
                                               --Mark Twain



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

Date: 01 Nov 2002 07:55:03 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Why is this an infine loop???
Message-Id: <m3vg3hmouw.fsf@mumonkan.sunstarsys.com>

Joe Schaefer <joe+usenet@sunstarsys.com> writes:

[...]

> And be sure to say whether or not you are using taint checks (-T).
> Tainted hash/array entries are known to cause this behavior in pre-5.8
> perls.

  s/pre-5.8/modern/; 

Just checked- this bug isn't fixed in 5.8 either.

-- 
Joe Schaefer   "The difference between the right word and the almost right word
                 is the difference between lightning and the lightning bug."
                                               --Mark Twain



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

Date: Fri, 1 Nov 2002 09:54:24 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: ~ Perl script output help ~
Message-Id: <slrnas58tg.3je.tadmc@magna.augustmail.com>

inderjit s gabrie <igabrie@mis.gla.ac.uk> wrote:

> Subject: Re: ~ Perl script output help ~
               ^                         ^
               ^                         ^

You should not try and "trick" people into reading your article.

Such things are very likely to have an effect opposite of
what you were hoping to achieve by employing them.

That is, _less_ people read your article when you do that, not more people.


> This is a multi-part message in MIME format.


But Usenet is a plain text medium. Please don't post MIME.


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


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

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


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