[30085] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1328 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 3 09:10:15 2008

Date: Mon, 3 Mar 2008 06:09:06 -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           Mon, 3 Mar 2008     Volume: 11 Number: 1328

Today's topics:
    Re: A question about multithreading <ThomasKratz@REMOVEwebCAPS.de>
    Re: Converting "&#x2019;" to an Apostrophe? <nospam-abuse@ilyaz.org>
    Re: Crypt::CBC vs individual cipher module differs? keith@bytebrothers.co.uk
        grep in file and date process <gniagnia@gmail.com>
    Re: grep in file and date process <RedGrittyBrick@SpamWeary.foo>
    Re: grep in file and date process <gniagnia@gmail.com>
    Re: grep in file and date process <peter@makholm.net>
    Re: grep in file and date process <gniagnia@gmail.com>
    Re: grep specific info from a file <joe@inwap.com>
        new CPAN modules on Mon Mar  3 2008 (Randal Schwartz)
        Parsing natural language timestamps <peter@makholm.net>
        reading from  stdin via pipe, buffering? <Rudy.Gevaertno@spamugent.be>
    Re: reading from  stdin via pipe, buffering? <someone@example.com>
    Re: reading from  stdin via pipe, buffering? <Rudy.Gevaertno@spamugent.be>
    Re: regex for chars 192 to 255 <RedGrittyBrick@SpamWeary.foo>
    Re: unsetenv in the shell <szrRE@szromanMO.comVE>
    Re: unsetenv in the shell <ben@morrow.me.uk>
    Re: unsetenv in the shell <szrRE@szromanMO.comVE>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 03 Mar 2008 11:18:45 +0100
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: A question about multithreading
Message-Id: <47cbd088$0$2609$bb690d87@news.main-rheiner.de>

Ted wrote:

> If I launch the same four child processes manually, each in its own
> separate commandline window, then I get the processor being fully
> utilized.  How do I get the same effect by launching threads or child
> processes?  But this gets quite tedious very quickly when there are
> dozens of scripts to run!

I suspect Joost is right in suspecting IO might be the problem.
Since ou mention a "commandline window", are you generating output to 
the same terminal from each thread? If so, this could be the bottleneck. 
In the example code below you can play around with the amount of output 
send to the terminal. On my machine going below 2000 will show the 
effect you are describing.

use strict;
use warnings;
use threads;

my $counter        = 0;
my $print_interval = $ARGV[0] || 10000;

sub adder {
     my $tid  = threads->self()->tid();
     while (1) {
         $counter++;
         if ( $counter % $print_interval == 0 ) {
             print "Hi! from thread $tid\n";
         }
     }
}

threads->new(\&adder)->detach() for 1 .. 4;

while (1) { sleep 1 }

-- 
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-


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

Date: Mon, 3 Mar 2008 06:37:40 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Converting "&#x2019;" to an Apostrophe?
Message-Id: <fqg6bk$2iii$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Petr Vileta
<stoupa@practisoft.cz>], who wrote in article <fqflav$2n2k$1@ns.felk.cvut.cz>:
> >> my $string = "foo\n&#x2019;\nbar";
> >> $string =~ s/&#x2019;/'/g;
> >> print "$string\n";
> >> __END__

> Sorry, I wrote my mess late at night ;-) The true print was to have been
> 
> foo
> &#x2019;
> bar
> 
> In other word the substitution failed.

Does not fail on mine 5.6.1.  Are you sure you run it exactly as posted?

Hope this helps,
Ilya


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

Date: Mon, 3 Mar 2008 02:31:19 -0800 (PST)
From: keith@bytebrothers.co.uk
Subject: Re: Crypt::CBC vs individual cipher module differs?
Message-Id: <497c1f01-6d23-4c5a-9b89-4b2cc8561045@p73g2000hsd.googlegroups.com>

On 3 Mar, 00:01, "Waylen Gumbal" <wgum...@gmail.com> wrote:
> I noticed that if I use a "CBC compatible" crypt module directly, I get
> a normal expected result. But if I use CBC with the same cipher type on
> the same key and plaintext I get a completely different result.
>
<snip>
> __OUTPUT__
> OpenSSL AES
> [e1f461cdc00f4855b9b2c0367cd3a293]
>
> AES via CBC
> [53616c7465645f5f36dd0b8d9b84e278382b8cd329f7020b545c3595c239284d37d4e3dc2d6a2fc97d375675b793b357]

