[31267] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2512 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 9 11:09:47 2009

Date: Thu, 9 Jul 2009 08:09:12 -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, 9 Jul 2009     Volume: 11 Number: 2512

Today's topics:
    Re: Finding recent files and copy them into another fol <derykus@gmail.com>
    Re: formatting a number of elsif statements <m@rtij.nl.invlalid>
        How to make STDOUT unbuffered, please guide me <sahana.h-v@hp.com>
    Re: How to make STDOUT unbuffered, please guide me <michaelgang@gmail.com>
    Re: How to make STDOUT unbuffered, please guide me <josef.moellers@ts.fujitsu.com>
    Re: OT: unix to Windows technology <xahlee@gmail.com>
    Re: Question on a 'perlsub' statement. <hjp-usenet2@hjp.at>
    Re: Question on a 'perlsub' statement. <tadmc@seesig.invalid>
    Re: Question on a 'perlsub' statement. <derykus@gmail.com>
    Re: Question on a 'perlsub' statement. <jurgenex@hotmail.com>
    Re: Shedding some light on R. Malph <tadmc@seesig.invalid>
        Shedding some light on U. Guttman <ralph.malph@altavista.com>
    Re: Shedding some light on U. Guttman <jurgenex@hotmail.com>
    Re: Shedding some light on U. Guttman <jurgenex@hotmail.com>
        To extract file name only from a file <clearguy02@yahoo.com>
    Re: To extract file name only from a file <josef.moellers@ts.fujitsu.com>
    Re: To extract file name only from a file <josef.moellers@ts.fujitsu.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 8 Jul 2009 22:16:32 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: Finding recent files and copy them into another folder
Message-Id: <1382744a-091d-4f4f-a3b3-f7ef0607470b@i8g2000pro.googlegroups.com>

On Jul 8, 5:14=A0pm, Jorge Reyes <jorg_re...@hotmail.com> wrote:
> Hi everyone,
>
> I have this issue which is killing me, this is the scenario
>
> if i make =A0 ls -l =A0 =A0 i get this:
> -rw-r--r-- =A0 1 netrac =A0 netrac =A0 =A0 =A02928 jul =A0 8 18:47 file1.=
pl
> -rw-r--r-- =A0 1 netrac =A0 netrac =A0 =A0 =A02928 jul =A0 8 19:07 file2.=
pl
> -rw-r--r-- =A0 1 netrac =A0 netrac =A0 =A0 =A02928 jul =A0 8 19:10 file3.=
pl
>
> now what i need is only the files were accessed >=3D 19:00 =A0i.e.
> -rw-r--r-- =A0 1 netrac =A0 netrac =A0 =A0 =A02928 jul =A0 8 19:07 file2.=
pl
> -rw-r--r-- =A0 1 netrac =A0 netrac =A0 =A0 =A02928 jul =A0 8 19:10 file3.=
pl
>
> i found this example which create a rule to find only files (and not
> directories or other things) that have been accessed at least 14 days
> ago
>
> use File::Find::Rule;
> my $path =3D "/data";
> my @results =3D File::Find::Rule->file->ctime('>14')->in($path);
> foreach my $i (@results) {
> =A0 =A0 =A0 =A0 print "$i\n";
>
> }
>
> Question is, instead 14 days ago, a specific time i.e. >=3D current
> system date ????


[untested]

use File::Find::Rule;
use Time::Local;

my $target =3D timelocal( 0, 0, 0, 19, 6, 2009 );
my @results =3D File::Find::Rule
                ->file
		->exec(
	          sub{ (stat($_))[10] - $target < 0
                           ? $_   : ''
                     }  )
                ->in($path);

--
Charles DeRykus


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

Date: Thu, 9 Jul 2009 07:18:09 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: formatting a number of elsif statements
Message-Id: <h5bgi6-9mn.ln1@news.rtij.nl>

On Mon, 06 Jul 2009 13:32:51 -0700, sln wrote:

>>Another reason is that it can often be implemented using a branch table.
>>
> [snip]
>>
>>M4
> 
> I'm sorry, I missed that branch table instruction in the op code list
> (rst?). Perhaps you should dissasemble your assembler.

It's called an indirect jump. Sorry, but you really should take some 
education here, these are rather basic concepts.

M4


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

