[26252] in Perl-Users-Digest
Perl-Users Digest, Issue: 8436 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 20 14:05:19 2005
Date: Tue, 20 Sep 2005 11:05:05 -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 Tue, 20 Sep 2005 Volume: 10 Number: 8436
Today's topics:
best practices - compare lists <everythingelse@bobotheclown.org>
Re: best practices - compare lists xhoster@gmail.com
Re: best practices - compare lists <jurgenex@hotmail.com>
Re: chenga script to show one houer more <mothra@nowhereatall.com>
finding a binary pattern in a file. <shashank@mia.ece.uic.edu>
Re: finding a binary pattern in a file. xhoster@gmail.com
Re: STDOUT pass-through with system() xhoster@gmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 20 Sep 2005 15:38:27 GMT
From: Rocky Allen <everythingelse@bobotheclown.org>
Subject: best practices - compare lists
Message-Id: <pan.2005.09.20.15.40.59.612988@bobotheclown.org>
Hey Y'all
I have been trying to find the most effective way to compare the values in
two arrays. The idea is to match the list of files sent into cpio vs. the
files that actually made it onto the tape. I have been looking at
Array::Compare, but the example in cpan is broken. Does anyone know the
best way to compare two arrays?
thanks,
Rocky
#!/usr/bin/perl
use strict;
use warnings;
my @posttape;
open FH3, '</tmp/cpioin' or die "Cannot open /tmp/cpioin: $!";
my @pretape = <FH3>;
open IN, '<', '/tmp/filesontape' or die "Cannot open /tmp/filesontape: $!";
while ( <IN> ) {
my @fields = split;
push @posttape, "$fields[8]\n";
}
close IN;
open(FH5, '>/tmp/ontape') or die "no FH5:$!";
print FH5 @posttape;
------------------------------
Date: 20 Sep 2005 16:08:20 GMT
From: xhoster@gmail.com
Subject: Re: best practices - compare lists
Message-Id: <20050920120820.543$Qq@newsreader.com>
Rocky Allen <everythingelse@bobotheclown.org> wrote:
> Hey Y'all
> I have been trying to find the most effective way to compare the values
> in two arrays.
The easiest way to compare two arrays is to convert them into two hashes.
> The idea is to match the list of files sent into cpio vs.
> the files that actually made it onto the tape. I have been looking at
> Array::Compare, but the example in cpan is broken.
Could you be more specific?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Tue, 20 Sep 2005 16:53:52 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: best practices - compare lists
Message-Id: <A8XXe.7394$nV1.4225@trnddc06>
Rocky Allen wrote:
> Does anyone know the best way to compare two arrays?
Simple.
my $equal=1;
for (0..$#arr1) {
$equal = $arr1[$_] == $arr2[$_];
#use "eq" instead of "==" if comparing text
last unless $equal;
}
There isn't much optimization you can do because you have to compare every
single element.
------------------------------
Date: Tue, 20 Sep 2005 10:10:04 -0700
From: "Mothra" <mothra@nowhereatall.com>
Subject: Re: chenga script to show one houer more
Message-Id: <4330490a$1@usenet.ugs.com>
Hello,
kozmos241 wrote:
> On Mon, 19 Sep 2005 10:53:18 -0700, Mothra wrote:
>
>> Hello,
>>
(my stuff snipped)
> well, it will have to do, i hopet that someon will change in script
> needed and post it cos i am not perl programer but its never to late
> lo learn something.
Sorry, I did not realize that. I should have provided a sample script.
use strict;
use warnings;
use DateTime;
use DateTime::Format::Strptime;
use CGI;
my $Strp = new DateTime::Format::Strptime(
pattern => '%d %B %Y %H:%M',
locale => 'en_de',
time_zone => 'Europe/Berlin',
);
my $dt = DateTime->now( locale => 'de', time_zone => 'Europe/Berlin' );
my $q = new CGI;
my $table = $q->table(
$q->Tr(
$q->td(
{ width => 185, valign => 'top', height => 15 },
$q->p( $q->b( 'City', 'State' ), $Strp->format_datetime($dt) )
)
)
);
This should provide you what you need. With using the DateTime suite of
modules
it will "know" weather or not the date is DST or not. From the docs:
is_dst
Returns a boolean indicating whether or not the datetime object is
currently in Daylight Saving Time or not.
So you could use this Method to see if the time is DST or not.
>>>
>>>}elsif ($mon == 3){
>>> $mon = "März";
^^^^^^
one question, what language is that? My guess was german (hence my example)
I hope this helps
Mothra
------------------------------
Date: Tue, 20 Sep 2005 12:11:58 -0500
From: Shashank Khanvilkar <shashank@mia.ece.uic.edu>
Subject: finding a binary pattern in a file.
Message-Id: <dgpfon$kjt$1@newsx.cc.uic.edu>
Hi,
I want to write a simple program that can search for a 13 _BIT_ pattern
in a file opened in a binary mode. Is there a simple way of doing this?
for example, can someone complete the below program code.
open(IN,"$inFile");
binmode(IN);
while (<IN>) //while there is still data in the file
{
Read the IN file for the 13 bit pattern
if found{
..do something
}
}
Thanks
Shashank
------------------------------
Date: 20 Sep 2005 17:36:12 GMT
From: xhoster@gmail.com
Subject: Re: finding a binary pattern in a file.
Message-Id: <20050920133612.915$NN@newsreader.com>
Shashank Khanvilkar <shashank@mia.ece.uic.edu> wrote:
> Hi,
> I want to write a simple program that can search for a 13 _BIT_ pattern
> in a file opened in a binary mode. Is there a simple way of doing this?
> for example, can someone complete the below program code.
Is the file much smaller than memory? I'll assume not...
> open(IN,"$inFile");
> binmode(IN);
>
> while (<IN>) //while there is still data in the file
> {
> Read the IN file for the 13 bit pattern
> if found{
> ..do something
> }
> }
> Thanks
> Shashank
warn "Untested Code";
my $thing_to_find = some_string_of_ones_and_zeros();
my $count=0;
my $buffer='';
while (<IN>) { #presumably, $/ is set to something appropriate
$buffer .= unpack "B*", $_;
my $i=index $buffer, $thing_to_find;
unless ($i == -1) {
print "Found at ", ($i+$count), "\n";
};
$count+= length ( substr $buffer, 0, -length($thing_to_find),'');
};
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 20 Sep 2005 15:13:03 GMT
From: xhoster@gmail.com
Subject: Re: STDOUT pass-through with system()
Message-Id: <20050920111303.599$W1@newsreader.com>
Justin <kf1zr0y02@sneakemail.com> wrote:
> Justin <kf1zr0y02@sneakemail.com> wrote in
> news:Xns96D6D72D26F5Ekf1zr0y02sneakemail@18.181.0.25:
>
> > Turns out it must be two different causes producing similar errors
> > since in my production system I specify full paths to the executables.
>
> A classy guy replying to my own post but just in case it ever turns out
> to be useful to someone else...
>
> It turns out my problem was a couple of debug characters weren't being
> printed to STDERR but to the default STDOUT by mistake. In v5.002 these
> few chars in the STDOUT buffer were disappearing during either the
> system() or exec(), and since they'd never been seen in any output no-one
> spotted the error (I don't know why this would happen mind you). Under
> v5.8.0 these couple of chars were being flushed to STDOUT into the "data
> stream" which was screwing up latter processing. So it looks like some
> strange behaviour of v5.002 was covering up a bug that was there all the
> time...
I believe the behavior you observe is due to this:
(from perldoc -f system)
Beginning with v5.6.0, Perl will attempt to flush all files
opened for output before any operation that may do a fork,
but this may not be supported on some platforms (see
perlport). To be safe, you may need to set $| ($AUTOFLUSH
in English) or call the "autoflush()" method of "IO::Handle"
on any open handles.
Cheers,
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
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 V10 Issue 8436
***************************************