[28851] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 95 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 1 21:10:47 2007

Date: Thu, 1 Feb 2007 18:10:14 -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           Thu, 1 Feb 2007     Volume: 11 Number: 95

Today's topics:
    Re: sort filename array the same way as windows explore panofish@gmail.com
        Storing results in array rather than printing joseph85750@yahoo.com
    Re: Storing results in array rather than printing <mritty@gmail.com>
    Re: Storing results in array rather than printing xhoster@gmail.com
    Re: Upload file fails <bik.mido@tiscalinet.it>
    Re: Upload file fails <cwilbur@chromatico.net>
    Re: Upload file fails <purlgurl@purlgurl.net>
    Re: Upload file fails <bik.mido@tiscalinet.it>
    Re: Upload file fails <purlgurl@purlgurl.net>
    Re: Upload file fails <purlgurl@purlgurl.net>
        Win32::Clipboard mutilates \n <fred4414@nethere.com>
    Re: Win32::Clipboard mutilates \n <veatchla@yahoo.com>
    Re: Win32::Clipboard mutilates \n <fred4414@nethere.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 1 Feb 2007 13:40:40 -0800
From: panofish@gmail.com
Subject: Re: sort filename array the same way as windows explorer
Message-Id: <1170366040.279175.301370@p10g2000cwp.googlegroups.com>

On Feb 1, 2:03 pm, "Paul Lalli" <mri...@gmail.com> wrote:
> On Feb 1, 1:04 pm, panof...@gmail.com wrote:
>
>
>
> > I've searched and searched... I've seen references to sort:naturally
> > and other, but I do not have enough experience to write a piece of
> > code that will sort an array the same way that windows explorer sorts
> > its file list.
>
> > Here is my list I want sorted:
>
> > AsM-00 (EPC) 20070125 173425.wmf
> > AsM-01 (EPC) 20070125 173425.wmf
> > AsM-01-01 (EPC) 20070125 173425.wmf
> > AsM-01-02 (EPC) 20070125 173425.wmf
> > AsM-01-03 (EPC) 20070125 173425.wmf
> > AsM-01-04 (EPC) 20070125 173425.wmf
> > AsM-01-05 (EPC) 20070125 173425.wmf
> > AsM-01-06 (EPC) 20070125 173425.wmf
> > AsM-02 (EPC) 20070125 173425.wmf
> > CpM-00 (EPC) 20070125 173425.wmf
> > CpM-01 (EPC) 20070125 173425.wmf
> > CpM-01-01 (EPC) 20070125 173425.wmf
> > CpM-01-02 (EPC) 20070125 173425.wmf
>
> > The desired sorted result should look the same as it would in windows
> > explorer like this:
>
> > AsM-00 (EPC) 20070125 173425.wmf
> > AsM-01-01 (EPC) 20070125 173425.wmf
> > AsM-01-02 (EPC) 20070125 173425.wmf
> > AsM-01-03 (EPC) 20070125 173425.wmf
> > AsM-01-04 (EPC) 20070125 173425.wmf
> > AsM-01-05 (EPC) 20070125 173425.wmf
> > AsM-01-06 (EPC) 20070125 173425.wmf
> > AsM-01 (EPC) 20070125 173425.wmf
> > AsM-02 (EPC) 20070125 173425.wmf
> > CpM-00 (EPC) 20070125 173425.wmf
> > CpM-01-01 (EPC) 20070125 173425.wmf
> > CpM-01-02 (EPC) 20070125 173425.wmf
> > CpM-01 (EPC) 20070125 173425.wmf
>
> > The difference is subtle.
> > I hope some one can provide a robust, and elegant piece of source code
> > that can do this sort.
> > That would be very appreciated.
>
> I don't know for a fact that this is true, but it *appears* that
> Windows is sorting the filenames as they would be sorted if the non-
> alphanumeric characters were not present.  If that's true, the
> following does the job:
>
> @sorted =  map { $_->[0] }
>                  sort { $a->[1] cmp $b->[1] }
>                  map { [ $_, do { $t = $_; $t =~ s/[^a-zA-Z0-9]//g;
> $t } ] }  @files
>
> We're using a Schwartzian Transform to generate a list of all the
> files that have the non-alphanumerics removed, and have them
> correspond to their originals.  Then we sort on the modified version,
> and return back the originals.
>
> For more information:
> perldoc -f map
> perldoc -f sort
>
> Hope this helps,
> Paul Lalli