Without knowing exactly how those particular modules do what they do,
the first thing that occurs to me is that nowhere are you providing an
initialisation vector, so presumably the modules are generating a
random IV.  That will give you totally different ciphertext.  The
lengths _may_ be different because the latter attempt is prepending
the ciphertext with the IV, which is required for decryption.

Just my 2 pennyworth...


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

Date: Mon, 3 Mar 2008 04:42:20 -0800 (PST)
From: Mr_Noob <gniagnia@gmail.com>
Subject: grep in file and date process
Message-Id: <2150b63a-3ad8-4416-a030-e0a373e602f7@n36g2000hse.googlegroups.com>

Hi all,

here is an extract of my file :

2008/03/03 12:56:07 put /name_of_client4/pub/file.xml
2008/03/03 12:56:07 put /name_of_client1/pub/videos/file.mov
2008/03/03 12:56:07 put /name_of_client1/pub/videos/file.wmv
2008/03/03 12:56:07 put /name_of_client5/pub/file.xml
2008/03/03 12:56:07 put /name_of_client1/pub/videos/file.flv
2008/03/03 12:56:07 put /name_of_client1/pub/videos/file.jpg
2008/03/03 12:56:07 put /name_of_client2/pub/file.jpg
2008/03/03 12:56:07 put /name_of_client3/pub/file.xml
2008/03/03 12:56:07 put /name_of_client5/pub/file.mov
2008/03/03 12:56:07 put /name_of_client1/pub/file.xml
 ...

What would be the best way to grep for a specified "name_of_client"
then calculate the time since last file has been put ?

open( FILE, "< $filename" ) or die "Can't open $filename : $!";
while( <FILE> ) {
# grep last appearance of specified name_of_client
# time since last transfer
}
close FILE;



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

Date: Mon, 03 Mar 2008 12:49:26 +0000
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: grep in file and date process
Message-Id: <47cbf3d8$0$32041$da0feed9@news.zen.co.uk>

Mr_Noob wrote:
> Hi all,
> 
> here is an extract of my file :
> 
> 2008/03/03 12:56:07 put /name_of_client4/pub/file.xml
> 2008/03/03 12:56:07 put /name_of_client1/pub/videos/file.mov
> 2008/03/03 12:56:07 put /name_of_client1/pub/videos/file.wmv
> 2008/03/03 12:56:07 put /name_of_client5/pub/file.xml
> 2008/03/03 12:56:07 put /name_of_client1/pub/videos/file.flv
> 2008/03/03 12:56:07 put /name_of_client1/pub/videos/file.jpg
> 2008/03/03 12:56:07 put /name_of_client2/pub/file.jpg
> 2008/03/03 12:56:07 put /name_of_client3/pub/file.xml
> 2008/03/03 12:56:07 put /name_of_client5/pub/file.mov
> 2008/03/03 12:56:07 put /name_of_client1/pub/file.xml
> ...
> 
> What would be the best way to grep for a specified "name_of_client"
> then calculate the time since last file has been put ?
> 
> open( FILE, "< $filename" ) or die "Can't open $filename : $!";
> while( <FILE> ) {
> # grep last appearance of specified name_of_client
> # time since last transfer

Some combination of 'next unless /name_of_client/', split, a hash and a 
date module.

> }
> close FILE;
> 



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

Date: Mon, 3 Mar 2008 05:03:01 -0800 (PST)
From: Mr_Noob <gniagnia@gmail.com>
Subject: Re: grep in file and date process
Message-Id: <caef7dc8-421e-448f-9b11-a2f512e228d1@s8g2000prg.googlegroups.com>

