[29858] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1101 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Dec 9 21:09:47 2007

Date: Sun, 9 Dec 2007 18:09:07 -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           Sun, 9 Dec 2007     Volume: 11 Number: 1101

Today's topics:
    Re: FAQ 4.63 How do I reset an each() operation part-wa <xueweizhong@gmail.com>
    Re: FAQ 4.63 How do I reset an each() operation part-wa <brian.d.foy@gmail.com>
    Re: How can I print a number larger than 128? (Doug Miller)
    Re: How can I print a number larger than 128? <m@rtij.nl.invlalid>
        How to easily append a timestamp to tar archive name ? (Matthew Lincoln)
    Re: How to easily append a timestamp to tar archive nam <thepoet_nospam@arcor.de>
    Re: How to easily append a timestamp to tar archive nam <martin.klar@web.de>
    Re: How to easily append a timestamp to tar archive nam <ben@morrow.me.uk>
    Re: How to easily append a timestamp to tar archive nam <ZekeGregory@netscape.net>
    Re: How to easily append a timestamp to tar archive nam <john@castleamber.com>
    Re: Multi phase processing <ben@morrow.me.uk>
    Re: Problem in LDAP authentication <hjp-usenet2@hjp.at>
    Re: Questions about the operator \(...) <ben@morrow.me.uk>
    Re: Questions about the operator \(...) <xueweizhong@gmail.com>
    Re: Questions about the operator \(...) <ben@morrow.me.uk>
    Re: Questions about the operator \(...) <nospam-abuse@ilyaz.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 9 Dec 2007 01:37:14 -0800 (PST)
From: Todd <xueweizhong@gmail.com>
Subject: Re: FAQ 4.63 How do I reset an each() operation part-way through?
Message-Id: <b745faa2-30d2-4e3f-8fc9-86f4e23f3263@e23g2000prf.googlegroups.com>



> But the sub just moves the idiom out of the line
> of sight. Even the sub name is cryptic unless you can guess what the
> shorthand "rhi" stands for... but then you'd  likely know something
> about iterators and how  they work. A simple inline comment is a
> clearer, more direct reminder of
> the idiom IMO.
>
Yes, hope perl6 provide a useful name for this.

-Todd


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

Date: Sun, 09 Dec 2007 11:43:23 -0600
From: brian d  foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 4.63 How do I reset an each() operation part-way through?
Message-Id: <091220071143233413%brian.d.foy@gmail.com>

In article
<09923d1e-7f11-46f6-aea7-26a0215fc6ed@d27g2000prf.googlegroups.com>,
Todd <xueweizhong@gmail.com> wrote:

> First, void context is an special case of scalar context. I prefer
> using comment for this trick:

Void context is not a special case of scalar context. Note the
documenation of keys: in void context it only resets the iterator.

Despite that, the answer is half-wrong and out-of-date, so I've updated
it.


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

Date: Sun, 09 Dec 2007 22:25:59 GMT
From: spambait@milmac.com (Doug Miller)
Subject: Re: How can I print a number larger than 128?
Message-Id: <SXZ6j.31589$Pv2.17624@newssvr23.news.prodigy.net>

In article <pkC6j.10305$OR.7977@trnddc01>, QoS@domain.invalid wrote:
>
>spambait@milmac.com (Doug Miller) wrote in message-id: 
> <6bA6j.5046$fl7.3162@newssvr22.news.prodigy.net>
>
>> 
>> In article <Jzy6j.1032$bW.927@trnddc07>, QoS@domain.invalid wrote:
>> >
>> >kun niu <haoniukun@gmail.com> wrote in message-id: 
>> > <23f658ee-76ed-4d2f-b77c-de62ade9bcae@d27g2000prf.googlegroups.com>
>> >
>> >> 
>> >> Dear all,
>> >> I'm new here.
>> >> I've got a number larger than 128.
>> >> I want to send it by socket.
>> >> I find that if print the number directly, I'll print the number in
>> >> ascii format.
>> >> So I'll have 3 separate numbers transmitted.
>> >> But I only want to transmit one byte.
>> >> How can I do so?
>> >> 
>> >> Thanks for any help.
>> >
>> >You can try developing a compression algo or else use one off the shelf.
>> 
>> Why would that be necessary?
>> 
>> >Something that reduces the need for consecutive zeros or ones.
>> 
>> Why would that be necessary?
>> 
>> >The one byte constraint is more than a bit limiting though.
>> 
>> Huh? One byte = 8 bits, which can hold values up to 2^8 - 1 = 255. All he 
>> needs to do is send it in binary.
>> 
>
>cause the OP says that he wishes to send _only one byte_
>

