[26253] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8437 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 20 18:05:35 2005

Date: Tue, 20 Sep 2005 15: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: 8437

Today's topics:
    Re: best practices - compare lists <abigail@abigail.nl>
    Re: chenga script to show one houer more <mothra@nowhereatall.com>
    Re: chenga script to show one houer more (Anno Siegel)
    Re: finding a binary pattern in a file. <newskf@numericable.fr>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 20 Sep 2005 20:36:23 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: best practices - compare lists
Message-Id: <slrndj0sm7.qv6.abigail@alexandra.abigail.nl>

Rocky Allen (everythingelse@bobotheclown.org) wrote on MMMMCDIII
September MCMXCIII in <URL:news: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?


$ perldoc -q 'duplicate elements'


HTH. HAND.


Abigail
-- 
perl -we'$;=$";$;{Just=>another=>Perl=>Hacker=>}=$/;print%;'


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

Date: Tue, 20 Sep 2005 11:36:50 -0700
From: "Mothra" <mothra@nowhereatall.com>
Subject: Re: chenga script to show one houer more
Message-Id: <43305d5f$1@usenet.ugs.com>

Hi Anno,

Anno Siegel wrote:
(snipped)
> That's hard to do, since it is by no means clear what change you want.
> Show the time one hour later than the code you have?

I think the OP was a poor attempt at DST conversion. Hence
my post about the DateTime project.

> Since you
> mention DST in the context, you can simply add 1 to the number of
> hours you have now.  If it's DST it won't overflow into the next day,
> so the operation is trivial.

not quite, switching to and from DST is not an easy task. Example:

 All countries in Europe, except Iceland , observe daylight-saving time and
change on the same date: moving clocks forward one hour on the last Sunday
in March and back one hour on the last Sunday in October.
In the West European (UTC), Central European (UTC+1), and
East European (UTC+2) time zones the change is simultaneous: on both dates
the clocks are changed everywhere at 01:00 UTC, i.e. from local times
of 01:00/02:00/03:00 to 02:00/03:00/04:00 in March, and vice versa in 
October.

If the script in question was to run at 12:30 UTC and you add one hour to 
that is would
be 1:30UTC which would be an invalid time for that zone (Western European)

This and other issues is what the DateTime project is attempting to solve.
If you have a chance, please take a look at the DateTime project
http://DateTime.perl.org I think you will find it to be a very complete
date/time suite of modules.

> If it's something else you want, please explain.

Yes, I think the OP could have explained a little better but I suppect
that english is not his native tongue.

(more snippage)
>
>
> Anno

Mothra 




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

Date: 20 Sep 2005 21:51:31 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: chenga script to show one houer more
Message-Id: <dgq093$ok2$1@mamenchi.zrz.TU-Berlin.DE>

Mothra <mothra@nowhereatall.com> wrote in comp.lang.perl.misc:
> Hi Anno,
> 
> Anno Siegel wrote:
> (snipped)
> > That's hard to do, since it is by no means clear what change you want.
> > Show the time one hour later than the code you have?
> 
> I think the OP was a poor attempt at DST conversion. Hence
> my post about the DateTime project.
> 
> > Since you
> > mention DST in the context, you can simply add 1 to the number of
> > hours you have now.  If it's DST it won't overflow into the next day,
> > so the operation is trivial.
> 
> not quite, switching to and from DST is not an easy task. Example:
> 
>  All countries in Europe, except Iceland , observe daylight-saving time and
> change on the same date: moving clocks forward one hour on the last Sunday
> in March and back one hour on the last Sunday in October.
> In the West European (UTC), Central European (UTC+1), and
> East European (UTC+2) time zones the change is simultaneous: on both dates
> the clocks are changed everywhere at 01:00 UTC, i.e. from local times
> of 01:00/02:00/03:00 to 02:00/03:00/04:00 in March, and vice versa in 
> October.
> 
> If the script in question was to run at 12:30 UTC and you add one hour to 
> that is would
> be 1:30UTC which would be an invalid time for that zone (Western European)

I'm not sure I understand your argument. Is that 12:30 Sunday or Monday
(before or after the switchover) and is it spring or autumn?  And how can
a UTC time be valid or invalid in a certain time zone?  It's either valid
UTC or it isn't.

In any case, it is concerned with *when* to begin (or stop) adding an hour.
My only point was that the switchover, when it occurs, doesn't involve a
date change.  That is taken care of in all civilized time zones.

> This and other issues is what the DateTime project is attempting to solve.
> If you have a chance, please take a look at the DateTime project
> http://DateTime.perl.org I think you will find it to be a very complete
> date/time suite of modules.

Ah, I'm sure it is.  Time and calendar(s) are fascinating subjects, and
they lend themselves to be cast into Perl modules.  That probably explains
the proliferation of Date/Time modules on CPAN, not by itself a bad thing.

On the other hand, I find that my day-to-day needs are met by Perl's
localtime and gmtime, POSIX::strftime and the occasional use of Time::Local.
So, I'm currently just not interested enough in the subject to review a
large Date/Time project.  I do understand the fascination with it, I've
been there.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Tue, 20 Sep 2005 22:23:16 +0200
From: News KF <newskf@numericable.fr>
Subject: Re: finding a binary pattern in a file.
Message-Id: <43306fa2$0$169$a3f2974a@nnrp1.numericable.fr>

Hi,

I think this solution should work.
However $buffer would grow during the parsing and could therefore blow 
up the memory.


If the file is big and there is no delimiter, then you should probably 
use the read statement in order to read junks of data.

Additionally you had to be sure, that the search pattern is not in the 
part, that is wrapping (pattern is half at end of previous junk and half 
at beginning of new junk).



the  code below should roughly work: (I did not try it, so some errors 
may be in):

my $searchspace="";
my $chunksize = 1024; # 1 kB in one chunk
my $hitcount=0;
my $positioninstream=0;

while (!eof(IN)){
   read($chunk,$chunksize,$_);   #### please check exact order of
                                 ### read or sysread. Don't know it by
                                 ### heart
    $searchspace .= unpack("B*", $_); #
    my $i;
    do {
       $i=index($searchspace,$thing_to_find);
       if($i>=0){
           print "Found at ", ($i+$positioninstream), "\n";
           $positioninstream += $i+length($thing_to_find);
           $searchspace =
                 substr($searchspace,$i+$length($thing_to_find));
       }
    } while $i>=0;
}


bye


nkf.


P.S. This suggested solution is not optimized for speed thoug.

xhoster@gmail.com wrote:
> 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
> 


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

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


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