On Mar 3, 1:49 pm, RedGrittyBrick <RedGrittyBr...@SpamWeary.foo>
wrote:
> Mr_Noob wrote:
> > Hi all,
>
> > here is an extract of my file :
>
> > 2008/03/03 12:56:07 put /name_of_client4/pub/file.xml
> > 2008/03/03 12:56:07 put /name_of_client1/pub/videos/file.mov
> > 2008/03/03 12:56:07 put /name_of_client1/pub/videos/file.wmv
> > 2008/03/03 12:56:07 put /name_of_client5/pub/file.xml
> > 2008/03/03 12:56:07 put /name_of_client1/pub/videos/file.flv
> > 2008/03/03 12:56:07 put /name_of_client1/pub/videos/file.jpg
> > 2008/03/03 12:56:07 put /name_of_client2/pub/file.jpg
> > 2008/03/03 12:56:07 put /name_of_client3/pub/file.xml
> > 2008/03/03 12:56:07 put /name_of_client5/pub/file.mov
> > 2008/03/03 12:56:07 put /name_of_client1/pub/file.xml
> > ...
>
> > What would be the best way to grep for a specified "name_of_client"
> > then calculate the time since last file has been put ?
>
> > open( FILE, "< $filename" ) or die "Can't open $filename : $!";
> > while( <FILE> ) {
> > # grep last appearance of specified name_of_client
> > # time since last transfer
>
> Some combination of 'next unless /name_of_client/', split, a hash and a
> date module.
>
> > }
> > close FILE;

ok , but how can I tell my script to grep only the last appearance of
a client's name for further process ?


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

Date: Mon, 03 Mar 2008 13:09:35 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Re: grep in file and date process
Message-Id: <87bq5w2bu8.fsf@hacking.dk>

Mr_Noob <gniagnia@gmail.com> writes:

>> > open( FILE, "< $filename" ) or die "Can't open $filename : $!";
>> > while( <FILE> ) {
>> > # grep last appearance of specified name_of_client
>> > # time since last transfer
>>
>> Some combination of 'next unless /name_of_client/', split, a hash and a
>> date module.
>>
>> > }
>> > close FILE;
>
> ok , but how can I tell my script to grep only the last appearance of
> a client's name for further process ?

Moving the further processing outside the loop might do it...

//Makholm


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

Date: Mon, 3 Mar 2008 05:25:14 -0800 (PST)
From: Mr_Noob <gniagnia@gmail.com>
Subject: Re: grep in file and date process
Message-Id: <7de4425c-a02e-4603-b32b-477def6b74c8@i12g2000prf.googlegroups.com>