Date: Thu, 9 Jul 2009 19:27:46 +0530
From: "sahana H V" <sahana.h-v@hp.com>
Subject: How to make STDOUT unbuffered, please guide me
Message-Id: <h34t0r$mh8$1@usenet01.boi.hp.com>

Hi,

Can i make stdout associated with my own file handle as unbuffered ?
If so can you please tell me how to do it?

What i am trying  to do is:

open (HVS, "/<command> <cmnd_args> 2>&1 |");   <==
at this point of time i need stdout to be unbuffered .so that command output 
should be logged to HVS in unbuffered fashion.

Thanks,
 -Sahana 




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

Date: Thu, 9 Jul 2009 07:34:29 -0700 (PDT)
From: david <michaelgang@gmail.com>
Subject: Re: How to make STDOUT unbuffered, please guide me
Message-Id: <c48d920b-32eb-423a-af00-94f2faeaacfa@y17g2000yqn.googlegroups.com>

On Jul 9, 4:57=A0pm, "sahana H V" <sahana....@hp.com> wrote:
> Hi,
>
> Can i make stdout associated with my own file handle as unbuffered ?
> If so can you please tell me how to do it?
>
> What i am trying =A0to do is:
>
> open (HVS, "/<command> <cmnd_args> 2>&1 |"); =A0 <=3D=3D
> at this point of time i need stdout to be unbuffered .so that command out=
put
> should be logged to HVS in unbuffered fashion.
>
> Thanks,
> =A0-Sahana

perldoc -q unbuffer


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

Date: Thu, 09 Jul 2009 17:00:21 +0200
From: Josef Moellers <josef.moellers@ts.fujitsu.com>
Subject: Re: How to make STDOUT unbuffered, please guide me
Message-Id: <h350m4$ki2$1@nntp.fujitsu-siemens.com>

sahana H V wrote:
> Hi,
> 
> Can i make stdout associated with my own file handle as unbuffered ?
> If so can you please tell me how to do it?
> 
> What i am trying  to do is:
> 
> open (HVS, "/<command> <cmnd_args> 2>&1 |");   <==
> at this point of time i need stdout to be unbuffered .so that command output 
> should be logged to HVS in unbuffered fashion.

You can't, unless you have control over the command.

It's the binary of the command (more precise: the stdio library linked 
to the command) which does the buffering and if stdout is not connected 
to a terminal (and a pipe is *not* a terminal), it will buffer its output.

Josef
-- 
These are my personal views and not those of Fujitsu Technology Solutions!
Josef Möllers (Pinguinpfleger bei FTS)
	If failure had no penalty success would not be a prize (T.  Pratchett)
Company Details: http://de.ts.fujitsu.com/imprint.html


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

Date: Thu, 9 Jul 2009 05:19:29 -0700 (PDT)
From: Xah Lee <xahlee@gmail.com>
Subject: Re: OT: unix to Windows technology
Message-Id: <0de99585-6a35-498d-b5d1-6eb8724c41b3@m3g2000pri.googlegroups.com>

a fried showed me this today:

http://xahlee.org/funny/Microsoft_eula.html

not sure which site originally reported it.

  Xah
=E2=88=91 http://xahlee.org/

=E2=98=84


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

Date: Thu, 9 Jul 2009 03:03:04 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Question on a 'perlsub' statement.
Message-Id: <slrnh5agea.ac4.hjp-usenet2@hrunkner.hjp.at>

