[28448] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9812 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 6 14:05:41 2006

Date: Fri, 6 Oct 2006 11:05:06 -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           Fri, 6 Oct 2006     Volume: 10 Number: 9812

Today's topics:
    Re: Can perl test for .mp3 file? <john@castleamber.com>
    Re: Complex regular expression <glex_no-spam@qwest-spam-no.invalid>
    Re: Find First Date of A Calendar Month\Year <idgarad@gmail.com>
    Re: Find First Date of A Calendar Month\Year <idgarad@gmail.com>
    Re: Hard or Easy? To find string, then grab criterion m samiam@mytrashmail.com
    Re: Hard or Easy? To find string, then grab criterion m <spamtrap@ntp.isc.org>
    Re: How to parse a new computer language in Perl? anno4000@radom.zrz.tu-berlin.de
    Re: If gethostbyname fails it never recovers <mark.clementsREMOVETHIS@wanadoo.fr>
    Re: LWP and Unicode (reading news)
    Re: newbie cspan example question <glex_no-spam@qwest-spam-no.invalid>
    Re: Output of Concise <glex_no-spam@qwest-spam-no.invalid>
    Re: parsing event handler and object data <nobull67@gmail.com>
    Re: parsing event handler and object data (reading news)
    Re: Parsing HTML - using HTML::TreeBuilder <DJStunks@gmail.com>
    Re: Passing parameter through SOAP::Lite <glex_no-spam@qwest-spam-no.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 6 Oct 2006 16:32:10 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Can perl test for .mp3 file?
Message-Id: <Xns98547559377F5castleamber@130.133.1.4>

Fred <itfred@cdw.com> wrote:

> On Fri, 06 Oct 2006 05:42:07 +0000, John Bokma wrote:
>  
>> The magic keyword is magic:
>> 
>> <http://search.cpan.org/search?query=magic&mode=all>
>> 
>> File::Type
>> File::MimeInfo::Magic
> 
> 
> I just fond that if I pass an .mp3 file, an empty
> text file, or a directory, to File::Type, it always
> returns a MIME type of application/octet-stream.

Are you sure this is File::Type, and not File::MimeInfo? I have no 
experience with the modules, but read the documentation (fast). I read 
that File::MimeInfo doesn't use magic, but (surprise!) 
File::MimeInfo::Magic does.

Also, IIRC, File::Type does use magic, but like I said, all from a quick 
glance at the documentation.

-- 
John                Experienced Perl programmer: http://castleamber.com/

          Perl help, tutorials, and examples: http://johnbokma.com/perl/


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

Date: Fri, 06 Oct 2006 12:46:38 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Complex regular expression
Message-Id: <452695fe$0$25774$815e3792@news.qwest.net>

chaitask@yahoo.com wrote:

>> /\A\*?\d(?:\d(?:\d(?:-(?:\d(?:\d(?:-(?:\d(?:\d\d?)?)?)?)?)?)?)?)?\*?\z/

 >Hi John,

John who?

 > I've just read up the perldoc on perlretut and am not still very clear
 > on this expression.....do you think you could write up a little help
 > note on this (rather, on how you framed it......the process of thinking
 > about it and framing it)? If you have time, that is.....
 >
 > Will be grateful for anything...

OK. You owe me for fixing the order of your response.


Take a look at YAPE::Regex::Explain, which should help you understand
regular expressions.

http://search.cpan.org/~pinyan/YAPE-Regex-Explain-3.011/Explain.pm


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

Date: 6 Oct 2006 09:47:39 -0700
From: "Idgarad" <idgarad@gmail.com>
Subject: Re: Find First Date of A Calendar Month\Year
Message-Id: <1160153259.297774.156140@k70g2000cwa.googlegroups.com>

The solution worked great but I modified it to take a month parameter
to ease the consecutive use of generating the calendars following
January. i.e. first_sunday_of_calmonth(1,2005) and
first_sunday_of_calmonth(4,2006).

sub first_sunday_of_calmonth {
  my $m = shift;
  my $y = shift;

  my $dow = strftime("%w", 0,0,0,1,$m-1,$y-1900);
  my $time = timelocal(0,0,0,1,$m-1,$y-1900);
  return $time - ($dow * 24 * 60 * 60);
}

A latter poster was correct, I was seeking the upper left-most box on a
calendar. I have posted below the finished product which was a simple
pager rotation script that generates a calendar in Excel format. It is
designed at this time only to handle 3 people as I have to fix the mod
(%) math to handle a variable number of people properly. If anyone
knows a good solution please let me know. Critiques welcome!

