[30044] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1287 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 18 18:09:40 2008

Date: Mon, 18 Feb 2008 15:09:08 -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, 18 Feb 2008     Volume: 11 Number: 1287

Today's topics:
    Re: Linux, IO::Socket::INET and recv'ing broadcasted UD <DJStunks@gmail.com>
        Number of days since 1/1/2000 oprah.chopra@gmail.com
    Re: Number of days since 1/1/2000 <m@rtij.nl.invlalid>
    Re: Number of days since 1/1/2000 <glex_no-spam@qwest-spam-no.invalid>
    Re: Number of days since 1/1/2000 oprah.chopra@gmail.com
    Re: Number of days since 1/1/2000 oprah.chopra@gmail.com
    Re: Number of days since 1/1/2000 <joost@zeekat.nl>
    Re: Number of days since 1/1/2000 <joost@zeekat.nl>
    Re: Number of days since 1/1/2000 <ben@morrow.me.uk>
    Re: Number of days since 1/1/2000 <ben@morrow.me.uk>
    Re: Number of days since 1/1/2000 <someone@example.com>
    Re: Regular Expression to Replace UPPER Case Text with  <tadmc@seesig.invalid>
    Re: Regular Expression to Replace UPPER Case Text with  <kevin.penny@gmail.com>
        Searching within XLS files - is it good approach ? <telemach@go2.pl>
    Re: Searching within XLS files - is it good approach ? <joost@zeekat.nl>
    Re: Searching within XLS files - is it good approach ? <telemach@go2.pl>
    Re: Searching within XLS files - is it good approach ? <arifsaha@yahoo.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 18 Feb 2008 14:19:47 -0800 (PST)
From: DJ Stunks <DJStunks@gmail.com>
Subject: Re: Linux, IO::Socket::INET and recv'ing broadcasted UDP
Message-Id: <46d82a5e-bec2-4d80-b7bb-bfd7325a32f9@s19g2000prg.googlegroups.com>

On Feb 17, 10:16 pm, DJ Stunks <DJStu...@gmail.com> wrote:
> On Feb 17, 8:24 am, DJ Stunks <DJStu...@gmail.com> wrote:
> > In summary, I'm attempting to use Net::DHCP::Packet and
> > IO::Socket::INET to generate, transmit and receive DHCP messages
> > (discover, offer, request, ack).  The problem is that I'm not able to
> > use the IO::Socket recv method to receive a broadcasted DHCP offer
> > packet.  My script blocks indefinitely though I see the offer arrive
> > via Wireshark.


> Well, after Ben mentioned promiscuous mode I did some more Googling
> and it turns out Abigail had problems with the same issue in 2004
> (http://www.perlmonks.org/index.pl?node_id=325248).
>
> So I feel a lot better if it can happen to him too ;-)
>
> Abigail was on RH; I'm on Fedora.  So now to figure out what was
> blocked and how to unblock it.  iptables?  I'll check tomorrow but I
> thought I tried with the thing wide open at least once...

Still no luck.  Have tried with Flags => 1 in the IO::Socket::INET
constructor.  The DHCPOFFER is broadcasted regardless (Ethernet
destination MAC = ff:ff:ff:ff:ff:ff; destination IP = 255.255.255.255;
destination udp port = 68) but my socket never receives it.

Have run with iptables completely flushed.  Tried running the same
script on FreeBSD with the same results.

Does Abigail still hang out here?  It sounds like he had an identical
issue...

Last thing to do: trying to set interface as promiscuous.  Can I do it
from Perl?  I tried ifconfig eth0 promisc before running the script,
but identical results.

Thanks,
-jp


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

Date: Mon, 18 Feb 2008 11:20:30 -0800 (PST)
From: oprah.chopra@gmail.com
Subject: Number of days since 1/1/2000
Message-Id: <7c71334e-95bd-46da-bd83-78d7bb72d175@u10g2000prn.googlegroups.com>

I am using the following subroutine to calculate the  number of days
since 1/1/2000 . Is there any possible bug in it? I know  I can use
Date::Manip but it will slow down my program which is around 100 kb
long.

use strict;
use warnings;

my $days = &calc_days;

print "The number of days since 1/1/2000 is $days\n";

###############