And your point would be....?

255 > 128, last time I checked.



-- 
Regards,
        Doug Miller (alphageek at milmac dot com)

It's time to throw all their damned tea in the harbor again.


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

Date: Mon, 10 Dec 2007 00:08:18 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: How can I print a number larger than 128?
Message-Id: <pan.2007.12.09.23.08.18@rtij.nl.invlalid>

On Sun, 09 Dec 2007 22:25:59 +0000, Doug Miller wrote:

>>> >The one byte constraint is more than a bit limiting though.
>>> 
>>> Huh? One byte = 8 bits, which can hold values up to 2^8 - 1 = 255. All
>>> he needs to do is send it in binary.
>>> 
>>> 
>>cause the OP says that he wishes to send _only one byte_
>>
>>
> And your point would be....?
> 
> 255 > 128, last time I checked.

Ah I see it now. The OP wants to send a number GREATER than 128. If that 
number is < 256, one byte will do. Otherwise if < 384, just subtract 128 
and send it in byte. Otherwise, without more information, it seems 
impossible.

M4


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

Date: 09 Dec 2007 12:18:14 GMT
From: mlincoln100@hotmail.com (Matthew Lincoln)
Subject: How to easily append a timestamp to tar archive name ?
Message-Id: <475bdd06$0$16663$9b4e6d93@newsspool3.arcor-online.net>

I would like to create a tar archive with the well known tar command

tar czvf "/usr/local/user234/bkp.tar.gz" /home/users/pmiller/

It works. However I would like to automatically append a timestamp whenever I call this command
in a (perl) script.

The created archive file name should look like

bkp-20071109-1523.tar.gz

Where the format is preferred as YYYYMMDD-HHMM

Does Gnu-tar offer such an automatic timestamp appending?

If not: Is there a (short) work around (in perl) which let me create such a timestamp?

Thank you
Matthew


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

Date: Sun, 09 Dec 2007 15:38:42 +0100
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: How to easily append a timestamp to tar archive name ?
Message-Id: <475bfc5c$0$17523$9b4e6d93@newsspool4.arcor-online.net>

Matthew Lincoln wrote:
> I would like to create a tar archive with the well known tar command
> 
> tar czvf "/usr/local/user234/bkp.tar.gz" /home/users/pmiller/
> 
> It works. However I would like to automatically append a timestamp whenever
 > I call this command in a (perl) script.
> 
> The created archive file name should look like
> 
> bkp-20071109-1523.tar.gz
> 
> Where the format is preferred as YYYYMMDD-HHMM
> 
> Does Gnu-tar offer such an automatic timestamp appending?
> 
> If not: Is there a (short) work around (in perl) which let me create such
 > a timestamp?

The POSIX module supplies you with the strftime() function.
In your case, something like

use POSIX;

my $tarfile = strftime('bkp-%Y%m%d-%H%M.tar.gz', localtime(time));

should do the trick nicely. See "perldoc POSIX" for details.

-Chris


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

Date: Sun, 09 Dec 2007 16:34:26 +0100
From: Martin Klar <martin.klar@web.de>
Subject: Re: How to easily append a timestamp to tar archive name ?
Message-Id: <5s2g81F177fjdU1@mid.individual.net>

Matthew Lincoln schrieb:
> I would like to create a tar archive with the well known tar command
> 
> tar czvf "/usr/local/user234/bkp.tar.gz" /home/users/pmiller/
> 
> It works. However I would like to automatically append a timestamp whenever I call this command
> in a (perl) script.
> 
> The created archive file name should look like
> 
> bkp-20071109-1523.tar.gz
> 
> Where the format is preferred as YYYYMMDD-HHMM
> 
> Does Gnu-tar offer such an automatic timestamp appending?

AFAIK no.

Assuming you are using a bash you could solve it by:

tar czvf "/usr/local/user234/bkp-$(date +%Y%m%d-%H%M).tar.gz" /home/users/pmiller/

It *should* also work when called from a perl script, but I didn't test it.


HTH Martin


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

Date: Sun, 9 Dec 2007 16:43:09 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How to easily append a timestamp to tar archive name ?
Message-Id: <thit25-ab2.ln1@osiris.mauzo.dyndns.org>


Quoth Martin Klar <martin.klar@web.de>:
>
> Assuming you are using a bash you could solve it by:
> 
> tar czvf "/usr/local/user234/bkp-$(date +%Y%m%d-%H%M).tar.gz"
> /home/users/pmiller/
> 
> It *should* also work when called from a perl script, but I didn't test it.

Not with that syntax :).