--schedule.pl--
#!/usr/bin/perl
###### List of People to be on rotation
# --users, -u = "jeff,john,jack" with the person working evening that
week covering the weekend
# --year, -y = "2008" for instance.
# You may need to set yout TZ environment variable if the script cannot
# determine your time zone from the system.
######
use Getopt::Long;
use Date::Manip;
use Spreadsheet::WriteExcel;
use Calendar::Functions;
use Date::Holidays::USFederal;

use POSIX qw/strftime/;
use Time::Local;

my @users = ();

$result = GetOptions ("users|u=s" => \@users,
			"year|y=s" => \$year);




print "first sunday of week 1 is: ", ParseDate("sunday week 0
$year"),"\n";
@users = split(/,/,join(',',@users));
print @users;
#this would be used later in mod math to get things rotating properly
#but it fails miserable due to the addition later
$totalUsers=scalar(@users);

my $first = first_sunday_of_calmonth(1,$year);
$date=strftime("%m/%d/%Y", localtime($first));

print ("Initial Offset is $date\n");


#Make A SpreadSheet
my $workbook = Spreadsheet::WriteExcel->new("alpha-pager-$year.xls"); #
Step 1


#Build Formats

$fmtMonth=$workbook->add_format();
$fmtMonth->set_align('center');
$fmtMonth->set_align('Vcenter');
$fmtMonth->set_border(1);
$fmtMonth->set_bg_color('white');
$fmtMonth->set_font('Times New Roman');
$fmtMonth->set_size(24);
$fmtMonth->set_bold(1);

$fmtWeek=$workbook->add_format();
$fmtWeek->set_align('center');
$fmtWeek->set_align('Vcenter');
$fmtWeek->set_border(1);
$fmtWeek->set_bg_color('white');
$fmtWeek->set_font('Times New Roman');
$fmtWeek->set_size(14);
$fmtWeek->set_bold(1);

$fmtDate=$workbook->add_format();
$fmtDate->set_align('left');
$fmtDate->set_align('top');
$fmtDate->set_left(1);
$fmtDate->set_right(1);
$fmtDate->set_bg_color('white');
$fmtDate->set_font('Times New Roman');
$fmtDate->set_size(12);
$fmtDate->set_bold(1);

$fmtText=$workbook->add_format();
$fmtText->set_align('left');
$fmtText->set_align('top');
$fmtText->set_left(1);
$fmtText->set_right(1);
$fmtText->set_bg_color('white');
$fmtText->set_font('Arial');
$fmtText->set_size(10);
$fmtText->set_bold(0);

$fmtHoliday=$workbook->add_format();
$fmtHoliday->set_align('right');
$fmtHoliday->set_align('bottom');
$fmtHoliday->set_text_wrap(1);
$fmtHoliday->set_left(1);
$fmtHoliday->set_right(1);
$fmtHoliday->set_bottom(1);
$fmtHoliday->set_bg_color('white');
$fmtHoliday->set_font('Arial');
$fmtHoliday->set_color('Blue');
$fmtHoliday->set_size(8);
$fmtHoliday->set_bold(1);

$fmtDate2=$workbook->add_format();
$fmtDate2->set_align('left');
$fmtDate2->set_align('top');
$fmtDate2->set_left(1);
$fmtDate2->set_right(1);
$fmtDate2->set_bg_color('silver');
$fmtDate2->set_font('Times New Roman');
$fmtDate2->set_color('grey');
$fmtDate2->set_size(12);
$fmtDate2->set_bold(1);

$fmtText2=$workbook->add_format();
$fmtText2->set_align('left');
$fmtText2->set_align('top');
$fmtText2->set_left(1);
$fmtText2->set_right(1);
$fmtText2->set_bg_color('silver');
$fmtText2->set_font('Arial');
$fmtText2->set_color('grey');
$fmtText2->set_size(10);
$fmtText2->set_bold(0);

$fmtHoliday2=$workbook->add_format();
$fmtHoliday2->set_align('right');
$fmtHoliday2->set_align('bottom');
$fmtHoliday2->set_left(1);
$fmtHoliday2->set_right(1);
$fmtHoliday2->set_bottom(1);
$fmtHoliday2->set_bg_color('silver');
$fmtHoliday2->set_font('Arial');
$fmtHoliday2->set_color('plum');
$fmtHoliday2->set_size(8);
$fmtHoliday2->set_text_wrap(1);
$fmtHoliday2->set_bold(1);

@week=(
UnixDate(DateCalc($date,"+0 days"),"%A"),
UnixDate(DateCalc($date,"+1 days"),"%A"),
UnixDate(DateCalc($date,"+2 days"),"%A"),
UnixDate(DateCalc($date,"+3 days"),"%A"),
UnixDate(DateCalc($date,"+4 days"),"%A"),
UnixDate(DateCalc($date,"+5 days"),"%A"),
UnixDate(DateCalc($date,"+6 days"),"%A"),
);




for($month=1;$month<13;$month++)
{

        $first = first_sunday_of_calmonth($month,$year);
        $date=strftime("%m/%d/%Y", localtime($first));

   $workbook->add_worksheet((UnixDate("$month/1/$year","%B")));

$workbook->sheets($month-1)->merge_range(0,0,0,6,UnixDate("$month/1/$year","%B")."
- $year",$fmtMonth);

        $workbook->sheets($month-1)->set_column('A:A', 15);
        $workbook->sheets($month-1)->set_column('B:B', 15);
        $workbook->sheets($month-1)->set_column('C:C', 15);
        $workbook->sheets($month-1)->set_column('D:D', 15);
        $workbook->sheets($month-1)->set_column('E:E', 15);
        $workbook->sheets($month-1)->set_column('F:F', 15);
        $workbook->sheets($month-1)->set_column('G:G', 15);

   for($dow=0;$dow<7;$dow++){

        $workbook->sheets($month-1)->write(1,$dow,dotw($dow),$fmtWeek);
	}
#Render the Calendar Entries

        for($row=2;$row < 30;$row+=5)
        {

                for($cols=0;$cols<7;$cols++)
                {

                        #define the Roles, this is where mod math does
if not just three
                        $sunday=$users[($row)%$totalUsers];
                        $saturday=$users[($row+2)%$totalUsers];
                        $weekday=$users[($row+1)%$totalUsers];
                        $weeknight=$users[($row+2)%$totalUsers];

                        if (UnixDate($date,"%m") == $month) {


$workbook->sheets($month-1)->write($row,$cols,UnixDate($date,"%d"),$fmtDate);

$workbook->sheets($month-1)->write_blank($row+1,$cols,$fmtDate);
                        SWITCH: {

                        $cols==0 and do {

$workbook->sheets($month-1)->write($row+2,$cols,"Primary:
$sunday",$fmtText);

$workbook->sheets($month-1)->write_blank($row+3,$cols,$fmtText);

$workbook->sheets($month-1)->write($row+4,$cols,holidayCheck($date),$fmtHoliday);
                        last;
                        };

                        $cols==6 and do {

$workbook->sheets($month-1)->write($row+2,$cols,"Primary:
$saturday",$fmtText);

$workbook->sheets($month-1)->write_blank($row+3,$cols,$fmtText);

$workbook->sheets($month-1)->write($row+4,$cols,holidayCheck($date),$fmtHoliday);
                        last;
                        };
                        $cols!=6 || $cols!=0 and do {

$workbook->sheets($month-1)->write($row+2,$cols,"Days:
$weekday",$fmtText);

$workbook->sheets($month-1)->write($row+3,$cols,"Evenings:
$weeknight",$fmtText);

$workbook->sheets($month-1)->write($row+4,$cols,holidayCheck($date),$fmtHoliday);
                        last;
                        }

                        } #END OF SWITCH
                        } else {

$workbook->sheets($month-1)->write($row,$cols,UnixDate($date,"%d"),$fmtDate2);

$workbook->sheets($month-1)->write_blank($row+1,$cols,$fmtDate2);
                        SWITCH: {

                        $cols==0 and do {

$workbook->sheets($month-1)->write($row+2,$cols,"Primary:
$sunday",$fmtText2);

$workbook->sheets($month-1)->write_blank($row+3,$cols,$fmtText2);

$workbook->sheets($month-1)->write($row+4,$cols,holidayCheck($date),$fmtHoliday2);
                        last;
                        };

                        $cols==6 and do {

$workbook->sheets($month-1)->write($row+2,$cols,"Primary:
$saturday",$fmtText2);

$workbook->sheets($month-1)->write_blank($row+3,$cols,$fmtText2);

$workbook->sheets($month-1)->write($row+4,$cols,holidayCheck($date),$fmtHoliday2);
                        last;
                        };
                        $cols!=6 || $cols!=0 and do {

$workbook->sheets($month-1)->write($row+2,$cols,"Days:
$weekday",$fmtText2);

$workbook->sheets($month-1)->write($row+3,$cols,"Evenings:
$weeknight",$fmtText2);

$workbook->sheets($month-1)->write($row+4,$cols,holidayCheck($date),$fmtHoliday2);
                        last;
                        }

                        } #END OF SWITCH


                        }
                        $date=DateCalc($date,"+1 day");


                }

        if(UnixDate($date,"%m") > $month) {last;}
        };

        #Set Up The Printer Settings
        $workbook->sheets($month-1)->center_horizontally();
        $workbook->sheets($month-1)->center_vertically();
        $workbook->sheets($month-1)->set_paper(1);
        $workbook->sheets($month-1)->set_margins(.6);
        $workbook->sheets($month-1)->set_landscape();

        $workbook->sheets($month-1)->print_area(0,0,$row+4, $cols-1)

}
$workbook->close();

sub holidayCheck {
my $t = shift;
my $y = UnixDate($t,"%Y");
my $m = UnixDate($t,"%m");
my $d = UnixDate($t,"%d");

my $checkDate = "$m/$d/$y";

print "My CheckDate= $checkDate\n";

SWITCH: {

$checkDate eq "01/02/$y" and do {return "New Year's Day";};
$checkDate eq "01/16/$y" and do {return "Martin Luther King, Jr.
Day";};
$checkDate eq "02/20/$y" and do {return "Presidents' Day";};
$checkDate eq "05/29/$y" and do {return "Memorial Day";};
$checkDate eq "07/04/$y" and do {return "Independence Day";};
$checkDate eq "09/04/$y" and do {return "Labor Day";};
$checkDate eq "10/09/$y" and do {return "Columbus Day";};
$checkDate eq "11/11/$y" and do {return "Veterans' Day";};
$checkDate eq "11/23/$y" and do {return "Thanksgiving Day";};
$checkDate eq "12/25/$y" and do {return "Christmas Day";};

} #END SELECT


}

sub first_sunday_of_calmonth {
  my $m = shift;
  my $y = shift;

  my $dow = strftime("%w", 0,0,0,1,$m-1,$y-1900);
  my $time = timelocal(0,0,0,1,$m-1,$y-1900);
  return $time - ($dow * 24 * 60 * 60);
}

--End Schedule--
Paul Lalli wrote:
> idgarad@gmail.com wrote:
> > Very simple in description but tricky to implement so far. What I am
> > after is given a year, say 2006, what is the First sunday's date on the
> > calendar (For January). For instance in 2006 this would be january 1st
> > 2006. But in 2005 it would be Dec 26th 2004. Is there a simple module
> > for getting this kind of date?
>
> I'm sure one of the hundreds of Date* modules available on CPAN can do
> this, but if you don't feel like installing a non-standard module just
> for this purpose, this seems to work for me:
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> use POSIX qw/strftime/;
> use Time::Local;
>
> for my $y (2004, 2005, 2006) {
>   my $first = first_sunday($y);
>   print "$y:  ", strftime("%C", localtime($first)), "\n";
> }
>
> sub first_sunday {
>   my $y = shift;
>   my $dow = strftime("%w", 0,0,0,1,0,$y-1900);
>   my $time = timelocal(0,0,0,1,0,$y-1900);
>   return $time - ($dow * 24 * 60 * 60);
> }
> __END__
> 2004:  Sun Dec 28 00:00:00 EST 2003
> 2005:  Sun Dec 26 00:00:00 EST 2004
> 2006:  Sun Jan  1 00:00:00 EST 2006
>
> Basically, find the day of the week of the first of the year (as an
> integer from 0 - 6).  Then take that date, and subtract that number of
> days from it.
> 
> Paul Lalli



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

Date: 6 Oct 2006 09:50:57 -0700
From: "Idgarad" <idgarad@gmail.com>
Subject: Re: Find First Date of A Calendar Month\Year
Message-Id: <1160153456.136595.123230@c28g2000cwb.googlegroups.com>

Dead right David, that is what I was after. Effectivly what is the date
in row 0, col 0 of the calendar. I posted the completed work. Thank you
all for the help.


usenet@DavidFilmer.com wrote:
> anno4000@radom.zrz.tu-berlin.de wrote:
> > Just one question:  How is Dec 26th 2004 the first Sunday in 2005?
>
> I think the OP means  if you look at a calendar (where Sunday is the
> first column) and see which row holds Jan 1, what is the date of the
> first column of that row?
> 
> -- 
> David Filmer (http://DavidFilmer.com)



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

Date: 6 Oct 2006 09:03:11 -0700
From: samiam@mytrashmail.com
Subject: Re: Hard or Easy? To find string, then grab criterion matched lines above and below?
Message-Id: <1160150591.684844.248470@b28g2000cwb.googlegroups.com>

Hi Tad,

Links to the complete data files and a detailed description of my
simple data mining are in my first and second post.

Here is my perl script solution so far - at the end of this post.

I am a crude programmer and so I can't attest for the elegance of this
code or if it's even close to efficient. This code is bits and pieces I
have put together looking at examples on the net. It mostly works.

I haven't been able to get it to put both the %%before  and %%after
sections into the csv file.

I would also like to pull the descriptive title of the registry key
into the CSV file, ie. "Checking Netmeeting - Disable Remote Desktop
Sharing"  It comes at the end of the lines containing the CSR# such as
5.6.1.1

That part is tricky, at least to this noob.

Can anyone tell me how to add both the %%before and %%after  as well as
the key description to my csv file?

Thanks!

L,
Sam

-------sample data-----------

# NETMEETING REG SETTING #
dialog set,text1,"5.6.1.1 Checking Netmeeting - Disable Remote Desktop
Sharing"
dialog set,text2,"5.6.1.1 Checking Netmeeting - Disable Remote Desktop
Sharing"
%%before =
@REGREAD(HLM,SOFTWARE\Policies\Microsoft\Conferencing,NoRDS,)
REGISTRY
WRITE,HLM,SOFTWARE\Policies\Microsoft\Conferencing,NoRDS,1,INTEGER
%%after = @REGREAD(HLM,SOFTWARE\Policies\Microsoft\Conferencing,NoRDS,)
%%stat = FAIL
%%stat2 = FAIL
if @equal(%%before,"1")
%%stat = PASS
end
if @equal(%%after,"1")
%%stat2 = PASS
end
list add,debug,"5.6.1.1:Setting Before Run" %%before "Setting After
Run:" %%after
list add,log,"5.6.1.1~NetMeeting Disable Remote Desktop
Sharing~"%%stat"~"%%stat2"~"%%before%%after
list savefile,log,%%logfile
list savefile,debug,%%debugfile
wait 0.2

:checkseven
%%check = @INIREAD(checks,checkseven)
if @equal(%%check,off)
goto checkeight
end

--------end sample data------------

---------Script So Far-------------
#Create a couple of lookup hashes
open ANALYZE, 'analyze.dsc';
while(<ANALYZE>) {
  $section  = $1 if /^#\s+(.*)?\s+#/;
  $rule_no  = $1 if /^dialog set,text1,\"([.1234567890]*)/;
  if( /^REGISTRY WRITE,(.*)/ ) {
    $regkey{$rule_no} = $1;
    $sect{$rule_no}   = $section;
  }
}
close ANALYZE;

#Scan the Audit file for failures
open AUDITFILE, 'server.aud';
open CSVFILE, '>logfile.csv';
print CSVFILE "CSR #,Section Title,Registry Key\n";
while(<AUDITFILE>) {
  if(/^(.*?)~.*~FAIL~/) {
    $csr           = $1;
    $section_title = $sect{$csr};
    $registry_key  = $regkey{$csr};
    if( $section_title ne "" ) {
      print CSVFILE "\"$csr\",\"$section_title\",\"$registry_key\"\n";
    } else {
      print "Fail code $csr not found in analyze.dsc\n";
    }
  }
}
close AUDITFILE;
close CSVFILE;



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

Date: Thu, 5 Oct 2006 19:30:22 -0700
From: "Steve Kostecke" <spamtrap@ntp.isc.org>
Subject: Re: Hard or Easy? To find string, then grab criterion matched lines above and below?
Message-Id: <4onj4dFf9mvhU1@individual.net>


"Tad McClellan" <tadmc@augustmail.com> wrote in message 
news:slrneib43v.9e3.tadmc@magna.augustmail.com...
> samiam@mytrashmail.com <samiam@mytrashmail.com> wrote:
>
>> I know this is a trivial parse / grep job for any Perl rake worth his
>> salt, but does anyone have guidance on how this Perl newbie might pull
>> a string from one file and use this string to pull the lines in another
>> file out, and also pull the first line before (matching criteria) and
>> the first line after (matching criteria.)
>
>
> If you show us the code you have so far, we will help you fix it.
>
>
>> At first I thought to use VBScript, but then I realized that Perl is
>> portable, doesn't necessarily have to  be installed on the server, and
>
>
> What "server"?
>
> A server is not normally required to run Perl programs.
>
> Is this a stealth CGI question?

His question was obviously pertaining to Perl being used for a file parsing 
solution. The question itself had nothing to do with CGI and I think you 
knew that.

> If it is a CGI question, then you _do_ need to have perl installed
> on the web server.

No, not necessarily. There are several way to "compile" a Perl script into a 
standalone executable (perl2bin, perl2exe, etc. Also there's ActiveState's 
PerlEXE, part of the Perl Dev Kit.) Regardless of the OS, if you can make it 
into a standalone binary, it's only a matter of properly configuring the 
server to run it, and no Perl installation is needed (and yes I've tested.)

>> Summary: I need to find CSR numbers in FILE-A that map to registry key
>> entries in FILE-B, and report the pertinent surrounding info.
>
>
> None of the failed CSR numbers in your example FILE-A map to any registry
> key entries in FILE-B, so the program must make no output...

Maybe just a bad example and not necessarily the only data that'll be 
operated on?




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

Date: 6 Oct 2006 15:17:14 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: How to parse a new computer language in Perl?
Message-Id: <4onabqFf57p8U1@news.dfncis.de>

[newsgroup perl.beginners trimmed]

Davy <zhushenli@gmail.com> wrote in comp.lang.perl.misc:
> Hi all,
> 
> I was told that when design a new computer language, I need something
> like yacc to define the language parser principle. And other people
> told me that XML can be used to parse the computer language.
> 
> Please recommand a simple computer language parser module in Perl.

You want a parser generator.  Search CPAN (http://search.cpan.org/)
for "parser".  You'll find at least Parse::RecDescent, probably more.

Anno


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

Date: Fri, 06 Oct 2006 19:17:54 +0200
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: If gethostbyname fails it never recovers
Message-Id: <45268fb7$0$27387$ba4acef3@news.orange.fr>

Andrew DeFaria wrote:
> I've been having problems with my ISP. One way it seems to manifest 
> itself is that I can not reach or contact my ISP's DNS servers. IOW a 
> simply nslookup google.com will fail.
> 
> So I tried writing a script that would monitor this. The script calls 
> gethostbyname for google.com every 15 minutes and logs the status. When 
> gethostbyname fails however it never comes back. My ISP and internet 
> connection may come back and nslookup at the command line will work 
> fine. But my script will report failure at the next and following 15 
> minute intervals. This is very unexpected. What am I doing wrong and is 
> there a way to "reset" things so that it will start working again.

 From

perldoc - f gethostbyname

For the gethost*() functions, if the "h_errno" variable is supported in 
C, it will be returned  to you via $? if the function call fails.

It appears to be undefined as to what $? will be set to if the call 
*succeeds*, and thus it should not be relied upon to check for success 
or failure of the call.


> Here's a snippet:
> 
> sub CheckDNS {
>   my $host = shift;
> 
>   my @ipaddrs = gethostbyname $host;
>   my $status  = $?;
> 
>   if ($status ne 0 and $debug) {
>     debug "Host: $host ($status)";
>   } # if
> 
>   return $status
> } # CheckDNS
> 
> CheckDNS is called every 15 minutes with "google.com" as a parm. When a 
> failure happens $status = 2 and remains = 2 forever.

I'd check to see if

my @ipaddrs = gethostbyname $host;

returns a defined result. If not, only then should you look at $?.

Have you considered nagios?

Mark


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

Date: Fri, 06 Oct 2006 17:57:30 GMT
From: "Mumia W. (reading news)" <paduille.4058.mumia.w@earthlink.net>
Subject: Re: LWP and Unicode
Message-Id: <eOwVg.3962$Lv3.67@newsread1.news.pas.earthlink.net>

On 10/06/2006 03:55 AM, Dale wrote:
> Mumia W. (reading news) wrote:
>> 403 Forbidden
> 
> Whoops! I'm sure you managed to recreate the website yourself. But just
> in case:
> 
> http://www.sfs.uni-tuebingen.de/~dg/fooo.html
> 
> The contents are:
> 
> %D1%86 a ц
> [...]

I used GNU Wget to download that file (while using -s to also save the 
HTTP headers):


> HTTP/1.1 200 OK
> Date: Fri, 06 Oct 2006 16:20:56 GMT
> Server: Apache/1.3.33 (Debian GNU/Linux)
> Last-Modified: Fri, 06 Oct 2006 08:40:50 GMT
> ETag: "1d27db-b-45261692"
> Accept-Ranges: bytes
> Content-Length: 11
> Keep-Alive: timeout=15, max=100
> Connection: Keep-Alive
> Content-Type: text/html; charset=iso-8859-1
> 
> %D1%86 a ц

Your data seems to be UTF8, but you advertise it as iso-8859-1. Don't 
you think that will confuse user agents such as LWP::UserAgent?


-- 
paduille.4058.mumia.w@earthlink.net
Posting Guidelines for comp.lang.perl.misc:
http://www.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Fri, 06 Oct 2006 10:13:29 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: newbie cspan example question
Message-Id: <45267219$0$3572$815e3792@news.qwest.net>

ToddAndMargo@gbis.com wrote:
> Hi All,
> 
>     A am real new to Perl.  My background is Modula2 and Bash scripts.
> I love all the examples at CSPAN.

Too much drama, on CSPAN. :-)

There's no need to put 'newbie' in every subject, just set the
subject to something that briefly states your question.

> 
>     I have been looking at:
>           http://search.cpan.org/~ugansert/Paw-0.54/Paw/Popup.pm
> 
>                  @butt=('Okay', 'Cancel');
>                  $text=('Do you really want to continue ?');
>                  $pu=Popup::new(height=>20, width=>20,
>                         buttons=>\@butt, text=>\$text);
> 
> Having run the example and being told that something important
> was missing (Popup::new) I though I had better ask the following
> questions:

Possibly going through a few tutorials will get you up to speed
faster than posting a question every time something doesn't work.

  http://www.perlmonks.org/index.pl?node=Tutorials

There are also plenty of books  ( perldoc perlbook ), tutorials, and 
online documentation, along with the documentation that came along
with your installed version of perl.


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

Date: Fri, 06 Oct 2006 10:18:56 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Output of Concise
Message-Id: <4526735f$0$3572$815e3792@news.qwest.net>

Ferry Bolhar wrote:
> Hi,
> 
> when running code with
> 
> perl -MO=Concise,-exec
> 
> for lexical variables, I get output similar to this:
> 
> l  <0> padsv[$Search:26,28]
> 
> What does the "26,28" mean?
> 
> And for concatenation,
> 
> 12 <2> concat[t4] sK/2
> 
> What is the meaning of "[t4]"?

The documentation for B::Concise seems to explain the output pretty well.

perldoc B::Concise


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

Date: 6 Oct 2006 09:38:34 -0700
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: parsing event handler and object data
Message-Id: <1160152714.604238.296490@m7g2000cwm.googlegroups.com>



On Oct 6, 8:08 am, Michael Goerz <new...@8439.e4ward.com> wrote:
> Hi,
>
> I'm having some trouble with the event based HTML parser module
> HTML::Parser. See the attached example code. The problem is this:
>
> The event handlers seem to be completely self-contained, they only get
> the parameters that are passed to them by the parser. However, I'd like
> them to access variables from a higher scope, such as object data from
> the class I'm using the HTML parser in.

What you are saying is you want to pass the HTML::Parser a callback
that calls back to an object method rather than just to a subroutine.

> I suppose the same problem arises with other event-based parsers, too.

Or any API with callbacks.

Your question is, in fact, almost FAQ but it's perhaps not immediately
obvious that this is the case.

The FAQ in question is "How can I pass/return a {Function, FileHandle,
Array, Hash, Method, Regex}?". One way of looking at it is that you are
asking "How can I pass a Method?"

> What's the right way to do something like this?

This is Perl! There's more than on right way.

> Content-Type: application/x-perl; name="TestParser.pm"

text/plain please (or simply inline your text).

[ code slightly simplified for illustrative puposes, the OP's code was
an execllent *mimimal* but *complete* illustration of his point ]

> sub parse{
>    my $self = shift;
>    my $p = HTML::Parser->new( api_version => 3,
>                         start_h => [\&start, "tagname, attr"],
>                      );
>    $p->parse_file($self->{infile});
>}
>
> sub start{
>    # Doesn't work, how do I access variables from a hight scope?
>    $self->{tagname} = shift;
>}

Right. There are three approches that spring to mind.

  1) Move start() inside the lexical scope of parse() so that $self is
in scope. This is a slightly complicated by the fact that Perl doesn't
have proper named nested subs but does have anonymous closures.

  2) Call start() as a method using a small closure as a shim.

  3) Use package for the variables that you want to be shared between
multiple lexical scopes.

Note: Solution 3 is considered dity by some. It is generally the
easiest to debug unless you are interfacing to a object that will
persist beyond the context is which it is created in which case it
becomes the hardest to debug.

In your code the HTML::Parser object will only exist within the time
that parser() is on the stack. Futhermore, if parser() is called
reentrantly then you can be sure that the HTML::Parser object from the
outer instance of parser() will never try to call back dring the
execution of the inner parser(). Only because these two conditions are
met is it safe to opt for solution 3.


# Solution 1

sub parse{
   my $self = shift;
   my $start = sub {
      $self->{tagname} = shift;
   };

   my $p = HTML::Parser->new( api_version => 3,
                        start_h => [ $start, "tagname, attr"],
                     );
   $p->parse_file($self->{infile});
}

# Solution 2

sub parse {
   my $self = shift;
   my $p = HTML::Parser->new( api_version => 3,
                        start_h => [ sub { $self->start(@_) },
"tagname, attr"],
                     );
   $p->parse_file($self->{infile});
}

sub start {
   my $self = shift; # We're now a method
   $self->{tagname} = shift;
}

# Solution 3

our $self;

sub parse {
   local $self = shift;
   my $p = HTML::Parser->new( api_version => 3,
                        start_h => [\&start, "tagname, attr"],
                     );
   $p->parse_file($self->{infile});
}

sub start {
   $self->{tagname} = shift; 
}



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

Date: Fri, 06 Oct 2006 17:57:32 GMT
From: "Mumia W. (reading news)" <paduille.4058.mumia.w@earthlink.net>
Subject: Re: parsing event handler and object data
Message-Id: <gOwVg.3963$Lv3.2335@newsread1.news.pas.earthlink.net>

On 10/06/2006 02:08 AM, Michael Goerz wrote:
> Hi,
> 
> I'm having some trouble with the event based HTML parser module
> HTML::Parser. See the attached example code. The problem is this:
> 
> The event handlers seem to be completely self-contained, they only get
> the parameters that are passed to them by the parser. However, I'd like
> them to access variables from a higher scope, such as object data from
> the class I'm using the HTML parser in. I suppose the same problem
> arises with other event-based parsers, too. What's the right way to do
> something like this?
> 
> Thanks,
> Michael

Use anonymous subroutines as callbacks (handlers):

package TestParser;
use strict;

use HTML::Parser;

sub new{
     my $class = shift;
     my $self = {};
     $self->{tagname} = '';
     $self->{attr} = '';
     $self->{text} = '';
     $self->{infile} = "./test.html";
     bless($self, $class);
     return $self;
}



sub parse{
     my $self = shift;

     # Create anonymous subroutines to serve as handlers.
     my $start_hand = sub { $self->start(@_) };
     my $text_hand = sub { $self->text(@_) };

     my $p = HTML::Parser->new( api_version => 3,
                          start_h => [$start_hand, "tagname, attr"],
                          text_h  => [$text_hand,  "dtext"],
                          marked_sections => 1,
                        );
     $p->parse_file($self->{infile});

}

sub start{
     my $self = shift;
     my $tagname = shift;
     $self->{tagname} = $tagname;
     my $attr = shift;

}

sub text{
     my $self = shift;
     my $text = shift;
     $self->{$text} = $text;
}

1;

__HTH__

-- 
paduille.4058.mumia.w@earthlink.net
Posting Guidelines for comp.lang.perl.misc:
http://www.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: 6 Oct 2006 09:03:48 -0700
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: Parsing HTML - using HTML::TreeBuilder
Message-Id: <1160150628.383579.92190@e3g2000cwe.googlegroups.com>

olson_ord@yahoo.it wrote:
> Thanks a lot Paul.
> 	I looked at the documentation HTML::TokeParser and it does not tell me
> if there is an easy way to find a certain token (e.g. "h2") i.e. It
> seems that I would have to start from the beginning and then scan all
> the tokens until I reach the required token. (I am basically looking
> for a find() function - or something similar.)

Look a little harder, dude.  it's (basically) 2 lines of code:

  #!/usr/bin/perl

  use strict;
  use warnings;

  use LWP::Simple;
  use HTML::TokeParser;

  my $url = 'http://wordlist.gredic.com/kaleidoscope';
  my $html = get( $url );

  my $p = HTML::TokeParser->new( \$html );

  while (  my $tag_ref = $p->get_tag( 'h2' ) ) {
  	printf "%s: %s\n", $tag_ref->[0], $p->get_trimmed_text;
  }
  
  __END__



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

Date: Fri, 06 Oct 2006 10:45:14 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Passing parameter through SOAP::Lite
Message-Id: <4526798a$0$10301$815e3792@news.qwest.net>

niraj.kumar.ait@gmail.com wrote:
> Hi,
> 
> How to pass parameter to method in SOAP::Lite. Like I want to set ABC
> to xyz,CCNA to sdf
> 
> my $result = SOAP::Lite
> 
> ->service('https://192.168.9.1/imaPreOrder/preOrder?WSDL')
>                          ->getCSR('ABC' => 'xyz',
> 					'CCNA' => 'sdf',
> 					);
> 
> I even tried SOAP :: Data
> 
> my $result = SOAP::Lite
> 
> ->service('https://192.168.9.1/imaPreOrder/preOrder?WSDL')
>                          ->getCSR(SOAP::Data->name("ABC" => "xyz")
> 	                          SOAP::Data->name("CCNA" => "I28"),
> );
> 
> But these is not working .Please advice on how to pass data.

Define "not working".  The code you provide looks correct. Maybe
the issue is with your server, or your WSDL, or some other
piece of code.

You can view the entire request by adding:

use SOAP::Lite +trace;

Also, there's a Web site: http://www.soaplite.com/ with documentation,
examples, and mailing lists.


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

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


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