On 2009-07-08 23:42, Alan Curry <pacman@kosh.dhis.org> wrote:
> In article <6b8di6-6mj2.ln1@osiris.mauzo.dyndns.org>,
> Ben Morrow  <ben@morrow.me.uk> wrote:
>>
>>Quoth pacman@kosh.dhis.org (Alan Curry):
>>> To understand the comparison made above, you have to see similarity
>>> between this strange pair:
>>>     ($foo) = <STDIN>;
>>>     my($foo) = <STDIN>;
>>> 
>>> In the first, the left operand of the assignment operator is a
>>> parenthesized expression. In the second, the left operand of the
>>> assignment operator is a function call (by the rule "if it looks
>>> like a function, it is a function")
>>
>>No. my (and local) are among the few exceptions to 'if it looks like a
>>function',
>
> Exceptions make language learning harder. And it still looks like a
> function to me, long after I learned that it doesn't behave the way I
> thought it should.

Maybe my background in statically typed compiled languages like Pascal,
Modula and C is showing here, but my ($foo) never looked like a function
call to me - it is /obviously/ a variable declaration, and a variable
declaration is /obviously/ not a function call, just like if and return
are /obviously/ not function calls. (The premise is wrong of course -
all of these /could/ be implemented as functions, especially in an
interpreted, dynamic language like Perl, but I wouldn't expect them to
be).


> All right, by now we all know now that
>   ($x) = something_returning_a_list();
>   my ($x) = something_returning_a_list();
> both discard all but the first element of the generated list. New questions:
>
> If you saw a statement of that form in perl code, without knowing
> anything about the author, would you consider it more likely to be a
> mistake similar to the one that started this thread, or a deliberate
> use of single-element list assignment?

The latter.


> In your own code, would you actually use a single-element list
> assignment to take the first element of a list and discard the rest,

Yes. I do that all the time. It is a very common Perl idiom:

    sub foo {
        my ($arg) = @_;

        ...
    }

This assigns the first element of @_ to $arg and
discards the rest.


> or would you make the discard more explicit, as a favor to future
> readers of your code?

I don't think writing it as 

    sub foo {
        my ($arg, @ignored) = @_;

        ...
    }

or even

    sub foo {
        my ($arg) = $_[0];

        ...
    }

would be favour to readers. It is much more likely to confuse them.



> If it can be agreed that the slightly more verbose forms
>   $x = (something_returning_a_list())[0];
>   my $x = (something_returning_a_list())[0];
> are easier to read,

I don't agree they are easier to read. I have to explicitely match
parens here to find out what's going on. I do use that form
occasionally, but mosty if the index is substantially larger than 0, as
in 

    my $mtime = (stat($file))[9];

but I try to avoid that (in this case, by using File::stat).

        hp


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

Date: Wed, 08 Jul 2009 21:12:05 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Question on a 'perlsub' statement.
Message-Id: <slrnh5ak7k.aoj.tadmc@tadmc30.sbcglobal.net>

Alan Curry <pacman@kosh.dhis.org> wrote:

> All right, by now we all know now that
>   ($x) = something_returning_a_list();
>   my ($x) = something_returning_a_list();
> both discard all but the first element of the generated list. New questions:
>
> If you saw a statement of that form in perl code, without knowing anything
> about the author, would you consider it more likely to be a mistake similar
> to the one that started this thread, or a deliberate use of single-element
> list assignment?


A deliberate use.


> In your own code, would you actually use a single-element list assignment to
> take the first element of a list and discard the rest, or would you make the
> discard more explicit, as a favor to future readers of your code?


I used this just 5 minutes ago in the code I stopped writing so
I could check Usenet.  :-)

I have a subroutine that returns a 2-element list: a user ID, and the
age of their session.

When I don't intend to use the age of the session

    my($user_id) = somefunc();

_IS_ a favor to future readers. It tells them that I don't intend
to use the age.

    my($user_id, $age) = somefunc();

would leave them wondering if I forgot to use the $age variable
that I took the trouble to populate.

and

    my($user_id) = (somefunc())[0];

is just too homely to contemplate.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Thu, 9 Jul 2009 04:23:22 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: Question on a 'perlsub' statement.
Message-Id: <8e0a4580-fc58-42e2-af9e-714e373dd3fe@13g2000prl.googlegroups.com>

On Jul 8, 4:42=A0pm, pac...@kosh.dhis.org (Alan Curry) wrote:

 ...

> All right, by now we all know now that
> =A0 ($x) =3D something_returning_a_list();
> =A0 my ($x) =3D something_returning_a_list();
> both discard all but the first element of the generated list. New questio=
ns:
> ...
> If you saw a statement of that form in perl code, withou
> If it can be agreed that the slightly more verbose forms
> =A0 $x =3D (something_returning_a_list())[0];
> =A0 my $x =3D (something_returning_a_list())[0];
> are easier to read, might we get a warning for the "too subtle" form?

I tend to agree but IMO the less cluttered

   ( my $x, () ) =3D  something_returning_a_list();

is an improvement with the empty list () clearly
signaling the throw-away's.

--
Charles DeRykus


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