Something like

    system 'tar', 'czvf', (
        '/usr/local/user234/bkp-' . qx(date +%Y%m%d-%H%M) . '.tar.gz'
    ), '/home/users/pmiller/';

or
    system sprintf 'tar cvf "/usr/.../bkp-%s.tar.gz" /home/...',
        qx(date +%Y%,%d-%H%M);

would work, but it would be better to do it from within Perl using
POSIX::strftime.

Ben



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

Date: Mon, 10 Dec 2007 07:25:27 +1100
From: Gregory Shearman <ZekeGregory@netscape.net>
Subject: Re: How to easily append a timestamp to tar archive name ?
Message-Id: <3010051.kfzsOfQ4sc@netscape.net>

Matthew Lincoln wrote:

> I would like to create a tar archive with the well known tar command
> 
> tar czvf "/usr/local/user234/bkp.tar.gz" /home/users/pmiller/
> 
> It works. However I would like to automatically append a timestamp
> whenever I call this command in a (perl) script.
> 
> The created archive file name should look like
> 
> bkp-20071109-1523.tar.gz
> 
> Where the format is preferred as YYYYMMDD-HHMM
> 
> Does Gnu-tar offer such an automatic timestamp appending?
> 
> If not: Is there a (short) work around (in perl) which let me create such
> a timestamp?
> 
> Thank you
> Matthew

==================================

#!/your/perl/path

use strict;
use warnings;
use POSIX qw(strftime);

my $now_string = strftime "%Y%m%d-%H%M", localtime;

my $your_filename = "bkp-".$now_string".tar.gz

==================================

man perlfunc

man strftime

-- 
Regards,

Gregory.
Gentoo Linux - Penguin Power


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

Date: 9 Dec 2007 20:44:47 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: How to easily append a timestamp to tar archive name ?
Message-Id: <Xns9A019604763B8castleamber@130.133.1.4>

Gregory Shearman <ZekeGregory@netscape.net> wrote:

 
> my $your_filename = "bkp-".$now_string".tar.gz

O_o too much PHP?

my $your_filename = "bkp-$now_string.tar.gz";

or to make the scalar stand out a bit more:

my $your_filename = "bkp-${now_string}.tar.gz";

or, if you insist on  . :

my $your_filename = 'bkp-' . $now_string . '.tar.gz';


-- 
John

Arachnids near Coyolillo - part 1
http://johnbokma.com/mexit/2006/05/04/arachnids-coyolillo-1.html


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

Date: Sun, 9 Dec 2007 13:54:24 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Multi phase processing
Message-Id: <gl8t25-vm1.ln1@osiris.mauzo.dyndns.org>


Quoth Dave Stratford <daves@orpheusmail.co.uk>:
> My problem is that part of the data is dynamically generated, and I
> cannot, currently, see an obvious way to drop it into hidden fields. (Or
> for that matter cookies!)

You can serialize any Perl data structure with e.g. Storable +
MIME::Base64, or Data::Dumper, or YAML, and put the result into a single
hidden field. The outcome is rather similar to using a session ID in a
hidden field, except you have to send all the data down to the client
all the time.

Ben



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

Date: Sun, 9 Dec 2007 13:49:49 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Problem in LDAP authentication
Message-Id: <slrnflnp3h.j0r.hjp-usenet2@hrunkner.hjp.at>

On 2007-12-08 23:53, Big and Blue <No_4@dsl.pipex.com> wrote:
>     To valid date with LDAP:
>
> a) Open an *anonymous* connexion
> b) search() for the given id with a relevant base (so probably the 
> ou=active,ou=employees,ou=people,o=abc.com" you mention)
> c) check that you get one, and only one, result from b) and get the dn 
> (distinguished name)
> d) bind using the dn and the given password
> e) check whether d) succeeds
>
> If your LDAP server doesn't allow anonymous connexions then a) needs to be 
> done using a known (to you) LDAP dn + password (so not allowing anon 
> connexions is a bit silly, since you'd need to supply all clienst with an 
> known id/pwd anyway).

If there is a known mapping from the given id to the DN you can skip
steps a) to c). Just compute the DN from the id, then do steps d) and
e). Voila, no anonymous access needed.

	hp



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

Date: Sun, 9 Dec 2007 13:49:20 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Questions about the operator \(...)
Message-Id: <0c8t25-vm1.ln1@osiris.mauzo.dyndns.org>


Quoth Todd <xueweizhong@gmail.com>:
> 
> > perldoc perlref
> I don't think perlref have the explanation about this.