sub calc_days {

my ( $mday, $mon, $year ) = ( localtime(time) )[3,4,5];
      if ($mday < 10) { $mday = "0$mday"; }

$year += 1900;

# assign the Beginning date values

my ($MTH,$TDD,$YRW) = (1,1,2000);

my @TM = (31,28,31,30,31,30,31,31,30,31,30,31);
my $total_days = 0;

while ($MTH <= ($mon + 1) && $YRW == $year || $MTH <= 12 && $YRW <
$year)  {

 ## test for leap year
my    $yeardiv = ($YRW / 4);
my    $yearint = int($yeardiv);
my    $yeardiv1 = ($YRW / 100);
my    $yearint1 = int($yeardiv1);
    if ($yeardiv eq $yearint && $yeardiv1 ne $yearint1) {
       $TM[1] = 29;
    }else {    $TM[1] = 28;
    }

     if ($MTH == ($mon + 1) && $YRW == $year)   {

          while (++$TDD <= $mday)  { $total_days += 1; }

     }else{
           while (++$TDD <= $TM[$MTH - 1])  { $total_days += 1; }

 $TDD = 0;   # reset TDD after each full month
     }   # end inside if/else

 $MTH += 1;

 if  ($MTH == 13 )  {
 $MTH =1;
 $YRW += 1;
 }
}  # end outside loop

return $total_days;

} # end sub


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

Date: Mon, 18 Feb 2008 20:58:13 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Number of days since 1/1/2000
Message-Id: <pan.2008.02.18.19.58.13@rtij.nl.invlalid>

On Mon, 18 Feb 2008 11:20:30 -0800, oprah.chopra wrote:

> I am using the following subroutine to calculate the  number of days
> since 1/1/2000 . Is there any possible bug in it? I know  I can use
> Date::Manip but it will slow down my program which is around 100 kb
> long.

Seeing you use a loop to calculate the difference, are you sure 
Date::Manip is slower? Did you benchmark it? You might be surprised.

M4


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

Date: Mon, 18 Feb 2008 14:03:51 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Number of days since 1/1/2000
Message-Id: <47b9e4a7$0$10301$815e3792@news.qwest.net>

oprah.chopra@gmail.com wrote:
> I am using the following subroutine to calculate the  number of days
> since 1/1/2000 . Is there any possible bug in it? I know  I can use
> Date::Manip but it will slow down my program which is around 100 kb
> long.

It's doubtful that using Date::Manip would slow it down much, if at
all.  So what if using it added .001 second to the run time? The
valuable lesson is that you probably wasted a couple of hours/days
writing this poor code, when all it would really take is a module and
a call or two. The solution is already written, well tested, and
makes your code much easier to manage. Code re-use is a wonderful
thing.

> use strict;
> use warnings;

Good start.

> 
> my $days = &calc_days;
              ^
Eeeekk.. not so good.