Date: Thu, 09 Jul 2009 07:59:12 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Question on a 'perlsub' statement.
Message-Id: <681c5593h77enm8nuqdn8pe5jckrks1t1f@4ax.com>

Tad J McClellan <tadmc@seesig.invalid> wrote:
>I have a subroutine that returns a 2-element list: a user ID, and the
>age of their session.
>
>When I don't intend to use the age of the session
>    my($user_id) = somefunc();
>_IS_ a favor to future readers. It tells them that I don't intend
>to use the age.

Or that the programmer isn't aware/forgot that there are more return
values.
	(my $user_id, undef) = somefunc();
would be even more explicit.

jue


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

Date: Wed, 08 Jul 2009 22:20:22 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Shedding some light on R. Malph
Message-Id: <slrnh5ao7l.bfk.tadmc@tadmc30.sbcglobal.net>

Ralph Malph <ralph.malph@altavista.com> wrote:


> Users new to this group should be aware
> with whom they are dealing with.


This is the only post that Ralph Malph has ever made to Usenet
(according to google groups).

New users should be aware of the trolls that post one-offs
to further their personal vendettas.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Wed, 08 Jul 2009 22:28:26 -0400
From: Ralph Malph <ralph.malph@altavista.com>
Subject: Shedding some light on U. Guttman
Message-Id: <h33kkl$phi$1@aioe.org>