Well Mr. Lalli ... Mr. Lilly says THANK YOU!  That worked! It was just
missing the ending semicolon.
VERY MUCH APPRECIATED.



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

Date: 1 Feb 2007 11:13:31 -0800
From: joseph85750@yahoo.com
Subject: Storing results in array rather than printing
Message-Id: <1170357211.249593.12390@l53g2000cwa.googlegroups.com>

I have a unix program called zathras which will generate some useful
output results when a file is piped into it.

ie:

cat /path/to/asci-file.txt | zathras
  (this will output some text I wish to capture)

I'm trying to write a perl script to execute the above, but not from a
file piped in.  Instead, a variable within the perl script, since the
asci-file.txt above will have changing content.  Here's what I have so
far:

$someData="12 15 77 19 42 2112 99 88";  #data from asci-file.txt

open (FOO,"|zathras");

print FOO $someData;
close;

This works, and behaves exactly as running the program directly from
unix.  But what I really want is to store the results in an array,
rather than printing.

I suspected I could do something like:

@array=<FOO $someData>;

But this does not work.  The @array ends up empty, but no errors are
thrown.

Any help would be great.

Thanks!



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

Date: 1 Feb 2007 11:38:30 -0800
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Storing results in array rather than printing
Message-Id: <1170358710.603956.240080@a34g2000cwb.googlegroups.com>

On Feb 1, 2:13 pm, joseph85...@yahoo.com wrote:
> I have a unix program called zathras which will generate some useful
> output results when a file is piped into it.
>
> ie:
>
> cat /path/to/asci-file.txt | zathras
>   (this will output some text I wish to capture)
>
> I'm trying to write a perl script to execute the above, but not from a
> file piped in.  Instead, a variable within the perl script, since the
> asci-file.txt above will have changing content.  Here's what I have so
> far:
>
> $someData="12 15 77 19 42 2112 99 88";  #data from asci-file.txt
>
> open (FOO,"|zathras");
>
> print FOO $someData;
> close;
>
> This works, and behaves exactly as running the program directly from
> unix.  But what I really want is to store the results in an array,
> rather than printing.

Sounds like you need to open this zathras program for both reading and
writing.  For that, you want the IPC::Open2 module:

[untested]
#!/usr/bin/perl
use strict;
use warnings;
use IPC::Open2;

my $someData="12 15 77 19 42 2112 99 88";
my $pid = open2(my ($read_fh, $write_fh), 'zathras')
  or die "Cannot open zathras: $!";
print $write_fh $someData;
my @results = <$read_fh>;
#do whatever you want with @results;
__END__

For more info, see `perldoc IPC::Open2`

Hope this helps,
Paul Lall



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

Date: 01 Feb 2007 23:21:53 GMT
From: xhoster@gmail.com
Subject: Re: Storing results in array rather than printing
Message-Id: <20070201182414.133$NQ@newsreader.com>

joseph85750@yahoo.com wrote:
> I have a unix program called zathras which will generate some useful
> output results when a file is piped into it.
>
> ie:
>
> cat /path/to/asci-file.txt | zathras
>   (this will output some text I wish to capture)
>
> I'm trying to write a perl script to execute the above, but not from a
> file piped in.  Instead, a variable within the perl script, since the
> asci-file.txt above will have changing content.  Here's what I have so
> far:
>
> $someData="12 15 77 19 42 2112 99 88";  #data from asci-file.txt
>
> open (FOO,"|zathras");
>
> print FOO $someData;
> close;
>
> This works, and behaves exactly as running the program directly from
> unix.  But what I really want is to store the results in an array,
> rather than printing.
>
> I suspected I could do something like:
>
> @array=<FOO $someData>;

my @array = `echo '$someData' | zathras`;

This could be problematic if the shell interprets the characters in
$someData (particular if $someData contains quotes, or on some systems,
newlines)

Also, IPC::Open2 would work, but getting the buffering right is not trivial
if $someData is big and you are not used to that kind of thing.


Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Thu, 01 Feb 2007 21:14:14 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Upload file fails
Message-Id: <9fi4s258gaak6jat0ljojgakqgd112ksn1@4ax.com>