my @clientlog;
open(FILE, "< $xferlog") or die "Can't open $xferlog : $!";
while(<FILE>)
{
	next unless /put \/$client/;
	push (@clientlog, $_);

}
# Display last element
my $lastclientlog = $clientlog[$#clientlog];
print $lastclientlog;
close FILE;


This works great but i cannot get rid of this error in apache's log
file:

"Use of uninitialized value in print..."  (line 10)


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

Date: Mon, 03 Mar 2008 04:33:18 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: grep specific info from a file
Message-Id: <0MKdnYCQb9OTbVbanZ2dnUVZ_gednZ2d@comcast.com>

Mr_Noob wrote:
> Hi all,
> 
> What is the best way to grep into a file, only lines beginning with
> "[" and ending with "]" ?
> And then, how can I feed an array with the information contained
> between the 2 brackets, without the 2 brackets?
> 
> here is a sample of my file :
> 
> ...
> [blah blah blah]
> some stuff here
> 
> [blabla again]
> here is some other stuff here too
> ...

That looks suspiciously line a config or *.INI file.

> What I'd like to obtain is :
> 
> ...
> bla blah blah
> blabla again
> ...

Would you be interested in a CPAN module that parses INI files?
No need to write your own when there is a good, small module already.
	-Joe





linux% cat test.pl
#!/usr/bin/perl
use strict; use warnings;

use Config::Tiny;
#my $config = Config::Tiny->read('MyProg.ini') or die 'Oops:',Config::Tiny->errstr();
my $data = do { local $/; <DATA>};
my $config = Config::Tiny->read_string($data) or die 'Oops:',Config::Tiny->errstr();

my @sections = sort keys %{$config};
print "   The sections are:\n";
print "$_\n" for @sections;
print "\n\n";

foreach my $section (@sections) {
   print "Section '$section':\n";
   my $href = $config->{$section} or next;
   my @keys = keys %$href;
   printf "%20s = %s\n", $_, $config->{$section}{$_} for sort @keys;
   print "End     $section\n\n";
}
__DATA__
global1 = Hello, World.

[blah blah blah]
comment = 1st Section
data = some stuff here

[blabla again]
comment = 2nd Section
data = here is some other stuff here too

linux% perl test.pl
    The sections are:
_
blabla again
blah blah blah


Section '_':
              global1 = Hello, World.
End     _

Section 'blabla again':
              comment = 2nd Section
                 data = here is some other stuff here too
End     blabla again

Section 'blah blah blah':
              comment = 1st Section
                 data = some stuff here
End     blah blah blah

linux%


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

Date: Mon, 3 Mar 2008 05:42:18 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Mon Mar  3 2008
Message-Id: <Jx53uI.ywx@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

Acme-Globule-0.003
http://search.cpan.org/~mooli/Acme-Globule-0.003/
Extensible package-local way to override glob() 
----
Angel
http://search.cpan.org/~mingzhang/Angel/
Build up a robust connection to your DUT 
----
CGI-Application-Plugin-Authorization-0.07
http://search.cpan.org/~ceeshek/CGI-Application-Plugin-Authorization-0.07/
Authorization framework for CGI::Application 
----
CGI-Application-Plugin-LogDispatch-1.01
http://search.cpan.org/~ceeshek/CGI-Application-Plugin-LogDispatch-1.01/
Add Log::Dispatch support to CGI::Application 
----
CGI-Application-Plugin-Redirect-1.00
http://search.cpan.org/~ceeshek/CGI-Application-Plugin-Redirect-1.00/
Easy external redirects in CGI::Application 
----
CGI-Application-Plugin-Session-1.03
http://search.cpan.org/~ceeshek/CGI-Application-Plugin-Session-1.03/
Add CGI::Session support to CGI::Application 
----
CGI-Application-Plugin-TT-1.04
http://search.cpan.org/~ceeshek/CGI-Application-Plugin-TT-1.04/
Add Template Toolkit support to CGI::Application 
----
CPAN-Dependency-0.13
http://search.cpan.org/~saper/CPAN-Dependency-0.13/
Analyzes CPAN modules and generates their dependency tree 
----
Catalyst-Plugin-Assets-0.030
http://search.cpan.org/~rkrimen/Catalyst-Plugin-Assets-0.030/
Manage and minify .css and .js assets in a Catalyst application 
----
Catalyst-Request-REST-ForBrowsers-0.01
http://search.cpan.org/~drolsky/Catalyst-Request-REST-ForBrowsers-0.01/
A Catalyst::Request::REST subclass for dealing with browsers 
----
CatalystX-Example-YUIUploader-0.02
http://search.cpan.org/~rkrimen/CatalystX-Example-YUIUploader-0.02/
A YUI Uploader example for Catalyst 
----
Config-General-2.38
http://search.cpan.org/~tlinden/Config-General-2.38/
Generic Config Module 
----
Convert-UU-0.5201
http://search.cpan.org/~andk/Convert-UU-0.5201/
Perl module for uuencode and uudecode 
----
Cookie-XS-0.04
http://search.cpan.org/~agent/Cookie-XS-0.04/
Cookie parser in C 
----
Curses-UI-0.9602
http://search.cpan.org/~mdxi/Curses-UI-0.9602/
A curses based OO user interface framework 
----
Data-Validation-0.1.13
http://search.cpan.org/~pjfl/Data-Validation-0.1.13/
Check data values form conformance with constraints 
----
Devel-Hook-0.004
http://search.cpan.org/~ferreira/Devel-Hook-0.004/
Mess around with BEGIN/CHECK/INIT/END blocks 
----
Devel-PerlySense-0.0147
http://search.cpan.org/~johanl/Devel-PerlySense-0.0147/
Perl IDE with Emacs frontend 
----
EekBoek-1.03.10_2
http://search.cpan.org/~jv/EekBoek-1.03.10_2/
Bookkeeping software for small and medium-size businesses 
----
ExtUtils-Install-1.47
http://search.cpan.org/~yves/ExtUtils-Install-1.47/
install files from here to there 
----
File-Assets-0.050
http://search.cpan.org/~rkrimen/File-Assets-0.050/
Manage .css and .js assets in a web application 
----
GRID-Machine-0.085
http://search.cpan.org/~casiano/GRID-Machine-0.085/
Remote Procedure Calls over a SSH link 
----
GRID-Machine-0.086
http://search.cpan.org/~casiano/GRID-Machine-0.086/
Remote Procedure Calls over a SSH link 
----
GRID-Machine-0.087
http://search.cpan.org/~casiano/GRID-Machine-0.087/
Remote Procedure Calls over a SSH link 
----
IO-Handle-Moose-0.01
http://search.cpan.org/~dexter/IO-Handle-Moose-0.01/
Moose reimplementation of IO::Handle with improvements 
----
JSON-RPC-Server-FastCGI-0.03
http://search.cpan.org/~faiz/JSON-RPC-Server-FastCGI-0.03/
A FastCGI version of JSON::RPC::Server 
----
KSx-Highlight-Summarizer-0.02
http://search.cpan.org/~sprout/KSx-Highlight-Summarizer-0.02/
KinoSearch Highlighter subclass that provides more comprehensive summaries 
----
Net-MirrorDir-0.14
http://search.cpan.org/~knorr/Net-MirrorDir-0.14/
Perl extension for compare local-directories and remote-directories with each other 
----
Net-OBEX-Packet-Request-0.003
http://search.cpan.org/~zoffix/Net-OBEX-Packet-Request-0.003/
create OBEX protocol request packets. 
----
Net-OBEX-Response-0.001
http://search.cpan.org/~zoffix/Net-OBEX-Response-0.001/
interpret OBEX protocol response packets 
----
Net-OBEX-Response-0.002
http://search.cpan.org/~zoffix/Net-OBEX-Response-0.002/
interpret OBEX protocol response packets 
----
Net-SLP-1.3
http://search.cpan.org/~mikem/Net-SLP-1.3/
Perl extension for accessing the Service Location Protocol (SLP) API. SLP can be used to discover the location of services 
----
Number-Continuation-0.04
http://search.cpan.org/~schubiger/Number-Continuation-0.04/
Create number continuations 
----
OOB-0.07
http://search.cpan.org/~elizabeth/OOB-0.07/
out of band data for any data structure in Perl 
----
Perl-Critic-1.081_006
http://search.cpan.org/~elliotjs/Perl-Critic-1.081_006/
Critique Perl source code for best-practices. 
----
SVG-2.37
http://search.cpan.org/~ronan/SVG-2.37/
Perl extension for generating Scalable Vector Graphics (SVG) documents 
----
SVN-Notify-Config-0.0908
http://search.cpan.org/~jpeacock/SVN-Notify-Config-0.0908/
Config-driven Subversion notification 
----
SVN-Notify-Mirror-0.037
http://search.cpan.org/~jpeacock/SVN-Notify-Mirror-0.037/
Keep a mirrored working copy of a repository path 
----
Term-GentooFunctions-1.01.4
http://search.cpan.org/~jettero/Term-GentooFunctions-1.01.4/
provides gentoo's einfo, ewarn, eerror, ebegin and eend. 
----
Test-Steering-0.02
http://search.cpan.org/~andya/Test-Steering-0.02/
Execute test scripts conditionally 
----
Time-Piece-1.13
http://search.cpan.org/~msergeant/Time-Piece-1.13/
Object Oriented time objects 
----
WWW-Ebay-0.083
http://search.cpan.org/~mthurn/WWW-Ebay-0.083/
----
WWW-Search-Yahoo-2.411
http://search.cpan.org/~mthurn/WWW-Search-Yahoo-2.411/
backend for searching www.yahoo.com 
----
XML-OBEXFTP-FolderListing-0.001
http://search.cpan.org/~zoffix/XML-OBEXFTP-FolderListing-0.001/
parse OBEX FTP x-obex/folder-listing XML 
----
XPanel-0.0.10
http://search.cpan.org/~xpanel/XPanel-0.0.10/
Perl extension to XPanel servers 
----
XPanel-0.0.2
http://search.cpan.org/~xpanel/XPanel-0.0.2/
Perl extension to XPanel servers 
----
XPanel-0.0.3
http://search.cpan.org/~xpanel/XPanel-0.0.3/
Perl extension to XPanel servers 
----
XPanel-0.0.4
http://search.cpan.org/~xpanel/XPanel-0.0.4/
Perl extension to XPanel servers 
----
XPanel-0.0.5
http://search.cpan.org/~xpanel/XPanel-0.0.5/
Perl extension to XPanel servers 
----
XPanel-0.0.6
http://search.cpan.org/~xpanel/XPanel-0.0.6/
Perl extension to XPanel servers 
----
XPanel-0.0.7
http://search.cpan.org/~xpanel/XPanel-0.0.7/
Perl extension to XPanel servers 


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Mon, 03 Mar 2008 08:37:54 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Parsing natural language timestamps
Message-Id: <87fxv82of1.fsf@hacking.dk>

I have a command line application where the use specifies a time span
with two arguments --from and --to. At the moment I'm using strptime
from Date::Parse, but it would be nice to support dates like '2 days
ago', 'today', 'next friday'.

If the user doesn't specifies a exact time but just a day I would like
to have the from argument use the start of the date (00:00:00) and the
to argument use the end of the date (23:59:59).

Date::Manip and Time::ParseDate both parses these natural language
timestamps, but I can't get either to work quite as I need. Both seem
to have 'today' parsed as 'right now' as default.

Date::Manip have a TodayIsMidnight setting, but 'tomorrow' is still '24
hours from right now' and I can't differ between wether the user used
the not specific 'today' or '2008-03-03 00:00:00' which would mean
differing things in the to argument.

Time::ParseDate has a nice TIME_REQUIRED setting, but it seems to be
non-working for relative dates like today and tomorrow by coding.

Any idears for a solution?

 



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

Date: Mon, 03 Mar 2008 09:20:22 +0100
From: Rudy Gevaert <Rudy.Gevaertno@spamugent.be>
Subject: reading from  stdin via pipe, buffering?
Message-Id: <fqgchd$g9t$1@ikaria.belnet.be>

Hi,

I have written a perl program that reads from stdin:
while(<STDIN>)
{
    chomp
    do_it($_);
}
Data is fed to it via a pipe:

cat myfile | ./myprogram

When running the program, the program doesn't always read the whole
line.  I'm guessing this has something to do with the stdin buffer.

I would like to know how I can make that perl gets the whole line.  As
it is clearly failing from time to time.

Thanks in advance,

Rudy



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

Date: Mon, 03 Mar 2008 08:42:04 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: reading from  stdin via pipe, buffering?
Message-Id: <wROyj.56279$w57.44701@edtnps90>

Rudy Gevaert wrote:
> 
> I have written a perl program that reads from stdin:
> while(<STDIN>)
> {
>    chomp
>    do_it($_);
> }
> Data is fed to it via a pipe:
> 
> cat myfile | ./myprogram
> 
> When running the program, the program doesn't always read the whole
> line.  I'm guessing this has something to do with the stdin buffer.
> 
> I would like to know how I can make that perl gets the whole line.  As
> it is clearly failing from time to time.

It is not your program's STDIN that is the problem, it is the STDOUT 
through the pipe that is the problem.  If possible, try opening 'myfile' 
in your program instead, possibly using sysopen instead of open.

perldoc -f open
perldoc perlopentut
perldoc -f sysopen


John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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

Date: Mon, 03 Mar 2008 10:07:01 +0100
From: Rudy Gevaert <Rudy.Gevaertno@spamugent.be>
Subject: Re: reading from  stdin via pipe, buffering?
Message-Id: <fqgf8r$i3g$1@ikaria.belnet.be>

John W. Krahn wrote:
> Rudy Gevaert wrote:
>>
>> I have written a perl program that reads from stdin:
>> while(<STDIN>)
>> {
>>    chomp
>>    do_it($_);
>> }
>> Data is fed to it via a pipe:
>>
>> cat myfile | ./myprogram
>>
>> When running the program, the program doesn't always read the whole
>> line.  I'm guessing this has something to do with the stdin buffer.
>>
>> I would like to know how I can make that perl gets the whole line.  As
>> it is clearly failing from time to time.
> 
> It is not your program's STDIN that is the problem, it is the STDOUT 
> through the pipe that is the problem.  If possible, try opening 'myfile' 
> in your program instead, possibly using sysopen instead of open.

Unfortunately it needs to work with a pipe.  What is the 'perl way' to 
handle input coming from a pipe?

Thanks in advance,

Rudy


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

Date: Mon, 03 Mar 2008 10:07:49 +0000
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: regex for chars 192 to 255
Message-Id: <47cbcdf6$0$8419$db0fefd9@news.zen.co.uk>

John wrote:
> "Tad J McClellan" <tadmc@seesig.invalid> wrote in message 
> news:slrnfsfsa7.6t2.tadmc@tadmc30.sbcglobal.net...
>> John <john1949@yahoo.com> wrote:
>>
>>> Is there a character class like [a-zA-Z] for accented characters that lie
>>> between ASCII 192 and 255 (excluding 215 and 247)?
>>
>> ASCII defines characters from 0-127, so 192 and 255 are not in ASCII.
>>
>>
>> -- 
>> Tad McClellan
>> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
> 
> Thanks.  I should have said extended ASCII

I'd rather you said "Code Page 1252", "Windows Latin-1", "ISO-8859-1" or 
the name of some other specific character set/encoding. :-)



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