> 
> print "The number of days since 1/1/2000 is $days\n";
> 
> ###############
> 
> sub calc_days {
> 
> my ( $mday, $mon, $year ) = ( localtime(time) )[3,4,5];
>       if ($mday < 10) { $mday = "0$mday"; }

Whenever I see that, instead of sprintf, I say to myself, "Inexperienced 
coder."
> 
> $year += 1900;
> 
> # assign the Beginning date values
> 
> my ($MTH,$TDD,$YRW) = (1,1,2000);

Upper case variables. Less experienced than I thought.

> 
> my @TM = (31,28,31,30,31,30,31,31,30,31,30,31);
> my $total_days = 0;

At this point I'd give up and never use this code, because
it's pretty obvious the programmer really doesn't know
what they're doing.

After looking your example it's probably not surprising that
your code is possibly 100kb. BTW: The number of bytes of
code has nothing to do with how long it might take to execute.



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

Date: Mon, 18 Feb 2008 12:22:06 -0800 (PST)
From: oprah.chopra@gmail.com
Subject: Re: Number of days since 1/1/2000
Message-Id: <b178f896-0431-4e02-970e-a37770fc8d64@e23g2000prf.googlegroups.com>

Martijn Lievaart wrote:
>
> Seeing you use a loop to calculate the difference, are you sure
> Date::Manip is slower? Did you benchmark it? You might be
surprised. >

One problem with Date::Manip is it is not a standard module and not
available on some of the servers I run the code on. Since my code is
alrady 100+kb long, I would think requireinf another few hundred kb
would be overkill for something I can do in one subroutine?


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

Date: Mon, 18 Feb 2008 12:27:06 -0800 (PST)
From: oprah.chopra@gmail.com
Subject: Re: Number of days since 1/1/2000
Message-Id: <d6a7945f-8a2b-4109-8e01-e74118d4fe9c@d21g2000prf.googlegroups.com>

J. Gleixner wrote:
> Whenever I see that, instead of sprintf, I say to myself,
"Inexperienced > coder."

Well I have been coding perl for seven years and and count on one
hand the number of times I used sprintf. print is simple , why make
code more unreadable by unncessarily cluttering it with esoteric
functions? At least that has always been my philosophy. Yes there may
be more 'technically correct' ways to do things, but I am running a
business and have to look at the bigger picture . If I hire a new
perl programmer, will they know the difference between print and
sprintf?

I can tell you have a PhD, because you suffer from the classic
ostrich mentality, i.e head is stuck in the ground lookiing at
details, while you can't see the train coming..


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

Date: Mon, 18 Feb 2008 21:30:46 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: Number of days since 1/1/2000
Message-Id: <87r6fanh1l.fsf@zeekat.nl>

oprah.chopra@gmail.com writes:

> Martijn Lievaart wrote:
>>
>> Seeing you use a loop to calculate the difference, are you sure
>> Date::Manip is slower? Did you benchmark it? You might be
> surprised. >
>
> One problem with Date::Manip is it is not a standard module and not
> available on some of the servers I run the code on. Since my code is
> alrady 100+kb long, I would think requireinf another few hundred kb
> would be overkill for something I can do in one subroutine?

If my choice was between installing a prepackaged, tested, measily 100K
of code or reverse engineering a 100K of code, I know I wouldn't easily
take the second option.

Even if the module contains XS code (I don't think Date::Manip does, but
I haven't checked) you can generally install the module into a local
tree and copy it with your own code, provided the systems have all have
the same specs (OS and perl version, more or less).

Also, many unix systems have system packages for lots of perl modules
(on linux, I'd be surprised if any large vendor doesn't ship
Date::Manip, even if it's not installed by default).

-- 
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/


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

Date: Mon, 18 Feb 2008 21:38:24 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: Number of days since 1/1/2000
Message-Id: <87mypyngov.fsf@zeekat.nl>

oprah.chopra@gmail.com writes:

> J. Gleixner wrote:
>> Whenever I see that, instead of sprintf, I say to myself,
> "Inexperienced > coder."
>
> Well I have been coding perl for seven years and and count on one
> hand the number of times I used sprintf. print is simple , why make
> code more unreadable by unncessarily cluttering it with esoteric
> functions? At least that has always been my philosophy. Yes there may
> be more 'technically correct' ways to do things, but I am running a
> business and have to look at the bigger picture . If I hire a new
> perl programmer, will they know the difference between print and
> sprintf?

Are you kidding? sprintf isn't esotheric, it's been a standard C
function for ages and pretty much all modern scripting languages
implement it in one way or the other. I don't use sprintf every day but
for general number-to-string conversion it's by far the best and easiest
to use built-in function.

-- 
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/


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

Date: Mon, 18 Feb 2008 20:41:02 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Number of days since 1/1/2000
Message-Id: <u37p85-kj6.ln1@osiris.mauzo.dyndns.org>


Quoth oprah.chopra@gmail.com:
> I am using the following subroutine to calculate the  number of days
> since 1/1/2000 . Is there any possible bug in it? I know  I can use
> Date::Manip but it will slow down my program which is around 100 kb
> long.
> 
> use strict;
> use warnings;
> 
> my $days = &calc_days;

Don't call subs with & unless you need to.

> print "The number of days since 1/1/2000 is $days\n";
> 
> ###############
> 
> sub calc_days {
> 
> my ( $mday, $mon, $year ) = ( localtime(time) )[3,4,5];

Your code will be much more readable if you use sensible indentation.

>       if ($mday < 10) { $mday = "0$mday"; }

What is the point of this? You only use $mday numerically, so this will
have exactly no effect.

> $year += 1900;
> 
> # assign the Beginning date values
> 
> my ($MTH,$TDD,$YRW) = (1,1,2000);

Representing dates in M/D/Y order is not helpful when performing date
calculations.

> my @TM = (31,28,31,30,31,30,31,31,30,31,30,31);
> my $total_days = 0;
> 
> while ($MTH <= ($mon + 1) && $YRW == $year || $MTH <= 12 && $YRW <
> $year)  {
> 
>  ## test for leap year
> my    $yeardiv = ($YRW / 4);
> my    $yearint = int($yeardiv);
> my    $yeardiv1 = ($YRW / 100);
> my    $yearint1 = int($yeardiv1);
>     if ($yeardiv eq $yearint && $yeardiv1 ne $yearint1) {
>        $TM[1] = 29;
>     }else {    $TM[1] = 28;
>     }

This is incorrect. 2000 *was* a leap year, as it is divisible by 400.
This means that all dates after 2000-02-29 will be returned as one day
short.

While this is fixable, it is much simpler to just use the values
returned by time directly. The following is correct except for leap
seconds, which are generally not supported by localtime anyway.

use Time::Local qw/timelocal/;  # core since 5.000

my $elapsed = time - timelocal 0, 0, 0, 1, 0, 2000;
my $days = int( $elapsed / (60*60*24) );

>      }   # end inside if/else

This sort of comment is unhelpful, and would be unnecessary if you had
used decent indentation.

Ben



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

Date: Mon, 18 Feb 2008 20:44:06 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Number of days since 1/1/2000
Message-Id: <m97p85-kj6.ln1@osiris.mauzo.dyndns.org>


Quoth oprah.chopra@gmail.com:
> J. Gleixner wrote:
> > Whenever I see that, instead of sprintf, I say to myself,
> "Inexperienced > coder."
> 
> Well I have been coding perl for seven years and and count on one
> hand the number of times I used sprintf. print is simple , why make
> code more unreadable by unncessarily cluttering it with esoteric
> functions?

IMHO you managed to make your code quite unreadable enough without using
sprintf :).

> At least that has always been my philosophy. Yes there may
> be more 'technically correct' ways to do things, but I am running a
> business and have to look at the bigger picture . If I hire a new
> perl programmer, will they know the difference between print and
> sprintf?

Would you *really* hire someone who didn't, or who couldn't find out in
10 seconds from the docs?

Ben



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

Date: Mon, 18 Feb 2008 22:42:20 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Number of days since 1/1/2000
Message-Id: <gRnuj.30795$w57.13667@edtnps90>

oprah.chopra@gmail.com wrote:
> I am using the following subroutine to calculate the  number of days
> since 1/1/2000 . Is there any possible bug in it? I know  I can use
> Date::Manip but it will slow down my program which is around 100 kb
> long.

[ SNIP ]

You could always do it like this:

use strict;
use warnings;
use POSIX qw/ mktime /;

my $days = calc_days_MDY( 1, 1, 2000 );

print "The number of days since 1/1/2000 is $days\n";

sub calc_days_MDY {
     my ( $mon, $day, $year ) = @_;

     my $total_days;
     for my $i_year ( $year - 1900 .. ( localtime )[ 5 ] - 1 ) {
         $total_days += 1 + ( localtime mktime 0, 0, 12, 31, 11, $i_year 
)[ 7 ];
         }
     $total_days += 1 + ( localtime )[ 7 ];
     $total_days -= 1 + ( localtime mktime 0, 0, 12, $day, $mon - 1, 
$year - 1900 )[ 7 ];

     return $total_days;
     }



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, 18 Feb 2008 16:31:59 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Regular Expression to Replace UPPER Case Text with lower case  text
Message-Id: <slrnfrk1qv.ejt.tadmc@tadmc30.sbcglobal.net>

ccc31807 <cartercc@gmail.com> wrote:
> On Feb 18, 9:34 am, RK_78 <riad.ka...@gmail.com> wrote:
>> Better ideas folks ?
>
> Ditch CF and use Perl.


What, and get laughed at?


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


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

Date: Mon, 18 Feb 2008 12:44:35 -0800 (PST)
From: penny <kevin.penny@gmail.com>
Subject: Re: Regular Expression to Replace UPPER Case Text with lower case  text
Message-Id: <1efae968-bc81-45d2-af32-1c326411f19c@u10g2000prn.googlegroups.com>

Thanks for all the replies - For those keeping Score at home:
Replace:
"([A-Z]){1}([[:upper:]]+)"
WITH:
"\1\L\2"

The reason I didn't go the CFusion newsgroup first is that CF runs
with a limited perl engine and I figured you guys would know more
about regex than the cf group (eek)

But turns out it can be done and very easily with one line of
REReplace.

The application is written in CF so - sorry- no chance of ditching
cf ;)

This is a back reference example and here is the Break Down:
First 'group' is the
([A-Z]){1} - This means exactly 1 Single Upper Case Character and the
() parenthesis is so that I can Reference this Match later in the
Replace with string as \1
([[:upper:]]+) - This means 1 or more upper case characters and the ()
parenthesis is so that I can reference this Match later as \2

Then I replace this string with
\1 - this means the 'first' match from my () group (which will be a
single upper case character)
\L\2 - Means the Rest of the String that I got from my second () match
above as \2 will be all LOWER case

Thanks


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

Date: Mon, 18 Feb 2008 12:13:32 -0800 (PST)
From: Telemach <telemach@go2.pl>
Subject: Searching within XLS files - is it good approach ?
Message-Id: <1d64fb5b-46f8-4e0f-8633-b5aaebbda78d@e23g2000prf.googlegroups.com>


I'm newbie in Perl but don't give up so easily. My question is : Is it
possible to achieve my goals browsing just a xls file ? I know it's
good to convert to some better format but I would be happy if that
step is not necessary.

I have big Excel file which has over 20 worksheets.
What I need is to search for $value1 within the whole spreadsheet and
if found to search for $value2 within a worksheet where $value1 was
found. I know that cells have multi line input like :

ABCaaa
CDEbbb
EFGccc
etc.

so if $value2 = "CDE" I need Perl to get only CDEbbb and put under
$result1

next I want to read the col/row number of search result for $value2
and check the cell on two colums right from this one and copy the
content to $result2, if cell is blank I need to check
every single one above until cell with content is found

I'd appreciate any help about what module and commands shall be used
or where can I find an examples or a tutorial about searching withing
XLS files.

Kind regards,

- Telemach -


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

Date: Mon, 18 Feb 2008 21:24:24 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: Searching within XLS files - is it good approach ?
Message-Id: <87ve4mnhc7.fsf@zeekat.nl>

Telemach <telemach@go2.pl> writes:

> I'm newbie in Perl but don't give up so easily. My question is : Is it
> possible to achieve my goals browsing just a xls file ? I know it's
> good to convert to some better format but I would be happy if that
> step is not necessary.

I've only used SpreadSheet::WriteExcel, which as the name implies,
doesn't read excel files, but the documentation for that module points
to a lot modules that do. See:

<http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-2.20/lib/
Spreadsheet/WriteExcel.pm#READING_EXCEL_FILES>

As far as I can tell, most of those will only work on Windows.

Even more can probably be found if you search for "excel" on
<http://search.cpan.org/>


-- 
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/


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

Date: Mon, 18 Feb 2008 12:42:08 -0800 (PST)
From: Telemach <telemach@go2.pl>
Subject: Re: Searching within XLS files - is it good approach ?
Message-Id: <6398f640-b953-4ebd-86b6-738df5c311d2@i29g2000prf.googlegroups.com>

> As far as I can tell, most of those will only work on Windows.

I need to get this working under linux


> Even more can probably be found if you search for "excel" on
> <http://search.cpan.org/>

I found some but still can't get a decent documentation how to search
and not only read.

- Telemach -


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

Date: Mon, 18 Feb 2008 17:57:12 -0500
From: S P Arif Sahari Wibowo <arifsaha@yahoo.com>
Subject: Re: Searching within XLS files - is it good approach ?
Message-Id: <alpine.OSX.1.00.0802181755440.17449@imac2006.local>

  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.

--0-328509215-1203375434=:17449
Content-Type: TEXT/PLAIN; charset=ISO-2022-JP; format=flowed

On Mon, 18 Feb 2008, Telemach wrote:
> Is it possible to achieve my goals browsing just a xls file ?

Try this one: 
http://search.cpan.org/~szabgab/Spreadsheet-ParseExcel-0.32/

-- 
                              (stephan paul) Arif Sahari Wibowo
    _____  _____  _____  _____
   /____  /____/ /____/ /____
  _____/ /      /    / _____/      http://www.arifsaha.com/

Disclaimer: IANAL, IANALP, IANAMD, IANAMP, IANAAP
my statements - if any - should be treated as such.

Xinnian Kuaile! 新年快樂 Gongxi Facai 恭喜發財
--0-328509215-1203375434=:17449--


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

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


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