On Thu, 01 Feb 2007 09:21:49 -0800, Purl Gurl <purlgurl@purlgurl.net>
wrote:

>Finally, failure of CGI.pm to function correctly with Linux.

Huh?!? Since when?


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 01 Feb 2007 15:23:45 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Upload file fails
Message-Id: <87irelsk32.fsf@mithril.chromatico.net>

>>>>> "PG" == Purl Gurl <purlgurl@purlgurl.net> writes:

    PG> Charlton Wilbur wrote:
    >> Purl Gurl wrote:

    >>> Do not use binmode for Unix / Linux systems.

    >> From perldoc -f binmode on perl 5.8.8, second and third
    >> paragraphs:

    PG> What version of Perl is the originating author using?  What
    PG> version of CGI.pm is the originating author using?

    PG> You do not know, yes?

Largely irrelevant; the "don't bother with binmode on Unixlikes"
advice is outdated.  If it's a situation in which the binmode
statement is a no-op, having it in won't hurt; if it's a situation in
which binmode actually does something, leaving it out will hurt. 

Charlton


-- 
Charlton Wilbur
cwilbur@chromatico.net


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

Date: Thu, 01 Feb 2007 15:30:25 -0800
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: Upload file fails
Message-Id: <45C27811.4000907@purlgurl.net>



Michele Dondi wrote:

> Purl Gurl wrote:

>> Finally, failure of CGI.pm to function correctly with Linux.

> Huh?!? Since when?

My suggestion is you read, research and learn about
Stein's CGI.pm module. Your learning will place you
in a position of not having to ask.

Purl Gurl



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

Date: Fri, 02 Feb 2007 00:43:16 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Upload file fails
Message-Id: <fju4s219g0l5fg6a9vij56lj4246j1biep@4ax.com>

On Thu, 01 Feb 2007 15:30:25 -0800, Purl Gurl <purlgurl@purlgurl.net>
wrote:

>>> Finally, failure of CGI.pm to function correctly with Linux.
>
>> Huh?!? Since when?
>
>My suggestion is you read, research and learn about
>Stein's CGI.pm module. Your learning will place you
>in a position of not having to ask.

Well, but I've never heard anything along the lines of what you claim,
nor does it match with my own -admittedly very limited- experience.
Thus I would be extremely grateful to you if you could post some
examples of code showing how CGI.pm "fails to function correctly with
Linux"...


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Thu, 01 Feb 2007 15:47:31 -0800
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: Upload file fails
Message-Id: <45C27C13.1080204@purlgurl.net>

Charlton Wilbur wrote:

> Purl Gurl wrote:
>> Charlton Wilbur wrote:
>>> Purl Gurl wrote:

>     >>> Do not use binmode for Unix / Linux systems.

>     >> From perldoc -f binmode on perl 5.8.8, second and third
>     >> paragraphs:

>> What version of Perl is the originating author using?
 >> What version of CGI.pm is the originating author using?

>> You do not know, yes?



> Largely irrelevant;

Is this one-hundred percent irrelevant?


> the "don't bother with binmode on Unixlikes" advice is outdated.

Are you factually stating there are no systems in use which
are binmode sensitive?

Are you factually stating all systems which run Perl only
run Perl versions 5.8 and newer?

I am most skeptical you know everything there is to know
about every computer system in use, worldwide.

> If it's a situation in which the binmode statement is a no-op,
 > having it in won't hurt;

This is confusing. What reason would you offer readers
for them to include Perl code which performs no function?

Are you stating there is not a single system in use which
will be effected by a binmode statement, when not needed
in programming?

I am very skeptical about your statements. You are informing
readers there are no longer any systems, no longer any reasons
to be concerned about binmode being used, or not used.

Your statements are based upon a premise all systems, literally
all systems run the most recent operating systems and most recent
versions of Perl and based upon a premise there are no systems
found which are binmode sensitive.

I know this is not true.

Purl Gurl



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

Date: Thu, 01 Feb 2007 16:08:54 -0800
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: Upload file fails
Message-Id: <45C28116.505@purlgurl.net>

Michele Dondi wrote:

> Purl Gurl wrote:

>>>> Finally, failure of CGI.pm to function correctly with Linux.

>>> Huh?!? Since when?