It's not terribly obvious: I had to read it several times before I found
it. It's in "Making References", item 2 (about []):

   Taking a reference to an enumerated list is not the same as using
   square brackets‐‐instead it’s the same as creating a list of refer‐
   ences!

       @list = (\$a, \@b, \%c);
       @list = \($a, @b, %c);      # same thing!

   As a special case, "\(@foo)" returns a list of references to the
   contents of @foo, not a reference to @foo itself.  Likewise for
   %foo, except that the key references are to copies (since the keys
   are just strings rather than full‐fledged scalars).

The 'special case' is actually backwards here: one would expect (@foo)
to interpolate the contents of @foo, so it's \(@foo, @bar) (and \@foo
itself, of course) that is the special case. It applies to any literal
list with more than one specified element as the argument to \,
including lists inside more parens and lists inside 'my', 'our', 'state'
and '+', but excluding lists inside 'do'. 

> Let me make my example clearer:

I think it was quite clear already. The behaviour is inconsistent and
slightly odd, but useful, as with much of Perl.

<snip>
>     @a = (aa, bb, cc);
>     sub foo {@a}
<snip>
>     print '\\foo:    ', \foo;
>     print '\\(foo):  ', \(foo);
>     print '\\(foo,1):', \(foo, 1);
<snip>
>     \foo:    SCALAR(0x10410e54)SCALAR(0x1042ec84)SCALAR(0x1042ec78)
>     \(foo):  SCALAR(0x10410e54)SCALAR(0x1042ec84)SCALAR(0x1042ec78)
>     \(foo,
> 1):SCALAR(0x10410e54)SCALAR(0x1042ec84)SCALAR(0x1042ec78)SCALAR(0x1042ecb4)

\ passes list context to its argument (check with wantarray) so these
are all as expected.

> From the results, I see that \@a and \(@a,1) are the different from
> others. So i do think it's defined by syntax sugar for some special
> usages. We can only treat them as syntax ruls, there are no expression
> meaning here.

If you think about it, the evaluation of \ has to be rather special. @a
will normally evaluate to either its contents or its length, neither of
which lets you get a reference to array as a whole. The exception is the
behaviour of functions like 'push', which, at least nowadays, can be
understood in terms of prototypes, which are defined in terms of \.

Ben



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

Date: Sun, 9 Dec 2007 06:36:28 -0800 (PST)
From: Todd <xueweizhong@gmail.com>
Subject: Re: Questions about the operator \(...)
Message-Id: <a51132ee-4011-4346-9d04-6f206d95f336@e23g2000prf.googlegroups.com>

Thanks, Ben.

But it seems that i'm not smart enough to understand these. I know for
Perl, in many places, syntax wins over expression explanation like
context, .... Hmm, but Perl doesn't have fixed sytax, right?

But anyway, it's Perl, just like any human language...

-Todd


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

Date: Sun, 9 Dec 2007 16:39:06 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Questions about the operator \(...)
Message-Id: <aait25-ab2.ln1@osiris.mauzo.dyndns.org>


Quoth Ben Morrow <ben@morrow.me.uk>:
> 
>    Taking a reference to an enumerated list is not the same as using
>    square brackets‐‐instead it’s the same as creating a list of refer‐

GAH @groff for adding fancy Unicode formatting! I didn't realise and
failed to set the Content-type: sorry.

Ben



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

Date: Sun, 9 Dec 2007 21:46:06 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Questions about the operator \(...)
Message-Id: <fjhnmu$ls0$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Uri Guttman 
<uri@stemsystems.com>], who wrote in article <x7sl2daxu3.fsf@mail.sysarch.com>:
> \ distributes over the syntactical elements in the following
> parenthesized list. so it will work with \(@x, @y) and return \@x and
> \@y. it is trivial to distribute \ over the expanded elements of the
> list with map \$_, @x, @y. so consider the behavior as a syntactical
> shortcut as you can get the other semantics with map. i still have never
> seen a real world need or use of \() with distribution.
> 
> if there is only a single syntactical element inside the \(@x) it will
> distribute over the array's elements since making that be the same as
> \@x would be redundant.
> 
> not the most consistant thing but the choices larry made make the most
> flexible use of the concept and syntax.

Allow me to disagree.

1) (as with most of Perl defects) quite probably it might have been
   not "a choice" made by anybody, but just a side effect of a
   particular implementation (the side effect which was discovered too
   late to change the semantic);

2) are you sure it was made by Larry, and not by "a random poster to p5-p"?

3) as far as I'm concerned, this "concept and syntax" is so convoluted
   that nobody will be able to RELIABLY memorize it.  Which makes it
   unusable (and unused); I doubt one should call unusable stuff "the
   most flexible"...

Hope this helps,
Ilya


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

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 V11 Issue 1101
***************************************


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