This was posted in another thread by Jon Kim and is 
worth wider
distribution. Users new to this group should be aware
with whom they are dealing with.

 > Here is the deal with U. Guttman:
 >     (1) He is chronically unemployed(i.e. he "works
 > for himself" but has no clients)
 >     (2) He is a loud boorish oaf. Picture the "comic
 > book guy" from The Simpsons. He is morbidly obese with a
 > constant stench of faeces.
 >     (3) He was a smart kid (he went to harvard or
 > mit or someplace of that caliber) but has been a 
failure as an adult.
 > Rumor mill at yapc this year held that he is losing his
 > house to foreclosure after many long years of
 > professional failure.
 > Bottom line, take his advice but with no more weight
 > given to it than that from any other enthusiastic
 > amateur or academic. He doesn't seem to have much
 > understanding of(or aptitude for) real life. I have 
seen him irl at yapc
 > the several times I have gone since he always seems 
to be a presence
 > there. I think he is from Boston(Not that it matters 
at all). I don't
 > think I have ever spoken to him but people do make 
fun of him behind his
 > back quite a bit and he seems to have few real 
friends in the community
 > anymore. You should probably should just feel sad for 
him and leave him
 > alone. Just another internet weirdo...


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

Date: Wed, 08 Jul 2009 21:51:47 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Shedding some light on U. Guttman
Message-Id: <5bta55han89k3dn7r5b9eftntkp8jtdujf@4ax.com>

Ralph Malph <ralph.malph@altavista.com> wrote:
>This was posted in another thread by Jon Kim and is 
>worth wider
>distribution. Users new to this group should be aware
>with whom they are dealing with.

New users to this group should also be aware that neither Ralph Malph
nor Jon Kim have ever posted to this NG before. Their only(!)
contribution ever is badmouthing a long-standing, respected member of
CLPM. 

I'd call them drive-by posters: no good for nothing

jue


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

Date: Wed, 08 Jul 2009 22:01:23 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Shedding some light on U. Guttman
Message-Id: <73ua55h2qo656o9b47khoflfhe75bgs2bk@4ax.com>

Jürgen Exner <jurgenex@hotmail.com> wrote:
>Ralph Malph <ralph.malph@altavista.com> wrote:
>>This was posted in another thread by Jon Kim and is 
>>worth wider
>>distribution. Users new to this group should be aware
>>with whom they are dealing with.
>
>New users to this group should also be aware that neither Ralph Malph
>nor Jon Kim have ever posted to this NG before. Their only(!)
>contribution ever is badmouthing a long-standing, respected member of
>CLPM. 
>
>I'd call them drive-by posters: no good for nothing

Oh, and just to state the obvious: of course Mr. Ralph Malph and Mr Jon
Kim just happen to post from the same NNTP server using identical
versions of the same client running on the same OS using exactly the
same configuration. What a remarkable coincidence! 

jue


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

Date: Thu, 9 Jul 2009 08:00:03 -0700 (PDT)
From: Rider <clearguy02@yahoo.com>
Subject: To extract file name only from a file
Message-Id: <94871e04-6029-40e5-9af6-b28d7b7db786@g31g2000yqc.googlegroups.com>


Hi experts,

I have this file, inut.txt (listed below). each line in the file has
more than 10 fields, but I am just listing a sample format here.

I need to print out only the filenames that are ending with .txt in
the output..

The output should be:
===============
unixFile1.txt
unixFile2.txt
unixFile3.txt
 ...
 ..
===============

I am looking out for a shorter form of a reg exp to extract only the
file names in to the output here. I do the basic perl coding on an
occasional basis, but don't know the right reg exp to do it.

Thanks in advance,
J


Here is the input file.
===================
1, bob, usr/tst/unixFile1.txt, boston, text1, text2, text3
2, bob, usr/tst/unixFile2.txt, boston, text1, text2, text3
3, bob, usr/tst/unixFile3.txt, boston, text1, text2, text3
 .....
 ....
===================


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

Date: Thu, 09 Jul 2009 17:04:07 +0200
From: Josef Moellers <josef.moellers@ts.fujitsu.com>
Subject: Re: To extract file name only from a file
Message-Id: <h350t7$ki2$2@nntp.fujitsu-siemens.com>

Rider wrote:
> Hi experts,
> 
> I have this file, inut.txt (listed below). each line in the file has
> more than 10 fields, but I am just listing a sample format here.
> 
> I need to print out only the filenames that are ending with .txt in
> the output..
> 
> The output should be:
> ===============
> unixFile1.txt
> unixFile2.txt
> unixFile3.txt
> ...
> ..
> ===============
> 
> I am looking out for a shorter form of a reg exp to extract only the
> file names in to the output here. I do the basic perl coding on an
> occasional basis, but don't know the right reg exp to do it.
> 
> Thanks in advance,
> J
> 
> 
> Here is the input file.
> ===================
> 1, bob, usr/tst/unixFile1.txt, boston, text1, text2, text3
> 2, bob, usr/tst/unixFile2.txt, boston, text1, text2, text3
> 3, bob, usr/tst/unixFile3.txt, boston, text1, text2, text3

$f1 = (split(/,\s+/, $line))[2];
print "$f1\n" if $f1 =~ /\.txt$/;


-- 
These are my personal views and not those of Fujitsu Technology Solutions!
Josef Möllers (Pinguinpfleger bei FTS)
	If failure had no penalty success would not be a prize (T.  Pratchett)
Company Details: http://de.ts.fujitsu.com/imprint.html


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

Date: Thu, 09 Jul 2009 17:06:10 +0200
From: Josef Moellers <josef.moellers@ts.fujitsu.com>
Subject: Re: To extract file name only from a file
Message-Id: <h35111$lgr$1@nntp.fujitsu-siemens.com>

Rider wrote:
> Hi experts,
> 
> I have this file, inut.txt (listed below). each line in the file has
> more than 10 fields, but I am just listing a sample format here.
> 
> I need to print out only the filenames that are ending with .txt in
> the output..
> 
> The output should be:
> ===============
> unixFile1.txt
> unixFile2.txt
> unixFile3.txt
> ...
> ..
> ===============
> 
> I am looking out for a shorter form of a reg exp to extract only the
> file names in to the output here. I do the basic perl coding on an
> occasional basis, but don't know the right reg exp to do it.
> 
> Thanks in advance,
> J
> 
> 
> Here is the input file.
> ===================
> 1, bob, usr/tst/unixFile1.txt, boston, text1, text2, text3
> 2, bob, usr/tst/unixFile2.txt, boston, text1, text2, text3
> 3, bob, usr/tst/unixFile3.txt, boston, text1, text2, text3
> .....
> ....
> ===================


$f1 = (split(/\//, (split(/,\s+/, $line))[2]))[-1];
print "$f1\n" if $f1 =~ /\.txt$/;


-- 
These are my personal views and not those of Fujitsu Technology Solutions!
Josef Möllers (Pinguinpfleger bei FTS)
	If failure had no penalty success would not be a prize (T.  Pratchett)
Company Details: http://de.ts.fujitsu.com/imprint.html


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

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


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