Date: Sun, 2 Mar 2008 21:04:56 -0800
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: unsetenv in the shell
Message-Id: <fqg0tr01gtj@news2.newsguy.com>

Uri Guttman wrote:
>>>>>> "x" == xhoster  <xhoster@gmail.com> writes:
>
>  x> Others have explained why this doesn't work.  By adding an extra
>  scope x> and a local, you can avoid having to explicitly store the
> old values.
>
>  x> {
>  x>   my @del=qw/VAR1 VAR2 VAR3/;
>  x>   local %ENV{@del};
>  x>   delete %ENV{@del};
>
>
> technically those should be @ENV{@del} as they are hash slices. but i
> think perl allows % there.

I get:

$ perl -v | head -n 2 | tail -n 1
This is perl, v5.8.8 built for i686-linux-64int-ld


$ ./test_clpm_env_0001.pl
syntax error at ./test_clpm_env_0001.pl line 9, near "%ENV{"
syntax error at ./test_clpm_env_0001.pl line 10, near "%ENV{"
Execution of ./test_clpm_env_0001.pl aborted due to compilation errors.
You have new mail in /var/spool/mail/root


$ nl -b a -n rn -w 3 -s ' ' test_clpm_env_0001.pl | head -n 10 | tail -n 
2
  9    local %ENV{@var_list};
 10    delete %ENV{@var_list};


If I changed those lines to have @ENV{... instead of %ENV{... it works 
as expected.

* * *

One more thing; the "delete" statement on line 10 is not needed:

$ nl -b a -n rn -w 3 -s ' ' test_clpm_env_0001.pl
  1 #!/usr/local/bin/perl
  2
  3 use strict;
  4
  5 my @var_list = qw/VAR1 VAR2 VAR3/;
  6 @ENV{@var_list} = qw/X1 Y2 Z3/;
  7
  8 {
  9    local @ENV{@var_list};
 10    #delete @ENV{@var_list};
 11
 12    #run_the_external_app;
 13    print "[", join(', ', @ENV{@var_list}), "]\n";
 14 };
 15 print "[", join(', ', @ENV{@var_list}), "]\n";


$ ./test_clpm_env_0001.pl
[, , ]
[X1, Y2, Z3]


Reemmber that the "local" statement gives a temporary copy of %ENV which 
is in a clean state, making the "delete" unnecessary :-)

--
szr (mmmmm.., Perl) 




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

Date: Mon, 3 Mar 2008 05:39:21 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: unsetenv in the shell
Message-Id: <9hfs95-il1.ln1@osiris.mauzo.dyndns.org>


Quoth "szr" <szrRE@szromanMO.comVE>:
> 
[ local $ENV{FOO}; delete $ENV{FOO} ]
>
> One more thing; the "delete" statement on line 10 is not needed:
<snip>
> 
> Reemmber that the "local" statement gives a temporary copy of %ENV which 
> is in a clean state, making the "delete" unnecessary :-)

This is not the case. local sets the value to undef, which in the case
of %ENV is translated to the empty string. An empty environment variable
is very different from one which isn't there:

    ~% perl -le'$ENV{FOO} = 1; local $ENV{FOO}; system "env"' | grep FOO
    FOO=

Ben



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

Date: Mon, 3 Mar 2008 01:07:28 -0800
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: unsetenv in the shell
Message-Id: <fqgf4h01vth@news2.newsguy.com>

Ben Morrow wrote:
> Quoth "szr" <szrRE@szromanMO.comVE>:
>>
> [ local $ENV{FOO}; delete $ENV{FOO} ]
>>
>> One more thing; the "delete" statement on line 10 is not needed:
> <snip>
>>
>> Reemmber that the "local" statement gives a temporary copy of %ENV
>> which is in a clean state, making the "delete" unnecessary :-)
>
> This is not the case. local sets the value to undef, which in the case
> of %ENV is translated to the empty string. An empty environment
> variable is very different from one which isn't there:
>
>    ~% perl -le'$ENV{FOO} = 1; local $ENV{FOO}; system "env"' | grep
>    FOO FOO=

Excellent point. I view %ENV as a tied hash of sorts.

-- 
szr 




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

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


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