>> My suggestion is you read, research and learn about
>> Stein's CGI.pm module. Your learning will place you
>> in a position of not having to ask.

> Well, but I've never heard anything along the lines of what you claim,
> nor does it match with my own -admittedly very limited- experience.
> Thus I would be extremely grateful to you if you could post some
> examples of code showing how CGI.pm "fails to function correctly with
> Linux"...


Do you read "Slave Girl" tattooed upon my forehead?

Purl Gurl



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

Date: Thu, 01 Feb 2007 11:16:20 -0800
From: Fred Hare <fred4414@nethere.com>
Subject: Win32::Clipboard mutilates \n
Message-Id: <-IydnV1uRs0VoV_YnZ2dnUVZ8sSrnZ2d@giganews.com>

Using WinXP and Perl ActiveState 5.61

The following code loads some text to the clipboard. However when I 
paste from the clipboard to a text editor the newlines (hex 0D 0A) are 
gone, replaced by hex 0A. I wonder if this usual for Win32::Clipboard 
or if my Perl installation is broken. I have also tried text from <<here 
and text from <DATA> with the same result.

Fred


use strict ;
use warnings ;
use Win32::Clipboard ;

my $CLIP = Win32::Clipboard();

my $block = '<table border="0" cellpadding="2" cellspacing="2" 
width="70%">' . "\n" . '<tbody>' . "\n" .
     '<tr>' . "\n" . '  <td valign="top"><br>' . "\n" .  '    </td>' . 
"\n" .  '   </tr>' . "\n" . '  </tbody>' . "\n" . '</table>' . "\n" . 
'<br>' ;

$CLIP->Set($block);

__DATA__
<table border="0" cellpadding="2" cellspacing="2" width="70%">
   <tbody>
     <tr>
       <td valign="top"><br>
       </td>
     </tr>
   </tbody>
</table>
<br>

__END__

-- 
When using my email address, add the word "Trustme" anywhere on the 
subject-line. Otherwise the message will be deleted on the server.


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

Date: Thu, 01 Feb 2007 13:37:28 -0600
From: l v <veatchla@yahoo.com>
Subject: Re: Win32::Clipboard mutilates \n
Message-Id: <12s4gbhkdd79hbb@news.supernews.com>

Fred Hare wrote:
> Using WinXP and Perl ActiveState 5.61
> 
> The following code loads some text to the clipboard. However when I 
> paste from the clipboard to a text editor the newlines (hex 0D 0A) are 
> gone, replaced by hex 0A. I wonder if this usual for Win32::Clipboard or 
> if my Perl installation is broken. I have also tried text from <<here 
> and text from <DATA> with the same result.
> 
> Fred
> 
> 
[code snip]
> 

Pastes correctly into wordpad, notepad+ (RogSoft), Lotus Notes, vim 
(windows) and a dtterm session.

Does *not* paste correctly into notepad (windows standard).

My guess is that the text editor is broken.

-- 

Len


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

Date: Thu, 01 Feb 2007 14:49:40 -0800
From: Fred Hare <fred4414@nethere.com>
Subject: Re: Win32::Clipboard mutilates \n
Message-Id: <tPidneCOVrYU81_YnZ2dnUVZ8t2snZ2d@giganews.com>

l v wrote:
> Fred Hare wrote:
>> Using WinXP and Perl ActiveState 5.61
>>
>> The following code loads some text to the clipboard. However when I 
>> paste from the clipboard to a text editor the newlines (hex 0D 0A) are 
>> gone, replaced by hex 0A. I wonder if this usual for Win32::Clipboard or 
>> if my Perl installation is broken. I have also tried text from <<here 
>> and text from <DATA> with the same result.
>>
>> Fred
>>
>>
> [code snip]
> 
> Pastes correctly into wordpad, notepad+ (RogSoft), Lotus Notes, vim 
> (windows) and a dtterm session.
> 
> Does *not* paste correctly into notepad (windows standard).
> 
> My guess is that the text editor is broken.
> 
OK, I tried 8 different text editors and also
   my $clip = Win32::Clipboard::GetText();
   print "Clipboard content is $clip\n" ;

All but Windows Notepad and UltraEdit converted "0A" back to "0D 0A"
Fred

-- 
When using my email address, add the word "Trustme" anywhere on the 
subject-line. Otherwise the message will be deleted on the server.


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

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


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